/*
	javascript development
	============================
	website 	: 	Excelsior
	date 		: 	9-12-2009		
	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]);
		//alert(trackercat); 
		//alert(tracktag); 
}

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


/*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 hide_intro() 
{		
	$("#html").css("visibility","visible");
		
	$(".flashintro_holder").hide();	
	$(".skip_intro").hide();
	
	$('#footer_menu').show();				
	$('.slider_div').show();	
	$('.content').show();				
	
	document.location.href = "#nointro";
	
	//scroller.init();
}


function tab_blocks(id, howmany)
{
	for (i=1; i<=howmany; i++)
	{
		document.getElementById("tab_content_"+i).style.display = "none";
		document.getElementById("tablink_"+i).className = "";
	}
		
	document.getElementById("tab_content_"+id).style.display = "block";
	document.getElementById("tablink_"+id).className = "loc";	
	
}


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

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

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].type!="textarea") )
			document.forms[which].elements[i].style.background="#CDCAB7";
	}
}


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;
			}
		}
	}
	
	document.getElementById(formid).submit();
}



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;
			}
		}
	}
	
	document.getElementById(formid).submit();
}

/*


function file_upload(file_id)	
{
	var file = document.getElementById(file_id);
	if (file.value == "")
	{
		alert("You have to attach a file!");
		return false;
	}
	
	var file1 = file.value.split(".");
	
	if (file1.length < 2)
	{
		alert("Invalid file path!");
		return false;
	}
	if ( (file1[file1.length-1] != "txt") && (file1[file1.length-1] != "doc") && (file1[file1.length-1] != "docx") && (file1[file1.length-1] != "rtf") && (file1[file1.length-1] != "pdf") && (file1[file1.length-1] != "zip") )
	{
		alert("Invalid file type! Accepted file types: .txt, .doc, .rtf, .pdf, .docx, .zip");
		return false;
	}

	return true;
		
}*/




/* ============================================ resize =========================================== */

function get_div_width(id)
{
	var width = document.getElementById(id).offsetWidth;
	return (width);
}

function get_div_height(id)
{
	var height = document.getElementById(id).offsetHeight;
	return (height);
}


function total_resize()
{	
	var w = $(window).width();
	var h = $(window).height();
	
	resizeElements();
	
	if (document.getElementById('container'))
	{		
		
		var cheight = h-50-10;	//-footer - marginTop

		//document.getElementById('container').style.width = w+"px";
		$("#container").height(cheight);						
	}
	
	if (document.getElementById('slider_div'))
	{		
		var fheight = cheight-45-10;	//-margins
		//var fwidth = w-152-40;	//-left -margins
		//var fwidth = get_div_width('right_col')-40-77;	//-margins
		var fwidth = w-152-40-77;	//-left_col -margins
		
		$("#slider_div").width(fwidth);
		$("#slider_div").height(fheight);	
	}
	
	if (document.getElementById('content'))
	{		
		//var cont_width = get_div_width('right_col')-2-7;	//-borders - right_gap
		var cont_width = w-152-2;	//-left_col -borders - right_gap

		$("#content").width(cont_width);
	}
	
	if (document.getElementById('flashintro_holder'))
	{		
		var fheight = cheight-45-10;	//-margins
		//var fwidth = w-152-40;	//-left -margins
		//var fwidth = get_div_width('right_col')-40-77;	//-margins
		var fwidth = w-152-40-77;	//-left_col -margins

		$("#flashintro_holder").width(fwidth);
		$("#flashintro_holder").height(fheight);		
	}

}

$('.event_thumb').hover(function () {
		$(this).children('.img').stop().fadeTo(300, 0.4);
		$(this).children('.plus').fadeIn(200);
	}, 
	function () {
		$(this).children('.img').stop().fadeTo(300, 1);
		$(this).children('.plus').fadeOut(200);
});


