/*
	javascript development
	============================
	website 	: 	Acropolis hill
	date 		: 	08-11-2010		
	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="#DFD5C3";
}

function track_ga(action, key)
{
	var trackings = ["/virtual/book-online-form", "/virtual/book-now", "/virtual/book-now-menu", "/virtual/excursions-activities" ];
	
	var tracktag = trackings[key];
	if (action==1)
		_gaq.push(['_trackPageview', tracktag]);
	if (action==2)
		_gaq.push(['_trackEvent', trackercat, 'click', tracking_page]);
	
}
/*function track_ga(trackercat, tracktag)
{
	//category, action, opt_label, opt_value
	if (trackercat!="")
		_gaq.push(['_trackEvent', trackercat, 'click', tracking_page]);
		
	if (tracktag!="")
		_gaq.push(['_trackPageview', tracktag]);
}*/


function clear_errors(formid)
{
	var form = document.getElementById(formid);
	
	for (i=0;i<form.elements.length;i++)
	{
	
		if ( (form.elements[i].type != "button") && (form.elements[i].type != "reset") && (form.elements[i].type != "textarea") )
			form.elements[i].style.background="#c5b99e";
	}
}


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, mandatory_fields, numericfields, emailid)
{
	clear_errors(formid);
	
	//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("Security Code should be a number. Please try again!");
				return false;
			}
		}
	}

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

