function new_window(url)
{
	link = window.open(url,"Link","toolbar=yes,location=0,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=yes,width=640,height=480,left=100,top=100");
}
function kiosk_window(url)
{
	KioskLink = window.open(url,"KioskLink","addressbar=no,toolbar=no,location=0,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=yes,width=640,height=480,left=100,top=100");
}
function splash_window(url)
{
	link = window.open(url,"splash","addressbar=yes,toolbar=yes,location=1,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=no,width=640,height=430,left=100,top=100");
}
function new_miniwindow(url) 
{
	link = window.open(url,"Link","toolbar=yes,location=0,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=yes,width=320,height=240,left=100,top=100");
}
function new_fdic_window(url) 
{
	var link = window.open(url,"Link","toolbar=yes,location=0,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=500,left=100,top=100");
}
function new_mortgage_window(url)
{
	var link = window.open(url,"Link","toolbar=yes,location=0,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=yes,width=900,height=500,left=100,top=100");
}
function new_leadcapture_window(url)
{
	var link = window.open(url,"Link","toolbar=yes,location=0,directories=0,status=0,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=600,left=100,top=100");
}

function lNavGetTotalHeight() {
	var retVal = 0;
	//Modified due to increase in menu options
	for(i=0;i<21;i++) {//21 because there are a total of 21 options. If new is added this number will be changed accordingly.
		retVal += 18;
	}
	return retVal;
}
function lNavCreateCurve() {
	var leftOverHeight = (lNavGetTotalHeight() - 110 +50 + 10)
	var defaultLeft = (navigator.userAgent.indexOf('Mac') != -1) ? 135 : 136;
	var defaultTop = (navigator.userAgent.indexOf('Mac') != -1) ? 25 : 28;
	var objHTML;
	objHTML = '<div id="leftNavCurve" name="leftNavCurve" style="position:absolute; left:' + defaultLeft + 'px; top:' + defaultTop + 'px; z-index:1; visibility: visible">';
	objHTML += '		<table width="16" border="0" cellspacing="0" cellpadding="0" >';
	objHTML += '		<tr><td>';
	
	objHTML += '		<table border="0" width="16" cellpadding="0" cellspacing="0" >';
	objHTML += '			<tr>';
	objHTML += '				<td width="16"><img src="images/left_nav/side_curve2.gif" height="110" width="16"></td>';
	objHTML += '			</tr>';
	objHTML += '			<tr>';
	objHTML += '				<td width="16" height="' + leftOverHeight + '" bgColor="#FFFFFF"><img src="images/shared/pixel.gif" height="' + leftOverHeight + '" width="16"></td>';
	objHTML += '			</tr>';
	objHTML += '		</table>'
	objHTML += '		</td></tr>';
	objHTML += '		</table>';
	objHTML += '</div>';
	return objHTML;	
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
}
function splitDate(dtStr, returnStr) {
	var pos1=dtStr.indexOf("/")
	var pos2=dtStr.indexOf("/",pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	var returnVal = null;
	if (returnStr == 'D') {
		returnVal = strDay
	}
	else if (returnStr == 'M') {
		returnVal = strMonth
	}
	else if (returnStr == 'Y') {
		returnVal = strYear
	}
	return returnVal
}

/**
 * Autoformatting function for dates based on MetLife guidelines
 */
var dateSeparatorsArray = [" ", "-", "\\."];
function formatDate(dateElement) {
	var dateString = Trim(dateElement.value);
	var dateStringLength = dateString.length;
	var newDateString = dateString;
	// If "/" exists in the string, assume no seperator processing needed
	if (newDateString.indexOf("/") < 0) {
		if (dateStringLength == 4) {
			// Assume mdyy
			newDateString = dateString.substr(0,1) + "/" + dateString.substr(1,1) + "/" + dateString.substr(2,2);		
		} else if (dateStringLength == 5) {
			// Assume mmdyy
			newDateString = dateString.substr(0,2) + "/" + dateString.substr(2,1) + "/" + dateString.substr(3,2);		
		} else {
			// Loop through and replace all defined special characters with a "/"
			for (var i = 0; i < dateSeparatorsArray.length; i++) {
				newDateString = newDateString.replace(new RegExp(dateSeparatorsArray[i], "g"), "/");
			}
			// If no characters were replaced and "/" seperators don't exist, assume no seperators and add them
			if (newDateString == dateString) {
				newDateString = dateString.substr(0,2) + "/" + dateString.substr(2,2) + "/" + dateString.substr(4,(dateStringLength - 4));
			}
		}
	}
	var dateElementArray = newDateString.split("/");
	if (dateElementArray.length == 3) {
		var month = dateElementArray[0];
		var day = dateElementArray[1];
		var year = dateElementArray[2];
		if (((!isNaN(month)) && month.length < 3) &&
			((!isNaN(day)) && day.length < 3) &&
			((!isNaN(year)) && (year.length == 2 || year.length == 4))) {
			if (month.length == 1 && parseInt(month) < 10) {
				month = "0" + month;
			}
			if (day.length == 1 && parseInt(day) < 10) {
				day = "0" + day;
			}
			if (year.length == 2) {
				//Always append 19 in front of year...
				year = "19" + year;
				/*if (parseInt(year) < 11) {
					year = "20" + year;
				} else {
					year = "19" + year;
				}*/
			}
			
			dateElement.value = month + "/" + day + "/" + year;
		}
	}
}
/**
 * LTrim(string) - Returns a copy of a string without leading spaces.
 */
function LTrim(str) {
	// We don't want to trim JUST spaces, but also tabs, line feeds, etc.
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		// We have a string with leading blank(s)
		var j=0, i = s.length;
		// Iterate from the far left of string until we don't have any more whitespace
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
			j++;
		}
		// Get the substring from the first non-whitespace character to the end of the string
		s = s.substring(j, i);
	}
	return s;
}

/**
 * RTrim(string) - Returns a copy of a string without trailing spaces.
 */
function RTrim(str) {
	// We don't want to trim JUST spaces, but also tabs, line feeds, etc.
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
  // We have a string with trailing blank(s)
  var i = s.length - 1;
		// Iterate from the far right of string until we don't have any more whitespace
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
			i--;
		}
		// Get the substring from the front of the string to where the last non-whitespace character is...
		s = s.substring(0, i+1);
	}
	return s;
}

/**
 * Trim(string) - Returns a copy of a string without leading or trailing spaces
 */
function Trim(str) {
	return RTrim(LTrim(str));
}

//Calculats age from a given year, month, and day to current date
//Sample usage
//calculateAge (year, month, day, unit, decimals, rounding)
//Unit can be "years", "months", or "days"
//Decimals specifies demical places to round to (ie: 2)
//Rounding can be "roundup" or "rounddown"
var one_day=1000*60*60*24
var one_month=1000*60*60*24*30
var one_year=1000*60*60*24*30*12

function calculateAge(yr, mon, day, unit, decimal, round){
	today=new Date()
	var pastdate=new Date(yr, mon-1, day)

	var countunit=unit
	var decimals=decimal
	var rounding=round

	finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year
	decimals=(decimals<=0)? 1 : decimals*10

	if (unit!="years"){
		if (rounding=="rounddown")
			document.write(Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)
		else
			document.write(Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit)
	}
	else{
		yearspast=today.getFullYear()-yr-1
		tail=(today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0
		pastdate.setFullYear(today.getFullYear())
		pastdate2=new Date(today.getFullYear()-1, mon-1, day)
		tail=(tail==1)? tail+Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals : Math.floor((today.getTime()-pastdate2.getTime())/(finalunit)*decimals)/decimals
		//document.write(yearspast+tail+" "+countunit)
		return yearspast+tail;
	}
}