﻿// JScript File

function checkRequired(theForm, idTd ,textAlert)
{
    if (theForm !=''&&spaceCheck(theForm)!=true)
    {
        document.all[idTd].innerHTML="";
        return true;
    }
    else
    {
        document.all[idTd].innerHTML=textAlert;
        return false;
    }
}

function checkLength(theForm, theLength, idTd ,textAlert)
{
    if (theForm.length > theLength)
    {
        document.all[idTd].innerHTML=textAlert;
        return false;
    }
    else
    {
        document.all[idTd].innerHTML="";
        return true;
    }
}

function checkNum(theForm,idTd)
{
	if(isNaN(theForm.value)&&spaceCheck(theForm.value)!=true)
	{	
		theForm.value=1;
		document.all(""+idTd+"").innerHTML="<strong>הכנס ערך מספרי</strong>";
		theForm.focus();
		return false;
	}
	else if(spaceCheck(theForm.value)==true)
	{
		theForm.value=1;
		document.all(""+idTd+"").innerHTML="<strong>הכנס ערך מספרי</strong>";
		theForm.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function checkNum2(theForm, idTd, textAlert)
{
	if(isNaN(theForm)&&spaceCheck(theForm)!=true)
	{	
		document.all[idTd].innerHTML=textAlert;
		return false;
	}
	else if(spaceCheck(theForm)==true)
	{
		document.all[idTd].innerHTML=textAlert;
		return false;
	}
	else
	{
	    document.all[idTd].innerHTML="";
		return true;
	}
}

function checkSelectList(theForm, idTd, badValue, textAlert)
{
    if(theForm.options[theForm.selectedIndex].value==badValue)
    {
        document.all[idTd].innerHTML=textAlert;
        return false;
    }
    else
    {
        document.all[idTd].innerHTML="";
        return true;
    }
}

function checkCheckbox(theForm, idTd, textAlert)
{
    if(theForm.checked != true)
    {
        document.all[idTd].innerHTML=textAlert;
        return false;
    }
    else
    {
        document.all[idTd].innerHTML="";
        return true;
    }
}


function spaceCheck(theStr)
{
	str = theStr;
	strarray = str.split(" ");
	if(str.length==strarray.length-1){return theStr=true;}
}
function emailCheck(Email)
{
	if (Email.length >0)
	{
		var i   = Email.indexOf("@")
		var j   = Email.indexOf(".",i)
		var k   = Email.indexOf(",")
		var kk  = Email.indexOf(" ")
		var aa  = Email.indexOf("'")
		var jj  = Email.lastIndexOf(".") + 1
		var len = Email.length

		if ((i > 0) && (j > (i + 1)) && (k == -1) && (kk == -1) && (aa == -1) && (len - jj >= 2) && (len - jj <= 3)) 
		{
		 	return true;
		}
        else
		{
        	return false; 
		}	
	}
	else
	{
		 return false;
	}
}

var slicer1;
function makeValue(theForm,textLength,theCheck,urlPic)
{
	if (theForm.value.length > textLength)
	{
		document.all[theCheck].innerHTML="הטקסט ערוך מידי<img src="+urlPic+" width=16 height=15 border=0>";
		slicer1=theForm.value.slice(0,textLength-1)
		theForm.value = slicer1;
		theForm.focus();
		return false;
	}
	else
	{
		document.all[theCheck].innerHTML="";
	}
}

