function loadDataURL(id,url,position){
	if(position==null){
		position=1;  
	}
	//url = url+"&s="+new Date().getTime();
	$.get(url,function(response){
		$("#"+id).empty();
		switch(position){
			case '1': $("#"+id).append(response);break;
			case '2': $("#"+id).prepend(response);break;
			case '3': $("#"+id).before(response);break;
			case '4': $("#"+id).after(response);break;
			default:$("#"+id).empty();$("#"+id).prepend(response);break;
		}
	});
}
function addBookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}

var onFocusID = "";
function absPos(node){
            var x=y=0;
            do{
                x =node.offsetLeft;
                y =node.offsetTop;
            }while(node=node.offsetParent);  
            return{  
                'x':x,  
                'y':y  
            };        
}
//

 function login(){
	showPla();
}

function showPla(){
	var width = $('#pla').width();
   	var height = $('#pla').height();
   	if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
   	    width = ($(window).width() - width)/2 ;
   	}else{
   	    width =($(window).width() - width)/2 ;
   	}
   	height = ($(window).height() - height) /2;
    $.blockUI({ message: $('#pla'),
    css: {
    border: 'none',
            top:  height + 'px',
            left: width + 'px'
         }
    });
}

function ajaxSubmit(){
	/*var link = document.getElementById("loginForm").action;
	$('#loginForm input[name]').each(function(i){
		if(i == 0)
			link = link + "?" + this.name + "=" + this.value; 
		else
			link = link + "&" + this.name + "=" + this.value;
	});
	var flag = false;
	 $.ajax({
         type : "GET",
         url : link,
         async:false,
         dataType : "jsonp",
         jsonp: 'callback',
         success : function(json){
             if(json.message == 'success'){
             	flag = true;
             	setTimeout('submitOrder()', 500);
             	alert(link);
             }
         }
     });
    setTimeout('validateReturn('+flag+')', 2000);*/
    var link = document.getElementById("loginForm").action;
    $('#loginForm input[name]').each(function(i){
		if(i == 0)
			link = link + "?" + this.name + "=" + this.value; 
		else
			link = link + "&" + this.name + "=" + this.value;
	});
	link = link + "&num=" + Math.random();
    $.ajax({
    	type : "GET",
         url : link,
         cache :false,
         async:false,
         success : function(json){
         	
         }
    });
   
    $.ajax({
    	type : "GET",
         url : $("#loginCheck").val(),
         async:false,
         cache :false,
         dataType : "json",
         success : function(json){
         	//json=eval('('+json+')');
         	if(json.message == "success"){
         		$.unblockUI();
         		if(loginornot('storeHeader','store')==true){
         			nextStep('yes');
         		}
         	}else{
         		$("#errorSpan").html("用户名或密码不正确");
         	}
         }
    });
}

function validateReturn(flag){
	if(!flag){
    	$("#errorSpan").text("用户名或密码不正确");
    }
}

function register(){

	
	var link = document.getElementById("registerForm").action;
	$('#registerForm input[name]').each(function(i){
		if(i == 0)
			link = link + "?" + this.name + "=" + this.value; 
		else
			link = link + "&" + this.name + "=" + this.value;
	});
	var url = encodeURI(link);
	var flag = false;
	$.ajax({
         type : "GET",
         url : url,
         async:false,
         dataType : "json",
         success : function(json){
             if(json.message == 'success'){
             	flag = true;
             }else{
             	$('#errorLabel').text(json.message);
             	$('#errorLabel').parent().parent().show();
             }
         }
     });
     
    //注册成功自动登录
    if(flag){
    	var login = document.getElementById("loginForm").action;
	    $('#loginForm input[name]').each(function(i){
			if(i == 0)
				login = login + "?"; 
			else
				login = login + "&";
			if(this.name == "j_username"){
				login = login + this.name + "=" + $("#registerForm input[name='user.mobile']").val();
			}else if(this.name == "j_password"){
				login = login + this.name + "=" + $("#registerForm input[name='user.password']").val();
			}else{
				login = login + this.name + "=" + this.value;
			}
		});

     	login = login + "&num=" + Math.random();
     	$.ajax({
	    	type : "GET",
	         url : login,
	         cache :false,
	         async:false
	    });
	    
	   //登录成功后，自动刷新当前页面
	    $.ajax({
	    	type : "GET",
	         url : $("#loginCheck").val(),
	         async:false,
	         cache :false,
	         dataType : "json",
	         success : function(json){
	         	if(json.message == "success"){
	         		$.unblockUI();
         			
         			if(loginornot('storeHeader','store')==true){
         				
         				nextStep('yes');
         			}
	         	}else{
	         		$("#errorSpan").text("用户名或密码不正确");
	         	}
	         }
	    });
    }

}
function registerSubmit(){
		if ($.browser.safari) {
  			var a= $("#registerForm").attr("action")+($("#registerForm").attr("action").indexOf('?') == -1 ? '?' : '&');
  			$("#registerForm").attr("action",a+'t=' + new Date().getTime());
		}
		$("#registerForm").submit();

}

function formValidate(){
	 // 手机号码验证   
		jQuery.validator.addMethod("isMobile", function(value, element) {   
			var length = value.length;   
			return this.optional(element) || (length == 11);   
			}, "请正确填写您的手机号码");
			
		jQuery.validator.addMethod("isUserName", function(value, element) {   
			return this.optional(element) || (/^\w*$/.test(value));   
			}, "用户名不能为特殊符号");
			
		jQuery.validator.addMethod(
				"isMobileRegistered", 
				function(value, element) {   
					var ret=false;
					var url="/ajax/load!isMobileRegistered.action?mobile="+value+"&s="+new Date().getTime();
					$.get(url, function(data){
  						data=eval('('+data+')');
  						$("#isMobileRegisteredValue").val(data.success);
  						
					});
					if($("#isMobileRegisteredValue").val()=='true'){
						return false;
					}else{
						return true;
					}
					
				},"该手机号已被注册");
			
		jQuery.validator.addMethod(
				"isEmailRegistered", 
				function(value, element) {   
					
					var ret=false;
					var url="/ajax/load!isEmailRegistered.action?email="+value+"&s="+new Date().getTime();
					$.get(url, function(data){
  						data=eval('('+data+')');
  						$("#isEmailRegisteredValue").val(data.success);
					});
					if($("#isEmailRegisteredValue").val()=='true'){
						return false;
					}else{
						return true;
					}
					
				},"该邮箱已被注册");	
			
			
		$("#registerForm").validate({
			errorPlacement: function(error, element) {
				//element.parent("td").next("td").children("span").hide();
				element.parent('div').next('div').children("span").hide();
		     	error.appendTo( element.parent('div').next('div') );
		    },
			rules: {
				"user.fullName": {
					required: true
				},
				"user.mobile": {
					required: true,
					isMobile: true,
					isMobileRegistered:true
				},
				"user.email": {
					required: true,
					email: true,
					isEmailRegistered:true
				},
				"user.password": {
					required: true,
					rangelength: [6,16]
				},
				"repassword": {
					required: true,
					equalTo: "#password"
				},
				"agreement": {
					required: true
				},
				"j_code": {
					required: true
				}
			},
			messages: {
				"user.fullName": {
					required: "× 用户名必填"
				},
				"user.mobile": {
					required: "× 手机号必填",
					isMobile: "× 请输入合法的手机号",
					isMobileRegistered:"该手机号已被注册"
				},
				"user.email": {
					required: "× 电子邮箱必填",
					email: "× 请输入合法的电子邮箱",
					isEmailRegistered:"该电子邮箱已被注册"
				},
				"user.password": {
					required: "× 密码必填",
					rangelength: jQuery.format("× 密码长度介于 {0} 和 {1} 之间")
				},
				"repassword": {
					required: "× 确认密码必填",
					equalTo: "× 密码和确认密码输入不一致"
				},
				"agreement": {
					required: "× 请认真阅读注册协议"
				},
				"j_code": {
					required: ""
				}
			},
			focusInvalid: false,
			onkeyup: false,
			submitHandler:function(){
				register();
			}
		});
		
}

function loginornot(ele,pos){
	var url="/info/loginornot.jsp?s="+new Date().getTime();
	$.ajax({
	    	type : "GET",
	         url : url,
	         async:false,
	         cache :false,
	         dataType : "json",
	         success : function(response){
	         	$("#loginV").val(response);
	         }
    });
    var v=$("#loginV").val();
	if(v=='true'){
		loadUserInfo(ele,pos);
		return true;
	}else{
		return false;
	}
}
//弹出层，登录注册
function hotelContactInfo(){
	var hotelId=$("#hotelId").val();
	if(hotelId!=null&&hotelId!=''){
		var url="/hotel/contactInfo.action?hotelId="+hotelId+"&s="+new Date().getTime();
		$.get(url,function(response){
				var response=eval('('+response+')');
				if(response.loginOrNot==true){
					$("#hotelMobile").html(response.hotelMobile);
					$("#hotelTel").html(response.hotelTel);
				}else{
					
				}
		});
	}
}

function viewContactInfo(){
	var ret=loginornot();	
	if(ret==false){
		login();
		return;
	}
	hotelContactInfo();
}
function loadUserInfo(ele,pos){
	if(pos==null){
		pos='common';
	}
	var url="/info/userinfo.jsp?pos="+pos+"&s="+new Date().getTime();
	
	$.get(url,function(response){
		$("#"+ele).empty();
		$("#"+ele).prepend(response)
	});	
}
function loadHotelMinPrice(){
	var hotelIds=document.getElementsByName("hotelIds");
	for(i=0;i<hotelIds.length;i++){
		var url="/ajax/load!loadHotelMinPrice.action?hotelId="+hotelIds[i].value+"&s="+new Date().getTime();
		$.ajax({
    	type : "GET",
         url : url,
         async:true,
         cache :false,
         dataType : "json",
         success : function(json){
         	if(json.success==true){
         		$("#hotelMinPrice_"+json.hotelId).html(json.price);
         	}else{
         		$("#hotelMinPrice_"+json.hotelId).html("暂无");
         	}
         }
    	});
	}
}

//event tag search

function searchEventTag(cityId,tagId,categoryId){
	if(tagId==null&&cityId==null&&categoryId==null){
		return ;
	}
	if(tagId==null){tagId='';}
	if(cityId==null){cityId='';}
	if(categoryId==null){categoryId='';}
	location.href="/frontend/activity/activity-query!result.action?queryVO.tagId="+tagId+"&queryVO.cityId="+cityId+"&queryVO.categoryId="+categoryId;
}

function isNumber(val){
	var reg=new RegExp('^-?[0-9]*\\.[0-9]*$');
	return !isNaN(val) && (!reg.test(val));
}
function loadVehicleNoDriverForm(locationId){
	var url="/ajax/load/loadVehicleNoDriverSearchForm.action?locationId="+locationId;
	
	$.get(url,function(response){
		$("#span-vehicle-1").html(response);
		$('#no-carry-time').val(GetDateStr(1));
		$('#no-return-time').val(GetDateStr(2));
	    //自驾搜索提交
		$("#no_driver_search").click(function(){
			if($("#driver-l-name").val() == '' && $("#no-l-name-give").val() == ''){
				searchCommon("driver-l-name","1");
			}else{
				if ($.browser.safari) {
  					var a= $("#noSearchForm").attr("action")+($("#noSearchForm").attr("action").indexOf('?') == -1 ? '?' : '&');
  					$("#noSearchForm").attr("action",a+'t=' + new Date().getTime());
				}
				$("#noSearchForm").submit();
			}
		});
	});
}
function loadVehicleWithDriverForm(locationId){
	var url="/ajax/load/loadVehicleWithDriverSearchForm.action?locationId="+locationId;
	$.get(url,function(response){
		$("#span-vehicle-2").html(response);
		$('#withTime').val(GetDateStr(1));
		
		//代驾搜索提交
		$("#with_driver_search").click(function(){
			if($("#driver-w-name").val() == ''){
				searchCommon('driver-w-name','1');
			}else{
				if ($.browser.safari) {
  					var a= $("#withSearchForm").attr("action")+($("#withSearchForm").attr("action").indexOf('?') == -1 ? '?' : '&');
  					$("#withSearchForm").attr("action",a+'t=' + new Date().getTime());
				}
				$("#withSearchForm").submit();
			}
		});
		
	});
}
//接机
function loadVehicleFromAirportForm(locationId){
	var url="/ajax/load/loadVehicleFromAirportSearchForm.action?locationId="+locationId;
	$.get(url,function(response){
		$("#span-vehicle-4").html(response);
		$('#air-away-time').val(GetDateStr(1));
		
		//接机搜索提交
		$("#air_away_search").click(function(){
			if($("#air-away-b-name").val() == '' && $("#air-away-e-name").val() == ''){
			    initHotCityHide();
				searchCommon('air-away1-b-name','4');
			}
			//控制价格块显示
			var checkval =  $("input[name='airPortRadio']:visible:checked").val();
			if(checkval != "" && checkval != null && checkval != "undefined"){
				var arr = checkval.split("_");
				if(arr.length > 1){
					$("#air-away-b-id").val(arr[0]);
					$("#air-away-b-name").val(arr[1]);	
				}
			}
			$("#v-page-num").val(1);
			$("#v-result-type").val();
			$("#qurey_type").val("0");
			//beforeSubmit("air-away");
			if ($.browser.safari) {
  					var a= $("#atAirSearchForm").attr("action")+($("#atAirSearchForm").attr("action").indexOf('?') == -1 ? '?' : '&');
  					$("#atAirSearchForm").attr("action",a+'t=' + new Date().getTime());
			}
			$("#atAirSearchForm").submit();
		});
		
		//
		//initAutoAirToAway();
	});
}
//送机
function loadVehicleToAirportForm(locationId){
	var url="/ajax/load/loadVehicleToAirportSearchForm.action?locationId="+locationId;
	$.get(url,function(response){
		$("#span-vehicle-3").html(response);
		$('#away-air-time').val(GetDateStr(1));
		
		//送机搜索提交
		$("#away_air_search").click(function(){
			if($("#away-air-b-name").val() == '' && $("#away-air-e-name").val() == ''){
				searchCommon('away-air1-e-name','3');
			}
			//控制价格块显示
			var checkval =  $("input[name='airPortRadio']:visible:checked").val();
			if(checkval != "" && checkval != null && checkval != "undefined"){
				var arr = checkval.split("_");
				if(arr.length > 1){
					$("#away-air-e-id").val(arr[0]);
					$("#away-air-e-name").val(arr[1]);	
				}
			}
			$("#v-page-num").val(1);
			$("#v-result-type").val("");
			$("#qurey_type").val("1");
			//beforeSubmit("away-air");
			if ($.browser.safari) {
  					var a= $("#awayAirSearchForm").attr("action")+($("#awayAirSearchForm").attr("action").indexOf('?') == -1 ? '?' : '&');
  					$("#awayAirSearchForm").attr("action",a+'t=' + new Date().getTime());
			}
			$("#awayAirSearchForm").submit();
		});
		
		//initAutoAwayToAir();
		
	});
}
function loadVehicleLineForm(locationId){
	var url="/ajax/load/loadVehicleLineSearchForm.action?locationId="+locationId;
	$.get(url,function(response){
		$("#span-vehicle-5").html(response);
		$('#a2b-time').val(GetDateStr(1));
		
		//城际搜索提交奥
		$("#a2b_search").click(function(){
			if($("#a2b-b-name").val() == '' && $("#a2b-e-name").val() == ''){
			    initHotCityHide();
				searchCommon('a2b-b-name','1');
			}
			//beforeSubmit("a2b");
			if ($.browser.safari) {
  					var a= $("#rountA2BSearchForm").attr("action")+($("#rountA2BSearchForm").attr("action").indexOf('?') == -1 ? '?' : '&');
  					$("#rountA2BSearchForm").attr("action",a+'t=' + new Date().getTime());
			}
			$("#rountA2BSearchForm").submit();
		});
		
		//initAutoRount();
	});
}
//身份证
function  isIdCard(card)
{
	var cardLen;
	var cardDate;
	var chkSex;
	cardLen=card.length;
		if (cardLen!=15 && cardLen!=18)
			{
			return false;
			}

		if (isNaN(card.substring(0,cardLen-1)))
		{
			return false;
		}
		else
		{
			chkSex=card.charAt(cardLen-1);
		}

		if (18==cardLen){
			cardDate=card.substring(6,14);
		}else{
			cardDate=card.substring(6,12);
		}

		if (cardLen==15)
		{
			if (isNaN(chkSex))
			{
				return false;
			}
		}else{
			if (isNaN(chkSex)){
				if (chkSex!="x" && chkSex!="X")
				{
					return false;
				}
			}
		}
	return true;
}
function flashValidateCode(){
	setTimeout("",1000);
	document.getElementById('verify').src='/code-image?num='+new Date().getTime();
}
