var errorList = new Array();
var errorListText = new Array();
	
function checkEmail(email)
	{ /* var email_split = email.split(" ");
	if (email_split.length!=1)
		{ return false;
		} */
	if (email==null || email.indexOf(",")!=-1 || email.indexOf(" ")!=-1 || email.indexOf("@")==-1 || email.indexOf(".")==-1)
		return false;
	else 
		return true;
	}

function checkform_login()
	{ removeErrors();
	if (errorList.length!=0)
		{ errorList.length=0;
		errorListText.length=0
		}
	if (document.loginform.email.value=="" || checkEmail(document.loginform.email.value)==false)
		{ 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_add_user()
	{ removeErrors();
	if (document.add_user.firstname.value=="")
		{ errorList.push("firstname_error");
		errorListText.push("Dit fornavn:");
		}
	if (document.add_user.lastname.value=="")
		{ errorList.push("lastname_error");
		errorListText.push("Dit efternavn:");
		}
	if (document.add_user.address.value=="")
		{ errorList.push("address_error");
		errorListText.push("Din adresse:");
		}
	if (document.add_user.password.value=="")
		{ errorList.push("zipcode_error");
		errorListText.push("Postnummer:");
		}
	if (document.add_user.conditions.checked==false)
		{ errorList.push("city_error");
		errorListText.push('By:');
		}
	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 (document.add_user.conditions.checked==false)
		{ errorList.push("conditions_error");
		errorListText.push('Jeg har læst og accepterer <a class="warning" href="http://www.lejenlejlighed.dk/betingelser.php">betingelserne</a>');
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.add_user.submit();
		}
	else
		displayErrors();
	}
	
function checkform_update_address()
	{ removeErrors();
	if (document.update_address.address.value=="")
		{ errorList.push("address_error");
		errorListText.push("Din adresse:");
		}
	if (document.update_address.zipcode.value=="")
		{ errorList.push("zipcode_error");
		errorListText.push("Postnummer:");
		}
	if (document.update_address.city.value=="")
		{ errorList.push("city_error");
		errorListText.push('By:');
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.update_address.submit();
		}
	else
		displayErrors();
	}
	
function checkform_add_invoice()
	{ removeErrors();
	if (document.add_invoice.conditions.checked==false)
		{ errorList.push("conditions_error");
		errorListText.push('Jeg har læst og accepterer <a class="warning" href="http://www.lejenlejlighed.dk/betingelser.php">betingelserne</a>');
		}
	if (errorList.length==0)
		{ document.getElementById('general_error').innerHTML="";
		this.document.add_invoice.submit();
		}
	else
		displayErrors();
	}
	
function checkform_add_address()
	{ removeErrors();
	if (document.add_address.address.value=="")
		{ errorList.push("address_error");
		errorListText.push("Adresse:");
		}
	if (document.add_address.zipcode.value=="")
		{ errorList.push("zipcode_error");
		errorListText.push("Postnummer:");
		}
	if (document.add_address.city.value=="")
		{ errorList.push("city_error");
		errorListText.push("By:");
		}
	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 showAddress(first, last)
    { var at = String.fromCharCode(64);
    this.document.location="mailto:"+first+at+last;
    } 
