function GetQueryString(name) 
{ 
 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
 var r = window.location.search.substr(1).match(reg); 
 if (r!=null) return unescape(r[2]); return null; 
}

function isInteger( str )
{  
    var regu = /^[-]{0,1}[0-9]{1,}$/;

    return regu.test(str);
}

$(document).ready(function(){
	$("#hotel_num_t").bind("change", function()
	{
		var num = $(this).val();
		$("#num").val( num );
		$("#hotel_adult_t").val(num);
		$('#adult').val(num);
	});
	$("#hotel_adult_s").bind("change", function()
	{
		$("#adult").val( $(this).val() );
		
	});
	
	$("#hotel_adult_t").bind("change", function()
	{
		$("#adult").val( $(this).val() );
		$("#hotel_adult_t").val( $(this).val() );
	});
	$("#hotel_child_s").bind("change", function()
	{
		$("#child").val( $(this).val() );
	});
	$("#hotel_child_t").bind("change", function()
	{
		$("#child").val( $(this).val() );
	});
	$("#country").bind("change", function()
	{
		getCity( $(this).val() );
	});
	
	
	$("#hotel_num_s").bind("change", function()
	{
		var num = $(this).val();
		$("#num").val( num );
		var str = "";
		if(Number(num)!=10)
		{
			$("#hotel_adult_s").html("");
			for(var i=num;i<=num*4;i++)
			{
				str = str + "<option value="+i+" >"+i+"</option>";
			}
			$("#hotel_adult_s").append(str);
		}
		else
		{	
			$(this).attr("style","display:none");
			$("#hotel_adult_s").attr("style","display:none");
			$("#hotel_child_s").attr("style","display:none");
			
			$("#hotel_num_t").attr("style","");
			$("#hotel_adult_t").attr("style","");
			$("#hotel_child_t").attr("style","");
			
			$('#hotel_num_t').val(1);
			$('#hotel_adult_t').val(2);
			$('#hotel_child_t').val(0);
			
			$('#num').val(1);
			$('#adult').val(2);
			$('#child').val(0);
		}
	});
});

function getDateDiff (small, big) 
{
    return (big-small)/1000/60/60/24;
}
function setTourTipe(obj)
{
	document.getElementById('webTopTourTypeIndex').value=obj.getAttribute('tourTypeIndex');

	var lineTag  = obj.getAttribute('lineTag');
	
	if(null!=lineTag)
	{
		document.getElementById('lineTag').value = obj.getAttribute('lineTag');
	}
	
	document.getElementById('webTopSubmit').click();
}
function search(keyword)
{
	var keyword = $('#'+keyword).attr("value");

	if(null==keyword || keyword=='' || keyword=='景点搜索')
		return ;
	else
		location.href=contextPath + '/webSite/scenicSpots/searchjd.jsp?keyword='+keyword;
}
//收藏网站代码 
function favSite() 
{ 
    //网站网址 
    url  ='http://www.tianhai.com/'; 
    //网站名称 
    title="天海旅游网"; 
    if (window.sidebar) 
    { 
        window.sidebar.addPanel(title,url,""); 
    } 
    else  if(document.all) 
    {  
        window.external.AddFavorite(url,title); 
    } 
    else 
    { 
        return   true; 
    } 
} 
function logout()
{
	var path = contextPath + "/webSite/member!logonOut.do";
		var obj = new Ajax.Request(
			path,{
				method:'post',
				parameters:'',
				onSuccess:function(o){
					window.location=contextPath ;
				}
			}
		);
}
function openOnlineService()
{
	var flag = "no"
	
	var features = "help=no,height=" + 494 +
    "px,width=" + 535 +
    "px,scroll=" + flag + 
    ",resizable=" + flag + 
    ",location=" + flag + 
   ",top=" + (screen.height-464)/2 + 
    ",left=" + (screen.width-535)/2 + 
    ",toolbar=" + flag + 
    ",menubar=" + flag + 
    ",status=" + flag;
	var win = window.open(contextPath + "/oa/msg/cometClient.jsp", "customerService", features );
	win.focus();
}


function getCountry(selVal)
{
	$("#country").append("<option value=0 >选择国家</option>");
	var insertStr = '';
	$.ajax({url:"/xml/hot/Country.xml",
        success:function(xml){
		    	$(xml).find("data > country").each(function(){ 
	    			var country_id = $(this).find("country_id").text();
					var foreign_country_name = $(this).find("foreign_country_name").text();

					var selHTML = ""
					if(''!=selVal && 0!=selVal && country_id ==selVal)
					{
						selHTML = "selected=\"selected\"";
					}
					insertStr = insertStr + "<option value="+country_id+" "+selHTML+" >"+foreign_country_name+"</option>";
					
				}); 
		    	$("#country").append(insertStr);
        }
	});
}

function openMap(path)
{
	var flag = "no"
	var features = "help=no,height=" + 694 +
	   "px,width=" + 935 +
	   "px,scroll=" + flag + 
	   ",resizable=" + flag + 
	   ",location=" + flag + 
	  ",top=" + (screen.height-694)/2 + 
	   ",left=" + (screen.width-935)/2 + 
	   ",toolbar=" + flag + 
	   ",menubar=" + flag + 
	   ",status=" + flag;
	var win = window.open(path, "googleMap", features );
	win.focus();
}

var selCityName = "";

function getCity(countryId,selVal)
{
	if(0!=countryId && '0'!=countryId)
	{
		$("#city").html("<option value=0 >加载中....</option>");
		city.length=1;
		var requestPath = "/xml/city/"+countryId+".xml";
		$.ajax({url:requestPath,
			cache:true,
	        success:function(xml){
	        		var str = "";
	        		var i=0;
	        		var city_id ;
					var foreign_city_name;
					var selHTML = "";
			    	$(xml).find("data > city ").each(function(){ 
			    		city_id = $(this).find("city_id").text();
			    		foreign_city_name = $(this).find("foreign_city_name").text();	
						if(i==0 || (''!=selVal && 0!=selVal && city_id ==selVal))
						{
							selHTML = "selected=\"selected\"";
							selCityName = foreign_city_name;
							i++;
							$("#city").html("<option value="+city_id+" >"+foreign_city_name+"</option>");
						}
						else
						str = str + "<option value="+city_id+" >"+foreign_city_name+"</option>";
						
					}); 
			    	$("#city").append(str);
	        }
		});
	}
}

function getHotelList(hisList)
{
	var hotelHis = getCookie("hotelHis");
	
	$("#"+hisList);
}

function addCookie( value )
{
	var historyList = getCookie("hotelHis");
	var flag = true;
	
	var allStr = getCookie("hotelHis");
	
	var allStr = "["+allStr.substring(0,allStr.length-1)+"]";
	var allArr = eval(allStr);
	var vaArr = eval(value);
	var len =(allArr.length>5)?5:allArr.length;
	
	for(var i=0;i<len;i++)
	{
		if(allArr[i][0]===vaArr[0])
		{
			flag = false;
		}
	}
	if(flag)
	{
		historyList = value+","+historyList
		
		setCookie("hotelHis",historyList);
	}
}
function getCookieList(innerObj,contextPath)
{
	var allStr = getCookie("hotelHis");
	if(null==allStr || 'null'==allStr)
	{
		return ;
	}
	var allStr = "["+allStr.substring(0,allStr.length-1)+"]";
	var allArr = eval(allStr);
	
	var len =(allArr.length>5)?5:allArr.length;
	
	var innerStr ="";
	
	for(var i=0;i<len;i++)
	{
		var city_Id = allArr[i][2];
		
		var path =contextPath+'/webSite/hotel/hotelDetail.jsp?hotel_id='+allArr[i][0]+'&hotelInfo.city_Id='+city_Id;
		
		if('hotel'==allArr[i][4])
		{
			path =contextPath+"/webSite/hotel/hotelDetail.jsp?hotel_id="+allArr[i][0]+"&hotelInfo.city_Id="+city_Id;
		}
		var nameA = allArr[i][1];
		
		if(null!=nameA && undefined!=nameA && nameA.length>65)
        {
        	nameA = nameA.substring(0,65)+"....";
        }
		innerStr = innerStr +"<li class=\"hotel_home\"><a href='"+path+"' title='"+allArr[i][1]+"' target='_blank' >"+nameA+"</a></li>";
	}
    innerStr = innerStr +"<div class='clear'></div>";
    document.getElementById(innerObj).innerHTML = innerStr;
}

function queryHotel()
{
	var num = $('#num').val();
	var adult = $('#adult').val();
	var child = $('#child').val();
	var city = $('#city').val();
	var country = $('#country').val();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	
	if('0'==country || ''==country || null==country || undefined ==country)
	{
		alert('请选择国家!!');
		return false;
	}
	if('0'==city || ''==city  || null==city || undefined ==city)
	{
		alert('请选择城市!!');
		return false;
	}
	if(''==startDate || null==startDate || undefined ==startDate)
	{
		alert('请选择入住时间!!');
		return false;
	}
	if(''==endDate || null==endDate || undefined ==endDate)
	{
		alert('请选择离店时间!!');
		return false;
	}
	if(Number( Date.parse(endDate.replace("-","/")) - (Date.parse(startDate.replace("-","/")) ))<1)
	{
		alert('离店时间需大于入住时间!!');
		return false;
	}

	if( ''==num || null==num || undefined ==num || 0 ==num)
	{
		alert('房间数不能为空或为零!!');
		return false;
	}
	if(!isInteger( num ))
	{
		alert('房间数只能填数字!!');
		return false;
	}

	if( ''==adult || null==adult || undefined ==adult || 0 ==adult)
	{
		alert('成人数不能为空或为零!!');
		return false;
	}
	if(!isInteger( adult ))
	{
		alert('成人只能填数字!!');
		return false;
	}
	if(!isInteger( child ))
	{
		alert('小童只能填数字!!');
		return false;
	}

	var num = $('#num').val();
	var adult = $('#adult').val();
	var child = $('#child').val();
	var city = $('#city').val();
	var country = $('#country').val();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	var hotelName = $('#hotelName').val();
	var hprice = $('#hprice').val();
	var hstar = $('#hstar').val();
	
	var paramStr="?star="+hstar+"&price="+hprice+"&num="+num+"&adult="+adult+"&child="+child+"&city="+city+"&country="+country+"&startDate="+startDate+"&endDate="+endDate+"&hotelName="+hotelName;
	var path = contextPath + "/webSite/hotel/hotelList.jsp" + paramStr;
	window.location =  path ;
}

