
// comment out the insertIcons() function in Window OnLoad if this file is modified and moved to production.

function date() {
	today=new Date();

	day=today.getDate();
	dayName=today.getDay();
	month=today.getMonth();
	year=today.getFullYear();

	dayNameArray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

	monthNameArray=new Array(12);
	monthNameArray[0]="January";
	monthNameArray[1]="February";
	monthNameArray[2]="March";
	monthNameArray[3]="April";
	monthNameArray[4]="May";
	monthNameArray[5]="June";
	monthNameArray[6]="July";
	monthNameArray[7]="August";
	monthNameArray[8]="September";
	monthNameArray[9]="October";
	monthNameArray[10]="November";
	monthNameArray[11]="December";

	document.write(dayNameArray[dayName]+", "+monthNameArray[month]+" "+day+", "+year);
}
	
function currentYear() {
	today=new Date();
	year=today.getFullYear();
	document.write(year);
}


 // function to stripe table rows for a specific class (onload function uses as "data_table")
function tableStripe(stripedClass) {
	if (document.getElementById == null) return;
	var tables = document.getElementsByTagName("table");
	for (var i = 0; i < tables.length; i++) {
		var t = tables[i];
		if (t == null) return;
		var tClass = t.className;
		if (tClass.indexOf(stripedClass) != -1) {
			var aTBODY = t.getElementsByTagName("tbody");
			for (var j = 0; j < aTBODY.length; j++) {
				var aTR = aTBODY[j].getElementsByTagName("tr");
				for (var k = 0; k < aTR.length; k++) {	
					aTR[k].className = (k % 2 == 1) ? "stripe1" : "stripe2";
				}
			}
		}
	}
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}


// FUNCTION TO STRIPE TABLE ROWS
function createStripedTable(idArray) {
	if (document.getElementById == null) return;
	
	for (var indx = 0; indx < idArray.length; indx++) {
		var id = idArray[indx];
		var oTable = document.getElementById(id);
		if (oTable == null) 
			return;

		var aTBODY = oTable.getElementsByTagName("tbody");

		for (var i = 0; i < aTBODY.length; i++) {
			var aTR = aTBODY[i].getElementsByTagName("tr");
			
			for (var j = 0; j < aTR.length; j++) {	
				aTR[j].className = (j % 2 == 1) ? "stripe1" : "stripe2";
			}
		}
	}
}

// FUNCTION TO ALLOW MULTIPLE TABLES WITH ROW STRIPING (i.e. theList, theList2, theList3, etc.)
function createStripedTables(id) {
	if (document.getElementById == null) return;
	
	var oTable = document.getElementById(id);
	if (oTable == null) return;
	createStripedTable(new Array(id));
	for (i=2;i<=100;i++) {
		var oTable = document.getElementById(id+i);
		if (oTable == null) return;
		createStripedTable(new Array(id+i));
	}
}
// FUNCTION TO SORT COLUMNS
var gbAscending = true;
var gbCol = 0;
function sortCallBack(a,b)
{
	// each of the arguments passed to this function is a TR node
	// with one or more child TD nodes.
	// get the child node of each TR element that corresponds
	// to the column to be sorted.
	var col1 = a.getElementsByTagName("TD")[gbCol];
	var col2 = b.getElementsByTagName("TD")[gbCol];

	// now get the text node for each col (with extra code to work with link tags)
	var text1 = col1.firstChild.data;
	var text2 = col2.firstChild.data;
	// if text is contained within another tag
	var tags = new Array("DIV","P","CENTER","A","B","STRONG","COMMENT","SPAN");
	for (i=0; i<tags.length; i++) {
		if (col1.firstChild.tagName == tags[i]) {
			text1 = col1.getElementsByTagName(tags[i])[0].firstChild.data;
		}
		if (col2.firstChild.tagName == tags[i]) {
			text2 = col2.getElementsByTagName(tags[i])[0].firstChild.data;
		}
	}
	
	// now that we have the text nodes, do the sorting
	if (text1 < text2)
		return gbAscending ? -1 : 1;
	else if (text1 > text2)
		return gbAscending ? 1 : -1;
	else return 0;
}
function sortTable(whichTable, whichCol, sortDir)
{
	var oTable = document.getElementById(whichTable);
	// begin by getting the node for the TBODY, since that
	// node contains all the rows to be sorted
	var oTBody = oTable.getElementsByTagName('TBODY')[0];
	// get all of the TR tags within the tbody
	var aTRows = oTBody.getElementsByTagName('TR');
	// store the length of the TR array
	var numRows = aTRows.length;
	
	gbAscending = sortDir;
	gbCol = whichCol;
	
	// make an array to hold each TR tag in the body.
	var theSortedRows = new Array(numRows);
	// copy each TR tag into the array. Do a "deep clone" on
	// each TR tag so that all of the child TD tags come along
	// with it.
	var i;
	for (i=0; i < numRows; i++)
	{
		theSortedRows[i] = aTRows[i].cloneNode(true);
	}
	
	// now -- sort the array!
	theSortedRows.sort(sortCallBack);
	
	// now that the array has been sorted, we put back all of the
	// table rows that we had copied out earlier.
	
	// First, get rid of the the current TBODY.
	oTable.removeChild(oTBody);
	// make a new one in its place
	oTBody = document.createElement("TBODY");
	oTable.appendChild(oTBody);
	// now copy in all of the sorted TR tags
	for (i=0; i< numRows; i++)
	{
		oTBody.appendChild(theSortedRows[i]);
	}
	createStripedTable(new Array(whichTable));
}

// inserts icons after links for various types of documents (.doc, .xls, .pdf, .ppt)
function insertIcons()
{
	// get an array of all the <a> tags in the document using the
	// standard DOM function getElementsByTagName.
   var aLinks = document.getElementsByTagName('a');
   var count = aLinks.length;

   // for each one of the <a> tags, get its href attribute
   // and see if it ends with ".pdf"
   for (var i = 0; i < count; i++) {
      var str = new String(aLinks[i].getAttribute('href'));

      // Note that this test only checks for links that end with ".pdf". A more advanced
      // test would take into account links that have parameters on them, like
      // ".pdf?arg1=val1", etc.
      if (str.lastIndexOf(".pdf",str.length) != -1)
      {
      	// if this <a> has a link to a PDF file, make a new <img> tag
      	// that points to our PDF file icon (you can substitute your
      	// own path to the image here, like "/images/icons/small_pdf_icon.gif"
         var image = document.createElement("img");
         image.setAttribute("src","images/icon_pdf.gif");
         // insert the new IMG into the document right before the current
         // <a> tag. This is handled by asking whatever the parent tag of the
         // current <a> tag is to insert the new image in front of the <a>.
         // The standard DOM function insertBefore() does this: it takes
         // two arguments - the new element to insert, and the element you want
         // it inserted in front of.
        // aLinks[i].parentNode.insertBefore(image,aLinks[i]);
		aLinks[i].appendChild(image);
      }
	   if (str.lastIndexOf(".doc",str.length) != -1)
      {
         var image = document.createElement("img");
         image.setAttribute("src","images/icon_doc.png");
  		 aLinks[i].appendChild(image);
      }
	    if (str.lastIndexOf(".xls",str.length) != -1)
      {
         var image = document.createElement("img");
         image.setAttribute("src","images/icon_xls.png");
  		 aLinks[i].appendChild(image);
      }
	    if (str.lastIndexOf(".ppt",str.length) != -1)
      {
         var image = document.createElement("img");
         image.setAttribute("src","images/icon_ppt.png");
  		 aLinks[i].appendChild(image);
      }
	    if (str.lastIndexOf(".pps",str.length) != -1)
      {
         var image = document.createElement("img");
         image.setAttribute("src","images/icon_ppt.png");
  		 aLinks[i].appendChild(image);
      }
	  
   }
}

window.onload = function() {
// comment out the insertIcons() function if this file is modified and moved to production. 
	insertIcons();
	//setFooter();
	createStripedTables("theList");
	// resets Quick Links menu when users return to the page via the back button
}

//Contact Us Form
function validateForm(f) {
	var msg = "";
	var valid = true;
	var state = f.state.options[f.state.selectedIndex].value;
	var product = f.product.options[f.product.selectedIndex].value;
	if (state == "N/A") {
   		msg += "Please select a state.\n";
   		valid = false;
	} else {
   		f.stateval.value = state.substr(1,2);
	}
	if (isEmpty(f.sphone.value) && isEmpty(f.semail.value)) {
		msg += "Please enter your phone number and/or email address.\n";
   		valid = false;
	}
	if (product == "ADD") {
		f.address.value = "Steven.Durany@hartfordlife.com";
		//alert(f.address.value);
		
	} else if (product == "Bus. Travel") {
		f.address.value = "Steven.Durany@hartfordlife.com";
		//alert(f.address.value);
		
	} else {
		f.address.value = "Catherine.Vinson@hartfordlife.com";
		//alert(f.address.value);
	}
	
	
	
	if (!valid) {
		alert (msg);
	} else {
		
		f.submit();
	}
}
function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}

/*start dropdown menu navigation*/
function jumpMenu(selObj) {
	var url = selObj.options[selObj.selectedIndex].value; 
	if (url && url!='#') window.location.href = url; 
	selObj.selectedIndex=0; 
}
/*end dropdown menu navigation*/

function pfversion(){
	openBWindow(pfurl, "pf", "true", "610", "400", "10", "10");
}

function openBWindow(pageToLoad, winName, rs, w, h, thex, they) {
        xposition=0; yposition=0;
        if ((parseInt(navigator.appVersion) >= 4 ) && (thex) && (they)){
                xposition = thex
                yposition = they
        }
	var resize = "";
	if (rs) {
	    resize = "resizable,";
	}

       msgWindow=open(pageToLoad,winName,'toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=1,' + resize + 'width=' + w + ',height=' + h);
        if (msgWindow.opener == null){
                msgWindow.opener = self;
        }
	    if(! window.focus){

	     }
	   else{
		 msgWindow.focus();
	   }

}