/*
	javascript development
	============================
	website 	: 	Daios
	date 		: 	19-8-2009		
	author 		: 	mayra metaxa / developer
	company		: 	mozaik creative business solutions
	url			:	http://www.mozaik.com

*/

function ga_call(trpage)
{
	_gaq.push(['_trackEvent', trpage, 'click']);		
}


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 windowopen_ga(url, trackercat)
{
	url=Base64.decode(url);

	//category, action, opt_label, opt_value
	_gaq.push(['_trackEvent', trackercat, 'click', tracking_page]);
	_gaq.push(['_trackPageview', 'book-now']);
	
	window.open (url, "mywindow","");
}

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

/**/

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

function show_error(id)
{
	document.getElementById(id).style.color="#CF4D62";
}

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.color="#756a5b";
	}
}


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_prefilled(formid, whichform, mandatory_fields, prefilled_fields, prefilled_values, 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]).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;
			}
		}
	}		

	if (emailid!="")
	{
		if (!checkEmail(emailid))
		{
			show_error(emailid);
			alert ("Your email address is not valid.");
			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])
			{
				show_error(pref_f[i]);
				alert ("You must fill all the mandatory fields (*)");
				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;
			}
		}
	}
	
	_gaq.push(['_trackEvent', 'booking-form', 'submit', tracking_page]);
	_gaq.push(['_trackPageview', 'book-form']);
	
	document.getElementById(formid).submit();
}




/* ============================ */

function get_div_width(id)
{
	var width = $("#"+id).width();	//document.getElementById(id).offsetWidth;
	return (width);
}

function get_div_height(id)
{
	var height = $("#"+id).height();	//document.getElementById(id).offsetHeight;
	return (height);
}


function resize_mosaic_6()
{	
	var divid = 'sixpack';
	
	if (document.getElementById(divid))
	{				
		var width = get_div_width(divid);		
		var height = window_height() - 24;
		
		var thumbwidth = parseInt(width/2);
		var thumbheight = parseInt(height/3);		
		
		for (i=1; i<=6; i++)
		{
			$("#mosaik_"+i).width(thumbwidth);
			$("#mosaik_"+i).height(thumbheight);
		}
	}
}


function resize_mosaic_2()
{	
	var divid = 'twopack';
	
	if (document.getElementById(divid))
	{				
		var width = get_div_width(divid);		
		var height = window_height() - 24;
		
		var thumbwidth = parseInt(width/2);		
		
		for (i=1; i<=2; i++)
		{
			$("#mosaik_"+i).width(thumbwidth);
			$("#mosaik_"+i).height(height);
		}
	}
}



function total_resize()
{
	var brw = $(window).width();
	var brh = $(window).height()-24;	//-footer
	
	//resize mid col height
	if (document.getElementById('middle_col'))	
		$("#middle_col").height(brh);	
	
	//resize columns width:
	var w = $(window).width() - 150;
	var col_width = parseInt(w/2);	
	
	if (document.getElementById('column'))
	{			
		$("#column").width(col_width);
		$("#column").height(brh);
	}
	
	if (document.getElementById('sixpack'))
		$("#sixpack").width(col_width);	
	else if (document.getElementById('twopack'))
		$("#twopack").width(col_width);
	else if (document.getElementById('column2'))
		$("#column2").width(col_width);	
		
	if (document.getElementById('flashholderdiv'))
	{
		$("#flashholderdiv").width(col_width);
		$("#flashholderdiv").height(brh);
	}	
	if (document.getElementById('flashholderdiv2'))
	{
		$("#flashholderdiv2").width(col_width);
		$("#flashholderdiv2").height(brh);
	}

	//resize thimbs:
	
	if (document.getElementById('sixpack'))
		resize_mosaic_6();
		
	if (document.getElementById('twopack'))
		resize_mosaic_2();
	
}

