/*
	javascript development
	============================
	website 	: 	Onassis foundation
	date 		: 	14-3-2011		
	author 		: 	mayra metaxa / developer
	company		: 	mozaik creative business solutions
	url			:	http://www.mozaik.com



function track_ga(trackercat, tracktag)
{
	if (trackercat!="")
		_gaq.push(['_trackEvent', trackercat, 'click', tracking_page]);
	if (tracktag!="")
		_gaq.push(['_trackPageview', tracktag]);
}*/

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

function show_error(id)
{
	$('#'+id).css("background", "#6BCFF9");	//CFC7B5 4BBDF2
}

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="#fefefe url("+websiteURL+"images/input_bg.jpg) repeat-x left bottom";
	}
}

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

	var man = mandatory_fields.split(",");
	for (i=0;i<man.length;i++)
	{
		if ($('#'+man[i]).val()=="")		
		{
			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;
		}
	}
	
	if (numericfields != "")
	{
		var numeric = numericfields.split(",");
		for (i=0;i<numeric.length;i++)
		{
			var nv = $('#'+numeric[i]).val().replace(/,/,".");
			$('#'+numeric[i]).val(nv);
			
			if (isNaN ($('#'+numeric[i]).val()))
			{
				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_nosubm(formid, mandatory_fields, numericfields, emailid)
{
	clear_errors(formid);

	var man = mandatory_fields.split(",");
	for (i=0;i<man.length;i++)
	{
		if ($('#'+man[i]).val()=="")		
		{
			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;
		}
	}
	
	if (numericfields != "")
	{
		var numeric = numericfields.split(",");
		for (i=0;i<numeric.length;i++)
		{
			var nv = $('#'+numeric[i]).val().replace(/,/,".");
			$('#'+numeric[i]).val(nv);
			
			if (isNaN ($('#'+numeric[i]).val()))
			{
				show_error(numeric[i]);
				alert (numeric[i]+": should be a number. Plase check and try again!");
				return false;
			}
		}
	}

	return true;
}
