﻿/*清除错误*/
window.onerror = function(){return true;};
/*============
//加载样式css 开始
==============*/
$(function(){
        var NameLi=$(".nav_sec > ul > li:eq(0)");
        var NameLong=NameLi.find("a").text().length	
        if(NameLong<=5)
        {
            if(NameLi.attr("class")=="on")
                NameLi.attr("class","homepage_1_on");
            else
                NameLi.attr("class","homepage_1_off")
        }
        else if(NameLong<=7)
        {
            if(NameLi.attr("class")=="on")
                NameLi.attr("class","homepage_2_on");
            else
                NameLi.attr("class","homepage_2_off")
        }
        else
        {
            if(NameLi.attr("class")=="on")
                NameLi.attr("class","homepage_3_on");
            else
                NameLi.attr("class","homepage_3_off")
        }
});
function ConentListCss(EventID)
{
    var obj= $(".lists > div:eq(1)");
    if(EventID=="440")
        obj.addClass("t_pices").removeClass("t_information");
    else if(EventID=="442")
        obj.addClass("t_guidelines").removeClass("t_information");
    else if(EventID=="439")
        obj.addClass("t_gonglve").removeClass("t_information");
    else if(EventID=="438")
        obj.addClass("t_notes").removeClass("t_information"); 
}
/*============
//加载样式css 结束
==============*/
/*信息安全*/
function InfoSafe()
{ 
    if (window.Event) 
        document.captureEvents(Event.MOUSEUP);    
    //自动在复制网页后加网址
    document.body.oncopy = function () {
    setTimeout( function () {
	    var text = window.clipboardData.getData("Text");
	    if (text)
	    {
		    text =  text + "\r\n本文来源：重庆中国旅行社国际旅行社 \r\n原文链接：" + location.href;  
		    window.clipboardData.setData("Text", text);
	    }
	    },100 )
    }
}
/*初始化电子地图*/
var maplet = null; 
function initMap(mapid,Longitude,WeiDegree,Zoom,LineTagName){  
    maplet = new Maplet(mapid);  
    maplet.centerAndZoom(new MPoint(Longitude,WeiDegree),Zoom);  
    maplet.addControl(new MStandardControl());
    maplet.showOverview(true,false);
    var marker = new MMarker(
    new MPoint(Longitude,WeiDegree),
    new MIcon("/App_Themes/WebStyle/tb1.gif",32,32),
    new MInfoWindow("<center>"+LineTagName+"</center>","<div></div>")
    ); 
   
    maplet.addOverlay(marker); 

    avBubble.width = 155;  
    avBubble.height = 50; 
    marker.openInfoWindow();
}

/*添加到收藏*/
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{obj.style.behavior='url(#default#homepage)';obj.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 ChangeTab(IDPre,CssPre,num,select)
{
    if(document.getElementById(IDPre+"_"+select).className==CssPre+"_on")
        return;
	for(var i=1;i<=num;i++)
	{
	    if(i==select)
	    {
	    	document.getElementById(IDPre+"_"+i).className=CssPre+"_on";
	        document.getElementById(IDPre+"_"+i+i).style.display="block";
	    }
	    else
	    {
		    document.getElementById(IDPre+"_"+i).className=CssPre+"_off";
		    document.getElementById(IDPre+"_"+i+i).style.display="none";
		}
	}
}
/*标签切换函数*/
function ChangeTab2(IDPre,num,select)
{
    //是否包含样式名
    var cn=document.getElementById(IDPre+"_"+select).className.toString();
    var patrn=/(^|\s)(on)($|\s)/ig; 
    if(patrn.exec(cn))
    {
        return;
    }        
	for(var i=1;i<=num;i++)
	{
	    var navObj=document.getElementById(IDPre+"_"+i);
	    cn=navObj.className.toString();	
	    var blockObj=document.getElementById(IDPre+"_"+i+i);	        
	    if(i==select)
	    {
	    	navObj.className=cn.replace(/(^|\s)(on|off)($|\s)/ig,"$1on$3");	    	
	    	if(blockObj) 
	            blockObj.style.display="block";
	    }
	    else
	    {
		    navObj.className=cn.replace(/(^|\s)(on|off)($|\s)/ig,"$1off$3");
	    	if(blockObj) 
	            blockObj.style.display="none";
		}
	}
}
/*分析价格字段串 460|0|20|f*/
function SplitPrice(prices,index)
{
    var s=prices.split("|");
    if(s.length==4){return s[index]+"元/人";}else{return "";}
}
/*回车搜索*/
function SearchLinesOnkeyDown(type,e)
{
    var key = window.event ? e.keyCode:e.which;
    if(key==13)
    {
        SearchLines(type);
        return false;
    }
    return true;
}
/*===================
线路查询 type=1：高级搜索
====================*/
function SearchLines(type)
{
    var st=document.getElementById("LineKeyWord").value;    
    st=st.trim();
    if((st=="")||(st=="请输入目的地或景点"))
    {
        st="关键字不限制";
    }    
    var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/; 
    if (!patrn.exec(st) && (st!=""))
    {
      alert("关键字包含非法字符");
      return;
    }    
    var pageUrl="/lineSearch/";
    patrn=/^(\d+)|(my\d+)$/ig; 
    if(patrn.exec(st))//根据ID直接查询
    {
        st=st.replace(/my/ig,"");
        pageUrl="/line/"+st+".aspx";
    }
    else
    {
        var ChuJingGuoNei="0_0",LineIsTour="0",JourneyDays="0-0",LinePrice="0-0";
        if(type==1)
        {
            var ChuJingGuoNeiSelect=document.getElementById("ChuJingGuoNei");
            if(ChuJingGuoNeiSelect.value=="1")
                ChuJingGuoNei="1_0";
            else if(ChuJingGuoNeiSelect.value=="2")
                ChuJingGuoNei="0_1";
                        
            LineIsTour=document.getElementById("LineIsTour");
            LineIsTour=LineIsTour.value;

            JourneyDays=document.getElementById("JourneyDays");
            JourneyDays=JourneyDays.value;
        }
        

        LinePrice=document.getElementById("LinePrice");
        LinePrice=LinePrice.value;
            
        pageUrl=pageUrl+encodeURIComponent(st)+"_"+ChuJingGuoNei+"_"+LineIsTour+"_"+JourneyDays+"_"+LinePrice+"_1.aspx"
     }
     //alert(pageUrl);
     this.location=pageUrl;
}
/*===================
提交咨询
===================*/
var s___c
function SaveConsult()
{
    var patrn=/<[a-zA-Z][a-zA-Z0-9]*>/; 
    var GuestName=$("#consult input[name='GuestName']")
    if(GuestName.val()=="")
    {
        alert("请输入姓名。");
        GuestName.focus();
        return;
    }  
    if (patrn.exec(GuestName.val()) && (GuestName.val()!=""))
    {
        alert("姓名包含非法字符。");
        GuestName.focus();
        return;
    }
    var Content=$("#consult textarea[name='Content']")
    if(Content.val()=="")
    {
        alert("请输入咨询内容。");
        Content.focus();
        return;
    }
    if (patrn.exec(Content.val()) && (Content.val()!=""))
    {
        alert("咨询内容包含非法字符。");
        Content.focus();
        return;
    } 
    
    
    var c=$("#consult").serialize();
    if(c==s___c)
    {
        alert("请不要重复咨询");
        return;
    }
    $.post("/Consult/Save.ashx",c,function(data){alert(data);});
    s___c=c;
}
/*取得TAG对应的URL*/
function GetTagGoUrl(id)
{
    $.get("/JavaScript/TagGoUrl.ashx?LineTagID="+id,
     function(data){data=data.toString();if(data!=""){window.location=data;}}
    );
}
//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);
}
//对齐左右几块
function AlignmentBlock()
{
    var maxheight=0;
    for(var i=0;i<arguments.length;i++)
    {
        if($(arguments[i]).height()>maxheight)
            maxheight=$(arguments[i]).height();
    }
    for(var i=0;i<arguments.length;i++)
    {
        $(arguments[i]).height(maxheight);
    }
}
//div显示或隐藏菜单
function Div_DisplayNoDelay(objName,val)
{ 
   var list= document.getElementById(objName);
   list.style.display=val; 
}

//打开窗口
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') 
}
// 用正则表达式将前后空格 用空字符串替代。  
String.prototype.trim= function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
// 格式化日期
Date.prototype.format = function(style) {
    var o = {
        "M+" : this.getMonth() + 1, //month
        "d+" : this.getDate(),      //day
        "h+" : this.getHours(),     //hour
        "m+" : this.getMinutes(),   //minute
        "s+" : this.getSeconds(),   //second
        "w+" : "天一二三四五六".charAt(this.getDay()),   //week
        "q+" : Math.floor((this.getMonth() + 3) / 3), //quarter
        "S" : this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(style)) {
        style = style.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for(var k in o){
        if(new RegExp("("+ k +")").test(style)){
          style = style.replace(RegExp.$1,
            RegExp.$1.length == 1 ? o[k] :
            ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return style;
};
//ajax加载状态
function ShowUpdateProgresDiv()
{
    $("body").append('<div id="UpdateProgresDiv" style="z-index:9999;POSITION:absolute;right:1px;TOP:1px;background-color:#FFFFFF;border:#ff0000 solid 1px; width:100px;display:none;"><img src="/App_Themes/WebStyle/loading.gif" border="0" /></div>');
    window.setInterval("SetDivMiddle('UpdateProgresDiv')",1500);
    $("#UpdateProgresDiv").ajaxStart(function(){$(this).show();});
    $("#UpdateProgresDiv").ajaxStop(function(){$(this).hide();});
}
//全区域居中
function SetDivMiddle(obj)
{ 
    var de=document.documentElement;var db=document.body;
    var viewW=de.clientWidth==0 ?  db.clientWidth : de.clientWidth;
    var viewH=de.clientHeight==0 ?  db.clientHeight : de.clientHeight;
    var scrollL=de.scrollLeft==0 ?  db.scrollLeft : de.scrollLeft;
    var scrollT=de.scrollTop==0 ?  db.scrollTop : de.scrollTop;    
    document.getElementById(obj).style.left=(scrollL+(viewW-70)/2)+"px";
    document.getElementById(obj).style.top=(scrollT+(viewH-102)/2)+"px";
} 
/*===================
flash输出图片
====================*/
function FlashPics(swf_width,swf_height,pics,links,texts)
{
	//var swf_width=520;
	//var swf_height=179;
	var config='5|0xffffff|0x0099ff|50|0xffffff|0x0099ff|0x000000';
	//-- config 参数设置 -- 自动播放时间(秒)|文字颜色|文字背景色|文字背景透明度|按键数字颜色|当前按键颜色|普通按键色彩 --
	//var pics='/UpFiles/banner/banner4.jpg|/UpFiles/banner/banner1.jpg';
	//var links='';
	//var texts='';
	var outputstr='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ swf_width +'" height="'+ swf_height +'">';
	outputstr=outputstr+'<param name="movie" value="/App_Themes/swf/focus.swf" />';
	outputstr=outputstr+'<param name="quality" value="high" />';
	outputstr=outputstr+'<param name="menu" value="false" />';
	outputstr=outputstr+'<param name=wmode value="opaque" />';
	outputstr=outputstr+'<param name="FlashVars" value="config='+config+'&bcastr_flie='+pics+'&bcastr_link='+links+'&bcastr_title='+texts+'" />';
	outputstr=outputstr+'<embed src="/App_Themes/swf/focus.swf" wmode="opaque" FlashVars="config='+config+'&bcastr_flie='+pics+'&bcastr_link='+links+'&bcastr_title='+texts+'& menu="false" quality="high" width="'+ swf_width +'" height="'+ swf_height +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	outputstr=outputstr+'</object>';
	document.write(outputstr);
}

/****游船内容页开始*******************************************/
//读取价格
function YReadPrice()
{
    var x=Math.random()*10;        
    var url="?action=readprice&date="+dateNow.format("yyyy-M")+"&nationality="+NationalityId+"&"+x;
    $.getJSON(url,function(json){JsonData=json;YUpDatePriceBlock();}); 
}
//更新价格区域
function YUpDatePriceBlock()
{
    if(RoomName==null)
        RoomName=YGetRoomName();
    var priceBlock=$("#priceBlock");
    priceBlock.find("._price_data_L").remove(); 
    var str='',ydatec='';
    for(var i=0;i<JsonData.prices.length;i++)
    {
        if(JsonData.prices[i].isdown==isDown)
        {
            if(ydatec==JsonData.prices[i].ydate)
                continue;
            ydatec=JsonData.prices[i].ydate;
            str=str+'<tr class="_price_data_L"><td>'+ydatec+'</td>'
            for(var j=0;j<RoomName.length;j++)
            {
                var pricesLine=YGetOnePrice(ydatec,RoomName[j].id);
                if(pricesLine=="")
                {
                    str=str+'<td>&nbsp;</td>';
                }
                else
                {
                    if(pricesLine.recommend==1)
                        str=str+'<td>￥ '+pricesLine.price+'元/'+RoomName[j].unit+'<img src="/Themes/Skins2009/icon/discount_1.gif" alt="推荐" /></td>';
                    else
                        str=str+'<td>￥ '+pricesLine.price+'元/'+RoomName[j].unit+'&nbsp;&nbsp;&nbsp;&nbsp;</td>';
                }
            }
            str=str+'</tr>'
        }
    } 
    priceBlock.find("._price_title_L").after(str); 
    if(str!="")
        $("#priceht").text(dateNow.format("yyyy年MM月")+((isDown==1)?"下水":"上水")+$("#priceBlock .nationality .on").eq(0).text()+"游客价格");
    else
        $("#priceht").text(dateNow.format("yyyy年MM月")+((isDown==1)?"下水":"上水")+$("#priceBlock .nationality .on").eq(0).text()+"游客价格(暂无)");
}
function YGetOnePrice(ydatec,RoomId)
{
    for(var i=0;i<JsonData.prices.length;i++)
    {
        if((JsonData.prices[i].isdown==isDown)&&(JsonData.prices[i].ydate==ydatec)&&(JsonData.prices[i].ypnid==NationalityId)&&(JsonData.prices[i].yrid==RoomId))
        {
            return JsonData.prices[i];
        }
    }
    return "";
}
function YGetRoomName()//户型名称数组化
{
    var priceBlock=$("#priceBlock ._price_title_L td").not($("#priceBlock ._price_title_L td")[0]);
    arrayObj = new Array(priceBlock.size());
    for(var i=0;i<arrayObj.length;i++)
    {
        var chars= priceBlock.eq(i).attr("char").toString();
        var charsA=chars.split("|");
        if(charsA.length==2)
            arrayObj[i]={index:i,name:priceBlock.eq(i).text(),id:charsA[0],unit:charsA[1]};
        else 
            arrayObj[i]={index:i,name:priceBlock.eq(i).text(),id:charsA[0],unit:""};
    }        
    return arrayObj;
}
/****游船内容页结束********************************************************/

/****游船船期表开始********************************************************/
//选择月份
function YTSelectMonth(year,month)
{
    dateNow=new Date(year,month,1);
    var str='<div class="cqb_year1 yc_fl cqbyear" onclick="YTSelectMonth('+(dateNow.getFullYear()-1)+',11);YTReadTimeTable();">'+(dateNow.getFullYear()-1)+'年</div>';
    for(var i=0;i<=11;i++)
    {
        if(month==i)
            str=str+'<div class="yzy_cqbhc05 yzy_cqbhsj">'+(i+1)+'月</div>';
        else
            str=str+'<div class="yzy_cqbhc04 yzy_cqbhsj" onclick="YTSelectMonth('+dateNow.getFullYear()+','+i+');YTReadTimeTable();">'+(i+1)+'月</div>';
       //onmouseover="javascript:$(this).addClass(\'yzy_cqbhc05\').removeClass(\'yzy_cqbhc04\')" onmouseout="javascript:$(this).addClass(\'yzy_cqbhc04\').removeClass(\'yzy_cqbhc05\')"
    }
    str=str+'<div class="cqb_year2 yc_fl cqbyear" onclick="YTSelectMonth('+(dateNow.getFullYear()+1)+',0);YTReadTimeTable();">'+(dateNow.getFullYear()+1)+'年</div>';
    var yachtmonth=$("#yachtmonth");
    yachtmonth.find("div:gt(0)").remove();
    yachtmonth.append(str);
}
//选择航段        
function YTSelectPort(id0,id1,down)
{
    var yachtmonth=$("#yachtport .yzy_cqbhc1").addClass("yzy_cqbhc02").removeClass("yzy_cqbhc03");
    $("#yachtport"+id0+id1+down).addClass("yzy_cqbhc03");
    isDown=down; port0id=id0;  port1id=id1;        
}
//读取价格
function YTReadTimeTable()
{  
    var x=Math.random()*10;        
    var url="/Yacht_Timetable.aspx?action=readtimetable&date="+dateNow.format("yyyy-M");
    url=url+"&isDown="+isDown+"&port0id="+port0id+"&port1id="+port1id+"&"+x;
    $.post(url, function(data){
        var timetableblock=$("#timetable");
        timetableblock.find("tr:gt(0)").remove();
        timetableblock.append(data);
        //更新title
        $("#timetabletitle").text(dateNow.format("yyyy年MM月 ")+$("#yachtport .yzy_cqbhc03").text());            
    });
}
/****游船船期表结束********************************************************/


function btnLeftSearch(){
   var LineKeyWord=$("#LineKeyWord").val();
   var LinePrice=$("#LinePrice").val();
  if(LineKeyWord=="请输入目的地或景点")
      {
         LineKeyWord="''";
      }
      window.location.href="../Page/travelLine.aspx?Action=Search&&LineKeyWord="+LineKeyWord+"&&LinePrice="+LinePrice+""
}
