/**弹出框代码**/
var $w = window;
var $d = document;
var $l = location;
function $i(s){return $d.getElementById(s);}
function $t(s){return $d.getElementsByTagName(s);}
function $n(s){return $d.getElementsByName(s);}

var wrbhaoren = {};

wrbhaoren.client = (function(){ 
 var t = {};
 var b = navigator.userAgent.toLowerCase();
 t.isOpera = (b.indexOf('opera') > -1);
 t.isIE = (!t.isOpera && b.indexOf('msie') > -1);
 t.isFF = (!t.isOpera &&!t.isIE&&b.indexOf('firefox') > -1);
 return t;
})();

wrbhaoren.util = (function(){
 var t = {};
 t.addEvent = function(o,c,h){
  if(wrbhaoren.client.isIE){
   o.attachEvent('on'+c,h);
  }else{
   o.addEventListener(c,h,false);
  }
  return true;
 };
 t.delEvent = function(o,c,h){
  if(wrbhaoren.client.isIE){
   o.detachEvent('on'+c,h);
  }else{
   o.removeEventListener(c,h,false);
  }
  return true;
 };
 t.ga = function(o,s){
  return o.getAttribute(s);
 };
 t.sa = function(o,k,v){
  return o.setAttribute(k,v);
 };
 t.s2d = function(s){
  var sa = s.split('-');
  var d =  new Date(sa[0],(sa[1]-1),sa[2]);
  return d;
 };
 t.d2s = function(d,b){
  var ye = d.getFullYear();
  var me = (parseInt(d.getMonth())+1).toString()
  var de = d.getDate();
  if(me.length==1&&b)me='0'+me;
  if(de.length==1&&b)de='0'+de;
  return ye+me+de;
 };
 return t;
})();

wrbhaoren.cookies = (function(){
 var t = {};
 t.setCookie = function(name,value,days)
 {
  if(days){
    var exp  = new Date(); 
    exp.setTime(exp.getTime() + days*3*1000);
    document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString()+";path=/;";
  }else{
   document.cookie = name + "="+ escape(value)+";path=/;";
  }
 };
 
 t.getCookie = function(name)
 {
   var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
   if(arr != null) return unescape(arr[2]); return null;
 };
 
 t.setCookie2 = function(name,value,days)
 {
  if(days){
    var exp  = new Date(); 
    exp.setTime(exp.getTime() + days*3*1000);
    document.cookie = name + "="+ encodeURIComponent(value) +";expires="+ exp.toGMTString()+";path=/;";
  }else{
   document.cookie = name + "="+ encodeURIComponent(value)+";path=/;";
  }
 };
 
 t.getCookie2 = function(name)
 {
   var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
   if(arr != null) return decodeURIComponent(arr[2]); return null;
 };
 
 t.delCookie = function(name)
 {
   var exp = new Date();
   exp.setTime(exp.getTime() - 1);
   var cval=getCookie(name);
   if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.toGMTString();
 };
 
 t.delCookie2 = function(name)
 {
   var exp = new Date();
   exp.setTime(exp.getTime() - 1);
   var cval=getCookie2(name);
   if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.toGMTString();
 };
 
 return t;
})();

wrbhaoren.jscload = (function(){
 var t = function(){
     if(!wrbhaoren.quickload){
      var cs = $t('label');
      for(var i=0;i<cs.length;i++){  
       var ct = wrbhaoren.util.ga(cs[i],'c_type');
       if(ct){
        var pe = wrbhaoren.dom.gNxtSib(cs[i]);
        if(pe){
         eval("new "+ct+"(pe)");
        }
       }
      }
  }
  if(typeof jsconload == 'function'){
   jsconload();
  }
  wrbhaoren.loaded = true;
 };
 return t;
})();

wrbhaoren.jscunload = (function(){
 var t = function(){
  if(true){
      try{
    if(typeof jsconload == 'function'){
     jsconunload();
    }                           
            }catch(e){}
  }
 };
 return t;
})();

wrbhaoren.init = (function(){
 wrbhaoren.util.addEvent(window,'load',wrbhaoren.jscload);
 wrbhaoren.util.addEvent(window,'unload',wrbhaoren.jscunload);
 return true;
})();

var downMsg=function(msgid,contentid,config){
 this.msg = $i(msgid);
 this.content = $i(contentid);
 this.config = config ? config : {start_delay:5000, speed: 10, movepx:2,cookie:'downMsgcookie',expiresDay:0};
 this.offsetHeight;
 this.emsg_objTimer;
 this.ie6Add =0;
 var _this = this;
 
 this.init = function(){
  var ifcookie=wrbhaoren.cookies.getCookie(this.config.cookie);
  if(ifcookie == "show")
   return;
  window.setTimeout(_this.start,parseInt(_this.config.start_delay,10));
 }
 
 this.start = function(){
  _this.msg.style.display="block";
  _this.content.style.display="block";
  _this.offsetHeight = _this.content.offsetHeight;
  _this.content.style.height ="0px";
  _this.emsg_objTimer = setInterval(_this.moveUpDiv,parseInt(_this.config.speed,10));
 }
 
 this.moveUpDiv = function(){
   if(_this.offsetHeight> parseInt(_this.content.style.height,10)){
    _this.content.style.height =  parseInt(_this.content.style.height,10)+parseInt(_this.config.movepx,10)+"px";
   }
   else{
    window.clearInterval(_this.emsg_objTimer);
    wrbhaoren.cookies.setCookie(_this.config.cookie,"show",_this.config.expiresDay);
    // ie6下才做，因为没有fixed属性
    var isMSIE = !!(/*@cc_on!@*/0);
  if(isMSIE &&!(window.XMLHttpRequest))
  { 
    _this.content.style.height = parseInt(_this.content.style.height,10) +2+"px";
    _this.autoMoveIe6();
    }
   }
 }
 this.autoMoveIe6 = function(){

  if(_this.ie6Add ==0){
   _this.content.style.height =  parseInt(_this.content.style.height,10) + 1 +"px";
   _this.msg.style.bottom="-2px";
   _this.ie6Add =1;
  }
  else{
   _this.content.style.height =  parseInt(_this.content.style.height,10) - 1 +"px";
   _this.msg.style.bottom="-1px";
   _this.ie6Add =0;
  }
  setTimeout(_this.autoMoveIe6,1000)
 }
}

function closeDiv()
{
 document.getElementById('downmsg_emessage').style.display='none';
}

function showHideDiv()
{
 var ct = document.getElementById('donwmsg_content');
 var btn = document.getElementById('msg_hidden_btn');
 if(ct.style.display!="none"){
   ct.style.display = "none"
   btn.className="msg-hidden-btn-2";
 }else{
   ct.style.display="block";
   btn.className="msg-hidden-btn-1";
 }

}


var start=new Date();
 start=Date.parse(start)/1000;
 var counts=30;
 function CountDown(){
  var now=new Date();
  now=Date.parse(now)/1000;
  var x=parseInt(counts-(now-start),10);
  if(x>0){
   window.setTimeout('CountDown()',300)
  }else{
   //showHideDiv();
  }
 }
//window.setTimeout('CountDown()',300);


function closeDiv()
{
 document.getElementById('downmsg_emessage').style.display='none';
}

function showHideDiv()
{
 var ct = document.getElementById('donwmsg_content');
 var btn = document.getElementById('msg_hidden_btn');
 if(ct.style.display!="none"){
   ct.style.display = "none"
   btn.className="msg-hidden-btn-2";
 }else{
   ct.style.display="block";
   btn.className="msg-hidden-btn-1";
 }
}

function switchSkin(skin){
	var style = document.getElementById(skin);
	var tmp = document.getElementsByTagName('style');
	var skinArr = [];
	for(var i = 0; i < tmp.length; i++){
		if(tmp[i].getAttribute('id')){
			skinArr[i] =  tmp[i].getAttribute('id');
			document.getElementById(skinArr[i]).disabled = true;
		}
	}
	style.disabled = false;
}

//更换验证码
function changeCode(){	
	var now=new Date(); 
    var number = now.getTime();	
	var imgCode = document.getElementById('imgCode');
	imgCode.src = imgCode.src+"&"+Math.random(number);	
}

function showchild(id){
	var cid = "c_" + id;
	var childs = $_("cat_child");
	var tmpObj;
	var tmpId;
	var tmpStyle;
	for(var i=0;i<childs.length;i++){
		tmpObj = childs[i];
		tmpId = "c_" + tmpObj.value;
		tmpObj = $(tmpId);
		if(cid == tmpId){
			tmpStyle = tmpObj.style.display;
			if(tmpStyle == "none"){
				tmpObj.style.display = "";
			}else{
				tmpObj.style.display = "none";
			}
		}else{
			tmpObj.style.display = "none";
		}
	}
}


//浮动留言
/** 限制 textarea的长度 */
var oldValue=new Array();
function checkMaxLen(obj,maxlength,num){
	if(obj.value.length>maxlength){
		obj.value=oldValue[num];
	}
	else{
		oldValue[num]=obj.value;
	}
}

function cleanContent(){
	var content=document.forms["messageForm"].content.value;
	if(content=="您好，如果对产品感兴趣，请给我留言，我会在最快时间内回复您(2000字以内)"){
		document.forms["messageForm"].content.value="";
	}
}


//登陆的验证和提交
var hostname=location.hostname;//得到当前域名
function doSubmit1(){
	cleanContent();
	var title=document.forms["messageForm"].title.value.trim();
	var content=document.forms["messageForm"].content.value.trim();
	var validateCode=document.forms["messageForm"].validateCode.value.trim();

	var param ="";
	param+="&title="+title;
	param+="&content="+content;
	param+="&validateCode="+validateCode;
	  
	var Ajaxurl="http://"+hostname+"/b2b/mps/user/action/MessageOnlineAction/mplSubmitCheckMessage";
	new Ajax().sendPostRequest(Ajaxurl, param,ajax_callback1);
}
function ajax_callback1(resInfo){
	if(resInfo!=null && resInfo.trim()!=""){
		var strsArr= new Array(); 
		strsArr=resInfo.split(";"); //字符分割      

		var msgName="";
		var msgValue="";
		if(strsArr.length>0){
			msgName=strsArr[0];
			msgValue=strsArr[1];
		}
	
		if(msgValue!=null && msgValue!=""){
			if(msgName=="titleErrorMsg"){
				showError("titleErrorMsg",msgValue); 
				hideError("contentErrorMsg");
				hideError("codeErrorMsg");
				hideError("sendStatus");
			}else if(msgName=="contentErrorMsg"){
				showError("contentErrorMsg",msgValue);
				hideError("titleErrorMsg");
				hideError("codeErrorMsg");
				hideError("sendStatus");
			}else if(msgName=="codeErrorMsg"){
				showError("codeErrorMsg",msgValue);
				hideError("titleErrorMsg");
				hideError("contentErrorMsg");
				hideError("sendStatus");
			}
		}
	}else{
		hideError("titleErrorMsg");
		hideError("contentErrorMsg");
		hideError("codeErrorMsg");
		hideError("sendStatus");

		var Ajaxur2="http://"+hostname+"/b2b/mps/user/action/MessageOnlineAction/mplSubmitMessageOnlineSubmit";
		var title=document.forms["messageForm"].title.value.trim();
		var content=document.forms["messageForm"].content.value.trim();
		var validateCode=document.forms["messageForm"].validateCode.value.trim();
		//公共参数
		var receiverAccountid=document.forms["messageForm"].receiverAccountid.value.trim();
		var receiverId=document.forms["messageForm"].receiverId.value.trim();
		var receiverType=document.forms["messageForm"].receiverType.value.trim();
		var  receiverCorpid=document.forms["messageForm"].receiverCorpid.value.trim();
		var sourceFrom=document.forms["messageForm"].sourceFrom.value.trim();
		var type=document.forms["messageForm"].type.value.trim();
		var message_type=document.forms["messageForm"].message_type.value.trim();
		var hasLogin=document.forms["messageForm"].hasLogin.value.trim();



		var param ="";
		param+="&title="+title;
		param+="&content="+content;
		param+="&validateCode="+validateCode;
		//公共参数
		param+="&receiverAccountid="+receiverAccountid;
		param+="&receiverId="+receiverId;
		param+="&receiverType="+receiverType;
		param+="&receiverCorpid="+receiverCorpid;
		param+="&sourceFrom="+sourceFrom;
		param+="&type="+type;
		param+="&message_type="+message_type;
		param+="&hasLogin="+hasLogin;
		document.forms["messageForm"].tijiao.value="正在提交留言";
		document.forms["messageForm"].tijiao.disabled="true";
		new Ajax().sendPostRequest(Ajaxur2, param,submit_ajax_callback1);
	}
}

function submit_ajax_callback1(resInfo){
	if(resInfo!=null && resInfo.trim()!=""){
		var strsArr= new Array(); 
		strsArr=resInfo.split(";"); //字符分割      

		var msgName="";
		var msgValue="";
		if(strsArr.length>0){
			msgName=strsArr[0];
			msgValue=strsArr[1].trim();
		}

		var isLogin="$!isLogin";
		var sendStatus="";
		if(isLogin=="Y"){
			document.forms["messageForm"].title.value="";
			document.forms["messageForm"].content.value="";
			document.forms["messageForm"].validateCode.value="";
			if(msgValue.trim()=="Y") sendStatus="<font color=red>留言成功!</font>";  else  sendStatus="<font color=red>留言失败!</font>";
			showTipMsg("sendStatus",sendStatus);
		}else{ 
			document.forms["messageForm"].title.value="";
			document.forms["messageForm"].content.value="";
			document.forms["messageForm"].name.value="";
			document.forms["messageForm"].email.value="";
			document.forms["messageForm"].phone_country.value="";
			document.forms["messageForm"].phone_region.value="";
			document.forms["messageForm"].phone.value="";
			document.forms["messageForm"].phone_ext.value="";
			document.forms["messageForm"].validateCode.value="";
			if(msgValue.trim()=="Y") sendStatus="<font color=red>匿名留言成功!</font>";  else  sendStatus="<font color=red>匿名留言失败!</font>";
			showTipMsg("sendStatus",sendStatus);
		}
	}
	document.forms["messageForm"].tijiao.value="发送留言";
	document.forms["messageForm"].tijiao.disabled=false;
}

//未登陆的验证和提交 

function  doSubmit2(){
	cleanContent();
	var title=document.forms["messageForm"].title.value.trim();
	var content=document.forms["messageForm"].content.value.trim();
	var name=document.forms["messageForm"].name.value.trim();
	var email=document.forms["messageForm"].email.value.trim();
	var phone_country=document.forms["messageForm"].phone_country.value.trim();
	var phone_region=document.forms["messageForm"].phone_region.value.trim();
	var phone=document.forms["messageForm"].phone.value.trim();
	var phone_ext=document.forms["messageForm"].phone_ext.value.trim();
	var validateCode=document.forms["messageForm"].validateCode.value.trim();

	var param ="";
	param+="&title="+title;
	param+="&content="+content;
	param+="&name="+name;
	param+="&email="+email;
	param+="&phone_country="+phone_country;
	param+="&phone_region="+phone_region;
	param+="&phone="+phone;
	param+="&phone_ext="+phone_ext;
	param+="&validateCode="+validateCode;
		  
	var Ajaxurl="http://"+hostname+"/b2b/mps/user/action/MessageOnlineAction/mplSubmitCheckMessage";
	new Ajax().sendPostRequest(Ajaxurl, param,ajax_callback2);
}
function ajax_callback2(resInfo){
	if(resInfo!=null && resInfo.trim()!=""){
		var strsArr= new Array(); 
		strsArr=resInfo.split(";"); //字符分割      

		var  msgName="";
		var  msgValue="";
		if(strsArr.length>0){
			msgName=strsArr[0];
			msgValue=strsArr[1];
		}
		if(msgValue!=null && msgValue!=""){
			if(msgName=="titleErrorMsg"){
				showError("titleErrorMsg",msgValue); 
				hideError("contentErrorMsg");
				hideError("nameErrorMsg");
				hideError("emailErrorMsg");
				hideError("phoneErrorMsg");
				hideError("codeErrorMsg");
				hideError("sendStatus");
			}else if(msgName=="contentErrorMsg") {
				showError("contentErrorMsg",msgValue);
				hideError("titleErrorMsg");
				hideError("nameErrorMsg");
				hideError("emailErrorMsg");
				hideError("phoneErrorMsg");
				hideError("codeErrorMsg");
				hideError("sendStatus");
			}else if(msgName=="nameErrorMsg"){
				showError("nameErrorMsg",msgValue);
				hideError("titleErrorMsg");
				hideError("contentErrorMsg");
				hideError("emailErrorMsg");
				hideError("phoneErrorMsg");
				hideError("codeErrorMsg");
				hideError("sendStatus");
			}else if(msgName=="emailErrorMsg"){
				showError("emailErrorMsg",msgValue);
				hideError("titleErrorMsg");
				hideError("contentErrorMsg");
				hideError("nameErrorMsg");
				hideError("phoneErrorMsg");
				hideError("codeErrorMsg");
				hideError("sendStatus");
			}else if(msgName=="phoneErrorMsg"){
				showError("phoneErrorMsg",msgValue);
				hideError("titleErrorMsg");
				hideError("contentErrorMsg");
				hideError("nameErrorMsg");
				hideError("emailErrorMsg");
				hideError("codeErrorMsg");
				hideError("sendStatus");
			}else if(msgName=="codeErrorMsg"){
				showError("codeErrorMsg",msgValue);
				hideError("titleErrorMsg");
				hideError("contentErrorMsg");
				hideError("nameErrorMsg");
				hideError("emailErrorMsg");
				hideError("phoneErrorMsg");
				hideError("sendStatus");
			}
		}
	}else{
		hideError("titleErrorMsg");
		hideError("contentErrorMsg");
		hideError("nameErrorMsg");
		hideError("emailErrorMsg");
		hideError("phoneErrorMsg");
		hideError("codeErrorMsg");
		hideError("sendStatus");

		var Ajaxur2="http://"+hostname+"/b2b/mps/user/action/MessageOnlineAction/mplSubmitMessageOnlineSubmit";
		var title=document.forms["messageForm"].title.value.trim();
		var content=document.forms["messageForm"].content.value.trim();
		var name=document.forms["messageForm"].name.value.trim();
		var email=document.forms["messageForm"].email.value.trim();
		var phone_country=document.forms["messageForm"].phone_country.value.trim();
		var phone_region=document.forms["messageForm"].phone_region.value.trim();
		var phone=document.forms["messageForm"].phone.value.trim();
		var phone_ext=document.forms["messageForm"].phone_ext.value.trim();
		var validateCode=document.forms["messageForm"].validateCode.value.trim();
		//公共参数
		var receiverAccountid=document.forms["messageForm"].receiverAccountid.value.trim();
		var receiverId=document.forms["messageForm"].receiverId.value.trim();
		var receiverType=document.forms["messageForm"].receiverType.value.trim();
		var receiverCorpid=document.forms["messageForm"].receiverCorpid.value.trim();
		var sourceFrom=document.forms["messageForm"].sourceFrom.value.trim();
		var type=document.forms["messageForm"].type.value.trim();
		var message_type=document.forms["messageForm"].message_type.value.trim();
		var hasLogin=document.forms["messageForm"].hasLogin.value.trim();

		var param ="";
		param+="&title="+title;
		param+="&content="+content;
		param+="&name="+name;
		param+="&email="+email;
		param+="&phone_country="+phone_country;
		param+="&phone_region="+phone_region;
		param+="&phone="+phone;
		param+="&phone_ext="+phone_ext;
		param+="&validateCode="+validateCode;
		//公共参数
		param+="&receiverAccountid="+receiverAccountid;
		param+="&receiverId="+receiverId;
		param+="&receiverType="+receiverType;
		param+="&receiverCorpid="+receiverCorpid;
		param+="&sourceFrom="+sourceFrom;
		param+="&type="+type;
		param+="&message_type="+message_type;
		param+="&hasLogin="+hasLogin;
		document.forms["messageForm"].tijiao.value="正在提交留言";
		document.forms["messageForm"].tijiao.disabled="true";
		new Ajax().sendPostRequest(Ajaxur2, param,submit_ajax_callback2);

	}
}

function submit_ajax_callback2(resInfo){
	if(resInfo!=null && resInfo.trim()!=""){
		var strsArr= new Array(); 
		strsArr=resInfo.split(";"); //字符分割      

		var  msgName="";
		var  msgValue="";
		if(strsArr.length>0){
			msgName=strsArr[0];
			msgValue=strsArr[1].trim();
		}

		var isLogin="$!isLogin";
		var  sendStatus="";
		if(isLogin=="Y"){
			document.forms["messageForm"].title.value="";
			document.forms["messageForm"].content.value="";
			document.forms["messageForm"].validateCode.value="";
			if(msgValue.trim()=="Y")      sendStatus="<font color=red>留言成功!</font>";  else      sendStatus="<font color=red>留言失败!</font>";
			showTipMsg("sendStatus",sendStatus);
		}else{ 
			document.forms["messageForm"].title.value="";
			document.forms["messageForm"].content.value="";
			document.forms["messageForm"].name.value="";
			document.forms["messageForm"].email.value="";
			document.forms["messageForm"].phone_country.value="";
			document.forms["messageForm"].phone_region.value="";
			document.forms["messageForm"].phone.value="";
			document.forms["messageForm"].phone_ext.value="";
			document.forms["messageForm"].validateCode.value="";
			if(msgValue.trim()=="Y")     sendStatus="<font color=red>匿名留言成功!</font>";  else  sendStatus="<font color=red>匿名留言失败!</font>";

			showTipMsg("sendStatus",sendStatus);
			document.forms["messageForm"].tijiao.value="发送留言";
			document.forms["messageForm"].tijiao.disabled=false;
		}
	}
}

//用于请求后 返回提交信息
function showTipMsg(idName,msg)
{
	document.getElementById(idName).innerHTML = msg;
	document.getElementById(idName).style.display = "";
}

