/*
	javascript development
	============================
	website 	: 	katikies group
	date 		: 	22-7-2009		
	author 		: 	mayra metaxa / developer
	company		: 	mozaik creative business solutions
	url			:	http://www.mozaik.com

*/


/* ========= FORM functions ========= */

function show_error(id)
{
	document.getElementById(id).style.background="#F6EFFF";
}

function clear_errors(which)
{
	for (i=0;i<document.forms[which].elements.length;i++)
	{
		if ( (document.forms[which].elements[i].type != "button") && (document.forms[which].elements[i].type != "reset") && (document.forms[which].elements[i].id!="fieldset") )
			document.forms[which].elements[i].style.background="#B1AAAF";
	}
}


function checkEmail(elem)
{
   var field = document.getElementById(elem);
   var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
   if (field.value.length ==0)
		return false;

   if(field.value.match(emailExp))
		   return true;
   else 
		   return false;
   
}


function check_form(formid, whichform, mandatory_fields, numericfields, emailid)
{
	clear_errors(whichform);
	
	//check mandatory fields
	var man = mandatory_fields.split(",");
	for (i=0;i<man.length;i++)
	{
		if (document.getElementById(man[i]).value == "")
		{
			show_error(man[i]);
			alert ("You must fill all the mandatory fields (*)");
			return false;
		}
	}		

	if (emailid!="")
	{
		if (!checkEmail(emailid))
		{
			show_error(emailid);
			alert ("Your email address is not valid.");
			return false;
		}
	}
	
	//check numeric fields
	if (numericfields != "")
	{
		var numeric = numericfields.split(",");
		for (i=0;i<numeric.length;i++)
		{
			document.getElementById(numeric[i]).value = document.getElementById(numeric[i]).value.replace(/,/,".");
			
			if (isNaN (document.getElementById(numeric[i]).value))
			{
				show_error(numeric[i]);
				alert (numeric[i]+": should be a number. Plase check and try again!");
				return false;
			}
		}
	}
	
	document.getElementById(formid).submit();
}




/* ==== */

function window_width() 
{
	  var myWidth = 0;
	  if( typeof( window.innerWidth ) == 'number' ) 
	  {
		//Non-IE
		myWidth = window.innerWidth;
	  } 
	  else if ( (document.documentElement) && (document.documentElement.clientWidth) ) 
	  {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	  } 
	  else if( (document.body) && (document.body.clientWidth) ) 
	  {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	  }	  	  

	  return(myWidth);
}

function window_height()
{
	 var myHeight = 0;
	  if( typeof( window.innerHeight ) == 'number' ) 
	  {
		//Non-IE
		myHeight = window.innerHeight;
	  } 
	  else if ( (document.documentElement) && (document.documentElement.clientHeight) ) 
	  {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	  } 
	  else if( document.body && (document.body.clientHeight) ) 
	  {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	  }
	  
	  return(myHeight);
}




function resize()
{
	var imgid = 'bgimg';
	
	var browserheight = window_height();
	var browserwidth = window_width();
	
	if (parseInt(navigator.appVersion)>3) 
	{
		/*if (navigator.appName=="Netscape") 
		{
			browserwidth = browserwidth-20;
		}*/
		if (navigator.appName.indexOf("Microsoft")!=-1) 
		{
			browserheight = browserheight+14;
		}
	}

	document.getElementById(imgid).style.height = browserheight+"px";
	document.getElementById(imgid).style.width = browserwidth+"px";

}



function changeRooms() 
{
	var selected=document.getElementById("Hotel").selectedIndex;
	
	
	if(selected==0) 	//Katikies Hotel
	{
		document.getElementById("roomtypeDiv").innerHTML ='<select name="roomtype" id="roomtype" class="select"><option value=""></option><option value="Double Room">Double Room</option><option value="Junior Suite">Junior Suite</option><option value="Senior Suite">Senior Suite</option><option value="Superior Suite">Superior Suite</option><option value="Honeymoon Suite">Honeymoon Suite</option><option value="Katikies Suite">Katikies Suite</option></select>';
	}
	else if(selected==1) 	//Kirini
	{
		document.getElementById("roomtypeDiv").innerHTML ='<select name="roomtype" id="roomtype" class="select"><option value=""></option><option value="Junior Suite">Junior Suite</option><option value="Senior Suite">Senior Suite</option><option value="Wet Junior Suite">Wet Junior Suite</option><option value="Superior Suite">Superior Suite</option><option value="Honeymoon Suite">Honeymoon Suite</option><option value="Kirini Suite">Kirini Suite</option><option value="Spa Suite">Spa Suite</option></select>';
	}
	else if(selected==2) 
	{	//Villa Katikies
		document.getElementById("roomtypeDiv").innerHTML ='<select name="roomtype" id="roomtype" class="select"><option value=""></option><option value="Junior Suite">Villa Double Room</option><option value="Senior Suite">Villa Suites</option></select>';
	}
	else if(selected==3) 
	{	//Sun Rocks
		document.getElementById("roomtypeDiv").innerHTML ='<select name="roomtype" id="roomtype" class="select"><option value=""></option><option value="Double Room">Double Room</option><option value="Junior Suite">Junior Suite</option><option value="Superior Suite">Superior Suite</option><option value="Experience Suite">Experience Suite</option><option value="Honeymoon Suite">Honeymoon Suite</option><option value="The Grand Suite">The Grand Suite</option></select>';
	}
	else if(selected==4) 
	{	//Chromata
		document.getElementById("roomtypeDiv").innerHTML ='<select name="roomtype" id="roomtype" class="select"><option value=""></option><option value="Standard Room">Standard Room</option><option value="Superior Room">Superior Room</option><option value="Suite">Suite</option><option value="Honeymoon Suite">Honeymoon Suite</option><option value="Chromata Suite">Chromata Suite</option><option value="Master Suite">Master Suite</option></select>';
	}	
}



/**/

function show_hide_texts(howmany, which)
{
	for (i=1; i<=howmany; i++)
	{
		document.getElementById('section_'+i).style.display = "none";
		document.getElementById('sectionlink_'+i).className = "";
	}
		
	document.getElementById('section_'+which).style.display = "block";
	document.getElementById('sectionlink_'+which).className = "loc";
}



function change_img(flag_over, which)
{
	var imagesarray = new Array ("kkh", "vkk", "kirini", "sun", "chr");
	var path = 'images/menu/';
	
	if (flag_over==1)				
		document.getElementById('menu_'+which).src = path+imagesarray[which]+'_hover.png';
	else
		document.getElementById('menu_'+which).src = path+imagesarray[which]+'.png';
}