/*
	javascript development
	============================
	website 	: 	eclub
	date 		: 	16-12-2010		
	author 		: 	mayra metaxa / developer
	company		: 	mozaik creative business solutions
	url			:	http://www.mozaik.com

*/

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

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

function click_clear(id) 
{
	if (document.getElementById(id).value == document.getElementById(id).defaultValue)
		document.getElementById(id).value = "";
	else if (document.getElementById(id).value == "")
		document.getElementById(id).value = document.getElementById(id).defaultValue;
}


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


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].style.background="#fff";			
	}
}


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]);
			//You must fill all the mandatory fields (*)
			if (websiteLang=='gr')
			{alert ("Πρέπει να συμπληρώσετε όλα τα υποχρεωτικά πεδία (*)");}
			else
			{alert ("You must fill all the mandatory fields (*)");}
			return false;
		}
	}		

	if (emailid!="")
	{
		if (!checkEmail(emailid))
		{
			show_error(emailid);
			//Your email address is not valid.
			if (websiteLang=='gr')
			{alert ("Παρακαλούμε πληκτρολογήστε το email σας σωστά.");}
			else
			{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]);
				//{field} should be a number. Please check and try again.
				if (websiteLang=='gr')
				{alert (numeric[i]+": πρέπει να είναι αριθμός. Παρακαλούμε διορθώστε το και δοκιμάστε ξανά.");}
				else
				{alert (numeric[i]+": should be a number. Please check and try again.");}
				return false;
			}
		}
	}
	
	document.getElementById(formid).submit();
}


function check_form_prefilled(formid, mandatory_fields, prefilled_fields, numericfields, emailid)
{
	//prefilled_values
	
	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]);
				//You must fill all the mandatory fields (*)
				if (websiteLang=='gr')
				{alert ("Πρέπει να συμπληρώσετε όλα τα υποχρεωτικά πεδία (*)");}
				else
				{alert ("You must fill all the mandatory fields (*)");}
				return false;
			}
		}
		else
		{
			if (document.getElementById(man[i]).value == "")
			{
				show_error(man[i]);
				//You must fill all the mandatory fields (*)
				if (websiteLang=='gr')
				{alert ("Πρέπει να συμπληρώσετε όλα τα υποχρεωτικά πεδία (*)");}
				else
				{alert ("You must fill all the mandatory fields (*)");}
				return false;
			}
		}
	}		

	//prefilled
	if (prefilled_fields!="")
		var pref_f = prefilled_fields.split(",");
		
	//if (prefilled_values!="")
		//var pref_v = prefilled_values.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]);
				//You must fill all the mandatory fields (*)
				if (websiteLang=='gr')
				{alert ("Πρέπει να συμπληρώσετε όλα τα υποχρεωτικά πεδία (*)");}
				else
				{alert ("You must fill all the mandatory fields (*)");}
				return false;
			}
		}
	}
	
	if (emailid!="")
	{
		if (!checkEmail(emailid))
		{
			show_error(emailid);
			if (websiteLang=='gr')
			{alert ("Παρακαλούμε πληκτρολογήστε το email σας σωστά.");}
			else
			{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]);
				//{field} should be a number. Please check and try again.
				if (websiteLang=='gr')
				{alert (numeric[i]+": πρέπει να είναι αριθμός. Παρακαλούμε διορθώστε το και δοκιμάστε ξανά.");}
				else
				{alert (numeric[i]+": should be a number. Please check and try again.");}
				return false;
			}
		}
	}
	
	document.getElementById(formid).submit();
}

