



// client-side functions for [parking-brand].com

// pop-up window
function openW(url, name, w, h, x, y, o) {
// options - scrollbars, resizable (there are more)
// if you want them just list them seperated by commas
	var windowprops = "width=" + w + ", height=" + h; // size
	windowprops += "left=" + x + ", screenX=" + x + ", top=" + y + ", screenY=" + y + ", "; // location
	windowprops += "toolbar=0, location=0, directories=0, status=0, menubar=0, marginwidth=0, marginheight=0";
	if (o != '')
	    windowprops += ", " + o;
	popup = window.open(url, name, windowprops);
	popup.focus();
}

// more info pop-ups
function showInfo(topic) {
	openW("/partners/pages/help/helpPop.jsp?key=" + topic, "infoPop", 400, 280, 25, 25, "scrollbars=1, resizable=1")
}

// more info pop-ups
function showInfoTemplate(topic) {
	openW("/partners/pages/help/helpPop.jsp?key=" + topic, "infoPop", 833, 472, 25, 25, "scrollbars=1, resizable=1")
}

// validate email address
function isValidEmail(email) {
    var result = true;
    if (email != null && email.length > 0) {
        var emailRegxp = /^.+@.+\..{2,4}$/;
        result = emailRegxp.test(email);
    }
    return result;
}

// Check/Uncheck all checkboxes -- need to include (this) when calling up function
function checkAll(box) {
	var obj = document.forms[0].elements;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].type == "checkbox" && obj[i].name != box.name) {
			if (box.checked) {
				obj[i].checked = true;
			} else {
				obj[i].checked = false;
			}
		}
	}
}

// Uncheck the "Check All" checkbox -- need to include the id of the "Check All" box when calling up function
function uncheckAllBox(box) {
	document.getElementById(box).checked = false;
}

// Get correct number of days in a month
function showDays(whichDayList, month, dateRangeRadioButton, dateRangeRadioButtonValue) {
	month = month - 1; // take into account actual placement of month in dropdown box
	var dayLength = 31; // number of days in the months
	if (month == 4 || month == 6 || month == 9 || month == 11) {
		dayLength = 30;
	} else if (month == 2) {
		dayLength = 28;
	}
	var currentDay = document.getElementById(whichDayList);
	currentDay = currentDay.selectedIndex;
	var tmpDayList = "<select name=\"" + whichDayList + "\" id=\"" + whichDayList + "\" class=\"formFont\" onchange=\"changeRadioButtonByValue(" + dateRangeRadioButton + ", '" + dateRangeRadioButtonValue + "')\">";
	tmpDayList += "<option selected=\"selected\" value=\"\">Day</option>";
	tmpDayList += "<option value=\"\">----</option>";
	for (var i = 1; i < dayLength + 1; i++) { // have same day selected if change months
		if (i == currentDay - 1) {
			tmpDayList += "<option value=\"" + i + "\" selected=\"selected\">" + i + "</option>";
		} else {
			tmpDayList += "<option value=\"" + i + "\">" + i + "</option>";
		}
	}
	tmpDayList += "</select>&nbsp;";
	var obj = document.getElementById(whichDayList + "List");
	obj.innerHTML = tmpDayList;
}

function changeRadioButtonByValue(radioButton, radioButtonValue) {
    for (var i = 0; i < radioButton.length; i++)  {
        if (radioButton[i].value == radioButtonValue)  {
            radioButton[i].checked = true;
        }
    }
}

// allows buttons on manage pages to submit -- is turned to true if valid
var boolValidSubmit = false; // do not allow form to be submitted
function isValidForm() {
    // alert (boolValidSubmit);
    return boolValidSubmit;
}

// swapping the form action on manage pages -- no requirements
function swapAction (theAction) {
    document.forms[0].action = theAction;
    boolValidSubmit = true; // allow form to be submitted
}

// swapping the form action on manage pages -- requires selected checkboxes
function swapActionCheck (theAction) {
    boolValidSubmit = false;
    var obj = document.forms[0].elements;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].type == "checkbox") {
		    if (obj[i].checked) {
               document.forms[0].action = theAction;
               boolValidSubmit = true; // allow form to be submitted
               return;
		    }
		}
	}
	var objErr = document.getElementById("errorMsg");
	objErr.innerHTML = "You have not selected any items to manage.";
	objErr.className = "inlineError";
	scrollToTop();
}

// swapping the form action on manage pages -- requires text in textbox
function swapActionSearch (theAction) {
    boolValidSubmit = false;
    var obj = document.forms[0].elements;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].type == "text") {
		    if (obj[i].value != "") {
		       document.forms[0].action = theAction;
               boolValidSubmit = true; // allow form to be submitted
               return;
		    }
		}
	}
	var objErr = document.getElementById("errorMsg");
	objErr.innerHTML = "You have not entered text to be searched.";
	objErr.className = "inlineError";
	scrollToTop();
}
// test to make sure [Default] portfolio checkbox is not selected
function testDefault(value, theAction) {
    boolValidSubmit = false;
    var obj = document.forms[0].elements;
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].type == "checkbox" && obj[i].value == value) {
			if (obj[i].checked) { // Default is checked -- will be forced unchecked
			    obj[i].checked = false;
			    document.forms[0].elements["all"].checked = false;
			    var objErr = document.getElementById("errorMsg");
	            objErr.innerHTML = "You cannot rename or delete the [Default] portfolio.";
	            objErr.className = "inlineError";
	            scrollToTop();
			    return;
			}
		}
	}
	swapActionCheck(theAction);
}

// allow form to submit to new window
function swapTarget(newTarget) {
	var obj = document.forms[0];
	obj.target = newTarget;
}

// used to scroll to show the error msg
function scrollToTop() {
    window.scrollTo(0, 0);
}

// date info
// code for conversion of dates for comparison to see if it's still active or expired
var today = new Date();
var todayMonth = today.getMonth() + 1;
var todayDate = today.getDate();
var todayYear = today.getYear();
if (todayYear < 2000) { // Netscape fix
	todayYear = todayYear + 1900;
}
var monName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
var strToday = monName[todayMonth - 1] + " " + todayDate + ", " + todayYear;
var strDay1 = monName[todayMonth - 1] + " 1, " + todayYear;

// Auto center window script
var win = null;
function centerWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}

// get elements by their class name
function getElementsByClassName(thisTag, thisClass) {
	var obj = document.getElementsByTagName(thisTag);
	var arrElements = new Array();
	for (i = 0; i < obj.length; i++) {
		if(obj[i].className == thisClass) {
			arrElements[arrElements.length] = obj[i]
		}
	}
	return arrElements;
}

