//function validate extension
function validateExt(formName,fldName, extArray)
{
	var file = eval('document.'+ formName + '.' + fldName + '.value');
	allowSubmit = false ;
	
	while (file.indexOf("\\") != -1)
	{
		file = file.slice(file.indexOf("\\") + 1);		
	}		
	fileRev=strrev(file) 		
	extRev = fileRev.slice(0,fileRev.indexOf(".") ).toLowerCase();
	ext = strrev(extRev);
	
	
	for (var i = 0; i < extArray.length; i++) {
		
		if (extArray[i] == ext) {allowSubmit = true; break; }
	}
	if (allowSubmit){					
		return true;
		}
	else
		{
		if (file.length > 0 ){				
			alert("Only File Types  \'" + (extArray.join(",")) + "\'  are accepted.");								
			goBack("document."+formName+"."+fldName+".focus()");	
		}
			return  false;	
	}
}

function strrev(str) {
   if (!str) return '';
   var revstr='';
   for (i = str.length-1; i>=0; i--)
       revstr+=str.charAt(i)
   return revstr;
}		
//function validateData
function validateData(formName,fldName, fldLblValue,validateType)
{
	var fldValue = eval('document.'+ formName + '.' + fldName + '.value');
	type = validateType.toUpperCase();
	if (fldValue != "")
	{
		if (type == "INTEGER")
		{
			if(!isInteger(fldValue))
			{
				alert (fldLblValue + ' only accepts digit 0123456789');
				goBack("document."+formName+"."+fldName+".focus()");
				return false;
			}
		}
		else if (type == "NUMERIC")
		{
			if(!isNumeric(fldValue))
			{
				alert (fldLblValue + ' only accepts these characters +-0123456789.');
				goBack("document."+formName+"."+fldName+".focus()");
				return false;
			}
		}
		else if (type == "STRING")
		{
			if(!isGoodChar(fldValue))
			{
				alert (fldLblValue +  " can not have the following characters: #, %, &, <, >");
				goBack("document."+formName+"."+fldName+".focus()");
				return false;
			}
		}
		
		
	}
}		
function CustomValidator_Integer(sender, args)
{
	args.IsValid = isInteger(args.Value);	
}
function CustomValidator_Numeric(sender, args)
{
	args.IsValid = isNumeric(args.Value);	
}
function CustomValidator_String(sender, args)
{
	args.IsValid = isGoodChar(args.Value);	
}

function goBack(fld)
{
	eval(fld);
}

//function for checking invalid integer string
function isGoodChar(fldValue)
{
	i = 0;
	if (fldValue.length > 0){
		//alert ( 'length ' + objValue.length);
		do{			
			kcode = fldValue.charCodeAt(i);
			//alert ('while is true ' + i);
			if ((kcode == 35)||(kcode == 37)||(kcode == 38)||(kcode == 60)||(kcode == 62)){
				i = fldValue.length;				
				return false;		
			}
			else{
				i = i + 1;
			}
			//alert (i + ' and ' + objValue.length)
		} while (i < fldValue.length + 1);
	}
	return true;
}

//function for checking all NUMERIC values
function isNumeric(fldValue)
{
	var ValidChars = "0123456789.-+";
   var IsNumber=true;
   var Char; 
   var numberOfDot = 0;
   var numberOfSign = 0; 
   for (i = 0; i < fldValue.length && IsNumber == true; i++) 
      { 
		Char = fldValue.charAt(i); 
      
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
        }
         
		if (Char == ".")
			numberOfDot = numberOfDot + 1;
      
		if (numberOfDot > 1)
			IsNumber = false;
			
		if ((Char == "-") || (Char == "+"))
			numberOfSign = numberOfSign + 1;
		if (numberOfSign > 1)
			IsNumber = false;
			
		if ( (i > 0) && ((Char == "-") || (Char == "+")))
			IsNumber = false;
			
		
      }
   return IsNumber;


 }
 
//function for checking all integer values
function isInteger(fldValue)
{
	
    var flag=true
    var test = "" + fldValue
    if(test.length<=0)
    {
		return false
    }
    else
	{
		for (var k =0; k < test.length; k++)
		{
		    var c = test.substring(k, k+1);
		    if (isDigit(c) == false)
		        {
					flag=false
		        }
		}
		if(flag == false)		
		{			
			return false
		}
		else
		{
			return true

		}
    }
    return true
 }

 //funtion to check whether the given character is numeric or not.This function is used in
 //isAlldigits() function.


function isDigit(c)
{
var test = "" + c;
if (test == "0" || test == "1" || test == "2" || test == "3" || test == "4"
    || test == "5" || test == "6" || test == "7" || test == "8" || test == "9")
{
	return true;
}
return false;
}
