﻿
var ok=true
function is_char(st)
	{

	for(i=0;i<st.length;i++)
		if((st.charAt(i)<"a" || st.charAt(i)>"z") && (st.charAt(i)!=" "))
			{
			return false
			break
			}
	return true
	}

function is_heb(st)
	{
	for(i=0;i<st.length;i++)
		if((st.charAt(i)<"א" || st.charAt(i)>"ת") && (st.charAt(i)!=" ") && (st.charAt(i)!="-"))
			{
			return false
			break
			}
	return true
	}
	
 
function is_num(st)
	{
	for(i=0;i<st.length;i++)
		if(st.charAt(i)<"0" || st.charAt(i)>"9")
			{
			return false
			break
			}
	return true
	}


function is_empty(st)
	{
	if(st=="")
		return true
	else    return false
	}


function check_name(first, last)
	{
	
	
	if(is_empty(last.value))
		{
		alert("נא לכתוב שם משפחה")
		formi.Last.focus()
		return false
		}
	if(is_empty(first.value))
		{
		alert("נא לכתוב שם פרטי")
		formi.First.focus()
		return false
		}
	if (is_char(first.value)==false && is_heb(first.value)==false)
		{
		alert("השם הפרטי מכיל תווים לא מוכרים")
		first.select()
		return false
		}
	if (is_char(last.value)==false && is_heb(last.value)==false)
		{
		alert("שם המשפחה מכיל תווים לא מוכרים")
		Last.select()
		return false
		}
	return true
	}

function check_job(job)
	{

	if(is_empty(job.value))
		{
		alert("נא לכתוב תפקיד בחברה")
		formi.Job.focus()
		return false
		}

	
	return true
	}



function check_company(company)
	{

	if(is_empty(company.value))
		{
		alert("נא לכתוב שם חברה")
		formi.Company.focus()
		return false
		}

	
	
	return true
	}


function check_email(str)
	{
	if(is_empty(str.value))
		{
		alert("נא לכתוב דואר אלקטרוני")
		formi.Email.focus()
		return false
		}
		
	invalidchars = " /:,;אבגדהוזחטיכלמנסעפצקרשתןףךץ"
				 
		 // be sure there are no illegal chars
			 for (i=0;i<invalidchars.length;i++)
			 {
			 		 badchar = invalidchars.charAt(i)
					 if (str.value.indexOf(badchar,0) > -1 )
					 {	alert("כתובת דואר אלקטרוני לא תקינה")
						str.select()
						return false
						}
				}
						 
		// be sure there is a @		 
			atPos=str.value.indexOf("@",1)
			 if (atPos ==-1)
				 {	alert("כתובת דואר אלקטרוני לא תקינה")
					str.select()
					return false
					}
				 
		//be sure there is only 1 @	 
			 if (str.value.indexOf("@",atPos+1) != -1 )
				{	alert("כתובת דואר אלקטרוני לא תקינה")
					str.select()
					return false
					}
				 
		//is there a period after the @
			 periodPos = str.value.indexOf(".",atPos)
			 if (periodPos == -1 )
				{	alert("כתובת דואר אלקטרוני לא תקינה")
					str.select()
					return false
					}
	
		 //are there at least 2 chars after the period ?
			 if (periodPos + 3 > str.value.length )
				{	alert("כתובת דואר אלקטרוני לא תקינה")
					str.select()
					return false
					}
				
	return true
	}

	function check_phone(phone)
	{
	if(is_empty(phone.value))
		{
		alert("נא להזין מספר טלפון")
		phone.select()
		return false
		}
		
		return true
	}


function check_form_histalmut()
	{

	if( check_name(document.formi.First , document.formi.Last))
	if( check_company(document.formi.company))
	if( check_job(document.formi.job))
	if( check_phone(document.formi.telephone))
	if( check_email(document.formi.Email))
		{


			if (document.formi.confirm_privacy_policy.checked==true)
			 { document.formi.submit()
			   alert("בקשתך התקבלה - נציג פורטל שבתון יצור קשר בהקדם")
			 }
			if (document.formi.confirm_privacy_policy.checked==false)
				alert("אנא סמנו את תיבת ההסכמה לשימוש בפרטים בהתאם למדיניות הפרטיות של הפורטל - ושלחו שוב")
	
	}
}