$(document).ready
(
  function() {      
		var imageBtnClose = jQuery('#base_url').val() + 'js/lightbox/images/lightbox-btn-close.gif';
		$('#gallery a').lightBox();
  }
);
 
function loadTourCategory(langID) {
	var baseUrl = $('#base_url').val();
	$("#category_id").html('<option>Loading...</option>');
	
	$('#category_id').load(baseUrl + 'backend/tour/ajax_load_tour_category/' + langID);
}

function loadAvailablePage(langID) {
	var baseUrl = $('#base_url').val();
	$("#url_item").html('<option>Loading...</option>');
	
	$('#url_item').load(baseUrl + 'backend/navigation/ajax_load_available_page/' + langID);
}

function weblinksAction()
{
	var web_links;
	web_links = document.getElementById('web_links').value;
	if (web_links)
	{
		document.location = web_links;
	}
}
function panelShow(id)
{
	var offset = $('#send-email').offset();
	var x = offset.left;
	var y = offset.top;
	
	if (id == 'panel-email')
	{
		x-=60;
		y-=540;	
		$('#panel-printer').hide();
		$('#'+id+'-content').height(470);
	}else{
		x-=230;
		y-=500;
		$('#panel-email').hide();
		$('#'+id+'-content').height(400);
	}
	$('#'+id).fadeIn("slow").css({left: x + "px", top: y + "px"});
}
function panelClose(id)
{
	$('#'+id).fadeOut();
}

function panelSend()
{
	var msg				= '';
	var data 			= '';
	var firstname 		= encodeURIComponent($('#firstname').val());
	var lastname 		= encodeURIComponent($('#lastname').val());
	var from_email		= $('#from_email').val();
	var to_email 		= $('#to_email').val();
	var subject			= encodeURIComponent($('#subject').val());
	var sendcontent 	= encodeURIComponent($('#sendcontent').val());
	
	var email_tour_name				= encodeURIComponent($('#email_tour_name').val());
	var email_tour_images			= encodeURIComponent($('#email_tour_images').val());
	var email_tour_description	    = encodeURIComponent($('#email_tour_description').val());
                                       
	
	if (jQuery.trim(firstname)=='')
	{
		$('#firstname').focus();
		msg += $('#msg-firstname').val()+' \n';
	}
	if (jQuery.trim(lastname)=='')
	{
		$('#lastname').focus();
		msg += $('#msg-lastname').val()+' \n';
	}	
	if (jQuery.trim(from_email)=='')
	{
		$('#from_email').focus();
		msg += $('#msg-from-email').val()+' \n';
	} else if (jQuery.trim(from_email)!='' && !isValidEmail(from_email)){
		msg += $('#msg-validate-from-email').val()+" \n";
	}
	if (jQuery.trim(to_email)=='')
	{
		$('#to_email').focus();
		msg += $('#msg-to-email').val()+' \n';
	} else if (jQuery.trim(to_email)!='' && !isValidEmail(to_email)){
		msg += $('#msg-validate-to-email').val()+' \n';
	}	
	if (jQuery.trim(subject)=='')
	{
		$('#subject').focus();
		msg += $('#msg-subject').val()+' \n';
	}	
	if (jQuery.trim(sendcontent)=='')
	{
		$('#sendcontent').focus();
		msg += $('#msg-sendcontent').val()+' \n';
	}	
	if (msg) {
		alert(msg);
	} else {
		data += 'firstname='+firstname;
		data += '&lastname='+lastname;
		data += '&from_email='+from_email;
		data += '&to_email='+to_email;
		data += '&subject='+subject;
		data += '&sendcontent='+sendcontent;

		data += '&email_tour_name='+email_tour_name;
		data += '&email_tour_images='+email_tour_images;
		data += '&email_tour_description='+email_tour_description;
		
        
		$.ajax
			({
				type: "POST",
				url: $('#base-url-send').val(), 
				data: data, success: function(html)
				{
					$('#firstname').val('');
					$('#lastname').val('');
					$('#from_email').val('');
					$('#to_email').val('');
					$('#subject').val('');
					$('#sendcontent').val('');
					
					$('#panel-email').hide();
				}
			});		
	}
}
function panelPrint()
{
	window.frames['framePrinter'].focus();
	window.frames['framePrinter'].print();
}
function isValidEmail(strEmail)
{
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      return false;
    } 
    return true; 
}

function weblinksAction()
{
	var web_links;
	web_links = document.getElementById('web_links').value;
	if (web_links)
	{
		document.location = web_links;
	}
}