﻿// JScript 文件
window.status=WebName_Js;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//全区域居中
function SetDivMiddle(obj)
{ 
    document.getElementById(obj).style.top=(document.body.offsetHeight-102)/2+"px";
    document.getElementById(obj).style.left=(document.body.offsetWidth-70)/2+"px";
} 
//打开窗口
function  WindowOpen(pageUrl,w,h)
{
    var iTop = (window.screen.availHeight-30-h)/2;
    var iLeft = (window.screen.availWidth-10-w)/2;
    window.open(pageUrl, 'DateWindow', 'height='+h+', width='+w+', top='+iTop+', left='+iLeft+', toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') 
}

/*世博*/
function SB_Start()
{
//    return;
    if(GetCookie("SbBanner")=="1")
        return;
    SB_ChangShow("SbSmallBanner","SbBanner",120,526,true);    
}
function SB_End()
{
   SB_ChangShow("SbSmallBanner","SbBanner",120,526,false);
   SetCookie("SbBanner","1");
}
function SB_ChangShow(SId,Id,min,max,isToMax)
{
    var SbSmallBanner=document.getElementById(SId);
    var SbBanner=document.getElementById(Id);
    
    if(isToMax)//从小变大
    {
        SbSmallBanner.style.display="none";
        SbBanner.style.display="block";
        var s=max-min;
        s=Math.round(s*0.1);
        if(s<1)
        {
            SbBanner.style.height=max+"px"
            setTimeout("SB_End()", 2000);
        }
        else
        {
            min=min+s;
            SbBanner.style.height=min+"px"
            setTimeout("SB_ChangShow('"+SId+"','"+Id+"',"+min+","+max+",true)", 10);
        }
    }
    else//从大变小
    {
        var s=max-min;
        s=Math.round(s*0.2);        
        if(s<1)
        {
            SbBanner.style.height=min+"px"
            SbSmallBanner.style.display="block";
            SbBanner.style.display="none";
        }
        else
        {
            max=max-s;
            SbBanner.style.height=max+"px"
            setTimeout("SB_ChangShow('"+SId+"','"+Id+"',"+min+","+max+",false)", 10);
        }    
    }
}

function gb2312(key)
{
    var r = "";
    for(var i=0;i<key.length;i++)
    {
            var t = key.charCodeAt(i);
            if(t>=0x4e00 || t==0x300A || t==0x300B)
            {
                    try
                    {
                    execScript("ascCode=hex(asc(\""+key.charAt(i)+"\"))", "vbscript"); r += ascCode.replace(/(.{2})/g, "%$1"); }
                    catch(e)
                     {}
             }
            else{r += escape(key.charAt(i))}
       }
    return r;
}
//div显示或隐藏菜单
var delayShowFlag_t;
function Div_DisplayMenu(objName,val)
{ 
    var n=0;   
    if(val=="none")
    {
        n=500;
    }
    else
    {
        clearTimeout(delayShowFlag_t); 
        n=0;
    }
    delayShowFlag_t=setTimeout(
         function()
         {
            var list= document.getElementById(objName); list.style.display=val;            
         }
     ,n);
}
//div显示或隐藏菜单
function Div_DisplayNoDelay(objName,val)
{ 
   var list= document.getElementById(objName);
   list.style.display=val; 
}
//回车搜索
function SearchOnkeyDown(op)
{
    if(event.keyCode==13)
    {
        if(op=="line")
            SearchLines()
        else if(op=="hotel")
            SearchHotels()
    }
}
/*回车*/    
function EnterClick(code,e)
{
    var key = window.event ? e.keyCode:e.which;
    if(key==13)
    {
        eval(code);
        return false;
    }
    return true;
} 
//搜索线路
function SearchLines()
{
 
    var st=document.getElementById("LineKeyWord").value;
    st=st.replace(/\s/,"");
    var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/; 
    if (!patrn.exec(st) && (st!=""))
    {
      alert("关键字包含非法字符");
      return;
    }
   
    if(st==""||st=="景点或线路编号")
        st="关键字不限制";
    
    var pageUrl=installDir_Js;
    patrn=/^(HW)?(hw)?[\d]{0,6}$/; 
    if(patrn.exec(st))
    {
        pageUrl=pageUrl+"ShowLine.aspx?id="+st.replace("HW","").replace("hw","")+"";
    }
    else
    {
        var journeyDay="0";
        if(document.getElementById("JourneyDays"))
        {
           journeyDay=document.getElementById("JourneyDays").value;
        }
        //encodeURIComponent
        pageUrl=pageUrl+"lineSearch.aspx?key="+st+"&d="+journeyDay+"&p="+document.getElementById("LinePrice").value+"";
     }   
    this.location=pageUrl;               
    
}
//搜索酒店
function SearchHotels()
{    
    var st=document.getElementById("HotelKeyWord").value;
    st=st.replace(/\s/,"");
    var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/; 
    if(!patrn.exec(st) && (st!=""))
    {
      alert("关键字包含非法字符");
      return;
    }
    if(st=="")
        st="关键字不限制";
        
    var pageUrl=installDir_Js
    patrn=/^[\d]{0,6}$/;
    if(patrn.exec(st))
        pageUrl=pageUrl+"Redirect.aspx?HotelID="+st;
    else     
        pageUrl=pageUrl+"hotelSearch/"+encodeURIComponent(st)+"/"+document.getElementById("WebSearch1_DropDownListHotelArea").value+"_"+document.getElementById("WebSearch1_DropDownListhotelStar").value+"_"+document.getElementById("SelectHotelPrice").value+"_1.aspx"
    //window.open(pageUrl, '', '')
    this.location=pageUrl;
    //alert("提交成功");
}


////////////////////////////////////////////////////
//显示日历对话框
function showModalDialogDateWindow(divid,objID)
{ 
    var e=document.getElementById(objID);
    var t=e.offsetTop; 
	var l=e.offsetLeft; 
	var w=e.offsetWidth; 
	var h=e.offsetHeight; 
	while(e=e.offsetParent) 
	{ 
		t+=e.offsetTop; 
		l+=e.offsetLeft; 
	} 
	document.getElementById(divid).style.posLeft=l;
	document.getElementById(divid).style.posTop=t+h;
    
    if(document.getElementById(divid).style.display=="none")    
        document.getElementById(divid).style.display="block";
    else
        document.getElementById(divid).style.display="none"; 
} 
//ie? 
function IsIE()
{ //ie? 
    if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1)
    return true;
    else
     return false; 
} 
/////////////////////////////////////////////////////////
//写Cookies
function SetCookie(name,value)
{
   var argv=SetCookie.arguments;
   var argc=SetCookie.arguments.length;
   var expires=(2<argc)?argv[2]:null;
   var path=(3<argc)?argv[3]:null;
   var domain=(4<argc)?argv[4]:null;
   var secure=(5<argc)?argv[5]:false;
   document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}
//写Cookies
function SetCookie2(name,value)
{
   var argv=SetCookie2.arguments;
   var argc=SetCookie2.arguments.length;
   var expires=(2<argc)?argv[2]:null;
   var path=(3<argc)?argv[3]:null;
   var domain=(4<argc)?argv[4]:null;
   var secure=(5<argc)?argv[5]:false;
   document.cookie=name+"="+value+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}
//读Cookies
function GetCookie(Name)
{
   var search = Name + "=";
   var returnvalue = "";
   if (document.cookie.length > 0) 
   {
      offset = document.cookie.indexOf(search);
   if (offset != -1)
   { 
   offset += search.length;
         end = document.cookie.indexOf(";", offset); 
   if (end == -1)
            end = document.cookie.length;
         returnvalue=unescape(document.cookie.substring(offset,end));
       }
    }
    return returnvalue;
}
//读Cookies
function GetCookie2(Name)
{
   var search = Name + "=";
   var returnvalue = "";
   if (document.cookie.length > 0) 
   {
      offset = document.cookie.indexOf(search);
   if (offset != -1)
   { 
   offset += search.length;
         end = document.cookie.indexOf(";", offset); 
   if (end == -1)
            end = document.cookie.length;
         returnvalue=document.cookie.substring(offset,end);
       }
    }
    return returnvalue;
}
///////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//读取已经访过的线路
function ReadCOOKIESAlaredyLine(topnum,titlenum)
{
    var returnvalue=GetCookie2(SiteKey_Js+"COOKIESAlaredyLine");
    //alert(returnvalue)
    cookiesArry=returnvalue.split("||");
    var str="";
    //alert(cookiesArry.length);
    for(var i=0;i<cookiesArry.length;i++)
    {	
	    oneline=cookiesArry[i].split("|");
	    if(oneline.length>=2)
	    {
	        //str=str+"<li><input id=\"CheckboxAlreadyLine\" name=\"CheckboxAlreadyLine\" value=\""+decodeURIComponent(oneline[1])+"\" type=\"checkbox\" />";
	        str=str+"<li>";
	        var t=decodeURIComponent(oneline[0]);
	        if(t.length>titlenum)
	            t=t.substring(0,titlenum-1)+"..";
	        str=str+"<a href=\""+installDir_Js+"line/"+decodeURIComponent(oneline[1])+".aspx\" target=\"_blank\" title=\""+decodeURIComponent(oneline[0])+"\">"+t+"</a>";
	        str=str+"</li>";
	    }
	    if(i>=(topnum-1))
	        break;
    }
    document.getElementById("DivListAlreadyLine").innerHTML=str;
}
//删除已经访过的线路
function DeleteAlreadyLineCookies(types,topnum)
{
    if(types=="all")
    {
        SetCookie2(SiteKey_Js+"COOKIESAlaredyLine","")
        document.getElementById("DivListAlreadyLine").innerHTML="";
    }
    else
    { 
        var returnvalue=GetCookie2(SiteKey_Js+"COOKIESAlaredyLine");
        cookiesArry=returnvalue.split("||");
        var str="";
        var j=0;
        for(var i=0;i<cookiesArry.length;i++)
        {	
            oneline=cookiesArry[i].split("|");
            if(oneline.length>=2)
            {
                if(! IsDeleteAlreadyLineCookies(decodeURIComponent(oneline[1])))
                {  
                    if(j==0)
                    {str=cookiesArry[i];}
                    else
                    {str=str+"||"+cookiesArry[i];}  
                    j++;                            
                }
             }
        }
        SetCookie2(SiteKey_Js+"COOKIESAlaredyLine",str)
        ReadCOOKIESAlaredyLine(5,15)
    }
}
//判断是否删除或选中
function IsDeleteAlreadyLineCookies(id)
{
    var cbs = document.getElementsByTagName("input"); 
    for (var i=0; i<cbs.length; i++)
    {
        if ((cbs[i].type == "checkbox") && (cbs[i].name=="CheckboxAlreadyLine"))
        {
            if(cbs[i].value==id)
            {
                //alert("IsDeleteAlreadyLineCookies"+cbs[i].checked+id);
                if(cbs[i].checked)
                    return true;
                else
                    return false;                 
            }
        }
    }
    return false;
}
//取消选择
function NoSelectAlreadyLineCookies()
{
    var cbs = document.getElementsByTagName("input"); 
    for (var i=0; i<cbs.length; i++)
    {
        if ((cbs[i].type == "checkbox") && (cbs[i].name=="CheckboxAlreadyLine"))
        {

            if(cbs[i].checked)
                cbs[i].checked=false;           
        }
    }
    return false;
}
//线路对比
function lineContrast()
{
        var returnvalue=GetCookie2(SiteKey_Js+"COOKIESAlaredyLine");
        cookiesArry=returnvalue.split("||");
        var urlstr=installDir_Js +"lineContrast";
        var j=0;
        for(var i=0;i<cookiesArry.length;i++)
        {	
            oneline=cookiesArry[i].split("|");
            if(oneline.length>=2)
            {
                if(IsDeleteAlreadyLineCookies(decodeURIComponent(oneline[1])))
                {
                    urlstr= urlstr+"_" + oneline[1]
                    j++;                            
                }
             }
        }
        if(j<2)
        {
            alert("只少要选择两条线路对比．");
            return;
        }
        if(j>2)
        {
            alert("只能选择两条线路对比．");
            return;
        }
        urlstr= urlstr+".aspx"
        window.open(urlstr, "", "");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
页内弹出提示框
调用方式
显示调用：<span onclick="ShowNote('标题|内容')"  class="spannote">文本</span>
显示空：<span onclick="ShowNote('show')"  class="spannote">文本</span>
隐藏：<span onclick="ShowNote('')"  class="spannote">文本</span>
*/
function ShowNote(content)
{
	var divid="msgshowdiv";	
	var msgshowdiv_title="msgshowdiv_title";
	var msgshowdiv_content="msgshowdiv_content";
	if(content=="")
	{
		document.getElementById(divid).style.display="none"; 
		return;	
	}
	else if(content=="show")
	{
		document.getElementById(divid).style.display="block"; 
		return;	
	}
    
    if(document.getElementById(divid).style.display=="none") 
	{ 
		var x = event.clientX;
		var y = event.clientY; 
		document.getElementById(divid).style.posLeft=x;
		document.getElementById(divid).style.posTop=y+15;  
        document.getElementById(divid).style.display="block";
		var content_arry=content.split(/\|/);
        if(content_arry.length>=2)
        {
			document.getElementById(msgshowdiv_title).innerHTML=content_arry[0];
			document.getElementById(msgshowdiv_content).innerHTML=content_arry[1];
        }
	}
    else
	{
        document.getElementById(divid).style.display="none";
	} 
}
function ShowNoteL(content)
{
	var divid="msgshowdiv";	
	var msgshowdiv_title="msgshowdiv_title";
	var msgshowdiv_content="msgshowdiv_content";
	if(content=="")
	{
		document.getElementById(divid).style.display="none"; 
		return;	
	}
	else if(content=="show")
	{
		document.getElementById(divid).style.display="block"; 
		return;	
	}
    
    if(document.getElementById(divid).style.display=="none") 
	{ 
		var x = event.clientX;
		var y = event.clientY; 
		x=x-300;
		if(x<0)
		  x=0; 
		document.getElementById(divid).style.posLeft=x;
		document.getElementById(divid).style.posTop=y+15;  
        document.getElementById(divid).style.display="block";
		var content_arry=content.split(/\|/);
        if(content_arry.length>=2)
        {
			document.getElementById(msgshowdiv_title).innerHTML=content_arry[0];
			document.getElementById(msgshowdiv_content).innerHTML=content_arry[1];
        }
	}
    else
	{
        document.getElementById(divid).style.display="none";
	} 
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
function AddFavorite(sURL, sTitle)
{
    try
    {
         window.external.addFavorite(sURL, sTitle);
     }
    catch (e)
    {
        try
        {
             window.sidebar.addPanel(sTitle, sURL, "");
         }
        catch (e)
        {
             alert("加入收藏失败，请使用Ctrl+D进行添加");
         }
     }
}

function SetHome(obj,vrl){
        try{this.style.behavior='url(#default#homepage)';this.setHomePage(vrl);}
        catch(e){
                if(window.netscape) {
                        try {
                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                         }
                        catch (e) {
                                 alert("此操作被浏览器拒绝！");
                         }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                         prefs.setCharPref('browser.startup.homepage',vrl);
                  }
         }
}

function nocontextmenu(){ 
    event.cancelBubble = true 
    event.returnValue = false; 
    return false; 
} 
function norightclick(e){ 
    if (window.Event)
    { 
        if (e.which == 2 || e.which == 3) 
            return false; 
    } 
    else if (event.button == 2 || event.button == 3)
    { 
        event.cancelBubble = true 
        event.returnValue = false; 
        return false; 
    } 
} 
function NoSelectText(){return false;}

//document.oncontextmenu = nocontextmenu; // for IE5+ 
//document.onmousedown = norightclick; // for all others 
document.body.oncopy=NoSelectText;
document.body.oncut=NoSelectText;
document.body.onselectstart=NoSelectText;
//document.body.onpaste=NoSelectText;

