// Title: Utility
// Version: 1
// Last Modify: 27 Aug 2009, kc

var isSafari3 = false;	// safari only
if(window.devicePixelRatio) isSafari3 = true;
var european = ((new Date("01/02/2000")).getDate() != 2);

//alert(european);

function chr( ascii ) {
	// return the char character fromanumeric ascii
    return String.fromCharCode(ascii);
}

function Asc(String)
{
	return String.charCodeAt(0);
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function curTarg(e) {
var dumo;
	(typeof window.event!="undefined")? dumo=event.srcElement : dumo=e.currentTarget;
	return dumo;
}

function clientWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function clientHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function divPrint(id,title) {
	try {
		var oIframe = document.getElementById("i"+id);
		var oContent = document.getElementById(id).innerHTML;
		var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
		if (oDoc.document) oDoc = oDoc.document;
		oDoc.write("<head><title>"+title+"</title>");
		oDoc.write("</head><body onload='this.focus(); this.print();'>");
		oDoc.write(oContent + "</body>");
		oDoc.close();
	}
	catch(e) {
		self.print();
	}
}

function textToMenu(data, delim, valDelim, mnuObj, curChoice) {
	// convert data to and array called cList
	// if curChoice is in the new menu, return true, else false
		
	var retVal = false;
	
	if (delim == "[line]") {
		//find out if [crlf] [cr] or [lf]
		if (data.indexOf(chr(13)+chr(10))>=0) {
			delim = chr(13) + chr(10);
		} else if (data.indexOf(chr(13))>=0) {
			delim = chr(13);
		} else if (data.indexOf(chr(10))>=0) {
			delim = chr(10);
		}
	}
	if (delim =="[crlf]"){
		delim = chr(13) + chr(10);
	}
	if (delim =="[cr]"){
		delim = chr(13) ;
	}
	if (delim =="[lf]"){
		delim = chr(10) ;
	}
	if (delim == "[tab]"){
		delim = chr(9) ;
	}

	if (valDelim == "[line]") {
		//find out if [crlf] [cr] or [lf]
		if (data.indexOf(chr(13)+chr(10))>=0) {
			valDelim = chr(13) + chr(10);
		} else if (data.indexOf(chr(13))>=0) {
			valDelim = chr(13);
		} else if (data.indexOf(chr(10))>=0) {
			valDelim = chr(10);
		}
	}
	if (valDelim =="[crlf]"){
		valDelim = chr(13) + chr(10);
	}
	if (valDelim =="[cr]"){
		valDelim = chr(13) ;
	}
	if (valDelim =="[lf]"){
		valDelim = chr(10) ;
	}
	if (valDelim == "[tab]"){
		valDelim = chr(9) ;
	}

	var cList = data.split(delim);
	var newOption;

	while (mnuObj.options.length > 0) { 
		mnuObj.remove(0); 
	}
	
	//alert(parseInt2(valDelim) + "-" + (parseInt2(valDelim) == "NaN"));
	if (valDelim == null) {
		//alert("Null");
	}
	var texto = null;
	var fieldo = null;
	var mnuID = (mnuObj.id+"");
	var selPos = mnuID.indexOf("_sel");
	if (selPos>=0) {
		//find text object, put text value into it.
		var fieldID = mnuID.substring(0,selPos);
		fieldo = document.getElementById(fieldID);
		texto = document.getElementById(fieldID+"_text");
	}
	
	// create new options
	var selectedChoice = -1;
	
	for (var i=0; i<cList.length; i++) { //>
		var menuText = cList[i].trim();
		var menuVal = menuText;

		var optionAttribute = "";
		var tipText = null;

		if (valDelim != null) {
			// valDelim could be a character, that case the first part is the
			// value and the whole thing is the menu name
			// it could be numeric, in that case the first xx chars are the value and the remaining
			// is the menu name
			if (parseInt2(valDelim) != 0) {
				// we want the first xx chars as the value
				menuVal = menuVal.substr(0,parseInt2(valDelim));
				menuText = menuText.substr(parseInt2(valDelim)+1);
			} else {
				// split using the chars
				var mList = menuText.split(valDelim);
				if (mList.length > 1) {
					//if (i==0) alert(mList[0]+"--"+mList[1])
					menuVal = mList[0];
					menuText = mList[1];
				} else {
					//if (i==0) alert("length=0:"+valDelim+":"+Asc(valDelim))
				}
			}
		} else {
			// it's good as is
		}
		
		if (menuText.indexOf("[[")==0) {
			var dumList = menuText.split("]]");
			optionAttribute = dumList[0].substr(2);
			if (dumList.length > 1) {
				menuText = dumList[1];
			} else {
				menuText = optionAttribute;
			}
		}
		
		if (menuText.indexOf("{{")==0) {
			var dumList = menuText.split("}}");
			var dumTextName = dumList[0].substr(2);
			if (dumList.length > 1) {
				menuText = dumList[1];
				tipText = dumList[0].substr(2);
			} else {
				menuText = dumTextName;
			}
		}

		if (menuText == curChoice.trim()) retVal = true;
		newOption = document.createElement("option");

		newOption.value = menuVal;  // assumes option string and value are the same 
		newOption.text = menuText;
		if (tipText != null) {
			//newOption.title = tipText;
			newOption.setAttribute("title",tipText)
		}
		
		newOption.setAttribute("optionID",optionAttribute)

		if (selectedChoice == -1) {
			newOption.selected = (menuVal == curChoice.trim());
			if (menuVal == curChoice.trim()) {
				selectedChoice = i;
			}
		} else {
			newOption.selected = false;
		}
		
		if ((newOption.selected) && (fieldo != null)) {
			if (texto != null) {
				fieldo.value = menuVal;
				texto.value = menuText;
				//fieldo.value = menuText;
			} else {
				fieldo.value = menuText;
			}
		}
		
		// add the new option 
		try {
			mnuObj.add(newOption);  // this will fail in DOM browsers but is needed for IE
		}
		catch (e) {
			mnuObj.appendChild(newOption);
		}
	}
	return retVal;
}

// Round a number to a number of digits
function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber;
}


// Take an Hours time (ie 9.5166667 is 9:31 and round it to the nearest x minute provided)
// and return the result in hours
function roundHourToMin(inHours, stickyTime) {
	var minutes = inHours * 60;
	minutes = Math.round(minutes / stickyTime)*stickyTime;
	return (minutes / 60);
}

// return the current time (of browser) in Hrs
function curHr() {
	var nd = new Date();
	var h, m, s;
	h = nd.getHours();
	m = nd.getMinutes();
	s = nd.getSeconds();
	return (h + (m / 60) + (s / 3600));
}

// take a time in HH:MM and return the time in a decinal hours (09:30 returns 9.5)
function convertHHMMtoHours(theTime) {
	var retHrs = 0.0;
	if ((theTime == "") || (theTime == null)) {
		;
	} else {
		var tArray = theTime.split(":")
		retHrs = parseInt2(tArray[0]);
	
		if ((retHrs > 99) && (tArray.length == 1)) {
			// military time without the colon
			retHrs = parseInt2(tArray[0])/100;
			retHrs += ((tArray[0] % 100) / 60);
		} else {
			if (tArray.length > 1) retHrs += parseInt2(tArray[1])/60;
			if (tArray.length > 2) retHrs += parseInt2(tArray[2])/3600;
			// if there is a p in the string and retHrs < 12 then add 12 hours
			if (((theTime.indexOf("p")>=0) || (theTime.indexOf("P")>=0)) && (retHrs<12)) retHrs+= 12;
		}
	}
	return retHrs;
}

function textdate_addDays(textDate, numDays) {
	// take a text version of a date, and add a certain number of days, return result as a text date
	dumDate = new Date( textDate);
	dumDate.dateAdd(numDays)
	return(dumDate.toDateString());
}

function checkDAY(textDate, theDAYS) {
	// is the DAY code of the textDate (MON) located within theDAYS (MONTUEWED)
	// if so, return true
	dumDate = new Date( textDate);
	var dayCode = ["SUN","MON","TUE","WED","THU","FRI","SAT"];
	var theDay = dayCode[dumDate.getDay()];
	return (theDAYS.indexOf(theDay)>=0);
}

// return conditional text based on condition
function iftext(condition,trueText,falseText) {
	if (condition) {
		return(trueText);
	} else {
		if (falseText != null) {
			return(falseText);
		} else {
			return("");
		}
	}
}

function zEndDec(t,d) {
	if (d == null) {
		d = 5;
	}
	var out = "";
	for (c = 0; c < t.length; c++) {
		var theNo = Asc(t.substr(c,1));
		theNo = theNo + d
		if (theNo > 255) {
			theNo = theNo - 256
		}
		if (theNo <0) {
			theNo = theNo + 256; 
		}
		out += chr(theNo);
		d = -1*d;
	}
	return out;
}

// Take an hours number (9.5 is 9:30) and return the time, formatted and rounded to stickyTime minutes
function convertHourToHHMM(theHour,formatCode,stickyTime) {
	//formatCode (blank or 1) AM PM
	//formatCode (2) 8:00 1:00p [do not show a AM]
	//formatCode (3) 14:00 [military]
	//formatCode (4) 1400 0600 [military without the colon]
	
	var frmt = 1;
	if (formatCode != null) frmt = formatCode;
	
	var minutes = Math.round(theHour * 60);
	//stickyTime cause the time to be rounded to the nearest sticky minute
	if (stickyTime != null) minutes = Math.round(minutes / stickyTime)*stickyTime;
	var hours = parseInt(minutes / 60);
	//parseInt2(theHour+" ");
	minutes = minutes % 60;
	if (minutes < 10) minutes = "0"+minutes;
	
	var sign = ""
	switch (frmt) {
		case 1:
				if (hours >= 12) {
					if (hours>12) hours -= 12;
					sign = " PM";
				} else {sign = " AM";}
				break;
		case 2: 
				if (hours >= 12) {
					if (hours>12) hours -= 12;
					sign = "p";
				} else {sign = "a";}
				break;
		case 3:
		case 4:
				if (hours < 10) hours = "0"+hours;
				break;
	}
	
	return(hours+iftext((frmt!=4),":","")+minutes+sign);
}

// Add to text times that are HH:MM together and round and format the result
function addTime(startTime, durTime, formatCode, stickyTime) {
	var frmt = 1;
	if (formatCode != null) frmt = formatCode;
	var endHour = convertHHMMtoHours(startTime)+convertHHMMtoHours(durTime);
	if (stickyTime != null) {
		return(convertHourToHHMM(endHour,frmt,stickyTime));
	} else {
		return(convertHourToHHMM(endHour,frmt));
	}
}

// parseInt that assumes NaN is 0
function parseInt2(theText) {


	var dumRet = parseInt(theText,10);
	if (isNaN(dumRet)) dumRet = 0;
	//if (dumRet == NaN) dumRet = 0;
	//dumRet = dumRet;// + "";
	//if (dumRet == "NaN") {
	//	return(0);
	//} else {
		return(dumRet);
	//}
}

// The doResArea is used to expand and contract a text area
// Call initResArea to hide the textArea and set the position of the resizer
function doResArea(olink,txtID) {
	var otxt = document.getElementById(txtID);
	var otxtDsp = document.getElementById(txtID+"_dsp");
	var otxtBtn = document.getElementById(txtID+"_btn");
	if (otxt.style.display == "none") { //Open it up
		otxt.style.display = "block";
		otxtDsp.style.display = "none"
		otxt.focus();
		//if (document.all) {//IE only
			otxtBtn.style.top = "-16px";
		//}
	} else {							// Close it down
		otxt.style.display = "none";
		otxtDsp.style.display = "block"
		if (document.all) {//IE only
			otxtDsp.style.marginTop = "1px";
		}
		otxtBtn.style.top = "2px";
	}
}
function initResArea(txtID) {
	var otxt = document.getElementById(txtID);
	var otxtDsp = document.getElementById(txtID+"_dsp");
	var otxtBtn = document.getElementById(txtID+"_btn");
	otxt.style.display = "none";
	otxtDsp.style.width = otxt.style.width;
	otxtBtn.style.left = parseInt2(otxtDsp.style.width)+2;
	otxtBtn.style.top = "0px";
	
	if (document.all) {//IE only
		otxtDsp.style.marginTop = "1px";
	}
	if (otxt.value == "") resAreaBlank(txtID);
}

function resAreaBlank(txtID) {
	var otxt = document.getElementById(txtID);
	var otxtDsp = document.getElementById(txtID+"_dsp");
	var noTextMsg = otxt.getAttribute("noTextMsg");
	if (noTextMsg != null) {
		otxtDsp.innerHTML = noTextMsg;
	} else {
		otxtDsp.innerHTML = "No text entered for this...click the button to display";
	}
}
// a custom attribute in the textarea called stripTags (true or false)
//allows tags to be stripped for the display area
function resAreaChanged(txtID) {
	var otxt = document.getElementById(txtID);
	var otxtDsp = document.getElementById(txtID+"_dsp");
	var stripTags = (otxt.getAttribute("stripTags")=="true");
	var strInputCode = otxt.value;
		
	if (strInputCode == "") {
		resAreaBlank(txtID);
	} else {
		if (stripTags) {
			strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
			 		return (p1 == "lt")? "<" : ">";
				});
				var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
			otxtDsp.innerHTML = strTagStrippedText.substr(0,400);
		} else {
			otxtDsp.innerHTML = strInputCode;
		}
	}
}

// based on data formatted as such:
// 	attribute1=yes/no
//  attribute2=yes/no
//  attribute3=yes/no
// Will look for all divs with the attribute='attribute' and change the
// style.display attribute to block/none based on yes/no values

// requires prototype.js
function visibilityTagUpdate(tagData) {
	retData = tagData.split('\r');
	for (var c=0; c<retData.length; c++) {
		var code = retData[c];
		var tag = code.split("=");
		if (tag.length == 2) {
			if (tag[0].indexOf('label ')>=0) {
				code = ((tag[0]+"").split(' '))[1];
				var tempObj = document.getElementById(code);
				if (tempObj != null) {
					if ((tempObj.getAttribute("requiredname") != null) && (tempObj.getAttribute("requiredname") != "")) {
						tempObj.setAttribute("requiredname",tag[1])
					}
				}
				var tempObj = document.getElementById(code+"_lbl");
				if (tempObj != null) {
					var addColon = (tempObj.innerHTML.indexOf(":")>=0);
					tempObj.innerHTML = tag[1] + iftext(addColon,":");
				}
			} else if (tag[0].indexOf('required ')>=0) {
				code = ((tag[0]+"").split(' '))[1];
				// code is id of object to set the required attribute
				var tempObj = document.getElementById(code);
				if (tempObj != null) {
					if (tag[1] == 'yes') {
						tempObj.setAttribute('required','required');
					} else {
						tempObj.setAttribute('required','no');
					}
				}
			} else {
				divs = $$('div['+tag[0]+'="'+tag[0]+'"]')
				for( var i = 0; i < divs.length; i++ ) {
					divs[i].style.display = ( tag[1] == "yes" ? "block" : "none" );
				}
				divs = $$('span['+tag[0]+'="'+tag[0]+'"]')
				for( var i = 0; i < divs.length; i++ ) {
					divs[i].style.display = ( tag[1] == "yes" ? "block" : "none" );
				}
			}
		}
	}
}

// this function displays a transparent box on top of everything, indicating that a
// transaction is being sent to the server
// status code is a code to display as the action being taken,
// objID is the optional obj ID to attach the progress mask to (default  is body)

function displayProgress( statusCode , objID) {
	var body;
	if (objID == null) {
		body = document.getElementsByTagName('body')[0];
	} else {
		body = document.getElementById(objID);
		if (body == null) {
			body = document.getElementsByTagName('body')[0];
		}
	}

	var scLeft,scTop;
	if (self.pageYOffset) {
		scLeft = self.pageXOffset;
		scTop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		scLeft = document.documentElement.scrollLeft;
		scTop = document.documentElement.scrollTop;
	} else if (document.body) {
		scLeft = document.body.scrollLeft;
		scTop = document.body.scrollTop;
	} 


	var popmask = document.createElement('div');
	popmask.id = 'statusMask';
	popmask.innerHTML = '' +
		'<div id="statusContainer">' +
			"Now processing request to "+statusCode+",<br> please hold...<br>" +
			"<img src='images/delay2.gif'>" +
		'</div>';
	body.appendChild(popmask);
	$('statusMask').style.top = parseInt(scTop)+"px";
	$('statusMask').style.left = parseInt(scLeft)+"px";
	$('statusMask').myParent = body;
}

function clearProgress() {
    itemMask = $('statusMask');
    if (itemMask != null) {
        parento = itemMask.myParent;
        parento.removeChild(itemMask);
    }
}

/* utility functions that are used to adjust a counter in a URL
	(if it doesn't exist, set to 1), or get a URL param or to change a param
*/

function refreshCurPage() {
    var theLoc = url_incrGSP("","tc") ;
    document.location = theLoc;
}

function url_incrGSP(inURL,gsp,amount) {
	if ((amount=="")||(amount==null)) amount = 1;
	if ((inURL=="")||(inURL==null)) inURL = document.location+"";

	urlComponent = inURL.split("&"+gsp+"=");
	if (urlComponent.length==1) {
		if (inURL.indexOf("?")>=0) {
			inURL = inURL + "&"+gsp+"="+amount;
		} else {
			inURL = inURL + "?"+gsp+"="+amount;
		}
	} else {
		dumInt = parseInt2(urlComponent[1])+amount;
		inURL = urlComponent[0] + "&"+gsp+"="+dumInt;
	}
	return inURL;
}
function url_setGSP(inURL,gsp,val) {
	if ((inURL=="")||(inURL==null)) inURL = document.location+"";

	urlComponent = inURL.split("&"+gsp+"=");
	if (urlComponent.length==1) {
		//if 1st param, let make change
		urlComponent = inURL.split("?"+gsp+"=");
		if (urlComponent.length==1) {
			if (inURL.indexOf("?")>=0) {
				inURL = inURL + "&"+gsp+"="+val;
			} else {
				inURL = inURL + "?"+gsp+"="+val;
			}
		} else {
			suffix = "";
			suffixPos = urlComponent[1].indexOf("&");
			if (suffixPos>=0) {suffix = urlComponent[1].substr(suffixPos)}
			inURL = urlComponent[0] + "?"+gsp+"="+val+suffix;
		}
	} else {
		suffix = "";
		suffixPos = urlComponent[1].indexOf("&");
		if (suffixPos>=0) {suffix = urlComponent[1].substr(suffixPos)}
		inURL = urlComponent[0] + "&"+gsp+"="+val+suffix;
	}
	return inURL;
}
function url_GSP(inURL,gsp) {
	if ((inURL=="")||(inURL==null)) inURL = document.location+"";
	
	urlComponent = inURL.split("&"+gsp+"=");
	if (urlComponent.length==1) {
		urlComponent = inURL.split("?"+gsp+"=");
		if (urlComponent.length==1) {
			return "";
		} else {
			suffix = "";
			suffixPos = urlComponent[1].indexOf("&");
			if (suffixPos>=0) {
				return urlComponent[1].substr(0,suffixPos)
			} else {
				return urlComponent[1];
			}
		}
	} else {
		suffix = "";
		suffixPos = urlComponent[1].indexOf("&");
		if (suffixPos>=0) {
			return urlComponent[1].substr(0,suffixPos)
		} else {
			return urlComponent[1];
		}
	}
}

/*
 sethtml is for dynamic html that contains scripts
 pass div's id and the html content to set
*/
function sethtml(div,content)
{
    var search = content;
    var script;
         
    while( script = search.match(/(<script[^>]+javascript[^>]+>\s*(<!--)?)/i))
    {
      search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length);
      
      if (!(endscript = search.match(/((-->)?\s*<\/script>)/))) break;
      
      block = search.substr(0, search.indexOf(RegExp.$1));
      search = search.substring(block.length + RegExp.$1.length);
      
      var oScript = document.createElement('script');
      oScript.text = block;
      document.getElementsByTagName("head").item(0).appendChild(oScript);
  	}
   
    document.getElementById(div).innerHTML=content;
} 


/* Next section has to do with adding to the date function for adding days, months, etc.
*/

function dateAddExtention(p_Interval, p_Number){
   var thing = new String();
   p_Interval = p_Interval.toLowerCase();
   
   if(isNaN(p_Number)){
      throw "The second parameter must be a number. \n You passed: " + p_Number;
      return false;
   }

   p_Number = new Number(p_Number);
   switch(p_Interval){
      case "yyyy": {	// year
         this.setFullYear(this.getFullYear() + p_Number);
         break;
      }
      case "q": {		// quarter
         this.setMonth(this.getMonth() + (p_Number*3));
         break;
      }
      case "m": {		// month
         this.setMonth(this.getMonth() + p_Number);
         
			/*t.setMonth(d.getMonth()+ month) ;
			if (t.getDate() < d.getDate()) {
				t.setDate(0);
			}
			return t;*/
         break;
      }
      case "y":			// day of year
      case "d":			// day
      case "w": {		// weekday
         this.setDate(this.getDate() + p_Number);
         break;
      }
      case "ww": {		// week of year
         this.setDate(this.getDate() + (p_Number*7));
         break;
      }
      case "h": {		// hour
         this.setHours(this.getHours() + p_Number);
         break;
      }
      case "n": {		// minute
         this.setMinutes(this.getMinutes() + p_Number);
         break;
      }
      case "s": {		// second
         this.setSeconds(this.getSeconds() + p_Number);
         break;
      }
      case "ms": {		// millisecond
         this.setMilliseconds(this.getMilliseconds() + p_Number);
         break;
      }
      default: {
         throw   "The first parameter must be a string from this list: \n" +
               "yyyy, q, m, y, d, w, ww, h, n, s, or ms.  You passed: " + p_Interval;
         return false;
      }
   }
   return this;
}

function addDaysExt (numDays) {
	this.setDate( this.getDate() + parseInt(numDays));
}

function getMMDDYYtextExtension () {
	// given a date, return M/D/YY as text from date
	var yearStr = this.getFullYear()+"";
	if (european) {
		return(this.getDate()+"/"+(this.getMonth()+1)+"/"+yearStr.substr(2,2));
	} else {
		return((this.getMonth()+1)+"/"+this.getDate()+"/"+yearStr.substr(2,2));
	}
}

function getMMDDYYYYtextExtension () {
	// given a date, return M/D/YYYY as text from date
	
	if (european) {
		var yearStr = this.getFullYear()+"";
		return(this.getDate()+"/"+(this.getMonth()+1)+"/"+yearStr.substr(0,4));
	} else {
		var yearStr = this.getFullYear()+"";
		return((this.getMonth()+1)+"/"+this.getDate()+"/"+yearStr.substr(0,4));
	}
}

function getMMDDYYYY00dateExtension () {
	// given a date, return MM/DD/YYYY as text from date
	var yearStr = this.getFullYear()+"";
	var m = this.getMonth()+1;
	if (m < 9) m = "0"+m;
	var d = this.getDate()+1;
	if (d < 9) d = "0"+d;
	
	if (european) {
    	return(d+"/"+m+"/"+yearStr.substr(0,4));
	} else {
    	return(m+"/"+d+"/"+yearStr.substr(0,4));
	}
}


function getDAYCodeExt () {
	var dumDate = new Date( this+"" );
	var dayCode = ["SUN","MON","TUE","WED","THU","FRI","SAT"];
	return(dayCode[dumDate.getDay()]);
}

function setMMDDYYExtension (dateStr) {
	// set the date based on the string MM/DD/YY or DD/MM/YY
	
	if (european) {
		var dArray = dateStr.split("/");
		if (dArray[2].length==2) {
			dArray[2] = parseInt(dArray[2])+2000;
		}
		this.setFullYear(dArray[2]);
		this.setMonth(parseInt(dArray[1])-1);
		this.setDate(parseInt(dArray[0]));	
	} else {
		var dArray = dateStr.split("/");
		if (dArray[2].length==2) {
			dArray[2] = parseInt(dArray[2])+2000;
		}
		this.setFullYear(dArray[2]);
		this.setMonth(parseInt(dArray[0])-1);
		this.setDate(parseInt(dArray[1]));
	}
}

// Extension to String
// replaceAll returns the first word of inText,
function replaceAllExt ( fromText, toText) {
	//var r = new RegExp(fromText, 'g');
	//return this.replace(r, toText);
	var dumText = this;
	while (dumText.indexOf(fromText)>=0) {
		dumText = dumText.replace(fromText,toText);
	}
	return dumText;
}


// Extension to String
// firstWord returns the first word of inText,
// what's a 'word' use the optional char instead of space
function firstWordExt ( wordDelim) {
	if (wordDelim == null) wordDelim = ' ';
	var dArray = this.split(wordDelim);
	return(dArray[0]);
}

// Extension to String
// lastWord returns the last word of inText,
// what's a 'word' use the optional char instead of space
function lastWordExt ( wordDelim) {
	if (wordDelim == null) wordDelim = ' ';
	var dArray = this.split(wordDelim);
	return(dArray[dArray.length - 1]);
}

// Extension to String
// allButLastWord returns the beginning portion of inText except for the last word,
// what's a 'word' use the optional char instead of space
function allButLastWordExt( wordDelim ) {
	if (wordDelim == null) wordDelim = ' ';
	var dArray = this.split(wordDelim);
	var retVal = '';
	for (var c = 0;(c<(dArray.length-1));c++) {
		retVal += dArray[c];
		if (c<(dArray.length-2)) {
			retVal += wordDelim;
		}
	}
	return(retVal);
}

// Extension to String
// nthWord returns the nth word of inText,
// what's a 'word' use the optional char instead of space
function nthWordExt ( wordNum, wordDelim) {
	if (wordDelim == null) wordDelim = ' ';
	var dArray = this.split(wordDelim);
	if ((wordNum<1)||(wordNum>dArray.length)) {
		return("");
	} else {
		return(dArray[wordNum-1]);
	}
}

// Extension to String
// countWords returns the number of words in inText,
// what's a 'word' use the optional char instead of space
function countWordsExt ( wordDelim) {
	if (wordDelim == null) wordDelim = ' ';
	var dArray = this.split(wordDelim);
	return(dArray.length);
}


// Extension to String
// converts the text m/d/yy to mm/dd/yyyy
function getMMDDYYYY00textExtension () {
	// given a date, return MM/DD/YYYY or DD/MM/YYYY as text from date
	
		var dArray = this.split('/');
		var retVal = '';
	    if (dArray[0].length < 2) retVal = retVal + '0';
		retVal = retVal + dArray[0] + '/';
		
	    if (dArray[1].length < 2) retVal = retVal + '0';
		retVal = retVal + dArray[1] + '/';
	
	    var year = parseInt(dArray[2]);
	    if (year < 10) {
	        retVal += '200';
	    } else if (year < 50) {
	        retVal += '20';
	    } else if (year < 100) {
	        retVal += '19'
	    } else {
	        retVal += dArray[2];
	    }
    return(retVal);
}


Date.prototype.dateAdd = addDaysExt; 
Date.prototype.dateAddInterval = dateAddExtention;
Date.prototype.getMMDDYYtext = getMMDDYYtextExtension;
Date.prototype.getMMDDYYYYtext = getMMDDYYYYtextExtension;
Date.prototype.getMMDDYYYY00text = getMMDDYYYY00textExtension;
Date.prototype.setMMDDYY = setMMDDYYExtension;

String.prototype.firstWord = firstWordExt; /* optional char for word delim */
String.prototype.lastWord = lastWordExt; /* optional char for word delim */
String.prototype.allButLastWord = allButLastWordExt; /* optional char for word delim */
String.prototype.nthWord = nthWordExt; /* index, optional char for word delim */
String.prototype.countWords = countWordsExt;  /* optional char for word delim */
String.prototype.getDAYCode = getDAYCodeExt; /* returns MON portion of the date string that's in MM/DD/YY format */
String.prototype.replaceAll = replaceAllExt; /* from, to replacement text passed */
String.prototype.getMMDDYYYY = getMMDDYYYY00textExtension;

String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};


/* 
	Next functions Originated from
	Reference Article:
Dustin Diaz:
http://www.dustindiaz.com/top-ten-javascript/
*/

function callEvent (obj, type) {
	EventCache.call(obj, type);
}

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		},
		call : function(node, sEventName) {
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				var func = item[2];
				if (item[0] == node) {
					if ((item[1] == sEventName) || (("on"+item[1]) == sEventName)) {
						func();
					}
				}
			};
		}
	};
}();

// usage:
//addEvent(window,'unload',EventCache.flush);


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag); // use "*" for all elements
	var elsLen = els.length;
	var pattern = new RegExp("\\b"+searchClass+"\\b");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

Array.prototype.inArrayPos = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] == value) {
			return i;
		}
	}
	return -1;
}

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
}

// Cookies
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}


// positioning
function findPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
      while(1) 
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}

function getScrollX() {
	var scLeft;
	if (self.pageYOffset) {
		scLeft = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		scLeft = document.documentElement.scrollLeft;
	} else if (document.body) {
		scLeft = document.body.scrollLeft;
	}
	return scLeft;
}

function getScrollY() {
	var scTop;
	if (self.pageYOffset) {
		scTop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		scTop = document.documentElement.scrollTop;
	} else if (document.body) {
		scTop = document.body.scrollTop;
	}
	return scTop;
}


/* simple tabs */
 var panels = new Array('panel1', 'panel2', 'panel3', 'panel4', 'panel5', 'panel6', 'panel7');
 var selectedTab = null;
 function showPanel(tab, name, idx)
 {
 
   if (selectedTab) 
   {
     //selectedTab.style.backgroundColor = '';
     //selectedTab.style.paddingTop = '';
     //selectedTab.style.marginTop = '4px';
     selectedTab.className = "tab"
   }
   if (idx != null) {
    paneName = panels[idx-1];
    tabName = paneName;
    tabName = tabName.replace(/pane/, "tab");
   	tab = $(tabName);
   	name = paneName;
   }
   
   selectedTab = tab;
   selectedTab.className = "tab seltab";
   //selectedTab.style.backgroundColor = 'white';
   //selectedTab.style.paddingTop = '6px';
   //selectedTab.style.marginTop = '0px';        
   for(i = 0; i < panels.length; i++)
   {
		paneName = panels[i];
		tabName = paneName;
		tabName = tabName.replace(/pane/, "tab");
		tab = $(tabName);
   	
		var panelo = document.getElementById(panels[i]);
		if (panelo != null) {
		 	panelo.style.display = (name == panels[i]) ? 'block':'none';
		 	
		 	if (tab.className.indexOf("seltab")>=0) {
		 		// selected
		 		tab.setAttribute("alt","Currently Selected Tab "+tab.innerHTML);
   				tab.setAttribute("title","Currently Selected Tab "+tab.innerHTML);
		 	} else {
		 		// not selected
		 		tab.setAttribute("alt","Show Tab "+tab.innerHTML);
   				tab.setAttribute("title","Show Tab "+tab.innerHTML);
		 	}
		 	
		 	
		} else {
			//
		}
   }
   
   // perform the load if it exists
   	// look for a function called name+load()
	try {
		eval("dumBool = " + name+"loaded;");
		if (dumBool != true) {
			try {
				eval(name+"load()");
			} catch(err) {
				//
			}
		}
		eval(name+"loaded = true;");
	} catch (err) {
		//
		eval(name+"loaded = true;");
		try {
			eval(name+"load()");
		} catch(err) {
			//
		}
	}


   return false;
 }



// add custom tooltips based on A link info
// called on load and only affects a links with class having mytip or myatip in class name
function addCustomTips() {
	var links = document.links || document.getElementsByTagName('a');
	var n = links.length;
	for (var i = 0; i < n; i++) {
		if (links[i].title && links[i].title != '' && (links[i].className.indexOf('mytip') >= 0)) {
			// add the title to anchor innerhtml
			links[i].innerHTML += '<span id="tip'+i+'">'+links[i].title+'</span>'; 
			links[i].title = ''; // remove the title
			
			// now what is the link width 250
			// what is x pos of link
			linkso = $('tip'+i);
			if (linkso != null) {
				var theX = findPosX(links[i]);
				//linkso.style.left = 0;
				if ((theX + 250)>document.width) {
					theX = document.width - 250;
					linkso.style.position = 'relative';
					linkso.style.left = document.width - (theX + 250);
				}
			}
		} else if (links[i].title && links[i].title != '' && (links[i].className.indexOf('myatip') >= 0)) {
			// add the title to anchor innerhtml
			links[i].innerHTML += '<span id="tip'+i+'">'+links[i].title+'</span>'; 
			links[i].title = ''; // remove the title
			
			// now what is the link width 250
			// what is x pos of link
			linkso = $('tip'+i);
			if (linkso != null) {
				var theX = findPosX(links[i]);
				var theY = findPosY(links[i]);
				
				linkso.style.position = 'absolute';
				if ((theX + 250)>document.width) {
					linkso.style.left = document.width - (theX + 300);
				}
			}
		}
		
	}
	
}

function addCustomTipsb() {
	var links = document.links || document.getElementsByTagName('a');
	var n = links.length;
	for (var i = 0; i < n; i++) {
		if (links[i].title && links[i].title != '' && (links[i].className.indexOf('mytip') >= 0)) {
			// add the title to anchor innerhtml
			links[i].innerHTML += '<span id="tip'+i+'">'+links[i].title+'</span>'; 
			links[i].title = ''; // remove the title
			
			// now what is the link width 250
			// what is x pos of link
			linkso = $('tip'+i);
			if (linkso != null) {
				var theX = findPosX(links[i]);
				var theY = findPosY(links[i]);
				
				linkso.style.position = 'absolute';
				if ((theX + 250)>document.width) {
					linkso.style.left = document.width - (theX + 300);
				}
			} else {
				//alert('Link not found: '+i);
			}
		}
	}
}


// Prototype function $

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

// Sample Usage:
//var obj1 = document.getElementById('element1');
//var obj2 = document.getElementById('element2');
//function alertElements() {
//  var i;
//  var elements = $('a','b','c',obj1,obj2,'d','e');
//  for ( i=0;i



