// JavaScript Document

var linktabcolor = "#0A406F"; //initilize color string for tabs
var name = ""; //initialize string for hide and unhide

var alltags = new Array();

function getElementByClass(theClass) {

	//Create Array of All HTML Tags
	var alltags = document.getElementsByTagName("*");
	
	//Loop through all tags using a for loop
	for (i=0; i<alltags.length; i++) {
	
		//Get all tags with the specified class name.
		if (alltags[i].className==theClass) {
		
			//Place any code you want to apply to all
			//pages with the class specified.
			//In this example is to “display:none;” them
			//Making them all dissapear on the page.
			
			alltags[i].style.backgroundColor=linktabcolor;
		
		}
	}
}

function hideme(layer_ref,layer_ref2,layer_ref3){
	if(!layer_ref){ // used as initiation and error clearing.
		var names = new Array("home","about","area","other","info","contact");
		for(i=0; i < names.length; i++){
			document.getElementById(names[i]+"_links").style.display="none";
			document.getElementById(names[i]+"_yHL").style.display="none";
		}
		getElementByClass('link_tabs');
	}
	else{
		document.getElementById(layer_ref).style.display="none";
		document.getElementById(layer_ref2).style.backgroundColor="";
		document.getElementById(layer_ref3).style.display="none";
	}
}

function unhideme(layer_ref,layer_ref2,layer_ref3){
	if((layer_ref != "home_links") && (layer_ref != "contact_links")){ // exceptions
		document.getElementById(layer_ref).style.display="";
	}
	document.getElementById(layer_ref2).style.backgroundColor=linktabcolor;
	document.getElementById(layer_ref3).style.display="";
}

function hide(name){ //hide function simplified
	hideme(name+"_links",name+"_main", name+"_yHL");
}

function unhide(name){ //unhide function simplified
	unhideme(name+"_links",name+"_main", name+"_yHL");
}

function pplshow(obj){
	var ppl = new Array("p1","p2","p3","p4","p5","p6");
	for (i=0; i < ppl.length; i++){
		if(ppl[i] == obj){
			document.getElementById(ppl[i]).style.display="";
		}
		else{
			document.getElementById(ppl[i]).style.display="none";
		}
	}
}

function validate_required(field)
{
	with (field){
	if (value==null||value==""){
		return false;
	}
	else{
		return true;
	}
	}
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	 if (str.indexOf(" ")!=-1){
		return false
	 }
	 return true					
}

function validate_form(thisform)
{
	with (thisform){
	  if (validate_required(full_name)==false){
		alert("Full Name is missing.\n请填入姓名。");
		full_name.focus();
		return false;
	  }
	  if (validate_required(email)==false || !echeck(email.value)){
		alert("Email is incorrect.\n电子邮箱不正确。");
		email.focus();
		return false;
	  }
	  if (validate_required(phone)==false && validate_required(mobile)==false ){
		alert("Must fill in either a Phone or Mobile Number.\n请填入电话或者手机号码。");
		phone.focus();
		return false;
	  }
	  if (validate_required(country)==false){
		alert("Country is not selected.\n没有选择居住地点。");
		country.focus();
		return false;
	  }
	}
}
