//获取对象y坐标
function getY(e)
{
 var   obj   =   e; 
 var   getTop   =   obj.offsetTop;
 while(obj   =   obj.offsetParent) 
 {
    getTop   +=   obj.offsetTop;  
 }
 return getTop;
}
//获取对象x坐标
function getX(e)
{
 var   obj   =   e; 
 var   getLeft   =   obj.offsetLeft; 
 while(obj   =   obj.offsetParent) 
 {
    getLeft   +=   obj.offsetLeft; 
 }
 return getLeft;
}
function $id(id)
{
	return document.getElementById(id);
}
//---navigation
function show(){
    $id('navigation').style.left=getX($id('Image22'))+3+"px";
	$id('navigation').style.top=getY($id('Image22'))+65+"px";
	$id('navigation').style.display="block";
}
function hidden(){
    $id('navigation').style.display="none";
}
//--
//--image change
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//--
//--check login form
function trim(s)
{
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function isNotEmpty(e)
{
	str = trim(e.value);
	var reg = /./;
	if (str.match(reg))
	{
		return true;
	}
	else
	{
		e.select();
		return false;
	}
}
function checklogin(f){
	 if (!isNotEmpty(f.username1))
	  {
		alert('Please enter your user name!');
		return false;
	  }
	  else  if (!isNotEmpty(f.username2))
	  {
		alert('Please enter your user name!');
		return false;
	  }
	  else  if (!isNotEmpty(f.password))
	  {
		alert('Please enter your password!');
		return false;
	  }
	  else  if (!isNotEmpty(f.picture))
	  {
		alert('Please enter Characters!');
		return false;
	  } 
}
function checkregister(f){
	 if (f.company.value=="")
	  {
		alert('Please enter your company!');
		return false;
	  }
	 else if (!isNotEmpty(f.companyid))
	  {
		alert('Please enter your ID!');
		return false;
	  }
	  if(f.company.selectedIndex==1){//aon
	  	  if(!isNotEmpty(f.companyid1)){
			  alert('Please enter your right ID1!');
			  return false;
		  }
		  if(!isNotEmpty(f.companyid2)){
			  alert('Please enter your right ID2!');
			  return false;
		  }
		  f.companyid.value=f.companyid1.value+"-"+f.companyid2.value;		  
		  if(f.companyid.value.toLowerCase() =="aon-p044600" ||  f.companyid.value.toLowerCase() =="aon-k044300" || f.companyid.value.toLowerCase() =="aon-b149300" || f.companyid.value.toLowerCase() =="aon-r363800" || f.companyid.value.toLowerCase() =="aon-c295100" || f.companyid.value.toLowerCase() =="aon-a599900" || f.companyid.value.toLowerCase() =="aon-a058800" || f.companyid.value.toLowerCase() =="aon-m173300" || f.companyid.value.toLowerCase() =="aon-h284200" || f.companyid.value.toLowerCase() =="aon-s130100" || f.companyid.value.toLowerCase() =="aon-h552500" || f.companyid.value.toLowerCase() =="aon-acr2001" || f.companyid.value.toLowerCase() =="aon-acr2002" || f.companyid.value.toLowerCase() =="aon-acr2003" || f.companyid.value.toLowerCase() =="aon-acr2004" || f.companyid.value.toLowerCase() =="aon-acr2005" || f.companyid.value.toLowerCase() =="aon-acr2006" || f.companyid.value.toLowerCase() =="aon-acr2007" || f.companyid.value.toLowerCase() =="aon-b120600" || f.companyid.value.toLowerCase() =="aon-p507000" || f.companyid.value.toLowerCase() =="aon-f042700" || f.companyid.value.toLowerCase() =="aon-f472800" || f.companyid.value.toLowerCase() =="aon-i507100" || f.companyid.value.toLowerCase() =="aon-r073900" || f.companyid.value.toLowerCase() =="aon-r140100" || f.companyid.value.toLowerCase() =="aon-w612200" || f.companyid.value.toLowerCase() =="aon-u776500" || f.companyid.value.toLowerCase() =="aon-w169700" || f.companyid.value.toLowerCase() =="aon-t524200" || f.companyid.value.toLowerCase() =="aon-h536400" || f.companyid.value.toLowerCase() =="aon-h807200" || f.companyid.value.toLowerCase() =="aon-r871600" || f.companyid.value.toLowerCase() =="aon-s241600" || f.companyid.value.toLowerCase() =="aon-c889700" || f.companyid.value.toLowerCase() =="aon-f046600" || f.companyid.value.toLowerCase() =="aon-f047500" || f.companyid.value.toLowerCase() =="aon-h176200" || f.companyid.value.toLowerCase() =="aon-n128700" || f.companyid.value.toLowerCase() =="aon-h848100" || f.companyid.value.toLowerCase() =="aon-a666000" || f.companyid.value.toLowerCase() =="aon-r868900" || f.companyid.value.toLowerCase() =="aon-m051200" || f.companyid.value.toLowerCase() =="aon-h200100" || f.companyid.value.toLowerCase() =="aon-h914100" || f.companyid.value.toLowerCase() =="aon-m136200" || f.companyid.value.toLowerCase() =="aon-m136100" || f.companyid.value.toLowerCase() =="aon-m136300" || f.companyid.value.toLowerCase() =="aon-h246800" || f.companyid.value.toLowerCase() =="aon-s883700" || f.companyid.value.toLowerCase() =="aon-a812400" || f.companyid.value.toLowerCase() =="aon-b046400" || f.companyid.value.toLowerCase() =="aon-c590100" || f.companyid.value.toLowerCase() =="aon-g185300" || f.companyid.value.toLowerCase() =="aon-e024800" || f.companyid.value.toLowerCase() =="aon-d765300" || f.companyid.value.toLowerCase() =="aon-d052000" || f.companyid.value.toLowerCase() =="aon-d892400" || f.companyid.value.toLowerCase() =="aon-g483600" || f.companyid.value.toLowerCase() =="aon-h240200" || f.companyid.value.toLowerCase() =="aon-m893800" || f.companyid.value.toLowerCase() =="aon-p605700" || f.companyid.value.toLowerCase() =="aon-p051900" || f.companyid.value.toLowerCase() =="aon-w957600"){
			 
		  }else{
		 	 alert('Please enter your right ID!');
			 return false;
		  }
	  }else if(f.company.selectedIndex==2){//bupa
		  var pattern = /^\d{8}-\d{8}$/;
		  flag = pattern.test(f.companyid.value);
		  if(flag !== true){
			 alert('Please enter your right ID!');
			 return false;
		  }
	  }else if(f.company.selectedIndex==3){//CPAL
	       if(f.cardtype.selectedIndex==0){//员工卡
			  var pattern = /^\d{6}[a-zA-Z]$/;
			  flag = pattern.test(f.companyid.value);
			  if(flag !== true){
				 alert('Please enter your right employee reference No.!');
				 return false;
			  }
		  }
		   if(f.cardtype.selectedIndex==1){//员工家属
			  var pattern = /^\d{7}[a-zA-Z]$/;
			  flag = pattern.test(f.companyid.value);
			  if(flag !== true){
				 alert('Please enter your right dependent No.!');
				 return false;
			  }
		  }
	  }else if(f.company.selectedIndex==4){//JSA
		  var pattern = /^\d{2}-\d{5}-\d{4}$/;
		  flag = pattern.test(f.companyid.value);
		  if(flag !== true){
			 alert('Please enter your right ID!');
			 return false;
		  }
	  }

}
//--picturen
function refurbish(){ 
    var img = document.getElementById("varImg"); 
    img.src = "authimg.php?" + Math.random(); 
} 
//
function SelectCompany(){	
	if($id("company").selectedIndex==1){
		$id("CompanyInfo").innerHTML='<div id="holderDiv"><div class="title">Aon Registration Code</div><div class="input"><input name="companyid1" type="text" id="companyid1" size="5" value="Aon"/> - <input name="companyid2" type="text" id="companyid2" size="10" /><input name="companyid" type="hidden" id="companyid" value="0"/></div></div>';
	}else if($id("company").selectedIndex==2){
		$id("CompanyInfo").innerHTML='<div id="holderDiv"><div class="title">Bupa membership No.</div><div class="input"><input name="companyid" type="text" id="companyid" size="35" /></div></div>';
	}else if($id("company").selectedIndex==3){
		$id("CompanyInfo").innerHTML='<div class="input"><select name="cardtype" id="cardtype" onchange="SelectCardtype()"><option value="國泰員工">CX Staff</option><option value="員工家屬">CX Staff Dependant</option></select></div><div id="holderDiv"><div class="title">ERN (Employee Reference No.)</div><div class="input"><input name="companyid" type="text" id="companyid" size="35" /></div></div>';
	}else if($id("company").selectedIndex==4){
		$id("CompanyInfo").innerHTML='<div class="title">JSA ID</div><div class="input"><input name="companyid" type="text" id="companyid" size="35" /></div><div class="title">Relationship to JSA Principal cardholder <span class="hs">(If applicants are family members)</span></div><div class="input"><input name="companyholder" type="text" id="companyholder" size="35" /></div>';
	}else if($id("company").selectedIndex==0){
		$id("CompanyInfo").innerHTML='';
	}	
}

function SelectCardtype(){
	if($id("cardtype").selectedIndex==1){
		$id("holderDiv").innerHTML='<div class="title">Dependent No.</div><div class="input"><input name="companyid" type="text" id="companyid" size="35" /></div><div class="title">Relationship to CX Staff</div><div class="input"><input name="companyholder" type="text" id="companyholder" size="35" /></div>';
	}else{
		$id("holderDiv").innerHTML='<div class="title">ERN (Employee Reference No.)</div><div class="input"><input name="companyid" type="text" id="companyid" size="35" /></div>';
	}
}