﻿//set css style for menu
function showBorderServer(){
var ta=document.getElementById('serverA');ta.className='borderMenuServer ';
}
function hideBorderServer(){
var ta=document.getElementById('serverA');ta.className='';
}
function showBorderAbout(){
var ta=document.getElementById('aboutA');ta.className='borderMenuAbout ';
}
function hideBorderAbout(){
var ta=document.getElementById('aboutA');ta.className='';
}
function showBorderJob(){
var ta=document.getElementById('jobA');ta.className='borderMenuJob ';
}
function hideBorderJob(){
var ta=document.getElementById('jobA');ta.className='';
}
//function for document
document.onclick =onBodyClick;

//关闭AccountLoginForm

function onBodyClick() 
{ 
if(canClose){
//MM_showHideLayers('accountLoginFrom','','hide');
$('#accountLoginFrom2k8').fadeOut('3000');
}
} 
var canClose=true;
var tipId;
var timeC=0;
function enterLoginForm(){
canClose=false;
window.clearInterval(tipId);
}
function outLoginForm(){
canClose=true;
tipId=window.setInterval("delayClose()",500); 
}
function delayClose(){
timeC=timeC+1;
if(canClose && timeC==4){
timeC=0;
window.clearInterval(tipId);
//MM_showHideLayers('accountLoginFrom','','hide');
$('#accountLoginFrom2k8').fadeOut('3000');
}
}

//act for document onload
$(document).ready(
    function() {
	if (get_cookie("taiAutoLogin")==1){
try{document.forms[0].Username.value=get_cookie("ailogin");
document.forms[0].Password.value=get_cookie("aipswd") ;
document.forms[0].autologin.checked=true;
}
catch(e3){}
}
		
    }
);


function newXMLHttpRequest() {
 var XMLHttpReq = false;
  if (window.XMLHttpRequest) {
     XMLHttpReq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
      try {
        XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
      }
    }
  }
  return XMLHttpReq;
}
  function HiddenSelect(){var allselect = gname("select");for (var i=0; i<allselect.length; i++) allselect[i].style.visibility = "hidden";}
   function ShowSelect(){var allselect = gname("select");for (var i=0; i<allselect.length; i++)  allselect[i].style.visibility = "visible";}
   
  function ScreenConvert(){var browser = new Browser();var objScreen = gid("ScreenOver");if(!objScreen) var objScreen = document.createElement("div");var oS = objScreen.style;objScreen.id = "ScreenOver";oS.display = "block";oS.top = oS.left = oS.margin = oS.padding = "0px";if (document.body.clientHeight)	{var wh = document.body.clientHeight + "px";}else if (window.innerHeight){var wh = window.innerHeight + "px";}else{var wh = "100%";}oS.width = "102%";oS.height = "200%";oS.position = "absolute";oS.zIndex = "30";if ((!browser.isSF) && (!browser.isOP)){oS.background = "#000000";}else{oS.background = "#000000";}oS.filter = "alpha(opacity=75)";oS.opacity = 75/100;oS.MozOpacity = 75/100;document.body.appendChild(objScreen);var allselect = gname("select");for (var i=0; i<allselect.length; i++) allselect[i].style.visibility = "hidden";}
function ScreenClean(){var objScreen = document.getElementById("ScreenOver");if (objScreen) objScreen.style.display = "none";var allselect = gname("select");for (var i=0; i<allselect.length; i++) allselect[i].style.visibility = "visible";}
function gid(id){return document.getElementById?document.getElementById(id):null;}
function gna(id){return document.getElementsByName?document.getElementsByName(id):null;}
function gname(name){return document.getElementsByTagName?document.getElementsByTagName(name):new Array()}
var t_DiglogX,t_DiglogY,t_DiglogW,t_DiglogH;
function DialogLoc(){var dde = document.documentElement;if (window.innerWidth){var ww = window.innerWidth;var wh = window.innerHeight;var bgX = window.pageXOffset;var bgY = window.pageYOffset;}else{var ww = dde.offsetWidth;var wh = dde.offsetHeight;var bgX = dde.scrollLeft;var bgY = dde.scrollTop;}t_DiglogX = (bgX + ((ww - t_DiglogW)/2));t_DiglogY = (bgY + ((wh - t_DiglogH)/2));}
function DialogShow(showdata,ow,oh,w,h){
	var objDialog = document.getElementById("DialogMove");
	if (!objDialog) objDialog = document.createElement("div");
	t_DiglogW = ow;
	t_DiglogH = oh;
	DialogLoc();
	objDialog.id = "DialogMove";
	var oS = objDialog.style;
	oS.display = "block";
	oS.top = t_DiglogY + "px";oS.left = t_DiglogX + "px";oS.margin = "0px";oS.padding = "0px";oS.width = w + "px";oS.height = h + "px";oS.position = "absolute";oS.zIndex = "31";oS.background = "#FFF";oS.border = "solid #000 3px";
        objDialog.innerHTML = showdata;document.body.appendChild(objDialog);}
function DialogHide(){ScreenClean();var objDialog = document.getElementById("DialogMove");if (objDialog) objDialog.style.display = "none";}
function Browser(){var ua, s, i;this.isIE = false;this.isNS = false;this.isOP = false;this.isSF = false;ua = navigator.userAgent.toLowerCase();s = "opera";if ((i = ua.indexOf(s)) >= 0){this.isOP = true;return;}s = "msie";if ((i = ua.indexOf(s)) >= 0) {this.isIE = true;return;}s = "netscape6/";if ((i = ua.indexOf(s)) >= 0) {this.isNS = true;return;}s = "gecko";if ((i = ua.indexOf(s)) >= 0) {this.isNS = true;return;}s = "safari";if ((i = ua.indexOf(s)) >= 0) {this.isSF = true;return;}}


function searchform(e,lang) {
	if (lang!="" && lang!="undefined")
	{
		window.location="/qi/aiweb.nsf/2008SearchResult_"+lang+"?openform&"+document.getElementById('searchfld').value;
	}else{
  		window.location="/qi/aiweb.nsf/2008SearchResult?openform&"+document.getElementById('searchfld').value;
	}
}

function login(ln){
	//nom=window.document.forms[0].Username.value;
	//pas=window.document.forms[0].Password.value;
	nom=changeIt($("#Username").val());
	pas=changeIt($("#Password").val());
	if (get_cookie("taiAutoLogin")==1) 
	{
		var expdate = new Date();
		expdate.setTime (expdate.getTime() +	31536000000);
		SetCookie ("ailogin",nom,expdate, "/");
		SetCookie ("aipswd",pas,expdate, "/");
	}	
	var msg;
	if (ln=="en")
	{
		msg="Login or/and Password are empty.";
	}
	switch(ln)
	{
	case "fr":
	msg="Login / Password sont vides.";
	break;
	case "sp":
	msg="Login / Password son vacias.";
	break;
	case "it":
	msg="Login  / Password sono vuote.";
	break;
	case "ge":
	msg="Login / Password sind leer.";
	break;
	case "cn":
	msg="登录名或密码为空.";
	break;
	default:
	msg="Login or/and Password are empty.";
	break;
	}
	if (nom=="" || pas=="")
	{alert(msg);
return;
}
	else{
        url1="/QI/AIWeb.nsf/(TrackLogin)?OpenAgent&UserName="+nom+"&Password="+pas+"&Website=AsiaInspection";
        url2="/QI/AIWeb.nsf/AuthTest";
        //window.location=url1;
        /*
        $.post(url2,{l:nom,p:pas},function(data){
        	if(data.replace(/[\r\n]/g,"")=="ok"){
        		window.location=url1;
        	} else {
        		alert("Wrong login or password");
        	}
        });
        */
        
        var strdata=nom+"&"+pas
        
      $.ajax({
				type: "POST",
				url: "/QI/AIWeb.nsf/AuthTest",
				async: "false",
				data: strdata,
				success: function(msg){
					
					if ($.trim(msg.toLowerCase())=="ok"){
						window.location=url1;
					}else{
						alert("Wrong login or password");
					}
				}
			});		

}
 }
function forgotpwd() {
var tUrl="/QI/AIWeb.nsf/2008mForgotPwd?OpenForm&KeepThis=true&TB_iframe=true&modal=true&height=200&width=450";
//openWindowB(url,'400','150','Forgot your login / password ?', 'no');
//GB_showCenter("Forgot your login / password ?",url,180,420);
fillContainer(tUrl);
}


function popupJobDetail(strid) {
var tUrl="/QI/AIJOB.nsf/vWebJobOfferByIds/" + strid + "?OpenDocument&KeepThis=true&TB_iframe=true&modal=true&height=600&width=700";
//openWindowB(url,'400','150','Forgot your login / password ?', 'no');
//GB_showCenter("Forgot your login / password ?",url,180,420);
fillContainer(tUrl);
}


function fillContainer(arg){
	$("#containerclick").attr("href",arg);
	$("#containerclick").click();
}
//common js

//function for menu downlist
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//-----------Select the country area phone---------------

var CodeArray = new Array();

function CountrySelection( obj)
	{
		CodeArray[0]='';
CodeArray[1]='93';
CodeArray[2]='355';
CodeArray[3]='213';
CodeArray[4]='376';
CodeArray[5]='244';
CodeArray[6]='1264';
CodeArray[7]='54';
CodeArray[8]='374';
CodeArray[9]='297';
CodeArray[10]='61';
CodeArray[11]='43';
CodeArray[12]='994';
CodeArray[13]='973';
CodeArray[14]='880';
CodeArray[15]='375';
CodeArray[16]='32';
CodeArray[17]='501';
CodeArray[18]='229';
CodeArray[19]='1441';
CodeArray[20]='975';
CodeArray[21]='591';
CodeArray[22]='387';
CodeArray[23]='267';
CodeArray[24]='55';
CodeArray[25]='1284';
CodeArray[26]='673';
CodeArray[27]='359';
CodeArray[28]='226';
CodeArray[29]='257';
CodeArray[30]='855';
CodeArray[31]='237';
CodeArray[32]='001';
CodeArray[33]='238';
CodeArray[34]='1345';
CodeArray[35]='236';
CodeArray[36]='235';
CodeArray[37]='56';
CodeArray[38]='86';
CodeArray[39]='57';
CodeArray[40]='269';
CodeArray[41]='242';
CodeArray[42]='682';
CodeArray[43]='506';
CodeArray[44]='385';
CodeArray[45]='53';
CodeArray[46]='357';
CodeArray[47]='420';
CodeArray[48]='243';
CodeArray[49]='45';
CodeArray[50]='246';
CodeArray[51]='253';
CodeArray[52]='1809';
CodeArray[53]='593';
CodeArray[54]='20';
CodeArray[55]='503';
CodeArray[56]='240';
CodeArray[57]='291';
CodeArray[58]='372';
CodeArray[59]='251';
CodeArray[60]='691';
CodeArray[61]='500';
CodeArray[62]='298';
CodeArray[63]='679';
CodeArray[64]='358';
CodeArray[65]='33';
CodeArray[66]='689';
CodeArray[67]='241';
CodeArray[68]='220';
CodeArray[69]='995';
CodeArray[70]='49';
CodeArray[71]='233';
CodeArray[72]='350';
CodeArray[73]='30';
CodeArray[74]='299';
CodeArray[75]='590';
CodeArray[76]='502';
CodeArray[77]='594';
CodeArray[78]='224';
CodeArray[79]='245';
CodeArray[80]='592';
CodeArray[81]='509';
CodeArray[82]='504';
CodeArray[83]='852';
CodeArray[84]='36';
CodeArray[85]='354';
CodeArray[86]='91';
CodeArray[87]='62';
CodeArray[88]='98';
CodeArray[89]='964';
CodeArray[90]='353';
CodeArray[91]='972';
CodeArray[92]='39';
CodeArray[93]='225';
CodeArray[94]='1876';
CodeArray[95]='81';
CodeArray[96]='962';
CodeArray[97]='7';
CodeArray[98]='254';
CodeArray[99]='686';
CodeArray[100]='850';
CodeArray[101]='82';
CodeArray[102]='965';
CodeArray[103]='996';
CodeArray[104]='856';
CodeArray[105]='371';
CodeArray[106]='961';
CodeArray[107]='266';
CodeArray[108]='231';
CodeArray[109]='218';
CodeArray[110]='423';
CodeArray[111]='370';
CodeArray[112]='352';
CodeArray[113]='853';
CodeArray[114]='389';
CodeArray[115]='261';
CodeArray[116]='265';
CodeArray[117]='60';
CodeArray[118]='960';
CodeArray[119]='223';
CodeArray[120]='356';
CodeArray[121]='692';
CodeArray[122]='596';
CodeArray[123]='222';
CodeArray[124]='230';
CodeArray[125]='52';
CodeArray[126]='373';
CodeArray[127]='377';
CodeArray[128]='976';
CodeArray[129]='382';
CodeArray[130]='1664';
CodeArray[131]='212';
CodeArray[132]='258';
CodeArray[133]='95';
CodeArray[134]='264';
CodeArray[135]='674';
CodeArray[136]='977';
CodeArray[137]='31';
CodeArray[138]='599';
CodeArray[139]='687';
CodeArray[140]='64';
CodeArray[141]='505';
CodeArray[142]='227';
CodeArray[143]='234';
CodeArray[144]='683';
CodeArray[145]='47';
CodeArray[146]='968';
CodeArray[147]='92';
CodeArray[148]='680';
CodeArray[149]='970';
CodeArray[150]='507';
CodeArray[151]='675';
CodeArray[152]='595';
CodeArray[153]='51';
CodeArray[154]='63';
CodeArray[155]='48';
CodeArray[156]='351';
CodeArray[157]='1809';
CodeArray[158]='974';
CodeArray[159]='995';
CodeArray[160]='40';
CodeArray[161]='7';
CodeArray[162]='250';
CodeArray[163]='290';
CodeArray[164]='378';
CodeArray[165]='239';
CodeArray[166]='966';
CodeArray[167]='221';
CodeArray[168]='381';
CodeArray[169]='248';
CodeArray[170]='232';
CodeArray[171]='65';
CodeArray[172]='421';
CodeArray[173]='386';
CodeArray[174]='677';
CodeArray[175]='252';
CodeArray[176]='27';
CodeArray[177]='34';
CodeArray[178]='94';
CodeArray[179]='508';
CodeArray[180]='249';
CodeArray[181]='597';
CodeArray[182]='268';
CodeArray[183]='46';
CodeArray[184]='41';
CodeArray[185]='963';
CodeArray[186]='886';
CodeArray[187]='992';
CodeArray[188]='255';
CodeArray[189]='66';
CodeArray[190]='670';
CodeArray[191]='228';
CodeArray[192]='690';
CodeArray[193]='676';
CodeArray[194]='1809';
CodeArray[195]='216';
CodeArray[196]='90';
CodeArray[197]='993';
CodeArray[198]='1649';
CodeArray[199]='688';
CodeArray[200]='256';
CodeArray[201]='380';
CodeArray[202]='971';
CodeArray[203]='44';
CodeArray[204]='1';
CodeArray[205]='1340';
CodeArray[206]='598';
CodeArray[207]='998';
CodeArray[208]='678';
CodeArray[209]='39';
CodeArray[210]='58';
CodeArray[211]='84';
CodeArray[212]='681';
CodeArray[213]='685';
CodeArray[214]='967';
CodeArray[215]='260';
CodeArray[216]='263';	

	var objTemp=document.getElementById("Temp");
	var strTel=CodeArray[obj.selectedIndex];
	
	if (strTel!=""){
		strTel="+ " + strTel;	
	}

	objTemp.value=strTel;	
	setValue(CodeArray[obj.selectedIndex]);
	
	var strS=obj.options[obj.selectedIndex].text;
	//alert(strS);
	if (strS=="Turkey" ||strS=="Thailand" ||strS=="Sri Lanka" ||strS=="Singapore" ||strS=="Philippines" || strS=="Pakistan" ||strS=="Nepal" || strS=="Myanmar (Burma)" || strS=="Malaysia" || strS=="Laos" || strS=="Cambodia" || strS=="Bangladesh" || strS=="China" || strS=="Taiwan. Province Of China" || strS=="India" || strS=="Indonesia" || strS=="Korea (South)" || strS=="Korea (North)"||strS=="Viet Nam"){
		document.getElementById("IsSupplier").style.display = "";
	}else{
		document.getElementById("IsSupplier").style.display = "none";}
	}
	
function setValue(strTel){
var objTel=document.getElementById("TelNum");
var objFax=document.getElementById("MobileNum");

	if (strTel!=""){
		strTel="+ " + strTel;	
	}

	//isEmpty of telphone field
	if (objTel.value==""){
		objTel.value=strTel;
		objTel.text=strTel;
	}else{
		if (objTel.value.indexOf("+")==-1){
			//has input value
			objTel.value=strTel+objTel.value;
			objTel.text+=strTel+objTel.value;}
		else{
			objTel.value=strTel;
			objTel.text=strTel;	}
	}

	//isEmpty of FaxNumber field
	if (objFax.value==""){
		objFax.value=strTel;
		objFax.text=strTel;
		}
	else{
		if (objFax.value.indexOf("+")==-1){
			//has input value
			objFax.value=strTel+objFax.value;
			objFax.text+=strTel+objFax.value;}
		else{
			objFax.value=strTel;
			objFax.text=strTel;	}
	}	
}
//--------------------end select country area phone----------


function getLong(str){
	  var valueLen = 0;
	  if (str != "")
		{
	    for (i = 0; i < str.length; i ++)
		{
	      var code = escape(str.charAt(i));
	      if ((code.length >= 4) && (code < '%uFF60' || code > '%uFF9F'))
		{
	        valueLen += 2;
	      }
	else
		{
	        valueLen ++;
	      }
	    }
	  }
	 return valueLen;
	}

function checkLoginKey(evt){
 evt = (evt) ? evt : (window.event) ? event : null;
  if (evt)
  {
    var charCode = (evt.charCode) ? evt.charCode :((evt.keyCode) ? evt.keyCode :((evt.which) ? evt.which : 0));
    if (charCode == 13) {
	    login();
    	return false;
    }
  }
}
function addtoFav(){
if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
   //firefox
    {
        window.sidebar.addPanel('AsiaInspection - Your Eyes in the Factory','http://www.asiainspection.com',"");
    }
    else//IE
    {
	window.external.addFavorite('http://www.asiainspection.com','AsiaInspection - Your Eyes in the Factory');
    }
}
 function openDemo(el){
   state='toolbar=none,scrollbar=none,location=none,left=0,top=0,width=810,height=570';
   window.open("/qi/aiweb.nsf/2k8Demo?openForm&lang="+el,"Demo",state);
 }
 function sendsample(){
	url='/QI/AIWeb.nsf/2008popupWhereToSendSamples?Openpage'
	//fillContainer(url+'&height=529&width=700&KeepThis=true&TB_iframe=true&modal=true');
	//fillContainer(url+'&height=529&width=740&KeepThis=true&TB_iframe=true&modal=true');
	fillContainer(url+'&height=540&width=780&KeepThis=true&TB_iframe=true&modal=true');
}

function fillContainer(arg){
	$("#containerclick").attr("href",arg);
	$("#containerclick").click();
}
function openConditions() {
   state='toolbar=none,scrollbars=yes,location=none,left=0,top=0,width=810,height=570';
   window.open("/qi/aiweb.nsf/2008ConditionsPopup","Conditions",state);
 }
var start=1;
function disShowCon(){
if(start==1){
document.all.anotherStr.style.display='inline';
}
eval("document.all.anotherEm_"+start+".style.display='inline'");
eval("document.all.anotherInput_"+start+".style.display='inline'");
if(start>3){
document.all.speTr.style.backgroundColor='#fff';
document.all.emailBu.style.display="none";
return;
}
start++;
}
var unsafeString = "\"<>%\\^[]`\+\$\,";
var hexVals = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
              "A", "B", "C", "D", "E", "F");
function isUnsafe(compareChar){
    if (unsafeString.indexOf(compareChar) == -1 && compareChar.charCodeAt(0) > 32 && compareChar.charCodeAt(0) < 123)
          { return false; }
else
   { return true; }
}
function convert(val){ 
    return  "%" + decToHex(val.charCodeAt(0), 16);
}
function reversal(s) // part of the hex-ifying functionality
{
var len = s.length;
var trans = "";
for (i=0; i<len; i++)
    { trans = trans + s.substring(len-i-1, len-i); }
s = trans;
return s;
}
function decToHex(num, radix){
var hexString = "";
while (num >= radix)
      {
       temp = num % radix;
       num = Math.floor(num / radix);
       hexString += hexVals[temp];
      }
hexString += hexVals[num];
return reversal(hexString);
}

function changeIt(val) {
    var i = 0;
    var newStr="";
    for (i=0;i<val.length;i++){
        if (isUnsafe(val.substring(i,i+1)) == false)
            { newStr = newStr + val.substring(i,i+1); }
        else
            { newStr = newStr + convert(val.substring(i,i+1)); }
    }
    return newStr;
}
function replaceVowel(str){
	str=str.replace(/ä/g,"a");
	str=str.replace(/à/g,"a");
	str=str.replace(/á/g,"a");
	str=str.replace(/é/g,"e");
	str=str.replace(/è/g,"e");
	str=str.replace(/ë/g,"e");
	str=str.replace(/í/g,"i");
	str=str.replace(/ì/g,"i");
	str=str.replace(/ï/g,"i");
	str=str.replace(/ó/g,"o");
	str=str.replace(/ò/g,"o");
	str=str.replace(/ö/g,"o");
	str=str.replace(/ú/g,"u");
	str=str.replace(/ù/g,"u");
	str=str.replace(/ü/g,"u");
	str=str.replace(/ç/g,"c");
	str=str.replace(/ñ/g,"n");
	
  return str;
}