﻿/* CUSTOM FORM VALIDATION */
function validateRegExp(string,type)
{
	var regExp;
	switch(type)
	{
		case "noSpecialCaracters":
			regExp = /^[0-9a-zA-ZäöüÄÖÜß]+$/;
			break;
		case "email":
			regExp = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/;
			break;
		case "phone":
			regExp = /^((\+[0-9]{2,4}( [0-9]+? | ?\([0-9]+?\) ?))|(\(0[0-9 ]+?\) ?)|(0[0-9]+? ?( |-|\/) ?))[0-9]+?[0-9 \/-]*[0-9]$/;
			break;
		case "integer":
			regExp = /^[\-\+]?\d+$/;
			break;
		case "price":
			regExp = /^[0-9.,]+$/;
			break;
		case "date":
			regExp = /^\d{2}[\.\-]\d{1,2}[\.\-]\d{4}$/
			break;
		default:
			return false;
	}

	var result = regExp.test(string);
	if(result === false)
		return false;
	return true;
}

function setInputErrorBackground(input, action)
{
	if(action == "add")
	{
		if(!input.hasClass('error'))
			input.addClass('error');
	}
	else if(action == "remove")
	{
		if(input.hasClass('error'))
			input.removeClass('error');	
	}
}

function setLineValidity(id, valid)
{
	if(valid)
		id.show();
	else
		id.hide();
}

/* CONTACT FORM VALIDATION */
function validateCompany()
{
	if($("#contactCompany").val().length >= 3)
	{	
		setInputErrorBackground($("#contactCompany"), "remove");
		setLineValidity($("#validCompany"), true);
		return true;
	}
	setLineValidity($("#validCompany"), false);
	setInputErrorBackground($("#contactCompany"), "add");	
	return false;
}

function validateBranche()
{
	if($("#contactBranche option:selected").length == 1)
	{
		if($("#contactBranche option:selected").get(0).value != "")
		{
			setInputErrorBackground($("#contactBranche_title"), "remove");
			setLineValidity($("#validBranche"), true);
			return true;
		}
	}
	setLineValidity($("#validBranche"), false);
	setInputErrorBackground($("#contactBranche_title"), "add");	
	return false;
}

function validateSalutation()
{
	if($("#contactSalutation option:selected").length == 1)
	{
		if($("#contactSalutation option:selected").get(0).value != "")
		{
			setInputErrorBackground($("#contactSalutation_msdd"), "remove");
			setLineValidity($("#validSalutation"), true);
			return true;
		}
	}
	setLineValidity($("#validSalutation"), false);
	setInputErrorBackground($("#contactSalutation_msdd"), "add");	
	return false;
}

function validateFirstname()
{
	if($("#contactFirstname").val().length >= 3)
	{	
		setInputErrorBackground($("#contactFirstname"), "remove");
		setLineValidity($("#validFirstname"), true);
		return true;
	}
	setLineValidity($("#validFirstname"), false);
	setInputErrorBackground($("#contactFirstname"), "add");	
	return false;
}

function validateLastname()
{
	if($("#contactName").val().length >= 3)
	{
		setInputErrorBackground($("#contactName"), "remove");
		setLineValidity($("#validName"), true);
		return true;
	}
	setLineValidity($("#validName"), false);
	setInputErrorBackground($("#contactName"), "add");
	return false;
}

function validateSchool()
{
	if($("#educationSchool").val().length >= 3)
	{	
		setInputErrorBackground($("#educationSchool"), "remove");
		setLineValidity($("#validSchool"), true);
		return true;
	}
	setLineValidity($("#validSchool"), false);
	setInputErrorBackground($("#educationSchool"), "add");	
	return false;
}

function validatePosition()
{
	if($("#contactPosition").val().length >= 3)
	{
		setInputErrorBackground($("#contactPosition"), "remove");
		setLineValidity($("#validPosition"), true);
		return true;
	}
	setLineValidity($("#validPosition"), false);
	setInputErrorBackground($("#contactPosition"), "add");
	return false;
}

var validStreet = false;
var validNo = false
function checkStreetValidity()
{
	if(validStreet && validNo)
		setLineValidity($("#validStreet"), true);
	else
		setLineValidity($("#validStreet"), false);
}

function validateStreet()
{
	if($("#contactStreet").val().length >= 3)
	{
		validStreet = true;
		setInputErrorBackground($("#contactStreet"), "remove");
		checkStreetValidity();
		return true;
	}
	validStreet = false;
	checkStreetValidity();
	setInputErrorBackground($("#contactStreet"), "add");
	return false;
}
	
function validateNo()
{
	if($("#contactNo").val().length >= 1 && validateRegExp($("#contactNo").val(), "noSpecialCaracters"))
	{
		validNo = true;
		setInputErrorBackground($("#contactNo"), "remove");
		checkStreetValidity();
		return true;
	}
	validNo = false;
	checkStreetValidity();
	setInputErrorBackground($("#contactNo"), "add");
	return false;
}

var validZip = false;
var validCity = false
function checkCityValidity()
{
	if(validZip && validCity)
		setLineValidity($("#validCity"), true);
	else
		setLineValidity($("#validCity"), false);
}

function validateZip()
{
	if($("#contactZip").val().length == 5  && validateRegExp($("#contactZip").val(), "integer"))
	{
		validZip = true;
		setInputErrorBackground($("#contactZip"), "remove");
		checkCityValidity();
		return true;
	}
	validZip = false;
	checkCityValidity();
	setInputErrorBackground($("#contactZip"), "add");
	return false;
}

function validateCity()
{
	if($("#contactCity").val().length >= 3)
	{
		validCity = true;
		setInputErrorBackground($("#contactCity"), "remove");
		checkCityValidity();
		return true;
	}
	validCity = false;
	checkCityValidity();
	setInputErrorBackground($("#contactCity"), "add");
	return false;
}

function validateEmail()
{
	if($("#contactEmail").val().length >= 1)
	{
		if(validateRegExp($("#contactEmail").val(), "email"))
		{
			setInputErrorBackground($("#contactEmail"), "remove");
			setLineValidity($("#validEmail"), true);
			return true;		
		}
		else
		{
			setLineValidity($("#validEmail"), false);
			setInputErrorBackground($("#contactEmail"), "add");
			$.validationEngine.buildPrompt("#contactEmail", "Geben Sie bitte eine korrekte E-Mail-Adresse ein", "error");
			return false;
		}
	}
	else
	{
		setLineValidity($("#validEmail"), false);
		setInputErrorBackground($("#contactEmail"), "add");
		return false;
	}
}

function validateSchoolEmail()
{
	if($("#educationEmail").val().length >= 1)
	{
		if(validateRegExp($("#educationEmail").val(), "email"))
		{
			setInputErrorBackground($("#educationEmail"), "remove");
			setLineValidity($("#validSchoolEmail"), true);
			return true;		
		}
		else
		{
			setLineValidity($("#validSchoolEmail"), false);
			setInputErrorBackground($("#educationEmail"), "add");
			$.validationEngine.buildPrompt("#educationEmail", "Geben Sie bitte eine korrekte E-Mail-Adresse ein", "error");
			return false;
		}
	}
	else
	{
		setLineValidity($("#validSchoolEmail"), false);
		setInputErrorBackground($("#educationEmail"), "add");
		return false;
	}
}

function validatePhone()
{
	if($("#contactPhone").val().length >= 1)
	{
		setLineValidity($("#validPhone"), true);
		return true;		
	}
	setLineValidity($("#validPhone"), false);
	return true;
}

function validateRequest()
{
	if($("#contactRequest option:selected").length == 1)
	{
		if($("#contactRequest option:selected").get(0).value != "")
		{
			setInputErrorBackground($("#contactRequest_title"), "remove");
			setLineValidity($("#validRequest"), true);
			return true;
		}
	}
	setLineValidity($("#validRequest"), false);
	setInputErrorBackground($("#contactRequest_title"), "add");	
	return false;
}

function validateMessage()
{
	if($("#contactMessage").val().length >= 3)
	{	
		setInputErrorBackground($("#contactMessage"), "remove");
		setLineValidity($("#validMessage"), true);
		return true;
	}
	setLineValidity($("#validMessage"), false);
	setInputErrorBackground($("#contactMessage"), "add");	
	return false;
}

function validateProductform()
{
	$(".productforms form").each(function(i) {
		$product = $(this).find('input[type="hidden"]').val();
		if($product == "strom" || $product == "erdgas")
		{
			$submitButton = $(this).find('.submit');
			if($(this).find('.radio:checked').length > 0 || $(this).find('.checkbox:checked').length > 0)
			{
				$submitButton.removeClass('inactive');	
			}
			else
			{
				$submitButton.addClass('inactive');	
			}
		}
	});
}

function validateRecommendName()
{
	if($("#recommendName").val().length >= 3)
	{	
		setInputErrorBackground($("#recommendName"), "remove");
		setLineValidity($("#validRecommendName"), true);
		$("#recommendPreviewName").html($("#recommendName").val());
		return true;
	}
	setLineValidity($("#validRecommendName"), false);
	setInputErrorBackground($("#recommendName"), "add");
	$("#recommendPreviewName").html("");	
	return false;
}

function validateRecommendEmail()
{
	if($("#recommendEmail").val().length >= 1)
	{
		if(validateRegExp($("#recommendEmail").val(), "email"))
		{
			setInputErrorBackground($("#recommendEmail"), "remove");
			setLineValidity($("#validRecommendEmail"), true);
			return true;		
		}
		else
		{
			setLineValidity($("#validRecommendEmail"), false);
			setInputErrorBackground($("#recommendEmail"), "add");
			$.validationEngine.buildPrompt("#recommendEmail", "Geben Sie bitte eine korrekte E-Mail-Adresse ein", "error");
			return false;
		}
	}
	else
	{
		setLineValidity($("#validRecommendEmail"), false);
		setInputErrorBackground($("#recommendEmail"), "add");
		return false;
	}
}

function validateRecommendAddresseeName()
{
	if($("#recommendAddresseeName").val().length >= 3)
	{	
		setInputErrorBackground($("#recommendAddresseeName"), "remove");
		setLineValidity($("#validRecommendAddresseeName"), true);
		$("#recommendPreviewAddresseeName").html($("#recommendAddresseeName").val());
		return true;
	}
	setLineValidity($("#validRecommendAddresseeName"), false);
	setInputErrorBackground($("#recommendAddresseeName"), "add");	
	$("#recommendPreviewAddresseeName").html("");
	return false;
}

function validateRecommendAddresseeEmail()
{
	if($("#recommendAddresseeEmail").val().length >= 1)
	{
		if(validateRegExp($("#recommendAddresseeEmail").val(), "email"))
		{
			setInputErrorBackground($("#recommendAddresseeEmail"), "remove");
			setLineValidity($("#validRecommendAddresseeEmail"), true);
			return true;		
		}
		else
		{
			setLineValidity($("#validRecommendAddresseeEmail"), false);
			setInputErrorBackground($("#recommendAddresseeEmail"), "add");
			$.validationEngine.buildPrompt("#recommendAddresseeEmail", "Geben Sie bitte eine korrekte E-Mail-Adresse ein", "error");
			return false;
		}
	}
	else
	{
		setLineValidity($("#validRecommendAddresseeEmail"), false);
		setInputErrorBackground($("#recommendAddresseeEmail"), "add");
		return false;
	}
}
	
function validateBelkawMeldungEMail()
{
	if($("#BelkawMeldungE-Mail").val().length >= 1)
	{
		if(validateRegExp($("#BelkawMeldungE-Mail").val(), "email"))
		{
			setInputErrorBackground($("#BelkawMeldungE-Mail"), "remove");
			setLineValidity($("#validBelkawMeldungE-Mail"), true);
			return true;		
		}
		else
		{
			setLineValidity($("#validBelkawMeldungE-Mail"), false);
			setInputErrorBackground($("#BelkawMeldungE-Mail"), "add");
			$.validationEngine.buildPrompt("#BelkawMeldungE-Mail", "Geben Sie bitte eine korrekte E-Mail-Adresse ein", "error");
			return false;
		}
	}
	else
	{
		setLineValidity($("#validBelkawMeldungE-Mail"), false);
		setInputErrorBackground($("#BelkawMeldungE-Mail"), "add");
		return false;
	}
}	

function validateBelkawMeldungName()
{	
	if($("#BelkawMeldungName").val().length >= 3)
	{	
		setInputErrorBackground($("#BelkawMeldungName"), "remove");
		setLineValidity($("#validBelkawMeldungName"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungName"), false);
	setInputErrorBackground($("#BelkawMeldungName"), "add");	
	return false;
}	

function validateBelkawMeldungBetreff()
{	
	if($("#BelkawMeldungBetreff").val().length >= 3)
	{	
		setInputErrorBackground($("#BelkawMeldungBetreff"), "remove");
		setLineValidity($("#validateBelkawMeldungBetreff"), true);
		return true;
	}
	setLineValidity($("#validateBelkawMeldungBetreff"), false);
	setInputErrorBackground($("#BelkawMeldungBetreff"), "add");	
	return false;
}
	
function validateBelkawMeldungVorname()
{	
	if($("#BelkawMeldungVorname").val().length >= 3)
	{	
		setInputErrorBackground($("#BelkawMeldungVorname"), "remove");
		setLineValidity($("#validBelkawMeldungVorname"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungVorname"), false);
	setInputErrorBackground($("#BelkawMeldungVorname"), "add");	
	return false;
}

function validateBelkawMeldungNachname()
{
	if($("#BelkawMeldungNachname").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungNachname"), "remove");
		setLineValidity($("#validBelkawMeldungNachname"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungNachname"), false);
	setInputErrorBackground($("#BelkawMeldungNachname"), "add");
	return false;
}

function validateBelkawMeldungGeburtsdatum()
{
	if(validateRegExp($("#BelkawMeldungGeburtsdatum").val(), "date"))
	{
		setInputErrorBackground($("#BelkawMeldungGeburtsdatum"), "remove");
		setLineValidity($("#validBelkawMeldungGeburtsdatum"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungGeburtsdatum"), false);
	setInputErrorBackground($("#BelkawMeldungGeburtsdatum"), "add");
	return false;
}

function validateBelkawMeldungAenderungsdatum()
{
	if(validateRegExp($("#BelkawMeldungAenderungsdatum").val(), "date"))
	{
		setInputErrorBackground($("#BelkawMeldungAenderungsdatum"), "remove");
		setLineValidity($("#validateBelkawMeldungAenderungsdatum"), true);
		return true;
	}
	setLineValidity($("#validateBelkawMeldungAenderungsdatum"), false);
	setInputErrorBackground($("#BelkawMeldungAenderungsdatum"), "add");
	return false;
}

function validateBelkawMeldungAblesedatum()
{
	if(validateRegExp($("#BelkawMeldungAblesedatum").val(), "date"))
	{
		setInputErrorBackground($("#BelkawMeldungAblesedatum"), "remove");
		setLineValidity($("#validateBelkawMeldungAblesedatum"), true);
		return true;
	}
	setLineValidity($("#validateBelkawMeldungAblesedatum"), false);
	setInputErrorBackground($("#BelkawMeldungAblesedatum"), "add");
	return false;
}

function validateBelkawMeldungAbschlagsbetrag()
{
	if(validateRegExp($("#BelkawMeldungAbschlagsbetrag").val(), "price") && $("#BelkawMeldungAbschlagsbetrag").val().length >= 2)
	{
		setInputErrorBackground($("#BelkawMeldungAbschlagsbetrag"), "remove");
		setLineValidity($("#validateBelkawMeldungAbschlagsbetrag"), true);
		return true;
	}
	setLineValidity($("#validateBelkawMeldungAbschlagsbetrag"), false);
	setInputErrorBackground($("#BelkawMeldungAbschlagsbetrag"), "add");
	return false;
}

function validateBelkawMeldungEinzugsdatum()
{
	if(validateRegExp($("#BelkawMeldungEinzugsdatum").val(), "date"))
	{
		setInputErrorBackground($("#BelkawMeldungEinzugsdatum"), "remove");
		setLineValidity($("#validBelkawMeldungEinzugsdatum"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungEinzugsdatum"), false);
	setInputErrorBackground($("#BelkawMeldungEinzugsdatum"), "add");
	return false;
}

function validateBelkawMeldungAuszugsdatum()
{
	if(validateRegExp($("#BelkawMeldungAuszugsdatum").val(), "date"))
	{
		setInputErrorBackground($("#BelkawMeldungAuszugsdatum"), "remove");
		setLineValidity($("#validBelkawMeldungAuszugsdatum"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAuszugsdatum"), false);
	setInputErrorBackground($("#BelkawMeldungAuszugsdatum"), "add");
	return false;
}

function validateBelkawMeldungPlz()
{
	if($("#BelkawMeldungPlz").val().length == 5)
	{
		setInputErrorBackground($("#BelkawMeldungPlz"), "remove");
		setLineValidity($("#BelkawMeldungOrt"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungOrt"), false);
	setInputErrorBackground($("#BelkawMeldungPlz"), "add");
	return false;
}

function validateBelkawMeldungOrt()
{
	if($("#BelkawMeldungOrt").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungOrt"), "remove");
		setLineValidity($("#validBelkawMeldungOrt"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungOrt"), false);
	setInputErrorBackground($("#BelkawMeldungOrt"), "add");
	return false;
}

function validateBelkawMeldungStrasse()
{
	if($("#BelkawMeldungStrasse").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungStrasse"), "remove");
		setLineValidity($("#BelkawMeldungHausnummer"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungHausnummer"), false);
	setInputErrorBackground($("#BelkawMeldungStrasse"), "add");
	return false;
}

function validateBelkawMeldungHausnummer()
{
	if($("#BelkawMeldungHausnummer").val().length >= 1)
	{
		setInputErrorBackground($("#BelkawMeldungHausnummer"), "remove");
		setLineValidity($("#validBelkawMeldungHausnummer"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungHausnummer"), false);
	setInputErrorBackground($("#BelkawMeldungHausnummer"), "add");
	return false;
}


function validateBelkawMeldungAbmeldeadresse_Auszugsdatum()
{
	if(validateRegExp($("#BelkawMeldungAbmeldeadresse_Auszugsdatum").val(), "date"))
	{
		setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Auszugsdatum"), "remove");
		setLineValidity($("#validBelkawMeldungAbmeldeadresse_Auszugsdatum"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbmeldeadresse_Auszugsdatum"), false);
	setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Auszugsdatum"), "add");
	return false;
}

function validateBelkawMeldungAbmeldeadresse_Plz()
{
	if($("#BelkawMeldungAbmeldeadresse_Plz").val().length == 5)
	{
		setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Plz"), "remove");
		setLineValidity($("#BelkawMeldungAbmeldeadresse_Ort"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbmeldeadresse_Ort"), false);
	setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Plz"), "add");
	return false;
}

function validateBelkawMeldungAbmeldeadresse_Ort()
{
	if($("#BelkawMeldungAbmeldeadresse_Ort").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Ort"), "remove");
		setLineValidity($("#validBelkawMeldungAbmeldeadresse_Ort"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbmeldeadresse_Ort"), false);
	setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Ort"), "add");
	return false;
}

function validateBelkawMeldungAbmeldeadresse_Strasse()
{
	if($("#BelkawMeldungAbmeldeadresse_Strasse").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Strasse"), "remove");
		setLineValidity($("#BelkawMeldungAbmeldeadresse_Hausnummer"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbmeldeadresse_Hausnummer"), false);
	setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Strasse"), "add");
	return false;
}

function validateBelkawMeldungAbmeldeadresse_Hausnummer()
{
	if($("#BelkawMeldungAbmeldeadresse_Hausnummer").val().length >= 1)
	{
		setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Hausnummer"), "remove");
		setLineValidity($("#validBelkawMeldungAbmeldeadresse_Hausnummer"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbmeldeadresse_Hausnummer"), false);
	setInputErrorBackground($("#BelkawMeldungAbmeldeadresse_Hausnummer"), "add");
	return false;
}

function validateBelkawMeldungAbschlussrechnung_Vorname()
{	
	if($("#BelkawMeldungAbschlussrechnung_Vorname").val().length >= 3)
	{	
		setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Vorname"), "remove");
		setLineValidity($("#validBelkawMeldungAbschlussrechnung_Vorname"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbschlussrechnung_Vorname"), false);
	setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Vorname"), "add");	
	return false;
}

function validateBelkawMeldungAbschlussrechnung_Nachname()
{
	if($("#BelkawMeldungAbschlussrechnung_Nachname").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Nachname"), "remove");
		setLineValidity($("#validBelkawMeldungAbschlussrechnung_Nachname"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbschlussrechnung_Nachname"), false);
	setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Nachname"), "add");
	return false;
}

function validateBelkawMeldungAbschlussrechnung_Plz()
{
	if($("#BelkawMeldungAbschlussrechnung_Plz").val().length == 5)
	{
		setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Plz"), "remove");
		setLineValidity($("#validBelkawMeldungAbschlussrechnung_Ort"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbschlussrechnung_Ort"), false);
	setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Plz"), "add");
	return false;
}

function validateBelkawMeldungAbschlussrechnung_Ort()
{
	if($("#BelkawMeldungAbschlussrechnung_Ort").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Ort"), "remove");
		setLineValidity($("#validBelkawMeldungAbschlussrechnung_Ort"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbschlussrechnung_Ort"), false);
	setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Ort"), "add");
	return false;
}

function validateBelkawMeldungAbschlussrechnung_Strasse()
{
	if($("#BelkawMeldungAbschlussrechnung_Strasse").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Strasse"), "remove");
		setLineValidity($("#validBelkawMeldungAbschlussrechnung_Hausnummer"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbschlussrechnung_Hausnummer"), false);
	setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Strasse"), "add");
	return false;
}

function validateBelkawMeldungAbschlussrechnung_Hausnummer()
{
	if($("#BelkawMeldungAbschlussrechnung_Hausnummer").val().length >= 1)
	{
		setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Hausnummer"), "remove");
		setLineValidity($("#validBelkawMeldungAbschlussrechnung_Hausnummer"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungAbschlussrechnung_Hausnummer"), false);
	setInputErrorBackground($("#BelkawMeldungAbschlussrechnung_Hausnummer"), "add");
	return false;
}

function validateBelkawMeldungKontonummer()
{
	if(validateRegExp($("#BelkawMeldungKontonummer").val(), "integer") && $("#BelkawMeldungKontonummer").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungKontonummer"), "remove");
		setLineValidity($("#validBelkawMeldungKontonummer"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungKontonummer"), false);
	setInputErrorBackground($("#BelkawMeldungKontonummer"), "add");
	return false;
}

function validateBelkawMeldungBankleitzahl()
{
	if(validateRegExp($("#BelkawMeldungBankleitzahl").val(), "integer") && $("#BelkawMeldungBankleitzahl").val().length >= 5)
	{
		setInputErrorBackground($("#BelkawMeldungBankleitzahl"), "remove");
		setLineValidity($("#validBelkawMeldungBankleitzahl"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungBankleitzahl"), false);
	setInputErrorBackground($("#BelkawMeldungBankleitzahl"), "add");
	return false;
}

function validateBelkawMeldungKontoinhaber()
{
	if($("#BelkawMeldungKontoinhaber").val().length >= 3)
	{
		setInputErrorBackground($("#BelkawMeldungKontoinhaber"), "remove");
		setLineValidity($("#validBelkawMeldungKontoinhaber"), true);
		return true;
	}
	setLineValidity($("#validBelkawMeldungKontoinhaber"), false);
	setInputErrorBackground($("#BelkawMeldungKontoinhaber"), "add");
	return false;
}



	
/* BOOKMARK */
function bookmark()
{
	var url = document.URL;
	var title = document.title;
	
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
		
	return false;
}	

/* PRINT */
function printPage()
{
	if($('.content_accordion').length)
	{
		$('.content_accordion').accordion("disable");
		$('.content_accordion .header').addClass('ui-state-active');
		$('.content_accordion .content').show();
		window.print();
		$('.content_accordion .content').hide();
		$('.content_accordion .header').removeClass('ui-state-active');
		$('.content_accordion').accordion("enable");
	}
	else if($('.content_accordion_big').length)
	{
		$('.content_accordion_big').accordion("disable");
		$('.content_accordion_big .header').addClass('ui-state-active');
		$('.content_accordion_big .content').show();
		window.print();
		$('.content_accordion_big .content').hide();
		$('.content_accordion_big .header').removeClass('ui-state-active');
		$('.content_accordion_big').accordion("enable");
	}
	else
	{
		window.print();
	}
}

/* JOBOFFERS PAGINATION */
function handlePaginationClick(new_page_index, pagination_container)
{
	var elPerPage = parseInt($(".boxcontainer .joboffers .offercount").html());
	$(".boxcontainer .joboffers div.offer").hide();
	var lastItem = new_page_index + 1;
	lastItem *= elPerPage;
	var firstItem = new_page_index * elPerPage;
	for (var i=firstItem; i<lastItem; i++)
	{
		$($(".boxcontainer .joboffers div.offer")[i]).show();
	}
	return false;
}

/* TABS */
$(function() {
	$(".content_tablist").tabs();
});

function resolution() 
{
	if ($.browser.msie)
		width = 1260;
	else
		width = 1264;
	
	if($(window).width() < width)
		$('body').addClass('smallRes');
	else
		$('body').removeClass('smallRes');
}

/* Converts a relative path to absolute */
function toAbs(link, host) {

	var lparts = link.split('/');
	if (/http:|https:|ftp:/.test(lparts[0]))
		return link;

	var i, hparts = host.split('/');
	if (hparts.length > 3)
		hparts.pop();

	if (lparts[0] === '')
	{
		host = hparts[0] + '//' + hparts[2];
		hparts = host.split('/');
		delete lparts[0];
	}

	for(i = 0; i < lparts.length; i++) 
	{
		if (lparts[i] === '..')
		{
			if (typeof lparts[i - 1] !== 'undefined')
			{
				delete lparts[i - 1];
			}
			else if (hparts.length > 3)
			{ 
				hparts.pop(); 
			}
			delete lparts[i];
		}
		if(lparts[i] === '.') 
		{
			delete lparts[i];
		}
	}

	var newlinkparts = [];
	for (i = 0; i < lparts.length; i++)
	{
		if (typeof lparts[i] !== 'undefined')
		{
			newlinkparts[newlinkparts.length] = lparts[i];
		}
	}
	
	return hparts.join('/') + '/' + newlinkparts.join('/');
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}

function registerHandler()
{
    /* LIGHTBOX DETAIL IMAGES */
    $('.inlineimage a').fancybox();
    
    $('.image a').fancybox();
	$('.view, .educationmaterial .teaserimage').fancybox();
                               
    /* LIGHTBOX */
    $('.lightbox').fancybox({
                                'type': 'iframe',
                                width: 2000,
                                height: 2000
                            });
							
	/* BILL EXPLANATION LIGHTBOX */
	$("#lightbox_billexplanation").fancybox({
												padding: 20
											});
                            
    /* LIGHTBOX CONTENT GALLERY */
    $('.content_gallery a.lightbox').fancybox();	
    $('.content_gallery a.lightbox_content').fancybox({
                                'type': 'iframe',
                                width: 2000,
                                height: 2000
                            });
							
	/* LIGHTBOX NEWS IMAGE */
    $('a.imagedownload').fancybox();	
                            
    /* CONTENT ACCORDION */
    $(".content_accordion").accordion('destroy').accordion({
                                        active: false,
                                        collapsible: true,
                                        autoHeight: false
                                      });
    
    $(".content_accordion").bind( "accordionchangestart", function(event, ui) {
        ui.oldHeader.removeClass('active');
        ui.newHeader.addClass('active');
        ui.newContent.removeClass('nomargin'); 
        ui.oldContent.addClass('nomargin'); 

    });	
    
    if($("#mediadownload .content_accordion .header").size() == 1)
        $("#mediadownload .content_accordion").accordion("activate", 0);
    
    /* CONTENT ACCORDION BIG */
    $(".content_accordion_big").accordion('destroy').accordion({
                                        header: '.header_big',
                                        collapsible: true,
                                        autoHeight: false
                                      });	
                                      
    $(".content_accordion_big").bind( "accordionchangestart", function(event, ui) {
        ui.oldHeader.removeClass('active');
        ui.newHeader.addClass('active');
    });	
	    
    /* GALLERY */
    $(".right_small_image_box .image_small").click(function() {
        $imageSrc = $(this).parent().find('.image_big').attr('src');
        $(".right_image_box img").attr('src', $imageSrc);
    });
           

}

/* DOCUMENT READY */
$(document).ready(function() {

	/* RESOLUTION */
	resolution();
	$(window).resize(function() {
		resolution();
	});

	/* STARTPAGE IMAGESWITCHER */
	if($.fn.imageSwitcher)
	{
		$("#imageswitcher").imageSwitcher();
	}
	
	/* CLEAR HTTPS-LINKS */
	if(window.location.pathname.indexOf("tarifberater") != -1)
	{
		$("a").not(".cancel, .button").each(function(i) {
			if($(this).attr("href"))
			{
				if(
					$(this).attr("href").indexOf("tarifberater") == -1 
					&& $(this).attr("href").indexOf("javascript:") == -1 
					&& $(this).attr("href").indexOf("mailto:") == -1
					&& $(this).attr("href") != "#"
				)
				{
					var href = toAbs($(this).attr("href"), self.location+"");
					$(this).attr("href", href.replace(/https:\/\//, "http://"));
				}
			}
		});
	}
    		
	/* REGISTER EVENTHANDLER */
	registerHandler();
		
	/* LIGHTBOX DVINCI */
	$('a.dvinci').fancybox({
								'hideOnOverlayClick':false,
								'hideOnContentClick':false,
								'enableEscapeButton':false,
								'type': 'iframe',
								width: 2000,
								height: 2000
							});

	/* HEADER ACCORDION */
	$('#accordion .header').click(function() {
		if(!$(this).next(".content").is(':visible'))
		{
			$('#accordion .active .content').hide('blind');
			$('#accordion .active').removeClass('active');
			$(this).parent().addClass('active');
			$(this).next(".content").show('blind');
			
			// Change image
			if($("#flashmovie").length == 0)
			{
				var $image = $(this).parent().find("img.hidden").attr("src");
				if($image != "" && $(".bannerPictureImg").attr("src") != $image)
				{
					$(".bannerPictureImg").hide("fade", {}, 200, function() {
						$(".bannerPictureImg").attr("src", $image);
						$(".bannerPictureImg").show("fade", {}, 200);					
					});	
				}
			}			
		}
		return false;
	});

	/* MENU ACCORDION 
	$(".menu_accordion").accordion({
										header: '.sidebarNavigation h2',
										active: '.sidebarNavigation .current',
										autoHeight: false
									  });
									  
	$(".menu_accordion").bind( "accordionchangestart", function(event, ui) {
		ui.oldHeader.removeClass('current');
		ui.oldHeader.parent().find('h3.current').removeClass('current');
		ui.newHeader.addClass('current');
	});	*/
	
	/* BILL EXPLANATION */
	$('#billpage_stage').html($('#billexplanation').find('.billpage').first().html()).find('.infobox').each(function() {
		$('#billexplanation .pages').find('.changepage').first().addClass('active');
		$(this).find('.info_icon').tinyTips($(this).find('.info_container').html());
	});

	/* BILL EXPLANATION PAGE CHANGER */
	$('#billexplanation .changepage').click(function(e) {
		var pageId = $(this).attr('id').split('_'); 
		pageId = pageId[1];
		
		$('#billpage_stage').html($('#billexplanation #page_'+pageId).html());

		$("#billpage_stage").find('.infobox').each(function() {
			$(this).find('.info_icon').tinyTips($(this).find('.info_container').html());
		});
		
		$('#billexplanation .pages').find('.changepage').removeClass('active');
		$(this).addClass('active');
		
		e.preventDefault();
	});
		
	/* NEWS IMAGE CAROUSELL */
	$(".content_newsdetail .imagecarousel").jCarouselLite({
		btnNext: ".content_newsdetail .next",
		btnPrev: ".content_newsdetail .prev",
		visible: 4
	});	
		
	/* PRODUCT FORM */
	var activeIndex = 0;
	if($(".productforms_accordeon").hasClass('closed'))
	{
		activeIndex = false;
		$(".productforms_accordeon .product_name").removeClass('product_active');
	}
	
	$(".productforms_accordeon").accordion({
									header: '.product_name',
									collapsible: true,
									autoHeight: false,
									active: activeIndex
								});
								
	$(".productforms_accordeon").bind( "accordionchangestart", function(event, ui) {
		ui.oldHeader.removeClass('product_active');
		ui.newHeader.addClass('product_active');
	});	
	
	validateProductform();
	
	$(".productforms .checkbox").change(function() {
		validateProductform();
	});
	
	$(".productforms .radio").change(function() {
		validateProductform();
		$(".productforms .radio").each(function(i) {
			$(this).siblings('label').removeClass('checked');
		});
		//$(".productforms .radio:checked").siblings('label').addClass('checked');
	});
	
	$(".product_current button").click(function() {
		$(".product_current").hide();
		$(".product_detailpage").show();
	});
	
	$(".productforms button").click(function(e) {
		if($(this).hasClass('inactive'))
			return false;
	});
	
	
	/* RECOMMEND */
	$("#recommend_link").click(function(e) {
		if($("#recommend_container").css('display') == "none")
		{
			$("#recommend_container").show();
		}
		else
		{
			$("#recommend_container").hide();
		}
		e.preventDefault();
	});
	
	$("#recommend_close").click(function(e) {
		$("#recommend_container").hide();
		e.preventDefault();
	});
							
	$('#recommend_container a.email').fancybox({
										'autoDimensions' : false,
										'padding' : 20,
										'width' : 510,
										'height' : 580,
										'scroll' : 'auto'
									});

	$('#recommend_container a').click(function(){
		$("#recommend_container").hide();								
	});									
									
	/*SITEMAP POSITIONING*/
	var wrap_pos = $("#divWrap").position();
	$("#sitemap").css('left', wrap_pos.left+'px');
	
	/*SITEMAP TOGGLE*/
	var closeTimer;
	var effectRuning = false;
	var sitemapShadowRight = $("#sitemap .sitemap_container").css('background-image');
	var sitemapShadowBottom = $("#sitemap .shadow_bottom").css('background-image');

	$("#sitemap_toggle").mouseover(function(){
		$("#sitemap, #sitemap .sitemap_container, #sitemap .bgcolor").css("height", $("#sitemap").height());
		
		if($("#sitemap").css("display") == "none" && !effectRuning)
		{
			$("#sitemap_toggle_link").addClass('active');
			effectRuning = true;
			$("#sitemap .sitemap_container").css('background-image', 'none');
			$("#sitemap .shadow_bottom").css('background-image', 'none');
			$("#sitemap").show("fade", {}, 200, function() {
				effectRuning = false;
				$("#sitemap .sitemap_container").css('background-image', sitemapShadowRight);
				$("#sitemap .shadow_bottom").css('background-image', sitemapShadowBottom);
			});	
		}

	});
	
	$("#sitemap_toggle").mouseout(function(){ 
		if($("#sitemap").css("display") == "block" && !effectRuning)
		{
			closeTimer = setTimeout(function(){
				effectRuning = true;
				$("#sitemap .sitemap_container").css('background-image', 'none');
				$("#sitemap .shadow_bottom").css('background-image', 'none');				
				$("#sitemap").hide("fade", {}, 200, function() {
					$("#sitemap_toggle_link").removeClass('active');
					effectRuning = false
				});	
			}, 200);
		}
	});

	$("#sitemap").mouseenter(function(){
		if($("#sitemap").css("display") == "block")
		{
			clearTimeout(closeTimer);
		}
	});
	
	$("#sitemap").mouseleave(function(){
		if($("#sitemap").css("display") == "block" && !effectRuning)
		{
			effectRuning = true;
			$("#sitemap .sitemap_container").css('background-image', 'none');
			$("#sitemap .shadow_bottom").css('background-image', 'none');
			$("#sitemap").hide("fade", {}, 200, function() {
				$("#sitemap_toggle_link").removeClass('active');
				effectRuning = false;
			});
		}
	});
	
	/*METANAVIGATION TOGGLE*/
	var metaShadowRight = $("#divHeaderSubNavigation .sitemap_container").css('background-image');
	var metaShadowBottom = $("#divHeaderSubNavigation .shadow_bottom").css('background-image');
	
	$("#divHeaderSubNavigation").css('left', (wrap_pos.left+393)+'px');
	
	$("#divHeaderNavigation a").mouseover(function(){
		$("#divHeaderSubNavigation").css("height", $("#divHeaderSubNavigation").height());
		$("#divHeaderSubNavigation .sitemap_container").css("height", $("#divHeaderSubNavigation").height());
		$("#divHeaderSubNavigation .bgcolor").css("height", $("#divHeaderSubNavigation").height());
		
		$(this).addClass('active');
		$("#divHeaderSubNavigation .sitemap_container").css('background-image', 'none');
		$("#divHeaderSubNavigation .shadow_bottom").css('background-image', 'none');
		if($("#divHeaderSubNavigation").css("display") == "none")
		{
			$("#divHeaderSubNavigation").show("fade", {}, 200, function() {
				$("#divHeaderSubNavigation .sitemap_container").css('background-image', metaShadowRight);
				$("#divHeaderSubNavigation .shadow_bottom").css('background-image', metaShadowBottom);
			});	
		}
	});

	$("#divHeaderSubNavigation").mouseleave(function(){
		$("#divHeaderSubNavigation .sitemap_container").css('background-image', 'none');
		$("#divHeaderSubNavigation .shadow_bottom").css('background-image', 'none');
		$(this).hide("fade", {}, 200, function() {
			$("#divHeaderNavigation a").removeClass('active');
		});	
	});
	
	$("#divHeaderNavigation a").mouseout(function(){
		$("#divHeaderSubNavigation").hide();
		$(this).removeClass('active');
	});
	
	$("#divHeaderSubNavigation").mouseenter(function(){
		$(this).show();	
		$("#divHeaderNavigation a").addClass('active');
	});

	/*CONTACT TOGGLE*/
	var contactShadowRight = $("#divHeaderSubContact .sitemap_container").css('background-image');
	var contactShadowBottom = $("#divHeaderSubContact .shadow_bottom").css('background-image');
	
	$("#divHeaderSubContact").css('left', (wrap_pos.left+487)+'px');
	
	$("#divHeaderContact a").mouseover(function(){
		$("#divHeaderSubContact").css("height", $("#divHeaderSubContact").height());
		$("#divHeaderSubContact .sitemap_container").css("height", $("#divHeaderSubContact").height());
		$("#divHeaderSubContact .bgcolor").css("height", $("#divHeaderSubContact").height());
	
		$(this).addClass('active');
		$("#divHeaderSubContact .sitemap_container").css('background-image', 'none');
		$("#divHeaderSubContact .shadow_bottom").css('background-image', 'none');
		if($("#divHeaderSubContact").css("display") == "none")
		{
			$("#divHeaderSubContact").show("fade", {}, 200, function() {
				$("#divHeaderSubContact .sitemap_container").css('background-image', contactShadowRight);
				$("#divHeaderSubContact .shadow_bottom").css('background-image', contactShadowBottom);
			});	
		}

	});

	$("#divHeaderSubContact").mouseleave(function(){
		$(this).hide("fade", {}, 200, function() {
			setTimeout(function() {
				$("#divHeaderContact a").removeClass('active');
				$("#divHeaderSubContact .sitemap_container").css('background-image', 'none');
				$("#divHeaderSubContact .shadow_bottom").css('background-image', 'none');
			}, 100);
		});	
	});
	
	$("#divHeaderContact a").mouseout(function(){
		$("#divHeaderSubContact").hide();
		$(this).removeClass('active');
	});
	
	$("#divHeaderSubContact").mouseenter(function(){
		$(this).show();	
		$("#divHeaderContact a").addClass('active');
	});
	
	/* DROPDOWN */	
	$("#contactBranche").msDropDown({showIcon:false});
	$("#contactSalutation").msDropDown({showIcon:false});
	$("#contactRequest").msDropDown({showIcon:false});
	$("#branche_select").msDropDown({showIcon:false});
	$("#branche_select_marginal").msDropDown({showIcon:false});
	$("#thema_select").msDropDown({showIcon:false});
	$("#changeYear").msDropDown({showIcon:false});
	
	/* CONTACT FORM VALIDATION */
	$("#contact").validationEngine({
		validationEventTriggers:"blur",
		inlineValidation: true
	});
	
	$("#contactBranche_child a").click(function() {
		if($(this).attr('id') == "contactBranche_msa_0")
		{
			$.validationEngine.buildPrompt("#contactBranche","Bitte w&auml;hlen Sie Ihre Branche","error");
			setLineValidity($("#validBranche"), false);
			setInputErrorBackground($("#contactBranche_msdd"), "add");	
		}
		else
		{
			$.validationEngine.closePrompt("#contactBranche");
			setInputErrorBackground($("#contactBranche_msdd"), "remove");
			setLineValidity($("#validBranche"), true);
		}
	});
	
	$("#contactSalutation_child a").click(function() {
		if($(this).attr('id') == "contactSalutation_msa_0")
		{
			$.validationEngine.buildPrompt("#contactSalutation","Bitte w&auml;hlen Sie eine Anrede","error");
			setLineValidity($("#validSalutation"), false);
			setInputErrorBackground($("#contactSalutation_msdd"), "add");	
		}
		else
		{
			$.validationEngine.closePrompt("#contactSalutation");
			setInputErrorBackground($("#contactSalutation_msdd"), "remove");
			setLineValidity($("#validSalutation"), true);
		}
	});
	
	$("#contactRequest_child a").click(function() {
		if($(this).attr('id') == "contactRequest_msa_0")
		{
			$.validationEngine.buildPrompt("#contactRequest","Bitte w&auml;hlen Sie Ihr Anliegen","error");
			setLineValidity($("#validRequest"), false);
			setInputErrorBackground($("#contactRequest_title"), "add");	
		}
		else
		{
			$.validationEngine.closePrompt("#contactRequest");
			setInputErrorBackground($("#contactRequest_title"), "remove");
			setLineValidity($("#validRequest"), true);
		}
	});
	
	/* EDUCATION MATERIAL FORM VALIDATION */
	$("#education").validationEngine({
		validationEventTriggers:"blur",
		inlineValidation: true
	});

	
	/* RECOMMEND FORM VALIDATION */
	$("#recommendform").validationEngine({
		validationEventTriggers:"blur",
		inlineValidation: true
	});

	/* MEDIA DOWNLOADS */
	$("#mediadownload #categoryselect").change(function() {
		if($("option:selected", this).val() != "")
			window.location.href = "?mediacat="+$("option:selected", this).val();
	});

	/* HEADER LINKLIST */
	$(".bannerText .select").click(function(e) {
		var id = $(this).attr('id').split("_");
		$("#headerbox_"+id[1]).show();	
	});
	
	$(".headerbox_close").click(function(e) {
		$(this).parent().hide();
	});
	
	/* NAVIGATION SELECT */
	$("#branche_select_child").click(function() {
		window.location.href = $("#branche_select option:selected").val();
	});
	
	$("#branche_select_marginal_child").click(function() {
		window.location.href = $("#branche_select_marginal option:selected").val();
	});
	
	$("#thema_select_child").click(function() {
		window.location.href = $("#thema_select option:selected").val();
	});
	
	/* JOBOFFERS PAGINATION */
	if ($('.boxcontainer .joboffers div.offer').size() > 0)
	{
		var elPerPage = parseInt($(".boxcontainer .joboffers .offercount").html());
		
		if($('.boxcontainer .joboffers div.offer').size() > elPerPage)
		{
			$('.boxcontainer .joboffers div.offer').hide();

			$(".boxcontainer .joboffers .pagination_container").pagination(
				$(".boxcontainer .joboffers div.offer").size(), {
					items_per_page: elPerPage,
					callback: handlePaginationClick,
					next_text: 'Vorw&auml;rts &raquo;',
					prev_text: '&laquo; Zur&uuml;ck'

				});
		}
		else
		{
			$(".boxcontainer .joboffers .pagination_container").hide();
		}
	}
	
	/* PRESS RELEASE BOX */
	$("#pressreadmore").click(function(e) {
		$(".pressrelease .readmore").hide();
		$(".pressrelease .closed").show();
		$(".pressrelease").parent().find('.rh_box','.rh_big_box').each(function(i) {
			if(!$(this).hasClass('pressrelease'))
				$(this).hide();
		});
		$(".pressrelease").addClass("open");
		e.preventDefault();
	});	
	
	$("#pressclose").click(function(e) {
		$(".pressrelease .close").hide();
		$(".pressrelease .closed").hide();
		$(".pressrelease .readmore").show();
		$(".pressrelease").parent().find('.rh_box','.rh_big_box').each(function(i) {
			if(!$(this).hasClass('pressrelease'))
				$(this).show();
		});
		$(".pressrelease").removeClass("open");
		e.preventDefault();
	});	
	
	/* SEARCH FIELD */
	$("#rh_fastsearch_field").focus(function() {
		if(jQuery.trim($(this).val()) == "Suchbegriff eingeben")
			$(this).val("");
	}).blur(function() {
		if(jQuery.trim($(this).val()) == "")
			$(this).val("Suchbegriff eingeben");		
	});
	
        
	/* ENERGIE DICTIONARY */
	$("#dictsearch").focus(function() {
		if(jQuery.trim($(this).val()) == "Schlagwort eingeben")
			$(this).val("");
	}).blur(function() {
		if(jQuery.trim($(this).val()) == "")
			$(this).val("Schlagwort eingeben");		
	});
	
	$("#energydictsearch").submit(function() {
		if(jQuery.trim($("#dictsearch").val()) == "Schlagwort eingeben")
			return false;
		return true;			
	});
	
	$.extend({
	  getUrlVars: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
		  hash = hashes[i].split('=');
		  vars.push(hash[0]);
		  vars[hash[0]] = hash[1];
		}
		return vars;
	  },
	  getUrlVar: function(name){
		return $.getUrlVars()[name];
	  }
	});
	
	$('#contactZip').keydown(function()
		{
			if($(this).val != $.getUrlVar('plz'))
			{
				$('#contactCity').val('')
			}
		}
	);
	
	
	/*** NOTFALLMELDUNG LIGHTBOX  ***/
		$('.notfallmeldung .button').click(
		function() {
			$.fancybox(
				$(this).parent('.notfallmeldung').find('.fulltext').html(), 
				{
					'autoDimensions'	: false,
					'width'         	: 760,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'
				}
			);
		}
	)
	
	/*** NEWS ARCHIV **/
	$("#changeYear_child a").click(function() {
		$(this).parents('form.year').submit();
	})

	/*******************************************************************/
	/**************************** BELKAW *******************************/
	/*******************************************************************/
	
	$("#BelkawMeldung").validationEngine({
		validationEventTriggers:"blur",
		inlineValidation: true
	});
	
	$('#BelkawMeldungEinzugsdatum, #BelkawMeldungAenderungsdatum, #BelkawMeldungAuszugsdatum, #BelkawMeldungNachmieterEinzugszugsdatum, #BelkawMeldungAbmeldeadresse_Auszugsdatum, #BelkawMeldungAblesedatum').datepicker(
	{
		showOn: "button",
		onClose: function(dateText, inst) { 
			var inputId = inst.id;
			var validateFunc = 'validate'+inputId;
			if(typeof window[validateFunc] == 'function')
			{
				window[validateFunc]();
			}
			$('.'+inputId+'formError').remove();
		}
	});
	
	/* CART EDUCATION MATERIAL */
	var EducationRequestURL = '/de/spezialseiten_1/unterrichtsmaterial.php';
	
	
	function EducationAddToBasket(elem)
	{
		var fs_id  	 	= elem.val();		
		var name  		= elem.next('label').text();
		var desc  	 	= elem.parent('li').find('div').text();
		
		/*
		if(elem.find('input.amount').length)		
			var copies 	 = parseInt(elem.find('input.amount').val());
		else
		
			var copies 	 = 1;
		
		if(!isNaN(copies) && !isNaN(maxCopies))
		{
		*/
			/*
			if(copies > maxCopies)
			{
				elem.find('input.amount').val(maxCopies);
				elem.find('.copyerror').text('Ihre Auswahl wurde auf '+maxCopies+' Exemplare korrigiert').show();
			}
			else
			{
				elem.find('.copyerror').hide();
			}
			*/
			$.post(EducationRequestURL, { 			
									 itemFsId: fs_id, 
									 itemTitle: name, 
									 itemDesc: desc,
									 action: 'addItem' }, 
				function(e, i) {
					$('#mediabasket .content').html(e);
					$('.warenkorb_container').removeClass('hidden');
					
					elem.attr('disabled','disabled')
						.next('label').append(' (Bereits im Warenkorb)')
						.parent('li')
						.addClass('disabled')
				} 
			);
		//}
	}
		
	
	$('.educationmaterial .removeFromBasket').click(function() {		
		var itemFsId = $(this).parent('.teaser').find('.fs_id').text();

		var elem = $(this).parent('.teaser');
		$.post(EducationRequestURL, { fs_id: itemFsId, action: 'delItem' }, function(e,i) {
			elem.hide("fade", {}, 200, function() {
				$(this).remove();
			});
			if(e == "0")
			{
				$('.warenkorb_container').addClass('hidden');
			}
		} );
			
		return false;
	});	
	
	$('.addToEducationBasket').click( 
		function() {
			$(this).parent('div').find('.educationitems li input:checked:not(:disabled)').each(
				function()
				{
					EducationAddToBasket($(this));
				}
			)		

			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 0}, 500 ,
				function() {
					$('#mediabasket').effect("highlight", { 'color' : '#F2CDD2'}, 1000);
				}
			);
			return false;
		}
	)
	
	
	/** Clear Formfields onfocus **/
	var clearPrevious = '';	
	$('.clearFocus').live('focus', function()
	{
		if($(this).val()==$(this).attr('title'))
		{
			clearMePrevious = $(this).val();
			$(this).val('');
		}
	});
	$('.clearFocus').live('blur', function()
	{
		if($(this).val()=='')
		{
			$(this).val(clearMePrevious);
		}
	});
			
	// jQuery UI-Datepicker Wrapper
    $("#ui-datepicker-div").wrap("<div class='ui_theme_smoothness' />");
	
});
