

function cancelDateInterval() {
	var sid = $('#searchid').val();
	window.location = 'index.php?c=redirect&m=cancelDates&searchid=' + sid + '&from=' + encodeURIComponent(window.location);
}

function changeCurrency(val) {
	var sid = $('#searchid').val();
	window.location = 'index.php?c=redirect&m=changeCurrency&dev=' + val.value + '&from=' + encodeURIComponent(window.location);
}

function selectLoc(locID, name)
{
	$('#search_city_id').val(name);
	$('#searchid').val(locID);
	$('#popup_locations').hide();
	$("#searchbutton").css({"cursor":"pointer"});
}

function userLogout() {
	window.location = 'index.php?c=redirect&m=logout&from=' + encodeURIComponent(window.location);
}

function isDate (value)
{
	return (!isNaN (new Date (value).getYear () ) ) ;
}

/***************************************/
$(document).ready(function() {
	$("#popup_locations .close").click(function(){
		$("#popup_locations").hide();
	});
	$("#search_city_id").click(function(){
		$("#popup_locations").show();
	});
	$("#popup_locations_trigger").click(function(){
		$("#popup_locations").show();
	});	
	$("#searchbutton").click(function(){
		if($('#searchid').val()==''){
			$('#search_city_id').animate({ backgroundColor: 'rgb(254,239,131)' }, 120)
						.animate( { backgroundColor: 'white' }, 120)
						.animate( { backgroundColor: 'rgb(254,239,131)' }, 120)
						.animate( { backgroundColor: 'white' }, 120);
			return false;
		}
		else{
			document.forms['searchbloc'].submit();
		}
	});
	//*************bookmark**********************/
	if(window.opera) {
        if ($("a.jqbookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
           $("a.jqbookmark").attr("rel","sidebar");
        }
	    }
 
    $("a.jqbookmark").click(function(event){
        event.preventDefault(); // prevent the anchor tag from sending the user off to the link
        var url = this.rel;
        var title = this.title;
        if (window.sidebar) { // Mozilla Firefox Bookmark
           window.sidebar.addPanel(title, url,"");
        } else if( window.external ) { // IE Favorite
            window.external.AddFavorite( url, title);
	        } else if(window.opera) { // Opera 7+
            return false; // do nothing - the rel="sidebar" should do the trick
        } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
             alert('Unfortunately, this browser does not support the requested action,'
	             + ' please bookmark this page manually.');
        }
	 
	    });
	$("#but_change_date").click(function(){
		/*if(isDate($('#arrivee2').val())==false && isDate($('#depart2').val())==true){			
			$('#arrivee2').animate({ backgroundColor: 'rgb(254,239,131)' }, 120)
						.animate( { backgroundColor: 'white' }, 120)
						.animate( { backgroundColor: 'rgb(254,239,131)' }, 120)
						.animate( { backgroundColor: 'white' }, 120);
			return false;
		}
		else if(isDate($('#arrivee2').val())==true && isDate($('#depart2').val())==false){			
			$('#depart2').animate({ backgroundColor: 'rgb(254,239,131)' }, 120)
						.animate( { backgroundColor: 'white' }, 120)
						.animate( { backgroundColor: 'rgb(254,239,131)' }, 120)
						.animate( { backgroundColor: 'white' }, 120);
			return false;
		}
		else{*/
			document.forms['roomsbloc'].submit();
		//}
	});
	$('#bookbutton').click(function(){
		var total = 0;
		$('table.roomtable select').each(function() {
			total += this.selectedIndex;
		});
		if(total <= 0){
			$('table.roomtable select').each(function() {
				$(this).animate({ backgroundColor: 'rgb(254,239,131)' }, 120)
						.animate( { backgroundColor: 'white' }, 120)
						.animate( { backgroundColor: 'rgb(254,239,131)' }, 120)
						.animate( { backgroundColor: 'white' }, 120);
			});
		}
		else{
			document.forms['roomsbook'].submit();
		}
	});
	$('#roomstabs').tabs();
	$('#booklogin').click(function() {
		document.bookform.submit();
	});	
	/*****************sign in header**************/
	$("#signinlink").click(function(){
		$('#signin_2').hide();
		$('#signin_1').show();
		$.blockUI({ message: $('#signinbloc') });
	});
	$("#signbutton").click(function(){
		var boole = true;
		if(myVerifMail("emailsign")==false) {
			$("#emailsign").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#emailsign").css({"border":"1px solid #e6e4d8"});
		}
		if(document.getElementById("pwdsign").value=="") {
			$("#pwdsign").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#pwdsign").css({"border":"1px solid #e6e4d8"});
		}
		if(boole==true){
			$('#from_signin').attr('value',encodeURIComponent(window.location));
			document.forms['sign_form'].submit();
		}
	});
	$("#retrievepwdSign").click(function() {
		$('#signin_1').hide();
		$("#sign_mail_zone").show();
		$("#sign_msg_zone").hide();
		$('#signin_2').show();
	});
	$("#signrtvpwd").click(function() {
		if(myVerifMail("signrcvemail")==false) {
			$("#signrcvemail").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#signrcvemail").css({"border":"1px solid #e6e4d8"});
			var queryString = $("#signretpwd_form").serialize();
			$.ajax({type: "POST", url: "index.php?c=redirect&m=pwdrecover", data: queryString, success: function(msg){
				$("#sign_mail_zone").hide();
				$("#sign_msg_zone").show();
				}
			});
		}
	});
	/*********************************************/
	/*****************customer care***************/
	$("#popup_customer .close").click(function(){
		$("#popup_customer").hide();
	});
	$("#customer_care_link,#cc_link").click(function(){
		$("#popup_customer").show();
	});	
	$('#tabs').tabs();
	$("#callback_save").click(function(){
		boole=true;
		if(document.getElementById("prenom").value=="") {
			$("#prenom").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#prenom").css({"border":"1px solid #AAAAAA"});
		}
		if(document.getElementById("nom").value=="") {
			$("#nom").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#nom").css({"border":"1px solid #AAAAAA"});
		}
		if(myVerifMail("email")==false) {
			$("#email").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#email").css({"border":"1px solid #AAAAAA"});
		}
		if(document.getElementById("fixe").value=="") {
			$("#fixe").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#fixe").css({"border":"1px solid #AAAAAA"});
		}
		if(document.getElementById("comment").value=="") {
			$("#comment").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#comment").css({"border":"1px solid #AAAAAA"});
		}
		
		if(boole==true){
			var queryString = $("#callback_form").serialize();
			$.ajax({type: "POST", url: "index.php?c=ajax&m=callback", data: queryString, success: function(msg){
				document.getElementById("popup_customer").style.display="none";
					$.blockUI({ 
					message: $('div.msg'), 
					fadeIn: 700, 
					fadeOut: 700, 
					timeout: 4000, 
					showOverlay: false, 
					centerY: false, 
					css: { 
						width: '350px', 
						top: '10px', 
						left: '', 
						right: '10px', 
						border: 'none', 
						padding: '5px', 
						backgroundColor: '#82A61F', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: .8, 
						color: '#fff' 
					}
				});
				}
			});
			
	}
	});
	/*********************************************/
	/******************send friend****************/
	$("#popup_send_friend .close").click(function(){
		$("#popup_send_friend").hide();
	});
	$("#send_friend_link").click(function(){
		$("#popup_send_friend").show();
	});
	$("#send_friend_button").click(function(){
	boole=false;
	if(document.getElementById("prenom").value=="") {
		$("#prenom").css({"border":"2px dotted #df9034"});
		boole=false;
	}else{
		$("#prenom").css({"border":"1px solid #AAAAAA"});
	}
	if(myVerifMail("from_email")==false) {
		$("#from_email").css({"border":"2px dotted #df9034"});
		boole=false;
	}else{
		$("#from_email").css({"border":"1px solid #AAAAAA"});
	}
	if(myVerifMail("email_to")==false) {
		$("#email_to").css({"border":"2px dotted #df9034"});
		boole=false;
	}else{
		$("#email_to").css({"border":"1px solid #AAAAAA"});
	}
	if(document.getElementById("objet").value=="") {
		$("#objet").css({"border":"2px dotted #df9034"});
		boole=false;
	}else{
		$("#objet").css({"border":"1px solid #AAAAAA"});
	}
	if(document.getElementById("comment").value=="") {
		$("#comment").css({"border":"2px dotted #df9034"});
		boole=false;
	}else{
		$("#comment").css({"border":"1px solid #AAAAAA"});
	}
	if(boole==true){
		var queryString = $("#sendfriend_form").serialize();
		$.ajax({type: "POST", url: "index.php?c=ajax&m=send_friend", data: queryString, success: function(msg){
			document.getElementById("popup_send_friend").style.display="none";
			$.blockUI({ 
			message: $('div.msge'), 
			fadeIn: 700, 
			fadeOut: 700, 
			timeout: 4000, 
			showOverlay: false, 
			centerY: false, 
			css: { 
				width: '350px', 
				top: '10px', 
				left: '', 
				right: '10px', 
				border: 'none', 
				padding: '5px', 
				backgroundColor: '#82A61F', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .8, 
				color: '#fff' 
			} 
			});
			}
		});
	}
	});
	/*********************************************/
	/******************booking********************/
	$("#newuser").click(function() {
		$("#login_form").hide();
		$("#pwd_user").show();
	});
	$("#rtvpwd").click(function() {
		if(myVerifMail("emailrcvpw")==false) {
			$("#emailrcvpw").css({"border":"2px dotted #df9034"});
			boole=false;
		}else{
			$("#emailrcvpw").css({"border":"1px solid #e6e4d8"});
			var queryString = $("#retpwd_form").serialize();
			$.ajax({type: "POST", url: "index.php?c=redirect&m=pwdrecover", data: queryString, success: function(msg){
				$("#mail_zone").hide();
				$("#msg_zone").show();
				}
			});
		}
	});	
	$("#newslettersent").click(function() {
		if(myVerifMail("newslettertxt")==false) {
			$("#newslettertxt").css({"border":"2px dotted #df9034"});
		}else{
			$("#newslettertxt").css({"border":"1px solid #e6e4d8"});
			var queryString = $("#newsletter_form").serialize();
			$.ajax({type: "POST", url: "index.php?c=ajax&m=newsletter", data: queryString, success: function(msg){
				$("#newslettertxt").attr('value','');				
				$.blockUI({ 
				message: $('#newsletter_joinconf'), 
				fadeIn: 700, 
				fadeOut: 700, 
				timeout: 4000, 
				showOverlay: false, 
				centerY: false, 
				css: { 
					width: '350px', 
					top: '10px', 
					left: '', 
					right: '10px', 
					border: 'none', 
					padding: '5px', 
					backgroundColor: '#82A61F', 
					'-webkit-border-radius': '10px', 
					'-moz-border-radius': '10px', 
					opacity: .8, 
					color: '#fff' 
				} 
				});
				}
			});
		}
	});	
	
	/*********************************************/
});

function myVerifMail(mail) {
	var email = document.getElementById(mail).value;
	var posat = email.indexOf('@');
	var lstposat = email.lastIndexOf('@');
	var longueur = email.length;
	var splitMail = email.split('@');
	var username = splitMail[0];
	var domaine = '';
	var pospt = -1;
	var lstpospt = -1;
	if (posat != -1) {
	  domaine = splitMail[1];
	  pospt = domaine.indexOf('.');
	  lstpospt = domaine.lastIndexOf('.');
	}
	var count = 0;
	var nbErrors = 0;
	var bool = false;

	if (posat == -1) {
	  nbErrors++;
	}
	
	if (posat != lstposat) {
	  nbErrors++;
	}
	
	if (username == '') {
	  nbErrors++;
	}
	
	if (domaine == '') {
	  nbErrors++;
	}
	
	if (pospt == -1 || pospt == 0) {
	  nbErrors++;
	}
	
	if (lstpospt == (domaine.length - 1)) {
	  nbErrors++;
	}
	
	for (var i = 0; i < domaine.length; i++) {
	  var ch = domaine.substring(i, i+1);
	  if (ch == '.')
	    count++;
	}
	
	if (count > 2) {
	  nbErrors++;
	}
	
	if (nbErrors == 0) {
	  bool = true;
	} else {
	  bool = false;
	}
	   return bool;
}

function errpopup()
{
	$.blockUI({ message: $('#errpopup') });
}
function cancelerrpopup()
{
	setTimeout($.unblockUI, 1); 
}


