﻿function siteInit(){
	correctPNG();	
	return true;
}

function showAd(){
	dyLoad("page_body","resource/jsps/topic.jsp?content=resource/htmltopic/xncs.html",true);
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. 
{ 
    var arVersion = navigator.appVersion.split("MSIE") 
    var version = parseFloat(arVersion[1]) 
    if ((version >= 5.5) && (document.body.filters)) 
    { 
       for(var j=0; j<document.images.length; j++) 
       { 
          var img = document.images[j] 
          var imgName = img.src.toUpperCase() 
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
          { 
             var imgID = (img.id) ? "id='" + img.id + "' " : "" 
             var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
             var imgStyle = "display:inline-block;" + img.style.cssText 
             if (img.align == "left") imgStyle = "float:left;" + imgStyle 
             if (img.align == "right") imgStyle = "float:right;" + imgStyle 
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
             var strNewHTML = "<span " + imgID + imgClass + imgTitle 
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
             img.outerHTML = strNewHTML 
             j = j-1 
          } 
       } 
    }     
} 
//Banner Menu utility function
function highLight(item){
	item.style.backgroundColor="#AA0000";
	item.style.borderColor="#DDDDDD";

}
function recover(item){
	item.style.backgroundColor="black";
	item.style.borderColor="black";
}


//Flash communication utility
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1){
		return window[movieName];
	}
	else{
		return document[movieName];
	}
}
function setFlashVar(varName,varValue){
	window.document.PopShower.SetVariable(varName,varValue);
}
function flashClearVar(){
	thisMovie("PopShower").clearVar();
}
function flashShowPic(){
	thisMovie("PopShower").showPic();
}
function GetSwfUrl(){
	alert("Hello! world");
}

//Product menu show/hide function
var curSubMenu=0;
function showSubMenu(id){
	if(curSubMenu!=0)
		document.getElementById("subMenu"+curSubMenu).style.display='none';
	if(curSubMenu!=id){
    	document.getElementById("subMenu"+id).style.display='block';
    	curSubMenu=id;
	}else{
		curSubMenu=0;
	}
}

//Important pop up show features
var curPdtID=0;
function showProduct(pdtID,language){
	curPdtID=pdtID;
	
	var pic0="";
	var pic1="";
	var pic2="";
	var pic3="";
	var pic4="";
	var pic5="";
	var pdt_name="";
	var pdt_code="";
	var pdt_material="";
	var pdt_include="";
	var pdt_fit="";
	var pdt_detail="";
	
	showDiv();
	
	//Fill the var by xmlHttp...
	var xmlHttp;
	try{
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}catch(e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	if(xmlHttp==null){
		window.alert("Broswer don't support ajax")
		return;
	}
	
	xmlHttp.onreadystatechange = function(){
	 	if(xmlHttp.readyState==4){
	 		var tags=xmlHttp.responseXML.documentElement.getElementsByTagName("product");
	 		for(i=0;i<tags.length;i++){
	 			try{
	 				var pdt_name=tags[i].getElementsByTagName("name")[0].firstChild.nodeValue;
	 			}catch(e){pdt_name="";}
	 			try{
	 				var pdt_code=tags[i].getElementsByTagName("code")[0].firstChild.nodeValue;
	 			}catch(e){pdt_code="";}
	 			try{
	 				var pdt_material=tags[i].getElementsByTagName("material")[0].firstChild.nodeValue;
	 			}catch(e){pdt_material="";}
	 			try{
	 				var pdt_include=tags[i].getElementsByTagName("include")[0].firstChild.nodeValue;
	 			}catch(e){pdt_include="";}
	 			try{
	 				var pdt_fit=tags[i].getElementsByTagName("fit")[0].firstChild.nodeValue;
	 			}catch(e){pdt_fit="";}
	 			try{
	 				var pdt_detail=tags[i].getElementsByTagName("detail")[0].firstChild.nodeValue;
	 			}catch(e){pdt_detail="";}
	 			try{
	 				var pic0=tags[i].getElementsByTagName("pic0")[0].firstChild.nodeValue;
	 			}catch(e){pic0="";}
	 			try{
	 				var pic1=tags[i].getElementsByTagName("pic1")[0].firstChild.nodeValue;
	 			}catch(e){pic1="";}
	 			try{
	 				var pic2=tags[i].getElementsByTagName("pic2")[0].firstChild.nodeValue;
	 			}catch(e){pic2="";}
	 			try{
	 				var pic3=tags[i].getElementsByTagName("pic3")[0].firstChild.nodeValue;
	 			}catch(e){pic3="";}
	 			try{
	 				var pic4=tags[i].getElementsByTagName("pic4")[0].firstChild.nodeValue;
	 			}catch(e){pic4="";}
	 			try{
	 				var pic5=tags[i].getElementsByTagName("pic5")[0].firstChild.nodeValue;
	 			}catch(e){pic5="";}
	 		}
	 		if(tags.length<1)
	 			alert("No data return by getproduct.do!");
	 			
			//Init the popup content when Using flash displayer;
			/*flashClearVar();
			setFlashVar("pic0",pic0);
			setFlashVar("pic1",pic1);
			setFlashVar("pic2",pic2);
			setFlashVar("pic3",pic3);
			setFlashVar("pic4",pic4);
			setFlashVar("pic5",pic5);
			flashShowPic();*/
			
			//Init the popup content when Using HTML displayer;
			var tHead="resource/image/thumb/";
			var lHead="resource/image/logoed/";
			var pic_main=document.getElementById("pic_main");
			var pic_thumb0=document.getElementById("pic_thumb0");
			var pic_thumb1=document.getElementById("pic_thumb1");
			var pic_thumb2=document.getElementById("pic_thumb2");
			var pic_thumb3=document.getElementById("pic_thumb3");
			var pic_thumb4=document.getElementById("pic_thumb4");
			var pic_thumb5=document.getElementById("pic_thumb5");
			var pic_0=document.getElementById("pic_0");
			var pic_1=document.getElementById("pic_1");
			var pic_2=document.getElementById("pic_2");
			var pic_3=document.getElementById("pic_3");
			var pic_4=document.getElementById("pic_4");
			var pic_5=document.getElementById("pic_5");
			
			pic_main.src=lHead+pic0;
			pic_main.style.display="block";
			for(var i=0;i<6;i++){
				eval("pic_"+i+".src=tHead+pic"+i);
				eval("pic_thumb"+i+".style.display=pic"+i+".length>1?'block':'none'");
				eval("pic_thumb"+i+".style.opacity=0.7");
				try{
					eval("pic_thumb"+i+".filters[0].Opacity=70");
				}catch(e){}
			}
			try{
				pic_thumb0.filters[0].Opacity=100;
			}catch(e){}
			pic_thumb0.style.opacity=1;
			curPic=0;
			
			document.getElementById("pdt_name").innerHTML=pdt_name;
			document.getElementById("pdt_material").innerHTML=pdt_material;
			document.getElementById("pdt_include").innerHTML=pdt_include;
			document.getElementById("pdt_fit_model").innerHTML=pdt_fit;
			document.getElementById("pdt_detail").innerHTML=pdt_detail;
			document.getElementById("pdt_code").innerHTML=pdt_code;
			document.getElementById("reload").innerHTML="";
	 	}
	}
	if(language==null) 
		xmlHttp.open("GET","getproduct.do?method=getByID&id="+pdtID,true);
	else
		xmlHttp.open("GET","getproduct.do?method=getByID_English&id="+pdtID,true);
	xmlHttp.send(null);
}
function clearDiv(){
	document.getElementById("pdt_name").innerHTML="";	
	document.getElementById("pdt_material").innerHTML="";	
	document.getElementById("pdt_include").innerHTML="";	
	document.getElementById("pdt_fit_model").innerHTML="";	
	document.getElementById("pdt_detail").innerHTML="";	
	document.getElementById("pdt_code").innerHTML="";	
	document.getElementById("reload").innerHTML=document.getElementById("div_copy_reload").innerHTML;	
	
	//For Using Flash shower
	/*flashClearVar();
	flashShowPic();*/
	
	//For Using HTML shower
	document.getElementById("pic_main").style.display="none";
	document.getElementById("pic_main").src="resource/index/load.gif";
	for(var i=0;i<6;i++){
		eval("pic_thumb"+i+".style.display='none'");
	}
}

function showDiv(){
	var bottomDiv=document.getElementById("bottom_div");
	//bottomDiv.style.height=window.document.body.clientHeight+document.body.scrollTop;
	bottomDiv.style.height=document.body.scrollHeight;
	bottomDiv.style.width=window.document.body.clientWidth+document.body.scrollLeft;
	bottomDiv.style.display='block';
	
	var upperDiv=document.getElementById("upper_div");
	/*var maskIframe=document.getElementById("mask_iframe");*/
	upperDiv.style.display='block';
	var leftPos=window.document.body.clientWidth/2-upperDiv.clientWidth/2+document.body.scrollLeft;
	var topPos=window.document.body.clientHeight/2-upperDiv.clientHeight/2+document.body.scrollTop;
	upperDiv.style.left=leftPos>0?leftPos:0;
	upperDiv.style.top=topPos>0?topPos:0;
	
	/*maskIframe.style.left=(leftPos>0?leftPos:0)-100;
	maskIframe.style.top=topPos>0?topPos:0;*/
}
function hideDiv(){
	clearDiv();
	var targetDiv=document.getElementById("bottom_div");
	targetDiv.style.display='none';
	
	var upperDiv=document.getElementById("upper_div");
	upperDiv.style.display='none';
}

var curPic=0;
var curPos=0;
function onImgOver(){
	if(curPic==curPos)
		return true;
	
	document.getElementById("pic_thumb"+curPos).style.opacity=1;
	document.getElementById("pic_thumb"+curPos).filters[0].Opacity=100;
}
function onImgOut(){
	if(curPic==curPos)
		return true;
	
	document.getElementById("pic_thumb"+curPos).style.opacity=0.7;
	document.getElementById("pic_thumb"+curPos).filters[0].Opacity=70;
}
function onImgChange(imgHandle,id){
	if(curPic==id){
		return true;
	}
	var imgAddr=imgHandle.src;
	var pic_main=document.getElementById("pic_main");
	pic_main.src=imgAddr.replace("thumb","logoed");
	
	document.getElementById("pic_thumb"+curPic).style.opacity=0.7;
	try{
		document.getElementById("pic_thumb"+curPic).filters[0].Opacity=70;
	}catch(e){}
	curPic=id;
}

//****************************Dynamic Loading*******************************
function dyLoad(divID,url,showMask){
	//showMask=false;
	if(showMask)
		showWaiting(divID);
		
	var xmlHttp;
	try{
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}catch(e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	if(xmlHttp==null){
		window.alert("Broswer don't support ajax")
		return;
	}
	
	xmlHttp.onreadystatechange = function(){
	 	if(xmlHttp.readyState==4){
	 		document.getElementById(divID).innerHTML=xmlHttp.responseText;
		 	correctPNG();
		 	if(showMask){
		 		//alert("pause");
		 		hideWaiting();
		 	}
		 	document.body.scrollTop=0;
	 	}
	}
	 
	//xmlHttp.open("GET",url+"?random="+Math.random(),true);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}
function showWaiting(divID){
	var divWidth;
	var divHeight;
	var divX;
	var divY;
	var element=document.getElementById(divID);
	
	divWidth=element.offsetWidth;
	divHeight=element.offsetHeight;
	if(divWidth<2){
		divWidth=250;
	}
	if(divHeight<2){
		divHeight=20;
	}
	divY=element.offsetTop;
	divX=element.offsetLeft;
	while(element=element.offsetParent){
		divY+=element.offsetTop;
		divX+=element.offsetLeft;
	}	
	
	var x=divX;
	var y=divY;
	var mask=document.getElementById("waiting_bottom");
	var progress=document.getElementById("waiting_top");
	mask.style.width=divWidth;
	mask.style.height=divHeight;
	mask.style.left=x;
	mask.style.top=y;
	mask.style.display="block";
	
	progress.style.width=divWidth;
	if(divHeight>window.document.body.clientHeight/2){
		divHeight=window.document.body.clientHeight;
	}
	progress.style.height=divHeight;
	progress.style.left=x;
	progress.style.top=y;
	progress.style.display="block"; 
	//alert(x+" "+y+" "+divWidth+" "+divHeight);
}
function hideWaiting(){
	var mask=document.getElementById("waiting_bottom");
	var progress=document.getElementById("waiting_top");
	mask.style.display='none';
	progress.style.display='none';
}

//Static pages utility

//for about
function showContent(divID){
	document.getElementById(divID).style.display='block';
}
function hideContent(divID){
	document.getElementById(divID).style.display='none';
}

function insertFlash(elm,swfName,url, w, h) {
if (!document.getElementById(elm)) return;
var str = '';
str += '<object width="'+ w +'" height="'+ h +'" id="'+ swfName +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
str += '<param name="allowScriptAccess" value="sameDomain" />'
str += '<param name="movie" value="'+ url +'">';
str += '<param name="wmode" value="transparent">';
str += '<param name="quality" value="low">';
str += '<embed name="'+ swfName +'" width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="low" wmode="wmode="transparent"" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
str += '</object>';
document.getElementById(elm).innerHTML = str;
}

		function chkReturn(field,checkOk, msg, nofocus) {
			if (!checkOk){
		   	alert(msg);
		   	if(!nofocus)
		   		field.focus();
		    	return false;
		    }
			return true;
		}
		function chkLength(field, msg, minLength, maxLength)
		{
			checkOk=true;
			if (!minLength) minLength =1;	
			
			if (checkOk && field.value.length < minLength)  checkOk=false;
			if (checkOk && maxLength>minLength && field.value.length>maxLength){
				checkOk=false;
				msg=msg+"  您的内容过长！";
			}
			
			return chkReturn(field,checkOk, msg);
		}
		function chkEmail(field,msg) {
			var str=field.value;
			var checkOk=true;	
			var supported = 0;
			if (window.RegExp) {
				var tempStr = "a";
				var tempReg = new RegExp(tempStr);
				if (tempReg.test(tempStr)) supported = 1;
			}
			
		  	if (!supported) {
				checkOk=(str.indexOf(".") > 2) && (str.indexOf("@") > 0);
		  	} else {
			  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
			  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
			  checkOk=(!r1.test(str) && r2.test(str));
			}
		  return chkReturn(field,checkOk, msg);
		}		 
		function checkForm() {
			//check
			var frmObj=document.enquiry;
			var msgInput="请输入"; 
			var msgSelect="请选择";
			
			var compField=frmObj.companyName;
			var compMsg=msgInput + "\"公司名称\"";
	
			var contactField=frmObj.contact; 
			var contactMsg=msgInput+"\"联系人\"";
	
			var phoneField=frmObj.phone;  
			var phoneMsg=msgInput+"\"电话号码\"";
	
			var emailField=frmObj.email; 
			var emailMsg=msgInput+"\"电邮地址\"";
	
			var enMsgField=frmObj.message; 	
			var enMsgMsg=msgInput+"\"查询的具体内容\"";
		
			result=true;
			result=result && chkLength(enMsgField, enMsgMsg,1,1000);
			
			result=result && chkLength(compField, compMsg,1,100);
			result=result && chkLength(contactField, contactMsg,1,100);
			result=result && chkLength(phoneField, phoneMsg,1,100);
			result=result && chkLength(emailField, emailMsg,1,100) && chkEmail(emailField, emailMsg);
			
			if(result){
				document.getElementById("leave_message").style.height="1px";
				//frmObj.companyName.value="主站查询 - " + frmObj.companyName.value;
			}
			
			return(result);
		}