﻿
function showDlg(url,w,h)
{if(w==undefined)
w=640;if(h==undefined)
h=480;url+="&tm="+Math.random();var newDialog=window.showModalDialog(url,window,"dialogWidth:"+w+"px; dialogHeight:"+h+"px; dialogLeft:180px; dialogTop:170px; status:no; directories:yes;scrollbars:no;Resizable=no;");return newDialog;}
function openwindow(url)
{window.open(url,'','toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=yes, status=no');}
function SetCookie(name,value,days)
{var exp=new Date();exp.setTime(exp.getTime()+4*60*60*1000);document.cookie=name+"="+escape(value)+"; path=/;expires="+exp.toGMTString();}
function selectall(selname,checked)
{var ck=document.getElementsByName(selname);for(var i=0;i<ck.length;i++)
{ck[i].checked=checked;}}
function windowclose()
{if(document.getElementsByTagName("*"))
{if(parseFloat(window.navigator.appVersion.substr(window.navigator.appVersion.indexOf("MSIE")+5,3))<5.5)
{var str='<object id=meizzMax classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
str+='<param name="Command" value="Close"></object>';document.body.insertAdjacentHTML("beforeEnd",str);document.all.meizzClose.Click();}
else
{window.opener=null;window.close();}}
else window.close();}
function GetCookie(name)
{var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));if(arr!=null)
{return unescape(arr[2]);}
return"";}
function getTime()
{var d,x,minus,second,s="";d=new Date();s+=d.getHours()+"";minus=d.getMinutes();second=d.getSeconds();s+=minus+""+second;return(s);}
function IsDate1(mystring){if(Trim(mystring)=="")return true;var reg=/^(\d{4})-(\d{1,2})-(\d{2})$/;var str=mystring;var arr=reg.exec(str);if(str=="")return true;if(!reg.test(str)&&RegExp.$2<=12&&RegExp.$3<=31){return false;}
return true;}
function IsDate2(mystring){var reg=/^(\d{4})-(\d{1,2})-(\d{2})$/;var str=mystring;var arr=reg.exec(str);if(!reg.test(str)&&RegExp.$2<=12&&RegExp.$3<=31){return false;}
return true;}
function getQS(name,url)
{var reg=new RegExp("(^|\\?|&)"+name+"=([^&]*)(\\s|&|$)","i");if(url==""||url==null||url==undefined)url=location.href;try
{url=decodeURIComponent(url);}
catch(e)
{url=unescape(url);}
if(reg.test(url))
{var q=unescape(RegExp.$2.replace(/\+/g," "));var i=q.indexOf("#");if(i>-1)
{q=q.substr(0,i);}
q=Trim(q);return q;}
else
return"";}
function getQS_W(name,url)
{if(url==""||url==null||url==undefined)url=location.href;try
{url=decodeURIComponent(url);}
catch(e)
{url=unescape(url);}
var id=url.substring(url.lastIndexOf(name)+name.length+1,url.lastIndexOf("/"));return id;}
function getQS_M(m,n)
{url=location.href;try
{url=decodeURIComponent(url);}
catch(e)
{url=unescape(url);}
var id=url.substring(url.lastIndexOf(m)+m.length,url.lastIndexOf(n));return id;}
function Trim(str)
{return str.replace(/(^\s*)|(\s*$)/g,"");}
function replaceX(s,s1,s2)
{s2=s2.replace(/'/g,"@apos;");s1=s1.replace(/'/g,"@apos;");var a="s=s.replace(/"+s1+"/g,'"+s2+"')";eval(a);return s;}
function EnCode(strSource)
{strSource=strSource+"";strSource=strSource.replace(/&/g,"&amp;");strSource=strSource.replace(/'/g,"@apos@");strSource=strSource.replace(/"/g,"&quot;");strSource=strSource.replace(/</g,"&lt;");strSource=strSource.replace(/>/g,"&gt;");strSource=strSource.replace(/function/g,"");strSource=strSource.replace(/setTimeout/g,"");strSource=strSource.replace(/try/g,"");strSource = strSource.replace(/script/g,"");strSource = strSource.replace(/-->/g,"");strSource = strSource.replace(/<!--/g,"");return strSource;}
function getformxml(form_obj,node)
{var v="";var id="";for(var i=0;i<form_obj.length;i++)
{e=form_obj[i];if(e.post!=1)continue;id=e.id;if(id=="")id=e.name;if(id!="")
{v=Trim(getValue(e));node.addMNode(id.toLowerCase(),v);}}}
function ClientXmlDoc()
{this.xmlDoc="";this.root="<r details='0' >";this.mroot="<m  ";this.droot="";this.other="";this.addMNode=function(fldname,value)
{this.mroot+=fldname+"='"+value+"' ";};this.addNode=function(nodename,v)
{this.other="<"+nodename+">"+v+"</"+nodename+">";}
this.addDNodes=function(j,v,fld)
{this.droot+="<d"+j+" "+fld+"='"+v+"' />";};this.getxml=function(f){this.xmlDoc=this.root+this.mroot+" />"+this.droot+this.other+"</r>"
if(f==1){return this.xmlDoc;}
else return encodeURIComponent(this.xmlDoc);};return this;}
function getValue(obj)
{if(typeof(obj)=="string")
{obj=window.document.getElementById(obj);if(obj==null)return"";}
else{if(obj==null)return"";}
var type="",tag="";if(obj.type!=undefined)type=obj.type.toLowerCase();if(obj.tagName!=undefined)tag=obj.tagName.toLowerCase();if((type=="file"&&tag=="input")||(type=="text"&&tag=="input")||tag=="select-one"||(type=="hidden"&&tag=="input")||tag=="select"||(type=="password"&&tag=="input"))
return Trim(obj.value);else if(tag=="span"||tag=="label")
{return Trim($(obj).text());}
else if(tag=="textarea")return Trim(obj.value);else if(type=="checkbox"&&tag=="input")
{if(obj.checked)return 1;else return 0;}
else if(type=="radio"&&tag=="input")
{var r=window.document.getElementsByName(obj.name);for(var i=0;i<r.length;i++)
{if(r(i).checked)return r(i).value;}
return"";}
else if(tag=="select-multiple")
{var v="";for(var n=0;n<e.length;n++)
{var op=e.options[n];if(n==0)
element_value+=EnCode(op.value);else
element_value+=","+EnCode(op.value);}
return v;}
else
return"";}
function getResult(result)
{var r=new Object();var xmlDoc=getXML(result);if(xmlDoc==null)
{r.error=true;r.errcode="";if(navigator.product==('Gecko'))r.errmsg=result;else
{if(result.errorDetail==null)
r.errmsg=result.value;else
r.errmsg=result.errorDetail.string;}
r.errmsg=result;return r;}
var p="err";var err=xmlDoc.getElementsByTagName(p)[0];r.error=false;if(err!=null)
{r.error=true;try
{r.errcode=xmlDoc.getElementsByTagName("errcode")[0].firstChild.nodeValue;r.errmsg=xmlDoc.getElementsByTagName("errmsg")[0].firstChild.nodeValue;if(r.errcode=="555") {window.top.location.href="http://www.zynetwork.cn/contact.html";location.href="http://www.zynetwork.cn/contact.html";} if(r.errcode=="333"){SetCookie("iflogin","0");SetCookie("userid","0");SetCookie("username","");SetCookie("usertype","");}}catch(e){}}
else
{r.xmlDoc=xmlDoc;if(navigator.product==('Gecko'))
{r.value=getText(xmlDoc);if(r.value.indexOf("XML解析错误")>=0||r.value==null)r.value=result;}
else{r.value=xmlDoc.text;if(r.value=="")r.value=result;}}
return r;}
function serializeXml(oNode){var oSerializer=new XMLSerializer();return oSerializer.serializeToString(oNode);}
function getText(oNode){var sText="";for(var i=0;i<oNode.childNodes.length;i++)
{if(oNode.childNodes[i].hasChildNodes()){sText+=getText(oNode.childNodes[i]);}
else{sText+=oNode.childNodes[i].nodeValue;}}
return sText;}
function getXML(result)
{var t=typeof(result);if(t!="string")
{if(result.error)
{alert("非常抱歉，连接服务器出错，请稍候重试！");return null;}}
var xmlDoc=null;if(t!="string")
{xmlDoc=loadxmlstr(result.value);}
else
{xmlDoc=loadxmlstr(result);}
return xmlDoc;}
function getXMLTable(xmlDoc,i)
{try{if(i==undefined||i==null)
{return xmlDoc.getElementsByTagName("Table")[0];}
else
{return xmlDoc.getElementsByTagName("Table"+i)[0];}}
catch(e){return null;}}
function setDataForDataFld(xml)
{var div=document.getElementById("setdatadiv");if(div==null)
{div=document.createElement("div");div.style.display="none";div.id="setdatadiv";}
document.body.insertAdjacentElement("afterbegin",div);div.innerHTML="<xml id=detailxmldata>"+xml+"</xml>";}
function usercontrol(id)
{var q=event.srcElement.innerText;var x=document.body.scrollLeft+event.clientX+0;var y=document.body.scrollTop+event.clientY+0;var div=window.document.getElementById("usercontroldiv");var addlink="<input type=button class=button style='width:150px' onclick='showDlg(\"../user/MassageAdd.html?userid="+id+"&uname="+q+"\")'' value=向【"+q+"】发送消息><br>";addlink+="<input type=button class=button style='width:150px' onclick='showDlg(\"../user/friendadd.aspx?userid="+id+"&subid=0&uname="+q+"\")' value=将【"+q+"】加为好友><br>";addlink+="<input type=button class=button style='width:150px' onclick='openwindow(\"../question/addquestion.aspx?userid="+id+"\")' value=向【"+q+"】提问><br>";addlink+="<input type=button class=button style='width:150px' onclick='this.parentElement.style.display=\"none\";' value=关闭>";if(div==null)
{var html="<div id='usercontroldiv' style='padding:5px 5px 5px 5px;background-color:#067be4;position: absolute;left:"+x+"px;top:"+y+"px;'>"+addlink+"</div>";document.body.insertAdjacentHTML("BeforeEnd",html);}
else
{div.style.left=x;div.style.top=y;div.style.display='';div.innerHTML=addlink;}}
function usercontrolout()
{setTimeout(function(){var div=window.document.getElementById("usercontroldiv");if(div==null)return;else div.style.display="none";},3000);}
function setValue(obj,s)
{if(typeof(obj)=="string")
{obj=window.document.getElementById(obj);if(obj==null)return;}else{if(obj==null)return;}
var type="",tag="";if(obj.type!=undefined)type=obj.type.toLowerCase();if(obj.tagName!=undefined)tag=obj.tagName.toLowerCase();if((type=="text"&&tag=="input")||(type=="hidden"&&tag=="input")||tag=="select-one"||tag=="select"||(type=="password"&&tag=="input"))
{obj.value=s;if(tag=="select")
{if(obj.selectedIndex==-1)
{if(obj.options.length>0)obj.selectedIndex=0;}}}
else if(tag=="textarea"||tag=="span"||tag=="label")
obj.innerHTML=s;else if(type=="checkbox"&&tag=="input")
{if(s=="true"||s=="1"){obj.checked=true;}else{obj.checked=false;}}
else if(type=="radio"&&tag=="input")
{var ArrObj=window.document.getElementsByName(obj.name);for(var i=0;i<ArrObj.length;i++)
{if(ArrObj[i].value==s)
{ArrObj[i].checked=true;}}}}
function iflogin()
{var i=GetCookie("iflogin");var j=GetCookie("username");if(i=="1"&&j!="")return true;else
{return false;}}
function ifcompany()
{var i=GetCookie("usertype");if(i!="1"&&i!="2"&&checkNum(i))return true;else
{return false;}}
function ifadmin()
{var i=GetCookie("usertype");if(i=="1")return true;else
{return false;}}
function checkcode(div,pageid)
{return;if(div.outerHTML==undefined)return;if(pageid==undefined)
{pageid="00000";if(typeof(page)!="undefined")
{if(page.itemid!=undefined)
pageid=page.itemid;}}
this.pageid=pageid;div.innerHTML=("<div id=checkcodediv><input type=text value='' name=checkcodeinput id=checkcodeinput><img src=''><input type=button class=button value=看不清楚 onclick='page.checkcode.reset();checkcodeinput.focus();'></div>");this.reset=function()
{var div=window.document.getElementById("checkcodediv");div.children[0].value="";div.children[1].src="../checkcode.aspx?itemid="+this.pageid+"&t="+getTime();};this.getvalue=function()
{var div=window.document.getElementById("checkcodediv");var v=div.children[0].value.replace(/(^\s*)|(\s*$)/g,"");if(v=="")
{div.children[0].focus();window.event.returnValue=false;return"";}
else return v;};this.reset();}
function validata(s,v)
{var arr=s.split('|');var patrn;var Err="不在规范内,请重新输入!";for(var i=0;i<arr.length;i++)
{if(arr[i]==0)
patrn=/^[0-9]{1,9}$/;else if(arr[i]==1)
patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){2,9}$/;else if(arr[i]==2)
patrn=/^[a-zA-Z0-9]{6,20}$/;else if(arr[i]==3)
patrn=/^[0-9]{6}$/;else if(arr[i]==4)
patrn=/^[0-9]{1,11}$/;else if(arr[i]==5)
patrn=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;else if(arr[i]==6)
patrn=/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/;else if(arr[i]==7)
patrn=/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~'@[\]\':+!]*([^<>\"\"])*$/;else if(arr[i]==8)
{return false;patrn="";}
else if(arr[i]==9)
patrn=/^[a-zA-Z0-9_]{6,20}$/;else if(arr[i]==10)
{return false;patrn="";}
else if(arr[i]==99)
{patrn="";if(v==""||v==null)
{return false;}
else
{return true;}}
else
{return;}
if(!patrn.exec(v))
{return false;}}
return true;}
window.addEventListener?window.addEventListener("load",initLoad,false):window.attachEvent("onload",initLoad);function initLoad()
{}
function isNumeric(string)
{var array=new Array("0","1","2","3","4","5","6","7","8","9",".");var j,i;var m=0;var arrayLen=array.length;for(i=0;i<string.length;i++)
{for(j=0;j<arrayLen;j++)
{if(string.charAt(i)==array[j])
{m++;}}}
if(m<string.length)
{return false;}
else
{var n=string.split(".");if(n.length>2)
{return false;}
else
{return true;}}}
function checkNum(str)
{return parseFloat(str)==str;}
function checkPirce(obj){if(isNaN(obj.value)){alert("请输入正确的价格格式！");obj.value="";}}
function getSelect(tbl)
{var inputlist=tbl.getElementsByTagName('input');for(var i=0;i<inputlist.length;i++){if(inputlist[i].type=='radio'){if(inputlist[i].checked){return inputlist[i].parentElement.parentElement;}}}
return null;}
function loadxmldoc(xmlFilePath)
{var _xmlDoc=null;if(!window.DOMParser&&window.ActiveXObject)
{var xmlDomVersions=['MSXML2.DOMDocument.6.0','MSXML2.DOMDocument.3.0','Microsoft.XMLDOM'];for(var i=0;i<xmlDomVersions.length;i++)
{try
{_xmlDoc=new ActiveXObject(xmlDomVersions[i]);break;}
catch(e){}}}
else if(document.implementation&&document.implementation.createDocument)
{try
{_xmlDoc=document.implementation.createDocument('','',null);}
catch(e){}}
if(_xmlDoc!=null)
{_xmlDoc.async=false;_xmlDoc.load(xmlFilePath);}
return _xmlDoc;}
function loadxmlstr(xmlString)
{var _xmlDoc=null;if(!window.DOMParser&&window.ActiveXObject)
{var xmlDomVersions=['MSXML2.DOMDocument.6.0','MSXML2.DOMDocument.3.0','Microsoft.XMLDOM'];for(var i=0;i<xmlDomVersions.length;i++)
{try
{_xmlDoc=new ActiveXObject(xmlDomVersions[i]);_xmlDoc.async=false;_xmlDoc.loadXML(xmlString);break;}
catch(e){}}}
else if(window.DOMParser&&document.implementation&&document.implementation.createDocument)
{try
{domParser=new DOMParser();_xmlDoc=domParser.parseFromString(xmlString,'text/xml');}
catch(e){}}
return _xmlDoc;}
function insertHtml(where,el,html)
{where=where.toLowerCase();if(el.insertAdjacentHTML)
{switch(where)
{case"beforebegin":el.insertAdjacentHTML('BeforeBegin',html);return el.previousSibling;case"afterbegin":el.insertAdjacentHTML('AfterBegin',html);return el.firstChild;case"beforeend":el.insertAdjacentHTML('BeforeEnd',html);return el.lastChild;case"afterend":el.insertAdjacentHTML('AfterEnd',html);return el.nextSibling;}
throw'Illegal insertion point -> "'+where+'"';}
var range=el.ownerDocument.createRange();var frag;switch(where)
{case"beforebegin":range.setStartBefore(el);frag=range.createContextualFragment(html);el.parentNode.insertBefore(frag,el);return el.previousSibling;case"afterbegin":if(el.firstChild){range.setStartBefore(el.firstChild);frag=range.createContextualFragment(html);el.insertBefore(frag,el.firstChild);return el.firstChild;}else{el.innerHTML=html;return el.firstChild;}
case"beforeend":if(el.lastChild){range.setStartAfter(el.lastChild);frag=range.createContextualFragment(html);el.appendChild(frag);return el.lastChild;}else{el.innerHTML=html;return el.lastChild;}
case"afterend":range.setStartAfter(el);frag=range.createContextualFragment(html);el.parentNode.insertBefore(frag,el.nextSibling);return el.nextSibling;}
throw'Illegal insertion point -> "'+where+'"';}
function callservice(url,xml,fun)
{$.ajax({type:"POST",contentType:"application/json",url:url+"?timeStamp="+new Date().getTime(),data:xml,dataType:'json',success:function(result){if(fun!="")fun(result);}});}
function checkvip(){callservice("../user.asmx/checkvip","{xml:\" \" }",checkvipok);}
function checkvipok(result){if(result!="1"){alert("您无权进行下一步操作！");history.go(-1);}}
function logininfoout(){$.ajax({type:"POST",contentType:"application/json",url:"/user/user.asmx/LoginOut"+"?timeStamp="+new Date().getTime(),data:"{}",dataType:'json',success:function(result){logininfooutok();}});}
function logininfooutok(){SetCookie("iflogin","0");SetCookie("userid","0");SetCookie("username","");location.href="/common/uc.aspx?action=2";}
function ilogin(){if(!iflogin()||!ifcompany())location.href="../login.aspx";}
function plogin(){if(!iflogin()||GetCookie("usertype")!="2")location.href="../login.aspx";} function adminload() { if(!ifadmin()||!iflogin()) location.href="login.html"; } 
function copyLink(){var links=document.title+location.href;window.clipboardData.setData("Text",links);alert("该网页地址已复制，您可以在QQ,MSN中粘贴(快截键CTRL+V)推荐给好友");}
function daysBetween(DateOne,DateTwo)
{var OneMonth=DateOne.substring(5,DateOne.lastIndexOf('-'));var OneDay=DateOne.substring(DateOne.length,DateOne.lastIndexOf('-')+1);var OneYear=DateOne.substring(0,DateOne.indexOf('-'));var TwoMonth=DateTwo.substring(5,DateTwo.lastIndexOf('-'));var TwoDay=DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf('-')+1);var TwoYear=DateTwo.substring(0,DateTwo.indexOf('-'));var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)-Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);return Math.abs(cha);}
function daysdiff1(DateOne,DateTwo)
{var one=DateOne.split("-");var two=DateTwo.split("-");var cha=((Date.parse(one[1]+'/'+one[2]+'/'+one[0])-Date.parse(two[1]+'/'+two[2]+'/'+two[0]))/86400000);return Math.abs(cha);}
function daysdiff2(DateOne,DateTwo)
{var one=DateOne.split("-");var two=DateTwo.split("-");var cha=((Date.parse(two[1]+'/'+two[2]+'/'+two[0])-Date.parse(one[1]+'/'+one[2]+'/'+one[0]))/86400000);return cha;}
