/*
	javascript development
	============================
	website 	: 	semeli
	date 		: 	17-4-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;
}*/

function ga_call()
{
	_gaq.push(['_trackEvent', 'accommodation-book-now', 'click', tracking_page]);
	_gaq.push(['_trackPageview', 'accommodation-book-now']);
	
	window.open ('https://semeli.reserve-online.net/', "mywindow","");
}

function click_clear(thisfield) 
{
	if (thisfield.value == thisfield.defaultValue)
		thisfield.value = "";
	else if (thisfield.value == "")
		thisfield.value = thisfield.defaultValue;
}


function track_ga(trackercat)
{
	//category, action, opt_label, opt_value
	_gaq.push(['_trackEvent', trackercat, 'click', tracking_page]);
	_gaq.push(['_trackPageview', trackercat]);
	
}

function track_ga_new(action, key)
{
	var trackings = ["/virtual/book-online-top-menu", "/virtual/book_online", "/virtual/book-online-sitemap"];
	
	var tracktag = trackings[key];
	if (action==1){
		_gaq.push(['_trackPageview', tracktag]);
	}
	if (action==2)
		_gaq.push(['_trackEvent', trackercat, 'click', tracking_page]);
	
}

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

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

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

function clear_errors_home(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="#b8b6ae";
	}
}


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;
			}
		}
	}
	
	if (document.getElementById('form_flag'))	
		track_ga(document.getElementById('form_flag').value);
	
	document.getElementById(formid).submit();
}

function check_form_home(formid, whichform, mandatory_fields, numericfields, emailid)
{
	clear_errors_home(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_form_prefilled(formid, mandatory_fields, prefilled_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]).type) && (document.getElementById(man[i]).type == "select-one") )
		{
			if (document.getElementById(man[i]).selectedIndex == 0)
			{
				show_error(man[i]);
				alert ("You must fill all the mandatory fields (*)");
				return false;
			}
		}
		else
		{
			if (document.getElementById(man[i]).value == "")
			{
				show_error(man[i]);
				alert ("You must fill all the mandatory fields (*)");
				return false;
			}
		}
	}		

	//prefilled
	if (prefilled_fields!="")
		var pref_f = prefilled_fields.split(",");

	//check prefilled:
	if (prefilled_fields!="")
	{
		for (i=0;i<pref_f.length;i++)
		{
			//if (document.getElementById(pref_f[i]).value == pref_v[i])
			if (document.getElementById(pref_f[i]).value == document.getElementById(pref_f[i]).defaultValue)			
			{
				show_error(pref_f[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. Please check and try again!");
				return false;
			}
		}
	}
	
	/*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 != "hidden") )
		{
			if ( form.elements[i].value == form.elements[i].defaultValue)		
				form.elements[i].value="";
		}
	}*/
	
	document.getElementById(formid).submit();
}

function lang_select(){
	var lang = $('.lang_select').val();
	if(lang=='en')
		lang='';	
	window.location=websiteURL+lang+pagename;
}
	
