/* Google toolbar autofill workaround */
if(window.attachEvent)
	window.attachEvent("onload",setListeners);
function setListeners(){
	inputList = document.getElementsByTagName("INPUT");
	for(i=0;i<inputList.length;i++){
		inputList[i].attachEvent("onpropertychange",restoreStyles);
		inputList[i].style.backgroundColor = "";
	}
	selectList = document.getElementsByTagName("SELECT");
	for(i=0;i<selectList.length;i++){
		selectList[i].attachEvent("onpropertychange",restoreStyles);
		selectList[i].style.backgroundColor = "";
	}
}
function restoreStyles(){
	if(event.srcElement.style.backgroundColor != "" && event.srcElement.style.backgroundColor != "#a0d0ff"){
		event.srcElement.style.color = "#000"; /* color of choice for AutoFill */
		// document.all['googleblurb'].style.display = "block";
	}
}


/* HOVERHELP */

	function HelpHover(){ 
		this._mousePosX = 0; 
		this._mousePosY = 0; 
		this._hoverItem = null; 
		this._hoverContents = null;
	}
	HelpHover.prototype.init = function(){ 
		var hh = this; 
		var helpItems = document.getElementsByClassName('hasHelp'); 
		for (var i=0; i < helpItems.length; i++){ 
			helpItems[i].onmousemove = function(e){ 
				if (!e) var e = window.event; 
				if (e.pageX || e.pageY){ 
					hh.mousePosX = e.pageX; 
					hh.mousePosY = e.pageY; 
				}else if (e.clientX || e.clientY){ 
					hh.mousePosX = e.clientX + document.documentElement.scrollLeft;
					hh.mousePosY = e.clientY + document.documentElement.scrollTop; 
				}; 
				hh._hoverItem = this; 
				hh._hoverContents = document.getElementById(this.id+'Help'); 
				hh.move();
			}; 
			helpItems[i].onmouseout = function (e){ hh.out(); } 
		} 
	}
	HelpHover.prototype.out = function(){ 
		this._hoverContents.style.top = -10000+'px'; 
		this._hoverContents.style.left = -10000+'px';
		this._hoverItem = null; 
		this._hoverContents = null;
		if (document.getElementById("HHiFrameShim")) {
			document.getElementById('HHiFrameShim').style.top = -10000+'px';
			document.getElementById('HHiFrameShim').style.left = -10000+'px';
		}
	}
	HelpHover.prototype.move = function(){ 
		this._hoverContents.style.top = this.mousePosY+10+'px'; 
		this._hoverContents.style.left = this.mousePosX+10+'px';
		if (navigator.userAgent.indexOf('MSIE') != -1){
			if (!document.getElementById("HHiFrameShim")) {
				try {
					var newNode = document.createElement("iFrame");
					newNode.setAttribute("id", "HHiFrameShim");
					newNode.setAttribute("src", "javascript:false;");
					newNode.setAttribute("scrolling", "no");
					newNode.setAttribute ("frameborder", "0");
					document.body.appendChild(newNode);
				} catch(e) {  }
			}
			try { 		
				HHShim = document.getElementById('HHiFrameShim');
				HHShim.style.position = "absolute";
				HHShim.style.width = this._hoverContents.offsetWidth;
				HHShim.style.height = this._hoverContents.offsetHeight;
				HHShim.style.top = this.mousePosY+10+'px'; 
				HHShim.style.left = this.mousePosX+10+'px';
				HHShim.style.zIndex = 100 - 1;
				HHShim.style.visibility = true;
				HHShim.style.display = 'none';
			} catch(e) {  }
		}
	}
	addEvent(window, 'load', function(){ var hh = new HelpHover(); hh.init(); });
	document.getElementsByClassName = function (needle){ 
		var my_array = document.getElementsByTagName("*"); 
		var retvalue = new Array(); 
		var i; 
		var j; 
		for (i = 0, j = 0; i < my_array.length; i++){ 
			var c = " " + my_array[i].className + " "; 
			if (c.indexOf(" " + needle + " ") != -1){ 
				retvalue[j++] = my_array[i];
			}
		} 
		return retvalue;
	}
	function addEvent(obj, evType, fn){ 
		if (obj.addEventListener){ 
			obj.addEventListener(evType, fn, true); 
			return true; 
		}else if (obj.attachEvent){ 
			var r = obj.attachEvent("on"+evType, fn); 
			return r; 
		}else{ 
			return false; 
		}
	}


/* MISC */
	function hidestatus(){ window.status=''; return true }
	if (document.layers){ document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT) }
	document.onmouseover = hidestatus;
	document.onmouseout = hidestatus;
	
	String.prototype.trim = function () {
		return this.replace(/^\s*|\s*$/,"");
	}
	
	function popUp(URL,windowName,width,height) {	
		var features = 'width=' + width + ',height=' + height + ',location=no' + ',menubar=no' + ',scrollbars=yes' + ',status=no' + ',toolbar=no' + ',resizable=yes,top=10,left=10';
		window.open (URL, windowName, features);
	}
	function confirmIt(message,url) { 
		if (confirm(message)){ self.location = url; } 
	}
	function selRow(IDprefix, defClass,addClass){
		cbox = document.getElementById(IDprefix + '_checkbox');
		trow = document.getElementById(IDprefix + '_row');
		if( cbox.checked == true ){ trow.className = 'row01s ' + addClass; }else{ trow.className = defClass; }
	}
	function selAll(IDprefix, defClass, numRows, allchecked){
		set_val = document.getElementById(IDprefix + 'checkbox_all').checked;
		for(i=1; i<=numRows; i++){
			document.getElementById(IDprefix + i + '_checkbox').checked = set_val;
			IdItemPrefix = IDprefix + i;
			selRow(IdItemPrefix, defClass);
		}
	}
	function checkAll(prefix, start, end, sel){
		if(sel){ cval = true; }else{ cval = false; }	
		for(i=start; i<=end; i++){
			try{ document.getElementById(prefix + i).checked = cval; }catch(err){}
		}
	}
	function SetAllCheckBoxes(FormName, FieldName, CheckValue){
		if(!document.forms[FormName]){
			return;
		}
		var objCheckBoxes = document.forms[FormName].elements[FieldName];
		if(!objCheckBoxes){
			return;
		}
		var countCheckBoxes = objCheckBoxes.length;
		if(!countCheckBoxes){
			objCheckBoxes.checked = CheckValue;
		}else{
			// set the check value for all check boxes
			for(var i = 0; i < countCheckBoxes; i++){
				objCheckBoxes[i].checked = CheckValue;
			}
		}
	}
	function showHide(this_id){ 
		obj = document.getElementById(this_id);
		if(obj.style.display == 'none'){ obj.style.display = 'block'; }else{ obj.style.display = 'none'; }
	}
	function pageTab(tab,tabtot,start,end){
		if (typeof start == 'undefined'){
			start = 1;
		}
		if (typeof end == 'undefined'){
			end = tabtot;
		}
		for(i=start; i<=end; i++){
			if( tab == i ){ 
				cdisp = 'block';
				tclass = 'page_tab_on';
			}else{ 
				cdisp = 'none';
				tclass = 'page_tab';
			}
			document.getElementById('page_div_' + i).style.display = cdisp;
			document.getElementById('page_tab_' + i).className = tclass;
		}
	}
	function formCharLimit(id, limit, alrt, ismin){
		ismin = typeof(ismin) != 'undefined' ? ismin : 0;
		fld = $('#' + id);
		dsp = $('#' + id + '_chr_cnt');
		num = fld.val().length > 0 ? fld.val().length : '0';
		dsp.html( num );
		if( ismin ){
			if( fld.val().length < limit ){
				dsp.addClass('error');
				dsp.addClass('bold');
			}else{
				dsp.removeClass('error');
				dsp.removeClass('bold');
			}
		}else{
			if( fld.val().length > limit ){
				dsp.addClass('error');
				dsp.addClass('bold');
			}else{
				dsp.removeClass('error');
				dsp.removeClass('bold');
			}
		}	
	}
	// Function add number sorting to array function ".sort()" ---> ".sort(arrSortNumber)"
	function arrSortNumber(a,b){
		return a - b;
	}	
	// Function to add array "indexOf" function to browsers that do not support it (IE)
	if (!Array.indexOf) {
		Array.prototype.indexOf = function (obj, start) {
		for (var i = (start || 0); i < this.length; i++) { if (this[i] == obj) { return i; } }
	  }
	}

/* DIRECTORY */
	function serverAction(action,urlvars){
		$.get('server_action.cfm?action=' + action + urlvars);
	}
	function faqs(a) { 
		faqs_window = window.open('list_sites_faqs.cfm#' + a,'faqs_window','toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=700,height=500,left=50,top=50')
	}

/* DATE PICKER SCRIPTS */

	var datePickerDivID = "datepicker";
	var iFrameDivID = "datepickeriframez";
	var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
	var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
	var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
	var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
	var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
	var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	var defaultDateSeparator = "/";   // common values would be "/" or "."
	var defaultDateFormat = "mdy";    // valid values are "mdy", "dmy", and "ymd"
	var dateSeparator = defaultDateSeparator;
	var dateFormat = defaultDateFormat;
	var initiated = 1;
	function displayDatePicker(dateFieldName, displayBelowThisObject,dtFormat,dtSep){
		
		var targetDateField = document.getElementById(dateFieldName);
		if (!displayBelowThisObject)
			displayBelowThisObject = targetDateField;
		if (dtSep)
			dateSeparator = dtSep;
		else
			dateSeparator = defaultDateSeparator;
		if (dtFormat)
			dateFormat = dtFormat;
		else
			dateFormat = defaultDateFormat;
		
		var x = displayBelowThisObject.offsetLeft;
		var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
		
		var parent = displayBelowThisObject;
		while (parent.offsetParent) {
			parent = parent.offsetParent;
			x += parent.offsetLeft;
			y += parent.offsetTop ;
		}
		drawDatePicker(targetDateField, x, y);
	}
	function drawDatePicker(targetDateField, x, y){
		var dt = getFieldDate(targetDateField.value );
		
		if (!document.getElementById(datePickerDivID)) {
			var newNode = document.createElement("div");
			newNode.setAttribute("id", datePickerDivID);
			newNode.setAttribute("class", "dpDiv");
			newNode.setAttribute("style", "visibility: hidden;");
			document.body.appendChild(newNode);
		}
		
		var pickerDiv = document.getElementById(datePickerDivID);
		pickerDiv.style.position = "absolute";
		pickerDiv.style.left = x + "px";
		pickerDiv.style.top = y + "px";
		pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
		pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
		pickerDiv.style.zIndex = 10000;
		
		refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate());
	}
	function refreshDatePicker(dateFieldName, year, month, day){
		
		cutMonth = getCutDate(dateFieldName, 'month');
		cutDay = getCutDate(dateFieldName, 'day');
		cutYear = getCutDate(dateFieldName, 'year');
		cutDate = cutMonth + "/" + cutDay + "/" + cutYear;
			
		var thisDay = new Date();
		
		if ((month >= 0) && (year > 0)) {
			thisDay = new Date(year, month, 1);
		} else {
			thisDay = new Date((cutYear), (cutMonth-1), 1);
		}
		
		var crlf = "\r\n";
		var TABLE = "<table cols=7 class='dpTable'>" + crlf;
		var xTABLE = "</table>" + crlf;
		var TR = "<tr class='dpTR'>";
		var TR_title = "<tr class='dpTitleTR'>";
		var TR_days = "<tr class='dpDayTR'>";
		var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
		var xTR = "</tr>" + crlf;
		var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' ";
		var TD_title = "<td colspan=5 class='dpTitleTD'>";
		var TD_buttons = "<td class='dpButtonTD'>";
		var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>";
		var TD_days = "<td class='dpDayTD'>";
		var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' ";
		var xTD = "</td>" + crlf;
		var DIV_title = "<div class='dpTitleText'>";
		var DIV_selected = "<div class='dpDayHighlight'>";
		var xDIV = "</div>";
		
		var html = TABLE;
		html += TR_title;
		html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "&lt;") + xTD;
		html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
		html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "&gt;") + xTD;
		html += xTR;
		html += TR_days;// this is the row that indicates which day of the week we're on
		for(i = 0; i < dayArrayShort.length; i++)
			html += TD_days + dayArrayShort[i] + xTD;
		html += xTR;
		html += TR;// now we'll start populating the table with days of the month
		
		// first, the leading blanks
		for (i = 0; i < thisDay.getDay(); i++)
			html += TD + "&nbsp;" + xTD;
			
		// now, the days of the month
		monthNum = thisDay.getMonth();
		yearNum = thisDay.getFullYear();
		
		do {
			dayNum = thisDay.getDate();
			
			if( (monthNum<=(cutMonth-1)) && (dayNum<cutDay) && (yearNum<=cutYear) ){
				TD_onclick = " style=\"color: #FF0000; text-decoration: line-through\">";
			}else{
				TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
			}
			
			if (dayNum == day){
				html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
			}else{
				html += TD + TD_onclick + dayNum + xTD;
			}
			
			if (thisDay.getDay() == 6)// if this is a Saturday, start a new row
				html += xTR + TR;
				
			thisDay.setDate(thisDay.getDate() + 1);// increment the day
		} while (thisDay.getDate() > 1)
	
		// fill in any trailing blanks
		if (thisDay.getDay() > 0) {
			for (i = 6; i > thisDay.getDay(); i--)
				html += TD + "&nbsp;" + xTD;
		}
		html += xTR;
			
		var today = new Date();// add a button to allow the user to easily return to today, or close the calendar
		var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[ today.getMonth()] + " " + today.getDate();
		html += TR_todaybutton + TD_todaybutton;
		
		show_first_avail = document.getElementById('first_avail').value;
	
		if( show_first_avail == 1 ){ html += "<button style='width:100px' class='dpTodayButton' onClick='updateDateField(\"" + dateFieldName + "\",\"" + cutDate + "\");'>first available</button> "; }
			
		html += "<button style='width:40px' class='dpTodayButton' onClick='updateDateField(\"" + dateFieldName + "\");'>close</button>";
		html += xTD + xTR;
		
			html += xTABLE;// and finally, close the table
			document.getElementById(datePickerDivID).innerHTML = html;
		adjustiFrame();// add an "iFrame shim" to allow the datepicker to display above selection lists
	}
	function getButtonCode(dateFieldName, dateVal, adjust, label){
	
		cutMonth = getCutDate(dateFieldName, 'month');
		cutDay = getCutDate(dateFieldName, 'day');
		cutYear = getCutDate(dateFieldName, 'year');
		
		var newMonth = (dateVal.getMonth () + adjust) % 12;
		var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
		if (newMonth < 0) {
			newMonth += 12;
			newYear += -1;
		}
		
		varWA1 = cutYear - 1900;
		varWA2 = dateVal.getYear();
		
		if( adjust == -1 && dateVal.getMonth() == (cutMonth-1) && varWA1 == varWA2 ){
			return "";
		}else{
			return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ", 0);'>" + label + "</button>";
		}
	}
	function getDateString(dateVal){
		var dayString = "00" + dateVal.getDate();
		var monthString = "00" + (dateVal.getMonth()+1);
		dayString = dayString.substring(dayString.length - 2);
		monthString = monthString.substring(monthString.length - 2);
		
		switch (dateFormat) {
			case "dmy" : return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
			case "ymd" : return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
			case "mdy" : 
			default : return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
		}
	}
	function getFieldDate(dateString) {
		var dateVal;
		var dArray;
		var d, m, y;
		try {
			dArray = splitDateString(dateString);
			if (dArray) {
				switch (dateFormat) {
					case "dmy" : d = parseInt(dArray[0], 10); m = parseInt(dArray[1], 10) - 1; y = parseInt(dArray[2], 10); break;
					case "ymd" : d = parseInt(dArray[2], 10); m = parseInt(dArray[1], 10) - 1; y = parseInt(dArray[0], 10); break;
					case "mdy" : default : d = parseInt(dArray[1], 10); m = parseInt(dArray[0], 10) - 1; y = parseInt(dArray[2], 10); break;
				}
				dateVal = new Date(y, m, d);
			} else if (dateString) {
				dateVal = new Date(dateString);
			} else {
				dateVal = new Date();
			}
		} catch(e) { dateVal = new Date(); }
		return dateVal;
	}
	function splitDateString(dateString){
		var dArray;
		if (dateString.indexOf("/") >= 0)
			dArray = dateString.split("/");
		else if (dateString.indexOf(".") >= 0)
			dArray = dateString.split(".");
		else if (dateString.indexOf("-") >= 0)
			dArray = dateString.split("-");
		else if (dateString.indexOf("\\") >= 0)
			dArray = dateString.split("\\");
		else
			dArray = false;
	
		return dArray;
	}
	function updateDateField(dateFieldName, dateString){
		cutMonth = getCutDate(dateFieldName, 'month');
		cutDay = getCutDate(dateFieldName, 'day');
		cutYear = getCutDate(dateFieldName, 'year');
		cutYear = cutYear;
		
		if(dateString){ 
			thisDateString = dateString; 
		}else{ 
			datePickerSelected(dateFieldName);
			thisDateString = op_date; 
		}
		
		dateArray = splitDateString(thisDateString);
		thisMonth = parseFloat(dateArray[0]);
		thisDay = parseFloat(dateArray[1]);
		thisYear = parseFloat(dateArray[2]);
		
		if( (thisYear < parseInt(cutYear)) || (thisMonth < parseInt(cutMonth) && thisYear <= parseInt(cutYear)) || (thisDay < parseInt(cutDay) && thisMonth <= parseInt(cutMonth) && thisYear <= parseInt(cutYear)) ){
			alert('The date you have chosen is not available');
			thisMonth = cutMonth;
			thisDay = cutDay;
			thisYear = cutYear;
			thisDateString = cutMonth + '/' + cutDay + '/' + cutYear;
		}
		
		document.getElementById(dateFieldName + '_month').selectedIndex = thisMonth - 1;
		document.getElementById(dateFieldName + '_day').selectedIndex = thisDay - 1; 
		document.getElementById(dateFieldName + '_year').selectedIndex = thisYear - document.getElementById(dateFieldName + '_year')[0].value;
		
		var targetDateField = document.getElementById(dateFieldName);
		targetDateField.value = thisDateString;
		
		var pickerDiv = document.getElementById(datePickerDivID);
		if(pickerDiv){
			pickerDiv.style.visibility = "hidden";
			pickerDiv.style.display = "none";
		}
		adjustiFrame();	
	}
	function adjustiFrame(pickerDiv, iFrameDiv){
		if(initiated){
			var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
			if (is_opera)
				return;
			try {
				if (!document.getElementById(iFrameDivID)) {
					var newNode = document.createElement("iFrame");
					newNode.setAttribute("id", iFrameDivID);
					newNode.setAttribute("src", "javascript:false;");
					newNode.setAttribute("scrolling", "no");
					newNode.setAttribute ("frameborder", "0");
				}			
				if (!pickerDiv)
					pickerDiv = document.getElementById(datePickerDivID);
				if (!iFrameDiv)
					iFrameDiv = document.getElementById(iFrameDivID);
				try {
					iFrameDiv.style.position = "absolute";
					iFrameDiv.style.width = pickerDiv.offsetWidth;
					iFrameDiv.style.height = pickerDiv.offsetHeight ;
					iFrameDiv.style.top = pickerDiv.style.top;
					iFrameDiv.style.left = pickerDiv.style.left;
					iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
					iFrameDiv.style.visibility = pickerDiv.style.visibility ;
					iFrameDiv.style.display = pickerDiv.style.display;
				} catch(e) { }
			} catch (ee) { }
		}
	}
	function datePickerSelected(fieldName){
		op_month = document.getElementById(fieldName + '_month').value;
		op_day = document.getElementById(fieldName + '_day').value;
		op_year = document.getElementById(fieldName + '_year').value;
		op_date = op_month + '/' + op_day + '/' + op_year;
		return op_date;
	}
	function getCutDate(fieldName, datePart){ 
		return_val = document.getElementById(fieldName + '_cut_' + datePart).value;
		return return_val;
	}
	initiated = 1;