
///////////////////////////////////////////////////////////////////////////
///This file is superceded by lendingcriteria.js and is no longer used ////
///////////////////////////////////////////////////////////////////////////


var urlParams = {};
onload=function() {
	if (document.getElementsByClassName == undefined) {
		document.getElementsByClassName = function(className)
		{
			var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
			var allElements = document.getElementsByTagName("*");
			var results = [];
			var element;
			for (var i = 0; (element = allElements[i]) != null; i++) {
				var elementClass = element.className;
				if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
					results.push(element);
			}
			return results;
		}
	}
	
    //Gets the various criteria querystring parameters and hides/shows the criteria sections as applicable
    getUrlParams();
    if (urlParams["filter"] == undefined && urlParams["uniqueid"] == undefined && searchTerms.length == 0)
    {
        hideAll();
    }
    
    if(urlParams["filter"] != undefined && urlParams["filter"].length > 0)
    {
        hideAll();
    }
    
    if(urlParams["uniqueid"] != undefined && urlParams["uniqueid"].length > 0)
    {
        showDetailAll();
    }
    
    if(searchTerms.length > 0)
    {
        showDetailAll();                    
    }   
}

//Get querystring parameters
function getUrlParams() {
        var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&;=]+)=?([^&;]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

        while (e = r.exec(q))
            urlParams[d(e[1])] = d(e[2]);
};

// Hides all the definitions
function hideAll() {
	
	// The containing list for the results
	var objfoldlist = document.getElementById('foldlist');
    //The containing list for the results
	//var objSearchTerms = document.getElementById('searchterms');

	// An array of all the DIV elements inside this list
	var arrDefinitions = objfoldlist.getElementsByTagName('DIV');
	
	// An array of all the DT elements inside this list
	//var arrTerms = objSearchTerms.getElementsByTagName('DT');
	
	// An array of all elements which have the class "odd"
	var arrOddTerms = document.getElementsByClassName('odd');

	// Hiding all these elements
	for (i=0; i < arrDefinitions.length; i++)
	{
		arrDefinitions[i].style.display = "none";
	}
	// Making sure all the DTs have the default background graphic
	//for (i=0; i < arrTerms.length; i++)
	//{
	//	arrTerms[i].style.background = "url(/img/bg-searchterms-dt-odd-js.png) top left no-repeat";
	//}
	// Making sure all the odd DTs have the odd background graphic
	
}

// Hides juyst this definition
function hideThis(objDefTerm) {
	// For browsers who believe in text nodes
	if(objDefTerm.nodeType==3) {
		objDefinition = objDefTerm.nextSibling;
	}
	// For those who doubt their existance
	else {
		objDefinition = objDefTerm;
	}
	// Hiding all these elements
	objDefinition.style.display = "none";
}

// This shows the following sibling, and changes a background graphic.
function showDetail(objDefTerm) {
	// For browsers who believe in text nodes
	if(objDefTerm.nextSibling.nodeType==3) {
		objDefinition = objDefTerm.nextSibling.nextSibling;
	}
	// For those who doubt their existance
	else {
		objDefinition = objDefTerm.nextSibling;
	}
	// If the current definition is already showing, hide it
	if(objDefinition.style.display == "block") {
		hideThis(objDefinition);
		objDefTerm.style.background = "url(/img/bg-criteria-heading.jpg) top left no-repeat";
		//hideAll();
	}
	// If the current definition is hidden, show it
	else {
		// Comment the following line out, to turn this from radio, to checkbox style
		//hideAll();
		// Shows the new definition
		objDefinition.style.display = "block";
		objDefTerm.style.background = "url(/img/bg-criteria-heading-expanded.jpg) top left no-repeat";
		
	}
}

function showDetailAll() {
    var zDD=document.getElementById('foldlist').getElementsByTagName('div');
    for(var i=0;i<zDD.length;i++){
	    zDD[i].style.display='block';
    }
	return false;
}

function hideDefAll() {
    var zDD=document.getElementById('foldlist').getElementsByTagName('div');
    for(var i=0;i<zDD.length;i++){
	   zDD[i].style.display='none';
    }
	return false;
}

function doHideShowAllCriteria(x){
    var zDD=document.getElementById('foldlist').getElementsByTagName('div');
    zDD[x].className=(zDD[x].style.display=='none')?'block':'none';
}

function hideShowAllCriteria(){
    if (document.getElementById && document.getElementsByTagName){ 
	    var zDD=document.getElementById('foldlist').getElementsByTagName('div');
	    var hideShowOn = document.getElementById('hideShowOn');
	    var hideShowOff = document.getElementById('hideShowOff'); 
		    if (hideShowOn && hideShowOff){
				hideShowOn.onclick = showDetailAll;
				hideShowOn.title = "Show all criteria";
				hideShowOn.href = "#";
			   	hideShowOff.onclick = hideDefAll; 
 			   	hideShowOff.title = "Hide all criteria";
				hideShowOff.href = "#";
			}
    }
}

