function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '');
}

function isEmail(email)
{
	if (email.length == 0)
		return false;

	var x = email;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function isNumber(str)
{
	var ValidChars = "0123456789.- ";
	var IsNumber = true;
	var Char;
	for (i = 0 ; i < str.length && IsNumber == true ; i++) 
	{ 
		if (ValidChars.indexOf(str.charAt(i)) == -1) 
			IsNumber = false;
	}
	return IsNumber;
}

function checkContact(frm)
{
	var fullname = trim(frm.name.value);
	var phone = trim(frm.phone.value);
	var email = trim(frm.email.value);
	var comment = trim(frm.comment.value);
	
	var bool = true;
	var strAlert = "";
	if (fullname.length == 0)
	{
		bool = false;
		strAlert += "- חובה להזין שם מלא.\n";
	}
	else if (fullname.length < 2)
	{
		bool = false;
		strAlert += "- שם מלא לא תקין.\n";
	}
	
	if (phone.length == 0)
	{
		bool = false;
		strAlert += "- חובה להזין טלפון/נייד.\n";
	}
	else if (!isNumber(phone))
	{
		bool = false;
		strAlert += "- טלפון/נייד לא תקין.\n";
	}
	
	if (email.length == 0)
	{
		bool = false;
		strAlert += "- חובה להזין דואר אלקטרוני.\n";
	}
	else if (!isEmail(email))
	{
		bool = false;
		strAlert += "- דואר אלקטרוני לא תקין.\n";
	}
	
	if (!bool)
		alert(strAlert);
	
	return bool;
}

function initImage()
{
	for (var i = 0 ; i < scroll.length ; i++)
	{
		tag = scroll[i].getElementsByTagName("li");
		
		for (var j = 0 ; j < tag.length ; j++)
		{
			if (tag[j].style.display == "block")
			{
				tag[j].style.display = "none";
				show = j + 1;

				if (show >= tag.length)
					show = 0;

				tag[show].style.display = "block";

				imgcheck = tag[show].getElementsByTagName("img");
				if (imgcheck.length > 0)
				{
					imageId = "pic" + show;
					image = document.getElementById(imageId);

					setOpacity(image, 0);
					shiftOpacity(imageId,1000);

					image.style.visibility = 'visible';
				}

				break;
			}
		}
	}
}

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 opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function setOpacity(obj, opacity)
{
	opacity = (opacity == 100) ? 99.999 : opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
}