function changeElementAttributeById(id, attribute, content){	
	document.getElementById(id).setAttribute(attribute,content);	
}

function checkSpecialCharacter(input){
	return input.match(/^[a-zA-Z0-9äÄöÖüÜß]*$/) ? true : false;
}

function checkSpecialCharacterExt(input){
	return input.match(/^[a-zA-Z0-9äÄöÖüÜß#="\(\)\!\/\.\?\[\]\{\}\$%&\*\+\s]*$/) ? true : false;
}

function checkLength(input){
	return (input.length<8) ? true : false;	
}

function checkEmail(input){
	return input.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/) ? true : false;
}

function isWhiteSpace(value){
	if(value.replace(/\s+/,'')==''){
		return true;
	}			
	return false;

}

function submitform(){

	if(checkForm())
		document.forms[0].submit();
	
}


function error(msg){
	alert(msg);
}

function checkForm(){
	var form = this.document.forms[0];
	var msg = 'Bitte das rot markierte Textfeld ausfüllen!';
	for(i = 0;i<form.elements.length;i++){	
		var element = form.elements[i];
		switch(element.name){
			case 'name' :
				if(element.value==''){
					changeElementAttributeById('name', 'style', 'color:red;');
					element.focus();
					error(msg);					
					return false;
				}				
			break;
			case 'email' :
				if(element.value==''){
					changeElementAttributeById('email', 'style', 'color:red;');
					error(msg);	
					return false;
				}else{
					changeElementAttributeById('email', 'style', 'color:black;');
					if(!checkEmail(element.value)){
						changeElementAttributeById('email', 'style', 'color:red;');
						element.focus();
						error('Your email must formally be valid, i.e. should look like: example@example.com!');
						return false;
					}
					
				}

			break;		
			default:
			break;	 

		}
		

	}
	return true;
	//
	
}


var http = null;
if (window.XMLHttpRequest) {
   http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
   http = new ActiveXObject("Microsoft.XMLHTTP");
}

function productsdisplay(nr,lang,filename,elementID){
	
	if (http != null) {
			
		   http.open('GET', 'products.php?p='+filename+'&lang='+lang+'&n='+nr, true);
		   http.onreadystatechange = ausgeben(elementID);
		   http.send(null);
	}

	
}

function ausgeben(elementID) {
   if (http.readyState == 4) {
	   alert(elementID);	  
	   document.getElementById(elementID).innerHTML = http.responseText;
   }
}

function show(filename, elementID){
	document.getElementById(elementID).innerHTML = '<img name="img_to_replace" src="">';
	var img_to_replace = new Image();
	img_to_replace.src = filename;
	document.images['img_to_replace'].src = img_to_replace.src;
	
	
}

function changeColor(dest_elementID,href_elementID, elementID_label, flag){
	if(flag==0){

		document.getElementById(elementID_label).style.color = "white";
		document.getElementById(dest_elementID).style.color = "";
		document.getElementById(href_elementID).href = "javascript:changeColor('"+dest_elementID+"','"+href_elementID+"','"+elementID_label+"',1);";

	}else{
		
		document.getElementById(elementID_label).style.color = "black";
		document.getElementById(dest_elementID).style.color = "white";		
		document.getElementById(href_elementID).href = "javascript:changeColor('"+dest_elementID+"','"+href_elementID+"','"+elementID_label+"',0);";
	
	}
	
	
}

function changeColorLabel(elementID, color_label){	
		document.getElementById(elementID).style.color = "";
		document.getElementById(elementID).style.color = color_label;	
}




