//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(){
	var pageSpanName = "leftnav_lblPageOn";
	
	if (document.getElementById("lblPageOn")) pageSpanName = "lblPageOn";
	
	if (getValue(pageSpanName,"innerHTML") != ""){
		var newClassName = "topnavon";
		switch (getValue(pageSpanName,"innerHTML")){
			case "0":
				document.getElementById("menuInformation").className = newClassName;
				break;
			case "1":
				document.getElementById("menuPublicHousing").className = newClassName;
				break;
			case "2":
				document.getElementById("menuHCVP").className = newClassName;
				break;
			case "3":
				document.getElementById("menuWaitList").className = newClassName;
				break;
			case "4":
				document.getElementById("menuHopeVI").className = newClassName;
				break;
			case "5":
				document.getElementById("menuPolice").className = newClassName;
				break;
			case "6":
				document.getElementById("menuNews").className = newClassName;
				break;
			case "7":
				document.getElementById("menuPurchasing").className = newClassName;
				break;
			case "8":
				document.getElementById("menuEPC").className = newClassName;
				break;
			case "9":
				document.getElementById("menuResidents").className = newClassName;
				break;
		    case "10":
		        document.getElementById("menuCareers").className = newClassName;
		        break;
		}
	}
}

//check to see if the passed in document ID exists on the page
function exists(idValue){
	if (document.getElementById(idValue)){
		return true;
	}
	return false;
}

//checks to see if the passed in document ID of a radiobutton/checkbox is checked or not
function isChecked(idValue){
	if (document.getElementById(idValue)){
		if (document.getElementById(idValue).checked) return true;
	}
	return false;
}

//uncheck the passed in checkbox or radio button
function unCheck(idValue){
	if (document.getElementById(idValue)){
		document.getElementById(idValue).checked = 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 checkForm(formName){
    var showContentMessage = false;
    var showErrorMessage = false;
    var showNonMatch = false;
	var showInvalidEmail=false;
    switch (formName){
		case "rfpCreate":
            if (!checkEmail(getValue("txtVendorEmailCreate","value"))){highlightField("txtVendorEmailCreate","yellow");showInvalidEmail=true;}
            if (getValue("txtVendorNameCreate","value")==""){highlightField("txtVendorNameCreate","yellow");showErrorMessage=true;}
            if (getValue("txtVendorContactNameCreate","value")==""){highlightField("txtVendorContactNameCreate","yellow");showErrorMessage=true;}
            if (getValue("txtVendorEmailCreate","value")==""){highlightField("txtVendorEmailCreate","yellow");showErrorMessage=true;}
            if (getValue("txtVendorPasswordCreate","value")==""){highlightField("txtVendorPasswordCreate","yellow");showErrorMessage=true;}
            break;
		case "rfpUpdate":
            if (!checkEmail(getValue("txtVendorEmail","value"))){highlightField("txtVendorEmail","yellow");showInvalidEmail=true;}
            if (getValue("txtVendorName","value")==""){highlightField("txtVendorName","yellow");showErrorMessage=true;}
            if (getValue("txtVendorContactName","value")==""){highlightField("txtVendorContactName","yellow");showErrorMessage=true;}
            if (getValue("txtVendorEmail","value")==""){highlightField("txtVendorEmail","yellow");showErrorMessage=true;}
            if (getValue("txtVendorPassword","value")==""){highlightField("txtVendorPassword","yellow");showErrorMessage=true;}
            break;
        case "newsletters":
            if (getValue("txtFirstName","value")==""){highlightField("txtFirstName","yellow");showErrorMessage=true;}
            if (getValue("txtLastName","value")==""){highlightField("txtLastName","yellow");showErrorMessage=true;}
            if (getValue("txtEmail","value").replace(/ /g,"")==""){highlightField("txtEmail","yellow");showErrorMessage=true;}
            break;
        default:
            break;
    }
    
    if (showErrorMessage){
		alert("Please complete all highlighted/required field(s) to continue.");
		scrollTo(0,0);
		return false;
	}
	
	if (showContentMessage){
        alert("Please enter a message.");
		scrollTo(0,0);
		return false;
    }
	
	if (showNonMatch){
	    alert("Your passwords did not match.");
		scrollTo(0,0);
		return false;
	}
	
	if (showInvalidEmail){
	    alert("Please enter a valid email address.");
		scrollTo(0,0);
		return false;
	}
	
	//document.getElementById(btnID).click();
    return true;
}

function checkEmail(email){
    var emailReg = "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";
    var regex = new RegExp(emailReg);
    return regex.test(email);
}

function highlightField(fieldID,fieldColor){
	if (document.getElementById(fieldID)){
		document.getElementById(fieldID).style.backgroundColor = fieldColor;
	}
}

function removeHighlighting(fieldID){
	if (getValue(fieldID,"value") != "") document.getElementById(fieldID).style.backgroundColor="";
}

function forceRemoveHighlighting(fieldID){
	if (exists(fieldID)) document.getElementById(fieldID).style.backgroundColor="";
}

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(false);
	}
	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");
	showHide("popupmenuCareers","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);
	var menuCover = document.getElementById("cover" + menuID);
	showHide("popup" + menuID,"block");
	showHide("cover" + menuID,"block");
	popupMenu.style.top = newTop + "px";
	popupMenu.style.left = newLeft + "px";
	popupMenu.style.width = width + "px";
	menuCover.style.width = width + "px";
	menuCover.style.height = popupMenu.clientHeight + "px";
	menuCover.style.left = newLeft + "px";
	menuCover.style.zIndex = "99";
	menuCover.style.top = newTop + "px";
}

var navTimeout;
function startTimeout(menuID){
	navTimeout = setTimeout("showHide('popup" + menuID + "','none')",10);
	setTimeout("hideCover('" + menuID + "')",20);
}

function hideCover(menuID){
	if (document.getElementById("popup" + menuID).style.display == "none"){
		showHide("cover" + menuID,"none");
	}
}

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");
				if (newID=="chkEmail"){
					if (getValue(ajaxItem[i].id,"innerHTML") == "True"){
					    document.getElementById("chkEmail").checked = true;
					}
					else{
					    document.getElementById("chkEmail").checked = false;
					}
				}
			}
		}
	}
}

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","");
		}
	}
}

//Slideshow functions
var mainArray; //string list of images
var Pic = new Array(); 
var slideShowSpeed = new Array(); //speed of slideshow in milliseconds
var p = new Array(); //max number of images in slideshow
var t = new Array(); //slideshow timeout
var j = new Array(); //current image
var preLoad = new Array()
var crossFadeDuration = 3

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,buttonClicked){
	var imageID = document.getElementById(["SlideShow"+i]);
	if (imageID){
		if (document.all){
			imageID.style.filter="blendTrans(duration=2)"
			imageID.style.filter="blendTrans(duration=crossFadeDuration)"
			imageID.filters.blendTrans.Apply()      
		}
		if (document.all){
			imageID.filters.blendTrans.Play()
		}

		switch (buttonClicked){
			case "first":
				pauseSlideShow(i);
				j[i]=0;
				setSpecific("firstButton"+i,"innerHTML","<img src='" + firstButtonDisabled + " alt=''/>");
				break;
			case "previous":
				pauseSlideShow(i);
				if (j[i] == 0){
					j[i] = p[i] - 2;
				}
				else{
					j[i] = j[i] - 2;
				}
				setSpecific("previousButton"+i,"innerHTML","<img src='" + previousButtonDisabled + "' alt=''/>");
				break;
			case "next":
				pauseSlideShow(i);
				if (j[i] >= p[i]-1){
					//setSpecific("nextButton"+i,"innerHTML","<img src='" + nextButtonDisabled + "' alt=''/>");
					setSpecific("lastButton"+i,"innerHTML","<img src='" + lastButtonDisabled + "' alt=''/>");
				}
				break;
			case "last":
				pauseSlideShow(i);
				j[i] = p[i] - 1;
				//setSpecific("nextButton"+i,"innerHTML","<img src='" + nextButtonDisabled + "' alt=''/>");
				setSpecific("lastButton"+i,"innerHTML","<img src='" + lastButtonDisabled + "' alt=''/>");
				break;
			default:
				resetSlideShow(i);
				t[i] = setTimeout("runSlideShow(" + i + ",'')", slideShowSpeed[i])
				break;
		}
		
		if (exists("stopButton"+i)){
			if (j[i] > 0){
				setSpecific("firstButton"+i,"innerHTML","<img src='"+firstButton+"' alt='First' onclick='runSlideShow("+i+",\"first\");'/>");
				setSpecific("previousButton"+i,"innerHTML","<img src='"+previousButton+"' alt='Previous' onclick='runSlideShow("+i+",\"previous\");'/>");
			}
			else{
				setSpecific("firstButton"+i,"innerHTML","<img src='" + firstButtonDisabled + "' alt=''/>");
				setSpecific("previousButton"+i,"innerHTML","<img src='" + previousButtonDisabled + "' alt=''/>");
			}
			if (j[i] >= p[i]-1){
				//setSpecific("nextButton"+i,"innerHTML","<img src='" + nextButtonDisabled + "' alt=''/>");
				setSpecific("lastButton"+i,"innerHTML","<img src='" + lastButtonDisabled + "' alt=''/>");
			}
			else{
				setSpecific("nextButton"+i,"innerHTML","<img src='"+nextButton+"' alt='Next' onclick='runSlideShow("+i+",\"next\");'/>");
				setSpecific("lastButton"+i,"innerHTML","<img src='"+lastButton+"' alt='Last' onclick='runSlideShow("+i+",\"last\");'/>");
			}
			
			setSpecific("imageCounterCurrent"+i,"innerHTML",j[i]+1);
			setSpecific("imageCounterMax"+i,"innerHTML",p[i]);
			showSSDescriptions(i);
		}
		
		imageID.src = preLoad[i][j[i]].src
		
		if (j[i] >= (p[i]-1)) j[i]=-1
		j[i]++;
	}
}

function showSSDescriptions(i){
	//check for up to 8 ssDescription portions
	if (exists("ssDescription1") && i == 1){setSpecific("ssDescription1","innerHTML",slideShowDescriptions1[j[i]]);}
	if (exists("ssDescription2") && i == 2){setSpecific("ssDescription2","innerHTML",slideShowDescriptions2[j[i]]);}
	if (exists("ssDescription3") && i == 3){setSpecific("ssDescription3","innerHTML",slideShowDescriptions3[j[i]]);}
	if (exists("ssDescription4") && i == 4){setSpecific("ssDescription4","innerHTML",slideShowDescriptions4[j[i]]);}
	if (exists("ssDescription5") && i == 5){setSpecific("ssDescription5","innerHTML",slideShowDescriptions5[j[i]]);}
	if (exists("ssDescription6") && i == 6){setSpecific("ssDescription6","innerHTML",slideShowDescriptions6[j[i]]);}
	if (exists("ssDescription7") && i == 7){setSpecific("ssDescription7","innerHTML",slideShowDescriptions7[j[i]]);}
	if (exists("ssDescription8") && i == 8){setSpecific("ssDescription8","innerHTML",slideShowDescriptions8[j[i]]);}
}

function resetSlideShow(i){
	if (exists("stopButton"+i)) document.getElementById("stopButton"+i).src = stopButton;
	if (exists("pauseButton"+i)) document.getElementById("pauseButton"+i).src = pauseButton;
	if (exists("playButton"+i)) document.getElementById("playButton"+i).src = playButtonDisabled;
}

function pauseSlideShow(i){
	clearTimeout(t[i]);
	document.getElementById("stopButton"+i).src = stopButtonDisabled;
	document.getElementById("pauseButton"+i).src = pauseButtonDisabled;
	document.getElementById("playButton"+i).src = playButton;
}

function stopSlideShow(i){
	clearTimeout(t[i]);
	j[i]=0;
	if (exists("imageCounterCurrent"+i)) setSpecific("imageCounterCurrent"+i,"innerHTML",j[i]+1);
	showSSDescriptions(i);
	document.getElementById(["SlideShow"+i]).src = preLoad[i][j[i]].src;
	document.getElementById("stopButton"+i).src = stopButtonDisabled;
	document.getElementById("pauseButton"+i).src = pauseButtonDisabled;
	document.getElementById("playButton"+i).src = playButton;
}

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 showEOTM(employeeType){
	var eotmWindow = window.open("/eotm/" + employeeType + ".aspx","EOTM","width=600,height=500,location=no,scrollbars=yes,menubar=no,resizable=yes,status=no");	
	eotmWindow.focus();
	eotmWindow.moveTo((screen.availWidth / 2) - 300,(screen.availHeight / 2) - 250);
}

//clear errors from javascript so they don't alert user
function ClearError() {
	return true;
}

//window.onerror = ClearError;

if (top.location != location) {
    top.location.href = document.location.href ;
}
