




			// Removes the blank space before and after the passed string (if any)
	 
		function trim(myString) {
			
			return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
	 
		}
	 
			// Checks for a valid email address
			// Returns true in case of a valid email ortherwise returns false
		
		function checkEmail(email) {
	 
			emailRegexp = new RegExp("^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+[.]{1}[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]{2,8}$", "g");
			if(emailRegexp.test(email)) return true; else return false;
	 
		}





		/**
		 *
		 * Opens the popup for booking process
		 *
		 */
	
	function InvokeBookingPopup(url) {

		var w = 650;
		var h = 450;
		
		var posX = (window.screen.width/2) - (w/2);
		var posY = (window.screen.height/2) - (h/2);
		var title = '';
		var dsp_options = 'toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, top='+posY+',left='+posX+', width=' + w + ' ,height=' + h;
		var win = window.open(url, title, dsp_options);
		win.focus();
		win.moveTo(posX,posY);
		win.resizeTo(w, h);
		win.focus();

	} // end of fucntion InvokeBookingPopup





		/**
		 *
		 * Function GoToPage :: Invoke to browse pages when search engine was invoked
		 * 
		 * 1) Update the form's action with the given url
		 * 2) Submit the form
		 *
		 */
	
	function GoToPage(url) {

		if(document.forms['search']) {
			document.forms['search'].action = url;
			document.forms['search'].submit();
		}

		if(document.forms['AgencySearch']) {
			document.forms['AgencySearch'].action = url;
			document.forms['AgencySearch'].submit();
		}

	} // enf of function GoToPage
	
	
	
	
	
		/**
		 *
		 * Function ResetAllCriteriasButKindAndSubmit :: reset all values of the given form except the kind, and submit !
		 * 
		 * 1) Update the form's action with the given url
		 * 2) Submit the form
		 *
		 */
	
	function ResetAllCriteriasButKindAndSubmit(FormId) {

			// Unset the country
		if(FormId.elements['tx_gt_pi1[country]']) FormId.elements['tx_gt_pi1[country]'].value = 0;

			// Unset the city
		if(FormId.elements['tx_gt_pi1[city]']) FormId.elements['tx_gt_pi1[city]'].value = 0;

			// Unset the days
		FormId.elements['tx_gt_pi1[day]'].value = 0;

			// Unset the prices
		FormId.elements['tx_gt_pi1[price]'].value = 0;

			// Unset the date // Set to "Whenever", value 3 (hard coded...)
		FormId.elements['tx_gt_pi1[date]'].value = 3;
			
			// Submit the form
		FormId.submit();

	} // enf of function GoToPage





		/**
		 *
		 * Function ForceClick :: force a click on an <a> tag (used to twek "Send 2 friend button / shadowbox")
		 *
		 */	
	
	function ForceClick(a_id) {

		var target=document.getElementById(a_id);

		if(document.dispatchEvent) { 
			var oEvent = document.createEvent( "MouseEvents" );
			oEvent.initMouseEvent("click", true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
			target.dispatchEvent( oEvent );
		} else {
			if(document.fireEvent) { // IE
				target.fireEvent("onclick");
			} 
		}

	}





		/**
		 *
		 * Function SetBookingAgency :: called from popup ("choose an agency") when booking a trip
		 *
		 * 1) Function writes value in parent window
		 * 2) Function closes popup
		 *
		 */
	
	function SetBookingAgency(AgencyUid,AgencyLabel,AgencyEmail) {
		
		var ParentAgencyUid		= window.parent.document.forms['BookingForm'].elements['tx_gt_pi10[AgencyUid]'];
		var ParentAgencyLabel	= window.parent.document.getElementById('SelectedAgencyLabel');
		var ParentAgencyEmail	= window.parent.document.forms['BookingForm'].elements['tx_gt_pi10[recipient]'];

		ParentAgencyUid.value			= AgencyUid;
		ParentAgencyEmail.value		= AgencyEmail;
		ParentAgencyLabel.innerHTML	= '<b>Agence de voyage selectionnee:</b> '+AgencyLabel+'&nbsp;&nbsp;&nbsp;<img src="/fileadmin/templates/media/img/checked.png" />';

		// window.parent.Shadowbox.close();

		parent.$.fancybox.close();

	} // end of function SetBookingAgency





		/**
		 *
		 * Function ValidateBookingForm :: ensure we have everything we need for a trip and let the form go
		 *
		 */
	
	function ValidateBookingForm() {

			errors = false;
	 
			document.BookingForm.elements[0].style.border='1px solid #666';
			document.BookingForm.elements[1].style.border='1px solid #666';
			document.BookingForm.elements[2].style.border='1px solid #666';
			document.BookingForm.elements[3].style.border='1px solid #666';
			document.BookingForm.elements[4].style.border='1px solid #666';
			document.BookingForm.elements[5].style.border='1px solid #666';
			document.BookingForm.elements[6].style.border='1px solid #666';
			document.BookingForm.elements[7].style.border='1px solid #666';
			
			if(!trim(document.BookingForm.elements[0].value)) { errors = true; alert('Veuillez entrer une date de départ svp.\n'); document.BookingForm.elements[0].style.border='1px solid #f00'; ForceClick('OpenDatesPrix'); return false;}
			if(!trim(document.BookingForm.elements[1].value)) { errors = true; alert('Veuillez entrer votre nom svp.\n'); document.BookingForm.elements[1].style.border='1px solid #f00'; return false;}
			if(!trim(document.BookingForm.elements[2].value)) { errors = true; alert('Veuillez entrer votre prénom svp.\n'); document.BookingForm.elements[2].style.border='1px solid #f00'; return false;}
			if(!trim(document.BookingForm.elements[3].value)) { errors = true; alert('Veuillez entrer votre adresse svp.\n'); document.BookingForm.elements[3].style.border='1px solid #f00'; return false;}
			if(!trim(document.BookingForm.elements[4].value)) { errors = true; alert('Veuillez entrer votre code postal svp.\n'); document.BookingForm.elements[4].style.border='1px solid #f00'; return false;}
			if(!trim(document.BookingForm.elements[5].value)) { errors = true; alert('Veuillez entrer votre localité svp.\n'); document.BookingForm.elements[5].style.border='1px solid #f00'; return false;}
			if(!trim(document.BookingForm.elements[6].value)) { errors = true; alert('Veuillez entrer votre téléphone svp.\n'); document.BookingForm.elements[6].style.border='1px solid #f00'; return false;}
			if(!trim(document.BookingForm.elements[7].value) || (!checkEmail(document.BookingForm.elements[7].value))) { errors = true; alert('Veuillez vérifier votre adresse email svp.\n'); return false; }

			if(!trim(document.BookingForm.elements[9].value)) { errors = true; alert('Veuillez sélectionner une agence svp.\n'); ForceClick('SelectAgency_link'); return false;}
	 
			if(!errors) document.BookingForm.submit();

	}





	function openSwinglineEspacePro() 	{

		w = 750;
		h = 450;
		
		LeftPosition= (window.screen.width-w)/2 ;
		TopPosition=((window.screen.height-h)/2);
		
		pageUrl = "http://81.244.249.16/SwingLine/Modules/Booking/Default.aspx?LogonRequired=true";
		
		parametres = 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0';	
		
		win = window.open(pageUrl,'generaltour_servico_agence',parametres);
		win.focus();
		win.moveTo(posX,posY);
		win.resizeTo(w, h);
		win.focus();

	} // end of function openSwinglineEspacePro





	function openSwinglineMonCompte(type_action) 	{

		w = 650;
		h = 450;
		
		LeftPosition= (window.screen.width-w)/2 ;
		TopPosition=((window.screen.height-h)/2);

		pageUrl = "http://81.244.249.16/swingline/modules/"+type_action; 
		parametres = 'width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0';	
				
		win = window.open(pageUrl,'generaltour_servico',parametres);
		win.focus();
		win.moveTo(posX,posY);
		win.resizeTo(w, h);
		win.focus();

	} // end of function openSwinglineMonCompte