function printPage(divId)
{
 // w=window.open('','','scrollbars=1,resizable,width=100,height=100,top=0,left=0')
 // w.document.write('<html><body onLoad="window.print();window.close();"><table>'+document.getElementById(divId).innerHTML+'</table></body></html>')
 // w.document.close();
 var strHTML = document.getElementById(divId).innerHTML;

strHTML = strHTML.replace(/<\s*img[^>]*>/gi,"");  //remove all image tags
strHTML = strHTML.replace(/<\s*a[^>]*>/gi,"<b>");  //remove all link tags
strHTML = strHTML.replace(/<\s*\/a[^>]*>/gi,"</b>");  //remove all link tags
strHTML = strHTML.replace(/<\s*script[^>]*>/gi,"<!--");  //remove all script tags
strHTML = strHTML.replace(/<\s*\/script[^>]*>/gi,"-->");  //remove all link tags
strHTML = strHTML.replace(/<\s*hr[^>]*>/gi,"");  //remove all hr tags
strHTML = strHTML.replace(/BACKGROUND:/gi,"");    //remove all background images
strHTML = strHTML.replace(/DISPLAY: none/gi,"");    //display coverage descriptions
strHTML = strHTML.replace(/<select/gi,"<select disabled='true'");    //display coverage descriptions
strHTML = strHTML.replace(/<input/gi,"<input disabled "); //remove input tags
//strHTML = strHTML.replace(/quote_header3/gi,"quote_print_header3");    //style adjustments
//strHTML = strHTML.replace(/yourquote_title1green/gi,"yourquote_print_title1green");
//strHTML = strHTML.replace(/yourquote_title2green/gi,"yourquote_print_title2green");
//strHTML = strHTML.replace(/yourquote_results_topL/gi,"yourquote_print_results_topL");
//strHTML = strHTML.replace(/yourquote_results_topR/gi,"yourquote_print_results_topR");
//strHTML = strHTML.replace(/border=0/gi,"border=1");    //remove all background images

strHTML = strHTML.replace(/bgColor=#e3f4f2/gi,"");    //display coverage descriptions
w=window.open('print.htm','','scrollbars=1,resizable,toolbar=1,menubar=1,top=0,left=0')
//w.document.write('<html><head><link rel="stylesheet" type="text/css" href="/css/stylesheet.css" /></head><body onLoad="window.print();setTimeout(window.close, 0)" style="background: white">'+strHTML+'</body></html>')
w.document.write('<html><head></head><body onLoad="window.print();setTimeout(\'window.close()\', 0)" ><img src="/images/amicalogo.gif">'+strHTML+'</body></html>')
w.document.close();

}

// ===================================================================================
// Function...: trimLeadingChar
// Description: removes the specified leading character
// Returns....: new string with leading characters removed
// ===================================================================================
function trimLeadingChar(inputString, trimChar)
{
  while(inputString.charAt(0) == trimChar)  // remove specified trim character
	inputString = inputString.substring(1, inputString.length);

  return inputString;
}

// ===================================================================================
// Function...: trim
// Description:Remove leading and trailing blanks from the parameter string. Returns
//             empty string if parameter string is all blanks.   Imbedded blanks will
//             not be removed.
// returns....:trimmed string
// ==================================================================================
function Trim(str) {
  var trimmedString = "";
  var firstNonBlankPos = 0;
  // find position of first non-blank character
  while ((firstNonBlankPos < str.length) && (str.charAt(firstNonBlankPos) == ' '))
			  {
			  ++firstNonBlankPos;
			  }

  var lastNonBlankPos  = str.length;
  // find position of last non-blank character
  while ((lastNonBlankPos > 0) && (str.charAt(lastNonBlankPos - 1) == ' ')) {
	--lastNonBlankPos;
  }
  // Extract substring starting at first non-blank and ending at last non-blank.
  if ( firstNonBlankPos  <  lastNonBlankPos ) {
  trimmedString = str.substring(firstNonBlankPos, lastNonBlankPos);
	  }
  return trimmedString;
}

// ===================================================================================
// Function...: isValidSSN
// Description: validates a social security number
// returns....: error code (boolean)
// ===================================================================================
function isValidSSN(ssn)
{
  var tmp = removeChar(ssn,"-");

  if(IsBlank(tmp))
  { return true; } //this is not a required field but input must be correct

  if (tmp.length != 9 || !isNumeric(tmp))
  {
	return false;
  }
  return true;
}



// ===================================================================================
// Function...: isLastCharNumber
// Description: determines if last character of string is numeric
// returns....: true or false
// ===================================================================================
function isLastCharNumber(s)
{
  var valid = "0123456789";
  var c = s.charAt(s.length - 1);
  if (valid.indexOf(c) == "-1")
	return false;
  return true;
}

// ===================================================================================
// Function...: isSplitState
// Description: determines if input value is a split state by its length
// returns....: true or false
// ===================================================================================
function isSplitState(s)
{
  if (s.length == 8)
	return true;
  else
	return false;
}

// ===================================================================================
// Function...: pipHelp
// Description: display pip help window
// ===================================================================================
function pipHelp(state)
{
  var pipUrl = "/AutoQuote/";
  var prefix = "AePipHelp";
  var suffix = ".htm";

  state = removeChar(state, " ");
  pipUrl = pipUrl + prefix + state + suffix;

  var pipWindow = window.open(pipUrl, "PipHelp", "width=400,height=500,status=no,scrollbars=yes,resizable=yes");
}

// ===================================================================================
// Function...: privacyHelp
// Description: display the privacy statement window
// ===================================================================================
function privacyHelp()
{
  var privacyUrl = "/aboutus/privacy/privacy.html";


  var privacyWindow = window.open(privacyUrl, "privacyHelp", "width=500,height=450,status=no,scrollbars=yes,resizable=yes,titlebar=yes");
}

// ===================================================================================
// Function...: buildPrivacyLink
// Description: Builds the HTML required to display the Privacy Pledge link.
// ===================================================================================
function buildPrivacyLink() {

	document.write("<p align='center'>");
	document.write("<a href='JavaScript:privacyHelp()'>Privacy Pledge</a>");
	document.write("</p>");

		}

// ===================================================================================
// Function...: askForHelp
// Description: displays the Amica Help Center window
// ===================================================================================
function askForHelp(chatState)
{
  var askForHelpUrl = "/chat/livehelp1.asp?state=" + chatState;

  var askForHelpWindow = window.open(askForHelpUrl, "askForHelp", "width=500,height=450,status=no,scrollbars=yes,resizable=yes,titlebar=yes");
}

// ===================================================================================
// Function...: removeChar
// Description: removes specified character from a string
// returns.....: new string without specified character
// ===================================================================================
function removeChar(str, c)
{
  var tempStr = "";
  for (var x = 0; x < str.length; x++)
  {
	if (str.charAt(x) != c)
	{
	  tempStr = tempStr + str.charAt(x);
	}
  }
  return tempStr;
}

// ===================================================================================
// Function...: isNumeric
// Description: determines if input string is numeric only (0-9)
// returns....: true or false
// ===================================================================================
function isNumeric(s)
{

	if (isNaN(s)){
		return false;
	}
  var validNumbers = "0123456789";


  for (var i=0; i < s.length; i++)
  {
	if (validNumbers.indexOf(s.charAt(i)) == "-1")
	  return false;
  }

  return true;
}
// ===================================================================================
// Function...: isMoney
// Description: determines if input string is (0-9 or ,.)
// returns....: true or false
// ===================================================================================
function isMoney(s)
{

  var validInput = "0123456789,";

  for (var i=0; i < s.length; i++)
  {
	if (validInput.indexOf(s.charAt(i)) == "-1")
	  return false;
  }

  return true;
}
// ===================================================================================
// Function...: isCharacter
// Description: determines if input string is character only (a-z)
// returns....: true or false
// ===================================================================================
function isCharacter(s)
{
  var validCharacters = "abcdefghijklmnopqrstuvwxyz";

  s = s.toLowerCase();

  for (var i=0; i < s.length; i++)
  {
	if (validCharacters.indexOf(s.charAt(i)) == "-1")
	  return false;
  }

  return true;
}

// ===================================================================================
// Function...: createYearSelect
// Description: The createYearSelect function will create a select list containing
// consecutive 4 digit years. There are 2 parameters: 1) the NAME of the list and
// 2) The beginning year. The first option created will always be blank with a
// value = "blank". The last option will always be the current year.
// returns....: A select list.
// ===================================================================================

function createYearSelect(sName, firstYear)
{
today = new Date();
theyear = today.getFullYear();

var iTheYear = parseInt(theyear, 10);

document.write('<select name="');
document.write(sName);
document.write('" size=1>');
document.write('<option value="blank"></option>');

for (var thisYear = firstYear; thisYear <= theyear; thisYear++) {
	var thisYear = "" + thisYear;

	document.write('<option value="');
	document.write(thisYear);
	document.write('">');
	document.write(thisYear);
	document.write('</option>');
}
document.write('</select>');
}

// ===================================================================================
// Function...: isValidEmail
// Description: The isValidEmail function accepts 2 parameters:
//              1.(str) is the e-mail address to be edited.
//              2. (showAlerts) indicates whether the caller wishes to use the alerts
//                  called by isValidEmail.
// return val.: True - valid address, False - invalid address
// ===================================================================================

function isValidEmail(str, strCompare)
{

	var tmp = eval("document.getElementById('" + strCompare + "').value");
	//alert("in isvalidemail str = " + str + " compare = " + tmp);

	if(str != tmp)
	{
	  return false;
	}

	var address =  str;
   	address = Trim(address);
	address = address.toUpperCase();

	if (!isValidEmailFormat(address))
	{
		return false;
	}

	return true;
}

// ===================================================================================
// Function...: isValidEmailFormat
// Description: Validates that the email address is in an appropriate email address
//              format.
// ===================================================================================
function isValidEmailFormat(address) {

	//Check for the correct format of the email address based upon RFC 2822 rules
	var pattern = /^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i;

	if (!pattern.test(address))
	{
		return false;
	}

	return true;
}



// ===================================================================================
// Function...: IsBlank
// Description: Returns true if str is null, undefined or ""
// ===================================================================================
function IsBlank(str)
{

	 	var isValid=false;
	 	if (str+""=="null" || str+""=="undefined" || (str+""==""))
			isValid=true;
			//alert(isValid);
		return isValid;
	 }

// ===================================================================================
// Function...: isNotAlphaNumber
// Description: determines if input string is not at least one letter and one number
// returns....: true (if does not contain both) or false (if contains both)
// ===================================================================================
function isNotAlphaNumber(s)
{
  var validLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var validNumbers = "0123456789";

  for (var i=0; i < s.length; i++)
  {
	if (validLetters.indexOf(s.charAt(i)) != "-1")  //finds a letter - now check for a number
	{
		for (var n=0; n < s.length; n++)
		{
			 if (validNumbers.indexOf(s.charAt(n)) != "-1")  //finds a number - string is valid
			 {
				  return false;
			   }
		}
		return true;
	}
  }
  return true;
}



// ===================================================================================
// Function...: isAlphabetic
// Description: determines if input string is alphabetic, periods,hyphens, and blanks are also valid.
// returns....: true or false
// ===================================================================================
function IsAlphabetic(s)
{
  var validCharacters = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz .-";

  for (var i=0; i < s.length; i++)
  {
	if (validCharacters.indexOf(s.charAt(i)) == "-1")
	  return false;
  }

  return true;
}

// ===================================================================================
// Function...: isAlphaPeriodOrBlank
// Description: determines if input string is alphabetic, periods,hyphens, and blanks are also valid.
// returns....: true or false
// ===================================================================================
function isAlphaPeriodOrBlank(s)
{
  var validCharacters = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz . ";

  for (var i=0; i < s.length; i++)
  {
	if (validCharacters.indexOf(s.charAt(i)) == "-1")
	  return false;
  }

  return true;
}

// ===================================================================================
// Function...: isAlpha
// Description: Allows only letters (A - Z) either upper or lower case
// ===================================================================================
function IsAlpha(str) {
		var a;
		var b;
		var isValid=true;
		var fillblank=escape(str);
		while(fillblank.indexOf("%")!=-1) {
			a= fillblank.substring(0,fillblank.indexOf("%"));
			b= fillblank.substring(fillblank.indexOf("%")+3);
			fillblank=a + b;
		}

		for (i=0;i<fillblank.length;i++) {
			if (!(((fillblank.charAt(i) >= "a") && (fillblank.charAt(i) <= "z")) ||
						((fillblank.charAt(i) >= "A") && (fillblank.charAt(i) <= "Z"))) ) {
				isValid=false;
				break;
			}
		}
		return isValid;
	 }

// ===================================================================================
// Function...: isZipCode
// Description: validates a zip code
//                        Returns true if val is a 5 digit ZIP code
//                       or a 9 digit ZIP code in the format
//                       xxxxx-xxxx. Returns false otherwise.
// ===================================================================================
function isZipCode(val) {


				  var len;
				  if (val.length == 5)
						  len = 5;
				  else if (val.length == 10)
						  len = 10;
				  else
						  {
					   //   alert("Zip code entered is invalid");
						  return false;
						  }
				  var test = "0123456789";
				  //First 5 characters must all be digits.
				  for (var i = 0; i < 5; i++)
				  {
				  if (test.indexOf(val.charAt(i)) < 0)
						  {
					 //     alert("Zip code must be numeric");
						  return false;
						  }
				  }
				  //If a 5 digit ZIP we're done.
				  if (len == 5)
						  return true;
				  //The sixth character must be "-".
				  if (val.charAt(5) != '-')
						  {
					   //   alert("Zip code entered is invalid");
						  return false;
						  }
				  //The last 4 characters must be digits.
		  for (var i = 6; i < 10; i++) {
						  if (test.indexOf(val.charAt(i)) < 0)
								  {
							  //    alert("Zip code must be numeric");
								  return false;
								  }
				  }
				  return true;
  }


// ===================================================================================
// Function...: IsBlank
// Description: Returns true if str is null, undefined or ""
// ===================================================================================
function IsBlank(str)
{
	 	var isValid=false;
	 	if (str+""=="null" || str+""=="undefined" || (str+""==""))
			isValid=true;
		return isValid;
	 }

// ===================================================================================
// Function...: isValidPhone
// Description: validates a phone/fax number
// ===================================================================================
function isValidPhone(str) {
		var validPhone=false;
		var newstr=escape(str);
		var a;
		var b;
		while(newstr.indexOf("%")!=-1) {
			a= newstr.substring(0,newstr.indexOf("%"));
			b= newstr.substring(newstr.indexOf("%")+3);
			newstr=a + b;
		}
		while(newstr.indexOf("-")!=-1) {
			a= newstr.substring(0,newstr.indexOf("-"));
			b= newstr.substring(newstr.indexOf("-")+1);
			newstr=a + b;
		}
		while(newstr.indexOf("(")!=-1) {
			a= newstr.substring(0,newstr.indexOf("("));
			b= newstr.substring(newstr.indexOf("(")+1);
			newstr=a + b;
		}
		while(newstr.indexOf(")")!=-1) {
			a= newstr.substring(0,newstr.indexOf(")"));
			b= newstr.substring(newstr.indexOf(")")+1);
			newstr=a + b;
		}

		if (isNumber(newstr)) {
			if (newstr.length < 10) {
				//You must include your Area Code and hence 
				//Phone number is not of 10 digit length, but is numeric
				validPhone=false;
			}
			else {
				validPhone=true;
			}
		}
		else {
			validPhone=false;
		}

		return validPhone;
	}

// ===================================================================================
// Function...: isNumber
// Description:Returns true if val is a number defined as having an optional leading + or -.
//                       having at most 1 decimal point. otherwise containing only the characters 0-9.
// ===================================================================================
function isNumber(val) {
		  var test1 = ".+-0123456789"
		  var test2 = ".0123456789"
		  var c
		  var decimal = false
		  //The first character can be + - . or a digit.
		  c = test1.indexOf(val.charAt(0))
		  //Was it a decimal?
		  if (c == 0)
		  decimal = true
		  else if (c < 1)
				  return false

		  //Remaining characters can be only . or a digit, but only one decimal.
		  for (var i = 1; i < val.length; i++) {
				  c = test2.indexOf(val.charAt(i))
				  if (c < 0)
						  return false
				  else
						  if (c == 0)     {
								  if (decimal)            // Second decimal.
										  return false
								  else
										  decimal = true
						  }
		  }
		  return true
  }

// ===================================================================================
// Function...: changeContent
// Description: dynamically change the content of an HTML ID element
// ===================================================================================
function changeContent(what,text) {

	   what.innerHTML = text;
  }

//*************************************************************************************
function IsAddress(elementName)
{

   var v = elementName.toLowerCase();

   var validCharacters = " abcdefghijklmnopqrstuvwxyz0123456789.-";
   for (var i=0; i < v.length; i++)
   {
	 if (validCharacters.indexOf(v.charAt(i)) == "-1")
	 {
		 return false;
	 }
   }

	//check for p o box before removing ' ' in case street name is po box
	if ( (v.indexOf("po box") != -1) || (v.indexOf("p o box") != -1) || (v.indexOf("p.o. box") != -1) || (v.indexOf("p.o.box") != -1) )
	{

	  return false;
	}
	else
	{
	  for(var a=0; a < elementName.length; a++)
	  {
		v=v.replace(' ','');
	  }
	  for(var b=0; b<=9; b++)
	  {
		 if( ((v.charAt(0)=='b' || v.charAt(0)=='p') && (v.indexOf("box "+b) != -1)) )
		 {

		   return false;
		 }
	  }
	 }

	 return true;

}

/*
modified from File. . . . . : AeDateFucntions.js
Description . : Date related functions
Created . . . : 7/07
Modified. . . : <date>		<description>
*/

// ===================================================================================
// Function...: isValidDate
// Description: checks to see if the mm, dd, or yy field passed makes up a valid date
// when combined with the other individual mm or dd or yy text fields
// ===================================================================================
function isValidDOB(xObj)
{

if(isNaN(xObj.value))
{
  return false;
}

var xObjName = xObj.name;
var pfx = xObjName.substring(0,xObjName.length-3);
var datePart = xObjName.substring(xObjName.length-3,xObjName.length-1);
var idx = xObjName.substring(xObjName.length-1);
  var error = 0;

 switch(datePart)
 {
   case "Mo":
				var month = xObj.value;
				//month = removeChar(month, "0");
				var day = eval("document.getElementById('" + pfx + "Da" + idx + "').value");
				var year = eval("document.getElementById('" + pfx + "Yr" + idx + "').value");

				  if (month < 1 || month > 12)
					error = 1;

				  if (month == 4 || month == 6 || month == 9 || month == 11)
				  {
					 if (day == 31)
					  error = 1;
				  }

				  if (month == 2)
				  {
					if (isLeapYear(year))
					{
					  if (day > 29)
					  {
						 error = 1;
					   }
					}
					else
					{
					   if (day > 28)
					   {
						error = 1;
					   }
					}
				  }


				break;
   case "Da":
				var day = xObj.value;

				  if (day < 1 || day > 31)
					error = 1;

				break;
   case "Yr":
				var month = eval("document.getElementById('" + pfx + "Mo" + idx + "').value");
				var day = eval("document.getElementById('" + pfx + "Da" + idx + "').value");
				var year = xObj.value;

				 if(document.getElementById('curYear'))
				 {
				  var cyear = document.getElementById('curYear').value;
				 }
				 if(document.getElementById('today'))
				 {
				  var cdate = new Date(document.getElementById('today').value);
				  var cmonth = cdate.getMonth();
				  var cday = cdate.getDate();
				 }


				  if(cyear - year > 95 || cyear - year < 15)  //no one <15 or > 95
				  {
				   error = 1;
				  }

				  if(cyear - year == 15)  //test month/day to be sure at least 15 as of cur date
				  {

				   if(cmonth + 1 < month)
				   {
					 error = 1;
				   }
				   if((cmonth + 1) == month && cday < day)
				   {
					 error = 1;
				   }

				  }


				break;
   default:
				break;
 }


  if (error == 1)
	return false;
  else
	return true;
}






// ===================================================================================
// Function...: isLeapYear
// Description: checks to see if year passed is a leap year
// ===================================================================================
function isLeapYear(y)
{
  if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
	return true;
  else
	return false;
}





// ===============================================================================================
// Function...: isValidRoutingNumber
// Description: Validates that the bank routing number is in a valid format.
// ===============================================================================================
 function isValidRoutingNumber(routingNumber) {

 	var runningSum = 0;

	for (var a = 0; a < routingNumber.length; a+=3)
	{
		runningSum += (parseInt(routingNumber.charAt(a))*3) + (parseInt(routingNumber.charAt(a+1))*7) + (parseInt(routingNumber.charAt(a+2)));
	}

	if ((runningSum % 10) != 0) {
		return false;
	}

	return true;
 }

// ===============================================================================================
// Function...: isEmpty
// Description: Checks to see if the object's length is greater than 0.
// ===============================================================================================
	function isEmpty(object,text)
	{
		if(!object.value.length > 0)
		{
			return true;
		}
		else
		{
			if(navigator.appName.indexOf('Netscape') > -1)
			{
				object.focus();
			}
			return false;
		}
	}//end isEmpty


// ===============================================================================================
// Function...: newWindow
// Description: Opens a new window.
// ===============================================================================================
	function newWindow(file,rwindow)
	{
		var wname=window.open(file,rwindow,'status=yes,resizable=yes,scrollbars=yes,width=600,height=500,left=10,top=50');
	}

	function submitOnEnter(myForm,e) {
		var keycode;
		if(window.event) {
			keycode = window.event.keyCode;
		}
		else if(e) {
			keycode = e.which;
		};
		if(keycode == 13) {
			return true;
		}
		return false;
	}
//*************************************************************************************
//Changes the color of the label for elementName to red. Using span tags on the page for labels.
//*************************************************************************************
function turnToRed(elementName){
	var errorMsg ="Items in red that are incomplete, must be completed.  Items in red that are complete, contain invalid data.";
	var errorMsgObj = document.getElementById("errorMsg");
	var x = eval("document.getElementById('t" + elementName + "')");
    if(x){
	x.className ="error_font_color";
	errorMsgObj.innerHTML = errorMsg;
	errorMsgObj.className ="error_font_color";
   }
}
//***************************************************************************************
// Gets an error message and displays it on the page 
//***************************************************************************************
function errorMsgCreator(tempErrorMsg){
	var errorMsg = tempErrorMsg + "<br/>";
	var errorMsgObj = document.getElementById("errorMsg");
	errorMsgObj.innerHTML = errorMsg;
	errorMsgObj.className ="error_font_color";
}

//*************************************************************************************
function resetReqFields(elementName){
	var x = eval("document.getElementById('t" + elementName + "')");
	if(x){
	  x.className ="default_font_color";
	}
}

// ===================================================================================
// Function...: cleanInput
// Description: removes undesirable characters from field input
// ===================================================================================
function cleanInput(xField,iWant)
{

   switch(iWant)
   {
	 case "Integer":
	   var xVal = xField.value;
	   var tmp = ""
	   var xDecAt = xVal.indexOf(".");
	   if(xDecAt > -1)
	   {
		 xVal = xVal.substring(0,xDecAt);
	   }
	   var validNumbers = "0123456789";
	   for (var i=0; i < xVal.length; i++)
	   {
		 if (validNumbers.indexOf(xVal.charAt(i)) != "-1")
		 {
		   tmp += xVal.charAt(i);
		 }

	   }
	   break;
   }
   xField.value = tmp;
 }

/************************************************************************************
function zipCodeJump is used for autoskip
zip code can't use generic jumpToField()function because the next field to jump to
can change dynamically
currently DC is the only state that does not ask for county
some states don't ask for SSN: CA, FL, GA, MD, MA, MI, NJ, NY, VT
if county were removed, we would no jump at all for the above states
*************************************************************************************/

	function zipCodeJump(){
		var nextFieldId = "";
		var zip = Trim(document.HomeYourInfo.dwellingZipCode.value);

		if(zip.length == 5){
			if(document.getElementById("county") != null){
				nextFieldId = "county";
			}else if(document.getElementById("SocialSecurityNumber") != null){
				nextFieldId = "SocialSecurityNumber";
			}
			if(nextFieldId != ""){
				document.getElementById(nextFieldId).focus();
			}
		}

	}
	
	
	
//**********************************************************************************************************
// This function will determine the number of years a driver has been driving based on the current date 
// and the date in which they obtained their drivers license.
// An indicator of 0 in this function will return the difference between the current date and license date. If
// the licensed date is greater than the current date, a -1 will be returned which will fail this routine.
//**********************************************************************************************************
function yearsDriving(todaysDate, licenseDt, indicator)
{

	difference = (parseInt(todaysDate) - parseInt(licenseDt)).toString();
	
	
	// indicator 0 is to make sure that the licenseDate is not greater than today's date. This would be applicable for
	// all drivers. 
	if (indicator == 0)
	{
		if (difference < 0)
		{
			return -1;
		}
		else
		{
			return 1;
		}
	}

	if (Trim(difference).length == 6)
		return difference.substr(0,2);
	else if (Trim(difference).length == 5)
		return difference.substr(0,1);
	else if (Trim(difference).length == 7)
		return difference.substr(0,3);
	else if (Trim(difference).length == 4)
		return 0;

}

/*
Compares the two dates. Dates formats should be MM/DD/YY or MM/DD/YYYY
Returns 0 if dates are same
Returns -1 if date1 is prior to another date
Returns 1 if date1 is after another date.
@author Rajendra Anaganti
*/
function compareDates(date1, anotherDate) {
	var returnValue="";
	var date1Year = Trim(date1.substring(6));
	var anotherDateYear = Trim(anotherDate.substring(6));
	if (date1Year < anotherDateYear) {
		//alert("year is lesser");
		returnValue =  -1;

	} else if (date1Year > anotherDateYear) {
		//alert("year is greater");
		returnValue = 1;

	} else {//years are same

		var date1Month = date1.substring(0,2);
		var anotherDateMonth = anotherDate.substring(0,2);
		if (date1Month < anotherDateMonth) {
			//alert("month is lesser");
			returnValue = -1;

		} else if (date1Month > anotherDateMonth) {
			//alert("month is greater");
			returnValue = 1;

		} else {//months are same

			var date1Day = date1.substring(3,5);
			var anotherDateDay = anotherDate.substring(3,5);

			if (date1Day < anotherDateDay) {
				//alert("day is lesser");
				returnValue = -1;

			} else if (date1Day > anotherDateDay) {
				//alert("day is greater");
				returnValue = 1;

			} else {
				//alert("dates are same");
				returnValue = 0;
			}
		}			
	}

	return returnValue;
}


/*************************************************************************************
function isUnsignedNumeric checks if the value returned is a number having at most 1 
decimal point. It can be a number containing only the characters 0-9, without decimal 
point.  + or - is not allowed. 
*************************************************************************************/
function isUnsignedNumeric(value) {
		  var test = ".0123456789";
		  var c;
		  var decimal = false;
		  
		  c = test.indexOf(value.charAt(0))
		 
		  
		  if (c == 0)
		  decimal = true
		  else if (c < 1)
				  return false

		  
		  for (var i = 1; i < value.length; i++) {
				  c = test.indexOf(value.charAt(i))
				  if (c < 0)
						  return false
				  else
						  if (c == 0)     {
								  if (decimal)            
										  return false
								  else
										  decimal = true
						  }
		  }
		  return true
  }
