<!--

// FormatNumber (same as vbscript Functio

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - true / false - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

//IsNumeric function Like VBScript function
function IsNumeric(n) 
{   
	return !isNaN(parseFloat(n)) && isFinite(n); 
} 

function validNumber(FormObj,NumberField)
{
	n=document.forms[FormObj][NumberField].value
	if(!IsNumeric(n))
	{
		ShowError(NumberField,"יש להקליד ספרות בלבד",false);
		document.Forms[FormObj][NumberField].value=FormatNumber(n,0,false,false,false);
	}
	else
		ShowError(NumberField,"",true);
}

//function to display the error on the page
function ShowError(FieldName,ErrDescription,ClearErr)
{
    //alert(FieldName);
	if(ClearErr)
    {
        //alert("true");
		document.getElementById("Err" + FieldName).innerHTML = "";
        document.getElementById("Err" + FieldName).display="none";
        return;
    }
	else
	{
        
		document.getElementById("Err" + FieldName).innerHTML = "* " + ErrDescription;
		document.getElementById("Err" + FieldName).style.color = "Red";
        document.getElementById("Err" + FieldName).display="";
        document.getElementById(FieldName).focus();
        return;
	}
}
//Validation - Form Check
function checkGlobalForm(FormObj,FormFlds,Rems) 
{
	var bFlag = true;
	var RemArray = Rems.split(",");
    var reg = new RegExp(/^[(a-zA-Z)||(\u0591-\u05F4)]+$/);
	var formFld = FormFlds.split(",");
    //alert(formFld.length);
    var i=0;
	for (i = 0; i < formFld.length; i++) 
    {
        var sf = formFld[i];
        var sval = document.forms[FormObj][sf].value;
       
        if((sval == null || sval ==""))
        {
            ShowError(formFld[i],RemArray[i],false);
            bFlag=false;
            return false;
        }
	    else if (!reg.test(sval.value)) 
        {
            alert(reg.test(sval.value));
            document.forms[FormObj][formFld[i]].value="";
            document.forms[FormObj][formFld[i]].focus();
            ShowError(formFld[i],RemArray[i],false);
            bFlag=false;
            return false;
            break;
        }
    }
   
	if (bFlag)
		document.forms[FormObj].submit();
        
}
//Validation - Ilegal Chars
function validChar(FormObj,StringField, Is_Requierd) 
{	
    var reg = new RegExp(/^[(a-zA-Z)||(\u0591-\u05F4)]+$/);
	var s = document.forms[FormObj][StringField].value;
	if((s == null || s=="") && Is_Requierd)
            ShowError(StringField,Must_Field,false);
	else if (!reg.test(s.value))
            ShowError(StringField,cantUseThisCharHere,false);
    else 
        ShowError(StringField,Must_Field,true);  
}

//-->
