function compareDates(date1, date2)
{
    var f     = new Date(date1);
    var n     = new Date(date2);
    if (f > n)
    {
          return true;
    }
    else
    {
          return false;
    }
}

//compareDate("01/02/2000", "01/01/2000") 


 function enabled(sValue,obj)
   {
     if (sValue==1) 
     {
       obj.disabled = false;
     }
     else
     {
       obj.disabled=true;
     }
   return false;
   }


function SetFocus(object)
{
  /* sets focus to the object passed in */
  object.focus();
}


function newPage(newLocation)
{ 
  /* opens a new page in same window*/
   parent.location.href = newLocation;
}


function newWindow(newAddress,name, width, height) 
{
  // opens a new page in another window
  window.open
    (newAddress,name,'left=50,top=50,resizable=yes,scrollbars=yes,width='+width+',height='+height);  
}


function display(text)
{
  //used for onmouseover event
  window.status = text;
  return true;
}


function clearstatus()
{
  //used for onmouseout event
  window.status = " ";
}


function remLink() 
{
  if (window.sList && window.sList.open && !window.sList.closed)
    window.sList.opener = null;
}


function unformatSSN(obj)
{
  // strip out any  -'s in the SSN
    var sValue = obj.value;

    if (sValue.search("-") != -1)
    {
      sValue = sValue.replace("-", "");
      obj.value = sValue;
    }
}



function formatSSN(obj)
/* Format by putting  -'s in the SSN*/
{
    var sValue = obj.value;
    
    if (len(sValue) == 8)
    {
       sValue = "0" & sValue
     }

    if (len(sValue) == 7)
    {
       sValue = "00" & sValue
     }
 
    sValue = left(sValue,3) & "-" & mid(sValue,4,2) & "-" & right(sValue,4)   
    obj.value = sValue;    
}


//phone number template using a regular expression
//used with the formatPhone function below
var phREG=/\d(\(\d{3}\)\d{3}-\d{4})|(\(\d{3}\)\d{3}-\d{4})/
var phLengthREG=/(\d{10})|(\d{11})/

function formatPhone(field)
{
 //using the above template, formats a 10 or 11 digit
 //phone number as (xxx)xxx-xxxx or x(xxx)xxx-xxxx
  var enteredNumber=field.value;
  var spREG=/ /g;
  enteredNumber=enteredNumber.replace(spREG,'');
  var prefix='';

  //if the number isn't a 10 or 11 digit number, or if it already matches the template
  if (phLengthREG.test(enteredNumber)==false || phREG.test(enteredNumber)==true) 
  {
   alert('You must enter a valid phone number!');
   return;
  }
  //if the number is 11 digits, chop off the first one for now
  if (enteredNumber.length==11)
  {
   prefix=enteredNumber.substring(0,1);
   enteredNumber=enteredNumber.substring(1,enteredNumber.length);
  }

  var firstThree='',secondThree='',firstFour='';
  //break apart the phone number into blocks
  firstThree=enteredNumber.substring(0,3);
  secondThree=enteredNumber.substring(3,6);
  firstFour=enteredNumber.substring(6,enteredNumber.length);
  //paste it back together with the correct formatting
  field.value=prefix+'('+firstThree+') '+secondThree+'-'+firstFour
  //save:
  //field.value=prefix+' '+firstThree+'-'+secondThree+'-'+firstFour
}
 

function validateInt(iString) 
{
   // no leading 0's allowed
   return (("" + parseInt(iString)) == iString);
}


function maxLength(obj, maxlength)
{
   if (obj.value.length == maxlength)
   { 
     event.returnValue = false;
    } 
} 



function isNumeric(theValue)
{
   if (theValue=="") return false;

   // validates an entry is numeric & allows leading 0's
   //you can add in a period(.)  or any other char that
   //would be acceptable as a digit (i.e. $)
   var digits = "0123456789$.";
   for (i=0; i<theValue.length; i++)
   {
      var thisChar = theValue.charAt(i);
      if (digits.indexOf(thisChar) == -1) return false;
   }
   return true;
}
  
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function validDate (day,month,year) 
{
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false
}

function isDate(date){
     var input = date;
     input = input.replace('/', ',X,');
     input = input.replace('/', ',X,');
     input = input.replace('X', '/');
     input = input.replace('X', '/');
     var tosplit = input;
     var splitby = /,\/,/;
     var splitvalue = tosplit.split(splitby);
     var m = splitvalue[0];
     var d = splitvalue[1];
     var y = splitvalue[2];

     if(validDate(d,m,y) == true){
       return(true);
     }
     else{
       return(false);
     }
}

function Mid(str, start, len)
{
/*
   IN: str - the string we are LEFTing
       start - our string's starting position (0 based!!)
       len - how many characters from start we want to get

    RETVAL: The substring from start to start+len
*/

   //make sure start and len are within proper bounds
   if (start < 0 || len < 0) return "";

   var iEnd, iLen = String(str).length;
   if (start + len > iLen)
      iEnd = iLen;
   else
      iEnd = start + len;

   return String(str).substring(start,iEnd);
}


function round(number,X) 
{
   // rounds number to X decimal places, defaults to 2
   X = (!X ? 2 : X);
   return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}


function autoFormatDate(obj)
{
  //used with the onKeyUp event;
  //when the user enters 8 digits with
  //no 'slashes' this function formats 
  //the entry as a date: mm/dd/yyyy
  var sValue = obj.value;
  var sNumber = sValue;
  var sMonth;
  var sDay;
  var sYear;

  if (sValue.length == 8 && sValue.search("/") == -1)
  {
    //note: uses "custom" Mid function that is 0 based!
    sMonth =Mid(sValue,0,2);
    sDay = Mid(sValue, 2,2);
    sYear =  Mid(sValue, 4,4);
    sValue = sMonth + "/" + sDay + "/" + sYear ; 
    obj.value = sValue;
  }
}

function autoFormatPhone(obj)
{
  //used with the onKeyUp event;
  //when the user enters 10 digits with
  //no dash '-', this function formats 
  //the entry as a (999) 999-9999
  var sValue = obj.value;
  var sNumber = sValue;
  var sAreaCode;
  var sPrefix;
  var sSuffix;

  if (sValue.length == 10 && sValue.search("-") == -1)
  {
    //note: uses "custom" Mid function that is 0 based!
    sAreaCode =Mid(sValue,0,3);
    sPrefix = Mid(sValue,3,3);
    sSuffix =  Mid(sValue,6,4);
    sValue = "(" + sAreaCode + ")" + sPrefix + "-" + sSuffix; 
    obj.value = sValue;
  }
}


function Age(obj, targetObj)
{
//writes the Age to the targetObj based on
//the date input in obj
//dependent on formatDate function above
    formatDate(obj);
      var workdate = obj.value + "";
      if (workdate.length == 10){
        now = new Date();
        var year = now.getYear() + "" ;
        var month = now.getMonth() + 1;
        month = "0" + month;
        if (month.length == 3){
           month = Mid(month,1,2)
        }
        else{
           month = Mid(month, 0,2)
        }
        var day = "0" + now.getDate();
        if (day.length == 3){
           day = Mid(day,1,2)
        }
        else{
           day = Mid(day, 0,2)
        }
        var today = year + month + day;
        var birthdate = Mid(workdate, 6, 4) + Mid(workdate, 0, 2) + Mid(workdate, 3, 2)
        var age = today - birthdate;
        age = round(age, 0);
        age = age + "";

        var workage;
        if (age.length == 7){
          workage = Mid(age, 0,3);
        }
        if (age.length == 6){
          workage = Mid(age, 0,2);
        }
        if (age.length == 5){
          workage = Mid(age, 0,1);
        }
        if (age.length <= 4){
          workage = 0;
        }
        targetObj.value = workage;
    }
}


//the next 2 functions are used for validation of a form
// A utility function that returns true if a string contains only 
// whitespace characters.
function isblank(s)
{
  for(var i = 0; i < s.length; i++) 
  {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
   }
   return true;
}

// This function performs form verification. It will be invoked
// from the onSubmit() event handler. 
function verify(frm)
{
   var msg;
   var empty_fields = "";
   var errors = "";

   // Loop through the elements of the form, looking for all 
   // text and textarea elements that don't have an "optional" property
   // defined. Then, check for fields that are empty and make a list of them.
   // Also, if any of these elements have a "min" or a "max" property defined,
   // verify that they are numbers and that they are in the right range.
   // Then put together error messages for fields that are 
   //wrong and display to user for correction and re-submission.
   for(var i = 0; i < frm.length; i++) 
   {
      var e = frm.elements[i];
      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) 
      {
          // first check if the field is empty
          if ((e.value == null) || (e.value == "") || isblank(e.value)) 
          {
             empty_fields += "\n          " + e.name;
             continue;
          }

          // Now check for fields that are supposed to be numeric.
          if (e.numeric || (e.min != null) || (e.max != null)) 
          { 
             var v = parseFloat(e.value);
             if (isNaN(v) || 
                ((e.min != null) && (v < e.min)) || 
                ((e.max != null) && (v > e.max))) 
             {
                    errors += "- The field " + e.name + " must be a number";
                    if (e.min != null) 
                        errors += " that is greater than or equal to " + e.min;
                    if (e.max != null && e.min != null) 
                        errors += " and less than or equal to " + e.max;
                    else if (e.max != null)
                        errors += " that is less than or equal to " + e.max;
                    errors += ".\n";
                }
            }
        }
    }

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The information on the form cannot be Saved because of the \n"
    msg += "following error(s).\n";
    msg += "Please correct these error(s) and click Save to re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) 
    {
        msg += "--The following required field(s) are empty:" 
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}



function checkKeys(event,formatType,blnAlarm)
{
  //this validates the keys the user enters in an input box
  //and limits the user to the definition of "formatType" that is 
  //passed in (i.e. alpha, num, email, url, alphanum, phone, ssn, date)
  //Note: other definitions can be created as needed
  keys=(window.event)?window.event.keyCode:event.which
  if ((keys==0)||(keys==8)||(keys==9)||(keys==13)||(keys==27)) return true
  keys=String.fromCharCode(keys).toUpperCase()
  alpha='ABCDEFGHIJKLMNOPQRSTUVWXYZ';num='0123456789'
  if(formatType=='alpha')formatType=alpha
  else if(formatType=='num')formatType=num
  else if(formatType=='username')formatType='&-'+alpha
  else if(formatType=='email')formatType='_@.-'+alpha+num
  else if(formatType=='url')formatType=':/.-&=%?'+alpha+num
  else if(formatType=='alphanum')formatType=alpha+num
  else if(formatType=='phone')formatType='(-) '+num
  else if(formatType=='ssn')formatType='-'+num
  else if(formatType=='money')formatType='-.$'+num
  else if(formatType=='date')formatType='/'+num
  else if(!formatType)formatType=' */+-.=&%()$£§"_΅!:;<>?.,ΰηθιω'.toUpperCase()+alpha+num
  if ((formatType.indexOf(keys)>-1))return true
  else
  {
    if (blnAlarm) alert("The character \""+keys+"\" is not allowed.\n\nPlease use only the following characters for this field :\n\n"
       +formatType)
       return false
  }
}


//Dremweaver UltraDev Rollover Code
//Begin
function preloadImages() { //v3.0
  var d=document; 
  if(d.images){ 
  	if(!d.p){
	  d.p=new Array();
	}
    var i;
	var j=d.p.length;
	var a=preloadImages.arguments; 
	for(i=0; i<a.length; i++){
      if (a[i].indexOf("#")!=0){ 
		d.p[j]=new Image; 
		d.p[j++].src=a[i];
	  }
	}
  }
}

function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//End