﻿function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function mosadcheck() 
{
	var checkmosad = document.getElementsByName("inst_id[]");
	var num_mosad = checkmosad.length;
	var mosadvalid=false;
	for ( i=0; i < num_mosad; i++ )
	{
		if ( checkmosad[i].checked == true )
		{mosadvalid=true;}
	}
	if (mosadvalid==true) {return true} 
	else {return false}

}
	
function validate3(frm) {
    //
    // Check the Email field to see if any characters were entered
    //
    if (frm.email.value.length == 0 || frm.lname.value.length == 0 || frm.fname.value.length == 0|| frm.city.value.length == 0 || frm.num_phone_global.value.length!=7 || (echeck(frm.email.value)==false))
    {
        alert("אנא מלאו את כל שדות החובה.");
        frm.fname.focus();
        return false;
    }
	
	if (mosadcheck()!=true)
		{
		 alert("מלאו מוסדות.")
        frm.fname.focus()
		return false;
		
		}
	document.forms["frm"].submit();
document.forms["frm"].submit.disabled=true;
	
	

}
function checkAllFields(ref)
{
var chkAll = document.getElementById("checkAll");
var checks = document.getElementsByName("inst_id[]");
var boxLength = checks.length;
var allChecked = false;
var totalChecked = 0;
	if ( ref == 1 )
	{
		if ( chkAll.checked == true )
		{
			for ( i=0; i < boxLength; i++ )
			checks[i].checked = true;
		}
		else
		{
			for ( i=0; i < boxLength; i++ )
			checks[i].checked = false;
		}
	}
	else
	{
		for ( i=0; i < boxLength; i++ )
		{
			if ( checks[i].checked == true )
			{
			allChecked = true;
			continue;
			}
			else
			{
			allChecked = false;
			break;
			}
		}
		if ( allChecked == true )
		chkAll.checked = true;
		else
		chkAll.checked = false;
	}
	for ( j=0; j < boxLength; j++ )
	{
		if ( checks[j].checked == true )
		totalChecked++;
	}
}

function echeckside(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
function mosadcheckside() 
{
	var checkmosad = document.getElementsByName("inst_id1[]");
	var num_mosad = checkmosad.length;
	var mosadvalidside=false;
	for ( i=0; i < num_mosad; i++ )
	{
		if ( checkmosad[i].checked == true )
		{mosadvalidside=true;}
	}
	if (mosadvalidside==true) {return true} 
	else {return false}

}
function validate2(frm1) {
    //
    // Check the Email field to see if any characters were entered
    //
    if (frm1.email1.value.length == 0 || frm1.lname1.value.length == 0 || frm1.fname1.value.length == 0|| frm1.city1.value.length == 0 || frm1.num_phone_global1.value.length!=7 || (echeckside(frm1.email1.value)==false))
    {
        alert("אנא מלא את כל שדות החובה.")
        frm1.email1.focus()
		return false;
    }
	if (mosadcheckside()!=true)
		{
		 alert("מלאו מוסדות.")
        frm1.fname1.focus()
		return false;
		
		}
document.forms["frm1"].submit();
document.forms["frm1"].submit.disabled=true;

}
function checkAllFieldsside(ref)
{
var chkAll1 = document.getElementById("checkAll1");
var checks1 = document.getElementsByName("inst_id1[]");
var boxLength1 = checks1.length;
var allChecked1 = false;
var totalChecked1 = 0;
	if ( ref == 1 )
	{
		if ( chkAll1.checked == true )
		{
			for ( i=0; i < boxLength1; i++ )
			checks1[i].checked = true;
		}
		else
		{
			for ( i=0; i < boxLength1; i++ )
			checks1[i].checked = false;
		}
	}
	else
	{
		for ( i=0; i < boxLength1; i++ )
		{
			if ( checks1[i].checked == true )
			{
			allChecked1 = true;
			continue;
			}
			else
			{
			allChecked1 = false;
			break;
			}
		}
		if ( allChecked1 == true )
		chkAll1.checked = true;
		else
		chkAll1.checked = false;
	}
	for ( j=0; j < boxLength1; j++ )
	{
		if ( checks1[j].checked == true )
		totalChecked1++;
	}
}

