/*
	javascript development
	============================
	website 	: 	www.furdeco.gr/
	date 		: 	22-10-2008		
	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;
}


function openclose_block(id, prosimo, numofblocks)
{	
	
	if (document.getElementById(id).style.display == "none")
	{
		document.getElementById(id).style.display = "block";
		document.getElementById(prosimo).innerHTML = "-";
	}
	else
	{
		document.getElementById(id).style.display = "none";
		document.getElementById(prosimo).innerHTML = "+";
	}
	
	//close all other blocks
	if (numofblocks>1)
	{
		for (i=1;i<=numofblocks;i++)
		{
			if ('block'+i != id)
			{
				document.getElementById('block'+i).style.display = "none";
				document.getElementById('prosimo'+i).innerHTML = "+";
			}
		}
	}
}

function show_paragraph(id, total)
{
	for (i=1;i<=total;i++)
	{
		document.getElementById('par'+i).style.display = "none";
		document.getElementById('ptitle'+i).className = "";
	}
	
	document.getElementById('par'+id).style.display = "block";
	document.getElementById('par'+id).style.padding = "0 0 10px 8px";
	document.getElementById('ptitle'+id).className = "aloc";
}

function highlight_productrow(id)
{
	document.getElementById('row'+id).style.background = "#ed1555";
	document.getElementById('h3_'+id).style.color = "#ffffff";	
}
function de_highlight_productrow(id)
{
	document.getElementById('row'+id).style.background = "none";
	document.getElementById('h3_'+id).style.color = "#ed1555";
}

function highlight_mediarow(id)
{
	document.getElementById('row'+id).style.background = "#ed1555";
	document.getElementById('h3_'+id).style.color = "#ffffff";
	document.getElementById('download_'+id).style.color = "#ffffff";	
}
function de_highlight_mediarow(id)
{
	document.getElementById('row'+id).style.background = "none";
	document.getElementById('h3_'+id).style.color = "#ed1555";
	document.getElementById('download_'+id).style.color = "#ed1555";
}


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

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 show_error(id)
{
	document.getElementById(id).style.background="#c0c0c0";
}

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].type != "label") && (document.forms[which].elements[i].id!="fieldset") )
			document.forms[which].elements[i].style.background="#FFFFFF";
	}
}

function check_form(formid, whichform, mandatory_fields, numericfields)
{
	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;
		}
	}
	
	var emailid = 'email';
	if (formid == 'newsletform')
		emailid = 'newsemail';

	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_noemail(formid, whichform, mandatory_fields, numericfields)
{
	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;
		}
	}
		
	//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_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 don't match!");
			return false;
		}
		
	}
	
	document.getElementById(formid).submit();
}


function login_check()
{
	if ( (document.getElementById('login_username').value == "Username") || (document.getElementById('login_password').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 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 )
   	check_search();
}*/