$(function() {

	if($("#continent a").length>1){
		$("#continent a").click(function(){
			var continentid = $(this).attr('cid');
			$("#continent a").removeClass('selected');
			$(this).addClass('selected');
			$.post("http://www.cheapcarhirerates.com/locations.php",{action:'getCountries', continentid: continentid}, function(data){
				$("#country").html(data);
				$("#country a").click(function(){
					var countryid = $(this).attr('cid');
					$("#country a").removeClass('selected');
					$(this).addClass('selected');
					$.post("http://www.cheapcarhirerates.com/locations.php",{action:'getLocations', countryid: countryid, page:1}, function(data){
						$("#locations").html(data);
						handlePaging();
					});
				});
			});
		});
	}
	
    //Fancy Box gallery
//	$("p#thumbs a").fancybox();
	//Accordion
//	$("#accordion").accordion({ header: "div.title1", active: false,  alwaysOpen: false });
	//AJAX form submit
	var newsletteroptions = { target:        '#newsletter'}; 
	$('#newsletterfrm').ajaxForm(newsletteroptions); 
	var newsletteroptions1 = { target:        '#newsletter_unsubscribe'}; 
	$('#unsubscribenewsletterfrm').ajaxForm(newsletteroptions1); 
  });

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function handlePaging(){
		$(".col3 a").click(function(){
			var countryid = $(this).attr('cid');
			var page = $(this).html();
			$.post("http://www.cheapcarhirerates.com/locations.php",{action:'getLocations', countryid: countryid, page:page}, function(data){
				$("#locations").html(data);
				handlePaging();
			});
		});

	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function submitFrm(frm){
	   $('form#'+frm).submit();
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function clearInput(id,value){
	   if($('input#'+id).val()==value){$('input#'+id).val('');}
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    function hideDiv(id){	  $("div#"+id).hide();}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    function showDiv(id){	  $("div#"+id).show();	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    function switchLanguage(langid, currency){
	  //ajax script to set new session language
	  langid = (langid + '').toLowerCase();
	  $.get("language_switcher.php", {id:langid, currency: currency}, function(){
		  //reload page
		  location.href='http://www.cheapcarhirerates.com/'+langid+'/'; 
	  });
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function change2PassType(id, divid){
	   if($('input#'+id).attr('type')=='text'){
	      $('div#'+divid).html('<input type="password" name="'+id+'" id="'+id+'" value=""/>');
		  $('input#'+id).focus();
	   }
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   function add2cart(options){
	 $("#cart").html("<img src='imgs/loading.gif'/>");
     $.get('add2cart.jx.php', {id:options.id},function(data){ 
       $("#cart").html(data);
     });
   }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   function removefromcart(options){
	 $("#cart_details").html("<img src='imgs/loading.gif'/>");
     $.get('removefromcart.jx.php', {id:options.id},function(data){ 
       $("#cart_details").html(data);
	   refresh_cart();
     });
   }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   function refresh_cart(){
	if($("#cart")){
		$("#cart").html("<img src='imgs/loading.gif'/>");
		$.get('refresh_cart.jx.php', function(data){ 
			$("#cart").html(data);
		});
     	}
   }
   
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	function updateCart(itemId){
		var qty = $("#qty"+itemId).val();
		$.get('refresh_cart.jx.php', {id:itemId, qty: qty},function(data){ 
			$("#total").html(data);
			refresh_cart();			
			updateSubtotal(itemId);
		});
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function updateSubtotal(itemId){
		$.get("refresh_subtotal.jx.php", {id:itemId}, function(data){
			$("#subtotal"+itemId).html(data);
		});
	}
