if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]===obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}
/*	
Number.prototype.toFixed=function(len)
{
var add = 0;
var s,temp;
var s1 = this + "";
var start = s1.indexOf(".");
if(s1.substr(start+len+1,1)>=5)add=1;
var temp = Math.pow(10,len);
s = Math.floor(this * temp) + add;
return s/temp;
}
*/	
// search url  
// eg : QueryString("city")
function QueryString(fieldName)
{  
  var urlString = document.location.search;
  if(urlString != null)
  {
       var typeQu = fieldName+"=";
       var urlEnd = urlString.indexOf(typeQu);
       if(urlEnd != -1)
       {
            var paramsUrl = urlString.substring(urlEnd+typeQu.length);
            var isEnd =  paramsUrl.indexOf('&');
            if(isEnd != -1)
            {
                 return paramsUrl.substring(0, isEnd);
            }
            else
            {
                return paramsUrl;
            }
       }
       else 
       {
            return null;
       }
  }
 else
 {
    return null;
 }
}
//  set count --- start ---

function stopBubble(e)
{
	if (e && e.stopPropagation)
		e.stopPropagation();
	else
		window.event.cancelBubble=true;
}
//
function stopDefault(e)
     {
        if (e && e.preventDefault) 
        e.preventDefault(); 
        else
        window.event.returnValue=false; 
     }
// select city name by id
function getCityNamById(id){
	var result;
	for(i=0;i<cityJson.length;i++){
		if(cityJson[i].areaId == id){
			result =cityJson[i].city;
			break;
		}
	}
	return result;
}
// select city name by id
function getCityspellForShortById(id){
	var result;
	for(i=0;i<cityJson.length;i++){
		if(cityJson[i].areaId == id){
			result =cityJson[i].spellForShort;
			break;
		}
	}
	return result;
}
// select city name by id
function getValueByIdTyp(obj_id,obj_typ){
	var result='';
	if(obj_typ == 'service'){
		var _kk = obj_id.split(',');
		for(i=0; i<_kk.length; i++){
			for(j=0;j<key_json.length;j++){
				if(key_json[j].con_id == _kk[i] && key_json[j].type == obj_typ){
					result += ', '+ key_json[j].name;
					break;
				}
			}
		}
	}else{
		for(i=0;i<key_json.length;i++){
			if(key_json[i].con_id == obj_id && key_json[i].type == obj_typ){
				result =key_json[i].name;
				break;
			}
		}
	}
	if($.trim(result) == ','){
		result='';
	}
	return result;
}
//通过标签name获取vvalue值 例如往返交通   用于checkbox和radio
function getArrayValueByName(name)
{
	var values=new Array();
	var   c   =   document.getElementsByName(name);  
  for(i=0;i<c.length;i++)  
  {  
        if(c[i].checked   ==   true   )  
        {  
               values.push(c[i].value);                
        }  
  }
	return values;
}
//通过标签name获取vvalue值 例如往返交通   用于checkbox和radio
function deleteFirEndStr(str)
{
	return  str.subStr(1,str.length -1);
}
function Trim()
  {    
  return   this.replace(/(^\s*)|(\s*$)/g,   "");    
  } 
  function LTrim()
  {    
  return   this.replace(/(^\s*)/g,   "");   
  } 
  function Rtrim()
  {    
  return   this.replace(/(\s*$)/g,   "");     
  } 
 // startwith
String.prototype.startWith=function(str){
	if(str==null||str==""||this.length==0||str.length>this.length)
	  return false;
	if(this.substr(0,str.length)==str)
	  return true;
	else
	  return false;
	return true;
}//   
function strDecodedddd(str)
	{
	
		if((str+"").indexOf("--")<1)return str;
		var strs=str.split("--");
		if(strs.length<=1)return str;
		var returnstr="";
		
		for(var i=0;i<strs.length;i++)
		{
			
			var test=String.fromCharCode(strs[i]);
			returnstr+=test.toString();
			
		}
		return returnstr;
	}
	/*20090909 galen*/
	// cc= city from, kk =keyword ,ajaDataStr =url  eg : ?aa=ba&bb=ca&cc=ka
	function setSearchHistory(ajaDataStr,cc,kk){
		if(kk == ""){
			kk = cc;
		}
		var strhistory =  (getCookie("oyesgo_search_history")==null || getCookie("oyesgo_search_history")=="")?"":getCookie("oyesgo_search_history");
		var vhref = "http://carrental.oyesgo.com/";
		var currHisStr    ="$"+vhref +"searchCar.html"+ajaDataStr+"+租车+" + kk+ "+"+getToday();//+strhistory;
		currHisStr = encodeURI(currHisStr);
		setCookie("oyesgo_search_history",currHisStr);
		alert(getCookie("oyesgo_search_history"));
	}
	function getToday(){
		var date = new Date();
		var d  = date.getDate();
		var day = (d < 10) ? '0' + d : d;
		var m = date.getMonth() + 1;
		var month = (m < 10) ? '0' + m : m;
		var yy = date.getYear();
		var year = (yy < 1000) ? yy + 1900 : yy;
		return year+"-" +month + "-"+day;		
	}
/**
 * 
 * @param url			搜索条件URL，见下面例子说明
 * @param type			酒店/机票/度假等
 * @param keyword		如家快捷
 * @param date			2009-09-01
 * @param city			北京
 * @return
 */
function getNewCookie(name){
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return decodeURI(arr[2]); return null;
};
function save_new_history(url,type,left,right){
	left = encodeURIComponent(left);
	right = encodeURIComponent(right);
	var content = url+"+"+left+"+"+right;
	var cookie = getNewCookie("oyesgo_search_history_"+type);
	if(cookie!=null){
		var arr = cookie.split("$");
		if(arr.length>=6){
			arr.pop();
			cookie = arr.join("$");
		}
		content = content + "$"+ encodeURI(cookie);
	}
	var Days = 30;
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = "oyesgo_search_history_"+type + "="+ content + ";expires=" + exp.toGMTString()+";path=/;";
};

function display_cookie_local(type, target) {
    var cookie = null;
    cookie = getNewCookie("oyesgo_search_history_" + type);
    if (cookie == null)
       return;
    var arr = cookie.split("$");
    vtext = '<ul>';
    for ( var i = 0; i < arr.length; i++) {
       var arrr = arr[i].split("+");
       var link = arrr[0];
       if (type == "train") {
           link = link.replace(/@/g, "%u");
       }
       vtext += '<li><a href="' + link + '" target="_blank"><span>' + arrr[1]
              + '</span><em>' + arrr[2] + '</em></a></li>';
    }
    vtext += '</ul>';
    if ($(".search_note_pop").length == 0) {
       $("<div class=\"search_note_pop\" style=\"display:none;z-index:999;\"></div>")
              .appendTo(document.body);
    }
    if(target.offset().left+$(".search_note_pop").width() > document.body.offsetWidth){
       $(".search_note_pop").html("").html(vtext).css("left",
              target.offset().left - 348).css("top", target.offset().top + 36)
              .show();
    }else{
       $(".search_note_pop").html("").html(vtext).css("left",
              target.offset().left - 144).css("top", target.offset().top + 36)
              .show();
    }
};
// date check 20091015 galen
function dateValidate(str){
return str.match(/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/);
}

// 20090921  galen  check two array
function arrayIndexOf(a,b){
	for(var i=0;i<a.length;i++){
		for(var j=0;j<b.length;j++){
			if(a[i] == b[j]) {return 1;}
		}
	} 
	return -1;
}	
// 20100201  galen  get today date
function getTodayDate(){
   			var 	today = new Date();   
   			 		today.setDate(today.getDate()+1);			
			var 	s = today.getFullYear()+ "-";
			        if((today.getMonth() + 1)< 10){
			        	s += '0' +(today.getMonth() + 1) + "-" ;
			        }else{
			        	s += (today.getMonth() + 1) + "-" ;
			        }	  				
	  				if(today.getDate()<10){
			        	s += '0' +today.getDate();	
			        }else{
		  				s += today.getDate();
			        }  
	  	return s;
}	
	