
var ns4 = document.layers;
var op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) 
	||(navigator.userAgent.indexOf("Opera/5")!=-1);
var op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) 
	||(navigator.userAgent.indexOf("Opera/6")!=-1);
var agt=navigator.userAgent.toLowerCase();
var mac = (agt.indexOf("mac")!=-1);
var ie = (agt.indexOf("msie") != -1); 
var mac_ie = mac && ie;

var timer_hide="";
var sub_id=0;
var main_id=0;
var i=0;
var my_top=0;
var my_left=0;
var EmlExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
function getElementTop(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageY;
	} else {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}
function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}

function getElementLeft(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageX;
	} else {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}
submit_contact=function()
	{
	var ok="ok";
	if (document.getElementById('name').value=='')
		{
		ok="nok";
		alert ("Please enter your name");
		document.getElementById('name').focus();
		}
	if (ok=="ok") if (document.getElementById('subject').value=='')
		{
		ok="nok";
		alert ("Please enter a subject");
		document.getElementById('subject').focus();
		}
	if (ok=="ok") if (document.getElementById('country').value=='')
		{
		ok="nok";
		alert ("Please enter a country");
		document.getElementById('country').focus();
		}
	if (ok=="ok") if (document.getElementById('country').value=='0')
		{
		ok="nok";
		alert ("Please enter a country");
		document.getElementById('country').focus();
		}
	if (ok=="ok") if (document.getElementById('tel').value=='')
		{
		ok="nok";
		alert ("Please enter a telephone ");
		document.getElementById('tel').focus();
		}
	if (ok=="ok") if (document.getElementById('email').value=='')
		{
		ok="nok";
		alert ("Please enter an email address");
		document.getElementById('email').focus();
		}
	else if  (!document.getElementById('email').value.match(EmlExp)) 
		{
		ok="nok";
		alert ("Please enter a valid email address");
		document.getElementById('email').focus();
		}
	if (ok=="ok") if (document.getElementById('comment').value=='')
		{
		ok="nok";
		alert ("Please enter a comment/query");
		document.getElementById('comment').focus();
		}
	if (ok=="ok")
		{
		document.getElementById('sub_me').value="XX";
		document.getElementById('div_show_working').style.display="block";
	
		new Ajax.Updater("div_content_show", 'components/contact_form_update.php',
			{
			method: 'post',
			asynchronous:true,
			evalScripts:true,
			onComplete:function(request)
					{
					document.getElementById('div_show_working').style.display="none";
					
	
					},
			parameters: $("contact_form").serialize(true)  
			});
		}
	}
	submit_contact_new=function()
	{
	var ok="ok";
	if (document.getElementById('name').value=='')
		{
		ok="nok";
		alert ("Please enter your name");
		document.getElementById('name').focus();
		}
	if (ok=="ok") if (document.getElementById('email').value=='')
		{
		ok="nok";
		alert ("Please enter an email address");
		document.getElementById('email').focus();
		}
	else if  (!document.getElementById('email').value.match(EmlExp)) 
		{
		ok="nok";
		alert ("Please enter a valid email address");
		document.getElementById('email').focus();
		}
		
	
	if (ok=="ok") if (document.getElementById('country').value=='')
		{
		ok="nok";
		alert ("Please enter a country");
		document.getElementById('country').focus();
		}
	
	if (ok=="ok")
		{
		document.getElementById('sub_me').value="XX";
		document.getElementById('div_show_working').style.display="block";
	
		new Ajax.Updater("div_content_show", 'components/contact_form_update_new.php',
			{
			method: 'post',
			asynchronous:true,
			evalScripts:true,
			onComplete:function(request)
					{
					document.getElementById('div_show_working').style.display="none";
					
	
					},
			parameters: $("contact_form").serialize(true)  
			});
		}
	}
check_download_pic=function(image_id)
	{
	var ok="ok";
	
	if (ok=="ok")
		{
		document.getElementById('div_show_working').style.display="block";
	
		new Ajax.Updater("div_check_login", 'check_login_ajax.php',
			{
			method: 'post',
			asynchronous:true,
			evalScripts:true,
			onComplete:function(request)
					{
							
					document.getElementById('div_show_working').style.display="none";
					//alert(document.getElementById('is_logged_in').value);
					if (document.getElementById('is_logged_in')) if (document.getElementById('is_logged_in').value=='1')
						{
						 
							download_pic();
						}
					document.getElementById('div_check_login').style.display="block";
					},
				parameters: {image_id:image_id }
			});
		}
	}
download_pic=function()
 {
	 	//alert(document.getElementById('image_id').value); 
		var image_id=document.getElementById('image_id').value;
		//alert(image_id);
	    window.location.href="download_pic.php?image_id="+image_id;
		return true;
	
		 
 }
invoke_login=function()
	{
	var ok="ok";
	
	if (document.getElementById('thisuser').value=='')
		{
		ok="nok";
		alert ("Please enter your user name");
		document.getElementById('thisuser').focus();
		}
	if (ok=="ok") if (document.getElementById('pword').value=='')
		{
		ok="nok";
		alert ("Please enter your password");
		document.getElementById('pword').focus();
		}
	
	if (ok=="ok")
		{
		document.getElementById('div_show_working').style.display="block";
	
		new Ajax.Updater("div_check_login", 'check_login_ajax.php',
			{
			method: 'post',
			asynchronous:true,
			evalScripts:true,
			onComplete:function(request)
					{
					document.getElementById('div_show_working').style.display="none";
					if (document.getElementById('is_logged_in')) if (document.getElementById('is_logged_in').value=='1')
						{
							download_pic();
						}
					else document.getElementById('div_check_login').style.display="block";
					document.getElementById('div_check_login').style.display="block";
					},
				parameters: $("login_form").serialize(true)  
			});
		}
	}
close_login=function()
	{
	
	document.getElementById('div_check_login').style.display="none";
	document.getElementById('div_check_login').innerHTML="";
					
	}
submit_reservations=function()
	{
	var ok="ok";
	if (document.getElementById('firstname').value=='')
		{
		ok="nok";
		alert ("Please enter your first name");
		document.getElementById('firstname').focus();
		}
	if (ok=="ok") if (document.getElementById('lastname').value=='')
		{
		ok="nok";
		alert ("Please enter your last name");
		document.getElementById('lastname').focus();
		}
	if (ok=="ok") if (document.getElementById('email').value=='')
		{
		ok="nok";
		alert ("Please enter an email address");
		document.getElementById('email').focus();
		}
	else if  (!document.getElementById('email').value.match(EmlExp)) 
		{
		ok="nok";
		alert ("Please enter a valid email address");
		document.getElementById('email').focus();
		}
	if (ok=="ok") if (document.getElementById('tel').value=='')
		{
		ok="nok";
		alert ("Please enter a telephone ");
		document.getElementById('tel').focus();
		}
	if (ok=="ok") if (document.getElementById('country').value=='')
		{
		ok="nok";
		alert ("Please enter a Nationality");
		document.getElementById('country').focus();
		}
	if (ok=="ok") if (document.getElementById('country').value=='0')
		{
		ok="nok";
		alert ("Please enter a Nationality");
		document.getElementById('country').focus();
		}

	
	if (ok=="ok") if (document.getElementById('start_date').value>document.getElementById('end_date').value)
		{
		ok="nok";
		alert ("Start date cannot be greater than end date");
		document.getElementById('start_date').focus();
		}
	
	if (ok=="ok") if (document.getElementById('no_of_adults').value=='')
		{
		ok="nok";
		alert ("Please enter the number of adults");
		document.getElementById('no_of_adults').focus();
		}
	if (ok=="ok")
		{
		document.getElementById('sub_me').value="XX";
		document.getElementById('div_show_working').style.display="block";
	
		new Ajax.Updater("div_content_show", 'components/reservations_update.php',
			{
			method: 'post',
			asynchronous:true,
			evalScripts:true,
			onComplete:function(request)
					{
					document.getElementById('div_show_working').style.display="none";
	
					},
			parameters: $("reservation_form").serialize(true)  
			});
		}
	}
pre_load_images = function ()
	{
	//preloader_top_menu();
	}
back_cat = function (cat_id)
	{
	if (document.getElementById('back_cat')	) cat_id=document.getElementById('back_cat').value;
	document.location.href="cat.php?cat_id="+cat_id;
	}
show_content=function (id) {

	document.getElementById('div_show_working').style.display="block";
	
	new Ajax.Updater("div_main_content", 'ajax_content_detail.php',
		{
		method: 'post',
		asynchronous:true,
		evalScripts:true,
		onComplete:function(request)
				{
				document.getElementById('div_show_working').style.display="none";

				},
		parameters: {content_id:id }
		});
}



function show_submenu(id)
	{
		
	clearTimeout(timer_hide);
	
	my_top=getElementTop('div_main_menu');
	my_left=getElementLeft('div_mm'+id);
	my_width=getElementWidth('div_mm'+id);
	
	my_left=(my_width/2)+my_left-18;
	//alert(my_left+":"+my_width);
	
	
	var nof_brows=document.getElementById('nof_brows').value;
	
	for (k=1;k < nof_brows;k++)
		{
		sub_id=document.getElementById('nof_brows'+k).value;
		if (sub_id!=id)
			{
			main_id=k-1;
			hide_sub_menu();
			}
		}
	sub_id=id;
	
	if ((document.getElementById('div_sub_menu'+id).style.display=="none")||(document.getElementById('downarrow').style.display=="none"))
		{
		//document.getElementById('div_sub_menu'+id).style.display="";
		 slide_submenu_out();

		}
	}



function check_menu_to_show()
	{
	if (document.getElementById('sub_menu_to_show') )
		{
	 	if (document.getElementById('sub_menu_to_show').value!='')
	 		{
	 		show_sub_menu_for_a_bit(document.getElementById('sub_menu_to_show').value);
	 		}
		}
	}
	
function show_sub_menu_for_a_bit(id)
	{
	clearTimeout(timer_hide);
	my_top=getElementTop('div_main_menu');
	my_left=getElementLeft('div_mm'+id);
	my_left=getElementLeft('div_mm'+id);
	my_width=getElementWidth('div_mm'+id);
	//alert(my_left+":"+my_width);
	my_left=(my_width/2)+my_left-18;
	sub_id=id;
	slide_submenu_out();
	sub_id=id;
	timer_hide=setTimeout("hide_sub_menu()",5000);
	}
function slide_submenu_out()
	{
	var factor=document.getElementById('sub_menu_rows'+sub_id).value;
	if (factor>1) this_top=my_top-(20*factor);	
	else this_top=my_top-30;	
	
	//alert (my_top+":"+this_top+":"+sub_id);
	document.getElementById('div_sub_menu'+sub_id).style.zIndex = '5000';
	document.getElementById('div_sub_menu'+sub_id).style.top=this_top+"px";
	//document.getElementById('div_sub_menu'+sub_id).style.height=i+"px";
	document.getElementById('div_sub_menu'+sub_id).style.display="";
	document.getElementById('div_sub_menu'+sub_id).style.visibility = 'visible';
	
	document.getElementById('downarrow').style.left=my_left+"px";
	document.getElementById('downarrow').style.top=my_top+"px";
	document.getElementById('downarrow').style.display="block";
		
	}
function hide_submenu(id,mn_id)
	{
	sub_id=id;
	main_id=mn_id;
	//alert(main_id);
	timer_hide=setTimeout("hide_sub_menu()",3000);
	//hide_sub_menu();
	}
function hide_sub_menu()
	{
	document.getElementById('div_sub_menu'+sub_id).style.display="none";
	document.getElementById('downarrow').style.display="none";
	//alert(main_id);
  	//document.getElementById('mm'+main_id).className='main_menu';
  	//document.getElementById('mmimg'+main_id).src=images_out[main_id];
	
	}
function checkNumeric (e, which) {
// Ensure only numbers are entered
 
          var txtValue = which.value;
          var key = (e.keyCode ? e.keyCode : e.which);
 
          switch (key) {
                    case  8:
                    case  9:
                    case 37:
                    case 39:
                    case 46:
                    case 48:
                    case 49:
                    case 50:
                    case 51:
                    case 52:
                    case 53:
                    case 54:
                    case 55:
                    case 56:
                    case 57:        break;
                    default:         if (e.preventDefault) {
                                                            e.preventDefault ();
                                                  } else {
                                                            e.returnValue = false;
                                                  }
          }
 
          if (key == 46){
                    if (txtValue.indexOf ('.') != -1) {   
                              if (e.preventDefault) {
                                        e.preventDefault ();
                              } else {
                                        e.returnValue = false;
                              }
                    }
          }       
 
}