// MattB's generic new window function
function openWin(URL, width, height) {
	window.open(URL, 'selWin' , 'width=' + width + ',height=' + height + ',toolbar=0,directories=0,menubar=0,status=yes,resizable=1,location=0,scrollbars=1,copyhistory=0');
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

function stripyTables () {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("stripy")) return false;
	var stripe = document.getElementById("stripy");
	var tables = stripe.getElementsByTagName("table");
	for (var i=0; i<tables.length; i++) {
	  var odd = false;
	  var rows = tables[i].getElementsByTagName("tr");
	  for (var j=0; j<rows.length; j++) {
	    if (odd == true) {
	      addClass(rows[j],"odd");
	      odd = false;
	    } else {
	      odd = true;
	    }
	  }
	}
}

function highlightRows() {
  if(!document.getElementsByTagName) return false;
  if (!document.getElementById("stripy")) return false;
  var stripe = document.getElementById("stripy"); 
  var rows = stripe.getElementsByTagName("tr");
  for (var i=0; i<rows.length; i++) {
    rows[i].oldClassName = rows[i].className
    rows[i].onmouseover = function() {
      	addClass(this,"highlight");
		}
		rows[i].onmouseout = function() {
      	this.className = this.oldClassName
		}
	}
}

function rowClick () {
	if(!document.getElementsByTagName) return false;
	if (!document.getElementById("stripy")) return false;
	var stripe = document.getElementById("stripy");
	var rows = stripe.getElementsByTagName("tr");		
	for (var i=0; i<rows.length; i++) {
		var links = rows[i].getElementsByTagName("a");
		if (links[0] != null) {
			rows[i].linkHref = links[0].getAttribute("href");
			rows[i].onclick = function() {
				window.location.href = this.linkHref;
			}
		}	    
	}
}
function showSection(id) {
  var div = document.getElementById(id);
  if (div.style.display == "block") {
    div.style.display = "none";
  } else {
    div.style.display = "block";
  }
}

/*
function prepareInternalnav() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var sectionId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(sectionId)) continue;
    document.getElementById(sectionId).style.display = "none";
    links[i].destination = sectionId;
    links[i].onclick = function() {
      showSection(this.destination);
      return false;
    }
  }
}
*/
//addLoadEvent(prepareInternalnav);
addLoadEvent(stripyTables);
addLoadEvent(highlightRows);
addLoadEvent(rowClick);
//addLoadEvent(prepareInternalnav);

/*
function dsp(loc){
  if(document.getElementById){
    var foc=loc.firstChild;
    foc=loc.firstChild.innerHTML?
       loc.firstChild:
       loc.firstChild.nextSibling;
    foc.innerHTML=foc.innerHTML=='+'?'-':'+';
    foc=loc.parentNode.nextSibling.style?
       loc.parentNode.nextSibling:
       loc.parentNode.nextSibling.nextSibling;
    foc.style.display=foc.style.display=='block'?'none':'block';
  }
}

function dspControl(loc, collapse){
  if(document.getElementById){
    var foc=loc.firstChild;
    foc=loc.firstChild.innerHTML?
      loc.firstChild:
      loc.firstChild.nextSibling;
    if (collapse) {
      foc.innerHTML='+';
    } else {
      foc.innerHTML='-';
    }
    foc=loc.parentNode.nextSibling.style?
       loc.parentNode.nextSibling:
       loc.parentNode.nextSibling.nextSibling;
    if (collapse) {
      foc.style.display='none';
    } else {
      foc.style.display='block';
    }
  }
}

function dspAll(loc){
  if(document.getElementById){
    var foc=loc.firstChild;
    foc=loc.firstChild.innerHTML?
       loc.firstChild:
       loc.firstChild.nextSibling;
    var collapse = false;
    if (foc.innerHTML=='Show All') {
      foc.innerHTML = 'Hide All';
      collapse = false;
    } else {
      foc.innerHTML = 'Show All';
      collapse = true;
    }

    var foc=loc.nextSibling;
    while (foc) {
      if (foc.nodeName.toLowerCase() == "h5") {
        dspControl(foc.firstChild, collapse);
      }
      var foc=foc.nextSibling;
    }
  }
}
*/
function dsp2(loc){
  if(document.getElementById){
    var foc = loc.firstChild.firstChild.firstChild.firstChild.innerHTML ? 
    	loc.firstChild.firstChild.firstChild.firstChild : loc.firstChild.firstChild.firstChild;
		foc.innerHTML = foc.innerHTML == '+' ? '-' : '+';
    foc = loc.parentNode.nextSibling.style ? loc.parentNode.nextSibling : loc.parentNode.nextSibling.nextSibling;
    foc.style.display = foc.style.display == 'block' ? 'none' : 'block';
  }
}

function dspControl2(loc, collapse){
  if(document.getElementById){
    var foc = loc.firstChild.firstChild.firstChild.firstChild.innerHTML ? 
    	loc.firstChild.firstChild.firstChild.firstChild : loc.firstChild.firstChild.firstChild;
    if (collapse) {
      foc.innerHTML='+';
    } else {
      foc.innerHTML='-';
    }
    foc=loc.parentNode.nextSibling.style?
       loc.parentNode.nextSibling:
       loc.parentNode.nextSibling.nextSibling;
    if (collapse) {
      foc.style.display='none';
    } else {
      foc.style.display='block';
    }
  }
}

function dspAll2(loc){
  if(document.getElementById){
    var foc=loc.firstChild;
    foc=loc.firstChild.innerHTML?
       loc.firstChild:
       loc.firstChild.nextSibling;
    var collapse = false;
    if (foc.innerHTML=='Show All') {
      foc.innerHTML = 'Hide All';
      collapse = false;
    } else {
      foc.innerHTML = 'Show All';
      collapse = true;
    }

    var foc=loc.nextSibling;
    while (foc) {
      if (foc.nodeName.toLowerCase() == "h5") {
        dspControl2(foc.firstChild, collapse);
      }
      var foc=foc.nextSibling;
    }
  }
}


// travel advisory guff

function dsp(loc){
			if(document.getElementById){
				var foc=loc.firstChild;
				foc=loc.firstChild.innerHTML?
				loc.firstChild:
				loc.firstChild.nextSibling;
				foc.innerHTML=foc.innerHTML=='+'?'-':'+';
				foc=loc.parentNode.nextSibling.style?
				loc.parentNode.nextSibling:
				loc.parentNode.nextSibling.nextSibling;
				foc.style.display=foc.style.display=='block'?'none':'block';
			}
		}

		function dspControl(loc, collapse){
			if(document.getElementById){
				var foc=loc.firstChild;
				foc=loc.firstChild.innerHTML?
				loc.firstChild:
				loc.firstChild.nextSibling;
				if (collapse) {
				foc.innerHTML='+';
				} else {
				foc.innerHTML='-';
				}
				foc=loc.parentNode.nextSibling.style?
				loc.parentNode.nextSibling:
				loc.parentNode.nextSibling.nextSibling;
				if (collapse) {
				foc.style.display='none';
				} else {
				foc.style.display='block';
				}
			}
		}

		function dspAll(loc){
			if(document.getElementById){
				var foc=loc.firstChild;
				foc=loc.firstChild.innerHTML?
				loc.firstChild:
				loc.firstChild.nextSibling;
				var collapse = false;
				if (foc.innerHTML=='Show All') {
				foc.innerHTML = 'Hide All';
				collapse = false;
				} else {
				foc.innerHTML = 'Show All';
				collapse = true;
				}

				var foc=loc.nextSibling;
				while (foc) {
				if (foc.nodeName.toLowerCase() == "h5") {
					dspControl(foc.firstChild, collapse);
				}
				var foc=foc.nextSibling;
				}
			}
		}

		if(!document.getElementById)
			document.write('<style type="text/css"><!--\n' +
				'.dspcont{display:block;}\n' +



				'//--></style>');
/***************************************************************/
		//== *added for benefits - quote page*/
	//DO not delete //		
/***************************************************************/		
	
function trim(str) {
// removes white spaces from beginning and end of given string, str.
	return str.replace(/^\s*|\s*$/g,"");	
}

function addClassName(myElement, myClass) {
	var currentClassName = trim(myElement.className);
	var myReg = new RegExp("(^" + myClass + "$)|( " + myClass + "$)|(^" + myClass + " )|( " + myClass + " )", "g");
	if (!myReg.test(currentClassName)) {
		// not currently set on element, so add class..
		if (currentClassName != "") {
			myElement.className += " " + myClass;
		} else {
			myElement.className = myClass;
		}
	}
}

function removeClassName(myElement, myClass) {
	var currentClassName = trim(myElement.className);
	var myReg = new RegExp("(^" + myClass + "$)|( " + myClass + "$)|(^" + myClass + " )|( " + myClass + " )", "g");
	myElement.className = currentClassName.replace(myReg, "");
}

function switchClassName(myElement, removeClass, addClass) {
	removeClassName(myElement, removeClass);
	addClassName(myElement, addClass);
}

function hasClassName(myElement, myClass) {
	var currentClassName = trim(myElement.className);
	var myReg = new RegExp("(^" + myClass + "$)|( " + myClass + "$)|(^" + myClass + " )|( " + myClass + " )", "g");
	if (myReg.test(currentClassName)) {
		// has class name set..
		return true;
	} else {
		return false;
	}
}

//-- end of Benefit page script
