// ____________________________________________________________________________
function populate(frm, dropValue, dropboxName) {
	list=ecoc[dropValue.options[dropValue.selectedIndex].text];
	if (dropboxName.selectedIndex >=0) {oldValue = dropboxName.options[dropboxName.selectedIndex].value;}
	if(document.all) //IE
	{
		while (dropboxName.options.length) {dropboxName.options.remove(0);}
	}
	else
	{
		for(var ixx = dropboxName.options.length; ixx>=0; ixx--)
			{dropboxName.options[0] = null;}
	}
	if(list == null)
	{
		e = document.createElement('option');
		e.value = '';
		e.text = 'Select Industry...';
		dropboxName.options.add(e);
	}
	else
	{
		for(i=0;i<list.length;i+=2)
		{
			dropboxName.options[i/2] = new Option(list[i+1],list[i]);
		}
	}
}

// ____________________________________________________________________________
function openCalendarWindow(strFormName, strFieldName) {
	var objField = eval('document' + '.' + strFormName + '.' + strFieldName);
	setDateField(objField);
	top.newWin = window.open('../Calculators/Calendar.asp','cal','dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes'); 
	return false;
}


// ____________________________________________________________________________
function openCalculatorWindow(strCalcUrl, strFormName, strFieldName) {
	// this javascript opens a popup to a specified URL so a calculator
	// can be used to update a field.  the calculator page should send
	// it's value back to the main form like so like so:
	//   var objField = eval(window.opener.document.Q_FORM.OPENERINFO.value);
	//   objField.value = 'Return Value';
	//   self.close();
	//   // (you would probably put this in an onClick event)
	
	document.Q_FORM.OPENERINFO.value = 'window.opener.document.' + strFormName + '.' + strFieldName; 
	
	var intLeft = (screen.availWidth-210)/2;
	var intTop = (screen.availHeight-230)/2;
	
	if (!newWin || newWin.closed){
		newWin = window.open('../Calculators/' + strCalcUrl,'calc','dependent=yes,width=210,height=230,left=' + intLeft + ',top=' + intTop + ',titlebar=yes,resizable=yes,scrollbars=yes'); 
		if (newWin.opener == null){
			newWin.opener = self;
		}
		return false;
	}else{
		newWin.focus();
	}

}


// ____________________________________________________________________________
function openCalendarWindowURL(strCalcUrl, strCalcFileName, strFormName, strFieldName) {

	var objField = eval('document' + '.' + strFormName + '.' + strFieldName);
	setDateField(objField);
	top.newWin = window.open(strCalcUrl + '/' + strCalcFileName,'cal','dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes'); 

}

// ____________________________________________________________________________
function setDirtyBit() {
	// this function sets the dirty bit on the form so we know
	// if anything was changed.
	document.Q_FORM.DIRTY.value = '1';
}

// ____________________________________________________________________________
function saveForm(blnShowMessageBox) {
	// this function saves the form if it's dirty
	if (document.Q_FORM.DIRTY.value == '1') {
		document.Q_FORM.DESTINATION.value = 'Application.asp';
		document.Q_FORM.submit();
	}
	if (blnShowMessageBox) {
		jsPopUp('Save.asp',350,150,0,0);
	}
	return false;
}

// ____________________________________________________________________________
function submitForm(strDestination) {
	// this function submits the form, replacing the destination
	// if necessary
	if (strDestination != '') {
		document.Q_FORM.DESTINATION.value = strDestination;
	} 
	document.Q_FORM.submit();
	return true;
}

// ________________________________________________________________________
function getOpenerForm(txtFormName) {
	var i;
	for (i=0; i < window.opener.document.forms.length; i++){
		if (window.opener.document.forms[i].name == txtFormName){
			return window.opener.document.forms[i];
		}
	}
}	
// ________________________________________________________________________
function refreshOpener(strAnchor) {
	var objForm;
	objForm = getOpenerForm('Q_FORM');
	//alert(typeof objForm);
	var strUrl;
	strUrl = opener.location.href;
	if (strAnchor != '') {
		if (strUrl.lastIndexOf('#') > -1) {
			strUrl = strUrl.substring(0, strUrl.lastIndexOf('#'));
		}
		strUrl += '#' + strAnchor;
	}
	objForm.DESTINATION.value = strUrl;
	objForm.submit();
}

var m_strLastTextAreaThatHadFocus;
m_strLastTextAreaThatHadFocus = '';

// ____________________________________________________________________________
function refreshForm() {
	document.Q_FORM.DESTINATION.value = document.location;
	document.Q_FORM.submit();
}

var m_blnNoteAlertDisplayed;
m_blnNoteAlertDisplayed = false;
// ____________________________________________________________________________
function displayNonCssAlert() {
	// this function displays a confirmation box for non-css browsers
	// to see if they want to refresh the form to see child questions.
	// if they say no, then they won't be asked again until a page reload.
	if (m_blnNoteAlertDisplayed == false) {
		m_blnNoteAlertDisplayed = true;
		if (confirm('This question contains additional sub-questions,\nhowever a page reload is required to display them.\nWould you like to reload the page now?\n\n(Hint: InsuranceNoodle uses the latest browser\ntechnology to speed up the application process.\nYou can avoid this message by upgrading\n to the latest version.)')) {
			refreshForm();
		}
	}
}

// ____________________________________________________________________________
//remove all non-numeric characters
function MakeNumeric(thisfield){
	var regexp = /\D+/g;		//any number of non-numeric characters
	if (regexp.test(thisfield.value)){
		thisfield.value = thisfield.value.replace(regexp,"");
	}	
}

// ____________________________________________________________________________

///////////////////////////////////////////////////
// FORM VALIDATION FUNCTIONS
///////////////////////////////////////////////////

// ____________________________________________________________________________
function requireAllFields(objForm) {
   // Checks all fields on the given form.  if any fields are blank, then
   // it opens an alert box and returns false.  otherwise it returns true.

	var nElements = objForm.elements.length;
	var objElement;
	
	// loop through all the form elements
	for (var nNum = 0; nNum < nElements; nNum++) {
		objElement = objForm.elements[nNum];
		
		// if this element is empty then alert and return false
		if ((objElement.type == "text") && (objElement.value == "" || objElement.value == null)) {
			alert('Please complete all fields on this page to continue.');
			objElement.focus();
			return false;
		} else if ((objElement.type == "textarea") && (objElement.value == "" || objElement.value == null)) {
			alert(objElement.name);
			return false;
		} else if (objElement.type == "select-one" && objElement.selectedIndex == 0){
			alert('Please complete all fields on this page to continue.');
			objElement.focus();
			return false;
		} else if (objElement.type == "radio" && radioButtonFieldIsComplete(objForm,objElement.name) == false){
			alert(strErrorMessage);
			return false;
		}

	}
	
	// if we made it all the way to the end, then there were no problems
	return true;
}

// ____________________________________________________________________________
function RequireFields(objForm, arrFieldNames, arrErrorMessage) {
   // Checks specified fields on the given form.  if any of the specified
   // fields are blank, then it opens an alert box and returns false.
   // otherwise it returns true.
   // example: onsubmit="return requireFields(this,['field1','field2'],['msg1','msg2'])"
	//alert('Hi.');
	//return false;
	
	if (arrFieldNames.length != arrErrorMessage.length) {
		alert('requireFields error: arrays do not match-' + arrFieldNames[0]);
		return false;
	}

	var nElements = objForm.elements.length;
	var objElement, strErrorMessage;
	
	// loop through all the form elements
	for (var nNum = 0; nNum < nElements; nNum++) {
		objElement = objForm.elements[nNum];
		
		//alert(objElement.name + ': ' + objElement.type + ' ' + objElement.length + ' ' + objElement.value);

		// loop through the required fields array
		for (var nInner = 0; nInner < arrFieldNames.length; nInner++) {

			// if this element is in the required fields array, then check to see
			// if it is empty.  if so, alert and return false
			if (arrFieldNames[nInner] == objElement.name) {

				if (arrErrorMessage[nInner] != '') {
					strErrorMessage = arrErrorMessage[nInner];
				} else {
					strErrorMessage = objElement.name + ' is required.';
				}

                                if (objElement.type == "radio"){
                                  objRadioButtonGroup = eval('document.' + objForm.name + '.elements[\'' + objElement.name + '\']');
                                  objRadioButtonGroup[0].style.backgroundColor = '';
                                  objRadioButtonGroup[1].style.backgroundColor = '';
                                }
                                else {
				  objElement.style.backgroundColor = '';
				}
				if ((objElement.type == "text") && (objElement.value == "" || objElement.value == null)) {
					alert(strErrorMessage);
					objElement.style.backgroundColor = 'lightpink';
					objElement.focus();
					return false;
				} else if ((objElement.type == "textarea") && (objElement.value == "" || objElement.value == null)) {
					alert(strErrorMessage);
					objElement.style.backgroundColor = 'lightpink';
					objElement.focus();
					return false;
				} else if (objElement.type == "select-one" && objElement.selectedIndex == 0){
					alert(strErrorMessage);
					objElement.style.backgroundColor = 'lightpink';
					objElement.focus();
					return false;
				} else if (objElement.type == "select-multiple" && objElement.selectedIndex < 0){
					alert(strErrorMessage);
					objElement.style.backgroundColor = 'lightpink';
					objElement.focus();
					return false;
				} else if (objElement.type == "radio" && radioButtonFieldIsComplete(objForm,objElement.name) == false){
					alert(strErrorMessage);
                                        objRadioButtonGroup[0].style.backgroundColor = 'lightpink';
                                        objRadioButtonGroup[1].style.backgroundColor = 'lightpink';
					objElement.focus();
					return false;
				}
			}
		
		}

	}
	// if we made it all the way to the end, then there were no problems
	return true;
}

function radioButtonFieldIsComplete(objForm, strRadioGroupName) { 
	// this function accepts a form object and radio group name and
	// returns true if one radio button option is checked.
	
	// grab the button group object by combining the form name and group name
	objRadioButtonGroup = eval('document.' + objForm.name + '.elements[\'' + strRadioGroupName + '\']');
	// Loop from zero to the one minus the number of radio button selections
	for (var counter = 0; counter < objRadioButtonGroup.length; counter++) {
		// If a radio button has been selected it will return true
		if (objRadioButtonGroup[counter].checked) {
			return true;
		}
	}
	
	// if we made it this far, then none were checked
	return false;
}

// ____________________________________________________________________________
function findForm(txtFormName) {
   // This function is used by functions in this global.js to find the position
   //   of the form in the forms array of the document
   //      parameters:  txtFormName - form name whose array index to find
   //      returns:     position in forms array of specified form
   var i;

   // Loop through all the forms in the document and find the one passed 
   //   in as a parameter.  Return its position.
   for (i=0; i<document.forms.length; i++){
      if (document.forms[i].name==txtFormName){
         return i;
         }
      }
   }

// ____________________________________________________________________________
function findElement(nbrFormNum,txtElementName) {
   // This function is used by functions in this global.js to find the position
   //   of the specified element in the elements array of the specified form
   //      parameters:  nbrFromNum     - position in the forms array of the form to access
   //                   txtElementName - element whose array index to find
   var i;

   // Loop through all the elements on the specified form and find the one passed
   //   in as a parameter.  Return its position.
   for (i=0; i<document.forms[nbrFormNum].elements.length; i++){
      if (document.forms[nbrFormNum].elements[i].name==txtElementName){
         return i;
         }
      }
   }

// ____________________________________________________________________________
function replace(txtString,txtSrch,txtReplace) {
   // This function is used internally by functions in this file
   //   parameters:  txtString  - string within which to search for and replace text
   //                txtSrch    - text to be replaced
   //                txtReplace - text with which to replace txtSrch
   //   actions:     returns a string with txtSrch replaced by txtReplace
   var temp;
   var temp2;

   while (txtString.indexOf(txtSrch)>-1) {
      temp = txtString.substring(0,txtString.indexOf(txtSrch));
      temp2 = txtString.substring(txtString.indexOf(txtSrch)+1,txtString.length);
      txtString = temp+txtReplace+temp2;
      }
   return txtString;
   }


// ____________________________________________________________________________
function isWholeNum(txtnum) {
   // This function is used internally by functions in this file
   //   parameters:  txtnum - string to ensure includes only numbers
   //   actions:     returns true if only numbers are found within the string
   //                returns false if anything other than numbers are found
   var k;
   var mychar;

   // Make sure all the characters are numbers
   for (k = 0; k < txtnum.length; k++) {
      mychar = txtnum.charAt(k);
      if (mychar < "0" || mychar > "9") {
         return false;
      }
   }
   return true;
}


// ____________________________________________________________________________
function currencyAdd(txtFormName,txtElementName) {
   // This function is called by validateAll to add default values to the extra amounts 
   //   entered by the user
   //      parameters:  txtFormName    - name of form to access
   //                   txtElementName - element whose value is to be added
   //      actions:     displays an error message if the field contains an invalid currency
   var total;
   var elmVal;
   var defVal;
   var curFlag;
   var formNum;
   var totalNum;
   var defaultNum;
   var elementNum;
   var txtTotalName;

   txtTotalName = "TOT" + txtElementName.substring(3,txtElementName.length);
   txtDefaultName = "DEF" + txtElementName.substring(3,txtElementName.length);

   // Find the forms array position of the form parameter
   formNum=findForm(txtFormName);

   // Find the elements array position of the specified element
   elementNum=findElement(formNum,txtElementName);

   // Find the elements array position of the specified element
   totalNum=findElement(formNum,txtTotalName);

   // Find the elements array position of the specified element
   defaultNum=findElement(formNum,txtDefaultName);

   elmVal=document.forms[formNum].elements[elementNum].value;
   defVal=document.forms[formNum].elements[defaultNum].value;

   if (elmVal=="") {
      elmVal=0;
      }

   total = parseInt(elmVal) + parseInt(defVal);
   document.forms[formNum].elements[totalNum].value=total;
   }

// ____________________________________________________________________________
function checkPercentage(txtFormName,txtElementName) {
   // This function is called by the onBlur method of a field which should contain a numeric value
   //      parameters:  txtFormName    - name of form to access
   //                   txtElementName - element whose value should be a valid number
   //      actions:     displays an error message if the field contains an invalid number
   var i;
   var temp;
   var mychar;
   var txtnum;
   var formNum;
   var periodCount=0;

   // Find the forms array position of the form parameter
   formNum=findForm(txtFormName);

   // Find the elements array position of the specified element
   elementNum=findElement(formNum,txtElementName);

   txtnum=document.forms[formNum].elements[elementNum].value;

   // If it is empty, do nothing
   if (txtnum.length==0) {
      return 0;
      }

   // Count the number of decimals in the number
   temp=txtnum;
   while (temp.indexOf(".")>-1){
      temp=temp.substring(temp.indexOf(".")+1,temp.length);
      periodCount = periodCount + 1;
      }

   // if more than one decimal exists, it is not a valid number
   if (periodCount>1){
      alert("There are too many decimals.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   // Loop through all characters of the string and check for validity
   for (i = 0; i < txtnum.length; i++) {
      mychar = txtnum.charAt(i);
      // Make sure all the characters are numbers or the decimal.
      if ((mychar < "0" || mychar > "9") && mychar != ".") {
         alert("Please enter a valid percentage.");
         setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
         return -1;
         }
      }

   // Make sure the number is less than 100%
   if (parseInt(txtnum)>100) {
      alert("Please enter a percentage less than or equal to 100%.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }
   return 0;
   }



// ____________________________________________________________________________
function isValidDate(strFormName,strFieldName) {

// strFormName - form in which strFieldName resides
// strFieldName - is the field name used to reposition the cursor 
// on a validation failure.

var dateStr;
dateStr = eval("document." + strFormName + "." + strFieldName + ".value;");

if (dateStr.length < 1) {
	return true;
}

// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables


// Use this line to allow 2 and 4 digit years
//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
 var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
	alert("Please enter the date as mm/dd/yyyy.");
	eval("document." + strFormName + "." + strFieldName + ".focus();");
	return false;
}

month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];

if (month < 1 || month > 12) { // check month range
	eval("document." + strFormName + "." + strFieldName + ".focus();");
	alert("Month must be between 1 and 12.");
	return false;
}

if (day < 1 || day > 31) {
	eval("document." + strFormName + "." + strFieldName + ".focus();");
	alert("Day must be between 1 and 31.");
	return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	eval("document." + strFormName + "." + strFieldName + ".focus();");
	alert("Month "+month+" doesn't have 31 days!");
	return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
   if (day>29 || (day==29 && !isleap)) {
	eval("document." + strFormName + "." + strFieldName + ".focus();");
	alert("February " + year + " doesn't have " + day + " days!");
	return false;
   }
}

return true;  // date is valid
}

// ____________________________________________________________________________
function isNumber(txtFormName,txtElementName,txtFieldType) {
   // This function is called by the onBlur method of a field which should contain a numeric value
   //      parameters:  txtFormName    - name of form to access
   //                   txtElementName - element whose value should be a valid number
   //                   txtFieldType   - what type of field is being checked (used in error message)
   //      actions:     displays an error message if the field contains an invalid number
   var i;
   var dot;
   var dec;
   var temp;
   var mychar;
   var txtnum;
   var numPart;
   var periodCount=0;

   txtnum=eval("document." + txtFormName + "." + txtElementName + ".value");

   // If it is empty, do nothing
   if (txtnum.length==0) {
      return 0;
      }

   // Count the number of decimals in the number
   temp=txtnum;
   while (temp.indexOf(".")>-1){
      temp=temp.substring(temp.indexOf(".")+1,temp.length);
      periodCount = periodCount + 1;
      }

   // if more than one decimal exists, it is not a valid number
   if (periodCount>1){
      alert("There are too many decimals in this "+txtFieldType+".");
      eval("document." + txtFormName + "." + txtElementName + ".focus()");
      return -1;
      }

   // Strip out commas
   txtnum=replace(txtnum,",","");

   // Loop through all characters of the string and check for validity
   for (i = 0; i < txtnum.length; i++) {
      mychar = txtnum.charAt(i);
      // Make sure all the characters are numbers or the decimal.
      if ((mychar < "0" || mychar > "9") && mychar != ".") {
         alert("Please enter a valid "+txtFieldType+".");
         eval("document." + txtFormName + "." + txtElementName + ".focus()");
         return -1;
         }
      }
   dot=txtnum.indexOf(".");
   if (dot != -1) {
      dec=txtnum.substr(dot);
      numPart=txtnum.substr(0,dot);
      }
   else {
      dec="";
      numPart=txtnum;
      }

   // add commas in every 3 digits
   temp="";
   j=1;
   for (i=numPart.length-1; i>=0; i--) {
      temp=numPart.charAt(i)+temp;
      if (j%3==0) {
		 // this line adds the comma - commented out by jhinkle
         // temp=","+temp
         }
      j++;
      }
   if (temp.charAt(0)==",") {
      temp=temp.substr(1);
      }
   
   temp="\""+temp+dec+"\"";
   eval("document." + txtFormName + "." + txtElementName + ".value=" + temp);
   return 0;
   }



// ____________________________________________________________________________
function isAlphaNumeric(txtFormName,txtElementName) {
   // This function is called by the onBlur event of an email textbox
   //   parameters:  txtFormName    - name of form to access
   //                txtElementName - element whose value should be a valid email address
   //   actions:     displays an error message if the email address is invalid
   var k;
   var mychar;
   var txtVal;

   txtVal=eval("document." + txtFormName + "." + txtElementName + ".value");
   // if it is empty, do nothing
   if (txtVal.length==0) {
      return 0;
      }

   // make sure the characters are alphabetic or numeric
   for (k = 0; k < txtVal.length; k++) {
      mychar = txtVal.charAt(k);
      if (!((mychar >= "a" && mychar <= "z") || (mychar >= "A" && mychar <= "Z"))) {
         if (mychar < "0" || mychar > "9") {
            return -1;
            }
         }
      }
      return 1;
   }


// ____________________________________________________________________________
function currencyConvert(txtFormName,txtElementName) {
   // This function is called by the onBlur event of a currency control
   //   parameters:  txtFormName    - name of form to access
   //                txtElementName - element whose value should be a valid currency
   //   actions:     displays an error message if the field contains an invalid currency
   //                formats the element value to ####.## if it is valid
   var i;
   var j;
   var dot;
   var dec;
   var temp;
   var txtnum;
   var numPart;
   var elementNum;

   txtnum=eval("document." + txtFormName + "." + txtElementName + ".value");

   // if it is empty, do nothing
   if (txtnum.length==0) {
      return 0;
      }

   temp=txtnum;

   // if it is not a number, return (the error message is displayed from the isNumber function)
   if(isNumber(txtFormName,txtElementName,"currency")==-1) {
      return -1;
      }

   // take out commas
   txtnum=replace(txtnum,",","");

   dot=txtnum.indexOf(".");
   if (dot != -1) {
      numPart=txtnum.substr(0,dot);
      dec=txtnum.substr(dot);
      if (dec.length>3) {
         dec=dec.substr(0,3);
         }
      else if (dec.length==2) {
         dec=dec+"0";
         }
      else {
         dec=".00";
         }
      }
   else {
      numPart=txtnum;
      dec=".00";
      }

   temp="";
   j=1;
//   alert('1temp=' + temp);
   for (i=numPart.length-1; i>=0; i--) {
      temp=numPart.charAt(i)+temp;
      if (j%3==0) {
         temp=","+temp;
         }
      j++;
      }
//    alert('2temp=' + temp);
   if (temp.charAt(0)==",") {
      temp=temp.substr(1);
      }
//       alert('3temp=' + temp);
   temp="\""+temp+dec+"\"";
//      alert('4temp=' + temp);
   eval("document." + txtFormName + "." + txtElementName + ".value=" + temp);

   return 0;
   }



// ____________________________________________________________________________
function formatDate(txtFormName,txtElementName) {
   // This functions is called by the onBlur method of a date field
   //   parameters:  txtFormName    - name of form to access
   //                txtElementName - element whose value should be a valid date
   //   actions:     displays an error message if the date is invalid
   //                formats the element value to mm/dd/yyyy if it is valid
   var k;
   var leapCheck4;
   var leapCheck100;
   var leapCheck400;
   var month;
   var day;
   var year;
   var intMonth;
   var intDay;
   var intYear;
   var index1;
   var index2;
   var rest;
   var txtDate;
   var formNum;
   var leapYear;
   var elementNum;
   var goodSoFar = false;
   var month31Array = [1,3,5,7,8,10,12];
   var month30Array = [4,6,9,11];
   var separatorArray = ["-","/","."];

   // Find the forms array position of the form parameter
   formNum=findForm(txtFormName);

   // Find the elements array position of the specified element
   elementNum=findElement(formNum,txtElementName);

   txtDate=document.forms[formNum].elements[elementNum].value;

   // if it is empty, do nothing
   if (txtDate.length==0) {
      return 0;
      }

   // separate out the month, day, and year parts.  Make sure there are 2 separators in the string
   for(k=0;k<separatorArray.length;k++) {
      if (txtDate.indexOf(separatorArray[k])>-1) {
         index1=txtDate.indexOf(separatorArray[k]);
         month=txtDate.substring(0,index1);
         rest=txtDate.substring(index1+1,txtDate.length);
         if (rest.indexOf(separatorArray[k])>-1) {
            index2=rest.indexOf(separatorArray[k]);
            day=rest.substring(0,index2);
            year=rest.substring(index2+1,rest.length);
            goodSoFar=true;
            }
         else {
            alert("Please enter a valid date.  (ex. 1/3/1999)");
            setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
            return -1;
            }
         }
      }

   if (goodSoFar==false) {
      // an incorrect number of separators was used
      alert("Please enter a valid date.  (ex. 12/3/1999)");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   // check for appropriate entry lengths for month, day, and year
   if (year.length!=4) {
      if (year.length==2) {
      	 if (year<16) {
      	    year = "20" + year;
      	    }
      	 else {
      	    year = "19" + year;
      	    }
         }
      else {
         alert("Please enter a two or four digit year.");
         setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
         return -1;
         }
      }

   if (year<1900) {
      alert("Please enter a year after 1900.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }
   else if (month.length<1 || month.length>2) {
      alert("Please enter a valid month.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }
   else if (day.length<1 || day.length>2) {
      alert("Please enter a valid day.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   // make sure the month, day, and year contain only numbers
   if (isWholeNum(month)==false) {
      alert("Please enter a valid month.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   if (isWholeNum(day)==false) {
      alert("Please enter a valid day.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   if (isWholeNum(year)==false) {
      alert("Please enter a valid year.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   // For some reason parseInt("08") and parseInt("09") return 0, this will
   //  ensure the correct return of 8 and 9 respectively
   if (month=="08") {
      intMonth=8;
      }
   else if (month=="09") {
      intMonth=9;
      }
   else {
      intMonth=parseInt(month);
      }

   if (day=="08") {
      intDay=8;
      }
   else if (day=="09") {
      intDay=9;
      }
   else {
      intDay=parseInt(day);
      }

   // Make sure the month is valid and the day is not less than 1
   if (intMonth>12 || intMonth<1) {
      alert("Please enter a valid month.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }
   else if (intDay<1) {
      alert("Please enter a valid day.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   // set the leapyear flag
   leapCheck4 = year%4;
   leapCheck100 = year%100;
   leapCheck400 = year%400;

   if (leapCheck4==0) {
      if (leapCheck100==0) {
         if (leapCheck400==0) {
            leapYear=true;
            }
         else {
            leapYear=false;
            }
         }
      else {
         leapYear=true;
         }
      }
   else {
      leapYear=false;
      }

   // If the month contains 31 days, make sure the day is not greater than 31
   for(k=0;k<month31Array.length;k++) {
      if (intMonth==month31Array[k]) {
         if (intDay>31) {
            alert("This month contains only 31 days.");
            setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
            return -1;
            }
         }
      }

   // If the month contains 30 days, make sure the day is not greater than 30
   for(k=0;k<month30Array.length;k++) {
      if (intMonth==month30Array[k]) {
         if (intDay>30) {
            alert("This month contains only 30 days.");
            setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
            return -1;
            }
         }
      }

   // If the month is February and it is a leap year, make sure the day is not greater than 29
   if (intMonth==2 && leapYear==true && intDay>29) {
      alert("This month contains only 29 days.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   // If the month is February and it is not a leap year, make sure the day is not greater than 28
   if (intMonth==2 && leapYear==false && intDay>28) {
      alert("This month contains only 28 days in this non-leap year.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return -1;
      }

   // add leading zeros if needed
   if (month.length==1) {
      month = "0" + month;
      }

   if (day.length==1) {
      day = "0" + day;
      }
      
   // format the date
   txtDate=month+"/"+day+"/"+year;

   document.forms[formNum].elements[elementNum].value=txtDate;
   return 0;
   }


// ____________________________________________________________________________
function formatZip(txtFormName,txtElementName) {
   // This function is called by the onBlur method of a zip code control
   //   parameters:  txtFormName    - name of form to access
   //                txtElementName - element whose value should be a valid zip code
   //   actions:     displays an error message if the value cannot be a valid zip code
   //                formats the element value to ##### or #####-#### if it is valid
   var txtZip;
   var formNum;
   var elementNum;

   // Find the forms array position of the form parameter
   formNum=findForm(txtFormName);

   // Find the elements array position of the specified element
   elementNum=findElement(formNum,txtElementName);

   txtZip=document.forms[formNum].elements[elementNum].value;

   // if it is empty, do nothing
   if (txtZip.length==0) {
      return 1;
      }

   // remove any dashes and extra spaces
   txtZip=replace(txtZip,"-","");
   //added the next line on 6/11/01 - gdg
   txtZip = replace(txtZip," ","");

   // if each character is not a number, it is not valid
   if (isWholeNum(txtZip)==false) {
      alert("Please enter a valid Zip Code.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return 0;
      }

   // make sure it is either 5 or 9 digits and format accordingly
   if (txtZip.length==5) {
      document.forms[formNum].elements[elementNum].value=txtZip;
      return 1;
      }
   else if (txtZip.length==9) {
      txtZip=txtZip.substring(0,5);
      document.forms[formNum].elements[elementNum].value=txtZip;
      return 1;
      }
   else {
      alert("Please enter a valid Zip Code.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return 0;
      }
   }

// ____________________________________________________________________________
function formatPhone(txtFormName,txtElementName) {
   // This function is called by the onBlur method of a phone number control
   //   parameters:  txtFormName    - name of form to access
   //                txtElementName - element whose value should be a valid phone number
   //   actions:     displays an error message if the value cannot be a valid phone number
   //                formats the element value to ###-###-#### if it is valid
   var temp;
   var temp2;
   var temp3;
   var formNum;
   var txtPhone;
   var elementNum;

   // Find the forms array position of the form parameter
   formNum=findForm(txtFormName);

   // Find the elements array position of the specified element
   elementNum=findElement(formNum,txtElementName);

   txtPhone=document.forms[formNum].elements[elementNum].value;

   // if it is empty, do nothing
   if (txtPhone.length==0) {
      return;
      }

   // remove any dashes, perios, parenthesis, and spaces
   txtPhone=replace(txtPhone,"-","");
   txtPhone=replace(txtPhone,".","");
   txtPhone=replace(txtPhone,"(","");
   txtPhone=replace(txtPhone,")","");
   txtPhone=replace(txtPhone," ","");

   // if there are more than 10 numbers, it is not valid
   if (txtPhone.length!=10) {
      alert("Please enter a valid phone number along with the 3-digit area code.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return;
      }

   // if every character is not a number, it is not valid
   if (isWholeNum(txtPhone)==false) {
      alert("Please enter a valid phone number along with the 3-digit area code.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return;
      }

   // format the phone number
   temp=txtPhone.substring(0,3);
   temp2=txtPhone.substring(3,6);
   temp3=txtPhone.substring(6,txtPhone.length);
   txtPhone=temp+"-"+temp2+"-"+temp3;

   document.forms[formNum].elements[elementNum].value=txtPhone;
   }

// ____________________________________________________________________________
function formatSSN(txtFormName,txtElementName) {
   // This function is called by the onBlur method of an SSN control
   //   parameters:  txtFormName    - name of form to access
   //                txtElementName - element whose value should be a valid SSN
   //   actions:     displays an error message if the value cannot be a valid SSN
   //                formats the element value to ###-##-#### if it is valid
   var temp;
   var temp2;
   var temp3;
   var formNum;
   var txtSSN;
   var elementNum;

   // Find the forms array position of the form parameter
   formNum=findForm(txtFormName);

   // Find the elements array position of the specified element
   elementNum=findElement(formNum,txtElementName);

   txtSSN=document.forms[formNum].elements[elementNum].value;

   // if it is empty, do nothing
   if (txtSSN.length==0) {
      return;
      }

   // remove any dashes, perios, parenthesis, and spaces
   txtSSN=replace(txtSSN,"-","");
   txtSSN=replace(txtSSN,".","");
   txtSSN=replace(txtSSN,"(","");
   txtSSN=replace(txtSSN,")","");
   txtSSN=replace(txtSSN," ","");

   // if there are more than 10 numbers, it is not valid
   if (txtSSN.length!=9) {
      alert("Please enter a valid SSN.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return;
      }

   // if every character is not a number, it is not valid
   if (isWholeNum(txtSSN)==false) {
      alert("Please enter a valid SSN.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return;
      }

   // format the phone number
   temp=txtSSN.substring(0,3);
   temp2=txtSSN.substring(3,5);
   temp3=txtSSN.substring(5,txtSSN.length);
   txtSSN=temp+"-"+temp2+"-"+temp3;

   document.forms[formNum].elements[elementNum].value=txtSSN;
   }

// ____________________________________________________________________________
function formatFEIN(txtFormName,txtElementName) {
   // This function is called by the onBlur method of an SSN control
   //   parameters:  txtFormName    - name of form to access
   //                txtElementName - element whose value should be a valid SSN
   //   actions:     displays an error message if the value cannot be a valid SSN
   //                formats the element value to ###-##-#### if it is valid
   var temp;
   var temp2;
   var formNum;
   var txtFEIN;
   var elementNum;

   // Find the forms array position of the form parameter
   formNum=findForm(txtFormName);

   // Find the elements array position of the specified element
   elementNum=findElement(formNum,txtElementName);

   txtFEIN=document.forms[formNum].elements[elementNum].value;

   // if it is empty, do nothing
   if (txtFEIN.length==0) {
      return;
      }

   // remove any dashes, perios, parenthesis, and spaces
   txtFEIN=replace(txtFEIN,"-","");
   txtFEIN=replace(txtFEIN,".","");
   txtFEIN=replace(txtFEIN,"(","");
   txtFEIN=replace(txtFEIN,")","");
   txtFEIN=replace(txtFEIN," ","");

   // if there are more than 10 numbers, it is not valid
   if (txtFEIN.length!=9) {
      alert("Please enter a valid FEIN.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return;
      }

   // if every character is not a number, it is not valid
   if (isWholeNum(txtFEIN)==false) {
      alert("Please enter a valid SSN.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return;
      }

   // format the phone number
   temp=txtFEIN.substring(0,2);
   temp2=txtFEIN.substring(2,txtFEIN.length);
   txtFEIN=temp+"-"+temp2;

   document.forms[formNum].elements[elementNum].value=txtFEIN;
   }

// ____________________________________________________________________________
function validEmail(txtFormName,txtElementName) {
   // This function is called by the onBlur event of an email textbox
   //   parameters:  txtFormName    - name of form to access
   //                txtElementName - element whose value should be a valid email address
   //   actions:     displays an error message if the email address is invalid
   var k;
   var mychar;
   var txtVal;
   var formNum;
   var elementNum;
   var filter=/^.+@.+\..{2,4}$/;
   //this regexp below was taken from http://www.quirksmode.org/js/mailcheck.html
   //it appears to take many more possible email domains in to consideration
   //but we'll test it later when time allows
   // /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;


   // Find the forms array position of the specified form
   formNum=findForm(txtFormName);

   // Find the elements array position of the specified element
   elementNum=findElement(formNum,txtElementName);

   txtVal=document.forms[formNum].elements[elementNum].value;
   // if it is empty, do nothing
   if (txtVal.length==0) {
      return true;
      }

   if (!filter.test(txtVal)) {
      alert("Please enter a valid Email Address.");
      setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
      return false;
      }

   txtVal=replace(txtVal,"@","");
   txtVal=replace(txtVal,".","");
   txtVal=replace(txtVal,"-","");
   txtVal=replace(txtVal,"_","");

   // make sure the characters are alphabetic or numeric
   for (k = 0; k < txtVal.length; k++) {
      mychar = txtVal.charAt(k);
      if (!((mychar >= "a" && mychar <= "z") || (mychar >= "A" && mychar <= "Z"))) {
         if (mychar < "0" || mychar > "9") {
            alert("Please enter a valid Email Address.");
            setTimeout(function(){document.forms[formNum].elements[elementNum].focus();}, 100);
            return false;
            }
         }
      }
   return true;
   }

// ____________________________________________________________________________
function checkResourceAssignment(field) {
	var msg = "You cannot remove  this resource from your application because it is assigned to another resource in this application.";
	if (!field.checked) {
		alert(msg);
		return false;
	}
	return true;
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// JavaScript Calendar Component
// Author: Robert W. Husted  (robert.husted@iname.com)
// Date:   8/22/1999
// Modified Date: 11/30/1999
// Modified By:   Robert W. Husted
// Notes:  Added frameset support (changed reference for "newWin" to "top.newWin")
//         Also changed Spanish "March" from "Marcha" to "Marzo"
//         Fixed JavaScript Date Anomaly affecting days > 28
// 
// 
// 
// Usage:  Add the following lines of code to your page to enable the Calendar
//         component.
//
//
//         // THIS LINE LOADS THE JS LIBRARY FOR THE CALENDAR COMPONENT 
//
//         <SCRIPT LANGUAGE="JavaScript" SRC="calendar.js"></SCRIPT>
//
//
//
//         // THIS LINE IS USED IN CONJUNCTION WITH A FORM FIELD (myDateField) IN A FORM (myForm).
//         // Replace "myForm" and "myDateField" WITH THE NAME OF YOUR FORM AND INPUT FIELD RESPECTIVELY
//         // WINDOW OPTIONS SET THE WIDTH, HEIGHT, AND X/Y POSITION OF THE CALENDAR WINDOW 
//         // WITH TITLEBAR ON, ALL OTHER OPTIONS (TOOLBARS, ETC) ARE DISABLED BY DEFAULT
//
//         <A HREF="javascript:doNothing()" onClick="setDateField(document.myForm.myDateField);top.newWin = window.open('calendar.html','cal','dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes')">
//         <IMG SRC="calendar.gif" BORDER=0></A><font size=1>Popup Calendar</font>
//
//
// 
// Required Files:
//
//         calendar.js   - contains all JavaScript functions to make the calendar work
//
//         calendar.html - frameset document (not required if you call the showCalendar()
//                         function.  However, calling showCalendar() directly causes
//                         the Java Virtual Machine (JVM) to start which slows down the
//                         loading of the calendar.)
//
// 
// Files Generally Included:
//
//         calendar.gif  - image that looks like a little calendar
// 
//         yourPage.html - page that contains a form and a date field which implements 
//                         the calendar component
// 



// BEGIN USER-EDITABLE SECTION -----------------------------------------------------



// SPECIFY DATE FORMAT RETURNED BY THIS CALENDAR
// (THIS IS ALSO THE DATE FORMAT RECOGNIZED BY THIS CALENDAR)

// DATE FORMAT OPTIONS:
//
// dd   = 1 or 2-digit Day
// DD   = 2-digit Day
// mm   = 1 or 2-digit Month
// MM   = 2-digit Month
// yy   = 2-digit Year
// YY   = 4-digit Year
// yyyy = 4-digit Year
// month   = Month name in lowercase letters
// Month   = Month name in initial caps
// MONTH   = Month name in captital letters
// mon     = 3-letter month abbreviation in lowercase letters
// Mon     = 3-letter month abbreviation in initial caps
// MON     = 3-letter month abbreviation in uppercase letters
// weekday = name of week in lowercase letters
// Weekday = name of week in initial caps
// WEEKDAY = name of week in uppercase letters
// wkdy    = 3-letter weekday abbreviation in lowercase letters
// Wkdy    = 3-letter weekday abbreviation in initial caps
// WKDY    = 3-letter weekday abbreviation in uppercase letters
//
// Examples:
//
// calDateFormat = "mm/dd/yy";
// calDateFormat = "Weekday, Month dd, yyyy";
// calDateFormat = "wkdy, mon dd, yyyy";
// calDateFormat = "DD.MM.YY";     // FORMAT UNSUPPORTED BY JAVASCRIPT -- REQUIRES CUSTOM PARSING
//

calDateFormat    = "mm/dd/yyyy";


// CALENDAR COLORS
topBackground    = "white";         // BG COLOR OF THE TOP FRAME
bottomBackground = "white";         // BG COLOR OF THE BOTTOM FRAME
tableBGColor     = "black";         // BG COLOR OF THE BOTTOM FRAME'S TABLE
cellColor        = "lightgrey";     // TABLE CELL BG COLOR OF THE DATE CELLS IN THE BOTTOM FRAME
headingCellColor = "white";         // TABLE CELL BG COLOR OF THE WEEKDAY ABBREVIATIONS
headingTextColor = "black";         // TEXT COLOR OF THE WEEKDAY ABBREVIATIONS
dateColor        = "blue";          // TEXT COLOR OF THE LISTED DATES (1-28+)
focusColor       = "#ff0000";       // TEXT COLOR OF THE SELECTED DATE (OR CURRENT DATE)
hoverColor       = "darkred";       // TEXT COLOR OF A LINK WHEN YOU HOVER OVER IT
fontStyle        = "12pt arial, helvetica";           // TEXT STYLE FOR DATES
headingFontStyle = "bold 12pt arial, helvetica";      // TEXT STYLE FOR WEEKDAY ABBREVIATIONS

// FORMATTING PREFERENCES
bottomBorder  = false;        // TRUE/FALSE (WHETHER TO DISPLAY BOTTOM CALENDAR BORDER)
tableBorder   = 0;            // SIZE OF CALENDAR TABLE BORDER (BOTTOM FRAME) 0=none



// END USER-EDITABLE SECTION -------------------------------------------------------



// DETERMINE BROWSER BRAND
var isNav = false;
var isIE  = false;

// ASSUME IT'S EITHER NETSCAPE OR MSIE
if (navigator.appName == "Netscape") {
    isNav = true;
}
else {
    isIE = true;
}

// GET CURRENTLY SELECTED LANGUAGE
selectedLanguage = navigator.language;

// PRE-BUILD PORTIONS OF THE CALENDAR WHEN THIS JS LIBRARY LOADS INTO THE BROWSER
buildCalParts();



// CALENDAR FUNCTIONS BEGIN HERE ---------------------------------------------------



// SET THE INITIAL VALUE OF THE GLOBAL DATE FIELD
function setDateField(dateField) {

    // ASSIGN THE INCOMING FIELD OBJECT TO A GLOBAL VARIABLE
    calDateField = dateField;

    // GET THE VALUE OF THE INCOMING FIELD
    inDate = dateField.value;

    // SET calDate TO THE DATE IN THE INCOMING FIELD OR DEFAULT TO TODAY'S DATE
    setInitialDate();

    // THE CALENDAR FRAMESET DOCUMENTS ARE CREATED BY JAVASCRIPT FUNCTIONS
    calDocTop    = buildTopCalFrame();
    calDocBottom = buildBottomCalFrame();
}


// SET THE INITIAL CALENDAR DATE TO TODAY OR TO THE EXISTING VALUE IN dateField
function setInitialDate() {
   
    // CREATE A NEW DATE OBJECT (WILL GENERALLY PARSE CORRECT DATE EXCEPT WHEN "." IS USED AS A DELIMITER)
    // (THIS ROUTINE DOES *NOT* CATCH ALL DATE FORMATS, IF YOU NEED TO PARSE A CUSTOM DATE FORMAT, DO IT HERE)
    calDate = new Date(inDate);

    // IF THE INCOMING DATE IS INVALID, USE THE CURRENT DATE
    if (isNaN(calDate)) {

        // ADD CUSTOM DATE PARSING HERE
        // IF IT FAILS, SIMPLY CREATE A NEW DATE OBJECT WHICH DEFAULTS TO THE CURRENT DATE
        calDate = new Date();
    }

    // KEEP TRACK OF THE CURRENT DAY VALUE
    calDay  = calDate.getDate();

    // SET DAY VALUE TO 1... TO AVOID JAVASCRIPT DATE CALCULATION ANOMALIES
    // (IF THE MONTH CHANGES TO FEB AND THE DAY IS 30, THE MONTH WOULD CHANGE TO MARCH
    //  AND THE DAY WOULD CHANGE TO 2.  SETTING THE DAY TO 1 WILL PREVENT THAT)
    calDate.setDate(1);
}


// POPUP A WINDOW WITH THE CALENDAR IN IT
function showCalendar(dateField) {

    // SET INITIAL VALUE OF THE DATE FIELD AND CREATE TOP AND BOTTOM FRAMES
    setDateField(dateField);

    // USE THE JAVASCRIPT-GENERATED DOCUMENTS (calDocTop, calDocBottom) IN THE FRAMESET
    calDocFrameset = 
        "<HTML><HEAD><TITLE>JavaScript Calendar</TITLE></HEAD>\n" +
        "<FRAMESET ROWS='70,*' FRAMEBORDER='0'>\n" +
        "  <FRAME NAME='topCalFrame' SRC='javascript:parent.opener.calDocTop' SCROLLING='no'>\n" +
        "  <FRAME NAME='bottomCalFrame' SRC='javascript:parent.opener.calDocBottom' SCROLLING='no'>\n" +
        "</FRAMESET>\n";

    // DISPLAY THE CALENDAR IN A NEW POPUP WINDOW
    top.newWin = window.open("javascript:parent.opener.calDocFrameset", "calWin", winPrefs);
    top.newWin.focus();
}


// CREATE THE TOP CALENDAR FRAME
function buildTopCalFrame() {

    // CREATE THE TOP FRAME OF THE CALENDAR
    var calDoc =
        "<HTML>" +
        "<HEAD>" +
        "</HEAD>" +
        "<BODY BGCOLOR='" + topBackground + "'>" +
        "<FORM NAME='calControl' onSubmit='return false;'>" +
        "<CENTER>" +
        "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0>" +
        "<TR><TD COLSPAN=7>" +
        "<CENTER>" +
        getMonthSelect() +
        "<INPUT NAME='year' VALUE='" + calDate.getFullYear() + "'TYPE=TEXT SIZE=4 MAXLENGTH=4 onChange='parent.opener.setYear()'>" +
        "</CENTER>" +
        "</TD>" +
        "</TR>" +
        "<TR>" +
        "<TD COLSPAN=7>" +
        "<INPUT " +
        "TYPE=BUTTON NAME='previousYear' VALUE='<<'    onClick='parent.opener.setPreviousYear()'><INPUT " +
        "TYPE=BUTTON NAME='previousMonth' VALUE=' < '   onClick='parent.opener.setPreviousMonth()'><INPUT " +
        "TYPE=BUTTON NAME='today' VALUE='Today' onClick='parent.opener.setToday()'><INPUT " +
        "TYPE=BUTTON NAME='nextMonth' VALUE=' > '   onClick='parent.opener.setNextMonth()'><INPUT " +
        "TYPE=BUTTON NAME='nextYear' VALUE='>>'    onClick='parent.opener.setNextYear()'>" +
        "</TD>" +
        "</TR>" +
        "</TABLE>" +
        "</CENTER>" +
        "</FORM>" +
        "</BODY>" +
        "</HTML>";

    return calDoc;
}


// CREATE THE BOTTOM CALENDAR FRAME 
// (THE MONTHLY CALENDAR)
function buildBottomCalFrame() {       

    // START CALENDAR DOCUMENT
    var calDoc = calendarBegin;

    // GET MONTH, AND YEAR FROM GLOBAL CALENDAR DATE
    month   = calDate.getMonth();
    year    = calDate.getFullYear();


    // GET GLOBALLY-TRACKED DAY VALUE (PREVENTS JAVASCRIPT DATE ANOMALIES)
    day     = calDay;

    var i   = 0;

    // DETERMINE THE NUMBER OF DAYS IN THE CURRENT MONTH
    var days = getDaysInMonth();

    // IF GLOBAL DAY VALUE IS > THAN DAYS IN MONTH, HIGHLIGHT LAST DAY IN MONTH
    if (day > days) {
        day = days;
    }

    // DETERMINE WHAT DAY OF THE WEEK THE CALENDAR STARTS ON
    var firstOfMonth = new Date (year, month, 1);

    // GET THE DAY OF THE WEEK THE FIRST DAY OF THE MONTH FALLS ON
    var startingPos  = firstOfMonth.getDay();
    days += startingPos;

    // KEEP TRACK OF THE COLUMNS, START A NEW ROW AFTER EVERY 7 COLUMNS
    var columnCount = 0;

    // MAKE BEGINNING NON-DATE CELLS BLANK
    for (i = 0; i < startingPos; i++) {

        calDoc += blankCell;
	columnCount++;
    }

    // SET VALUES FOR DAYS OF THE MONTH
    var currentDay = 0;
    var dayType    = "weekday";

    // DATE CELLS CONTAIN A NUMBER
    for (i = startingPos; i < days; i++) {

	var paddingChar = "&nbsp;";

        // ADJUST SPACING SO THAT ALL LINKS HAVE RELATIVELY EQUAL WIDTHS
        if (i-startingPos+1 < 10) {
            padding = "&nbsp;&nbsp;";
        }
        else {
            padding = "&nbsp;";
        }

        // GET THE DAY CURRENTLY BEING WRITTEN
        currentDay = i-startingPos+1;

        // SET THE TYPE OF DAY, THE focusDay GENERALLY APPEARS AS A DIFFERENT COLOR
        if (currentDay == day) {
            dayType = "focusDay";
        }
        else {
            dayType = "weekDay";
        }

        // ADD THE DAY TO THE CALENDAR STRING
        calDoc += "<TD align=center bgcolor='" + cellColor + "'>" +
                  "<a class='" + dayType + "' href='javascript:parent.opener.returnDate(" + 
                  currentDay + ")'>" + padding + currentDay + paddingChar + "</a></TD>";

        columnCount++;

        // START A NEW ROW WHEN NECESSARY
        if (columnCount % 7 == 0) {
            calDoc += "</TR><TR>";
        }
    }

    // MAKE REMAINING NON-DATE CELLS BLANK
    for (i=days; i<42; i++)  {

        calDoc += blankCell;
	columnCount++;

        // START A NEW ROW WHEN NECESSARY
        if (columnCount % 7 == 0) {
            calDoc += "</TR>";
            if (i<41) {
                calDoc += "<TR>";
            }
        }
    }

    // FINISH THE NEW CALENDAR PAGE
    calDoc += calendarEnd;

    // RETURN THE COMPLETED CALENDAR PAGE
    return calDoc;
}


// WRITE THE MONTHLY CALENDAR TO THE BOTTOM CALENDAR FRAME
function writeCalendar() {

    // CREATE THE NEW CALENDAR FOR THE SELECTED MONTH & YEAR
    calDocBottom = buildBottomCalFrame();

    // WRITE THE NEW CALENDAR TO THE BOTTOM FRAME
    top.newWin.frames['bottomCalFrame'].document.open();
    top.newWin.frames['bottomCalFrame'].document.write(calDocBottom);
    top.newWin.frames['bottomCalFrame'].document.close();
}


// SET THE CALENDAR TO TODAY'S DATE AND DISPLAY THE NEW CALENDAR
function setToday() {

    // SET GLOBAL DATE TO TODAY'S DATE
    calDate = new Date();

    // SET DAY MONTH AND YEAR TO TODAY'S DATE
    var month = calDate.getMonth();
    var year  = calDate.getFullYear();

    // SET MONTH IN DROP-DOWN LIST
    top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;

    // SET YEAR VALUE
    top.newWin.frames['topCalFrame'].document.calControl.year.value = year;

    // DISPLAY THE NEW CALENDAR
    writeCalendar();
}


// SET THE GLOBAL DATE TO THE NEWLY ENTERED YEAR AND REDRAW THE CALENDAR
function setYear() {

    // GET THE NEW YEAR VALUE
    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;

    // IF IT'S A FOUR-DIGIT YEAR THEN CHANGE THE CALENDAR
    if (isFourDigitYear(year)) {
        calDate.setFullYear(year);
        writeCalendar();
    }
    else {
        // HIGHLIGHT THE YEAR IF THE YEAR IS NOT FOUR DIGITS IN LENGTH
        top.newWin.frames['topCalFrame'].document.calControl.year.focus();
        top.newWin.frames['topCalFrame'].document.calControl.year.select();
    }
}


// SET THE GLOBAL DATE TO THE SELECTED MONTH AND REDRAW THE CALENDAR
function setCurrentMonth() {

    // GET THE NEWLY SELECTED MONTH AND CHANGE THE CALENDAR ACCORDINGLY
    var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

    calDate.setMonth(month);
    writeCalendar();
}


// SET THE GLOBAL DATE TO THE PREVIOUS YEAR AND REDRAW THE CALENDAR
function setPreviousYear() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;

    if (isFourDigitYear(year) && year > 1000) {
        year--;
        calDate.setFullYear(year);
        top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE PREVIOUS MONTH AND REDRAW THE CALENDAR
function setPreviousMonth() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
    if (isFourDigitYear(year)) {
        var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

        // IF MONTH IS JANUARY, SET MONTH TO DECEMBER AND DECREMENT THE YEAR
        if (month == 0) {
            month = 11;
            if (year > 1000) {
                year--;
                calDate.setFullYear(year);
                top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
            }
        }
        else {
            month--;
        }
        calDate.setMonth(month);
        top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE NEXT MONTH AND REDRAW THE CALENDAR
function setNextMonth() {

    var year = top.newWin.frames['topCalFrame'].document.calControl.year.value;

    if (isFourDigitYear(year)) {
        var month = top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex;

        // IF MONTH IS DECEMBER, SET MONTH TO JANUARY AND INCREMENT THE YEAR
        if (month == 11) {
            month = 0;
            year++;
            calDate.setFullYear(year);
            top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        }
        else {
            month++;
        }
        calDate.setMonth(month);
        top.newWin.frames['topCalFrame'].document.calControl.month.selectedIndex = month;
        writeCalendar();
    }
}


// SET THE GLOBAL DATE TO THE NEXT YEAR AND REDRAW THE CALENDAR
function setNextYear() {

    var year  = top.newWin.frames['topCalFrame'].document.calControl.year.value;
    if (isFourDigitYear(year)) {
        year++;
        calDate.setFullYear(year);
        top.newWin.frames['topCalFrame'].document.calControl.year.value = year;
        writeCalendar();
    }
}


// GET NUMBER OF DAYS IN MONTH
function getDaysInMonth()  {

    var days;
    var month = calDate.getMonth()+1;
    var year  = calDate.getFullYear();

    // RETURN 31 DAYS
    if (month==1 || month==3 || month==5 || month==7 || month==8 ||
        month==10 || month==12)  {
        days=31;
    }
    // RETURN 30 DAYS
    else if (month==4 || month==6 || month==9 || month==11) {
        days=30;
    }
    // RETURN 29 DAYS
    else if (month==2)  {
        if (isLeapYear(year)) {
            days=29;
        }
        // RETURN 28 DAYS
        else {
            days=28;
        }
    }
    return (days);
}


// CHECK TO SEE IF YEAR IS A LEAP YEAR
function isLeapYear (Year) {

    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
        return (true);
    }
    else {
        return (false);
    }
}


// ENSURE THAT THE YEAR IS FOUR DIGITS IN LENGTH
function isFourDigitYear(year) {

    if (year.length != 4) {
        top.newWin.frames['topCalFrame'].document.calControl.year.value = calDate.getFullYear();
        top.newWin.frames['topCalFrame'].document.calControl.year.select();
        top.newWin.frames['topCalFrame'].document.calControl.year.focus();
    }
    else {
        return true;
    }
}


// BUILD THE MONTH SELECT LIST
function getMonthSelect() {

    // BROWSER LANGUAGE CHECK DONE PREVIOUSLY (navigator.language())
    // FIRST TWO CHARACTERS OF LANGUAGE STRING SPECIFIES THE LANGUAGE
    // (THE LAST THREE OPTIONAL CHARACTERS SPECIFY THE LANGUAGE SUBTYPE)
    // SET THE NAMES OF THE MONTH TO THE PROPER LANGUAGE (DEFAULT TO ENGLISH)

    // IF FRENCH
    if (selectedLanguage == "fr") {
        monthArray = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
    }
    // IF GERMAN
    else if (selectedLanguage == "de") {
        monthArray = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
    }
    // IF SPANISH
    else if (selectedLanguage == "es") {
        monthArray = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
    }
    // DEFAULT TO ENGLISH
    else {
        monthArray = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    }

    // DETERMINE MONTH TO SET AS DEFAULT
    var activeMonth = calDate.getMonth();

    // START HTML SELECT LIST ELEMENT
    monthSelect = "<SELECT NAME='month' onChange='parent.opener.setCurrentMonth()'>";

    // LOOP THROUGH MONTH ARRAY
    for (i in monthArray) {
        
        // SHOW THE CORRECT MONTH IN THE SELECT LIST
        if (i == activeMonth) {
            monthSelect += "<OPTION SELECTED>" + monthArray[i] + "\n";
        }
        else {
            monthSelect += "<OPTION>" + monthArray[i] + "\n";
        }
    }
    monthSelect += "</SELECT>";

    // RETURN A STRING VALUE WHICH CONTAINS A SELECT LIST OF ALL 12 MONTHS
    return monthSelect;
}


// SET DAYS OF THE WEEK DEPENDING ON LANGUAGE
function createWeekdayList() {

    // IF FRENCH
    if (selectedLanguage == "fr") {
        weekdayList  = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
        weekdayArray = ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'];
    }
    // IF GERMAN
    else if (selectedLanguage == "de") {
        weekdayList  = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
        weekdayArray = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'];
    }
    // IF SPANISH
    else if (selectedLanguage == "es") {
        weekdayList  = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];
        weekdayArray = ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'];
    }
    else {
        weekdayList  = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
        weekdayArray = ['Su','Mo','Tu','We','Th','Fr','Sa'];
    }

    // START HTML TO HOLD WEEKDAY NAMES IN TABLE FORMAT
    var weekdays = "<TR BGCOLOR='" + headingCellColor + "'>";

    // LOOP THROUGH WEEKDAY ARRAY
    for (i in weekdayArray) {

        weekdays += "<TD class='heading' align=center>" + weekdayArray[i] + "</TD>";
    }
    weekdays += "</TR>";

    // RETURN TABLE ROW OF WEEKDAY ABBREVIATIONS TO DISPLAY ABOVE THE CALENDAR
    return weekdays;
}


// PRE-BUILD PORTIONS OF THE CALENDAR (FOR PERFORMANCE REASONS)
function buildCalParts() {

    // GENERATE WEEKDAY HEADERS FOR THE CALENDAR
    weekdays = createWeekdayList();

    // BUILD THE BLANK CELL ROWS
    blankCell = "<TD align=center bgcolor='" + cellColor + "'>&nbsp;&nbsp;&nbsp;</TD>";

    // BUILD THE TOP PORTION OF THE CALENDAR PAGE USING CSS TO CONTROL SOME DISPLAY ELEMENTS
    calendarBegin =
        "<HTML>" +
        "<HEAD>" +
        // STYLESHEET DEFINES APPEARANCE OF CALENDAR
        "<STYLE type='text/css'>" +
        "<!--" +
        "TD.heading { text-decoration: none; color:" + headingTextColor + "; font: " + headingFontStyle + "; }" +
        "A.focusDay:link { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        "A.focusDay:hover { color: " + focusColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        "A.weekday:link { color: " + dateColor + "; text-decoration: none; font: " + fontStyle + "; }" +
        "A.weekday:hover { color: " + hoverColor + "; font: " + fontStyle + "; }" +
        "-->" +
        "</STYLE>" +
        "</HEAD>" +
        "<BODY BGCOLOR='" + bottomBackground + "'" +
        "<CENTER>";

        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE TABLE OUTLINES PROPERLY
        if (isNav) {
            calendarBegin += 
                "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'><TR><TD>";
        }

        // BUILD WEEKDAY HEADINGS
        calendarBegin +=
            "<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=" + tableBorder + " ALIGN=CENTER BGCOLOR='" + tableBGColor + "'>" +
            weekdays +
            "<TR>";


    // BUILD THE BOTTOM PORTION OF THE CALENDAR PAGE
    calendarEnd = "";

        // WHETHER OR NOT TO DISPLAY A THICK LINE BELOW THE CALENDAR
        if (bottomBorder) {
            calendarEnd += "<TR></TR>";
        }

        // NAVIGATOR NEEDS A TABLE CONTAINER TO DISPLAY THE BORDERS PROPERLY
        if (isNav) {
            calendarEnd += "</TD></TR></TABLE>";
        }

        // END THE TABLE AND HTML DOCUMENT
        calendarEnd +=
            "</TABLE>" +
            "</CENTER>" +
            "</BODY>" +
            "</HTML>";
}


// REPLACE ALL INSTANCES OF find WITH replace
// inString: the string you want to convert
// find:     the value to search for
// replace:  the value to substitute
//
// usage:    jsReplace(inString, find, replace);
// example:  jsReplace("To be or not to be", "be", "ski");
//           result: "To ski or not to ski"
//
function jsReplace(inString, find, replace) {

    var outString = "";

    if (!inString) {
        return "";
    }

    // REPLACE ALL INSTANCES OF find WITH replace
    if (inString.indexOf(find) != -1) {
        // SEPARATE THE STRING INTO AN ARRAY OF STRINGS USING THE VALUE IN find
        t = inString.split(find);

        // JOIN ALL ELEMENTS OF THE ARRAY, SEPARATED BY THE VALUE IN replace
        return (t.join(replace));
    }
    else {
        return inString;
    }
}


// JAVASCRIPT FUNCTION -- DOES NOTHING (USED FOR THE HREF IN THE CALENDAR CALL)
function doNothing() {
}


// ENSURE THAT VALUE IS TWO DIGITS IN LENGTH
function makeTwoDigit(inValue) {

    var numVal = parseInt(inValue, 10);

    // VALUE IS LESS THAN TWO DIGITS IN LENGTH
    if (numVal < 10) {

        // ADD A LEADING ZERO TO THE VALUE AND RETURN IT
        return("0" + numVal);
    }
    else {
        return numVal;
    }
}


// SET FIELD VALUE TO THE DATE SELECTED AND CLOSE THE CALENDAR WINDOW
function returnDate(inDay)
{

    // inDay = THE DAY THE USER CLICKED ON
    calDate.setDate(inDay);

    // SET THE DATE RETURNED TO THE USER
    var day           = calDate.getDate();
    var month         = calDate.getMonth()+1;
    var year          = calDate.getFullYear();
    var monthString   = monthArray[calDate.getMonth()];
    var monthAbbrev   = monthString.substring(0,3);
    var weekday       = weekdayList[calDate.getDay()];
    var weekdayAbbrev = weekday.substring(0,3);

    outDate = calDateFormat;

    // RETURN TWO DIGIT DAY
    if (calDateFormat.indexOf("DD") != -1) {
        day = makeTwoDigit(day);
        outDate = jsReplace(outDate, "DD", day);
    }
    // RETURN ONE OR TWO DIGIT DAY
    else if (calDateFormat.indexOf("dd") != -1) {
        outDate = jsReplace(outDate, "dd", day);
    }

    // RETURN TWO DIGIT MONTH
    if (calDateFormat.indexOf("MM") != -1) {
        month = makeTwoDigit(month);
        outDate = jsReplace(outDate, "MM", month);
    }
    // RETURN ONE OR TWO DIGIT MONTH
    else if (calDateFormat.indexOf("mm") != -1) {
        outDate = jsReplace(outDate, "mm", month);
    }

    // RETURN FOUR-DIGIT YEAR
    if (calDateFormat.indexOf("yyyy") != -1) {
        outDate = jsReplace(outDate, "yyyy", year);
    }
    // RETURN TWO-DIGIT YEAR
    else if (calDateFormat.indexOf("yy") != -1) {
        var yearString = "" + year;
        yearString = yearString.substring(2,4);
        outDate = jsReplace(outDate, "yy", yearString);
    }
    // RETURN FOUR-DIGIT YEAR
    else if (calDateFormat.indexOf("YY") != -1) {
        outDate = jsReplace(outDate, "YY", year);
    }

    // RETURN DAY OF MONTH (Initial Caps)
    if (calDateFormat.indexOf("Month") != -1) {
        outDate = jsReplace(outDate, "Month", monthString);
    }
    // RETURN DAY OF MONTH (lowercase letters)
    else if (calDateFormat.indexOf("month") != -1) {
        outDate = jsReplace(outDate, "month", monthString.toLowerCase());
    }
    // RETURN DAY OF MONTH (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("MONTH") != -1) {
        outDate = jsReplace(outDate, "MONTH", monthString.toUpperCase());
    }

    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat.indexOf("Mon") != -1) {
        outDate = jsReplace(outDate, "Mon", monthAbbrev);
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat.indexOf("mon") != -1) {
        outDate = jsReplace(outDate, "mon", monthAbbrev.toLowerCase());
    }
    // RETURN DAY OF MONTH 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("MON") != -1) {
        outDate = jsReplace(outDate, "MON", monthAbbrev.toUpperCase());
    }

    // RETURN WEEKDAY (Initial Caps)
    if (calDateFormat.indexOf("Weekday") != -1) {
        outDate = jsReplace(outDate, "Weekday", weekday);
    }
    // RETURN WEEKDAY (lowercase letters)
    else if (calDateFormat.indexOf("weekday") != -1) {
        outDate = jsReplace(outDate, "weekday", weekday.toLowerCase());
    }
    // RETURN WEEKDAY (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("WEEKDAY") != -1) {
        outDate = jsReplace(outDate, "WEEKDAY", weekday.toUpperCase());
    }

    // RETURN WEEKDAY 3-DAY ABBREVIATION (Initial Caps)
    if (calDateFormat.indexOf("Wkdy") != -1) {
        outDate = jsReplace(outDate, "Wkdy", weekdayAbbrev);
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (lowercase letters)
    else if (calDateFormat.indexOf("wkdy") != -1) {
        outDate = jsReplace(outDate, "wkdy", weekdayAbbrev.toLowerCase());
    }
    // RETURN WEEKDAY 3-DAY ABBREVIATION (UPPERCASE LETTERS)
    else if (calDateFormat.indexOf("WKDY") != -1) {
        outDate = jsReplace(outDate, "WKDY", weekdayAbbrev.toUpperCase());
    }

    // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR
    calDateField.value = outDate;

    // GIVE FOCUS BACK TO THE DATE FIELD
    calDateField.focus();

    // CLOSE THE CALENDAR WINDOW
    top.newWin.close();
}

// ____________________________________________________________________________
function CheckVin(vin) {
	var weight = 8;
	var total = 0;
	var length = 17;
	var final_value;

	var x = "12345678012345070923456789";
	
	if(!vin.value.length) {
		return;
	}

	if(vin.value.length < length) {
 		alert("VIN number is less than " + length + " characters");
 		setTimeout(function(){vin.select();}, 100);
		return;
	}
	if(vin.value.length > length) {
 		alert("VIN number is greater than " + length + " characters");
 		setTimeout(function(){vin.select();}, 100);
		return;
	}

	for (var t = 0; t < length; t++ ){
		switch (vin.value.charAt(t)) {
			case 'I':
			case 'O':
			case 'Q':
 			alert("VIN number contains invalid characters (I or O or Q).");
                        setTimeout(function(){vin.select();}, 100);
			return;
		}
		// if NOT alphanumeric
		if( ((vin.value.charCodeAt(t) < 48) || (vin.value.charCodeAt(t) > 90)) || ((vin.value.charCodeAt(t) < 57) && (vin.value.charCodeAt(t) > 65)) ) {
	 		alert("VIN number contains invalid characters.");
                        setTimeout(function(){vin.select();}, 100);
			return;
		}
	}

	//add the first 8 digits of the vin.value to total
	for (var i = 0; i < 7; i++) {
		if  ((vin.value.charCodeAt(i) - "A".charCodeAt(0)) <  0) {
			total+= (vin.value.charCodeAt(i)-"0".charCodeAt(0))*weight--;
		}
		else {
			total+= (x.charAt(vin.value.charCodeAt(i)-"A".charCodeAt(0)))*weight--;
		}
	}

	//add 8th position and takes into account that the weight factor is 10
	if  ((vin.value.charCodeAt(7) - "A".charCodeAt(0)) <  0) {
		total+= (vin.value.charCodeAt(7)-"0".charCodeAt(0))*10;
	}
	else {
		total+= (x.charAt((vin.value.charCodeAt(7)-"A".charCodeAt(0))))*10;
	}

	weight = 9;	//sets weight for calcultions of the second half of the vin.value

	//add the second half of the vin.value to total
	for(i = 9; i < length; i++) {
		if  ((vin.value.charCodeAt(i) - "A".charCodeAt(0)) <  0) {
			total+= (vin.value.charCodeAt(i)-"0".charCodeAt(0)) * weight--;
		}
		else {
			total+= (x.charAt(vin.value.charCodeAt(i)-"A".charCodeAt(0))) * weight--;
		}
	}

	final_value = total % 11;
	var tmp;

	if (vin.value.charCodeAt(8) == 'X') {
		tmp = 10;
	}
	else {
		tmp = vin.value.charCodeAt(8) - "0".charCodeAt(0);
	}

	//if final_value = the 9th position(the check digit) in the vin.value then it's a valid vin.value
	if ( final_value == tmp ) {
		return;
	}
	else  {
		alert("VIN number is not valid.");
		setTimeout(function(){vin.select();}, 100);
	}
}

function launchCenter(url, name, height, width) {
  var str = "scrollbars,height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  return window.open(url, name, str);
}

function removeElement(element,row) {
  row.parentNode.parentNode.parentNode.deleteRow(row.parentNode.parentNode.rowIndex);
  document.getElementById(element+'Count').value--;
  if (document.getElementById(element+'Count').value < 1){
    Hide(element);
  }
}
