var errorList = new Array();
var errorListText = new Array();
	
function checkEmail(email)
	{if((email.indexOf(",")!=-1)||email==null||(email.indexOf("@")==-1)||(email.indexOf(".")==-1))
		return false;
	else 
		return true;
	}

function checkform_login_front()
	{ removeErrors();
	if (errorList.length!=0)
		{ errorList.length=0;
		errorListText.length=0
		}
	if (document.loginform.email.value=="")
		{ errorList.push("email_error");
		errorListText.push("Email:");
		}
	if (document.loginform.password.value=="")
		{ errorList.push("password_error");
		errorListText.push("Password:");
		}
	if (errorList.length==0)
		{this.document.loginform.submit();
		}
	else
		displayErrors();
	}

function checkform_login()
	{ removeErrors();
	if (errorList.length!=0)
		{ errorList.length=0;
		errorListText.length=0
		}
	if (document.loginform.email.value=="")
		{ errorList.push("email_error");
		errorListText.push("Email:");
		}
	if (document.loginform.password.value=="")
		{ errorList.push("password_error");
		errorListText.push("Password:");
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		document.loginform.submit();
		}
	else
		displayErrors();
	}
	
function checkform_contact()
	{ removeErrors();
	if (errorList.length!=0)
		{ errorList.length=0;
		errorListText.length=0
		}
	if (document.contact.sender_name.value=="")
		{ errorList.push("name_error");
		errorListText.push("Dit navn:");
		}
	if (document.contact.sender_email.value==""||checkEmail(document.contact.sender_email.value)==false)
		{ errorList.push("email_error");
		errorListText.push("Din emailadresse:");
		}
	if (document.contact.subject.value=="")
		{ errorList.push("subject_error");
		errorListText.push("Emne:");
		}
	if (document.contact.body.value=="")
		{ errorList.push("body_error");
		errorListText.push("Din besked:");
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.contact.submit();
		}
	else
		displayErrors();
	}
	
function checkform_exhange_has()
	{ removeErrors();
	if (errorList.length!=0)
		{ errorList.length=0;
		errorListText.length=0
		}
	if (document.exchange_has.header.value=="")
		{ errorList.push("header_error");
		errorListText.push("Overskrift til din annonce");
		}
	if (document.getElementById('hometype').selectedIndex==null||document.getElementById('hometype').selectedIndex==-1)
		{ errorList.push("hometype_error");
		errorListText.push("Hvilken boligtype har du?");
		}
	if (document.exchange_has.description.value=="")
		{ errorList.push("description_error");
		errorListText.push("Skriv lidt om den bolig, du tilbyder");
		}
	if (document.exchange_has.m2.value=="")
		{ errorList.push("m2_error");
		errorListText.push("Boligens areal");
		}
	if (document.getElementById('hometype').selectedIndex==null||document.getElementById('hometype').selectedIndex==-1)
		{ errorList.push("rooms_error");
		errorListText.push("Antal opholdsrum");
		}
	if (document.exchange_has.rooms.value=="")
		{ errorList.push("rooms_error");
		errorListText.push("Boligens areal");
		}
	if (document.getElementById('area').selectedIndex==null||document.getElementById('area').selectedIndex==-1)
		{ errorList.push("area_error");
		errorListText.push("Boligen ligger i følgende kommune");
		}
	if (document.exchange_has.price.value=="")
		{ errorList.push("price_error");
		errorListText.push("Pris for andelen");
		}
	if (document.exchange_has.rent.value=="")
		{ errorList.push("rent_error");
		errorListText.push("Månedlig ydelse til andelsboligforeningen");
		}
	if (document.exchange_has.costs.value=="")
		{ errorList.push("costs_error");
		errorListText.push("Omkostninger");
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.exchange_has.submit();
		}
	else
		displayErrors();
	}
	
function checkform_exhange_wanted()
	{ removeErrors();
	if (errorList.length!=0)
		{ errorList.length=0;
		errorListText.length=0
		}
	if (document.getElementById('hometypes_wanted').selectedIndex==null||document.getElementById('hometypes_wanted').selectedIndex==-1)
		{ errorList.push("hometype_error");
		errorListText.push("Hvilke boligtyper ønsker du at bytte til?");
		}
	if (document.exchange_wanted.description_wanted.value=="")
		{ errorList.push("description_error");
		errorListText.push("Skriv lidt om den bolig, du tilbyder");
		}
	if (document.exchange_wanted.m2_min.value==""||document.exchange_wanted.m2_max.value==""||document.exchange_wanted.m2_min.value==0||document.exchange_wanted.m2_max.value==0)
		{ errorList.push("m2_error");
		errorListText.push("Boligens areal");
		}
	if (document.getElementById('rooms_min').selectedIndex==null||document.getElementById('rooms_min').selectedIndex==-1||document.getElementById('rooms_max').selectedIndex==null||document.getElementById('rooms_max').selectedIndex==-1)
		{ errorList.push("rooms_error");
		errorListText.push("Antal opholdsrum");
		}
	if (document.getElementById('areas_wanted').selectedIndex==null||document.getElementById('areas_wanted').selectedIndex==-1)
		{ errorList.push("area_error");
		errorListText.push("Boligen skal ligge i følgende kommune(r)");
		}
	if (document.exchange_wanted.price_min.value==""||document.exchange_wanted.price_max.value=="")
		{ errorList.push("price_error");
		errorListText.push("Pris for andelen");
		}
	if (document.exchange_wanted.rent_min.value==""||document.exchange_wanted.rent_max.value==""||document.exchange_wanted.rent_min.value==0||document.exchange_wanted.rent_max.value==0)
		{ errorList.push("rent_error");
		errorListText.push("Månedlig ydelse til andelsboligforeningen");
		}
	if (document.exchange_wanted.costs_wanted.value==""||document.exchange_wanted.costs_wanted.value==0)
		{ errorList.push("costs_error");
		errorListText.push("Omkostninger");
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.exchange_wanted.submit();
		}
	else
		displayErrors();
	}
	
function checkform_buy()
	{ removeErrors();
	if (errorList.length!=0)
		{ errorList.length=0;
		errorListText.length=0
		}
	if (document.buy.header.value=="")
		{ errorList.push("header_error");
		errorListText.push("Overskrift til din annonce");
		}
	if (document.getElementById('hometypes_wanted').selectedIndex==null||document.getElementById('hometypes_wanted').selectedIndex==-1)
		{ errorList.push("hometype_error");
		errorListText.push("Hvilke boligtyper ønsker du at købe?");
		}
	if (document.buy.description.value=="")
		{ errorList.push("description_error");
		errorListText.push("Skriv lidt om den bolig, du tilbyder");
		}
	if (document.buy.m2_min.value==""||document.buy.m2_max.value==""||document.buy.m2_min.value==0||document.buy.m2_max.value==0)
		{ errorList.push("m2_error");
		errorListText.push("Boligens areal");
		}
	if (document.getElementById('rooms_min').selectedIndex==null||document.getElementById('rooms_min').selectedIndex==-1||document.getElementById('rooms_max').selectedIndex==null||document.getElementById('rooms_max').selectedIndex==-1)
		{ errorList.push("rooms_error");
		errorListText.push("Antal opholdsrum");
		}
	if (document.getElementById('areas_wanted').selectedIndex==null||document.getElementById('areas_wanted').selectedIndex==-1)
		{ errorList.push("area_error");
		errorListText.push("Boligen skal ligge i følgende kommune(r)");
		}
	if (document.buy.price_min.value==""||document.buy.price_max.value=="")
		{ errorList.push("price_error");
		errorListText.push("Pris for andelen");
		}
	if (document.buy.rent_min.value==""||document.buy.rent_max.value==""||document.buy.rent_min.value==0||document.buy.rent_max.value==0)
		{ errorList.push("rent_error");
		errorListText.push("Månedlig ydelse til andelsboligforeningen");
		}
	if (document.buy.costs.value==""||document.buy.costs.value==0)
		{ errorList.push("costs_error");
		errorListText.push("Omkostninger");
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.buy.submit();
		}
	else
		displayErrors();
	}
	
function checkform_sell()
	{ removeErrors();
	if (errorList.length!=0)
		{ errorList.length=0;
		errorListText.length=0
		}
	if (document.sell.header.value=="")
		{ errorList.push("header_error");
		errorListText.push("Overskrift til din annonce");
		}
	if (document.getElementById('hometype').selectedIndex==null||document.getElementById('hometype').selectedIndex==0||document.getElementById('hometype').selectedIndex==-1)
		{ errorList.push("hometype_error");
		errorListText.push("Hvilken boligtype ønsker du at sælge?");
		}
	if (document.sell.description.value=="")
		{ errorList.push("description_error");
		errorListText.push("Skriv lidt om den bolig, du tilbyder");
		}
	if (document.sell.m2.value=="")
		{ errorList.push("m2_error");
		errorListText.push("Boligens areal");
		}
	if (document.getElementById('rooms').selectedIndex==null||document.getElementById('rooms').selectedIndex==0||document.getElementById('rooms').selectedIndex==-1)
		{ errorList.push("rooms_error");
		errorListText.push("Antal opholdsrum");
		}
	if (document.sell.rooms.value=="")
		{ errorList.push("rooms_error");
		errorListText.push("Boligens areal");
		}
	if (document.getElementById('area').selectedIndex==null||document.getElementById('area').selectedIndex==-1)
		{ errorList.push("area_error");
		errorListText.push("Boligen ligger i følgende kommune");
		}
	if (document.sell.price.value=="")
		{ errorList.push("price_error");
		errorListText.push("Pris for andelen");
		}
	if (document.sell.rent.value=="")
		{ errorList.push("rent_error");
		errorListText.push("Månedlig ydelse til andelsboligforeningen");
		}
	if (document.sell.costs.value=="")
		{ errorList.push("costs_error");
		errorListText.push("Omkostninger");
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.sell.submit();
		}
	else
		displayErrors();
	}
	
function checkform_add_user()
	{ removeErrors();
	if (document.add_user.firstname.value=="")
		{ errorList.push("firstname_error");
		errorListText.push("Dit fornavn:");
		}
	if (document.add_user.surname.value=="")
		{ errorList.push("surname_error");
		errorListText.push("Dit efternavn:");
		}
	if (document.add_user.email.value==""||checkEmail(document.add_user.email.value)==false)
		{ errorList.push("email_error");
		errorListText.push("Din email:");
		}
	if (document.add_user.password.value=="")
		{ errorList.push("password_error");
		errorListText.push("Dit ønskede password:");
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.add_user.submit();
		}
	else
		displayErrors();
	}

function displayErrors()
	{ var i=0;
	while (i!=errorList.length)
		{ document.getElementById(errorList[i]).innerHTML="<font style='color: #FF0000\; font-weight: bold\;'>" + errorListText[i] + "</font>";
		i++;
		}
	var fieldNo = null;
	if (errorList.length==1)
		fieldNo = "felt";
	if (errorList.length>1)
		fieldNo = "felter";
	document.getElementById('general_error').innerHTML="<font style='color: #FF0000\; font-weight: bold\;'>Denne formular er ikke klar til afsendelse, da " + errorList.length + " "+ fieldNo +" ikke er udfyldt korrekt.</font>";
	}

function removeErrors()
	{ var i=0;
	while (i!=errorList.length)
		{ document.getElementById(errorList[i]).innerHTML="<font style='color: #000000\; font-weight: normal\;'>" + errorListText[i] + "</font>";
		i++;
		}
	document.getElementById('general_error').innerHTML="";
		errorList=new Array();
		errorListText=new Array();
	}

//function removeErrors()
//	{var i = 0;
//	var div_array = document.getElementsByTagName("div");
//	while (i!=div_array.length)
//		{ //document.getElementById(div_array[i].id).innerHTML.style="color: #000000\; font-weight: bold\;";
//		alert(div_array[i].value);
//		i++;
//		}
//	}
