	//Validation.js
	//
	//For validation of form fields
	
	var gNS = (document.layers)? true:false
	var gIE = (document.all)? true:false
	var gCurrElement;
	
	//Patterns
	var PatternsDict = new Object();
   
	PatternsDict.isZip = /^(\d{5}(-\d{4})?)?$/;
	  // matches zip codes
	
	PatternsDict.isCrdCard = /^\d{8,16}$/;
	  // matches credit card number
	
	PatternsDict.isCommaDelimited = /^[1-9][0-9]?$|^([1-9][0-9]?\,?)*$/;
	  // matches comma dilimited numbers
	   
	PatternsDict.isCurrency = /^\d{1,3}(,\d{3})*\.\d{2}$/;
	  // matches $17.23 or 14,281,545.45 or ...
	
	PatternsDict.isFloat = /^\d*\.\d*$|^\d*$/;
	  // matches 17.23 or 14281.4555 or ...
	   
	PatternsDict.isTime = /^[0-1]?[0-9]:[0-5]?[0-9]$|^[2][0-3]:[0-5]?[0-9]$/;
	  // matches 5:04 or 12:34 

	PatternsDict.isDate = '';
	  // matches 12/31/1998 or 31/12/1998 or empty is allowed
	  
	PatternsDict.isAlpha = /^([A-Za-z\' \t])*$/;
	  // matches chuck Noris  or empty is allowed
	  
	PatternsDict.isWord = /^([A-Za-z0-9_ \t\-])*$/;
	  // matches doto2_So
	  
	PatternsDict.isEmail = /^(((\w)+[-.!])?(\w[!]?)+@((\w)+[-.])+(\w{1,3}))?$|^(((\w)+[-.!])?(\w[!]?)+@((\w)+[-.])+((\w{2})+[-.])+(\w{2}))?$/;
							  
	  // matches k1234!@ting.tong.com or t@k.king.com or t-ding@dong.com
	  
	PatternsDict.isDigit = /^\d*$/;
	  //equivalent to  [0-9]* matches 12312123 or empty is allowed

	PatternsDict.isPhone = /^([0-9_ \t\-])*$/;
	  // matches 03-9433399 or 054-889900 or 039433399
	  
	PatternsDict.isTinyInt = new Array("^\[0-9]?$","^[0-9]?[0-9]?$","^[0-2]?[0-5]?[0-5]?$");
	  // value <= 255

	PatternsDict.isSmallInt =new Array("^\[0-9]?$","^[0-9]?[0-9]?$","^[0-9]?[0-9]?[0-9]?$","^[0-9]?[0-9]?[0-9]?[0-9]?$","^[0-3]?[0-2]?[0-7]?[0-6]?[0-7]?$");
	  // value <= 32767
	  
	//this function selects an option that begins with
	//a letter pressed on the keyboard
	function ComboQuickNav(combo){
		if (gIE)
		{
			key=window.event.keyCode
			i=0
			found=false
			while (i<combo.options.length && !found)
			{
				if (key==combo.options[i].text.charCodeAt(0))
				{
					combo.options[i].selected=true
					found=true
				}
				i++
			}
		}
	}
  // Validate the form fields by the validator attribute
  function validateForm(theForm)
  { 
     // return true if all is well
	 var elArr = theForm.elements;   // get all elements of the form into array
	 for(var i = 0; i < elArr.length; i++)
	  with(elArr[i])
	  {                // for each element of the form...
	    gCurrElement = elArr[i];
	    if(elArr[i].required=="true")
	    {
	        if(Trim(value)=='')
	        {
	            try
				{ 
					elArr[i].focus();
					alert(L_Empty);
					elArr[i].style.filter="progid:DXImageTransform.Microsoft.Glow(color='red', Strength='3')";
					window.setTimeout("resetControl()",1500);
					if (elArr[i].tagName.toUpperCase()!="SELECT")
					{
						elArr[i].select();
					}
				    return false;
				}
				catch(e)
				{
				 return true;
				}
			}
		}
	    if(Trim(value)!='')
	    { 
			var v = elArr[i].validator;   // get validator, if any
			if(!v) continue;              // no validator property, skip
			else
			{
			     if(PatternsDict[v].length > 0)
			     {
			        for(var j=0; j < PatternsDict[v].length; j++)
			        {
			           var TempPatternsDict = new RegExp(PatternsDict[v][j]);
			           var gotIt = TempPatternsDict.exec(Trim(value));
			           if(gotIt) break;
			        }
			        if(!gotIt)
			        {
			              alert(L_Invalid);
			              elArr[i].focus();
			              elArr[i].style.filter="progid:DXImageTransform.Microsoft.Glow(color='red', Strength='3')";
					      window.setTimeout("resetControl()",1500);
			              if (elArr[i].tagName.toUpperCase()!="SELECT")
							{
							elArr[i].select();
							}
			              return false;
			        }
			     }
			     else
			     {
					if (v==='isDate')
					{
  					 if (isNaN(Date.parse(Trim(value))))
  					 {
  					  alert(L_Invalid);
					  elArr[i].focus();
					  elArr[i].style.filter="progid:DXImageTransform.Microsoft.Glow(color='red', Strength='3')";
					  window.setTimeout("resetControl()",1500);
				      elArr[i].select();
					  return false;
  					 }
					}
					else
					{
						var thePat = PatternsDict[v];   // select the validating regular expr
						var gotIt = thePat.exec(Trim(value)); // run it on value of elArr[i]
						if(!gotIt)
						{
						   alert(L_Invalid);
						   elArr[i].focus();
						   elArr[i].style.filter="progid:DXImageTransform.Microsoft.Glow(color='red', Strength='3')";
					       window.setTimeout("resetControl()",1500);
						   elArr[i].select();
						   return false;
						}
					}	
			     }
			}
		}	
	  }
	  return true;
	}
  //The Trim function ensures that pattern matching occurs on the 
  //appropriate portion of the string the user entered 
  //by removing leading and trailing white spaces from the string. 
  function Trim(oldString)
    {
	   // is oldString made up completely of whitespace?
	   var emptyPattern = /^(\s*)$/;
	   if(emptyPattern.test(oldString))
	      // if so, return null string
	      return '';
	   else
	      // else, return non-whitespace characters from middle of oldString
	      return oldString.replace(/^\s*(.*\S+)\s*$/,"$1");
	}
	//Resets the marked unvalidate control style.
	function resetControl(sID)
	{
		gCurrElement.style.filter='none';
	}
	//Dispays the validation message with all the validation behaviour.
	//
	//Accepts:
	//	e_field - The field to set focus on after the message box.
	//	sMessage - The message text.
	function validationMessage(e_field, sMessage)
	{
		alert(sMessage);
		if (e_field)
		{
			gCurrElement = e_field;
			e_field.focus();
			e_field.style.filter="progid:DXImageTransform.Microsoft.Glow(color='red', Strength='3')";
			window.setTimeout("resetControl()",1500);
			e_field.select();
		}
	} 