function showHideSections(sectionToShow){
	if(document.getElementById("preTextArea").className != "hideObject") document.getElementById("preTextArea").className = "hideObject";
	selContainer=document.getElementById("contentTables");
	selTables=selContainer.getElementsByTagName("div");
	for(n=0;n<selTables.length;n++){
		if(selTables[n].id != sectionToShow){
				selTables[n].className = "hideObject";
		}else{
			selectedDD = selTables[n];
			selTables[n].className = "showObject";
		}
	}				
}

/* Here is all the code for AJAXing HTML content into an ID'd container*/
 var req;
 var which;
var contentID;

 function retrieveURLForHTMLContent(url,contentTargetID) {
	contentID = contentTargetID;
  if (window.XMLHttpRequest) { // Non-IE browsers
     req = new XMLHttpRequest();
     req.onreadystatechange = processStateChangeForHTMLContent;
     try {
       req.open("GET", url, true);
     } catch (e) {
       alert(e);
     }
     req.send(null);
   } else if (window.ActiveXObject) { // IE
     req = new ActiveXObject("Microsoft.XMLHTTP");
     if (req) {
       req.onreadystatechange = processStateChangeForHTMLContent;
       req.open("GET", url, true);
       req.send();
     }
   }
 }

 function processStateChangeForHTMLContent() {
   if (req.readyState == 4) { // Complete
     if (req.status == 200) { // OK response
       document.getElementById(contentID).innerHTML = req.responseText;
     } else {
       alert("Problem: " + req.statusText);
     }
   }
 }

function showNowAvailable(xmlFeedName){
	showHideSections("nowAvailable");
	document.getElementById("nowAvailable").innerHTML = "<div align=\"center\">Loading...</div>";
	var dynURL = "/xsl/xmlContentView.cfm?xmlfeed=" + xmlFeedName;
	void retrieveURLForHTMLContent(dynURL,"nowAvailable");
}

function hideNowAvailable(){
	document.getElementById("nowAvailable").innerHTML = "<div align=\"center\">Loading...</div>";
	document.getElementById("nowAvailable").className = "hideObject";
}

			
function ajaxXML(xmlFeedName,optionalURLParameters){
	document.getElementById(xmlFeedName + "TD").innerHTML = "<div align=\"center\">Loading...</div>";
	document.getElementById(xmlFeedName + "Link").className = "hideObject";
	if (optionalURLParameters != null){
		var targetDynURLParameters = xmlFeedName + optionalURLParameters;
	}else{
		var targetDynURLParameters = xmlFeedName;
	}
	var dynURL = "/xsl/xmlContentView.cfm?xmlfeed=" + targetDynURLParameters;
	void retrieveURLForHTMLContent(dynURL,xmlFeedName + "TD");
	document.getElementById(xmlFeedName + "TR").className = "showRowObject";
}

function hideAjaxXML(xmlFeedName){
	document.getElementById(xmlFeedName + "Link").className = "bulletPlusListMtxTd";
	document.getElementById(xmlFeedName + "TD").innerHTML = "<div align=\"center\">Loading...</div>";
	document.getElementById(xmlFeedName + "TR").className = "hideObject";
}

function xmlShowHide(contentName,contentID,state){
	if(state == 0){
		document.getElementById(contentName + "linkObject" + contentID).className = "showObject";
		document.getElementById(contentName + "displayObject" + contentID).className = "hideObject";
	}else{
		document.getElementById(contentName + "linkObject" + contentID).className = "hideObject";
		document.getElementById(contentName + "displayObject" + contentID).className = "showRowObject";
	}
}


// These three arrays are used for the SEC filings paging
var xmlTableArray =  new Array("secFilingsTableContainer","secFilingsSection16TableContainer","secFilingsProxyTableContainer","pressReleaseListingTableContainer1","pressReleaseListingTableContainer2","pressReleaseListingTableContainer3","pressReleaseListingTableContainer4");
var xmlSelSlotArray = new Array(1,1,1,1,1,1,1);
var xmlTotalSlotsArray = new Array(0,0,0,0,0,0,0);
var xmlTRsPerRowArray = new Array(2,2,2,1,1,1,1);
function xmlTableShowHide(direction,arrayPosition){
	//Pull in the values from the arrays
	secSlot = xmlSelSlotArray[arrayPosition];
	totalSlots = xmlTotalSlotsArray[arrayPosition];
	
	//Need to determine where I'm at and how far I can go.. ie are there 10 more rows to show?
	if(totalSlots == 0){
		selContainer=document.getElementById(xmlTableArray[arrayPosition]);
		selRows=selContainer.getElementsByTagName("tr");
		totalSlots = (selRows.length - 1)/xmlTRsPerRowArray[arrayPosition];	
		//Set the array value
	}
	
	//Hide the current rows that are showing
	if(secSlot + 10 > totalSlots){
		lastExistingSlot = totalSlots;
	}else{
		lastExistingSlot = secSlot +10;	
	}
	
	for(n=secSlot;n<=lastExistingSlot;n++){
		document.getElementById("xml" + arrayPosition + "Row" + n).className = "hideObject";		
	}	
	
	//Determine the next set that needs to be shown
	if(direction == 1){
		startSlot = secSlot + 10;
		if(startSlot + 10 > totalSlots){
			stopSlot = totalSlots;
		}else{
			stopSlot = startSlot +9;	
		}		
	}else{
		stopSlot = secSlot - 1;
		if(stopSlot - 10 < 1){
			startSlot = 1;
		}else{
			startSlot = stopSlot - 9;	
		}		
	}
	//Loop through and show the new set
	for(n=startSlot;n<=stopSlot;n++){
		document.getElementById("xml" + arrayPosition + "Row" + n).className = "showRowObject";		
	}	
	//Hide or show the the navigation links and update the currentRecordset
	if(startSlot == 1){
		document.getElementById("prev" + arrayPosition + "Link").innerHTML = "Prev";
	}else{
		document.getElementById("prev" + arrayPosition + "Link").innerHTML = "<a href=\"javascript: void xmlTableShowHide(0," + arrayPosition + ");\">Prev</a>";
	}
	if(stopSlot == totalSlots){
		document.getElementById("next" + arrayPosition + "Link").innerHTML = "Next";
	}else{
		document.getElementById("next" + arrayPosition + "Link").innerHTML = "<a href=\"javascript: void xmlTableShowHide(1," + arrayPosition + ");\">Next</a>";
	}
	document.getElementById("currentRecordSpot" + arrayPosition).innerHTML = startSlot + " - " + stopSlot + " of " + totalSlots; 

	//Update the value in the array
	xmlSelSlotArray[arrayPosition] = startSlot;
}

//This function is used for updating the Stock Quote Chart
function updateStockQuoteChart(baseURL){
	var newImageURL = baseURL;
	newImageURL = newImageURL + "?symb=ibkc&size=2&style=455&lf=1";
	newImageURL = newImageURL + "&time=" + document.stockQuoteChartForm.time[document.stockQuoteChartForm.time.selectedIndex].value;
	newImageURL = newImageURL + "&freq=" + document.stockQuoteChartForm.freq[document.stockQuoteChartForm.freq.selectedIndex].value;
	newImageURL = newImageURL + "&compidx=" + document.stockQuoteChartForm.compidx[document.stockQuoteChartForm.compidx.selectedIndex].value;
	newImageURL = newImageURL + "&uf=" + document.stockQuoteChartForm.uf[document.stockQuoteChartForm.uf.selectedIndex].value;
	newImageURL = newImageURL + "&type=" + document.stockQuoteChartForm.type[document.stockQuoteChartForm.type.selectedIndex].value;
	document.getElementById("stockQuoteChart").src = newImageURL;
}

function showHistoricStockInformation(){
	var dynMonthVal = document.historicalQuote.month[document.historicalQuote.month.selectedIndex].value;
	var dynDayVal = document.historicalQuote.day[document.historicalQuote.day.selectedIndex].value;
	var dynYearVal = document.historicalQuote.year[document.historicalQuote.year.selectedIndex].value;

	var dynURL = "/xsl/xmlContentView.cfm?xmlfeed=stockHistoricQuote" + "&year=" + dynYearVal + "&month=" + dynMonthVal + "&day=" + dynDayVal;
	void retrieveURLForHTMLContent(dynURL,"historicalQuoteInformation");
}

function showFormFields(){
	var frm = document.emailAlertsForm;
	var regexp = /^[\w\.\-]*@[A-Za-z0-9\-\.]*\.[A-Za-z]{2,4}$/;
	
	if(frm.emailAddress.value.length > 0){
		var resultArray = frm.emailAddress.value.match(regexp)
		if (resultArray) {
			var subscribeFieldList = "";
			var unsubscribeFieldList = "";
			for(i = 0; i < frm.elements.length;i++){
				if (frm.elements[i].type == 'radio'){
					if (frm.elements[i].value == 0 && frm.elements[i].checked){
						if(unsubscribeFieldList.length > 0){
							unsubscribeFieldList = unsubscribeFieldList + ",";
						}
						unsubscribeFieldList = unsubscribeFieldList + frm.elements[i].name;
					}
					if (frm.elements[i].value == 1 && frm.elements[i].checked){
						if(subscribeFieldList.length > 0){
							subscribeFieldList = subscribeFieldList + ",";
						}
						subscribeFieldList = subscribeFieldList + frm.elements[i].name;
					}
				}
			}
			
			var dynURL = "/xsl/xmlContentView.cfm?xmlfeed=sendEmailAlrts&emailAddress=" + frm.emailAddress.value + "&Subscribe=" + subscribeFieldList + "&UnSubScribe=" + unsubscribeFieldList;
//				var dynURL = "/xsl/xmlContentView.cfm?xmlfeed=" + xmlFeedName;
				void retrieveURLForHTMLContent(dynURL,"nowAvailable");
		}else{
			alert("You must provide a valid email address.");
		}
	}else{
		alert("You must provide an email address.");			
	}	
}

