<!--
// Functions:
//  fnCheckExt(f,exts)
//  fnIsNumeric(fValue)
//  fnIsAlphabetic(strValue) 
//  fnIsAlphaNumeric(strValue) 
//  fnIsEmpty(strValue) 
//  fnCheckDoubleQuotes(strValue) 
//----------------------------------
//  chkValidCharSet(str,charset) : Returns false if any of the characters in charset are present in str (to validate a string for a set of not allowed characters)
//  alltrim(s)
//  CheckBrowser()
//  IsAlpha(strInput)
//  IsAlphaNumeric(strInput)
//  IsName(strInput)
//  IsCommaName(strInput)	
//  IsChecked(obj)
//  IsCheck(obj)
//  IsNumeric(strInput)
//  IsPrice(strInput)
//  IsCommaNumeric(strInput)
//  CheckCommaNumeric(strInput)
//  IsEmail(strInput)
//  ReplaceChars(entry)
//  isDotExpression( InString , NeedsDot )
//  GetRadioValue(obj)
//  ObjectExists(strObjName,strFormName)
//  IsCityName(mCity)
//  IsZip(strInput)
//  IsPhone(mStr)
//  fnOpenSSl(strUrl)
//  Validate_Phone()
//  fnAllowLimitedChars(cntl,totalchars)   : to allow limited char in textarea
//	IsUSCanZip(strZip)
//  fnAllowNum  :Allow only numeric input onKeyPress="return fnAllowNum(event);"
//  fnValidateDate(fieldname,PastPresentFuture) : txtDate is ID of the field , eg.  fnValidateDate('txtDate','YNN')  : to validate a date for Past/Present/Future Values : YNN means Allow Past,Do not allow Present,Do not allow Future

/*
	Function written by Rajiv : 22-nov-2004
	function to check extension of a file. pass filename and allowable extensions 
	eg fnCheckExt("test.xml","html,htm,doc");
	
*/

function chkValidCharSet(str,charset) 
{ 
	var result = true; 
	var strl = str.length;
	var curchar ;
		
	for (var i=0;i<strl;i++) 
	{
		curchar = str.substr(i,1);
			
		if (charset.indexOf(curchar)>=0 && result==true) 
		{ 
			result = false; 
			//If any of the characters mentioned in the not allowed charset is found in str return false.
		} 
	}	

	return result; 
} 


function fnCheckExt(f,exts) 
{
	var returnValue = true;
	
	//var strAllowedExt as new string;
	var strAllowedExt = exts.split(",");
	//var strAllowedExt = new Array("html","htm","doc","txt");

	for (i=0;i<strAllowedExt.length;i++) 
	{
		if (f.substr(f.lastIndexOf(".")+1,f.length).toLowerCase()  == strAllowedExt[i].toLowerCase()) 
		{
			returnValue = false;
		}
	}

	return returnValue;
}


/*
	Function written by Rajiv : 18-Oct-2005
	function to clear a form
	eg clearForm(this.form);
	
*/

function clearForm(frm)
{	
	for (i=0;i<frm.elements.length;i++)
	{
		var strType = ""; // setting string variable to null
		var objField = frm.elements[i]
		
		if (objField.length > 0) { strType = objField[0].type; }  // setting the type to strType variable 
		if (!strType) { strType = objField.type;}// again checking and setting the type to strType variable 

		//var strType = frm.elements[i].type;
		
		
		switch (strType) 
		{
						case "text":
						case "password":
						case "textarea":
								objField.value='';
						break;
						case "radio":
						case "checkbox":
								objField.checked=false;

						break;
						case "select-one":
								objField.selectedIndex = 0;
						break;
						case "select-multiple":
								for (j=0;j<objField.length;j++)
								{
									objField[j].selected =false;
								}
						break;
		}
	}
}


/* function to verify if value is a valid number (integer or float) 
argument - amount 
returns True for a valid Integer or fractional number else False */ 

function fnIsNumeric(fValue) 
{ 
   var rgnum = /^\d+(\.\d{2})?$/; 
   var result = rgnum.test(fValue); 
   return result; 
} 


/* function to verify if the value contains all alphabets 
argument - value 
returns True if all characters are alphabets else returns False */ 


function fnIsAlphabetic(strValue) 
{ 
   var rgstr = /^[A-Za-z]+$/; 
   var result = rgstr.test(strValue); 
   return result; 
} 


/* function to verify if the value contains only alphabets & numbers 
argument - value 
returns True if all characters are alphanumeric else returns False */ 

 
function fnIsAlphaNumeric(strValue) 
{ 
   var rgstr = /^[A-Za-z\d]+$/; 
   var result = rgstr.test(strValue); 
   return result; 
} 


/* this function is used to detect whether user has entered only spaces i.e. empty value 
javascript comparison value=="" returns True only if there is single space 
Use this function to detect spaces more than one (e.g. Username, password etc.) 
Returns False for empty value; True for non-empty value */ 

function fnIsEmpty(strValue) 
{ 
   var  rgempty = /\S/; 
   var result = rgempty.test(strValue); 
   return result; 
} 


/* this function is used to detect for a double quote in a string 
argument - string to be tested 
returns True if the string contains double quote else returns False */ 

function fnCheckDoubleQuotes(strValue) 
{ 
   var rgquote = /\"/; 
   var result = rgquote.test(strValue); 
   return result; 
}

function isValidEmail(strEmail)
{
	return IsEmail(strEmail);
}

function Trim(str)
{
	return alltrim(str);
}
function alltrim(str)
{
   str = this != window? this : str;
   return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}    


function Right(String, Length)
{
	if (String == null)
		return (false);

    var dest = '';
    alert(p.length); 
    for (var i = (String.length - 1); i >= 0; i--)
    		dest = dest + String.charAt(i);
	String = dest;
	String = String.substr(0, Length);
	dest = '';

    for (var i = (String.length - 1); i >= 0; i--)
		dest = dest + String.charAt(i);

	return dest;
}


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;
}

function IsChecked(val)
{
	ok = 0;
	for (var i=0;i<val.length;i++)
	{
		if (val[i].checked) {
			ok=1;}
	}
	if (ok == 0) { return true; }
	else { return false; }
}

function IsCheck(radioobj)
{
	//verify if one radio button from a multiple choice radio is checked  .. pass the obj as document.formname.radioname
	var bchk=false;
	// initialize bchk as false. if anybody turns it to true then it will return true.
	
	if (radioobj)
	{
		var chkcnt;
		if (isNaN(radioobj.length))
		{
			//if only 1 option is present on form
			if(radioobj.checked==true)
			{
				bchk=true;
			}
		}
		else
		{
			var chkboxcount=radioobj.length;
			for(chkcnt=0;chkcnt<chkboxcount;chkcnt++)
			{
				if(radioobj[chkcnt].checked==true && bchk==false)
				{
					bchk=true;
				}
			}
		}
		//alert(bchk);
	}
	return bchk;
}

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 IsPrice(strInput)
{
  var i
  var c
  var numOfDots = 0;

  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);

    // check if the DOT is the last charachter
    if (c == ".")
    {
       // added by Sudeep
       // count number of DOTS
       numOfDots = numOfDots + 1;

       if (strInput.length == i)
       {
         return false;
       }
    }

    if ((c < "0" || c > "9" ) &&( c != "."))
    {
	return false;
    }
  }

  // added by Sudeep
  // check if there are more than one DOTS
  if ( numOfDots > 1) 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 ("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.@_-".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(strInput)
{
  var i
  var c
  h_count=0
  for (i = 0; i < strInput.length; i++)
  {
	c = strInput.charAt(i);
 	if ((c < "0"  || c > "9"))
 	{
    	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 != "-") && (c != "+") && (c != " "))
	{
	   bFlag = false
	   break
	}
    }
    return bFlag
}



function fnOpenSSl(strUrl)
{
  window.open(strUrl,'MyWindow','toolbar=no,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=350,height=400,left=20,top=20');
}

function Validate_Phone()
{
   var strErrString="";
	Form=document.frmOrderInfo;

	var regexp="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/?*&%^()_$#@!~`|+/\<>[]\{}";	
	var strPhone="";
	var strErrString;
	strPhone=Form.txtBusinessPhone.value;

	intPhoneLength = strPhone.length;
	var intCount;
	for(intCount=0;intCount<intPhoneLength;intCount++)
	{
		mvar = strPhone.charAt(intCount)
		if (regexp.indexOf(mvar) != -1)
		{
			strErrString= "Please enter a valid Phone Number.\n";
			break;
		}
	    else
		{
		 	strErrString = "";
		}
   }
   return strErrString;
}

function fnAllowNum(e)
{
    //e = window.event;    NN: return false;    IE: e.returnValue = false
	//usage : onKeyPress="return fnAllowNum(event);" 
	
		var browser_name = navigator.appName;
		// 46= Dot  8 = BackSpace , 125 = Delete  ,0 = Left, Right
		if	(browser_name=="Netscape")
		{
			var iKeycod = e.which;
			//alert(iKeycod);
			if (iKeycod==8 || iKeycod==0)
			{
				return true;			
			}
			else
			{
				if(!(iKeycod >= 48 && iKeycod <= 57))
				{
					if (!(iKeycod==46))
					{
						return false;

					}
				}
			}
		}
		else
		{		
			var iKeycod = window.event.keyCode;
			if(!(iKeycod >= 48 && iKeycod <= 57))
			{
				if (!(iKeycod==46))
				{
					window.event.keyCode = 0;
				}
			}
		}
}

	
function fnAllowLimitedChars(cntl,totalchars)
{
	var sValue = document.all(cntl).value;
	var iLen = sValue.length;
	if(iLen == totalchars)
		window.event.keyCode = 0;
}

function IsUSCanZip(strZip)
{
   //US zip code :   99999 or 99999-9999
   var rgnum1 = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
   
   //Canadian postal code : Z5Z-5Z5 or  Z5Z 5Z5 or Z5Z5Z5
   var rgnum2 = /^\D{1}\d{1}\D{1}[\-\s]?\d{1}\D{1}\d{1}$/; 
   
   
   var result1=rgnum1.test(strZip);
   var result2=rgnum2.test(strZip);
   
   if (result1==true || result2==true)
   {
		result=true;
   }
   else
   {
		result=false;
   }
   
	//old canada reg exp   var rgnum2 = /^\D{1}\d{1}\D{1}\-?\d{1}\D{1}\d{1}$/;   
   //alert('resultUS:'+result1);
   //alert('resultCan:'+result2);
  // alert('resultUS or Canada:'+result);

   return result; 

}

	function fnValidateDate(fieldname,PastPresentFuture)
	{
		var yyyy=document.getElementById(fieldname).value.charAt(6)+document.getElementById(fieldname).value.charAt(7)+document.getElementById(fieldname).value.charAt(8)+document.getElementById(fieldname).value.charAt(9);
		var mm=document.getElementById(fieldname).value.charAt(0)+document.getElementById(fieldname).value.charAt(1);
		var dd=document.getElementById(fieldname).value.charAt(3)+document.getElementById(fieldname).value.charAt(4);
		
		var today=new Date();
		var numdate=yyyy+mm+dd;
		var strToday 
		strToday = (today.getFullYear() * 10000) + (100 * (today.getMonth()+1)) + today.getDate();
		var datediff=parseInt(strToday)-parseInt(numdate);
		
		
		if(datediff>0)
		   datediff=1;
		   
		
		if(datediff<0)
		   datediff=-1;
		   
		var datevalid=true;

		switch (datediff)
		{
		case 1:
			//Past Dates are allowed	
			if(PastPresentFuture.charAt(0)=="Y")
				datevalid=true;
			else
				datevalid=false;
			
			break;
			
		case 0:
			//Present Date is Allowed
			if(PastPresentFuture.charAt(1)=="Y")
				datevalid=true;
			else
				datevalid=false;
			break;
		case -1 :
			//Future Dates Are allowed
			if(PastPresentFuture.charAt(2)=="Y")
				datevalid=true;
			else
				datevalid=false;
			
			break;
		}
	//	alert(datevalid);
		
		return datevalid;
	}

//-->
