
function PServant() {
}

PServant.prototype.writeLoginInfo = function(l) {
	var url = "/welcometop.fs";
	if (l) {
		url+="?l=" + encodeURIComponent(l);
	}
	if("en"==l) {
		document.write("Welcome to Nanhua!");
		return true;
	}
	document.write("Loading...");
	PS.asyncRequest(url,"GET",{
	   success: function(o) {
					var h = o.responseText;
					if(document.getElementById("top-login-info")) {
							document.getElementById("top-login-info").innerHTML = h;
					}else {
						PS.onDOMReady(function() {
							document.getElementById("top-login-info").innerHTML = h;
						});
					}
	   },
	   failure: function(o) {
			if(document.getElementById("top-login-info")) {
					document.getElementById("top-login-info").innerHTML = "加载用户信息出错!";
			}else {
				PS.onDOMReady(function() {
					document.getElementById("top-login-info").innerHTML = "加载用户信息出错!";
				});
			}
	   }
	});
}

PServant.prototype.go2WelcomeLogin = function() {
	try {
		var w="/member/form/login.fs?f=top";
		var r=window.location.href;
		var h=w;
		if(r.indexOf("/member/form/login.fs")==-1 && r.indexOf("/member/form/register.fs")==-1) {
			h+="&redirectURL="+encodeURIComponent(r);
		}
		window.location.href=h;
	}catch (e) {
	}finally {
	}
}

PServant.prototype.writeLanguageInfo = function(l) {
	try {
		var w="/selectlanguage.fs";
		var r=location.href;
		var h=w;
		//h+="?redirectURL="+encodeURIComponent(r);
		var s = "";
		s += "<ul id='header-right'>";
		s += "<li><a href='/selectlanguage.fs?l=cn' class='nav-China'><span>中文</span></a></li>";
		s += "<li><a href='/selectlanguage.fs?l=en' class='nav-English'><span>English</span></a></li>";
		s += "</ul>";
		s += "";
		document.write(s);
	}catch (e) {
	}finally {
	}
}


PServant.prototype.go2RegisterNow = function(t) {
	try {
		var w="/member/form/login.fs?f=top";
		var r=location.href;		
		var h=w;
		if(r.indexOf("/member/form/login.fs")==-1) {
			//h+="&comeOf="+encodeURIComponent(r);
		}
		window.location.href=h;
	}catch (e) {
	}finally {
	}
}

PServant.prototype.createXMLHttpRequest = function() {
	var xmlhttp;
	if(window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else {
		xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
	}
	return  xmlhttp;
}
PServant.prototype.buildMenuFix = function() {
	var id_myhome = document.getElementById("id_myhome");
	var id_products = document.getElementById("id_products");
	var id_application = document.getElementById("id_application");
	var id_support = document.getElementById("id_support");
	var id_about = document.getElementById("id_about");
	var htmls = document.getElementsByTagName("HTML");
	var l = "zh-CN";
	if(htmls.length>0) {
		l = htmls[0].lang;
	}
	if("zh-CN"==l) {
		id_myhome.style.display = "block";
	}
	var _this = this;
	if(id_myhome) {
		var submenu = document.createElement("UL");
		submenu.id = "submenu1_id_myhome"
		submenu.style.width = "180px"
		//submenu.style.zIndex = 999;
		var submenuHTML = ""		
		if(l=="en") {
			submenuHTML+="<li><a href='/member/form/myorder.fs'><span>My Order</span></a></li>";
			submenuHTML+=" <li><a href='/member/form/mycart.fs'><span>My Cart</span></a></li>";
			submenuHTML+="<li><a href='/member/form/searchinquireorder.fs'><span>My Inquiry Price</span></a></li>";
			submenuHTML+="<li><a href='/download/contract.doc'><span>Download Contract Templete</span></a></li>";
			submenuHTML+="<li><a href='/shopflow/index.html'><span>Flow of Shopping</span></a></li>";
		}else {
			submenuHTML+="<li><a href='/member/form/myorder.fs'><span>我的订单</span></a></li>";
			submenuHTML+=" <li><a href='/member/form/mycart.fs'><span>我的购物车</span></a></li>";
			submenuHTML+="<li><a href='/member/form/searchinquireorder.fs'><span>询价订单查询</span></a></li>";
			submenuHTML+="<li><a href='/download/合同范本.doc'><span>空白合同下载</span></a></li>";
			submenuHTML+="<li><a href='/cn/shopflow/index.html'><span>购物流程</span></a></li>";
		}
		submenu.innerHTML = submenuHTML;
		id_myhome.appendChild(submenu);
	}
	if(id_products) {
		var submenu = document.createElement("UL");
		submenu.id = "submenu1_id_produts"
		submenu.style.width = "180px"
		var submenuHTML = "";
			if(l=="en") {
			submenuHTML+="<li id='product_item_id_5ec9b98225c029730125c3c69f520007'><a href='/communal/view/productpreview.fs?id=5ec9b98225c029730125c3c69f520007'><span>Aviation Obstruction Light</span></a></li>";
			submenuHTML+="<li id='product_item_id_5ec9b98225c029730125c3c617840006'><a href='/communal/view/productpreview.fs?id=5ec9b98225c029730125c3c617840006'><span>Warning Light </span></a></li>";
			submenuHTML+="<li id='product_item_id_5ec9b98225c029730125c3c590ef0005'><a href='/communal/view/productpreview.fs?id=5ec9b98225c029730125c3c590ef0005'><span>Alarm Series</span></a></li>";
			submenuHTML+="<li id='product_item_id_5ec9b98225c029730125c3c50b060004'><a href='/communal/view/productpreview.fs?id=5ec9b98225c029730125c3c50b060004'><span>Industrial communication</span></a></li>";
			submenuHTML+="<li id='product_item_id_5ec9b98225c029730125c3c4877e0003'><a href='/communal/view/productpreview.fs?id=5ec9b98225c029730125c3c4877e0003'><span>Power Equipment</span></a></li>";
			submenuHTML+="<li id='product_item_id_5ec9b98225c029730125c3c3dff30002'><a href='/communal/view/productpreview.fs?id=5ec9b98225c029730125c3c3dff30002'><span>Intelligent Instrument</span></a></li>";
		}else {
            submenuHTML+="<li id='product_item_id_402880a02529108d012529128e3f0000'><a href='/communal/view/productpreview.fs?id=402880a02529108d012529128e3f0000'><span>航空障碍灯</span></a></li>";
			submenuHTML+="<li id='product_item_id_402880a02529108d01252914d9580002'><a href='/communal/view/productpreview.fs?id=402880a02529108d01252914d9580002'><span>工业报警</span></a></li>";
			submenuHTML+="<li id='product_item_id_402880a02529108d0125291385420001'><a href='/communal/view/productpreview.fs?id=402880a02529108d0125291385420001'><span>工业灯具</span></a></li>";
			submenuHTML+="<li id='product_item_id_402880a02529108d0125291561350003'><a href='/communal/view/productpreview.fs?id=402880a02529108d0125291561350003'><span>工业通讯</span></a></li>";
			submenuHTML+="<li id='product_item_id_402880a02529108d0125291656240004'><a href='/communal/view/productpreview.fs?id=402880a02529108d0125291656240004'><span>电源管理</span></a></li>";
			submenuHTML+="<li id='product_item_id_5ec9b982274bde670128a516e2630043'><a href='/communal/view/productpreview.fs?id=5ec9b982274bde670128a516e2630043'><span>风速仪</span></a></li>";
		}
		submenu.innerHTML = submenuHTML;
		id_products.appendChild(submenu);
	}
	if(id_application){
		var submenu = document.createElement("UL");
		submenu.id = "submenu1_id_produts"
		submenu.style.width = "180px"
		var submenuHTML = "";
			if(l=="en") {
			submenuHTML+="<li><a href='/application/port/'><span>Port Machinery</span></a></li>";
			submenuHTML+="<li><a href='/application/engineering/'><span>Mechanical Engineering</span></a></li>";
			submenuHTML+="<li><a href='/application/aviation/'><span>Aviation Warning Light</span></a></li>";
		}else {
			submenuHTML+="<li><a href='/cn/application/port/'><span>港口机械</span></a></li>";
			submenuHTML+=" <li><a href='/cn/application/engineering/'><span>工程机械</span></a></li>";
			submenuHTML+="<li><a href='/cn/application/aviation/'><span>航空警示</span></a></li>";
			submenuHTML+="<li><a href='/cn/application/qd/'><span>桥吊产品应用示意</span></a></li>";
			submenuHTML+=" <li><a href='/cn/application/lt/'><span>轮胎吊产品应用示意</span></a></li>";
			submenuHTML+="<li><a href='/cn/application/ld/'><span>履带吊产品应用示意</span></a></li>";
			submenuHTML+="<li><a href='/cn/application/hc/'><span>行车产品应用示意</span></a></li>";
		}
		submenu.innerHTML = submenuHTML;
		id_application.appendChild(submenu);
	}
	if(id_support) {
		var submenu = document.createElement("UL");
		submenu.id = "submenu1_id_produts"
		submenu.style.width = "180px"
		var submenuHTML = "";
			if(l=="en") {
			submenuHTML+="<li><a href='/service_support/clause/'><span>After-sale policy</span></a></li>";
			submenuHTML+=" <li><a href='/service_support/madeservice/'><span>Customization Service</span></a></li>";
			submenuHTML+="<li><a href='/service_support/FAQ/'><span>Frequently Asked Questions</span></a></li>";
		}else {
			submenuHTML+="<li><a href='/cn/service_support/clause/'><span>售后服务政策</span></a></li>";
			submenuHTML+=" <li><a href='/cn/service_support/madeservice/'><span>产品定制服务</span></a></li>";
			submenuHTML+="<li><a href='/cn/service_support/FAQ/'><span>常见问题</span></a></li>";
			submenuHTML+="<li><a href='/cn/service_support/tech/'><span>技术与标准</span></a></li>";
		}
		submenu.innerHTML = submenuHTML;
		id_support.appendChild(submenu);
	}
	if(id_about) {
		var submenu = document.createElement("UL");
		submenu.id = "submenu1_id_produts"
		submenu.style.width = "180px"
		var submenuHTML = "";
			if(l=="en") {
			submenuHTML+="<li><a href='/company/Companyconstruction/'><span>Company construction</span></a></li>";
			submenuHTML+="<li><a href='/company/partners/'><span>Partners</span></a></li>";
			submenuHTML+="<li><a href='/company/research/'><span>Research & Development</span></a></li>";
			submenuHTML+="<li><a href='/company/proud/'><span>Valuable Staff</span></a></li>";
			submenuHTML+="<li><a href='/company/table/'><span>Certification</span></a></li>";
			submenuHTML+="<li><a href='/communal/view/news_en.fs'><span>Community Fund</span></a></li>";
			submenuHTML+="<li><a href='/company/contact/'><span>Contact Us</span></a></li>";
		}else {
			
			submenuHTML+=" <li><a href='/cn/company/Organizationchart/'><span>公司架构</span></a></li>";
			submenuHTML+=" <li><a href='/cn/company/research/'><span>研究与开发</span></a></li>";
			submenuHTML+="<li><a href='/cn/company/honour/'><span>荣誉员工</span></a></li>";
            submenuHTML+="<li><a href='/cn/company/table/'><span>资质认证</span></a></li>";
			submenuHTML+="<li><a href='/communal/view/news.fs'><span>公益基金</span></a></li>";
			submenuHTML+="<li><a href='/cn/company/contact/'><span>联系我们</span></a></li>";
		}
		submenu.innerHTML = submenuHTML;
		id_about.appendChild(submenu);
	}
}



PServant.prototype.getElementX = function(e) {
    var t=e.offsetLeft;
    while(e=e.offsetParent){t+=e.offsetLeft;};
    return t;
}

PServant.prototype.getElementY = function(e) {
    var t=e.offsetTop;
    while(e=e.offsetParent){
        t+=e.offsetTop;
    };
    return t;
}


PServant.prototype.menuFix = function() {
 var sfEls;
 if(document.getElementById("nav-list")) {
	 sfEls = document.getElementById("nav-list").getElementsByTagName("li");
 }else {
	return;
 }
 for (var i=0; i<sfEls.length; i++) {
  sfEls[i].onmouseover=function() {
	this.className+=(this.className.length>0? " ": "") + "sfhover";
	if(this.parentNode.parentNode) {
		var lastClass = this.parentNode.parentNode.firstChild.className;
		this.parentNode.parentNode.firstChild.setAttribute("lastClass",lastClass);
		this.parentNode.parentNode.firstChild.className="nav-selected"
	}
  }
  sfEls[i].onMouseDown=function() {
	this.className+=(this.className.length>0? " ": "") + "sfhover";
  }
  sfEls[i].onMouseUp=function() {
	this.className+=(this.className.length>0? " ": "") + "sfhover";
  }
  sfEls[i].onmouseout=function() {
	this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
	if(this.parentNode.parentNode) {
		var lastClass = this.parentNode.parentNode.firstChild.getAttribute("lastClass");
		lastClass = lastClass==null?"":lastClass;
		this.parentNode.parentNode.firstChild.className=lastClass
	}
  }
 }
}

PServant.prototype.addObjectEventListener = function(obj,eventName,func) {
	// DOM2
	if ( typeof window.addEventListener != "undefined" ) {
		if(eventName.indexOf("on")==0) {
			eventName = eventName.substring(2);
		}
		obj.addEventListener( eventName, func, false );
	// IE
	}else if ( typeof window.attachEvent != "undefined" ) {
		obj.attachEvent(eventName, func);
	}
}

PServant.prototype.removeObjectEventListener = function(obj,eventName,func) {
	// DOM2
	if ( typeof window.addEventListener != "undefined" ) {
		if(eventName.indexOf("on")==0) {
			eventName = eventName.substring(2);
		}
		obj.removeEventListener( eventName, func, false );
	// IE
	}else if ( typeof window.attachEvent != "undefined" ) {
		obj.detachEvent(eventName, func);
	}
}

PServant.prototype.addObjectEventListener = function(obj,eventName,func) {
	// DOM2
	if ( typeof window.addEventListener != "undefined" ) {
		if(eventName.indexOf("on")==0) {
			eventName = eventName.substring(2);
		}
		obj.addEventListener( eventName, func, false );
	// IE
	}else if ( typeof window.attachEvent != "undefined" ) {
		obj.attachEvent(eventName, func);
	}
}

PServant.prototype.removeObjectEventListener = function(obj,eventName,func) {
	// DOM2
	if ( typeof window.addEventListener != "undefined" ) {
		if(eventName.indexOf("on")==0) {
			eventName = eventName.substring(2);
		}
		obj.removeEventListener( eventName, func, false );
	// IE
	}else if ( typeof window.attachEvent != "undefined" ) {
		obj.detachEvent(eventName, func);
	}
}

PServant.prototype.callerWrapFunction = function(funcObject,object,object1,object2) {
	var handler = function() {
		return funcObject(object,object1,object2);
	}
	return handler;
}

PServant.prototype.isIE = function() {
	if (window.navigator.userAgent.indexOf("MSIE")>=1){
		return true;
	}else {
		return false;
	}
}

PServant.prototype.initMenu = function(l,t,id) {	
		var url = "/communal/view/productitemmenu.fs";
		var index = 0;
		if (l) {
			url+="?l=" + encodeURIComponent(l);
			index++;
			}
		if(t){			
			if(index >0){				
				 url+="&t=" + encodeURIComponent(t);				
			}else{
				 url+="?t=" + encodeURIComponent(t);
			}
			index++;
		}
		if(id){			
			if(index>0){
			url+="&id=" + encodeURIComponent(id);
			}else{
			url+="?id=" + encodeURIComponent(id);				
			}
			index++;
		}
		if(index>0){
			url+="&ran=" +new Date().getTime();	
		}else{
			url+="?ran=" +new Date().getTime();	
		}
	document.write("Loading...");
	PS.asyncRequest(url,"GET",{
	   success: function(o) {
					var h = o.responseXML;
					if(h){
						var menuhtmls = h.getElementsByTagName("menuhtml");						
						var priceEls = h.getElementsByTagName("price");
						if(menuhtmls){
							var menuhtml=menuhtmls[0];
							if(menuhtml){
									var menuContent = menuhtml.firstChild.nodeValue;
									//alert(menuContent);
									if(document.getElementById("mainBodyLeft")) {											
											document.getElementById("mainBodyLeft").innerHTML = menuContent;
									}else {
										PS.onDOMReady(function() {
											document.getElementById("mainBodyLeft").innerHTML =  menuContent;
										});
									}
							 }
						}
						if(priceEls){
								var priceEl = priceEls[0];
								if(priceEl){
									var price = priceEl.getAttribute("value");
									var title = priceEl.getAttribute("title");
									var currency = priceEl.getAttribute("currency");
									if(price){
											var priceCode="";
										//var priceCode =  "<ul class=\"priceWarp\">";
											//priceCode += "<li><span> "+title+"</span>";
											//priceCode += "<strong>"+price+"</strong>"+currency+"</li></ul>";
											priceCode ="<div>"+title+"<br />";
										    priceCode +="<span class='Price'>"+price+currency+"</span>";
											priceCode +="</div>";
										if(document.getElementById("block_price")){
											document.getElementById("block_price").innerHTML = priceCode;
										}else{
											PS.onDOMReady(function() {
												if(document.getElementById("block_price")){
													document.getElementById("block_price").innerHTML =  priceCode;
												}
										});
										}
								}
							}
						}
					}
	   },
	   failure: function(o) {
			if(document.getElementById("mainBodyLeft")) {
					document.getElementById("mainBodyLeft").innerHTML = "加载导航信息出错!";
			}else {
				PS.onDOMReady(function() {
					document.getElementById("mainBodyLeft").innerHTML = "加载导航信息出错!";
				});
			}
	   }
	});
}

function search(){
   //var searchTypeSel =document.getElementById("search_type");
   var searchK =document.getElementById("search_k").value;
   var w = "/communal/view/productsearch.fs"
   /*if(searchTypeSel){
	   var index = searchTypeSel.selectedIndex;
	   var searchType= searchTypeSel.options[index].value;
	   w = w+"?type=" +encodeURIComponent(searchType);*/
	   w =w +"?k=" +encodeURIComponent(searchK);
	   window.location=w
   /*}*/
}


PServant.prototype.writeSearchInfo = function(l) {
	var htmlCode="";
	var htmls =document.getElementsByTagName("html");
	var lang ="";
	if(htmls){
		lang = htmls[0].lang;		
	}
	if(l=="cn"){
		lang="zh-CN";
	}
    var htmlCode="";
	if(lang=="" || lang=="zh-CN"){
/*		htmlCode +="<span class='search_pad'>";
        htmlCode +="<select id='search_type' class='sel_search' name='type'>";
        htmlCode +="<option value='productName' selected>产品名称</option>";
        htmlCode +="<option value='model' >产品型号</option>";
        htmlCode +="<option value='application' >应用领域</option>";     
        htmlCode +="</select>"; 
        htmlCode +="</span>"; */
        htmlCode +="<input type='text' id='search_k' onkeydown='if(event.keyCode==13){ search();}' class='seach_inp' name='k' value='' />"; 
        htmlCode +="<button type='button'  onclick='search()' title='搜索' class='abs'>搜索</button>"; 	
	}else{
/*		htmlCode +="<span class='search_pad'>";
        htmlCode +="<select id='search_type' class='sel_search' name='t'>"; 
        htmlCode +="<option value='productName' selected>Product Name</option>"; 
        htmlCode +="<option value='model' >Model</option>"; 
        htmlCode +="<option value='application' >Application</option>"; 
        htmlCode +="</select>"; 
        htmlCode +="</span>"; */
        htmlCode +="<input type='text' id='search_k' onkeydown='if(event.keyCode==13){ search();}' class='seach_inp' name='k' value='' />"; 
        htmlCode +="<button type='button'  onclick='search()' title='Search' class='abs'>Search</button>"; 
	}  
	document.write(htmlCode);
}

PServant.prototype.onDOMReady = function(funcObject,object0,object1,object2) {
	var _this = this;
	var caller = function() {
		if(_this.isIE()){
			if("complete"==document.readyState){
				funcObject(object0,object1,object2);
			}
		}else {
			funcObject(object0,object1,object2);
		}
	}
	if(_this.isIE()) {
		_this.addObjectEventListener(document,"onreadystatechange",caller);
	}else {
		_this.addObjectEventListener(document,"DOMContentLoaded",caller);
	}
}


PServant.prototype.asyncRequest = function(url,method,callback) {
	var xmlhttp;
	var caller = function() {
		if (xmlhttp.readyState>3) {
			if(xmlhttp.status==200) {
				if(callback.success) {
					callback.success(xmlhttp);
				}else{
					callback(xmlhttp);
				}
			}else {
				if(callback){
					if(callback.failure) {
						callback.failure(xmlhttp);
					}else{
						callback(xmlhttp);
					}
				}
			}
		}
	}
	//try {
		xmlhttp = this.createXMLHttpRequest();
		if(url.indexOf("?")>-1) {
			url+="&d=" + encodeURIComponent(new Date().getTime());
		}else {
			url+="?d=" + encodeURIComponent(new Date().getTime());
		}
		xmlhttp.open(method,url,true);
		xmlhttp.onreadystatechange = caller;
		xmlhttp.send(null);
	//}catch(e) {

	//}
}


PServant.prototype.syncRequest = function(url,method,callback) {
	var xmlhttp;
	var caller = function() {
		if (xmlhttp.readyState>3) {
			if(xmlhttp.status==200) {
				if(callback.success) {
					callback.success(xmlhttp);
				}else{
					callback(xmlhttp);
				}
			}else {
				if(callback){
					if(callback.failure) {
						callback.failure(xmlhttp);
					}else{
						callback(xmlhttp);
					}
				}
			}
		}
	}
	//try {
		xmlhttp = this.createXMLHttpRequest();
		if(url.indexOf("?")>-1) {
			url+="&d=" + encodeURIComponent(new Date().getTime());
		}else {
			url+="?d=" + encodeURIComponent(new Date().getTime());
		}
		xmlhttp.open(method,url,false);
		xmlhttp.onreadystatechange = caller;
		xmlhttp.send(null);
	//}catch(e) {

	//}
}

PServant.prototype.initOnBodyLoad = function() {
	PS.buildMenuFix();
	PS.menuFix();
}


var PS = new  PServant();

PS.onDOMReady(PS.initOnBodyLoad);

