/*
	javascript development
	============================
	website 	: 	Yiannis art
	date 		: 	12-10-2009		
	author 		: 	mayra metaxa / developer
	company		: 	mayra
	url			:	

*/

function clear_class(nm)
{
	for (i=0; i<nm; i++)
	{
		if (document.getElementById('thumb_'+i))
			document.getElementById('thumb_'+i).className = "gal_thumb";
	}
}


var num_show_gal = 6;

function prev_next_gal(action) 
{										
	var nm = document.getElementById('nm').value;

	if (action==1)
		from_gal = from_gal+num_show_gal;
	else
		from_gal = from_gal-num_show_gal;
	
	if (from_gal>nm)
		from_gal = 0;
			
	if (from_gal<0)
		from_gal = 0;

	var to  = from_gal+num_show_gal;
	if (to>nm)
		to = nm;
		
	for (i=0; i<nm; i++)			
		document.getElementById('thumb_'+i).style.display= "none";
	
	for (j=from_gal; j<to; j++)
		document.getElementById('thumb_'+j).style.display= "inline";

}



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

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

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


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



var speed = 13;
var timer = 0;

function changeOpac(opacity, id) 
{
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function opac(visible, divid)
{
	if (visible == 1)
	{
		//fade in
		changeOpac(6, divid);
		document.getElementById(divid).style.display = "block";
		
		for(i = 10; i <= 100; i+=2) 
		{
			setTimeout("changeOpac(" + i + ",'"+ divid +"')",(timer * speed));
			timer++;
		}
		
		clearTimeout(timer);
	}
	else
	{	
		//fade out
		changeOpac(95, divid);
		
		for(i = 90; i >= 0; i-=5) 
		{
			setTimeout("changeOpac(" + i + ",'"+ divid +"')",(timer * speed));
			timer++;
		}
		
		clearTimeout(timer);
		
		setTimeout("displaynone('"+divid+"')",1000);
		
		clearTimeout(timer);
		
	}
}


function displaynone(divid)
{
	document.getElementById(divid).style.display = "none";
}

function display_block(divid)
{
	document.getElementById(divid).style.display = "block";
}


/* =============================== */

/*
function right(e) 
{
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
	{
		alert("1");
		return false;
	}
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) 
	{
		alert("Sorry, you do not have permission to right click.");
		return false;
	}
	else
		alert("mpe");
		return false;
}

document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
*/



function clickIE4()
{
	if (event.button==2)
		return false;
}

function clickNS4(e)
{
	if (document.layers||document.getElementById&&!document.all)
	{
		if (e.which==2||e.which==3)
			return false;
	}
	
}

if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById)
{
	document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false");
