
var getJson = function(url, fncb, param) {
  callAjax(url, null, fncb, param, null, "json");
}
var callAjax = function(url, dat, fncb, param, fnfl, ct) {
  var http, med, curl;
  if(window.XMLHttpRequest)
    http = new XMLHttpRequest();
  else
    http = new ActiveXObject("Microsoft.XMLHTTP");
  if(dat) {
    med = "POST";
    curl = url;
  } else {
    med = "GET";
    curl = url + (url.indexOf("?")>=0?"&":"?") + (new Date()).getTime();
  }
  http.open(med, curl, true);
  http.onreadystatechange = function(){
      callAjaxReadyState(http, fncb, param, fnfl, ct);
    };
  if(med=="POST") {
    http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    http.send(dat);
  } else {
    http.send(null);
  }
}
var callAjaxReadyState = function(http, fncb, param, fnfl, ct) {
  if(http.readyState == 4) {
    if (http.status==200 || http.status==0){
      var data = null;
      try {
        if(ct=="xml" || ct=="xmlObj" || (!ct && http.getResponseHeader("Content-Type").indexOf("text/xml")>=0)) {
          data = http.responseXML;
          if(ct=="xmlObj") data = xmlToOjb(data);
        } else {
          data = http.responseText;
          if(ct=="json" || http.getResponseHeader("Content-Type").indexOf("text/json")>=0) data = toJson(data);
        }
        if(data)
          if(fncb) fncb(data, param);
        else
          if(fnfl) fnfl(http.status, "nodata", param);
      } catch (e) {
        if(fnfl) fnfl(e.name, e.message, param);
      }
    }else{
      if(fnfl) fnfl(http.status, http.statusText, param);
    }
  }
}

var toJson = function(data) {
  eval("var d = "+data);
  return d;
}
var xmlToOjb = function(xml) {
  if(xml==null) return null;
  var obj = new Object();
  for(var i=0; i<xml.documentElement.childNodes.length; i++)
    obj[xml.documentElement.childNodes[i].nodeName] = getXmlNode(xml.documentElement.childNodes[i]);
  return obj;
}
var getXmlNode = function(nod) {
  var valu = null;
  var i;
  if(nod.childNodes && nod.childNodes.length>0 && !(nod.childNodes.length==1 && nod.childNodes[0].nodeName=="#text")) {
    valu = new Array();
    for(i=0; i<nod.childNodes.length; i++) {
      valu[i] = getXmlNode(nod.childNodes[i]);
    }
  }
  if(nod.attributes && nod.attributes.length>0) {
    if(valu==null) valu = new Object();
    for(i=0; i<nod.attributes.length; i++) {
      valu[nod.attributes[i].nodeName] = nod.attributes[i].nodeValue;
    }
  }
  if(nod.childNodes.length==1 && nod.childNodes[0].nodeName=="#text") {
    if(valu)
      valu["value"] = nod.childNodes[0].nodeValue;
    else
      valu = nod.childNodes[0].nodeValue;
  }
  if(valu==null && nod.nodeValue!=null) valu = nod.nodeValue;
  return valu;
}

var loadHtml = function(dvid, url, dat) {
  callAjax(url, dat, loadHtmlRet, dvid);
}
var loadHtmlRet = function(data, dvid) {
  var dv = document.getElementById(dvid);
  if(dv) {
    dv.innerHTML = data;
    if(pngfix) pngfix();
  }
}


function getLeftTop(ee) {
  var el = ee;
  var showy = 0, showx = 0;
  while(el) {
    showy += el.offsetTop;
    showx += el.offsetLeft;
    if(el.tagName=="DIV") {
      showy -= el.scrollTop
      showx -= el.scrollLeft
    }
    el = el.offsetParent;
  }
  return {left:showx, top:showy};
}

var getDocumentLeftTop = function() {
  var sctop = 0, scleft = 0;
  if (typeof window.pageYOffset != 'undefined') {
    sctop = window.pageYOffset;
    scleft = window.pageXOffset;
  } else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
    sctop = document.documentElement.scrollTop;
    scleft = document.documentElement.scrollLeft;
  }else if (typeof document.body != 'undefined') {
    sctop = document.body.scrollTop;
    scleft = document.body.scrollLeft;
  }
  return {left:scleft, top:sctop};
}

var getDocumentViewWH = function() {
  var ww = 0, hh = 0;

  if(document.documentElement.clientWidth>0 && (ww==0 || document.documentElement.clientWidth<ww)) ww = document.documentElement.clientWidth;
  if(document.body.clientWidth>0 && (ww==0 || document.body.clientWidth<ww)) ww = document.body.clientWidth;

  if(document.documentElement.clientHeight>0 && (hh==0 || document.documentElement.clientHeight<hh)) hh = document.documentElement.clientHeight;
  if(document.body.clientHeight>0 && (hh==0 || document.body.clientHeight<hh)) hh = document.body.clientHeight;

  return {w:ww, h:hh};
}


function dosearch() {
  var kw = document.getElementById("ipt_sch_keyw").value;
  var url = "cross!search"+(kw?("?keyw="+encodeURIComponent(kw)):"");
  window.location = url;
}


function initMsg() {
  var str = '<div id="div_msg_sh" style="position:absolute; display:none; width:210px; background-color:#99C6ED; border:1px solid #75A7F2; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; z-index:9999;">'
        + '  <div id="div_msg_cn" style="padding:15px 10px 10px; text-align:center; font-size:14px; color:#38708c;"></div>'
        + '</div>';
  document.write(str);
}
var _nedrload = false;
var _dmsgopa = 0;
function showMsgReload(msg, ib) {
  _nedrload = ib;
  showMsg(msg, ib);
}
function showMsg(msg, ib) {
  var div1 = document.getElementById("div_msg_sh");
  var div2 = document.getElementById("div_msg_cn");
  if(div1 && div2) {
    var ss = "";
    if(arguments.length>1) ss = '<img src="/images/signup_'+(ib?'yes':'no')+'.png" height="25" align="absmiddle" /> ';
    ss += msg;
    div2.innerHTML = ss;
    var w = 200, h = 60;
    var dtl = getDocumentLeftTop();
    var dwh = getDocumentViewWH();
    div1.style.left = (dtl.left + (dwh.w - w)/2) + "px";
    div1.style.top = (dtl.top + (dwh.h - h-50)/2) + "px";
    _dmsgopa = 0;
    setMsgShow();
  } else {
    window.alert(msg);
  }
}
function setOpacity(div, a) {
  div.style.opacity = (a/10);
  div.style.filter = "alpha(opacity="+(a*10)+")";
}
function setMsgShow() {
  var div = document.getElementById("div_msg_sh");
  if(!div) return;
  _dmsgopa++;
  setOpacity(div, Math.abs(_dmsgopa));
  if(_dmsgopa==0) {
    div.style.display = "none";
  } else if(_dmsgopa==10) {
    _dmsgopa *= -1;
    window.setTimeout(setMsgShow, 2000);
  } else {
    if(_dmsgopa==1) div.style.display = "";
    window.setTimeout(setMsgShow, 50);
  }
  if(_nedrload && _dmsgopa==-10) window.location.reload();
}


function initAuthmb() {
  var str = '<div id="div_auth_mb" style="position:absolute; display:none; width:210px; background-color:#99C6ED; border:1px solid #75A7F2; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; z-index:9999;">'
          + '  <div style="position:absolute; top:3px; right:3px;"><a href="javascript:cancelAuthmb();" class="alink1">关闭</a></div>'
          + '  <div id="div_auth_step1" style="margin:10px;">'
          + '    <div style="margin:3px;">请输入您的手机号码</div>'
          + '    <div style="margin:3px;"><input title="input" class="center_input" maxlength="11" style="width:120px; height:16px; line-height:14px; padding:1px 2px;" id="ipt_auth_mb" /></div>'
          + '    <div style="margin:3px;"><input type="button" value="下一步" onclick="sendCodemb();"/></div>'
          + '    <div style="margin:3px; font-size:11px;color:#628FAC;">我们将发送一条短信到您的手机</div>'
          + '  </div>'
          + '  <div id="div_auth_step2" style="margin:10px; display:none;">'
          + '    <div style="margin:3px;">请输入您收到的验证码</div>'
          + '    <div style="margin:3px;"><input title="input" class="center_input" maxlength="6" style="width:60px; height:16px; line-height:14px; padding:1px 2px;" id="ipt_auth_code" />'
          + '      <input type="button" value=" 确认 " onclick="chkCodemb();"/></div>'
          + '    <div style="margin:3px; font-size:11px;color:#628FAC;">如果您在1分钟后还没有收到短信<br>请点击这里[<a href="javascript:sendCodembR()" class="alink1">重发</a>]</div>'
          + '  </div>'
          + '</div>';
  document.write(str);
}
var _auth_mb;
function doAuthmb() {
  var div = document.getElementById("div_auth_mb");
  if(div) {
    var w = 200, h = 60;
    var dtl = getDocumentLeftTop();
    var dwh = getDocumentViewWH();
    div.style.left = (dtl.left + (dwh.w - w)/2) + "px";
    div.style.top = (dtl.top + (dwh.h - h-50)/2 - 110) + "px";
    div.style.display = "";
  }
}
function sendCodemb() {
  var mb = document.getElementById("ipt_auth_mb").value;
  if(mb=="") {
    showMsg("请输入手机号码");
    return;
  }
  var reg = /^(((13[0-9]{1})|15[0-9]{1}|18[0-9]{1}|)+\d{8})$/;
  if(!reg.test(mb)) {
    showMsg("请输入正确的手机号码");
    return;
  }
  _auth_mb = mb;
  var url = "center!sendAuthCode?mb="+mb;
  getJson(url, sendCodembRet);
}
function sendCodembRet(data) {
  if(data.ret) {
    var div = document.getElementById("div_auth_step1");
    if(div) div.style.display = "none";
    div = document.getElementById("div_auth_step2");
    if(div) div.style.display = "";
  } else {
    showMsg(data.msg);
  }
}
function sendCodembR() {
  var url = "center!sendAuthCode?mb="+_auth_mb+"&r=1";
  getJson(url, sendCodembrRet);
}
function sendCodembrRet(data) {
  showMsg(data.msg);
}
function chkCodemb() {
  var cc = document.getElementById("ipt_auth_code").value;
  if(cc=="") {
    showMsg("请输入验证码");
    return;
  }
  if(cc.length!=6) {
    showMsg("输入的验证码不正确");
    return;
  }
  var url = "center!checkAuthCode?code="+cc;
  getJson(url, chkCodembRet);
}
function chkCodembRet(data) {
  showMsg(data.msg);
  if(data.ret) {
    var div = document.getElementById("div_auth_mb");
    if(div) div.style.display = "none";
    div = document.getElementById("sp_auth_mb");
    if(div) div.innerHTML = '<img src="images/auth_v.gif" title="手机认证" align="absmiddle"/>';
    _isauthmb = true;
  }
}
function cancelAuthmb() {
  var div = document.getElementById("div_auth_mb");
  if(div) div.style.display = "none";
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
