<!--
// Functions:
// 1. CheckBrowser()
// 2. IsAlpha(strInput)
// 3. IsAlphaNumeric(strInput)
// 4. IsName(strInput)
// 5. IsChecked(obj)
// 6. IsNumeric(strInput)
// 7. IsEmail(strInput)
// 8. GetRadioValue(obj) 
// 9. ObjectExists(strObjName,strFormName)


   function alltrim(s)
   { 
   	  slen = s.length
   	  cnt = 0
      	  for(i=0;i<slen;i++)
   	  {
   	  	if(s.charAt(i) == " ")
   	  	    cnt++
   	  	else
   	  		break
   	  }

   	  if (cnt == slen)
   	  	return ""

   	  s = s.substring(cnt)

	  slen = s.length
   	  cnt = 0
   	  for(i=slen-1;i>=0;i--)
   	  {
   	  	if(s.charAt(i) == " ")
   	  		cnt++
   	  	else
   	  		break
   	  }
	  s = s.substring(0,slen-cnt)

     return s
   }     


function CheckBrowser()
{
    // Check the Browser type & its Version
    // If Netscape & version < 6 OR IE & Version < 5 then redirect the user to some other page
    // which also has the link to Download the lastest versions of Netscape & IE

    strbrowser = navigator.appName;
    strVer = navigator.appVersion;
    if(strbrowser == "Microsoft Internet Explorer")
    {
    	mArr = strVer.split(";")
    	mArr1 = mArr[1].split(" ")
    	
    	strVer = parseFloat(mArr1[2])
    }
    else if(strbrowser == "Netscape")
    {
    	//alert(strVer)
    	mArr = strVer.split(" ")
    	mArr1 = mArr[1].split(" ")
    	
    	strVer = parseFloat(mArr[0])
    	//alert(strVer)
    	//strVer = parseFloat(mArr1[2])
    }
    else
    {
    	strVer = parseFloat(navigator.appVersion);
    }

    if ((strbrowser == "Netscape" && strVer < 6) || (strbrowser == "Microsoft Internet Explorer" && strVer < 5)) 
    {
 	//location.href="Download.asp"
    }
}

function IsAlpha(strInput)
{
  var i
  var c
  if (strInput == "") return false;
  for (i = 0; i < strInput.length; i++)
  {
	c = strInput.charAt(i);
 	if ((c < "a"  || c > "z") && (c < "A" || c > "Z") && (c != " ") && (c != "+") && (c != "-") )
 	{
      return false;
    }
  }
  return true;
}

function IsAlphaNumeric(strInput)
{
  var i
  var c
  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
	if ((c < "a" || c > "z") && (c < "A" || c > "Z") && (c < "0" || c > "9"))
	{
      	   return false;
	}
  }
  return true;
}

function IsName(strInput)
{
  var i
  var c
  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
	if ((c < "a" || c > "z") && (c < "A" || c > "Z") && (c < "0" || c > "9") && (c != " ") && (c != "+") && (c != "-") )
	{
      return false;
	}
  }
  return true;
}
function IsCommaName(strInput)
{
  var i
  var c
  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
	if ((c < "a" || c > "z") && (c < "A" || c > "Z") && (c < "0" || c > "9") && (c != " ") && (c != "+") && (c != "-") && (c != ",") )
	{
      return false;
	}
  }
  return true;
}

//verify if one radio button from a multiple choice radio is checked
function IsCheck(obj) 
{ 
 var i
 for(i=0; i<obj.length; i++)
	if(obj[i].checked) return true;
  return false;
}  

function IsNumeric(strInput)
{
  var i
  var c
  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
    if (c < "0" || c > "9")
	return false;
  }
  return true;
}

function IsFloat(strInput)
{
  var i
  var c
  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
    if ((c < "0" || c > "9") && (c != "."))
	return false;
  }
  return true;
}


function IsCommaNumeric(strInput)
{
  var i
  var c
  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
	if ((c < "0" || c > "9") && (c != ","))
	return false;
  }
  return true;
}

function CheckCommaNumeric(strInput)
{
  var i
  var c
  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
   
	if ((c < "0" || c > "9" || c == ",")&&(c != "."))
	return false;
  }
  return true;
}

//verify if InString is an expression like this xxx.yyy.zzz@ppp.qqq.rrr
function IsEmail( InString )
{ 
  var left, right;
  if ( InString.length == 0 ) return (false);
  for (Count = 0; Count < InString.length; Count++)
  {
    TempChar = InString.substring (Count, Count+1);
	if ("1234567890abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ.@_".indexOf (TempChar, 0) == -1) return (false);
  }
  if ( InString.indexOf('@') < 1 ) return (false); //if it begins with or doesn't have a '@'zzzzzzzzzzzzzzzzz
  if ( InString.lastIndexOf('@') != InString.indexOf('@') ) return (false); //if it has more than one '@'
  
  left  = InString.substring( 0 , InString.indexOf('@') );
  right = InString.substring( InString.indexOf('@') + 1, InString.length );
  if ( (!isDotExpression( left, 0 )) || (!isDotExpression( right , 1 )) ) return (false);
  return true;
}

		function ReplaceChars(entry)
		{
		out = "'"; // replace this
		add = ""; // with this
		temp = "" + entry; // temporary holder

		while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
		}
		return temp;
		}
		
function isDotExpression( InString , NeedsDot )
{
  var dots, index, tmpNeedDot;
  dots = 0;
  for (index = 0; index < InString.length; index++)
  {
    if ( InString.substring( index , index + 1) == "." )
    {
      if ( ( index == 0 ) || ( index == InString.length - 1 ) ) return (false);
      dots++;
      if ( dots > 1 ) tmpNeedDot = 1;
      else tmpNeedDot = 0;
      if ( !isDotExpression( InString.substring( 0 , index ) , tmpNeedDot ) ) return (false);
    }
  }
  if ( ( NeedsDot == 1 ) && ( dots < 1 ) ) return (false);
  if ( InString.length < dots * 2 + 1 ) return (false);
  return (true);
}

//verify if one radio button is checked and returns it's value
function GetRadioValue(obj) 
{ 
 var i;
 if (obj.length == null){
   return obj.value;
 }else{
   for(i=0; i<obj.length; i++) if(obj[i].checked) return obj[i].value;
 }
  return "";
}

function ObjectExists( strObjName, strFormName )
{
  var oForm = document.forms[strFormName];
  var i=0;
  var bExists = false;
  while( i<oForm.elements.length && bExists==false)
  {
    if( oForm.elements[i].name == strObjName ){ bExists = true;}
    i++;
  }
  return bExists;
}





function IsCityName(mCity)
{
    bFlag = true
    for (i = 0; i < mCity.length; i++)
    {
 	c = mCity.charAt(i);
	if ((c < "a"  || c > "z") && (c < "A"  || c > "Z") && (c != " "))
	{
	   bFlag = false
	   break
	}
    }
    return bFlag
}


function IsZip(mStr)
{
    bFlag = true
    for (i = 0; i < mStr.length; i++)
    {
 	c = mStr.charAt(i);
	if ((c < "0"  || c > "9") && (c != " ") && (c != "(") && (c != ")") && (c != "-"))
	{
	   bFlag = false
	   break
	}
    }
    return bFlag
}

/*
function IsZip(strInput)
{
  var i
  var c
  h_count=0
  for (i = 0; i < strInput.length; i++)
  {
	c = strInput.charAt(i);
 	if ((c < "0"  || c > "9") && (c != "-"))
 	{
      	    return false;
      	}
      	else
      	{
      	   if (c=="-")
      	   	h_count++
      	}
  }
  if(h_count>1)
    return false
    
  return true;
}
*/
//This function is used to valadate Phone & Fax
function IsPhone(mStr)
{
    bFlag = true
    for (i = 0; i < mStr.length; i++)
    {
 	c = mStr.charAt(i);
	if ((c < "0"  || c > "9") && (c != "(") && (c != ")") && (c != "-"))
	{
	   bFlag = false
	   break
	}
    }
    return bFlag
}


function IsMobile(mStr)
{
    bFlag = true
    for (i = 0; i < mStr.length; i++)
    {
 	c = mStr.charAt(i);
	if ((c < "0"  || c > "9") && (c != "-"))
	{
	   bFlag = false
	   break
	}
    }
    return bFlag
}

function IsPreferredCity(mCity)
{
    bFlag = true
    for (i = 0; i < mCity.length; i++)
    {
 	c = mCity.charAt(i);
	if ((c < "a"  || c > "z") && (c < "A"  || c > "Z") && (c != " ") && (c != ",") )
	{
	   bFlag = false
	   break
	}
    }
    return bFlag
}


function IsAreaCode(oForm,mField)
{
    // Validation for Area Codes
    AreaError = ""
    for(q=1;q<=5;q++)
    {
	mArea = mField + q
	mAreaVal = alltrim(oForm.elements[mArea].value)
	if(mAreaVal != "")
	{
	    if(isNaN(mAreaVal))
	    {
		AreaError += "Area Code " + q + " Field must be an integer value.\n";
	    }
	}
    }
    return AreaError
}

//*********************************************************************
//date function to check for valid date

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function fnValid_Email(email)
{
	var flag = false;
	var rg2 = /^(([A-Z0-9]+[']?[A-Z0-9]+)*|(([A-Z0-9]+[']?[A-Z0-9]+)[\x2E]([A-Z0-9]+[']?[A-Z0-9]+))*|(([A-Z0-9]+[']?[A-Z0-9]+)*[\x5F]([A-Z0-9]+[']?[A-Z0-9]+)*)*)[\x40]{1}[A-Z0-9]+[\x2E]{1}[A-Z]{2,}([\x2E][A-Z]{2,})*$/g;
	
	email = email.toUpperCase();
	flag = rg2.test(email);
	return(flag);
}

//-->