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

*/

function booknow()
{
	pageTracker._trackPageview('book-now-button');
	//document.bookform.submit();
	document.getElementById('bookform').submit();
}

function booknow_link()
{
	pageTracker._trackPageview('reservation-click');
	//document.bookform.submit();
	document.getElementById('bookform').submit();
}


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

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

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


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();
}

/* === toggle WIDTH ======= */

function change_width(width, id)
{
	document.getElementById(id).style.width = width+"px";
}


function change_width_open(width, id, whole)
{
	document.getElementById(id).style.width = width+"px";
	
	var innerwidth = whole - 15;
	if (width<=275)
		document.getElementById('col2_text').style.width = width+"px";
	else
		document.getElementById('col2_text').style.display = "block";
}


function toggle(id, minwidth, maxwidth) 
{
	var speed = Math.round(110 / 100);
	var timer = 0;
	
	var whole = maxwidth+50;
	//minwidth = 21
	
	if (document.getElementById(id).offsetWidth > minwidth)
	{				
		//make small - toggle in: ------------- 
		
		document.getElementById('showhideimg').src = "images/show.gif";
		document.getElementById('col2_text').style.display = "none";
		
		for(i = whole; i >= minwidth; i--) 
		{
			setTimeout("change_width(" + i + ",'"+id+"')",(timer * speed));
			timer++;
		}
	}
	else
	{
		//toggle out: ---------------
		
		document.getElementById('showhideimg').src = "images/hide.gif";
						
		for(i = minwidth; i <= whole; i++) 
		{
			setTimeout("change_width_open(" + i + ",'"+id+"', "+maxwidth+")",(timer * speed));
			timer++;
		}
		
	}

}



/* ===== */

function showhide_intro(action) 
{		
	if (action == 1)	//html
	{
		document.getElementById('container').style.display = "block";
		document.getElementById('gallerybg').style.display = "block";
		document.getElementById('fullscreenintro').style.display = "none";	
		document.location.href = "index.php#nointro";
	}
	else if (action == 2)	//intro
	{
		document.getElementById('container').style.display = "none";
		document.getElementById('gallerybg').style.display = "none";
		document.getElementById('fullscreenintro').style.display = "block";
	}
}


function showhide_gallerybtns(action)
{	
	if (action == 1)	//show navigation:
	{
		document.getElementById('gallery_btns_block1').style.display = "block";
		document.getElementById('gallery_btns_block2').style.display = "none";
	}
	else if (action == 2)	//show + :
	{
		document.getElementById('gallery_btns_block1').style.display = "none";
		document.getElementById('gallery_btns_block2').style.display = "block";
	}
}



/* ===== */

function openclose_block(which, opentitleclass, deftitleclass, num)
{
	var i;
	
	for (i=1; i<=num; i++)
	{
		if (i!=which)
		{			
			
			//toggle_height('block_'+i, i, 0);
			
			document.getElementById('block_title_'+i).className = deftitleclass;
			
			document.getElementById('block_'+i).style.display = "none";
		}
	}

	
	if ((document.getElementById('block_'+which).style.display == "block") || (document.getElementById('block_'+which).style.display == "") )
	{
				
		document.getElementById('block_title_'+which).className = deftitleclass;
		
		//toggle_height('block_'+which, which, 0);
		
		document.getElementById('block_'+which).style.display = "none";
	}
	else
	{
				
		document.getElementById('block_title_'+which).className = opentitleclass;
				 
		//toggle_height('block_'+which, which, 1);
		
		document.getElementById('block_'+which).style.display = "block";
	}
}

/* === toggle HEIGHT ======= */

function change_height(height, id)
{
	document.getElementById(id).style.height = height+"px";
}


function toggle_height(id, which, action) 
{
	var speed = Math.round(110 / 100);
	var timer = 0;
	var i;
		
	var whole = document.getElementById(id).offsetHeight;
	
	if (action == 0)	//close
	{
		block_height[which] = whole;
		
		block_content[which] = document.getElementById('block_'+which).innerHTML;
		document.getElementById('block_'+which).innerHTML = "";
		
		for(i = whole; i >= 0; i--) 
		{
			setTimeout("change_height(" + i + ",'"+id+"')",(timer * speed));
			timer++;
		}
	}
	else
	{	
		if (document.getElementById(id).offsetHeight > 0)
		{				
			//make small - toggle in: ------------- 
			
			block_height[which] = whole;
			
			block_content[which] = document.getElementById('block_'+which).innerHTML;
			document.getElementById('block_'+which).innerHTML = "";
			
			for(i = whole; i >= 0; i--) 
			{
				setTimeout("change_height(" + i + ",'"+id+"')",(timer * speed));
				timer++;
			}
		}
		else
		{
			//toggle out: ---------------
			
			document.getElementById('block_'+which).innerHTML = block_content[which];
							
			for(i = 0; i <= block_height[which]; i++) 
			{
				setTimeout("change_height(" + i + ",'"+id+"')",(timer * speed));
				timer++;
			}
			
		}
	}

}

