//----------------בדיקת כתובת מייל-----------------------

function checkMail(emailVal)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(emailVal)) 
	return true;
	return false;
}

//------------------בדיקת מספרים------------------------

function check_digits(phoneVal)
{
	var filter  = /[^0-9]/;
	if (filter.test(phoneVal)) 
	return false;
	return true;
}


//------------------בדיקת הטופס------------------------

function check_form()
{
the_phone = document.the_form.phone.value
the_email = document.the_form.email.value
the_name = document.the_form.f_name.value
the_city = document.the_form.town.value

errors = 0

	if (the_name=='')
	{
	document.the_form.f_name.style.color='red';
	document.the_form.f_name.value='הכנס שם';
	document.getElementById('f_name').style.color='yellow';
	document.getElementById('form_name').style.display='inline';
	errors++
	}
	if (the_city=='')
	{
	document.the_form.town.style.color='red';
	document.the_form.town.value='הכנס עיר';
	document.getElementById('city').style.color='yellow';
	document.getElementById('form_city').style.display='inline';
	errors++
	}
	if(checkMail(the_email) == false)
	{
	document.the_form.email.style.color='red';
	document.the_form.email.value='כתובת מייל לא חוקית';
	document.getElementById('mail').style.color='yellow';
	document.getElementById('form_mail').style.display='inline';
	errors++
	}
	if(check_digits(the_phone) == false)
	{
	document.the_form.phone.style.color='red';
	document.the_form.phone.value='מספרים בלבד';
	document.getElementById('phone').style.color='yellow';
	document.getElementById('form_phone').style.display='inline';
	errors++
	}
	if(the_phone == '')
	{
	document.the_form.phone.style.color='red';
	document.the_form.phone.value='הכנס מספר טלפון';
	document.getElementById('phone').style.color='yellow';
	document.getElementById('form_phone').style.display='inline';
	errors++
	}
	if(errors==0)
	{
	set_cookie ( 'x_cookie', 1, 3000, 12, 12);
	document.the_form.submit();
	}
}


function clears(the_object)
{
if (the_object.value=='מספרים בלבד' || the_object.value=='כתובת מייל לא חוקית' || the_object.value=='הכנס שם' || the_object.value=='הכנס עיר' || the_object.value=='הכנס מספר טלפון')
the_object.value='';
}


//------------write a cookie--------------

function set_cookie ( name, value, exp_y, exp_m, exp_d)
{
	var cookie_string = name + "=" + escape ( value );

	if ( exp_y )
	{
	var expires = new Date ( exp_y, exp_m, exp_d );
	//alert(expires.toGMTString());
	cookie_string += "; expires=" + expires.toGMTString();
	}

	document.cookie = cookie_string;
	
}

//------------get a cookie--------------

function get_cookie ( cookie_name ) 
{ 
   var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' ); 
   if ( results ) 
   return ( unescape ( results[2] ) ); 
   else 
   return 'no_cookie'; 
}

function bring_x()
{
x = get_cookie ( 'x_cookie' )
	if (x==1)
	{
	document.getElementById('ok').style.display='block';
	}
	if (x==0)
	{
	document.getElementById('ok').style.display='none';
	}
set_cookie ( 'x_cookie', 0, 3000, 12, 12);
}


