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

*/


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

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.background="#ffffff";
	}
}


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 login_check()
{
	if ( (document.getElementById('log_username').value == "Username") || (document.getElementById('log_pwd').value == "Password") )
	{
		alert("You must fill in your username and password in order to login.");
		return false;
	}

	document.getElementById('form_login').submit();
}

function login_key_pressed(e)
{
	var numCharCode;
   
   // get event if not passed
   if (!e) var e = window.event;

   // get character code of key pressed
   if (e.keyCode) 
   		numCharCode = e.keyCode;
   else if (e.which) 
   		numCharCode = e.which;
   
   if ( numCharCode == 13 )
   		login_check('form_login');
}


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_search(defvalue)
{	
	//check mandatory fields

	if ( (document.getElementById('skeyword').value == "") || (document.getElementById('skeyword').value == defvalue) )
	{
		show_error('skeyword');
		alert ("You must type a keyword.");
		return false;
	}			
	
	document.getElementById('quickSearchForm').submit();
}


function check_newsletter(defvalue_name, defvalue_email)
{	
	//check mandatory fields

	if ( (document.getElementById('newsletter_name').value == "") || (document.getElementById('newsletter_name').value == defvalue_name) )
	{
		show_error('newsletter_name');
		alert ("You must type your name.");
		return false;
	}	
	if ( (document.getElementById('newsletter_mail').value == "") || (document.getElementById('newsletter_mail').value == defvalue_email) )
	{
		show_error('newsletter_mail');
		alert ("You must type your E-mail.");
		return false;
	}
	if (!checkEmail('newsletter_mail'))
	{
		show_error('newsletter_mail');
		alert ("Your email address is not valid.");
		return false;
	}
	
	document.getElementById('newsletform').submit();
}


function check_form_pwd(formid, whichform, mandatory_fields, pwdfields)
{
	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 (!checkEmail('email'))
	{
		show_error('email');
		alert ("Your email address is not valid.");
		return false;
	}
	
	//check numeric fields
	if (pwdfields != "")
	{
		var pwds = pwdfields.split(",");
		
		if (document.getElementById(pwds[0]).value != document.getElementById(pwds[1]).value )
		{			
			show_error(pwds[0]);
			show_error(pwds[1]);
			alert ("The passwords you typed do not match!");
			return false;
		}
		
	}
	
	document.getElementById(formid).submit();
}


function find_key_pressed(e)
{
	var numCharCode;
   
   // get event if not passed
   if (!e) var e = window.event;

   // get character code of key pressed
   if (e.keyCode) 
   		numCharCode = e.keyCode;
   else if (e.which) 
   		numCharCode = e.which;
   
   if ( numCharCode == 13 )
   		return true;
	else 
		return false;
}



/*
function make_cols_equal(numofcols)
{	
	var h;	
	var maxheight = 100;
		
	for (i=1;i<=numofcols;i++)
	{
		h = document.getElementById('coldiv_'+i).offsetHeight;

		if (h > maxheight)
			maxheight = h;
	}
	
	for (i=1;i<=numofcols;i++)
	{
		document.getElementById('coldiv_'+i).style.height = maxheight+"px";	
	}
}*/

function enlarge_leftcol()
{
	if (document.getElementById('coldiv_2'))
	{
		
		var h2 = document.getElementById('coldiv_2').offsetHeight;
		
		var h1 = document.getElementById('coldiv_1').offsetHeight;
		
		h1 = h2 + h1 - 133;
		//alert (h1);
	
		document.getElementById('coldiv_1').style.height = h1+"px";	
		
	}
}