var hostUrl = 'http://'+location.hostname+'/';
$(document).ready(function() {
	$("#mycarousel li").click(function(){
		var cur = $(this).index();
		$("#carouselContentWrap div").css('display','none');
		$("#carouselContentWrap div:eq("+cur+")").css('display','block');
	});
	$('.questionsWrap div a').click(function () {        
        $.scrollTo($(this).attr('href'), 800, {easing:'easeOutCubic'});
        return false;
    });
    $(".pricesMenuMain a").click(function(){
    	var indx = $(".pricesMenuMain a").index(this);
    	$(".pricesMenuMain a").removeClass("active");
    	$(this).addClass("active");
    	$(".pricesTable").hide();
    	$(".pricesTable").eq(indx).show();
    	return false;
    });
    $(".tripCountryListWrap a").click(function(){
    	$(".tripCountryListWrap a").removeClass("active");
	    $(this).addClass("active");
	    country_id = $(this).attr('href');
	    loadTripScheduleDates(country_id);
		return false;
    });
});
function loadTripScheduleDates(country_id) {
	if(country_id) {
		$.ajax({
			beforeSend: loadPopup(),
			type: 'POST',
			url: '/trips/load_trip_schedule/'+country_id,
			success: function(data) {
				$("#tripScheduleDetailsWrap").html('').html(data);
				disablePopup();
			}
		});
	}
	else {
		$("#tripScheduleDetailsWrap").html('').html('No Trips are Scheduled');
	}
}
function loadPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	$("#backgroundPopup").css({		
		"width": windowWidth,
		"height": windowHeight
	});
 
	$("#backgroundPopup").css({
		"opacity": "0.8"
	});
	$("#backgroundPopup").fadeIn("slow");
	$("#popupContact").fadeIn("slow");
} 
function disablePopup(){
	$("#backgroundPopup").fadeOut("slow");
	$("#popupContact").fadeOut("slow");
} 
function loadCityList(countryId) {
	if(countryId) {
		$.ajax({
			beforeSend: loadPopup(),
			type: 'POST',
			url: '/appointments/load_city/'+countryId,
			success: function(data) {
				$("#city_id").html('').html(data);
				disablePopup();
			}
		});
	}
	else {
		$("#city_id").html('').html('<option value="">SELECT</option>');
	}
}
function loadLocationList(cityId) {
	if(cityId) {
		$.ajax({
			beforeSend: loadPopup(),
			type: 'POST',
			url: '/appointments/load_location/'+cityId,
			success: function(data) {
				$("#location_id").html('').html(data);
				disablePopup();
			}
		});
	}
	else {
		$("#location_id").html('').html('<option value="">SELECT</option>');
	}
}
function loadAppointmentDates(locationId) {
	if(locationId) {
		$.ajax({
			beforeSend: loadPopup(),
			type: 'POST',
			url: '/appointments/load_appointment_date/'+locationId,
			success: function(data) {
				$("#date").html('').html(data);
				disablePopup();
			}
		});
	}
	else {
		$("#date").html('').html('<option value="">SELECT</option>');
	}
}
function submitAppointment() {
	$(".errorMsg").hide();
	var error = 0;
	if($("#name").val() == '') {
		$("#nameErr").html('').html('Kinldy enter your name').show();
		error++;
	}
	if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test($("#email").val()) === false) {
		$("#emailErr").html('').html('Kindly enter a vaild email address').show();
		error++;
	}
	if($("#phone").val() == '') {
		$("#phoneErr").html('').html('Kindly enter your phone number').show();
		error++;
	}
	if($("#country_id").val() == '') {
		$("#countryErr").html('').html('Kindly select a country').show();
		error++;
	}
	if($("#city_id").val() == '') {
		$("#cityErr").html('').html('Kindly select a city').show();
		error++;
	}
	if($("#location_id").val() == '') {
		$("#hotelErr").html('').html('Kindly select a hotel').show();
		error++;
	}
	if($("#date").val() == '') {
		$("#dateErr").html('').html('Kindly select a date').show();
		error++;
	}
	if($("#time").val() == '') {
		$("#timeErr").html('').html('Kindly select a time').show();
		error++;
	}	
	if(error == 0) {
		loadPopup();
		$("#appointmentForm").submit();	
	}	
}
function loadTripSchedule(country_id) {
	$(".tripCountryListWrap a").removeClass("active");
    $(this).addClass("active");
    if(country_id) {
		$.ajax({
			beforeSend: loadPopup(),
			type: 'POST',
			url: '/trips/load_trip_schedule/'+country_id,
			success: function(data) {
				$("#tripCountryHeading").html('').html($(this).html());
				$("#tripScheduleDetailsWrap").html('').html(data);
				disablePopup();
			}
		});
	}
	else {
		$("#tripScheduleDetailsWrap").html('').html('No Trips are Scheduled');
	}
}
function validateContactForm() {
	var error = 0;
	if($("#name").val() == '' || $("#name").val() == 'YOUR NAME') {
		$("#nameErr").html('').html('Kindly enter your name').show();
		error++;
	}
	if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test($("#email").val()) === false) {
		$("#emailErr").html('').html('Kindly enter a vaild email address').show();
		error++;
	}
	if($("#phone").val() == '' || $("#phone").val() == 'PHONE NO') {
		$("#phoneErr").html('').html('Kindly enter your phone number').show();
		error++;
	}
	if($("#message").val() == '' || $("#message").val() == 'YOUR MESSAGE') {
		$("#messageErr").html('').html('Kindly enter your message').show();
		error++;
	}
	if(error == 0) {
		$("#contact_form").submit();
	}
}
function signupNewsletter() {
	if (/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test($("#signupTextbox").val()) === false) {
		alert("Enter a valid email address");
	}
	else {
		$.ajax({
			beforeSend: loadPopup(),
			type: 'POST',
			url: '/newsletter.php?email='+$("#signupTextbox").val(),
			success: function(data) {
				if(data == 'success')
					alert("Thank you for subscribing to our newsletter");
				$("#signupTextbox").val('Signup for our newsletter');
				disablePopup();
			}
		});
	}
}
