$(document).ready(function (){

$("#login_username").focus();



 jQuery(".datepicker_in").datepicker({
  dateFormat: 'dd-mm-yy',
  firstDay: 1,
  minDate: +1,
  duration: ''
 });
 jQuery(".datepicker_out").datepicker({ 
  dateFormat: 'dd-mm-yy',
  firstDay: 1,
  minDate: +3,
  duration: ''
 });


jQuery("#hotel_select").bind("change",function(){
	$.post("../includes/hotels.php", {
			quicksearchSubmit: "OK",
			hotel_select: $("#hotel_select option:selected").val(),
		},
	   function(data){
	   	 $("#content_right").html(data);
	  });
})

function isValidEmailAddress(emailAddress) {  
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);  
	return pattern.test(emailAddress);  
} 


$('.error').hide();
$('.change').hide();

$("#toggle_company").click(function(){
	$(".saved").remove();
	$('#company_change').show();
	$('#company_save').show();
	$(this).hide();
})
$("#company_save").click(function(){
	$('#company_change').hide();
	$('#company_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#company_change").attr("name"),
			value: $('#company_change').val()
			},
	   function(data){
	   	 $("#toggle_company").show();
		 $("#company_res").html(data);
		 $("#company_save").after("<span class='saved'>Saved</span>");
	   });	
})

$("#toggle_contact_person").click(function(){
	$(".saved").remove();
	$('#contact_person_change').show();
	$('#contact_person_save').show();
	$(this).hide();
})
$("#contact_person_save").click(function(){
	$('#contact_person_change').hide();
	$('#contact_person_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#contact_person_change").attr("name"),
			value: $('#contact_person_change').val()
			},
	   function(data){
	   	 $("#toggle_contact_person").show();
		 $("#contact_person_res").html(data);
		 $("#contact_person_save").after("<span class='saved'>Saved</span>");
	   });	
})


$("#toggle_position").click(function(){
	$(".saved").remove();
	$('#position_change').show();
	$('#position_save').show();
	$(this).hide();
})
$("#position_save").click(function(){
	$('#position_change').hide();
	$('#position_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#position_change").attr("name"),
			value: $('#position_change').val()
			},
	   function(data){
	   	 $("#toggle_position").show();
		 $("#position_res").html(data);
		 $("#position_save").after("<span class='saved'>Saved</span>");
	   });	
})


$("#toggle_address").click(function(){
	$(".saved").remove();
	$('#address_change').show();
	$('#address_save').show();
	$(this).hide();
})
$("#address_save").click(function(){
	$('#address_change').hide();
	$('#address_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#address_change").attr("name"),
			value: $('#address_change').val()
			},
	   function(data){
	   	 $("#toggle_address").show();
		 $("#address_res").html(data);
		 $("#address_save").after("<span class='saved'>Saved</span>");
	   });	
})


$("#toggle_city").click(function(){
	$(".saved").remove();
	$('#city_change').show();
	$('#city_save').show();
	$(this).hide();
})
$("#city_save").click(function(){
	$('#city_change').hide();
	$('#city_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#city_change").attr("name"),
			value: $('#city_change').val()
			},
	   function(data){
	   	 $("#toggle_city").show();
		 $("#city_res").html(data);
		 $("#city_save").after("<span class='saved'>Saved</span>");
	   });	
})


$("#toggle_country").click(function(){
	$(".saved").remove();
	$('#country_change').show();
	$('#country_save').show();
	$(this).hide();
})
$("#country_save").click(function(){
	$('#country_change').hide();
	$('#country_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#country_change").attr("name"),
			value: $('#country_change').val()
			},
	   function(data){
	   	 $("#toggle_country").show();
		 $("#country_res").html(data);
		 $("#country_save").after("<span class='saved'>Saved</span>");
	   });	
})


$("#toggle_phone").click(function(){
	$(".saved").remove();
	$('#phone_change').show();
	$('#phone_save').show();
	$(this).hide();
})
$("#phone_save").click(function(){
	$('#phone_change').hide();
	$('#phone_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#phone_change").attr("name"),
			value: $('#phone_change').val()
			},
	   function(data){
	   	 $("#toggle_phone").show();
		 $("#phone_res").html(data);
		 $("#phone_save").after("<span class='saved'>Saved</span>");
	   });	
})


$("#toggle_fax").click(function(){
	$(".saved").remove();
	$('#fax_change').show();
	$('#fax_save').show();
	$(this).hide();
})
$("#fax_save").click(function(){
	$('#fax_change').hide();
	$('#fax_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#fax_change").attr("name"),
			value: $('#fax_change').val()
			},
	   function(data){
	   	 $("#toggle_fax").show();
		 $("#fax_res").html(data);
		 $("#fax_save").after("<span class='saved'>Saved</span>");
	   });	
})


$("#toggle_email").click(function(){
	$(".saved").remove();
	$('#email_change').show();
	$('#email_save').show();
	$(this).hide();
})
$("#email_save").click(function(){
	var email = $('#email_change').val();
	if (isValidEmailAddress(email)){
		$('#email_change').hide();
		$('#email_save').hide();
		$.post("../includes/myinfo.php", { 
				userid: $("#userid").val(),
				param: $("#email_change").attr("name"),
				value: email
				},
		   function(data){
			 $("#toggle_email").show();
			 $("#email_res").html(data);
			 $("#email_save").after("<span class='saved'>Saved</span>");
		   });
	  } else {
		alert("Invalid email address");
	  }
})


$("#toggle_website").click(function(){
	$(".saved").remove();
	$('#website_change').show();
	$('#website_save').show();
	$(this).hide();
})
$("#website_save").click(function(){
	$('#website_change').hide();
	$('#website_save').hide();
	$.post("../includes/myinfo.php", { 
			userid: $("#userid").val(),
			param: $("#website_change").attr("name"),
			value: $('#website_change').val()
			},
	   function(data){
	   	 $("#toggle_website").show();
		 $("#www_res").html(data);
		 $("#website_save").after("<span class='saved'>Saved</span>");
	   });	
})


	
$("#search_hotel").click(function() {
	var fromdate = jQuery("input#datepicker_in1").val();  
    if (fromdate == "") {
		jQuery("label#datepicker_in1_error").show();  
		jQuery("#datepicker_in1").focus();  
    return false;  
	}
	
	var todate = jQuery("#datepicker_out1").val();  
    if (todate == "") {
		jQuery("label#datepicker_out1_error").show();  
		jQuery("#datepicker_out1").focus();  
    return false;  
	}

})

jQuery("#datepicker_in1").bind("change",function(){
	jQuery("label#datepicker_in1_error").hide();
})
jQuery("#datepicker_out1").bind("change",function(){
	jQuery("label#datepicker_out1_error").hide();
})
jQuery("#search_again").live("click",function(){
	jQuery("#search_form").show();
	jQuery("#results").html("<p></p>");
})





$("#pay_button").click(function(){
	$.post("../includes/pay_button.php", { 
			userid: $("#userid5").val(),
			offerid: $("#offerid5").val(),
			partnerid: $("#partnerid5").val()
	}, function (data){
		//alert(data);
	});	

})


$("#pay_button2").click(function(){
	$.post("../includes/pay_button.php", { 
			userid: $("#userid6").val(),
			carofferid: $("#carofferid6").val(),
			partnerid: $("#partnerid6").val(),
			day_or_km: $("#day_or_km").val(),
			price: $("#price6").val(),
			number: $("#number6").val()
	}, function (data){
		//alert(data);
	});	

})




$("#link1").mouseover(function(){
	$(this).select();
})

$("#link2").mouseover(function(){
	$(this).select();
})



	

});


	
