// JavaScript Document

jQuery.noConflict();//TO RESOVLE CONFLICT BETWEEN ACCORDION AND JCAROUSEL
jQuery(document).ready(function(){

				// Accordion
	jQuery(".accordion").accordion({ header: "h3",
	                                 clearStyle: true,
									 autoHeight: true,
									 icons: { 'header': 'ui-icon-circle-arrow-w', 'headerSelected': 'ui-icon-circle-arrow-s' } });
			//Jcarousel
	$(".newsticker-jcarousellite").jCarouselLite({vertical: false,
												  hoverPause:true,
												  visible: 3,
												  auto:3000,
												  speed:2000,
												  btnNext: ".next",
												  btnPrev: ".prev",
												  scroll:2});
	
    jQuery('#slider').nivoSlider({pauseTime:5000,animSpeed:100});
	//datepicker
	$(".datepicker").datepicker({ numberOfMonths: 2,
								  showOn: 'button',
								  buttonImageOnly: true ,
								  buttonImage: '/portal/NewDesign/English/images/booking_28.gif',
								  closeText: ' ' ,
								  dateFormat: 'dd/mm/yy',
		  							firstDay: 6, // Start with Saturday
								  showButtonPanel : true});	 
	$(".datepicker-with-hijri").datepicker({ numberOfMonths: 1,
								  dateFormat: 'dd/mm/yy',
								  showOn: 'button',
								  buttonImageOnly: true ,
								  buttonImage: '/portal/NewDesign/English/images/booking_28.gif',
								  closeText: ' ' ,
								  showButtonPanel : true,
								  minDate:0,
								  displayHijri:true,
		 						  firstDay: 6, // Start with Saturday
								  HijriDateFrom: 2011, HijriDateTo: 2014 // dont forget to add the json file in hijri-calendar folder
								
					});
	
	$("#news").jCarouselLite({vertical: true,
	  //hoverPause:true,
	  visible: 1,
	  auto:5000,
	  speed:100,
	  btnNext: ".news-next",
	  btnPrev: ".news-prev",
	  scroll:1,
	  beforeStart: function(a) {
		  $(a).parent().fadeTo(500, 0);
		  //var bg = $(a).find('img').attr('src');
		  //$('#alert').css({backgroundImage: "url("+bg+")"}, 500);
	  },
	  afterEnd: function(a) {
		  $(a).parent().fadeTo(500, 1);
	  }
	  });

	
// depart and return date options
$("input#triptype_roundtrip").attr("checked", "checked");$("input#triptype_oneway").removeAttr("checked"); 
$('input#triptype_oneway').click(function(){	$('#Return_Date_wrapper').hide();});
$('input#triptype_roundtrip').click(function(){	$('#Return_Date_wrapper').show();});

$("#Depart_Date,#fst_depart").change(function(){
	var thisid=$(this).attr('id');
	var value=$(this).attr('value');
	day=parseInt(value.substr(0,2));
	month=parseInt(value.substr(3,2));
	year=parseInt(value.substr(6,4));
	if(thisid=='Depart_Date'){
		if(value==''){
			$("#Return_Date").datepicker("option", "minDate", 0);
		}else{
			$("#Return_Date").datepicker("option", "minDate", new Date(year, month-1, day));
		}
	}
	if(thisid=='fst_depart'){
		if(value==''){
			$("#fst_return").datepicker("option", "minDate", 0);
		}else{
			$("#fst_return").datepicker("option", "minDate", new Date(year, month-1, day));
		}
	}
	
});
$("#Return_Date,#fst_return").change(function(){
	var thisid=$(this).attr('id');
	var value;
	if(thisid=='Return_Date'){
		value=$("#Depart_Date").attr('value');
	}
	if(thisid=='fst_return'){
		value=$("#fst_depart").attr('value');
	}
	day=parseInt(value.substr(0,2));
	month=parseInt(value.substr(3,2));
	year=parseInt(value.substr(6,4));
	if(value==''){
		$(this).datepicker("option", "minDate", 0);
	}else{
		$(this).datepicker("option", "minDate", new Date(year, month-1, day));
	}
});

// end
	
// flight sked and timetable -- start
		$('#fs_flight').hide();		$("input#FS_OPTION_Flight").removeAttr("checked");
		$('#fs_timetable').show();		$("input#FS_OPTION_Timetable").attr("checked","checked"); 
		$('input#FS_OPTION_Flight').click(function(){
			$('#fs_flight').show();
			$('#fs_timetable').hide();
		});
		$('input#FS_OPTION_Timetable').click(function(){
			$('#fs_flight').hide();
			$('#fs_timetable').show();
		});
		
		$("input#fst_trip_roundtrip").attr("checked", "checked");$("input#fst_trip_oneway").removeAttr("checked"); 
		$('input#fst_trip_oneway').click(function(){
			$('.fst_rtrip_wrp').hide();
		});
		$('input#fst_trip_roundtrip').click(function(){
			$('.fst_rtrip_wrp').show();
		});
		
// -- end

$('.contact_forms').hide();									   
		$('#passenger_service').show();	
	$('.radio_buttons').click(function(){
		$('.contact_forms').hide();									   
		$('#'+$(this).attr('value')).show();
	});

	$("#alert").jCarouselLite({vertical: true,
							  //hoverPause:true,
							  visible: 1,
							  auto:5000,
							  speed:100,
							  btnNext: ".alert_next",
							  btnPrev: ".alert_prev",
							  scroll:1,
							  beforeStart: function(a) {
								  $(a).parent().fadeTo(500, 0);
								  //var bg = $(a).find('img').attr('src');
								  //$('#alert').css({backgroundImage: "url("+bg+")"}, 500);
							  },
							  afterEnd: function(a) {
								  $(a).parent().fadeTo(500, 1);
							  }
					});
	
	$("#B_LOCATION_auto").autocomplete(citiesList, {
		minChars: 0,
		//width: 310,
		max: citiesList.length,
		matchContains: "word",
		autoFill: false,
		mustMatch: true,
		//matchContains: false,
		scrollHeight: 220,
		
		formatItem: function(row, i, max) {
			return  row.cityName + " ("+ row.cityKey+")";
		},
		formatMatch: function(row, i, max) {
			return  row.cityName + " "+ row.cityKey;
		},
		formatResult: function(row) {
			//$("#B_LOCATION").value=row.cityKey;
			return row.cityName;
		}
		
	});
		$("#B_LOCATION_auto").result(function(event, data, formatted) {
			var hidden =  $("#B_LOCATION");
			//alert(data.cityKey);
			hidden.val( data.cityKey );
			showingPopUp(data.cityKey);
		});
		
	$("#E_LOCATION_auto").autocomplete(citiesList, {
		minChars: 0,
		//width: 310,
		max: citiesList.length,
		matchContains: "word",
		autoFill: false,
		mustMatch: true,
		//matchContains: false,
		scrollHeight: 220,
		
		formatItem: function(row, i, max) {
			return  row.cityName + " ("+ row.cityKey+")";
		}, 
		formatMatch: function(row, i, max) {
			return  row.cityName + " "+ row.cityKey;
		},
		formatResult: function(row) {
			//$("#E_LOCATION").value=row.cityKey;
			return row.cityName;
		}
		
	});
	
		$("#E_LOCATION_auto").result(function(event, data, formatted) {
			var hidden =  $("#E_LOCATION");
			hidden.val( data.cityKey  );
			showingPopUp(data.cityKey);
		});
		
	$("#B_LOCATION_auto2").autocomplete(citiesList, {
		minChars: 0,
		//width: 310,
		max: citiesList.length,
		matchContains: true,
		autoFill: false,
		mustMatch: true,
		//matchContains: false,
		scrollHeight: 220,
		
		formatItem: function(row, i, max) {
			return  row.cityName + " ("+ row.cityKey+")";
		},
		formatMatch: function(row, i, max) {
			return  row.cityName + " "+ row.cityKey;
		},
		formatResult: function(row) {
			//$("#B_LOCATION").value=row.cityKey;
			return row.cityName;
		}		
	});
		$("#B_LOCATION_auto2").result(function(event, data, formatted) {
			//var hidden =  $("#B_LOCATION");
			//alert(data.cityKey);
			var hidden = document.flightStatus.B_LOCATION;
			hidden.value= data.cityKey ;
			showingPopUp(data.cityKey);
		});
		
	$("#E_LOCATION_auto2").autocomplete(citiesList, {
		minChars: 0,
		//width: 310,
		max: citiesList.length,
		matchContains: true,
		autoFill: false,
		mustMatch: true,
		//matchContains: false,
		scrollHeight: 220,
		
		formatItem: function(row, i, max) {
			return  row.cityName + " ("+ row.cityKey+")";
		}, 
		formatMatch: function(row, i, max) {
			return  row.cityName + " "+ row.cityKey;
		},
		formatResult: function(row) {
			//$("#E_LOCATION").value=row.cityKey;
			return row.cityName;
		}
		
	});
	
		$("#E_LOCATION_auto2").result(function(event, data, formatted) {
			var hidden = document.flightStatus.E_LOCATION;
			hidden.value= data.cityKey ;
			showingPopUp(data.cityKey);
		});
	
		servicesDivSelect();
		
	
});
   
   function servicesDivSelect(){
	if($("input[@name='services']:checked").length > 0){
		var var_name = $("input[@name='services']:checked").val();
		if(var_name != '' || var_name != null){
			$('.contact_forms').hide();	
			$('#'+var_name).show();
		}
	}   
}


   function search_ver(val){
var ele=document.getElementById(val);
if(ele.value=="Search"){
ele.value="";
}
}
function change_piece(fmtTitle)
{
	var piece_bags = document.getElementById('pieces').value;
	var inner_html = '';
	for(i=1; i<=piece_bags; i++)
	{
		inner_html = inner_html + '<tr> '+
		'<td class="profile_title_field">*'+fmtTitle+''+ i + ':</td></tr><tr><td><input name="baggageReferencesNo" type="text" class="skyform_contact" id="reference_no' + i + '" maxlength="15" /></td></tr>';
	}
	
	$('.change_pieces').html(inner_html);
	
}

// New Added

$(document).ready(function(){
	$('body').append('<div class="bl-hover"><div class="map-holder" style="height:550px"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" class="ttl">Hajj & Umrah Travel Conditions</td><td align="right" class="ttl"><img src="/portal/NewDesign/English/images/btn-close.png" width="14" height="14" alt="close" id="btn-close" onClick="hidemap()"></td></tr><tr><td><p></p><p style="text-align:justify; padding:0 10px">A)&nbsp;&nbsp;Passengers traveling with <b><U>Umrah Visa</U></b> should note the following conditions:</p><p style="text-align:justify; padding:0 25px">1.&nbsp;&nbsp;As per Saudi Government Policies, Umrah Visa Holders can <b>Enter</b> or <b>Depart</b> from <b>Jeddah</b> (King Abdulaziz International Airport - <b>KAIA</b>) or  <b>Madinah</b> (Prince Mohammed bin Abdulaziz Airport at Al-Madinah Al-Munawwarah)<b>airports only</b>. </br> One of these two destinations must be the 1st embarkation point for Hajj and Umrah Visa Holders. Noncompliance of this condition by Pax who use SV online booking engine may result in unfavorable consequences, to whoever violates, in which case the violator will solely bear the responsibility and the consequences resulting from such violation, including non-refundability of tickets.   </p> <p style="text-align:justify; padding:0 25px">2.&nbsp;&nbsp;Umrah visa holders must have a valid air ticket with confirmed round trip/ onward bookings.</p> <p style="text-align:justify; padding:0 10px">B)&nbsp;&nbsp;Passengers traveling with <b><U>Hajj Visa</U></b> should note the following conditions:</p> <p style="text-align:justify; padding:0 25px">1.&nbsp;&nbsp;As per Saudi Government Policies, HAJJ Visa Holders can <b>Enter</b> or <b>Depart</b> from <b>Jeddah</b> (King Abdulaziz International Airport - <b>KAIA</b>) or  <b>Madinah</b> (Prince Mohammed bin Abdulaziz Airport at Al-Madinah Al-Munawwarah)<b>airports only</b>.</p> <p style="text-align:justify; padding:0 25px">2.&nbsp;&nbsp;Hajj visa holders will <b>Enter & Depart</b> from <b>Hajj Terminal</b> (not the regular SV Terminal)</p> <p style="text-align:justify; padding:0 25px">3.&nbsp;&nbsp;Umrah visa holders are not allowed to use it for Hajj purpose.</p> <p style="text-align:justify; padding:0 25px">4.&nbsp;&nbsp;During the official Hajj Period, <b>Muslim Passengers holding Visit or Business visas</b> are not allowed to arrive at Jeddah or Madinah airports.  However, they can enter via RUH or DMM airports.</p> <p style="text-align:justify; padding:0 25px">5.&nbsp;&nbsp;Non-Muslim passengers holding <b>Visit or Business visas</b> are permitted to travel via any airport in Kingdom of Saudi Arabia during the Hajj Period.</p> <p style="text-align:justify; padding:0 25px">6.&nbsp;&nbsp;Hajj Passenger will not be accepted for boarding to Kingdom of Saudi Arabia after the last date of entry set by the Ministry of Hajj.</p> <p style="text-align:justify; padding:0 10px">Further details about Hajj and Umrah can be obtained from the link to the MINISTRY OF HAJJ, Kingdom of Saudi Arabia Web site:&nbsp;<a href="http://www.hajinformation.com/index.htm">http://www.hajinformation.com</a></p><p style="text-align:justify; padding:0 10px"> <input type="checkbox" value="1" name="checkEnabled" id="checkEnabled" onClick="checkBoxChecked()"/> &nbsp; I am aware of the visa restrictions for travelling to the Kingdom of Saudi Arabia</p><input type="button" id="continueLink" disabled="disabled" onclick="contin();return false;" value="Continue">&nbsp; &nbsp; <input type="button" onClick="hidemap();return false;" value="Cancel"></td></tr></table></div></div>');
});

function checkBoxChecked(){
	check = document.getElementById("checkEnabled").checked;
	if(check){
			document.getElementById("continueLink").removeAttribute("disabled");
			//document.getElementById("continueLink").setAttribute("disabled","disabled");
			//document.getElementById("continueLink").setAttribute("onclick","contin();return false;");
			
	}else{
		//document.getElementById("continueLink").removeAttribute("disabled");
		document.getElementById("continueLink").setAttribute("disabled","disabled");
		//document.getElementById("continueLink").removeAttribute("onclick");
	}
}

//var checkifInitialized =0;
function showpage(){
	//alert(array[1][1]);
	//alert(x);
	//alert("A");
	//if(checkifInitialized==0){
	//	gmapinitialize (array) ;
	//	checkifInitialized = 1 ;
	//}
	//alert("Inside the showpage");
	$('.bl-hover').height($(document).height());
	$('.bl-hover').show();
	$('#account-login').css({'visibility':'visible'});							   
}
function hidemap(){
	$('.bl-hover').hide();
	$('#account-login').css({'visibility':'hidden'});							   	
}
function contin(){
	$('.bl-hover').hide();
	$('#account-login').css({'visibility':'hidden'});
	document.getElementById('availability').submit();
}
$('#showpage').click(function(){
	alert("A");
	$('.bl-hover').height($(document).height());
	$('.bl-hover').show();
	$('#account-login').css({'visibility':'visible'});							   
});
$('.bl-hover').click(function(){
	alert("A2");
	$('.bl-hover').hide();
	$('#account-login').css({'visibility':'hidden'});							   
});

function ForceNumbersOnly(myfield, e, dec)
{
    var key;
    var keychar;

    if (window.event)
    {
        key = window.event.keyCode;
    }
    else if (e)
    {
        key = e.which;
    }
    else
    {
        return true;
    }
    if(key != 46 && key != 45 && key > 31 && (key < 48 || key > 57))
    {
        return false;
    }
    else
    {
        return true;
    }
}

function RemoveNonNumeric(myfield)
{
    var re = /[^0-9\.\-]/g;
    if(re.test(myfield.value))
    {
        myfield.value = myfield.value.replace(re, '');
        myfield.value = myfield.value.replace(/\./, '');
    }
}
