//===============================================================
// Web Site Utility Routines
//	-The Doyle Group
//===============================================================

function breadCrumbs(delimiterStr) {
	loc2 = window.location.toString();
	loc = loc2.toLowerCase();
	subs = loc.substr(7).split("/"); // Makes the assumption that the first7 characters are "HTTP://"
	    document.write("<a href=\"" + getLoc(subs.length - 1) + "\"><span class=breadcrumb>Home</a></span> " +
	    delimiterStr + " ");
	    a = (loc.indexOf('index.') == -1) ? 1 : 2;
	    if (subs[subs.length-1].length == 0) {
	    a++;
	}
	for (i = 1; i < (subs.length - a); i++) {
	    subs[i] = makeCaps(unescape(subs[i]));
	    document.write("<a href=\"" + getLoc(subs.length - i - 2) + "\"><span class=breadcrumb>" +
	    subs[i] + "</a></span> " + delimiterStr + " ");
	}
	document.write(document.title);
}
function makeCaps(a) {
    g = a.split("_");
    for (l = 0; l < g.length; l++) {
    	g[l] = g[l].toUpperCase().slice(0, 1) + g[l].slice(1);
	}
	return g.join(" ");
}
function getLoc(c) {
    var d = "";
    if (c > 0) {
	    for (k = 0; k < c; k++) {
	    	d = d + "../";
	    }
	}
	return d;
}


//-----------------------------------------------
//Table row highlite
//-----------------------------------------------
function HL(E) { E.style.backgroundColor='#B8BECE'; }
function dHL(E) { E.style.backgroundColor='#E0E5EB'; }


//-----------------------------------------------
//Pop-up help Window
//-----------------------------------------------
function openWin(topic,w,h,scroll) {
    window.open(topic, "newWin", 'history=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' +scroll+ ',resizable=no,width=' +w+ ',height=' +h+ ' ');
}


//-----------------------------------------------
//set cookie
//-----------------------------------------------
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}

//-----------------------------------------------
//get cookie values
//-----------------------------------------------
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {begin += 2;}
var end = document.cookie.indexOf(";", begin);
if (end == -1) {end = dc.length;}
return unescape(dc.substring(begin + prefix.length, end));
}


//-----------------------------------------------
//Determine if browser is IE 5.5 or higher
//-----------------------------------------------
//convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

var hldPageFrom = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);

if (!is_ie5_5up && hldPageFrom != "browser.asp"){
	//redirect to warn about browser upgrade needed
	//window.location.href = "/site_manager/Content_manager/browser.asp";
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function


function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
}


/*--------------------------------------------
Auto-Tab form fields functions
--------------------------------------------*/
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 refreshMe() {
	var sPath = window.location.pathname;
	document.location.replace(addParamToURL(sPath,'yr','95'));
}

function refreshMe1(par,val) {
	var sPath = window.location.pathname;
	document.location.replace(addParamToURL(sPath,par,val));
}

function addParamToURL(url,elem,val) {
  if (isValEmpty(url)) url = ''
  var isonlyparam = url.indexOf('?');
  if (isonlyparam == -1)
	url = url + "?" +elem+ "=" +val;
  else
	url = url + "&" +elem+ "=" +val;

  return url;
}

function appendFormDataToURL(url,omit) {
 var footer = document.getElementById('div__footer');
 var elem, frm = footer.getElementsByTagName('input');
 if (isValEmpty(url)) url = ''
 for (var i=0; i<frm.length; i++) {
  elem = frm[i];
  if (elem.name.length == 0 || elem.name == omit || elem.name.indexOf('inpt_') == 0) continue;
  if (elem.type=='select-one')
   	url = addParamToURL(url, elem.name, escape(getSelectValue(elem)));
  else if (isMultiSelect(elem))
   	url = addParamToURL(url, elem.name, escape(getMultiSelectValues(elem)));
  else if (elem.type=='radio')
   	url = addParamToURL(url, elem.name, escape(getRadioValue(elem)));
  else if (elem.type=='checkbox')
   	url = addParamToURL(url, elem.name, (elem.checked ? 'T' : 'F'));
  else if (elem.type=='text')
   	url = addParamToURL(url, elem.name, escape(elem.value));
  else if (elem.type=='hidden' && elem.name != 'frame')
   	url = addParamToURL(url, elem.name, escape(elem.value));
 }
 return url;
}

function isValEmpty(val,nam) {
	if (val== null) return true;
	if (val.length == 0) return true;
	re = / /gi;
	val = val.replace(re,'');
	return (val.length == 0)
}

//-------------------------------------------