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

*/


function showhide_intro(action) 
{		
	if (action == 1)	//html
	{
		$("#html").css("visibility","visible");
		$('#bg_image').show();
		$('#container').show();
		$("#jsintro").hide();
		
		document.body.style.background = "#332c1e";
		
		document.location.href = "#nointro";
		//scroller.init();
		
		
		/*
		$("#jsintro").show();
					$('#container').hide();
					$('#bg_image').hide();
		*/
		
	}
	/*else if (action == 2)	//intro
	{
		document.getElementById('container').style.display = "none";
		document.getElementById('gallerybg').style.display = "none";
		document.getElementById('fullscreenintro').style.display = "block";
	}*/
}

/**/


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


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

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

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


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




/* ============================================ toggle height =========================================== */
  

var minheight=66;
var maxheight=200;

var event_div_id = "menu";


function change_height(height, id)
{
	document.getElementById(id).style.height = height+"px";
}


function change_height_open(height, id, whole)
{
	document.getElementById(id).style.height = height+"px";
	
	var innerheight = whole - 15;
		
	document.getElementById('menu_1').style.display = "none";	//content_inner
	document.getElementById('menu_2').style.display = "block";	
}



function toggle_in() 
{			
	var id = event_div_id;
	
	var speed = 1;	//Math.round(110 / 100);
	var timer = 0;	
	var whole = maxheight;
	
	if (document.getElementById(id).offsetHeight == maxheight)
	{				
		//make small - toggle in: ------------- 
		document.getElementById('menu_2').style.display = "none";	//content_inner
		document.getElementById('menu_1').style.display = "block";
		
		document.getElementById('hide_menu_centered').style.visibility = "hidden";
		
		for(i = whole; i >= minheight; i--) 
		{
			setTimeout("change_height(" + i + ",'"+id+"')",(timer * speed));
			timer++;
		}
		
		document.getElementById('menu').className = "menu";		
	}

}



function toggle_out() 
{
	var id = event_div_id;
	
	var speed = 1;	//Math.round(110 / 100);
	var timer = 0;
	
	var whole = maxheight;	
	
	if (document.getElementById(id).offsetHeight == minheight)	
	{
		//toggle out: ---------------						
		for(i = minheight; i <= whole; i++) 
		{
			setTimeout("change_height_open(" + i + ",'"+id+"', "+maxheight+")",(timer * speed));
			timer++;
		}		
		
		document.getElementById('menu').className = "menu_open";
		
		//document.getElementById('hide_menu_centered').style.display = "block";
		document.getElementById('hide_menu_centered').style.visibility = "visible";
	}
	
}


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

/**/
function window_width() 
{
	  var myWidth = 0;
	  if( typeof( window.innerWidth ) == 'number' ) 
	  {
		//Non-IE
		myWidth = window.innerWidth;
	  } 
	  else if ( (document.documentElement) && (document.documentElement.clientWidth) ) 
	  {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	  } 
	  else if( (document.body) && (document.body.clientWidth) ) 
	  {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	  }	  	  

	  return(myWidth);
}


function window_height()
{
	 var myHeight = 0;
	  if( typeof( window.innerHeight ) == 'number' ) 
	  {
		//Non-IE
		myHeight = window.innerHeight;
	  } 
	  else if ( (document.documentElement) && (document.documentElement.clientHeight) ) 
	  {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight+17;
		
		if (document.getElementById('flashholderdiv_flash'))
			myHeight = myHeight-17;
	  } 
	  else if( document.body && (document.body.clientHeight) ) 
	  {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	  }
	  
	  return(myHeight);
}

/*
function resize_bg()
{
	var imgid = 'bgimage';
	
	if (document.getElementById(imgid))
	{
		var browserheight = window_height();
		var browserwidth = window_width();
		
		if (parseInt(navigator.appVersion)>3) 
		{
			if (navigator.appName.indexOf("Microsoft")!=-1) 
			{
				browserheight = browserheight+14;
			}
		}
	
		document.getElementById(imgid).style.height = browserheight+"px";
		document.getElementById(imgid).style.width = browserwidth+"px";
	
	}
}*/


/* == 


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 browserwidth = window_width();
	var browserheight = window_height();
	
	var flash_height = browserheight - 320 - 26 - 61;	//-content -footer -(menu closed-1)
	var gallery_height = browserheight - 55 - 26 - 61;	//content_small- -footer -(menu closed-1)
	
	if (document.getElementById('bg_image'))
	{				
		document.getElementById('bg_image').style.width = browserwidth+"px";
		document.getElementById('bg_image').style.height = browserheight+"px";
	}
	
	if (document.getElementById('flashholderdiv'))
	{				
		document.getElementById('flashholderdiv').style.width = browserwidth+"px";
		document.getElementById('flashholderdiv').style.height = flash_height+"px";
	}
	
	if (document.getElementById('resize_wide_img'))
	{				
		document.getElementById('resize_wide_img').style.width = browserwidth+"px";
		document.getElementById('resize_wide_img').style.height = flash_height+"px";
	}
	
	if (document.getElementById('flashholderdiv_flash'))
	{				
		document.getElementById('flashholderdiv_flash').style.width = browserwidth+"px";
		document.getElementById('flashholderdiv_flash').style.height = flash_height+"px";
	}
	
	/**/
	
	if (document.getElementById('flashholder_gallery'))
	{				
		document.getElementById('flashholder_gallery').style.width = browserwidth+"px";
		document.getElementById('flashholder_gallery').style.height = gallery_height+"px";
		
	}
	if (document.getElementById('flashholder_gallery_flash'))
	{				
		document.getElementById('flashholder_gallery_flash').style.width = browserwidth+"px";
		document.getElementById('flashholder_gallery_flash').style.height = gallery_height+"px";
	}
	
}

