

var strPat = /^\w[\w\.\-]*@\w[\w\-\.]*\.\w{2}[\w\.\-\/]*$/i;

function validate_contact(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.name.value == "") {
		varAlert = varAlert + "- Name\n";
		send = false;
	}

	if (!strPat.test(frm.email.value) ) {
		varAlert = varAlert + "- Email\n";
		send = false;
	}
	
	if (frm.comments.value == "") {
		varAlert = varAlert + "- Comments\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}

function validate_contact_class(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.name.value == "") {
		varAlert = varAlert + "- Name\n";
		send = false;
	}

	if (!strPat.test(frm.email.value) ) {
		varAlert = varAlert + "- Email\n";
		send = false;
	}
	
	if (frm.message.value == "") {
		varAlert = varAlert + "- Comments\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}


function validate_recommend(frm) {
	var send,varAlert;
	varAlert = "";

	if (!strPat.test(frm.from_email.value) ) {
		varAlert = varAlert + "- Your email\n";
		send = false;
	}
	
	if (!strPat.test(frm.recipient_email.value) ) {
		varAlert = varAlert + "- Friends email\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		frm.submit();
        return false;
        //return true;
	}
}



function validate_newsletter(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.name.value == "") {
		varAlert = varAlert + "- Name\n";
		send = false;
	}

	if (!strPat.test(frm.email.value) ) {
		varAlert = varAlert + "- Email\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}



function validate_guestbook(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.name.value == "") {
		varAlert = varAlert + "- Name\n";
		send = false;
	}
	
	if (frm.message.value == "") {
		varAlert = varAlert + "- Comments\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}



function validate_password(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.password.value == "") {
		varAlert = varAlert + "- Password\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}



function validate_login(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.username.value == "") {
		varAlert = varAlert + "- Username\n";
		send = false;
	}

	if (frm.password.value == "") {
		varAlert = varAlert + "- Password\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}




function validate_orderinfo(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.name.value == "") {
		varAlert = varAlert + "- Name\n";
		send = false;
	}
	
	if (frm.address1.value == "") {
		varAlert = varAlert + "- Address\n";
		send = false;
	}
	
	if (frm.zipcode.value == "") {
		varAlert = varAlert + "- Zipcode\n";
		send = false;
	}
	
	if (frm.city.value == "") {
		varAlert = varAlert + "- City\n";
		send = false;
	}
	
	if (frm.phone.value == "") {
		varAlert = varAlert + "- Phone\n";
		send = false;
	}
	
	if (!strPat.test(frm.email.value) ) {
		varAlert = varAlert + "- Email\n";
		send = false;
	}
	
	if (!frm.acceptTerms.checked) {
		varAlert += "- Please accept this shops conditions\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}


function showHideLayer(layer) {
	if (document.getElementById(layer).style.display == "none")
	    document.getElementById(layer).style.display = "block";
	else
	    document.getElementById(layer).style.display = "none";
}

function Toggle(element) {
	curImg = document.getElementById(element).src
	if (curImg.match("_on.") == "_on.") {
		document.getElementById(element).src = curImg.replace(/_on./i,"_off.")
	}
	else {
		document.getElementById(element).src = curImg.replace(/_off./i,"_on.")
	}
}

function clear_sessions() {
  document.writeln('<iframe src=/includes/modules/abandon.asp frameborder="0" height=0 width=0></iframe>');
}



function validate_profile_new(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.name.value == "") {
		varAlert = varAlert + "- Name\n";
		send = false;
	}
	
	if (frm.username.value == "") {
		varAlert = varAlert + "- E-mail address\n";
		send = false;
	}

	if (frm.password.value == "") {
		varAlert = varAlert + "- Password\n";
		send = false;
	}

	if (frm.title.value == "") {
		varAlert = varAlert + "- Title\n";
		send = false;
	}

	if (frm.country.value == "") {
		varAlert = varAlert + "- Country\n";
		send = false;

	} else {

		if (frm.country.value == 0) {
			if (frm.alternativeCountry.value == "") {
				varAlert = varAlert + "- Country\n";
				send = false;
			}
		}

	}

	if (frm.city.value == "" && frm.alternativeCity.value == "") {
		varAlert = varAlert + "- City\n";
		send = false;

	} else {

		if (frm.city.value == 0) {
			if (frm.alternativeCity.value == "") {
				varAlert = varAlert + "- City\n";
				send = false;
			}
		}

	}

	if (frm.school.value == "" && frm.alternativeSchool.value == "") {
		varAlert = varAlert + "- School\n";
		send = false;

	} else {

		if (frm.school.value == 0) {
			if (frm.alternativeSchool.value == "") {
				varAlert = varAlert + "- School\n";
				send = false;
			}
		}

	}

	if (frm.schoolclass.value == "") {
		varAlert = varAlert + "- Class\n";
		send = false;
	}

	if (!frm.conditions.checked) {
		varAlert = varAlert + "- Accept conditions\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}


function validate_profile_change(frm) {
	var send,varAlert;
	varAlert = "";

	if (frm.name.value == "") {
		varAlert = varAlert + "- Name\n";
		send = false;
	}
	
	if (frm.username.value == "") {
		varAlert = varAlert + "- E-mail address\n";
		send = false;
	}

	if (frm.password.value == "") {
		varAlert = varAlert + "- Password\n";
		send = false;
	}

	if (frm.title.value == "") {
		varAlert = varAlert + "- Title\n";
		send = false;
	}

	if (frm.schoolid.value == 0) {
		varAlert = varAlert + "- School\n";
		send = false;
	}

	if (frm.schoolclass.value == "") {
		varAlert = varAlert + "- Class\n";
		send = false;
	}
	
	if (send == false) { 
		alert("Please fill out the fields below:\n\n" + varAlert);
		return false;
	}
	else {
		return true;
	}
}



function retrieveCities(id) {
  if (id.value=='0') {

	document.getElementById('showAlternativeCountry').style.display='block';
	document.getElementById('showAlternativeCity').style.display='block';
	document.getElementById('showAlternativeSchool').style.display='block';

	document.f0.city.options[0].selected=true;
	document.f0.city.disabled=true;

	document.f0.school.options[0].selected=true;
	document.f0.school.disabled=true;

  } else {
	document.getElementById('showAlternativeCountry').style.display='none';
	document.getElementById('showAlternativeCity').style.display='none';
	document.getElementById('showAlternativeSchool').style.display='none';

	xmlHttpObject=GetXmlHttpObject()
	// Browseren understøtter ikke  AJAX
	if (xmlHttpObject == null) {return;}
	// Send forespørgsel
	var getUrl = "/includes/modules/ajax_get_cities.asp?countryId=" + id.value;
	xmlHttpObject.onreadystatechange = readyStateChangedCities;
	xmlHttpObject.open("GET", getUrl, true);
	xmlHttpObject.send(null);
  }
}

function retrieveSchools(id) {
  if (id.value=='0') {

	document.getElementById('showAlternativeCity').style.display='block';
	document.getElementById('showAlternativeSchool').style.display='block';

	document.f0.school.options[0].selected=true;
	document.f0.school.disabled=true;

  } else {
	document.getElementById('showAlternativeCity').style.display='none';
	document.getElementById('showAlternativeSchool').style.display='none';
	xmlHttpObject=GetXmlHttpObject()
	// Browseren understøtter ikke  AJAX
	if (xmlHttpObject == null) {return;}
	// Send forespørgsel
	var getUrl = "/includes/modules/ajax_get_schools.asp?cityId=" + id.value;
	xmlHttpObject.onreadystatechange = readyStateChangedSchools;
	xmlHttpObject.open("GET", getUrl, true);
	xmlHttpObject.send(null);
  }
}

function checkSchools(id) {
  if (id.value=='0') {
	document.getElementById('showAlternativeSchool').style.display='block';

  } else {
	document.getElementById('showAlternativeSchool').style.display='none';
  }
}

function readyStateChangedCities()
{
  if (xmlHttpObject.readyState==4) {
    result = xmlHttpObject.responseText;  // get results

    eval(result)						  // make js results available in this script
	
	arr_cities = js_cities.split(";")
	arr_cityIDs = js_cityIDs.split(";")
	
	// delete all current options - except first empty option
	i_cities = document.getElementById("city").length

	for (i=2; i<i_cities; i++) {
		document.f0.city.options[2] = null;
	}

	i_schools = document.getElementById("school").length
   	for (i=2; i<i_schools; i++) {
		document.f0.school.options[2] = null;
	}
   
	// create new options
	for (i=0; i<arr_cities.length-1; i++) {
	  appendOption('city',arr_cities[i],arr_cityIDs[i]);
	}

	appendOption('city','','');
    appendOption('city','Click here if your city is NOT listed','0');
    
	// enable/disable element
	if (document.f0.country.value != '') {
		document.f0.city.disabled=false;
	} else {
		document.f0.city.disabled=true;
	}

	document.f0.school.disabled=true;
	
  }
}

function readyStateChangedSchools()
{
  if (xmlHttpObject.readyState==4) {
    result = xmlHttpObject.responseText;  // get results
    eval(result)						  // make js results available in this script
	
	arr_schools = js_schools.split(";")
	arr_schoolIDs = js_schoolIDs.split(";")
	
	// delete all current options - except first empty option
	i_schools = document.getElementById("school").length

	for (i=2; i<i_schools; i++) {
		document.f0.school.options[2] = null;
	}
   
	// create new options
	for (i=0; i<arr_schools.length-1; i++) {
	  appendOption('school',arr_schools[i],arr_schoolIDs[i]);
	}

	appendOption('school','','');
    appendOption('school','Click here if your school is NOT listed','0');
    
	// enable/disable element
	if (document.f0.city.value != '') {
		document.f0.school.disabled=false;
	} else {
		document.f0.school.disabled=true;
	}
	
  }
}


function appendOption(element,value,id) {
  var elOptNew = document.createElement('option');
  elOptNew.text = value;
  elOptNew.value = id;
  var elSel = document.getElementById(element);

  try {
    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
  }
  catch(ex) {
    elSel.add(elOptNew); // IE only
  }
}

function GetXmlHttpObject() {
  var xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttpObject = new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
  try
  {
    xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e)
  {
    xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
  }
}
  return xmlHttpObject;
}

function mm_showMenu(menuName) // , alwaysVisState = optional. 1=on, 0=off 
{ 
  var menuNum = getMenuByName(menuName); 
  if (arguments.length > 1)_m[menuNum][7] = arguments[1]; 
  menuDisplay(menuNum, 1); 
} 

function mm_hideMenu(menuName) // , alwaysVisState = optional. 1=on, 0=off 
{ 
  var menuNum = getMenuByName(menuName); 
  if (arguments.length > 1)_m[menuNum][7] = arguments[1]; 
  menuDisplay(menuNum, 0); 
}