function createCookie(strName, strValue, intTimtToLive) {
	var a = new Date();
	a = new Date(a.getTime() + intTimtToLive);
	document.cookie = strName + '=' + w + '; expires=' + a.toGMTString() + ';';
}

function readCookie(strName) {
	a = document.cookie;
	res = '';
	while(a != '') {
		cookieName = a.substring(0, a.search('='));
		cookieValue = a.substring(a.search('=')+1, a.search(';'));
		if(cookieValue == '') {
			cookieValue = a.substring(a.search('=')+1, a.length);
		}
		if(strName == cookieName){
			res = cookieValue;
		}
		i = a.search(';') + 1;
	  	if(i == 0){
	  		i = a.length;
	  	}
		a = a.substring(i, a.length);
	}
	return(res);
}

function getStyle(){
	if(document.cookie){
		strStyle = readCookie('style');
		if(strStyle != '') {
			b = text.replace('%1', strStyle);
		}
	} else{
		//writeStyle();
	}
}

function getElement(strElementID) {
	return document.getElementById(strElementID);
}

function emptyStringValue(strValue) {
	if(strValue == ''){
		return true;
	} else if(strValue == null) {
		return true;
	} else {
		return false;
	}
}

function mailAddressOk(strMail) {
	if (strMail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true;
	} else {
		return false;
	}
}

function chkFrm(){
	var arrObjects = new Array('inputname', 'inputemail', 'inputmessage');
	var bolFormOk = true;
	for(i=0;i<arrObjects.length;i++) {
		if(emptyStringValue(getElement(arrObjects[i]).value)) {
			bolFormOk = false;getElement('lab_'+arrObjects[i]).className = 'inputError';
		} else {
			getElement('lab_'+arrObjects[i]).className = 'inputName';
		}
	}
	if(!mailAddressOk(getElement('inputemail').value)) {
		bolFormOk = false;getElement('lab_inputemail').className = 'inputError';
	}
	if(!bolFormOk) {
		getElement('lab_formerror').style.visibility = 'visible';
	} else {
		getElement('lab_formerror').style.visibility = 'hidden';
	}
	return bolFormOk;
}

function mailSent() {
	var strUrl = window.location.href;
	var arrParts = strUrl.split("?");
	if (arrParts.length > 1) {
		return true;
	}
	return false;
}

function deaktivateForm(){
	if(mailSent()){
		var arrObjects = new Array('inputname', 'inputemail', 'send');
		for(i=0;i<arrObjects.length;i++) {
			getElement(arrObjects[i]).disabled = true;
		}
		getElement('inputmessage').value = 'Vielen Dank für Ihre Nachricht.\n\nIhre Anfrage wurde erfolgreich weitergeleitet.';
		getElement('inputmessage').style.color = 'red';
		getElement('inputmessage').readOnly = true;
	}
}

