﻿function DrawImage(ImgD,maxWidth,maxHeight,minWidth,minHeight)
{
     var flag=false;
     var  image=new  Image();
     image.src=ImgD.src;
     if(image.width>0  &&  image.height>0)
       {
         flag=true;       
               if(image.width>=maxWidth||image.height>=maxHeight)
               {
               if(image.width/image.height >=  maxWidth/maxHeight){
                 if(image.width>maxWidth){
                 ImgD.width=maxWidth;
                 ImgD.height=(image.height*maxWidth)/image.width;
                 }
                              
                 }
               else{
                 if(image.height>maxHeight){
                 ImgD.height=maxHeight;
                 ImgD.width=(image.width*maxHeight)/image.height;
                 }
               
                 
                 }
              }else if(image.width<=minWidth||image.height<=minHeight)
               {
               if(image.width/image.height >=  minWidth/minHeight){
                 if(image.width<minWidth){
                 ImgD.width=minWidth;
                 ImgD.height=(image.height*minWidth)/image.width;
                 }
                            
                 }
               else{
                 if(image.height<minHeight){
                 ImgD.height=minHeight;
                 ImgD.width=(image.width*minHeight)/image.height;
                 }
                             
                 }
              }else{
                ImgD.height=image.height;
                ImgD.width=image.width;
               
              }
       }       
}
function choosediv(aa)
{ 
    switch(aa)
    {
        case 0:document.getElementById("choose_left").className="Property_Content_div_right_title_current";
               document.getElementById("choose_center").className="Property_Content_div_right_title_center"; 
               document.getElementById("choose_right").className="Property_Content_div_right_title_right";
               document.getElementById("Property_Information").style.display="block";
               document.getElementById("Property_zbpt").style.display="none";
               document.getElementById("Property_xqzp").style.display="none";
               break;
        case 1:document.getElementById("choose_left").className="Property_Content_div_right_title_left";
               document.getElementById("choose_center").className="Property_Content_div_right_title_current2"; 
               document.getElementById("choose_right").className="Property_Content_div_right_title_right";
               document.getElementById("Property_Information").style.display="none";
               document.getElementById("Property_zbpt").style.display="block";
               document.getElementById("Property_xqzp").style.display="none";
               break;
        case 2:document.getElementById("choose_left").className="Property_Content_div_right_title_left";
               document.getElementById("choose_center").className="Property_Content_div_right_title_center"; 
               document.getElementById("choose_right").className="Property_Content_div_right_title_current";
               document.getElementById("Property_Information").style.display="none";
               document.getElementById("Property_zbpt").style.display="none";
               document.getElementById("Property_xqzp").style.display="block";
               break;
        default:document.getElementById("choose_left").className="Property_Content_div_right_title_current";
               document.getElementById("choose_center").className="Property_Content_div_right_title_center"; 
               document.getElementById("choose_right").className="Property_Content_div_right_title_right";
               document.getElementById("Property_Information").style.display="block";
               document.getElementById("Property_zbpt").style.display="none";
               document.getElementById("Property_xqzp").style.display="none";
               break;
    }
    
}

function checkphone(tel)  //验证号码， 手机，座机，小灵通
{
        var my=false;
        var reg0=/^(0212[56789]{1}\d{6})$/;
        var reg1=/^(0108[013679]{1}\d{6})$/;
        var reg2=/^(0106[019]{1}\d{6})$/;
        var reg3=/^(1[358]\d{9})$/;
        var reg4=/^\d{3,4}-\d{8}$/; 
        var reg5=/^\d{11,12}$/; 
        var reg6=/^\d{8}$/; 

      
        if(reg0.test(tel))my=true;
        if(reg1.test(tel))my=true;
        if(reg2.test(tel))my=true;
        if(reg3.test(tel))my=true;
        if(reg4.test(tel))my=true;
        if(reg5.test(tel))my=true;
        if(reg6.test(tel))my=true;
       
        return my;
}



function checkMoblephone(tel)  //验证号码， 手机，座机，小灵通
{
        var my=false;

        var reg3=/^(1[358]\d{9})$/;
     
        if(reg3.test(tel))my=true;
       
        return my;
}

function checknumber(number)
{
    var my=false;
    var reg0=/^\d+$/;
   
  
    if(reg0.test(number))my=true;
    return my;
}

function OnKeyDownClick(buttonname,e)
{
    if(e.keyCode==13)
    {  
        document.getElementById(buttonname).click();
        return false;
    }
}



function DataLength(fData,type)   //判断输入字符串长度 type : 0 只能为中文  type : 1 普通判断长度
{
    var intLength=0;
    switch(type)
    {
        case 0:for (var i=0;i<fData.length;i++)         //判断只能为中文，不为中文返回-1
                {
                    if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255))
                    {
                       intLength+=1;
                    }   
		            else
		            {
		               return -1;           
		            }
                }                
                return intLength;
        case 1: for (var i=0;i<fData.length;i++)       //判断输入字符串长度，中文为2个字节
                {
                    if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255))
                    {
                       intLength+=2;
                    }   
		            else
		            {
		               intLength+=1;              
		            }
                }
                return intLength;                
    }
}

function addBookmark(title,url) 
{
    if (window.sidebar) { 
       window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
       window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
      return true;
    }
}

function ShowOrderDiv(divname)
{
    document.getElementById(divname).style.display="block";
}

function CloseOrderDiv(divname)
{
    document.getElementById(divname).style.display="none";
}
function ShowPicture(img,houseid,ptype)
{
    var daps  = document.getElementById("abc").style;
   
    var thei=img.offsetHeight;
    var w=img.offsetWidth;
    var tleft=img.offsetLeft+40;
    var ttop=img.offsetTop;	  
    
    while (img = img.offsetParent){ttop+=img.offsetTop; tleft+=img.offsetLeft;}	  
    daps.top  =  ttop+thei+6+"px"; //层的 Y 坐标
    daps.left = tleft + 1+"px";  //层的 X 坐标
    daps.display = "";  //层显示
    document.getElementById("abc").innerHTML="<iframe src=\"/AdHouse/HousePictureView.aspx?id=" + houseid + "&ptype=" + ptype + "\" width=\"370\" height=\"280\" scrolling=\"no\" frameborder=\"0\" ></iframe>";       
}

function ClosePrePic(divname){
	document.getElementById(divname).style.display = "none";
}

document.onclick = function()
{  
     if(document.getElementById('AgencyBoxTitle')!=null)
        document.getElementById('AgencyBoxTitle').style.display='none';  
}   
function showcxt(cid,iscxt,cxt)
{
    if(document.getElementById(cid).checked==true)   
    {    
        
        window.location.href=iscxt;        
    }
    else
    {
        window.location.href=cxt;
    }
}
function changepointimg()
{

}

//加载该用户的订阅条件个数
function LoadCountForSubscription(sid)
{   
    return SW.BS.AjaxUI.AjaxProFun.GetSubscriptionList(sid).value.Rows.length;    
}




//搜索框变换后直接转换URL
function modifyHerf(varhref)
{
	var c=/\/[^\/.]*SO/;
	var varValue=document.getElementById("SearchControl1_TxtKeyword").value=="输入关键词、路名或小区名称"?"":document.getElementById("SearchControl1_TxtKeyword").value;
	var strvalue= '/'+encodeURI(varValue)+'SO';
	window.location.href=varhref.replace(c,strvalue);
	return false;
}

    
function CloseThis(StrValue)
{ 
   var divPriceLog = document.getElementById(StrValue);
   divPriceLog.style.display="none";
   return SW.BS.AjaxUI.AjaxProFun.ClickAdWriteHouse().value;    
} 


function  SetCookie(name, value, expires, path, domain, secure)   
  {   

       document.cookie = name + "=" + escape(value) +
            ((expires) ? "; expires=" + expires : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
  }  
  
function ShowThis(StrValue) 
{

   var divPriceLog = document.getElementById(StrValue);

   divPriceLog.style.display="none";
}




var JsCookie = new function()
{
    //计算cookie有效期
    this.GetExpDate = function (days, hours, minutes)
    {
        var expDate = new Date();
        if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number")
        {
            expDate.setDate(expDate.getDate() + parseInt(days));
            expDate.setHours(expDate.getHours() + parseInt(hours));
            expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
            return expDate.toGMTString();
        }
    }
    
    //取得一个cookie的值
    this.GetCookie = function (name)
    {
        var ck   = document.cookie;
        var exp1 = new RegExp(name + "=.*?(?=;|$)");
        var mch  = ck.match(exp1);
        return mch? mch[0].substring(name.length+1) : null;
    }
    
    //增加或修改一个cookie
    this.SetCookie = function (name, value, expires, path, domain, secure)
    {
        document.cookie = name + "=" + escape(value) +
            ((expires) ? "; expires=" + expires : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
    }
    
    //删除一个cookie(使cookie过期)
    this.DeleteCookie = function (name,path,domain) 
    {
        if(this.GetCookie(name))
        {
            document.cookie = name + "=" +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    }
}

