﻿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(name)
	{
	if(is_empty(name.value))
		{
		alert("נא לכתוב שם מלא")
		name.focus()
		return false
		}
	
	return true
	}
	
	
	
	
	function check_phone(phone)
	{
		
	if (is_num(phone.value)==false )
	  {
		alert("  נא להזין אזור חיוג ומספר טלפון - מספרים בלבד - ללא מקף")
		phone.select()
		return false
		}
		
	if(is_empty(phone.value))
		{
		alert("נא להזין מספר טלפון")
		phone.select()
		return false
		}
		
		return true
	}
	
	
	function check_email(str)
	{
	if(is_empty(str.value))
		{
		alert("נא למלא כתובת דואר אלקטרוני")
		str.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 send_form()
	
	{
		if( check_name(document.formi.name))
		if( check_email(document.formi.email))
		if( check_phone(document.formi.phone))
			{
			if (document.formi.confirm_privacy_policy.checked==true)
			  { 
			   
			   if (document.formi.confirm_mem_newsletter.checked==true) 
			    {
				
					document.formi._recipients.value=document.dummy.CompanyEmail.value
					document.formi._redirect.value ="http://www.mishtalmim.co.il/mis_thanks_mosad2.asp?name=" + document.formi.name.value + "&phone=" + document.formi.phone.value + "&email=" + document.formi.email.value + "&company=" + document.dummy.company.value + "&CompanyName=" + document.dummy.CompanyName.value + "&Interest-in=" + document.dummy.interest.value + "&mess=" + document.formi.mess.value  + "&Occupation=" + document.formi.Occupation.value + "&confirm_mem_newsletter=on" 
			}
		 if (document.formi.confirm_mem_newsletter.checked==false)
			{   
			   document.formi._recipients.value=document.dummy.CompanyEmail.value
					document.formi._redirect.value ="http://www.mishtalmim.co.il/mis_thanks_mosad2.asp?name=" + document.formi.name.value + "&phone=" + document.formi.phone.value + "&email=" + document.formi.email.value + "&company=" + document.dummy.company.value + "&CompanyName=" + document.dummy.CompanyName.value + "&Interest-in=" + document.dummy.interest.value + "&mess=" + document.formi.mess.value  + "&Occupation=" + document.formi.Occupation.value + "&confirm_mem_newsletter=off" 
			}
			  
					_gaq.push(['_trackEvent', 'course_form', 'submit', 'form', 1]);
					document.formi.submit()
				}
			
			
			if (document.formi.confirm_privacy_policy.checked==false)
  			alert("אנא סמנו את תיבת האישור ושלחו שנית")
			
			}
	}




	function check_form()
	
	{
		if( check_name(document.formi.name))
			if( check_phone(document.formi.phone))
			if( check_email(document.formi.email))
				
					{
					if (document.formi.confirm_privacy_policy.checked==true)
						{
						 if (document.formi.confirm_mem_newsletter.checked==true) 
			    {
				
					document.formi._recipients.value=document.dummy.CompanyEmail.value
					document.formi._redirect.value ="http://www.mishtalmim.co.il/mis_thanks_mosad2.asp?name=" + document.formi.name.value + "&phone=" + document.formi.phone.value + "&email=" + document.formi.email.value + "&company=" + document.dummy.company.value + "&CompanyName=" + document.dummy.CompanyName.value + "&Interest-in=" + document.dummy.interest.value + "&mess=" + document.formi.mess.value  + "&Occupation=" + document.formi.Occupation.value + "&confirm_mem_newsletter=on" 
			}
		 if (document.formi.confirm_mem_newsletter.checked==false)
			{   
			   document.formi._recipients.value=document.dummy.CompanyEmail.value
					document.formi._redirect.value ="http://www.mishtalmim.co.il/mis_thanks_mosad2.asp?name=" + document.formi.name.value + "&phone=" + document.formi.phone.value + "&email=" + document.formi.email.value + "&company=" + document.dummy.company.value + "&CompanyName=" + document.dummy.CompanyName.value + "&Interest-in=" + document.dummy.interest.value + "&mess=" + document.formi.mess.value  + "&Occupation=" + document.formi.Occupation.value + "&confirm_mem_newsletter=off" 
			}
						
						_gaq.push(['_trackEvent', 'course_form', 'submit', 'form', 1]);
						document.formi.submit()

		     				}
						if (document.formi.confirm_privacy_policy.checked==false)
  						alert("אנא סמנו את תיבת האישור ושלחו שנית")
					}
		
			
		
	}


