/**
 * Initialize the Logger
 */
// DEBUG LEVEL
var LOG = 0;
var DEBUG = 1;
var INFO = 2;
var ERROR = 3;

// Wrapper around Firebug Console, so we output just in case of console
// NOTE: i.e. IE does not have a Console
FB = function () { }


if(location.hostname == 'localhost') {
	FB.o = true;
	FB.l = 3; // add log level ID for console output
} else {
	FB.o = false;
	//FB.o = false; //globally disable debugging output
	FB.l = 0; // add log level ID for console output
}

FB.log = function (msg, level, x) {

	if (!FB.o) return true;

	if (!window.console) {
		return true;
	} else {
		switch(level) {
			case(DEBUG):
			    if (FB.l <= 1 ) {
					window.console.log('DEBUG: '+msg);
					//window.console.debug(msg); // won't work on Safari
				}
				break;
			case(INFO):
				if (FB.l <= 2 ) {
					window.console.log('INFO: '+msg);
					//window.console.info(msg); // won't work on Safari
				}
				break;
			case(ERROR):
			    if (FB.l <= 3 ) {
					window.console.log('ERROR: '+msg);
					//window.console.error(msg); // won't work on Safari
				}
				break;
			default:
			    if (FB.l <= 1 ) {
					window.console.log('LOG: '+msg);
				}
				break;
		}
	}
}

/**
 * eversjung package
 *
 * This package contains initialization functions.
 *
 * @author <a href="mailto:info@cappuccinonet.com.com">Bernhard Woehrlin, IT.CappuccinoNet.com</a>
 */
if (typeof eversjung == 'undefined') {
  eversjung = function () { }
}

eversjung.init = function () { }



/**
 * initializes the page's JavaScript

 * @package eversjung.init
 */
eversjung.init.initialize = function () {

	$(document).ready( function() {



		$('a[@href$=".pdf"]').addClass('pdflink');

		if ($("#kontaktform")) {

			// validate signup form on keyup and submit
			$("#kontaktform").validate({
				errorPlacement: function(error, element) {
					if ( element.is(":radio") )
						error.appendTo( element.parent("td") );
					else if ( element.is(":checkbox") )
						error.appendTo ( element.next() );
					else
						error.appendTo( element.parent("td") );
				},
				rules: {
					//anrede: {
					//	required: true
					//},
					name: {
						required: true,
						minlength: 2
					},
					email: {
						required: true,
						email: true
					}
				},
				messages: {
					anrede: STRING_ERR_MSG_ANREDE_HOW,
					name: {
						required: STRING_ERR_MSG_NAME,
						minlength: jQuery.format(STRING_ERR_MSG_NAME_LENGTH)
					},
					email: STRING_ERR_MSG_EMAIL
				}
			});

			$("#kontaktform input[type=image]").click(function() {
		  		if ($("#kontaktform").valid())
				{
					var kontaktformoptions = {
				        //target:        '#target',   // target element(s) to be updated with server response
				        beforeSubmit:  eversjung.kontaktform.validate,  // pre-submit callback
				        success:       eversjung.kontaktform.showResponse,  // post-submit callback

				        // other available options:
				        //url:       l         // override for form's 'action' attribute
				        //type:      type        // 'get' or 'post', override for form's 'method' attribute
				        dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type)
				        //clearForm: true        // clear all form fields after successful submit
				        //resetForm: true        // reset the form after successful submit

				        // $.ajax options can be used here too, for example:

			   		};

					// indicate the server that this form was sent through json
					$('#kontaktform').append('<input type="hidden" id="is_json" name="is_json" value="1" />');

			   		$('#kontaktform').ajaxForm(kontaktformoptions);
				}
			});
		}

	} );

}




eversjung.init.initialize();

