﻿$import("/hcrm/website/hotelhome/js/requestSource.js","js");//订单跟踪
//lightbox跳出窗口
var GB_ROOT_DIR = "/hcrm/website/hotelhome/js/greybox/";
$import("/hcrm/website/hotelhome/js/greybox/AJS.js","js");
$import("/hcrm/website/hotelhome/js/greybox/gb_scripts.js","js");
//lightbox结束

$import("/hcrm/website/hotelhome/js/calendar/calendar.js","js");//日历
$import("/hcrm/website/hotelhome/js/md5.js","js");//登录加密



//定义了城市的二维数组，里面的顺序跟省份的顺序是相同的。通过selectedIndex获得省份的下标值来得到相应的城市数组
     var hotels=[
		[{"code":"00163","name":"南京金鹰珠江壹号国际酒店"},{"code":"00848","name":"南京国仕达酒店"}],
		[{"code":"02673","name":"芜湖新百·金鹰国际酒店"}],
		[{"code":"03223","name":"昆明金鹰广场酒店"}]
     ];

     function getCity(){
         //获得省份下拉框的对象
         var sltProvince=document.forms['queryPriceForm'].province;
         //获得城市下拉框的对象
         var sltCity=document.forms['queryPriceForm'].hotels;
         
         //得到对应省份的城市数组
         var provinceCity=hotels[sltProvince.selectedIndex - 1];

         //清空城市下拉框，仅留提示选项
         sltCity.length=1;

         //将城市数组中的值填充到城市下拉框中
         for(var i=0;i<provinceCity.length;i++){
             sltCity[i+1]=new Option(provinceCity[i].name,provinceCity[i].code);
         }
     }







var language="chs";

//********日期函数********
var gDateDelimiter="-";		//日期分隔符
function gGetDateTimeStr(iChoice,oDate){
	var yy=oDate.getFullYear(), mm=oDate.getMonth()+1, dd=oDate.getDate();
	var hh=oDate.getHours(), nn=oDate.getMinutes(), ss=oDate.getSeconds();
	if(mm<10) mm="0"+mm;
	if(dd<10) dd="0"+dd;
	if(hh<10) hh="0"+hh;
	if(nn<10) nn="0"+nn;
	if(ss<10) ss="0"+ss;
	if(iChoice==0) return (yy+gDateDelimiter+mm+gDateDelimiter+dd);
	if(iChoice==1) return (hh+":"+nn+":"+ss);
	if(iChoice==2) return (yy+gDateDelimiter+mm+gDateDelimiter+dd+" "+hh+":"+nn+":"+ss);
	return "";
}
function gDateAdd(dateStr,addYear,addMonth,addDate){
	var dt=new Date(Date.parse(gReplace(dateStr,"-","/")));
	dt.setFullYear(dt.getFullYear()+addYear);
	dt.setMonth(dt.getMonth()+addMonth);
	dt.setDate(dt.getDate()+addDate);
	return gGetDateTimeStr(0,dt);
}
function gGetToday(){
	return gGetDateTimeStr(0,new Date());
}
function gReplace(src,sFor,sBy){
	if(sFor==""||sBy=="") return src;
	for(var l=sFor.length,s="",p0=0,p;(p=src.indexOf(sFor,p0))>=0;s+=src.substring(p0,p)+sBy,p0=p+l);
	return (s+src.substring(p0));
}
//********日期函数结束********

//预订自动加载时间
function getQueryString(name) {
   if (location.href.indexOf("?") == -1 || location.href.indexOf(name + '=') == -1) {
            return '';
   }
   var queryString = location.href.substring(location.href.indexOf("?") + 1);
   var parameters = queryString.split("&");
   var pos, paraName, paraValue;
   for (var i = 0; i < parameters.length; i++) {
            pos = parameters[i].indexOf('=');
            if (pos == -1) {
                     continue;
            }
            paraName = parameters[i].substring(0, pos);
            paraValue = parameters[i].substring(pos + 1);
            if (paraName == name) {
                    return unescape(paraValue.replace(/\+/g, " "));
            }
   }
   return '';
}


function MM_preloadcalendar() { //v3.0
  try{
	var sdt=gGetToday();
	var f=document.queryPriceForm;
	var p_checkInDate = getQueryString('checkInDate');
	
	if(p_checkInDate ==''){f.checkInDate.value=sdt;  }
		else {f.checkInDate.value = p_checkInDate;}
	var p_checkOutDate = getQueryString('checkOutDate');
	if(p_checkOutDate==''){f.checkOutDate.value=gDateAdd(sdt,0,0,1); }
 		else {f.checkOutDate.value=p_checkOutDate;}
  }
  catch (e){
  }
}
MM_preloadcalendar();

function afterSetDay()
{
	//预订入住时间
	var f=document.queryPriceForm;
	if(outObject.name=="checkInDate" && f.checkInDate.value>=f.checkOutDate.value)	
		f.checkOutDate.value=gDateAdd(f.checkInDate.value,0,0,1);
	else if(outObject.name=="checkOutDate" && f.checkInDate.value>f.checkOutDate.value)
		f.checkInDate.value=gDateAdd(f.checkOutDate.value,0,0,-1);
}

//查询按钮
function queryPrice(){
	var f=document.queryPriceForm;
	if(f.checkInDate.value<gGetToday())
	{
		alert("入住日期先于今日！");
		f.checkInDate.value=gGetToday();
		f.checkOutDate.value=gDateAdd(f.checkInDate.value,0,0,1);
		return false;
	}
	
	if(f.checkInDate.value>=f.checkOutDate.value){
		alert("离店日期先于入住日期！");
		return false;
	}
	if(f.checkOutDate.value>gDateAdd(f.checkInDate.value,1,0,0))
	{
		alert("入住时间大于一年！");
		f.checkOutDate.value=gDateAdd(f.checkInDate.value,1,0,0);
		return false;
	}
	if(f.hotels.value==""){
  	  alert("请选择要查询的酒店！");		
		return false;
	}
	else if(f.hotels.value=='003'){
  	  alert("客房预订正在建设中！");		
		return false;
	}
	else{
		var paras="hotelCode="+f.hotels.value+"&language="+language+"&checkInDate="+f.checkInDate.value
			+"&checkOutDate="+f.checkOutDate.value+"&roomNum="+f.roomNum.value+"&source="+getCookie("dplatform_source");
		var paction;
		if(f.hotels.value=='00848'){
			paction=getHotelIp(f.hotels.value)+"/hcrm/website/hotelhome/00848/cn/booking.jsp?"+paras;
		} else {
			paction=getHotelIp(f.hotels.value)+"/hcrm/FITRoomOrder.do?method=addForFIT&"+paras;
		}
	//var paction=getHotelIp(f.hotels.value)+"/hcrm/FITRoomOrder.do?method=addForFIT&hotelCode="
	//		+f.hotels.value+"&language="+language+"&checkInDate="+f.checkInDate.value
	//		+"&checkOutDate="+f.checkOutDate.value+"&roomNum="+f.roomNum.value;

	GB_showCenter(getHotelName(f.hotels.value),paction,550,650);//酒店名字，550是高，650是宽，根据需要修改。
	return '';
	}
	//f.action=paction;
	//this.href=paction;
	//f.target="_blank";
	//f.submit();
}

//用户登录
function validate(){
	var f=document.forms.loginForm;
	//f.hotelCode.value=hotelCode;
	f.language.value=language;
	if (f.loginName1.value==""){
		window.alert("用户名不能为空！");
		f.loginName1.focus();
		return false;
	}
	if (f.password1.value==""){
		window.alert("密码不能为空！");
		f.password1.focus();
		return false;
	}
	if(f.hotelCode.value==""){
  	    alert("请选择要登录的酒店！");		
		return false;
	}	
	f.password.value=MD5(f.password1.value);
	f.loginName.value=f.loginName1.value;
	f.password1.value="";
	f.loginName1.value="";
	return true;
}

//判断登录
function g_login(){
	if (!validate()) {
		return false;
	}	
	ajax_validate();
	return false;
}
function loginByUserType(type){
	if(type.isHotel){
		var f = document.forms.loginForm;
		f.action =getHotelIp(f.hotelCode.value)+'/hcrm/logon.do';
		f.submit();
	}else if(type.isGuest){
		guest_login();
	}
}
function guest_login(){
	var f = document.forms.loginForm;
	var url =getHotelIp(f.hotelCode.value)+"/hcrm/logon.do?hotelCode="+f.hotelCode.value+"&language="+language
				+"&loginName="+encodeURI(f.loginName.value)
				+"&password="+f.password.value
				+"&loginType=hotel&loginPage=hotelLogin.jsp";
	GB_showCenter(getHotelName(f.hotelCode.value),url,550,650);//酒店名字，550是高，650是宽，根据需要修改。
}
//判断登录结束

//我的预订
function mybooking()
{
	
	var f=document.queryPriceForm;
	var hotels = document.queryPriceForm.hotels.value;
	if(f.hotels.value==""){
  	  alert("请选择要查询订单的酒店！");		
		return;
	}else if(f.hotels.value=='003'){
  	  alert("该店正在建设中！");		
		return;
	}else{
	 var url =getHotelIp(f.hotels.value)+"/hcrm/FITRoomOrder.do?method=queryOrder&language="+language+"&hotelCode="+f.hotels.value;
	 GB_showCenter(getHotelName(hotels),url,450,650);//酒店名字，550是高，650是宽，根据需要修
	}
}

function getHotelName(hotelCode){
	if(hotelCode=='00163'){
		return '南京金鹰珠江壹号国际酒店';
	}else if(hotelCode=='02673'){
		return '芜湖新百·金鹰国际酒店';
	}else if(hotelCode=='00848'){
		return '南京国仕达酒店';
	}else if(hotelCode=='03223'){
		return '昆明金鹰广场酒店';
	}else{
		return '';
	}
}

function getHotelIp(hotelCode){
	if(hotelCode=='00163'){
		return 'http://211.144.86.157';
	}else if(hotelCode=='02673'){
		return 'http://211.144.87.79';
	}else if(hotelCode=='00848'){
		return 'http://211.144.87.20';
	}else if(hotelCode=='03223'){
		return 'http://211.144.86.161';
	}else{
		return '';
	}
}

//取回密码
function findPassword()
{
	var f=document.forms.loginForm;
	var hotelCode = document.loginForm.hotelCode.value;
	if(hotelCode==""){
  	  alert("请选择要找回密码的酒店！");		
		return;
	}

 var url =getHotelIp(f.hotelCode.value)+"/hcrm/FITMember.do?method=forgetPassword&hotelCode="+hotelCode+"&language="+language;
 GB_showCenter(getHotelName(hotelCode),url,450,650);//酒店名字，550是高，650是宽，根据需要修改。
 
}



//注册
function register()
{
	var f=document.forms.loginForm;
	var hotelCode = document.loginForm.hotelCode.value;
	if(hotelCode==""){
  	  alert("请选择要注册的酒店！");		
		return;
	}	

	var url =getHotelIp(f.hotelCode.value)+"/hcrm/FITMember.do?method=addForWeb&hotelCode="+hotelCode+"&language="+language;
	GB_showCenter(getHotelName(hotelCode),url,550,650);//酒店名字，550是高，650是宽，根据需要修改。	
}






function $import(path, type){
  if (type == "css") {
      document.write("<" + "link rel=\"stylesheet\" rev=\"stylesheet\" href=\"" + path + "\" type=\"text/css\" media=\"screen\" />");
  } else {
      document.write("<" + "script src=\"" + path + "\" type=\"text/javascript\"></" + "script>");
  }
}






//判断登录的，基本上不需要改动
function ajax_validate(){

	var head = document.getElementsByTagName("head")[0];
	var script = document.getElementById('login_script');
	if(script){
		head.removeChild(script);
	}
	var f=document.forms.loginForm;	
	var url =getHotelIp(f.hotelCode.value)+'/hcrm/website/hotelhome/logon1.jsp';//如有需要改动地址，这边也请加上！

	var paras = 'hotelCode='+f.hotelCode.value
				+'&language='+f.language.value
				+'&loginName='+f.loginName.value
				+'&password='+f.password.value;	
				
	script = document.createElement("script");
	script.id = 'login_script';
	script.type = 'text/javascript';
    script.src = url + '?' + paras;

	head.appendChild(script);
}

//判断登录的，基本上不需要改
