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

*/

/*

function hide_intro() 
{		

	$("#html").css("visibility","visible");
	
	$("#jsintro").hide();
	$('#content').show();
	$('#menu_top').show();	
		
	scroller.init();		
	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="#fbedec";
}

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


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;
		
}*/

/*

function check_date(id)
{
	var str = document.getElementById(id);
	
	months=new Array();
	months[1]=31;months[2]=28;months[3]=31;months[4]=30;
	months[5]=31;months[6]=30;months[7]=31;months[8]=31;
	months[9]=30;months[10]=31;months[11]=30;months[12]=31;
	
	var message="Unaccepled date format: (dd/mm/yyyy - eg. 31/12/20010)";
	
	field = str.value.replace(/-/g,"/");
	str.value =field;
	
	//field = str.value;
	
	var sep = "/";
	
	if (str.value=="")
	{
		show_error(id);
		alert(message);
		return(-1);
	}
	else
	{
		comp=field.split(sep);
		
		if (comp[2].length==2)
			comp[2] = "20" + comp[2];
		
		if ( (field.indexOf(sep)<0) || (comp.length!=3) || (isNaN(comp[2])) || (isNaN(comp[1])) || (isNaN(comp[0])) || (comp[1]<1)||(comp[1]>12) )
		{
			show_error(id);
			alert(message);
			return(-1);
		}
		
		if (months[comp[1]]<comp[0])
		{
			 
			if ((comp[1]==2)&&(comp[0]==29))
			{  
				if ( (comp[2]%400==0) || ( (comp[2]%4==0) && (comp[2]%100!=0) ) ) //->disekto
				{
					return(comp[0] + sep + comp[1] + sep + comp[2]);
				}
			}
			show_error(id);
			alert(message);
			return(-1);
		}
		if (comp[2].length!=4){
			show_error(id);
			alert(message);
			return(-1);
		}
		if ((comp[2]<2008)||(comp[2]>2020)){
			show_error(id);
			alert("Year is off limits: 2009 to 2030");
			return(-1);
		}
		
		return(comp[0] + sep + comp[1] + sep + comp[2] );
		
	}
}


function get_dates_in_between (from, to)
{
	var dates_str = "";
}

function sub_dates(date1_id, date2_id)
{
	var sep = "/";
	
	var date1 = document.getElementById(date1_id).value;
	var date2 = document.getElementById(date2_id).value;
	
	var date1_arr = date1.split(sep);
	var date2_arr = date2.split(sep);
	
	var dt1 = new Date(date1_arr[2], date1_arr[1]-1, date1_arr[0]);	//Month is 0-11 in JavaScript
	var dt2 = new Date(date2_arr[2], date2_arr[1]-1, date2_arr[0]);	//Month is 0-11 in JavaScript
	
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24
	
	var res = Math.ceil( (dt2.getTime()-dt1.getTime())/(one_day) );
	
	res = res+1;
		
	return (res);
	/*
	//Set the two dates
	today=new Date()
	var christmas=new Date(today.getFullYear(), 11, 25) //Month is 0-11 in JavaScript
	if (today.getMonth()==11 && today.getDate()>25) //if Christmas has passed already
	christmas.setFullYear(christmas.getFullYear()+1) //calculate next year's Christmas
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24
	
	//Calculate difference btw the two dates, and convert to days
	document.write(Math.ceil((christmas.getTime()-today.getTime())/(one_day))+
	" days left until Christmas!")*
}*/