var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31) ;
var monthEngArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December") ;
var monthHebArray = new Array("ינואר","פברואר","מרץ","אפריל","מאי","יוני","יולי","אוגוסט","ספטמבר","אוקטובר","נובמבר","דצמבר") ;
//***************************************************************************************************************************************************
function getDays(month, year)
{
	if (month == 1)
		return ((year % 4 == 0) && (0 != (year % 100))) || (year % 400 == 0) ? 29 : 28 ;
	else
		return daysInMonth[month] ;
}
//**************************************************************************************************************************************************
function checkMail(str)
{//check if email address is valid
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; //valid
	if (!reg1.test(str) && reg2.test(str))
		return true ;
	return false ;
}
//************************************************************
function isEmpty(str)
{//this function checks if the string is empty
	for (var intloop = 0; intloop < str.length; intloop++)
		if (str.charAt(intloop) !=  " ")
			return false;
		return true ;
}
//**************************************************************************************************
function makeSelect(startValue, finishValue, valueSelected)
{
	var i ;
	var ifSelected = ""
	for (i = startValue; i <= finishValue; i++)
	{
		if (i == parseInt(valueSelected,10))
			ifSelected = "selected"
		document.write("<option value='"+i+"' "+ifSelected+">"+i+"</option>") ;
	ifSelected = ""
	}
}
//**************************************************************************************************
function makeSelectMonth(arr, valueSelected)
{
	var i ;
	var ifSelected = ""
	for (i = 1; i <= arr.length; i++)
	{
		if (i == parseInt(valueSelected,10))
			ifSelected = "selected"
		document.write("<option value='"+i+"' "+ifSelected+">"+arr[i-1]+"</option>") ;
		ifSelected = ""
	}
}
//**************************************************************************************************
function validate(form)
{                            
	if (!form.vote[0].checked && !form.vote[1].checked)
	{
		alert(".\"יש להצביע \"כן\" או \"לא")
		return false ;
	}
	if (isEmpty(form.fname.value))
	{
		alert(".נא להכניס שם פרטי");
		form.fname.focus() ;
		return false ;
	}
	if (isEmpty(form.lname.value))
	{
		alert(".נא להכניס שם משפחה");
		form.lname.focus() ;
		return false ;
	}

	if ((parseInt(form.bday.value,10) == 0) || (parseInt(form.bmonth.value,10) == 0) || (parseInt(form.byear.value,10) == 0))
	{
		alert(".נא להכניס תאריך לידה") ;
		return false ;
	}
	else
		if (getDays(parseInt(form.bmonth.value,10)-1, parseInt(form.byear.value,10) == 0) < parseInt(form.bday.value,10))
		{
			alert(".התאריך שהכנסת הוא לא חוקי") ;
			return false ;
		}
	if (isEmpty(form.address.value))
	{
		alert(".נא להכניס את כתובת");
		form.address.focus() ;
		return false ;
	}
	if (isEmpty(form.town.value))
	{
		alert(".נא להכניס את עיר");
		form.town.focus() ;
		return false ;
	}
	if (form.country.value == "OO")
	{
		alert(".נא להכניס את מדינה");
		form.country.focus() ;
		return false ;
	}
	if (form.country.value == "US")
		if (form.usaState.value == "OO")
		{
			alert(".נא להכניס את מדינה באבה\"ב");
			form.usaState.focus() ;
			return false ;
		}
	if (isEmpty(form.zip.value))
	{
		alert(".נא להכניס את מיקוד");
		form.zip.focus() ;
		return false ;
	}
	if (isEmpty(form.phone1.value))
	{
		alert(".נא להכניס את מספר הטלפון");
		form.phone1.focus() ;
		return false ;
	}	
	if (isEmpty(form.email.value) || !checkMail(form.email.value))
	{
		alert(".נא להכניס כתובת דואר האלקטרוני חוקי");
		form.email.focus() ;
		return false 
	}
	return true ;
}
function validateEng(form)
{                            
	if (!form.vote[0].checked && !form.vote[1].checked)
	{
		alert("Please vote \"yes\" or \"no\"")
		return false ;
	}
	if (isEmpty(form.fname.value))
	{
		alert("Please enter First Name.");
		form.fname.focus() ;
		return false ;
	}
	if (isEmpty(form.lname.value))
	{
		alert("Please enter Last Name.");
		form.lname.focus() ;
		return false ;
	}

	if ((parseInt(form.bday.value,10) == 0) || (parseInt(form.bmonth.value,10) == 0) || (parseInt(form.byear.value,10) == 0))
	{
		alert("Please enetr Birthday Date.") ;
		return false ;
	}
	else
		if (getDays(parseInt(form.bmonth.value,10)-1, parseInt(form.byear.value,10) == 0) < parseInt(form.bday.value,10))
		{
			alert("Birthday Date is incorrect.") ;
			return false ;
		}
	if (isEmpty(form.address.value))
	{
		alert("Please enter Address.");
		form.address.focus() ;
		return false ;
	}
	if (isEmpty(form.town.value))
	{
		alert("Please enter the Town.");
		form.town.focus() ;
		return false ;
	}
	if (form.country.value == "OO")
	{
		alert("Please enter Country.");
		form.country.focus() ;
		return false ;
	}
	if (form.country.value == "US")
		if (form.usaState.value == "OO")
		{
			alert("Please enter the State for USA");
			form.usaState.focus() ;
			return false ;
		}
	if (isEmpty(form.zip.value))
	{
		alert("Please enter Zip Code.");
		form.zip.focus() ;
		return false ;
	}
	if (isEmpty(form.phone1.value))
	{
		alert("PLease enter Phone Number.");
		form.phone1.focus() ;
		return false ;
	}	
	if (isEmpty(form.email.value) || !checkMail(form.email.value))
	{
		alert("Please enter legal email address.");
		form.email.focus() ;
		return false 
	}
	return true ;
}
//********************************************************************************************************
function M_stop() 
{
	document.all.tags("marquee").item(0).stop();
}
function M_start() 
{
	document.all.tags("marquee").item(0).start();
}
//**************************************************************************************************