//populate the page number in the left nav section so that we know which main link
//to highlight when we are in that section
function PopulatePageNumber(){
	if (document.getElementById("footer_lblPageOn")) pageSpanName = "footer_lblPageOn";

	if (getValue(pageSpanName,"innerHTML") != ""){
		var newClassName = "topnavon";
		switch (getValue(pageSpanName,"innerHTML")){
			case "0":
				document.getElementById("menuMissionStatement").className = newClassName;
				break;
			case "1":
				document.getElementById("menuCommandStaff").className = newClassName;
				break;
			case "2":
				document.getElementById("menuPoliceUnits").className = newClassName;
				break;
			case "3":
				document.getElementById("menuTipsLine").className = newClassName;
				break;
			case "4":
				document.getElementById("menuAccreditation").className = newClassName;
				break;
			case "5":
				document.getElementById("menuContactUs").className = newClassName;
				break;
			case "6":
				document.getElementById("menuCareers").className = newClassName;
				break;
			case "7":
			    document.getElementById("menuMemorial").className = newClassName;
				break;
		}
	}
}

//checks to see if the passed in document ID of a radiobutton/checkbox is checked or not
function isChecked(idValue){
	if (document.getElementById(idValue).checked) return true;
	return false;
}

//gets the value of the passed in document ID based on "value" or "innerHTML" and returns it to
//the calling code
function getValue(idValue,idValueType){
	var elementValue = "";
	if (document.getElementById(idValue)){
		if (idValueType == "value"){
			elementValue = document.getElementById(idValue).value;
		}
		else{
			elementValue = document.getElementById(idValue).innerHTML;
		}
	}
	return elementValue;
}

//sets the value of the passed in document ID to the passed in value based on "value" or "innerHTML"
//example: setValue('txtSomeFieldName','value','ajaxSpanName','innerHTML');
//we chose "value" for the textbox because a textbox would use 'value' instead of 'innerHTML'
function setValue(idValue,idDisplayType,newValue,newValueType){
	//IF YOU GET AN ERROR, UNCOMMENT ALERT LINE TO LEAD YOU TO THE MISSING ID ELEMENT
	//alert("idValue = " + idValue + ", idDisplayType = " + idDisplayType + ", newValue = " + newValue + ", newValueType = " + newValueType);
	if (idDisplayType == "value" && newValueType == "innerHTML"){
		setSpecific(idValue,"value",getValue(newValue,"innerHTML"));
	}
	if (idDisplayType == "value" && newValueType == "value"){
		setSpecific(idValue,"value",getValue(newValue,"value"));
	}
	if (idDisplayType == "innerHTML" && newValueType == "value"){
		setSpecific(idValue,"innerHTML",getValue(newValue,"value"));
	}
	if (idDisplayType == "innerHTML" && newValueType == "innerHTML"){
		setSpecific(idValue,"innerHTML",getValue(newValue,"innerHTML"));
	}
}

//this function is just like the function above, but it sets the value of the passed in document ID
//to a specific value passed into the function: "newValue"
function setSpecific(idValue,idDisplayType,newValue){
	//alert("idValue = " + idValue + ", idDisplayType = " + idDisplayType + ", newValue = " + newValue);
	if (document.getElementById(idValue)){
		if (idDisplayType == "value"){
			document.getElementById(idValue).value = newValue;
		}
		else {
			document.getElementById(idValue).innerHTML = newValue;
		}
	}
}

//sets the display value of the passed in document ID to the passed in display value
function showHide(idValue,displayValue){
	//alert("idValue = " + idValue + "\ndisplayValue = " + displayValue);
	if (document.getElementById(idValue)){
		var newDisplayValue = "hidden";
		if (displayValue != "none") newDisplayValue = "visible";
		document.getElementById(idValue).style.display = displayValue;
		document.getElementById(idValue).style.visibility = newDisplayValue;
	}
}

function getObjectCoordinates(obj){
	var curLeft = 0;
	var curTop = 0;
	if (obj.offsetParent) {
		curLeft = obj.offsetLeft
		curTop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curLeft += obj.offsetLeft
			curTop += obj.offsetTop
		}
	}
	return curLeft + "|" + curTop;
}

//move the pop-up so that it's visible on the screen
function moveHelpDiv(pos,finalPos){
	document.getElementById("createAccountBox").style.top = pos + "px";
	if (pos > finalPos){
		newPos = pos - 5;
		setTimeout("moveHelpDiv("+newPos+"," + finalPos + ")",1);
	}
	else{
		setFocus("txtVendorNameCreate");
	}
}

//set the focus to the specified control
function setFocus(boxName){
	var currentBoxNumber = 0;
	try{
		document.getElementById(boxName).focus();
	}
	catch(e){
		//get number of boxName form element in the form and set currentBoxNumber equal to it
		for (i=0;i<=Form1.elements.length-1;i++){
			if (Form1.elements[i].id == boxName){
				currentBoxNumber = i;
			}
		}
		
		//loop through form elements beginning with passed in boxName until we find an element
		//that will accept the focus
		for (i=currentBoxNumber;i<=Form1.elements.length-1;i++){
			try{
				document.getElementById(Form1.elements[i].id).focus();
				break;
			}
			catch(err){
				
			}
		}
	}
}

function repositionCreateAccountBox(obj){
	var newWidth = 300;
	var objectCoordinates = getObjectCoordinates(document.getElementById(obj));
	//var newLeft = (document.body.clientWidth/2)-(newWidth/2);
	var newLeft = parseInt(objectCoordinates.substring(0,objectCoordinates.indexOf("|")) - 210);
	var newTop = parseInt(objectCoordinates.substring(objectCoordinates.indexOf("|") + 1,objectCoordinates.length));
	newTop = newTop + 18;
	var finalTop = newTop;
	var newHeight = 475;
	var needToScroll = false;
	var loginBox = document.getElementById("createAccountBox");
	var bodyHeight = document.body.offsetHeight;
	var bodyScroll = document.body.scrollTop;
	showHide("createAccountBox","block");
	loginBox.style.width = newWidth + "px";
	loginBox.style.height = newHeight + "px";
	loginBox.style.left = newLeft + "px";
	loginBox.style.top = newTop + "px";
	setFocus("txtVendorNameCreate");
}

function moveDiv(obj,divID){
	var objectCoordinates = getObjectCoordinates(document.getElementById(obj));
	var divObject = document.getElementById(divID);
	var newWidth = parseInt(divObject.style.width);
	var newLeft = (document.body.clientWidth/2)-(newWidth/2);
	var newTop = parseInt(objectCoordinates.substring(objectCoordinates.indexOf("|") + 1,objectCoordinates.length));
	newTop = newTop + 18;
	showHide(divID,"block");
	divObject.style.left = newLeft + "px";
	divObject.style.top = newTop + "px";
}

var alreadyRun = false; //need to set this here so it remembers throughout our double-running...
//tool tips based on control that calls this function
function toolTip(itemID,tipBeg,tipContent){
	var tipDivCover = document.getElementById("onScreenInfoCover");
	var itemPos = getObjectCoordinates(itemID);
	var toolTipPos = getObjectCoordinates("toolTip");
	var tipID = document.getElementById("toolTip");
	var newTop = parseInt(itemPos.substring(itemPos.indexOf("|") + 1,itemPos.length)) - 2;
	var newLeft = parseInt(itemPos.substring(0,itemPos.indexOf("|"))) + 1;
	var toolTipHeight = parseInt(document.getElementById("toolTip").clientHeight);
	showHide("toolTip","block");
	showHide("onScreenInfoCover","block");
	setSpecific("toolTip","innerHTML","<p class='smallerText'><strong>" + tipBeg + "</strong></p> " + tipContent);
	tipID.style.top = (newTop - toolTipHeight) + "px";
	tipID.style.left = newLeft + "px";
	tipDivCover.style.width = parseInt(document.getElementById("toolTip").clientWidth)+2 + "px";
	tipDivCover.style.height = toolTipHeight+2 + "px";
	tipDivCover.style.left = newLeft + "px";
	tipDivCover.style.zIndex = "99";
	tipDivCover.style.top = tipID.style.top;

	if (!alreadyRun){
		alreadyRun = true;
		toolTip(itemID,tipBeg,tipContent); //run the script one more time to get the appropriate values
	}
	else {
		alreadyRun = false;
	}
}

function hideToolTip(){
	showHide("toolTip","none");
	showHide("onScreenInfoCover","none");
}

/***************************/
/*     SUGGESTION DDL      */
/***************************/
function setLyr(obj,lyr, addTop, addLeft)
{
	var coors = findPos(obj);
	if (lyr == 'testP') coors[1] -= 50;
	var x = document.getElementById(lyr);
	x.style.display = "block";
	if (document.getElementById("ajaxSuggestHeight")){
		if (getValue("ajaxSuggestHeight","innerHTML") != "0px"){
			x.style.height = getValue("ajaxSuggestHeight","innerHTML");
		}
		else{
			x.style.display = "none";
		}
	}
	x.style.top = (coors[1] + addTop) + 'px';
	x.style.left = (coors[0] + addLeft) + 'px';
	x.style.zIndex = "50";
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

/***************************/
/*     AJAX FUNCTIONS      */
/***************************/
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;

function getNewXMLHttpRequest() {
	var obj;
	try {
	// For Internet Explorer.
	var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
	obj = new ActiveXObject(strObjName);
	}
	catch(e) {
		try {
			// Gecko-based browsers, Safari, and Opera.
			obj = new XMLHttpRequest();
		}
		catch (e) {
			// Browser supports Javascript but not XMLHttpRequest.
			obj = false;
		}
	}
	return obj;
}

function uncache(){
	var d = new Date();
	var time = d.getTime();
	return time;
} 

//function ajaxFunction will take several parameters and return values based on the asp.net functions that are called
//Input:
//  getPost = either GET or POST depending on the method used to submit to this function
//  functionToCall = the asp.net function to call located in the /ajaxfunction.aspx.vb file
//  param1 through param5 = optional parameters that can be passed into this function and used in asp.net
//  resultsID = the id of the control on the asp.net web page that should display the results of the ajax function
//Output:
//  results of the ajax function after asp.net functions are called (return results may or may not exist)
//Example:
//  ajaxFunction('GET', 'QuickLinks', 'no', window.location.href.replace('http://' + document.domain,''), '', '', 'leftnavmainlink');
function ajaxFunction(getPost, functionToCall, param1, param2, param3, param4, param5, resultsID, isFormElement){
	if (document.getElementById(resultsID)){
		setSpecific(resultsID,"innerHTML","");
	}
	
	var requestURL = "/ajaxfunctions.aspx?";
	var encodedParams = "";
	encodedParams += "&param1=" + encodeURIComponent(param1)
	encodedParams += "&param2=" + encodeURIComponent(param2)
	encodedParams += "&param3=" + encodeURIComponent(param3)
	encodedParams += "&param4=" + encodeURIComponent(param4)
	encodedParams += "&param5=" + encodeURIComponent(param5)
	
	if (getPost == "GET"){
		var request = getNewXMLHttpRequest();
		request.open('GET',requestURL + "functionToCall=" + functionToCall + encodedParams + "&time=" + uncache(),false);
		request.send();
	}
	else {
		var request = getNewXMLHttpRequest();
		var params = getFormValues("");
		params += "&functionToCall=" + functionToCall + encodedParams + "&time=" + uncache();
		request.open('POST', requestURL, false);
		request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		request.send(params);
	}
	
	//alert(request.responseText);
	if (document.getElementById(resultsID)){
		var parentElement = document.getElementById(resultsID);
		
		parentElement.innerHTML = '';
		
		try {
			parentElement.innerHTML = request.responseText;
		}
		catch (e) {
			// IE fails unless we wrap the string in another element.
			var wrappingDiv = document.createElement('span');
			wrappingDiv.innerHTML = request.responseText;
			parentElement.appendChild(wrappingDiv);
		}
	}
}

function getFormValues(valFunc) 
{ 
   var str = ""; 
   var valueArr = null; 
   var val = ""; 
   var cmd = ""; 

   for(var i = 0;i < Form1.elements.length;i++) 
   { 
       switch(Form1.elements[i].type) 
       { 
			case "text":
				str += Form1.elements[i].name + "=" + encodeURI(Form1.elements[i].value) + "&"; 
				break; 
			case "password":
				str += Form1.elements[i].name + "=" + encodeURI(Form1.elements[i].value) + "&"; 
				break; 
			case "textarea":
				str += Form1.elements[i].name + "=" + encodeURI(Form1.elements[i].value) + "&";
				break;
			case "checkbox":
				if(Form1.elements[i].checked) str += Form1.elements[i].name + "=" + encodeURI(Form1.elements[i].value) + "&";
				break;
			case "radio":
				if(Form1.elements[i].checked) str += Form1.elements[i].name + "=" + encodeURI(Form1.elements[i].value) + "&";
				break;
			case "select-one":
				if (Form1.elements[i].selectedIndex == -1){
					str += Form1.elements[i].name + "=&";
				}
				else {
					str += Form1.elements[i].name + "=" + Form1.elements[i].options[Form1.elements[i].selectedIndex].value + "&"; 
				}
				break;
       }
   } 
   str = str.substr(0,(str.length - 1)); 
   return str; 
}

/***************************/
/*     SEARCH FUNCTION     */
/***************************/
var originalTextForSearchReset = "";

function saveOriginalPageContentForSearch(){
	originalTextForSearchReset = document.body.innerHTML;	
}

function searchPage(){
	var qs = window.location.search.substring(1);
	var vars = qs.split("&");
			
	for (var i=0;i<vars.length;i++){
		var pair = vars[i].split("=");
		if (pair[0] == "q"){
			highlightSearchTerms(pair[1],true,false);
		}
	}
}

function removeSearchHighlight(){
	
}

/* This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}

function trimAndHighlight(sString){
	document.body.innerHTML = originalTextForSearchReset;
	
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	if (sString != "") highlightSearchTerms(sString,false);
	
	showSearch(document.getElementById("searchImage"));
	setSpecific("txtSearchTerm","value",sString);
	document.getElementById("searchPage").click();
}

function showSearch(searchID){
	var searchBox = getObjectCoordinates(searchID);
	var newTop = parseInt(searchBox.substring(searchBox.indexOf("|") + 1,searchBox.length)) + 20;
	var newLeft = parseInt(searchBox.substring(0,searchBox.indexOf("|"))) - 215;
	document.getElementById("searchForm").style.top = newTop + "px";
	document.getElementById("searchForm").style.left = newLeft + "px";
	showHide("searchForm","block");
	setFocus("txtSearchTerm");
}

function showMenu(menuName,menuID,width,offsetleft,offsetTop){
	showHide("popupmenuInformation","none");
	showHide("popupmenuPublicHousing","none");
	showHide("popupmenuHCVP","none");
	showHide("popupmenuWaitList","none");
	showHide("popupmenuHopeVI","none");
	showHide("popupmenuPolice","none");
	showHide("popupmenuNews","none");
	showHide("popupmenuPurchasing","none");
	showHide("popupmenuEPC","none");
	showHide("popupmenuResidents","none");
	var menuSelected = getObjectCoordinates(menuName);
	var newTop = parseInt(menuSelected.substring(menuSelected.indexOf("|") + 1,menuSelected.length)) + offsetTop;
	var newLeft = parseInt(menuSelected.substring(0,menuSelected.indexOf("|"))) - offsetleft;
	var popupMenu = document.getElementById("popup" + menuID);
	showHide("popup" + menuID,"block");
	popupMenu.style.top = newTop + "px";
	popupMenu.style.left = newLeft + "px";
	popupMenu.style.width = width + "px";
}

var navTimeout;
function startTimeout(menuID){
	navTimeout = setTimeout("showHide('popup" + menuID + "','none')",10);
}

function clearReport(reportType){
	resetVendorForm();
	
	switch (reportType){
		case "0":
			setSpecific("lblReportInfo","innerHTML","");
			showHide("pnlEmailSection","none");
			break;
		case "1":
			showHide("pnlEmailSection","none");
			break;
		case "2":
			setSpecific("lblReportInfo","innerHTML","");
			showHide("pnlEmailSection","none");
			break;
		case "3":
			setSpecific("lblReportInfo","innerHTML","");
			showHide("pnlEmailSection","none");
			break;
		case "4":
			setSpecific("lblReportInfo","innerHTML","");
			setSpecific("lblEmailListSub","innerHTML","");
			setSpecific("lblEmailSentTo","innerHTML","");
			showHide("emailBody","none");
			showHide("pnlEmailSection","none");
			break;
		case "9":
			setSpecific("lblReportInfo","innerHTML","");
			showHide("pnlEmailSection","none");
			break;
	}
}

function clearDDL(ddlNumber){
	var ddlID = new Array;
	
	ddlID[0] = "ddlVendorID";
	ddlID[1] = "ddlCategoryID";
	ddlID[2] = "ddlSolicitationID";
	ddlID[3] = "ddlVendorTypeID";
	ddlID[4] = "ddlEmail";
	
	showHide("pnlEmailSection","none");
	showHide("emailBody","none");
	setSpecific("lblEmailMessage","innerHTML","");
	
	if (ddlNumber == 4){
		showHide("pnlEmailSection","block");
		showHide("emailBody","block");
	}
	
	for (i=0;i<=ddlID.length;i++){
		if (ddlNumber != i) setSpecific(ddlID[i],"value","");
	}
}

function populateVendorFormInfo(){
	//loop through all ajax span elements and populate the form accordingly
	showHide("pnlEmailSection","none");
	showHide("pnlVendorAccount","block");
	setSpecific("lblSavedMessage","innerHTML","");
	showHide("btnSubmit","inline");
	showHide("btnCancel","inline");
	
	var ajaxItem = document.getElementsByTagName("span");
	var newID = "";
	for (i=0;i<=ajaxItem.length-1;i++){
		if (ajaxItem[i].id.indexOf("ajax") > -1){
			newID = ajaxItem[i].id.replace("ajax","")
			if (document.getElementById(newID) && ajaxItem[i].id.innerHTML != ""){
				//alert("newID = " + newID + ", ajax span ID = " + ajaxItem[i].id + ", new Value = " + getValue(ajaxItem[i].id,"innerHTML"));
				setValue(newID,"value",ajaxItem[i].id,"innerHTML");
			}
		}
	}
}

function resetVendorForm(){
	setSpecific("txtVendorName","value","");
	setSpecific("txtVendorContactName","value","");
	setSpecific("txtVendorEmail","value","");
	setSpecific("txtVendorPassword","value","");
	setSpecific("txtVendorAddress","value","");
	setSpecific("txtVendorAddress2","value","");
	setSpecific("txtVendorCity","value","");
	setSpecific("ddlVendorState","value","");
	setSpecific("txtVendorZip","value","");
	setSpecific("txtVendorPhone","value","");
	setSpecific("txtVendorFax","value","");
	setSpecific("txtVendorCell","value","");
	setSpecific("txtVendorDescription","value","");
	setSpecific("txtVendorExpirationDate","value","");
	setSpecific("ddlVendorInfoCategoryID","value","");
	showHide("btnSubmit","none");
	showHide("btnCancel","none");
	setSpecific("lblSavedMessage","innerHTML","");
}

function changePlusMinus(imageID,rowID,itemNumber){
	if (document.getElementById(imageID).src.indexOf("icon_plus") > -1){
		if (document.getElementById(imageID).src.indexOf("icon_plus_sub") > -1){
			document.getElementById(imageID).src = "/images/icon_minus_sub.gif";
		}
		else{
			if (itemNumber > 1){
				document.getElementById(imageID).src = "/images/icon_minus_has_top_dots.gif";
			}
			else{
				document.getElementById(imageID).src = "/images/icon_minus.gif";
			}
			if (!document.getElementById("subRow" + (itemNumber + 1))){
				document.getElementById("subDataRow" + itemNumber).style.backgroundImage = "";
			}
		}
		showHide(rowID,"block");
	}
	else{
		if (document.getElementById(imageID).src.indexOf("icon_minus_sub") > -1){
			document.getElementById(imageID).src = "/images/icon_plus_sub.gif";
		}
		else{
			if (itemNumber > 1){
				document.getElementById(imageID).src = "/images/icon_plus_has_top_dots.gif";
			}
			else{
				document.getElementById(imageID).src = "/images/icon_plus.gif";
			}
			clearReport("1");
		}
		showHide(rowID,"none");
	}
}

function checkSave(){
	ajaxFunction("POST", "SaveVendor", "", "", "", "", "", "lblSavedMessage");
}

function checkUploadFields(){
	var allowedExtensions = new Array;
	var filePassed = new Array;
	var errorMessage = "";
	
	allowedExtensions[0] = ".pdf";
	allowedExtensions[1] = ".doc";
	allowedExtensions[2] = ".zip";
	allowedExtensions[3] = ".jpg";
	allowedExtensions[4] = ".gif";
	allowedExtensions[5] = ".bmp";
	allowedExtensions[6] = ".xls";
	allowedExtensions[7] = ".ppt";
	
	
	for (var i=1;i<=5;i++){ //number of file fields
		document.getElementById("txtFile" + i).style.backgroundColor = "white";
		if (getValue("txtFile" + i,"value") != ""){
			filePassed[i] = false;
			for (var a=0;a<allowedExtensions.length;a++){ //array length
				if (getValue("txtFile" + i,"value").toLowerCase().indexOf(allowedExtensions[a]) > 0){
					filePassed[i] = true;
					break;
				}
			}
			if (!filePassed[i]){
				errorMessage += " - Invalid file extension in file number " + i + "\n";
				document.getElementById("txtFile" + i).style.backgroundColor = "yellow";
			}
		}
	}
	
	if (errorMessage != ""){
		alert("Please correct the following issue(s):\n---------------------------------------------\n" + errorMessage);
	}
	else{
		try{
			document.getElementById("btnSendEmail").click();
		}
		catch (e){
			alert("One of the files you entered does not appear to be valid.  Please be sure to include the full path to the file you wish to attach.");
		}
	}
}

function toggleEmailBoxes(){
	var checkedStatus = false;
	if (isChecked("toggleEmailAll")) checkedStatus = true;
	
	for(var i=0;i<Form1.elements.length;i++){ 
		if(Form1.elements[i].name.indexOf("emailTo") > -1){
			Form1.elements[i].checked = checkedStatus;
		}
	}
}

function repopulateEmailSection(){
	if (getValue("ddlEmail","value") == "Vendor"){
		ajaxFunction("GET", "PopulateEmailInfo", getValue("ddlEmail","value"), "", "", "", "", "lblEmailList");
	}
	else{
		var rfpID = 0;var addendaID = 0;
		var solicitationSubValue = getValue("lblSolicitationSub","innerHTML");
		var newEmailSectionValue = "";
		rfpID = solicitationSubValue.substr(0,solicitationSubValue.indexOf("|"));
		addendaID = solicitationSubValue.substr(solicitationSubValue.indexOf("|") + 1,solicitationSubValue.length);
		ajaxFunction("GET", "PopulateEmailInfo", "SolicitationNumber", "", "", "", "", "lblSolicitationSub");
		setSpecific("ddlSolicitationIDEmail","value",solicitationSubValue);
		ajaxFunction("GET", "PopulateEmailInfo", "Vendor", rfpID + "|" + addendaID, "", "", "", "lblEmailListSub");
	}
	
	var addressesToMatch = new Array;
	var totalCheckBoxes = 0; //count of total email checkboxes
	var totalBoxesChecked = 0; //count of total email chechboxes that were checked
	
	addressesToMatch = getValue("lblEmailSentTo","innerHTML").split(",");
	if (document.getElementById("toggleEmailAll")) document.getElementById("toggleEmailAll").checked = true;
	
	for(var i=0;i<Form1.elements.length;i++){ 
		if(Form1.elements[i].name.indexOf("emailTo") > -1){
			totalCheckBoxes++;
			for (var a=0;a<addressesToMatch.length;a++){
				if (Form1.elements[i].value == addressesToMatch[a]){
					Form1.elements[i].checked = true;
					totalBoxesChecked++;
					break;
				}
				else{
					Form1.elements[i].checked = false;
				}
			}
		}
	}
	
	if (totalCheckBoxes == totalBoxesChecked){
		document.getElementById("toggleEmailAll").checked = true;
	}
	else{
		document.getElementById("toggleEmailAll").checked = false;
	}
}

function getAjaxInfo(ddlValue){
	if (ddlValue == "Vendor"){
		ajaxFunction("GET", "PopulateEmailInfo", ddlValue, "", "", "", "", "lblEmailList")
		setSpecific("lblSolicitationSub","innerHTML","");
	}
	else{
		if (ddlValue == "emailOnNewRFP"){
			ajaxFunction("GET", "PopulateEmailInfo", ddlValue, "", "", "", "", "lblSolicitationSub")
			setSpecific("lblEmailList","innerHTML","");
		}
		else{
			ajaxFunction("GET", "PopulateEmailInfo", ddlValue, "", "", "", "", "lblSolicitationSub")
			setSpecific("lblEmailList","innerHTML","");
		}
	}
}
/*************************/
/* application functions */
/*************************/
function checkIfFromApplicationReview(querystring,entireURL){
	if (querystring.indexOf("fromReview") != -1) {
		showHide("btnBack","none");
		setSpecific("txtFromReview","value","yes");
		setSpecific("btnContinueCheck","value","Save and Continue Reviewing Information");
		if (document.getElementById("btnContinueCheck")){
			document.getElementById("btnContinueCheck").style.width = "240px";
		}
	}
}

function prePopulateApplication(pageNumber){
	switch (pageNumber){
		case 3:
			if (isChecked("rblGenTerminated_0")) showHide("terminated","block");
			if (isChecked("rblGenEligible_0")) showHide("citizen","block");
			if (isChecked("rblGenCMHAResident_0")) showHide("resident","block");
			if (isChecked("rblGenCMHAEverEmployed_0")) showHide("employed","block");
			if (isChecked("rblGenFelonyConvicted_0")) showHide("criminal","block");
			if (isChecked("rblGenFelonyPled_0")) showHide("criminal","block");
			if (isChecked("rblGenFelonyPending_0")) showHide("criminal","block");
			if (isChecked("rblGenProbation_0")) showHide("trial","block");
			if (isChecked("rblCarLicense_0")) showHide("license","block");
			if (isChecked("rblCarViolations_0")) showHide("violations","block");
			break;
		case 4:
			for (i=1;i<=parseInt(getValue("txtNumberOfEmployerRows","value"));i++){
				if (isChecked("rblEmployer" + i + "Contact_0")){ showHide("contactno" + i,"none");showHide("contactyes" + i,"block");}
			}
			for (i=1;i<=parseInt(getValue("txtNumberOfEmployerRows","value"));i++){
				if (isChecked("rblEmployer" + i + "Contact_1")){ showHide("contactyes" + i,"none");showHide("contactno" + i,"inline");}
			}
			break;
		case 7:
			showHide("btnUploadCancel","none");
			break;
	}
}

function checkApplication(pageNumber){
	var showErrorMessage = false;
	switch (pageNumber){
		case 2:
			if (getValue("txtEmailAddress","value") == ""){highlightField("txtEmailAddress","yellow");showErrorMessage=true;}
			if (getValue("txtPassword","value") == ""){highlightField("txtPassword","yellow");showErrorMessage=true;}
			if (getValue("txtFirstName","value") == ""){highlightField("txtFirstName","yellow");showErrorMessage=true;}
			if (getValue("txtLastName","value") == ""){highlightField("txtLastName","yellow");showErrorMessage=true;}
			if (getValue("txtSSN","value") == ""){highlightField("txtSSN","yellow");showErrorMessage=true;}
			if (getValue("txtAddress","value") == ""){highlightField("txtAddress","yellow");showErrorMessage=true;}
			if (getValue("txtCity","value") == ""){highlightField("txtCity","yellow");showErrorMessage=true;}
			if (getValue("txtZip","value") == ""){highlightField("txtZip","yellow");showErrorMessage=true;}
			if (getValue("ddlState","value") == ""){highlightField("ddlState","yellow");showErrorMessage=true;}
			if (getValue("txtHomePhoneArea","value") == ""){highlightField("txtHomePhoneArea","yellow");showErrorMessage=true;}
			if (getValue("txtHomePhonePre","value") == ""){highlightField("txtHomePhonePre","yellow");showErrorMessage=true;}
			if (getValue("txtHomePhoneSuf","value") == ""){highlightField("txtHomePhoneSuf","yellow");showErrorMessage=true;}
			break;
		case 3:
			if (isChecked("chkPrefFT") && !isChecked("chkPrefFTDay") && !isChecked("chkPrefFTEvening") && !isChecked("chkPrefFTWeekend")){highlightField("chkPrefFTDay","yellow");highlightField("chkPrefFTEvening","yellow");highlightField("chkPrefFTWeekend","yellow");showErrorMessage=true;}
			if (isChecked("chkPrefPT") && !isChecked("chkPrefPTDay") && !isChecked("chkPrefPTEvening") && !isChecked("chkPrefPTWeekend")){highlightField("chkPrefPTDay","yellow");highlightField("chkPrefPTEvening","yellow");highlightField("chkPrefPTWeekend","yellow");showErrorMessage=true;}
			if (!isChecked("chkPrefFT") && !isChecked("chkPrefFTDay") && !isChecked("chkPrefFTEvening") && !isChecked("chkPrefFTWeekend")){highlightField("chkPrefFT","yellow");showErrorMessage=true;}
			if (isChecked("rblGenTerminated_0") && getValue("txtGenTerminatedExplain","value") == ""){highlightField("txtGenTerminatedExplain","yellow");showErrorMessage=true;}
			if (isChecked("rblGenEligible_0") && getValue("txtGenEligiblePermit","value") == ""){ highlightField("txtGenEligiblePermit","yellow");showErrorMessage=true}
			if (isChecked("rblGenCMHAResident_0") && getValue("ddlGenCMHAResidentEstate","value") == ""){ highlightField("ddlGenCMHAResidentEstate","yellow");showErrorMessage=true}
			if (isChecked("rblGenCMHAEverEmployed_0") && getValue("txtGenCMHAEverEmployedName","value") == ""){ highlightField("txtGenCMHAEverEmployedName","yellow");showErrorMessage=true}
			if (isChecked("rblGenCMHAEverEmployed_0") && getValue("txtGenCMHAEverEmployedDates","value") == ""){ highlightField("txtGenCMHAEverEmployedDates","yellow");showErrorMessage=true}
			if (isChecked("rblGenCMHAEverEmployed_0") && getValue("txtGenCMHAEverEmployedSupervisor","value") == ""){ highlightField("txtGenCMHAEverEmployedSupervisor","yellow");showErrorMessage=true}
			if ((isChecked("rblGenFelonyConvicted_0") || isChecked("rblGenFelonyPled_0") || isChecked("rblGenFelonyPending_0")) && getValue("txtgenFelonyExplain","value") == ""){ showHide("criminal","block");highlightField("txtgenFelonyExplain","yellow");showErrorMessage=true}
			if (isChecked("rblGenProbation_0") && getValue("txtGenProbationExplain","value") == ""){ highlightField("txtGenProbationExplain","yellow");showErrorMessage=true}
			if (isChecked("rblCarLicense_0") && getValue("txtCarLicenseNumber","value") == ""){ highlightField("txtCarLicenseNumber","yellow");showErrorMessage=true}
			if (isChecked("rblCarLicense_0") && getValue("ddlCarLicenseState","value") == ""){ highlightField("ddlCarLicenseState","yellow");showErrorMessage=true}
			if (isChecked("rblCarViolations_0") && getValue("txtCarViolationsExplain","value") == ""){ highlightField("txtCarViolationsExplain","yellow");showErrorMessage=true}
			if (!isChecked("rblGenFelonyConvicted_0") && !isChecked("rblGenFelonyConvicted_1")){highlightField("rblGenFelonyConvicted_0","yellow");highlightField("rblGenFelonyConvicted_1","yellow");showErrorMessage=true;}
			if (!isChecked("rblGenFelonyPled_0") && !isChecked("rblGenFelonyPled_1")){highlightField("rblGenFelonyPled_0","yellow");highlightField("rblGenFelonyPled_1","yellow");showErrorMessage=true;}
			if (!isChecked("rblGenFelonyPending_0") && !isChecked("rblGenFelonyPending_1")){highlightField("rblGenFelonyPending_0","yellow");highlightField("rblGenFelonyPending_1","yellow");showErrorMessage=true;}
			if (!isChecked("rblGenProbation_0") && !isChecked("rblGenProbation_1")){highlightField("rblGenProbation_0","yellow");highlightField("rblGenProbation_1","yellow");showErrorMessage=true;}
			if (getValue("txtPrefPay","value") == ""){highlightField("txtPrefPay","yellow");showErrorMessage=true;}
			break;
		case 5:
			for (i=1;i<=parseInt(getValue("txtNumberOfEmployerRows","value"));i++){
				//if (document.getElementById("rblEmployer" + i + "Contact_0").checked && getValue("txtEmployer" + i + "ContactName","value") == ""){ document.getElementById("txtEmployer" + i + "ContactName").style.backgroundColor = "yellow";showErrorMessage = true;}
				if (isChecked("rblEmployer" + i + "Contact_1") && getValue("txtEmployer" + i + "ContactExplain","value") == "" && getValue("txtEmployer" + i + "Name","value") != ""){ document.getElementById("txtEmployer" + i + "ContactExplain").style.backgroundColor = "yellow";showErrorMessage = true;}
			}
			break;
		case 6:
			break;
		case 7:
			if (getValue("btnContinueCheck","value") == "Apply Without Uploading Resume >>"){
				window.location="applynow.aspx?applied=yes";
				return true;
			}
			break;
		case 8:
			if (getValue("txtInquirySignature","value") == ""){highlightField("txtInquirySignature","yellow");showErrorMessage=true;}
			if (getValue("ddlInquiryDOBM","value") == ""){highlightField("ddlInquiryDOBM","yellow");showErrorMessage=true;}
			if (getValue("ddlInquiryDOBD","value") == ""){highlightField("ddlInquiryDOBD","yellow");showErrorMessage=true;}
			if (getValue("ddlInquiryDOBY","value") == ""){highlightField("ddlInquiryDOBY","yellow");showErrorMessage=true;}
			if (getValue("txtSignature","value") == ""){highlightField("txtSignature","yellow");showErrorMessage=true;}
			break;
	}
	
	if (showErrorMessage){
		alert("Please complete the highlighted field(s) to continue.");
		scrollTo(0,0);
		return false;
	}
	
	document.getElementById("btnContinue").click();
}

function showAdditionalRow(rowName){
	for (i=1;i<=parseInt(getValue("txtNumberOf" + rowName + "Rows","value"));i++){
		if (document.getElementById(rowName + i).style.display != "block"){
			showHide(rowName + i,"block");
			if (i == parseInt(getValue("txtNumberOf" + rowName + "Rows","value"))){
				document.getElementById("btnAdd" + rowName).disabled = true;
			}
			break;
		}
	}
}

function highlightField(fieldID,fieldColor){
	document.getElementById(fieldID).style.backgroundColor = fieldColor;
}

function removeHighlighting(fieldID){
	if (getValue(fieldID,"value") != "") document.getElementById(fieldID).style.backgroundColor="";
}

function checkCriminal(){
	if (isChecked("rblGenFelonyConvicted_0") || isChecked("rblGenFelonyPled_0") || isChecked("rblGenFelonyPending_0")){
		showHide("criminal","block");
	}
	else{
		showHide("criminal","none");
		setSpecific("txtgenFelonyExplain","value","");
	}
}

//show additional input boxes if certain boxes are checked
function showAdditionalAppInfo(boxID,divToShow,boxToEmpty){
	var boxToCheck = document.getElementById(boxID);
	if (isChecked(boxID)){
		showHide(divToShow,"block");
		if (boxToEmpty != ""){setFocus(boxToEmpty);}
	}
	else{
		showHide(divToShow,"none");
		if (boxToEmpty != ""){
			var boxesToEmpty = boxToEmpty.split(",");
			for (i=0;i<=boxesToEmpty.length;i++){
				setSpecific(boxesToEmpty[i],"value","");	
			}
		}
	}
}

function checkContactDisplay(rowID,fieldPrefix){
	if (isChecked("rbl" + fieldPrefix + "Contact_0")){
		showHide("contactyes" + rowID,"block");
		setFocus("txt" + fieldPrefix + "ContactName");
		showHide("contactno" + rowID,"none");
		setSpecific("txt" + fieldPrefix + "ContactExplain","value","");
	}
	else{
		showHide("contactyes" + rowID,"none");
		showHide("contactno" + rowID,"inline");
		setFocus("txt" + fieldPrefix + "ContactExplain");
		setSpecific("txt" + fieldPrefix + "ContactName","value","");
	}
}

//Slideshow functions
var mainArray;
var Pic = new Array();
var slideShowSpeed = new Array();
var p = new Array();
var t = new Array();
var j = new Array();
var preLoad = new Array()
var crossFadeDuration = 500

function slideShowImages(slideShowNumber,rotationTime,images){
	mainArray = images.split(",");
	var i, c;
	Pic[slideShowNumber] = new Array(mainArray.length);
	for (c=0;c<mainArray.length;c++){
		Pic[slideShowNumber][c] = mainArray[c];
	}

	for (i=1;i<=slideShowNumber;i++){
		switch (slideShowNumber){
			case i:
				p[i] = mainArray.length;
				preLoad[i] = new Array(p[i]);
				for (r=0;r<p[i];r++){
					preLoad[i][r] = new Image()
					preLoad[i][r].src = Pic[i][r]
				}
				j[i] = 0;
				slideShowSpeed[i] = rotationTime;
				runSlideShow(i);
				break;
		}
	}
}

function runSlideShow(i){
	var imageID = document.getElementById(["SlideShow"+i]);
	if (imageID){
		if (document.all){
			imageID.style.filter="blendTrans(duration=500)"
			imageID.style.filter="blendTrans(duration=crossFadeDuration)"
			imageID.filters.blendTrans.Apply()      
		}
		imageID.src = preLoad[i][j[i]].src
		if (document.all){
			imageID.filters.blendTrans.Play()
		}
		j[i] = j[i] + 1
		if (j[i] > (p[i]-1)) j[i]=0
		t[i] = setTimeout("runSlideShow(" + i + ")", slideShowSpeed[i])
	}
}

function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	}
	else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}
	else{
		return false; 
	} 
}

function enlargeImage(zoomFile,imageToLoad){
	var windowWidth = screen.availWidth;
	var windowHeight = screen.availHeight;
	var imageWindow = window.open(zoomFile+"?imageName="+imageToLoad,"Enlarge","width="+windowWidth+",height="+windowHeight+",status=no,menubar=no,location=no,resizable=yes,scrollbars=yes,left=1,top=1");
	imageWindow.focus();
}

function changeImg(loadImg){
	var currentImage = parseInt(getValue("chargerImageNumber","value"));
	var chargerImage = document.getElementById("chargerimage");
	var newChargerImage = "/images/charger";

	switch (loadImg){
		case "first":
			chargerImage.src = newChargerImage + "1.jpg";
			setSpecific("chargerImageNumber","value","1");
			break;
		case "previous":
			if (currentImage > 1){
				chargerImage.src = newChargerImage + (currentImage - 1) + ".jpg";
				setSpecific("chargerImageNumber","value",currentImage - 1);
			}
			break;
		case "next":
			if (currentImage < 7){
				chargerImage.src = newChargerImage + (currentImage + 1) + ".jpg";
				setSpecific("chargerImageNumber","value",currentImage + 1);
			}
			break;
		case "last":
			chargerImage.src = newChargerImage + "7.jpg";
			setSpecific("chargerImageNumber","value","7");
			break;
	}
	currentImage = parseInt(getValue("chargerImageNumber","value"));
	if (currentImage == 1){
		document.getElementById("first").src = "/images/vcr_first_disabled.gif";
		document.getElementById("previous").src = "/images/vcr_previous_disabled.gif";
		document.getElementById("next").src = "/images/vcr_next.gif";
		document.getElementById("last").src = "/images/vcr_last.gif";
	}
	else if (currentImage == 7){
		document.getElementById("first").src = "/images/vcr_first.gif";
		document.getElementById("previous").src = "/images/vcr_previous.gif";
		document.getElementById("next").src = "/images/vcr_next_disabled.gif";
		document.getElementById("last").src = "/images/vcr_last_disabled.gif";
	}
	else{
		document.getElementById("first").src = "/images/vcr_first.gif";
		document.getElementById("previous").src = "/images/vcr_previous.gif";
		document.getElementById("next").src = "/images/vcr_next.gif";
		document.getElementById("last").src = "/images/vcr_last.gif";
	}
}

//clear errors from javascript so they don't alert user
function ClearError() {
	return true;
}

window.onerror = ClearError;