if(window.Event){
window.captureEvents(Event.KEYPRESS)
}

nets4 = (document.layers)? true:false
nets6 = (document.getElementById && !document.all)? true:false
inter4 = (document.all)? true:false
minWidth = 750

var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";
var validUSPhoneChars = digits + phoneNumberDelimiters;
var decimalPointDelimiter = "."
var whitespace = " \t\n\r";

function submitform(form,arrValidation){
		if(validateForm(form,arrValidation)){
			form.submit();
		}
	}
	
function changeBg(evt) {
var szEvent = "object" == typeof(event) ? event.type : evt.type;
//alert(this.type);
if((this.type=='text') || (this.type=='textarea') || (this.type=='password') || (this.type=='file')){
this.style.background = szEvent == "focus" ? "#ffffcc" : "#ffffff";
//if(szEvent == "focus"){this.select()}
}}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(replace(dc.substring(begin + prefix.length, end),'+',' '));
}

function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function GetDay(intDay){
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
                         "Thursday", "Friday", "Saturday")
    return DayArray[intDay]
    }

  function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December") 
    return MonthArray[intMonth] 	  	 
    }
  function getDateStrWithDOW(){
    var today = new Date()
    var year = today.getYear()
    if(year<1000) year+=1900
    var todayStr = GetDay(today.getDay()) + ", "
    todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
    todayStr += ", " + year
    return todayStr
    }
//**************************************************************************************************************

function validateEmail(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

/* function validateData 
*  Checks each field in a form 
*  Called from validateForm function 
*/ 
function validateData(strValidateStr,objValue,strError) 
{ 
    var epos = strValidateStr.search("="); 
    var command  = ""; 
    var cmdvalue = ""; 
    var strSearch = "";
      if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 


switch(command) 
    { 
	case "noquotes":
	 {
	   //CHECK FOR ' IN STRINGS AND ERROR IF ENCOUNTERED
    	   strSearch = objValue.value;
    	   regRes = strSearch.match("'"); 
    	   if(regRes=="'")
			{ 
			if(!strError || strError.length ==0) 
		              { 
                		strError = "Fields cannot contain quotation (') marks  ";
		              }//if  
			newAlert('Alert',strError,3,0);
         		return false;	
			}
           break; 
	 }//case noquotes
        case "req": 
        case "required": 
         { 
           if(isWhitespace(objValue.value)) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              }//if 
              newAlert('Alert',strError,4,0);
              return false; 
           }//if 
           break;             
         }//case required 
		case "date":
		 {
		 	if(objValue.value.length > 0)
		      {
	               if(!isDate(objValue.value)) 
	               { 
	                 if(!strError || strError.length ==0) 
	                 { 
	                    strError = objValue.name+": Enter a valid Date "; 
	                 }//if                                               
	 			     //newAlert('Alert',strError,4,0);
	                 return false; 
	               }//if 
		      }
           break; 
		 }//case isdate
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
               }//if 
               newAlert('Alert',strError + "\n[Current length = " + objValue.value.length + " ]",4,0);
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//if               
			   newAlert('Alert',strError + "\n[Current length = " + objValue.value.length + " ]",4,0);
               return false;                 
             }//if 
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9 ]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
			    newAlert('Alert',strError + "\n [Error character position " + eval(charpos+1)+"]",4,0);
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9-.]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if
			    newAlert('Alert',strError + "\n [Error character position " + eval(charpos+1)+"]",4,0);
                return false; 
              }//if 
              break;               
           }//numeric 
        case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z ]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alphabetic characters allowed "; 
                }//if
			    newAlert('Alert',strError + "\n [Error character position " + eval(charpos+1)+"]",4,0);
                return false; 
              }//if 
              break; 
           }//alpha 
        case "email": 
          { if(objValue.value.length > 0)
	      {
               if(!validateEmail(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Enter a valid Email address "; 
                 }//if                                               
 			     newAlert('Alert',strError,4,0);
                 return false; 
               }//if 
	      }
           break; 
          }//case email 
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              newAlert('Alert',objValue.name+": Should be a number ",4,0);
			  return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }//if               
		     newAlert('Alert',strError,4,0);
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
			  newAlert('Alert',objValue.name+": Should be a number ",4,0);
			  return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }//if               
		       newAlert('Alert',strError,4,0);
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
            if(!objValue.value.match(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name+": Invalid characters found "; 
              }//if                                                               
	          newAlert('Alert',strError,4,0);
              return false;                   
            }//if 
           break; 
         }//case regexp 
        case "dontselect": 
         { 
            if(objValue.selectedIndex == null) 
            { 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            } 
            if(objValue.selectedIndex == eval(cmdvalue)) 
            { 
             if(!strError || strError.length ==0) 
              { 
              strError = objValue.name+": Please Select one option "; 
              }//if                                                               
		      newAlert('Alert',strError,4,0);
              return false;                                   
             } 
             break; 
         }//case dontselect 
    }//switch 
    return true; 
} 

/* 
* function validateForm 
* the function that can be used to validate any form 
* returns false if the validation fails; true if success 
* arguments : 
*   objFrm     : the form object 
*   arrObjDesc : an array of objects describing the validations to conduct on each 
*        input item. 
*          The array should consist of one object per input item in the order the input 
*          elements are present in the form. Each object consist of zero or more validation 
*          objects. Each of these validation object is a pair consisting of the validation 
*          descriptor string and an optional Error message. 
*/ 

function validateForm(objFrm,arrObjDesc) 
{ 
 for(var itrobj=0; itrobj < arrObjDesc.length; itrobj++) 
 {
   if(objFrm.elements.length <= itrobj) 
   { 
        alert("BUG: Obj descriptor for a non existent form element"); 
        return false; 
   }//if 
   for(var itrdesc=0; itrdesc < arrObjDesc[itrobj].length ;itrdesc++) 
   { 
      if(validateData(arrObjDesc[itrobj][itrdesc][0], 
                 objFrm[itrobj],arrObjDesc[itrobj][itrdesc][1]) == false) 
       { 
	     objFrm[itrobj].focus();
         return false; 
       }//if 
   }//for 
   //alert(objFrm[itrobj].name);
   //REPLACE ALL ' WITH '' FOR SQL STRINGS - NO LONGER USED USE STR.MATCH IN VALIDATE DATA
   //objFrm[itrobj].value = replace(objFrm[itrobj].value,"'","''");
 }//for 
	return true;
} 

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

/***************************************************************************************************************
 * DHTML date validation script for dd/mm/yyyy.
 */
// Declaring valid date character, minimum year and maximum year
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 stripCharsNotInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        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 formatTime(strField){
	var strVal = strField.value
    var oLen = strVal.length; 
     var hr = strVal.split(":")[0]
     var mn = strVal.split(":")[1];
	 if(oLen == 2 || parseInt(hr)>2){
          if(strVal.search(":")<0){strField.value += ":";}
     }
}

function IsTime(strTime){
			var strTestTime = new String(strTime);
			strTestTime.toUpperCase();
			var bTime = false;
			var nColonPlace = strTestTime.indexOf(":",0);
			var leftstr = strTestTime.substring(0,nColonPlace)
			var rightstr = strTestTime.substring(nColonPlace+1,strTestTime.length)
			if(nColonPlace>0){bTime = true;}
			if(bTime && ((parseInt(nColonPlace)<1)||(parseInt(nColonPlace)>2))){bTime = false;}
			if(bTime && (!isInteger(leftstr))||(parseInt(leftstr)>23)){bTime = false;}
			if(bTime && (!isInteger(rightstr))||(parseInt(rightstr)>59)){bTime = false;}
			return bTime;
}

function isDate(dtStr){
	var daysInMonth = new Array(0,31,29,31,30,31,30,31,31,30,31,30,31)
	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){
        newAlert('Alert',"The date format should be : mm/dd/yyyy",4,0);
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		newAlert('Alert',"Please enter a valid month",4,0);
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		newAlert('Alert',"Please enter a valid day",4,0);
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		newAlert('Alert',"Please enter a valid 4 digit year before "+maxYear,4,0);
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		newAlert('Alert',"Please enter a valid date",4,0);
		return false
	}
return true
}
//**************************************************************************************************************

function newConfirm(title,mess,icon,defbut,mods) {
   if (inter4) {
      icon = (icon==0) ? 0 : 2;
      defbut = (defbut==0) ? 0 : 1;
      retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
      retVal = (retVal==6);
   }
   else {
      retVal = confirm(mess);
   }
   return retVal;
}

function newAlert(title,mess,icon,mods) {
  // (inter4) ? makeMsgBox(title,mess,icon,0,0,mods) : alert(mess);
	
alert(mess);
}

function HighlightCELL(ROWID, sImage)
			        {
					if (inter4){
					var objINFOROW = document.all(ROWID);
					}
				    else {
					var objINFOROW = document.getElementById(ROWID);
				    }
					objINFOROW.background = sImage;
					
			        }
					
//**************************************************************************************************************		
// COMBO BOX LOOK UP FUNCTIONS

var keyspressed="";
var cboSelValue="";

function selectKeyDown(e)
{
    // Delete Key resets previous search keys
    var n
	
	if(n == 46)
        {clrSelect();}
}

function selectKeyPress(e)
{
    // Notes:
    //    1) previous keys are cleared onBlur/onFocus and with Delete key
    //    2) if the search doesn't find a match, this returns to normal 1 key 
    //        search setting returnValue = false below for ALL cases will 
    //        prevent default behavior

    var sndr = e;
    var pre = keyspressed;
    (window.Event)?key=e.which :key=window.event.keyCode

	if(key==13){return true;} //enter key pressed, return true so can trigger in external code

    var charx = String.fromCharCode(key);
	var bfound = null;
	
    // "i" -> ignoreCase
    var re = new RegExp("^" + pre + charx, "i"); 

    for(var i=0; i<sndr.options.length; i++)
    {
        if(re.test(sndr.options[i].text))
        {
            sndr.options[i].selected=true;
            keyspressed = keyspressed + charx;
            window.event.returnValue = false;
			bfound = true;
            break;
        }
    }
	if(!bfound){clrSelect();keyspressed = charx;};
}

function clrSelect()
{
    keyspressed = "";
}

//**************************************************************************************************************
					
					
					
					