/**
 * General functions for Maduro Travel
 * Author: lufeceba - 2009
 **/

	function loadInIframe(theform) {
		var $modal = jQuery('#jqmFWindow');
		var myUrl = jQuery(theform).attr('action');

		if ( jQuery.browser.msie ) {
			var el = document.createElement("iframe");
			el.setAttribute('id', 'jqmFContent');
			el.setAttribute('frameborder', '0');
			el.setAttribute('src', 'http://www.madurotravelaruba.com/blank_page.html');
			$modal.append(el);
			var body = el.contentWindow.document;
			body.write('<form action="'+myUrl+'" method="post" id="frm_newfk" style="display:none"></form><h3 style="font-family: arial, sans-serif">Loading information, please wait...</h3>');
			var form = jQuery("form", body);
			form.append(jQuery(theform).html());
			form.trigger('submit');
			$modal.fadeIn('slow');
		} else {
			$modal.append('<iframe id="jqmFContent" name="jqmFrame"></iframe>');
			var $modalContent = jQuery("#jqmFContent");
			var body = $modalContent.contents().find('body');
			body.html('');
			body.append('<form action="'+myUrl+'" method="post" style="display:none"></form><h3 style="font-family: arial, sans-serif">Loading information, please wait...</h3>');
			var form = $modalContent.contents().find("form");

			jQuery(theform +" input, "+ theform +" select").each(function() {
				new_element = jQuery(this).clone();
				new_element.val(jQuery(this).val());
				new_element.appendTo(form);
			});
			jQuery(theform +" textarea").each(function() {
				new_element = jQuery(this).clone();
				new_element.text(jQuery(this).val());
				new_element.appendTo(form);
			});

			form.trigger('submit');
			$modal.fadeIn('slow');
		}
	}
	function loadUrlInIframe(theurl) {
		var $modal = jQuery('#jqmFWindow');
		$modal.append('<iframe id="jqmFContent"></iframe>');
		jQuery("#jqmFContent").attr('src', theurl);
		$modal.fadeIn('slow');
	}
	function unloadIframe() {
		jQuery('#jqmFWindow').fadeOut("normal");
		jQuery("#jqmFContent").remove();
	}

	function validateFrm(frm) {
		switch(frm) {
			case "#frm_amadeusearch":
				if(!jQuery("#b_location_1").val()) {
					alert('Please, tell us where are you leaving from');
					return false;
				}
				if(!jQuery("#e_location_1").val()) {
					alert('Please, tell us where are you going to');
					return false;
				}
				if(!jQuery("#b_date_1").val()) {
					alert('Please, provide the departure date');
					return false;
				}
				if( jQuery('#fk_ttype').val() == 'R' && !jQuery('#b_date_2').val() ) {
					alert('Since you have selected a round trip, please provide the return date');
					return false;
				}
				return true;
			case "#frm_touricosearch":
				if(jQuery.trim(jQuery('#sDestination').val()) == "") {
					alert('Please, provide a destination');
					jQuery('#sDestination').focus();
					return false;
				}
				if(jQuery('#dtChekIn').val() == "") {
					alert('Please, select a Check In date');
//					jQuery('#dtChekIn').focus();
					return false;
				}
				if(jQuery('#dtChekOut').val() == "") {
					alert('Please, select a Check Out date');
//					jQuery('#dtChekOut').focus();
					return false;
				}
				return true;
		}
	}

	function toggleDate2(action) {
		if(action == 'h') {
			jQuery('.hidewo').hide();
			jQuery('#fk_ttype').val('O');
			jQuery('#b_date_2, #fk_b_date_2').val('');
		} else {
			jQuery('.hidewo').show();
			jQuery('#fk_ttype').val('R');
		}
	}


	function fill_destination( contsel, pcode )
	{
		if( jQuery(contsel).val != "" ) {
			jQuery.post("/tourico/SearchDestination.php", {dopt: 'getcodes', continent: jQuery(contsel).val(), ccode: pcode}, function(data) {
				jQuery('#sDestination').html(data);
			});
		} else {
			jQuery('#sDestination').html("<option value=''> -- Select a zone -- </option>");
		}
	}