﻿var menuTimerLogin=0;
function MenumouseOverLogin(id)
{   
    if (menuTimerLogin!=0)
    {        
        clearTimeout(menuTimerLogin);
        menuTimerLogin=0;             
    }
    document.getElementById(id).style.display ="block";
}
function MenumouseOutLogin(id)
{    
    if (menuTimerLogin==0)    
        menuTimerLogin=setTimeout("HideMenuLoggedLogin('"+id+"')", 200);        
}
function HideMenuLoggedLogin(id)
{   
    document.getElementById(id).style.display ="none";                   
    menuTimerLogin=0;   
}
var isIe=(document.all)?true:false;
var currentContent;
//让背景渐渐变暗
function showBackground(obj,endInt)
{
    if(isIe)
    {
        obj.filters.alpha.opacity+=5;
        if(obj.filters.alpha.opacity<endInt)
        {
            setTimeout(function(){showBackground(obj,endInt)},20);
        }
    }
    else
    {
        al=parseFloat(obj.style.opacity)+0.05
        obj.style.opacity=al;
        if(al<=(endInt/100))
        {
            setTimeout(function(){showBackground(obj,endInt)},20);
        }
    }
}

//设置select的可见状态
function setSelectState(state)
{
    var objl=document.getElementsByTagName('select');
    for(var i=0;i<objl.length;i++)
    {
        objl[i].style.visibility=state;
    }
}

function getCenterPosition(divWidth,divHeight)
{
    var x1=0,y1=0;    
    var width=document.documentElement.clientWidth;
    var height=document.documentElement.clientHeight;
    x1=(width-divWidth)/2+document.documentElement.scrollLeft;//document.body.scrollLeft;
    y1=(height-divHeight)/2+document.documentElement.scrollTop;//document.body.scrollTop;
    x1=(x1<0?0:x1);
    y1=(y1<0?0:y1);
    return{ x:x1,y:y1 };
}

//弹出方法
function showMessageBox(contentObj,iwidth,iheight,param)
{
closeWindow();
var bWidth=parseInt(document.documentElement.scrollWidth);
var bHeight=parseInt(document.documentElement.scrollHeight);
if(isIe){setSelectState('hidden');}
var fullScreen=document.createElement("div");
fullScreen.id="fullScreen";
var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
fullScreen.style.cssText=styleStr;
document.body.appendChild(fullScreen);
showBackground(fullScreen,50);

var pos=getCenterPosition(iwidth,iheight);
contentObj.myWidth=iwidth;
contentObj.myHeight=iheight;
contentObj.style.left=pos.x+"px";
contentObj.style.top=pos.y+"px";
   contentObj.innerHTML=getBoxHtml();

currentContent=contentObj;
if(param.indexOf("active=logout")>0)
   loginPostUrl("active=logout");
document.body.appendChild(contentObj);
}

//层顶上的提示信息
function setTitleTxt(html){
  if(currentContent)
   currentContent.innerHTML='<div align=left style="border:solid 5px #DEEFFA;border-bottom:none;background-color:#F2F9FD;padding:5px;font-size:14px;color:red;">'+ html +'</div>'+currentContent.innerHTML;
}

//关闭窗口
function closeWindow()
{
    //debugger;
    if(currentContent && currentContent!=null)
    {
        if(document.getElementById("phideDiv")){
          document.getElementById("phideDiv").appendChild(currentContent)
          currentContent=null;
        }
        else
          currentContent.style.display="none";
    }

    if(document.getElementById("fullScreen")!=null)
    {
        document.getElementById("fullScreen").parentNode.removeChild(document.getElementById("fullScreen"));
    }
    if(isIe){ setSelectState('');}
}

window.onresize=function()
{
    if (currentContent!=null)
    {
        var pos=getCenterPosition(currentContent.myWidth,currentContent.myHeight);
        currentContent.style.left=pos.x+"px";
        currentContent.style.top=pos.y+"px";
    }
    if(document.getElementById("fullScreen")!=null)
    {
        var fullScreen=document.getElementById("fullScreen");
        fullScreen.style.width=document.documentElement.scrollWidth+"px";
        fullScreen.style.height=document.documentElement.scrollHeight+"px";
    }
    
}

//关闭当前对话，启动另外的对话框
function showOtherBox(contentObj,iwidth,iheight)
{
    //debugger;
    if(currentContent && currentContent!=null)
    {
        document.getElementById("phideDiv").appendChild(currentContent)
        currentContent=null;
    }
    
    var pos=getCenterPosition(iwidth,iheight);
    contentObj.myWidth=iwidth;
    contentObj.myHieght=iheight;
    contentObj.style.left=pos.x+"px";
    contentObj.style.top=pos.y+"px";
    currentContent=contentObj;
    document.body.appendChild(contentObj);
}

/*弹出登录框*/
function showLoginBox(param,elementname)
{
    elementname=document.getElementById(elementname);
    if(!elementname){
       elementname=document.createElement("div");
       elementname.style.width="410px";
       elementname.style.height="260px";
       elementname.style.position="absolute";
    }
    showMessageBox(elementname,412,262,param);
}

/*显示的html*/
function getBoxHtml(){
  var html = '<div style="border:solid 5px #DEEFFA; background-color:#F2F9FD; width:370px; height:250px; padding: 0 0 0 30px; margin:0 auto; text-align:left; margin:0 auto; line-height:180%;font-size:12px"> ';
      html += '<br /><img src="http://';
      html += mydomain;
      html +='/public/images/logo_zpgy.gif" alt="" /><br /><br />';
      html += '用户名：<input type="text" maxlength="20" id="zp365tbLoginUserName" style="border-color:#DEEFFA;border-width:1px;border-style:Solid;width:120px;" />　<br />';
      html += '密　码：<input type="password" id="zp365tbLoginPassword" onkeydown="if(event.keyCode==13){loginPostUrl(null);}" style="border-color:#DEEFFA;border-width:1px;border-style:Solid;width:120px;" />';
      html += '<span>　</span>';
      html += '<select id="zp365drpLoginOldUser">';
	  html += '<option value="">其他网站用户请选择</option>';
	  html += '<option value="gxhouse.com">房产街用户</option>';
	  html += '<option value="gxfdc.cn">房地产信息网用户</option>';
	  html += '<option value="';
	  html += pcatedomain;
	  html += '">众品网卡号或用户名</option>';
	  html += '<option value="';
	  html += pcatedomain;
	  html += '_nickname">众品网昵称</option>';
      html += '</select><br /><br />';
      html += '<input type="submit" name="btLogin" value="登录" id="btLogin" onclick="loginPostUrl(null);" />　&nbsp;';
      html += '<input id="Button1" type="button" value="返回" style="width:60px;" onclick="closeWindow()" />　　<a target="_top" href="http://my.zp365.com/PassportReg.aspx">注册新用户</a></div>';
  return html;
}
function loginPostUrl(pars){
  var aTxt="正在登录……";
   if(!pars){
      if(document.getElementById("zp365tbLoginUserName").value.replace(/(^\s*)|(\s*$)/g,'')=="" || document.getElementById("zp365tbLoginPassword").value.replace(/(^\s*)|(\s*$)/g,'')=="")
      {
         alert('用户名和密码不能为空！');
         return
      }
      
      pars="tbUserName=" + encodeURIComponent(document.getElementById("zp365tbLoginUserName").value);
      pars+="&tbPassword=" + encodeURIComponent(document.getElementById("zp365tbLoginPassword").value);
      pars+="&drpOldUser=" + document.getElementById("zp365drpLoginOldUser").value;
   }
   else{
     pars = "active=logout";
     aTxt="正在登出……";
   }
   var html='<div style="border:solid 5px #DEEFFA; background-color:#F2F9FD; width:370px; height:250px; padding: 0 0 0 30px; margin:0 auto; text-align:left; margin:0 auto; line-height:180%">';
       html+='<img src="http://'+mydomain+'/public/images/load.gif" hspace="30" vspace="30" />'+aTxt+'</div>';
    currentContent.innerHTML=html;
    
    var url=serverUrl+'/public/Login.aspx?'+pars;
    var oHead = document.getElementsByTagName('HEAD').item(0);
    var oScript= document.createElement("script");
    oScript.type = "text/javascript";
    oScript.charset="utf-8";
    oScript.src=url;
    oHead.appendChild( oScript);     
}
