var MESSAGE_REPLACE_CHAR = "@#$%";
var MESSAGE_REPLACE_CHAR2 = "#$%@";
var MESSAGE_REPLACE_CHAR3 = "$%@#";
//定义错误信息提示框
function showErrorTR(trId, spanId, picpath){
	var str = "";
	str = //"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">"
	    // "<TR ID=\"" + trId + "\" name=\"" +  trId + "\" style=\"display:none\">" +
		// "	<TD align=center width=10%>" +
		  "		<table width=\"95%\" ID=\"" + trId + "\" height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\" style=\"display:none\">" +
		  "			<tr height=\"10\" >" +
		  "				<td width=\"10\"><img src=\"" + picpath + "images/trip/error_tl.gif\" border=\"0\" alt=\"\" WIDTH=\"10\" HEIGHT=\"10\"></td>" +
		  "				<td style=\"background:url(" + picpath + "images/trip/error_t.gif);\"  colspan=\"3\"></td>" +
		  "				<td width=\"10\"><img src=\"" + picpath + "images/trip/error_tr.gif\" border=\"0\" alt=\"\" WIDTH=\"10\" HEIGHT=\"10\"></td>" +
		  "			</tr>" +
		  "			<tr>" +
		  "				<td BACKGROUND=\"" + picpath + "images/trip/error_l.gif\" ></td>" +
		  "				<td valign=\"top\" BGCOLOR=\"#F7F7F7\" ><img src=\"" + picpath + "images/trip/warnn.gif\" width=\"20\" height=\"20\" border=\"0\" alt=\"Please be aware\" title=\"\"></td>" +
		  "				<td colspan=\"2\"width=\"100%\" align=\"left\" BGCOLOR=\"#F7F7F7\">" +
		  "					<span id=\"" + spanId + "\" name=\"" + spanId + "\" STYLE=\"color:#A01E00;font-size:12px;font-Weight:bold\" class=errorTextStd></span>" +
		  "				</td>" +
		  "				<td BACKGROUND=\"" + picpath + "images/trip/error_r.gif\" ></td>" +
		  "			</tr>" +
		  "			<tr height=\"10\" >" +
		  "				<td><img src=\"" + picpath + "images/trip/error_bl.gif\" border=\"0\" alt=\"\" WIDTH=\"10\" HEIGHT=\"10\"></td>" +
		  "				<td style=\"background:url(" + picpath + "images/trip/error_b.gif);\" colspan=\"3\"></td>" +
		  "				<td><img src=\"" + picpath + "images/trip/error_br.gif\" border=\"0\" alt=\"\" WIDTH=\"10\" HEIGHT=\"10\"></td>" +
		  "			</tr>" +
		  "		</table>" ;
		 // "	</TD>" +
		 // "</TR><table>";
	return str;
}
//定义错误信息提示框
function showErrorTR_Right(trId, spanId, picpath){
	var str = "";
	str = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"96%\" ID=\"" + trId + "\" style=\"display:none\"><TR>" +
		  "	<TD align=center width=10%>" +
		  "		<table width=\"100%\" height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">" +
		  "			<tr height=\"10\" >" +
		  "				<td width=\"10\"><img src=\"" + picpath + "images/trip/error_tl.gif\" border=\"0\" alt=\"\" WIDTH=\"10\" HEIGHT=\"10\"></td>" +
		  "				<td BACKGROUND=\"" + picpath + "images/trip/error_t.gif\" colspan=\"3\"></td>" +
		  "				<td width=\"10\"><img src=\"" + picpath + "images/trip/error_tr.gif\" border=\"0\" alt=\"\" WIDTH=\"10\" HEIGHT=\"10\"></td>" +
		  "			</tr>" +
		  "			<tr>" +
		  "				<td BACKGROUND=\"" + picpath + "images/trip/error_l.gif\" ></td>" +
		  "				<td valign=\"top\" BGCOLOR=\"#F7F7F7\" ><img src=\"" + picpath + "images/trip/warnn.gif\" width=\"20\" height=\"20\" border=\"0\" alt=\"Please be aware\" title=\"\"></td>" +
		  "				<td colspan=\"2\"width=\"100%\" align=\"left\" BGCOLOR=\"#F7F7F7\">" +
		  "					<span id=\"" + spanId + "\" name=\"" + spanId + "\" STYLE=\"color:#A01E00;font-size:12px;font-Weight:bold\" class=errorTextStd></span>" +
		  "				</td>" +
		  "				<td BACKGROUND=\"" + picpath + "images/trip/error_r.gif\" ></td>" +
		  "			</tr>" +
		  "			<tr height=\"10\" >" +
		  "				<td><img src=\"" + picpath + "images/trip/error_bl.gif\" border=\"0\" alt=\"\" WIDTH=\"10\" HEIGHT=\"10\"></td>" +
		  "				<td BACKGROUND=\"" + picpath + "images/trip/error_b.gif\" colspan=\"3\"></td>" +
		  "				<td><img src=\"" + picpath + "images/trip/error_br.gif\" border=\"0\" alt=\"\" WIDTH=\"10\" HEIGHT=\"10\"></td>" +
		  "			</tr>" +
		  "		</table>" +
		  "	</TD>" +
		  "</TR><table>";
	return str;
}
//显示错误
function showError(objTR,objSpan,errStr){
	//objTR.style.display = "block";
	objTR.style.display = "";
	objSpan.innerHTML = errStr;
	
}
//判断浏览器类型
function isIE(){
	return (navigator.appName.indexOf("Explorer") > -1);
}
//判断是否是日期格式
function isDate(sDate) 
{
	var iYear, iMonth, iDay, iIndex

	var	reg
	reg = new RegExp('[^0-9-]','')
	if (sDate.search(reg) >= 0)
		return false;
	
	iIndex = sDate.indexOf('-');
	if ( iIndex == -1 )
		return false;
	else 
	{
		iYear = parseFloat(sDate.substr(0, iIndex));
		if ( isNaN(iYear) || iYear < 1900 || iYear > 2099 )
			return false;
		else
			sDate = sDate.substring(iIndex + 1, sDate.length);
	}
	
	iIndex = sDate.indexOf('-');
	if ( iIndex == -1 )
		return false;
	else 
	{
		iMonth = parseFloat(sDate.substr(0, iIndex));
		if ( isNaN(iMonth) || iMonth < 1 || iMonth > 12 )
			return false;
		else
			sDate = sDate.substring(iIndex + 1, sDate.length);
	}
	
	iIndex = sDate.indexOf('-');
	if ( iIndex >= 0 )
		return false;
	else {
		iDay = parseFloat(sDate);
		if ( isNaN(iDay) || iDay < 1 || iDay > 31 )
			return false;
	}
	
	
	switch(iMonth) 
	{
		case 4:
		case 6:
		case 9:
		case 11:
			if ( iDay > 30 )
				return false;
			else
				break;
		case 2:
			if ( ( ( iYear % 4 == 0 && iYear % 100 != 0 ) || iYear % 400 == 0 ) && iDay > 29 )
				return false;
			else if ( (iYear % 4 != 0 || (iYear % 100 == 0 && iYear % 400 != 0)) && iDay > 28 )
				return false;
			else
				break;
		default:
	}
	return true;
}
//转化成日期格式
function parseDate(sDate) 
{
	var year, month, day
	var iaDate = new Array(3)
	
	iaDate = sDate.toString().split("-")
	year = parseFloat(iaDate[0])
	month = parseFloat(iaDate[1]) - 1
	day=parseFloat(iaDate[2])
	return (new Date(year,month,day))
}
//比较日期
function compareDate(date1,date2)
{
	return (parseDate(date1) - parseDate(date2));	
}
//校验日期
function checkDate(date){
		var objTR = document.getElementById("TR_DateError");
		var objSpan = document.getElementById("Span_DateError");
		var error = "";
		var sDate = document.searchForHotel.calstart.value;	
		var eDate = document.searchForHotel.calend.value;	
		var checkInDateIsNull = false;
		var checkOutDateIsNull = false;
		
	    if(sDate.trim() == "")
	    {
	    	error += hotelc_NON_INDATE + '<br>';
	    	checkInDateIsNull = true;
	    }
	   
	    if(eDate.trim() == "")
	    {
	    	error += hotelc_NON_OUTDATE + "<br>";
	    	checkOutDateIsNull = true;
	    }    
	 
	    if(!checkInDateIsNull && !isDate(sDate))
	    {
	    	error += hotelc_ERROR_INDATE + "<br>";
	    }
	     
	    
	    if(!checkOutDateIsNull && !isDate(eDate))
	    {
	    	error += hotelc_ERROR_OUTDATE + "<br>";
	    }
	    
	    if(error != ""){
	    	showError(objTR,objSpan,error);
	    	//alert(error);
	    	return false;
	    }
	    /*
	    //比较起始日期和当前日期
	    if(compareDate(sDate,document.searchForHotel.hidNowDate.value) < 0)
	    {
	        showError(objTR,objSpan,hotelc_INVALID_INDATE + document.searchForHotel.hidNowDate.value + "!");
	        document.searchForHotel.calstart.focus();
	        return false;
	    }
	   */
	      //比较起始日期和截止日期
	    if(compareDate(sDate,document.searchForHotel.hidLastDate.value) >= 0)
	    {
	        showError(objTR,objSpan,hotelc_BOOKING_ALERT.replace(MESSAGE_REPLACE_CHAR,document.searchForHotel.hidLastDate.value));
			//alert(hotelc_INVALID_INDATE_S);
	       // document.searchForHotel.calstart.focus();
	        return false;
	    }
	   //比较结束日期和开始日期
	    if(compareDate(eDate,document.searchForHotel.calstart.value) <= 0)
	    {
	       showError(objTR,objSpan,hotelc_INVALID_OUTDATE_1);
	      // alert(hotelc_INVALID_OUTDATE_1);
	        document.searchForHotel.calstart.value = date;
	       // document.searchForHotel.calend.focus();
	        return false;
	    }
	   
	    
	    //比较结束日期和截止日期
	    if(compareDate(eDate,document.searchForHotel.hidLastDate.value) > 0)
	    {
	        showError(objTR,objSpan,hotelc_BOOKING_ALERT.replace(MESSAGE_REPLACE_CHAR,document.searchForHotel.hidLastDate.value));
			//alert(hotelc_INVALID_INDATE_E);
	       // document.searchForHotel.calend.focus();
	        return false;
	    }
	    
	    //比较结束日期和开始日期间隔
	    if(compareDate(eDate,document.searchForHotel.calstart.value) > 20*24*60*60*1000)
	    {
	       showError(objTR,objSpan,hotelc_INVALID_DATE);
	       // alert(hotelc_INVALID_DATE);
	      //  document.searchForHotel.calend.focus();
	        return false;
	    }
	    
	    return true;
}
//校验城市 
function checkCity(){
	//document.searchForHotel.selectedcity.value = "";
	var objTR = document.getElementById("TR_CityError");
	var objSpan = document.getElementById("Span_CityError");
	var cityID = document.searchForHotel.hotelCityID.value;
	//需要处理TODO
	if(cityID==""){
		showError(objTR,objSpan,hotelc_NON_CITY);
        return false;
	}
	return true;
}
//做Trim操作
String.prototype.trim = function()
{
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}
//城市名称和城市ID关联TODO
function cityNameOnFocus(objValue){
		var obj = document.getElementById("hotel_CityID");
		if(obj.value.trim()==objValue||obj.value.trim()==""){
			document.getElementById("hotelCityID").value = "";
		}
	}

//------ add by tangjian  Start -------
function getInnerText(obj){
	if(isIE())
		return obj.innerText;
	else
		return  obj.textContent;
}

function setInnerText(obj,text){
	if(isIE())
		obj.innerText = text;
	else
		obj.textContent =text;
}

function selectAddoption(select,option){
	if(isIE())
		select.add(option);
    else
    	select.appendChild(option);
}

function setStyle(obj,cssText){
	if(isIE()){
		obj.style.cssText = cssText;
	}else{
		obj.setAttribute("style",cssText);
	}
}

function isInteger(sNum){
	var	num;
	num=new RegExp('[^0-9_]','');
	if (isNaN(sNum)) {
		return false
	}
	else {
		if (sNum.search(num)>=0) {
			return false
		}else {
			return true
		}
	}
}
function getObj(objID){
	return document.getElementById(objID);
}
//------ add by tangjian  End -------