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

*/

/*
function click_clear(id, text)
{
	if (document.getElementById(id).value == text)
		document.getElementById(id).value = "";
}

function prefill(id, text)
{
	if (document.getElementById(id).value == "")
		document.getElementById(id).value = text;
}*/


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

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

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="#A0C5D6";
	}
}


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 login_check()
{
	if ( (document.getElementById('log_username').value == "Username") || (document.getElementById('log_pwd').value == "Password") )
	{
		alert("You must fill in your username and password in order to login.");
		return false;
	}

	document.getElementById('form_login').submit();
}

function login_key_pressed(e)
{
	var numCharCode;
   
   // get event if not passed
   if (!e) var e = window.event;

   // get character code of key pressed
   if (e.keyCode) 
   		numCharCode = e.keyCode;
   else if (e.which) 
   		numCharCode = e.which;
   
   if ( numCharCode == 13 )
   		login_check('form_login');
}

*/
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 check_bookonline(form_id) 
{
	clear_errors(0);
	
	var startdate=check_date(document.getElementById('checkin'));
	if(startdate == false)
	{
		show_error('checkin');
		alert("Check - in date should be a date");
		return false;
	}

	var stopdate=check_date(document.getElementById('checkout'));
	if(stopdate == false) 
	{
		show_error('checkout');
		alert("Check - out date should be a date");
		return false;
	}
	
	//document.getElementById('checkin').value=startdate;
	//document.getElementById('checkout').value=stopdate;
	
	if (date_comparison(startdate, stopdate)==1)	
	{
		alert("Departure date should be after Arrival day!");
		return false;
	}
	
	var nights = sub_dates(startdate, stopdate);
	
	document.getElementById('nights').value = nights;

	document.getElementById(form_id).submit();
}


function date_comparison(date1, date2)
{		
	dt1 = date1.split("-");
	dt2 = date2.split("-");
	
	if ( (dt1[0]==dt2[0]) && (dt1[1]==dt2[1]) && (dt1[2]==dt2[2]) )	//an idies imerominies
		return 0;	//equal
	if (dt1[2] > dt2[2])
		return 1;
	else if (dt1[2] < dt2[2])
		return 2;
	else	//idia eti
	{
		if (dt1[1] > dt2[1])
			return 1;
		else if (dt1[1] < dt2[1])
			return 2;
		else 	//idioi mines (kai idia eti)
		{
			if (dt1[0] > dt2[0])
				return 1;
			else
				return 2;
		}
	}
	
	return -1;
}
	
function sub_dates(date1, date2)
{
	var date1_arr = date1.split("-");
	var date2_arr = date2.split("-");
	
	var dt1 = new Date(date1_arr[2], date1_arr[1]-1, date1_arr[0]);	//Month is 0-11 in JavaScript
	var dt2 = new Date(date2_arr[2], date2_arr[1]-1, date2_arr[0]);	//Month is 0-11 in JavaScript
	
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24
	
	var res = Math.ceil( (dt2.getTime()-dt1.getTime())/(one_day) );
	
	return (res);
}


function check_date(str)
{
	months=new Array();
	months[1]=31;months[2]=28;months[3]=31;months[4]=30;
	months[5]=31;months[6]=30;months[7]=31;months[8]=31;
	months[9]=30;months[10]=31;months[11]=30;months[12]=31;
	
	//message="Unacceptable date format (dd-mm-yyyy)";
	
	var field = str.value;
	
	while (field.indexOf('/')>=0)
		field = field.replace('/', "-");
						
	//var field = str.value;
	//str.value =field;
	
	if (str.value=="")
		return(false);
	else
	{
		comp=field.split('-');

		if ( (field.indexOf('-')<0) || (comp.length!=3) || (isNaN(comp[2])) || (isNaN(comp[1])) || (isNaN(comp[0])) || (comp[1]<1)||(comp[1]>12) )
			return(false);
		
		if (comp[2].length==2)
			comp[2] = "20" + comp[2];
			
		if (months[comp[1]]<comp[0])
		{
			 
			if ((comp[1]==2)&&(comp[0]==29))
			{  
				if ( (comp[2]%400==0) || ( (comp[2]%4==0) && (comp[2]%100!=0) ) ) //->disekto
					return(comp[0] + "-" + comp[1] + "-" + comp[2]);
			}
			return(false);
		}
		if (comp[2].length!=4)
			return(false);
	
		if ((comp[2]<2009)||(comp[2]>2040)){
			alert("Year is out of range: should be between 2009 and 20240");
			return(false);
		}
		
		return(comp[0] + "-" + comp[1] + "-" + comp[2] );
		
	}
}
*/


/* ==== */

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 = 'gallery_prev';
	
	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";

}