﻿// JavaScript Document
/*firefox window.event*/
function __firefox(){
    HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style);
    window.constructor.prototype.__defineGetter__("event", __window_event);
    Event.prototype.__defineGetter__("srcElement", __event_srcElement);
}
function __element_style(){return this.style;}
function __window_event(){return __window_event_constructor();}
function __event_srcElement(){return this.target;}
function __window_event_constructor(){
    if(document.all){return window.event;}
    var _caller = __window_event_constructor.caller;
    while(_caller!=null){
        var _argument = _caller.arguments[0];
        if(_argument){
            var _temp = _argument.constructor;
            if(_temp.toString().indexOf("Event")!=-1){return _argument;}
        }
        _caller = _caller.caller;
    }
    return null;
}
if(window.addEventListener){__firefox();}
/*end firefox.event*/
//通用ID获取对象
function $(id){return document.getElementById(id);}
//通用NAME获取对象
function $N(Name){return document.getElementsByName(Name);}
//设为首页
function $HomePage(obj,Url){
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage(Url);
	return false
}
function $HomePage(obj,Url){
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage(Url);
	return false
}
function $JumpPage(Url){
	window.location.href=Url;
}
function $JumpPageA(Url){
	window.open(Url)
}
//判断浏览器
function $GetIE(){ 
   if(navigator.userAgent.indexOf("MSIE")>=0) return "IE"; 
   if(navigator.userAgent.indexOf("Firefox")>=0) return "Firefox"; 
   if(navigator.userAgent.indexOf("Opera")>=0) return "Opera"; 
   return "No"; 
};
//加入收藏夹
function $Favorite(Url,Title){
	switch($GetIE()){
		case "IE": window.external.addFavorite(Url,Title);break;
		case "Firefox": window.sidebar.addPanel(Title, Url, "");break;
		case "Opera":
			var Opera = document.createElement('a');Opera.setAttribute('rel','sidebar');
			Opera.setAttribute('href',Url);Opera.setAttribute('title',Title);Opera.click();break;
	}
}
//判断浏览器
function $GetIE(){ 
   if(navigator.userAgent.indexOf("MSIE")>=0) return "IE"; 
   if(navigator.userAgent.indexOf("Firefox")>=0) return "Firefox"; 
   if(navigator.userAgent.indexOf("Opera")>=0) return "Opera"; 
   return "No"; 
}
function $UpFile(Url,Width,Height,scrollbars){
	window.open(""+Url,"","Width="+Width+",Height="+Height+",top=100,left=100,status=no,scrollbars="+scrollbars)
}
//通用标签选择
function ShowTag(Name,Max,Num,nav){
	for(var i=1;i<=Max;i++){
		$(Name+i).className='';
		$(Name+"_"+i).style.display='none';
	}
	$(Name+Num).className=nav;
	$(Name+"_"+Num).style.display='block';
}
//通用标签选择
function ShowDiv(Name,Max,Num,nav){
	for(var i=1;i<=Max;i++){
		$(Name+i).style.display='none';
		$(Name+"_"+i).className='';
	}
	$(Name+Num).style.display='block';
	$(Name+"_"+Num).className=nav;
}
//通用标签选择
function HiddenDaig(Name){if($(Name))$(Name).style.display='none';}

function CheckSelect(Name,Str){
	var SelectStr=$(Name)
	if(SelectStr!=null){
		for(i=0;i<SelectStr.length;i++){
			if(Str == SelectStr.options[i].text || Str == SelectStr.options[i].value) SelectStr.selectedIndex = i;
		}	
	}
}
function CheckRadio(Name,Str){
    var RadioStr=$N(Name);
    if(RadioStr!=null){
        for(i=0;i<RadioStr.length;i++){
            if(RadioStr[i].value==Str){return RadioStr[i].checked="checked"; }
        }
    }
    return null;
}
function CheckCode(url){$("CheckCodeImg").src = url+"?"+Math.random()}

//选择生成对象
function ComMakeObj(oNum,oNumX,objA,objB,Room){
		var oText="";
		//alert(oNum)
		var Num ;
		Num = parseInt(oNum)+parseInt(oNumX)
		//alert(oNumX)
		for(i=1;i<=Num;i++){
			oText+=$(objB).innerHTML;
		}
		$(objA).innerHTML=""
	$(objA).innerHTML=oText;
	var Rooms
	Rooms=parseInt(oNum)/2
	if(Rooms!=parseInt(Rooms))(Rooms++)
	
	$(Room).value=parseInt(Rooms);
}
function GetMoney(adultnum,childrennum,adultfirstmoney,childrenmoney,adultfirstpoor,allmoney){
	var AMoneys,CMoneys
	AMoneys=parseInt($(adultnum).value)*parseInt(adultfirstmoney);
	CMoneys=parseInt($(childrennum).value)*parseInt(childrenmoney);
	//alert(CMoneys)
	$(allmoney).value=AMoneys+CMoneys;
	//parseInt(adultfirstpoor)
	if(parseInt($(adultnum).value)%2!=0 && parseInt($(adultnum).value)>1)$(allmoney).value=parseInt($(allmoney).value)+parseInt(adultfirstpoor)

}
//,'childrennum',{$sql.adultfirstmoney},{$sql.childrenmoney},'allmoney'



function ShowTeam(title,Str,KM,URL,Norm,NK){
	var TEAMTXT
	var e=window.event.srcElement,Obj;
	if (arguments.length == 0 ){
		Obj = e;
    }else{
		if(typeof(arguments[0])=='object'){
			Obj=arguments[0];
		}else{
        	Obj = document.getElementById(arguments[0]);
		}
    }
	var NormTxt =Norm.split(",");
	//取得对象位置给层定位
	var t = e.offsetTop,  h = e.clientHeight, l = e.offsetLeft,p = e.type;//控件的信息
	while (e = e.offsetParent){t += e.offsetTop; l += e.offsetLeft;}
	
	var cw = $("teamlist").clientWidth, ch = $("teamlist").clientHeight;
    var dw = document.body.clientWidth, dl = document.body.scrollLeft, dh = document.body.clientHeight,dt = document.body.scrollTop;
	if(NK!=1){
	if (document.body.clientHeight + dt - t - h >= ch) {
        $("teamlist").style.top = ((p=="image")? t + h : t + h + 14)+'px';
    }else {
        $("teamlist").style.top  = ((t - dt < ch) ? ((p=="image")? t + h : t + h + 14) : t - ch)+'px';
    }
    //if (dw + dl - l >= cw){
        $("teamlist").style.left = (l-520)+'px'; 
	}
    //}else{ 
        //$("teamlist").style.left = ((dw >= cw) ? dw - cw + dl : dl)-24+'px';
   // }
	var TeamTemp = Str.split("{$}")
	var year,yeartemp,month,monthtemp,CalendarText;
	yeartemp="";
	monthtemp="";
	for(n=0;n<TeamTemp.length;n++){
		//alert(TeamTemp[n])
		year=TeamTemp[n].split("|")[0].split("-")[0].toString()
		if(yeartemp==year || yeartemp=="")yeartemp+=year+"|";
		month=TeamTemp[n].split("|")[0].split("-")[1].toString();
		if(monthtemp.indexOf(month+"|")<0)monthtemp+=month+"|";
		//alert(monthtemp.indexOf(month+"|"))
	}
	//alert(monthtemp)
	yeartemp=yeartemp.substring(0,yeartemp.length-1).toString()
	monthtemp=monthtemp.substring(0,monthtemp.length-1).toString()
	//yeartemp = yeartemp.split("|")[KM];
	//alert(monthtemp)
	//if(KM>monthtemp.split("|").length){KM=monthtemp.split("|").length}
	//monthtemp = monthtemp.split("|")[KM]
	//alert(monthtemp)
	if(monthtemp.split("|").length>KM){
		if(KM>=0){
			monthtemp = monthtemp.split("|")[KM]
		}else{
			alert("对不起！上月以前的出团数据已过期。")
			KM=0
			monthtemp = monthtemp.split("|")[0]
		}
	}else{
		alert("对不起！目前还没有下月以后的出团数据。")
		monthtemp = monthtemp.split("|")[monthtemp.split("|").length-1]
		KM=monthtemp.split("|").length
	}
	//alert(monthtemp)
	var iWeek = new Date(yeartemp, monthtemp-1, 1).getDay();//星期
	var iEndDay = new Date(yeartemp, monthtemp , 0).getDate();//最后一天
	var iToday = new Date().getFullYear()+"-"+appendZero(new Date().getMonth()+1)+"-"+appendZero(new Date().getDate());//今天
	CalendarText="<div class=\"day\">"
	var M,Money,istyle;
	for(k=1;k<=iWeek;k++){CalendarText+="<p>&nbsp;</p>"}
	for(i=1;i<=iEndDay;i++){
		istyle=""
		//判断日期是否已过
		if ((yeartemp+"-"+appendZero(monthtemp)+"-"+appendZero(i))<iToday){istyle=" class='no1'";}
		//判断是否为当天日期
		
		M="-";
		Money="-"
		
		if(Str.split((yeartemp+"-"+monthtemp+"-"+i+"|").toString()).length>1  ){
			if(Str.split("{$}")[0].split("|")[4].toString()=="yes"){
				M =Str.split("{$}")[0].split("|")[1]+"|"+Str.split("{$}")[0].split("|")[2]+"|"+Str.split("{$}")[0].split("|")[3]+"{$}"
			}else{
				M =Str.split((yeartemp+"-"+monthtemp+"-"+i+"|").toString())[1]; 
			}
			
			M = M.split("{$}")[0]
			M = M.split("|")
			if(M[0].toString()=="0"){
				Money=""
			}else{
				Money="<span style='margin-bottom:6px;margin-top:4px' onmouseover=this.className='font1' onmouseout=this.className='' onclick=\"$JumpPage('"+URL+"&t2="+M[3]+"&x="+escape(NormTxt[0])+"')\">"+NormTxt[0]+": "+M[0].toString()+"元</span>"
			}
			//Money+="<br />"
			if(M[1].toString()=="0"){
				Money+=""
			}else{
				Money+="<span onmouseover=this.className='font1' onmouseout=this.className='' onclick=\"$JumpPage('"+URL+"&t2="+M[3]+"&x="+escape(NormTxt[1])+"')\">"+NormTxt[1]+": "+M[1].toString()+"元</span>"
			}
		
			//alert(M[3])
			if(istyle=="")istyle=" onmouseover=this.className='ifo1' onmouseout=this.className='' "
		}
		if ((yeartemp+"-"+appendZero(monthtemp)+"-"+appendZero(i))==iToday){istyle=" class='ifo2'";Money="<br/>今天"}
		CalendarText+="<p"+istyle+">"+i+"<br /><span>"+Money+"</span></p>"
		if (new Date(yeartemp, monthtemp-1, i).getDay()==7){CalendarText+="</div><div id=\"clear\"></div><div class=\"day\">"}//判断是否到周未
	}
	CalendarText+="</div>"
	
	//alert(CalendarText)
	TEAMTXT="<div class=\"title\"><p><b>线路</b>："+title+"<p><p onclick=\"HiddenTeam()\" class=\"teamclose\">关闭</p></div>"
	TEAMTXT+="<div id=\"clear\"></div><div class=\"year\"><p onclick=\"ShowTeam('"+title+"','"+Str+"',"+(KM-1)+",'"+URL+"','"+Norm+"',1)\" title=\"向前翻 1 月\" style=\"float:left;width:60px;text-align:center;cursor:pointer;color:#F60\">上一月</p><p style=\"float:left;width:440px;font-weight:bold\">"+yeartemp+" 年 "+monthtemp+" 月</p><p onclick=\"ShowTeam('"+title+"','"+Str+"',"+(KM+1)+",'"+URL+"','"+Norm+"',1)\" title=\"向后翻 1 月\" style=\"float:left;width:60px;text-align:center;cursor:pointer;color:#F60\">下一月</p></div>"
	TEAMTXT+="<div id=\"clear\"></div><div class=\"weak\"><p>日</p><p>一</p><p>二</p><p>三</p><p>四</p><p>五</p><p style='border-right:0'>六</p></div>"
	TEAMTXT+="<div id=\"clear\"></div><div class=\"day\">"+CalendarText+"</div><div id=\"clear\"></div>"
	//TEAMTXT+="<div id=\"clear\"></div><div><p>"+TeamTemp.length+"<p></div>"
	//alert(TEAMTXT)
	$("teamlist").innerHTML  = TEAMTXT;
	$("teamlist").style.display = "block";
}
function HiddenTeam(){$("teamlist").style.display="none";}//隐藏层
function appendZero(n){return(("00"+ n).substr(("00"+ n).length-2));}//日期自动补零程序

function travelorder(URL,Norm){
	var NormTxt = ""
	var NormT =$N(Norm)
	for(i=0;i<NormT.length;i++){
            if(NormT[i].checked==true){
				NormTxt=NormT[i].value
			//alert(NormT[i].value)
			}
        }
	//alert(NormTxt)
	$JumpPage(URL+"&x="+escape(NormTxt))
}

function del(url){
if(confirm("确认要删除吗?")){window.location=url}
}

function RegularPic(ID){
	var imgwidth=document.getElementById(ID).width;
	var imgheight=document.getElementById(ID).height;
	//document.getElementById(ID).height="100%";
	//document.getElementById(ID).width="100%";
	
	if (imgwidth>=500){
	    if (imgwidth>=imgheight){
			 document.getElementById(ID).width=500; 
			 //document.getElementById(ID).width=imgheight(imgwidth/500);
		}else{
		    document.getElementById(ID).height=330;
			
		} 
	}
	if (imgheight>=330){
		//if (imgheight>=imgwidth){
			document.getElementById(ID).height=330; 
		//}else{
			 //document.getElementById(ID).width=500; 
		//}
	}//else{
	//document.getElementById(ID).width=imgwidth;
	//}
	
	//if (imgheight>=330){
		//if (imgwidth>=imgheight){
			//document.getElementById(ID).height=330; 
		//}else{
			//document.getElementById(ID).width=500; 
		//}
	//}else{
	   // document.getElementById(ID).height=imgheight;
	//}
}
//设置图片Pic
function GetPic(Name,Pic){
	
	if(Pic.indexOf(".")>-1)$(Name).innerHTML="<img id=\"wpic\" src="+Pic+"  onerror=\"errpic('{$page.url}uploadfile/dnopic.gif',this)\" >"
	RegularPic("wpic");
	
}
function RegularPic1(ID){
	var imgwidth=document.getElementById(ID).width;
	var imgheight=document.getElementById(ID).height;
	if (imgwidth>=113){
	    if (imgwidth>=imgheight){
			 document.getElementById(ID).width=113;  
		}else{
		    document.getElementById(ID).height=100;
		} 
	}else{
	    document.getElementById(ID).width=imgwidth;
	}
	if (imgheight>=100){
		document.getElementById(ID).height=100;  
		document.getElementById(ID).width=113;
	}else{
	    document.getElementById(ID).height=imgheight;
	}
}
function errpic(url,thepic){thepic.src=url}

function TOPPicture(pic,urls,url,n,linkid,picid){
	var xN=n
	var xpic=pic.split("|")
	var xurl=urls.split("|")
	if(xN>xpic.length)xN=1
	$(picid).src=url+xpic[xN-1];
	$(linkid).href=xurl[xN-1];
	window.setTimeout("TOPPicture('"+pic+"','"+urls+"','"+url+"',"+(xN+1)+",'"+linkid+"','"+picid+"')",3000);
}

//在线QQ
function QQMSG(qq,Name){
	if(qq.indexOf("@")==-1){
		location.href="tencent://message/?uin="+qq+"&Site=qq在线客服&Menu=yes";
	}else
	{
		location.href="msnim:chat?contact="+qq;
	}
}

