// JavaScript Document

// Expands Users Browser Window to full screen when loading page.
function maxWindow() {
window.moveTo(0,0);

	if (document.all) {
	  top.window.resizeTo(screen.availWidth,screen.availHeight);
	}

		else if (document.layers||document.getElementById) {
		  if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
  		}
	}
}
//window.onload = maxWindow;

//Expand Collapse
// May not utilize the acordian like interaction. Thsi si just for demo.
// Alternative to expanding and collapsing all levels from any view is to click and have page refresh with section selected open.

// Page-wide expand collapse toggle.
function expandCollapseAll() {
	for (var i=0; i<expandCollapse.arguments.length; i++) {
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}

// element specific toggle.
function expandCollapse(id, selectedArrowID, elementOn) {
	var element = document.getElementById(id);
	var arrowID = selectedArrowID;
	element.style.display = (element.style.display == "none") ? "block" : "none";
	toggleArrow(arrowID, elementOn);
}

// Swap arrow state via class
function toggleArrow(arrowID, elementOn){
	var arrowElement = document.getElementById(arrowID);
	// Change the Selected or On arrow state.
	if (elementOn){
		arrowElement.className = (arrowElement.className == "vert-arrow") ? "vert-arrow vert-arrow-right-on" : "vert-arrow";
	// Change all the others.
	} else {
		arrowElement.className = (arrowElement.className == "vert-arrow") ? "vert-arrow vert-arrow-down-off" : "vert-arrow";
	}
}

// Lightbox Effects
function toggleLightBoxError(){
	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';
}

// Form Field Actions and Functions
function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}

function clearSearchBox(inputIdToClear, initValue, newValue){
		document.getElementById(inputIdToClear).style.color = "#000000";
		if(newValue == initValue){
			document.getElementById(inputIdToClear).value = '' ; 
		} else {
			document.getElementById(inputIdToClear).value = newValue ;
		}
	}
	
function resetSearchBox(inputIdToClear, initValue, newValue){
		if (newValue == '' || newValue == null){
			document.getElementById(inputIdToClear).value = initValue ; 
			document.getElementById(inputIdToClear).style.color = "#757575";
		} else {
			document.getElementById(inputIdToClear).value = newValue ; 
		}
	}
	
function highlightElement(id){
	var formObject 	= document.getElementById(id);
	var origClass 	= formObject.className;
	var newClass 	= origClass + " focused";
	formObject.className = newClass;
}

function unHighlightElement(id){
	var formObject 	= document.getElementById(id);
	var origClass 	= formObject.className;
	origClass 		= origClass.replace(/ focused/, "");
	formObject.className = origClass;
}

/* Expand Area */
  function toggleDiv(divid){
    if(document.getElementById(divid).className == 'list-queue-more-hidden'){
      document.getElementById(divid).className = 'list-queue-more-visible';
    }else{
      document.getElementById(divid).className = 'list-queue-more-hidden';
    }
  }

/* Resizing Divs to match table width */
function loadResize() {
//function expandElements() {
	var tblId = document.getElementById('table-landing');
	var tableWidth = tblId.offsetWidth - 11; // Need to reduce by 11 for anomoly.
	//alert('Width :' + tblId.offsetWidth);
	
	// List of items IDs you want to extend length on.
	document.getElementById('pagination-bottom').style.width=tableWidth+"px";
	document.getElementById('pagination-top').style.width=tableWidth+"px";
	//document.getElementById('main-body').style.width=tableWidth+"px";
	
}

// Window state change functions.
window.onload=function(){
	//loadResize();
	//Uncomment the below if you want the application to expand to full screen when user loads application.
	//maxWindow();
}

window.onresize = function(){
	//loadResize();
}


// AIB Select Functions -------------------------------------------

function releaseNextField(activeFieldID, previousFieldID, nextFieldID, valueSelected, iconActivated, parentDivID, nextParentDivID){	
	//alert(previousFieldID);
	if(valueSelected == "null"){
			document.getElementById(nextFieldID).disabled = true;
	} else {
		document.getElementById(nextFieldID).disabled = false;
		document.getElementById(iconActivated).src = "images/icons/approve__24.gif";
		document.getElementById(nextParentDivID).className = "list-select-aib";
	}
}


function getURLParam(strParamName){
			var strReturn = "";
			var strHref = window.location.href;
			if ( strHref.indexOf("?") > -1 ){
				var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
				var aQueryString = strQueryString.split("&");
			for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
				if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
			var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
			break;
			}
		}
	}
		return strReturn;
	}

function mocksuccessalert(){
	document.getElementById('success-message-1234').style.display = 'block';
	document.getElementById('success-message-1234').className = 'success-message-1234-visible';
	
	//alert("TEST");
}


function highlightNewRow(highlightRowId){
	// Temp highlights new row and then fades away. Sets back to class 'even' because will probably always be first.
	document.getElementById(highlightRowId).style.background  = '#50EF00'; // Deep Green
	$("#"+highlightRowId).stop().animate({ backgroundColor: "#FFFFEA"}, 2500);  
}


/* SUPPORTS THE  HORIZONTAL DROP DOWN NAVIGATION */

sfHover = function() {
	var sfEls = document.getElementById("navlist").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


