// Using Home Equity Tab Switch
function switchHomeEquityTab(tabname) {
	var alltabs = new Array();
	alltabs.push('securelineofcredit_tab');
	alltabs.push('mortgageadon_tab');
	alltabs.push('talktospecialist_tab');

	for(var x=0; x < alltabs.length; x++){
		var  currenttab = document.getElementById(alltabs[x]);
		var  currentcontent = document.getElementById(alltabs[x]+"_content");
		if (alltabs[x] != tabname) {
			if (alltabs[x] != 'default_tab') currenttab.className = 'btn-off';
			currentcontent.style.display = 'none';
		}
		else {
			if (alltabs[x] != 'default_tab') currenttab.className = 'btn-on';
			currentcontent.style.display = 'block';
		}
	}
}


// Mortgage Calculator Tab Switch
function switchMortgageCalculatorTab(tabname) {
	var alltabs = new Array();
	alltabs.push('rentorbuy_tab');
	alltabs.push('howmuchcanyouafford_tab');
	alltabs.push('mpc_tab');
	alltabs.push('howlongwillittake_tab');
	alltabs.push('cst_tab');

	for(var x=0; x < alltabs.length; x++){
		var  currenttab = document.getElementById(alltabs[x]);
		var  currentcontent = document.getElementById(alltabs[x]+"_content");
		if (alltabs[x] != tabname) {
			if (alltabs[x] != 'default_tab') currenttab.className = 'btn-off';
			currentcontent.style.display = 'none';
		}
		else {
			if (alltabs[x] != 'default_tab') currenttab.className = 'btn-on';
			currentcontent.style.display = 'block';
		}
	}
}


// Protecting Your Home Tab Switch
function switchProtectingHomeTab(tabname) {
	var alltabs = new Array();
	alltabs.push('titleinsurance_tab');
	alltabs.push('propertyinsurance_tab');
	alltabs.push('mortgageprotection_tab');

	for(var x=0; x < alltabs.length; x++){
		var  currenttab = document.getElementById(alltabs[x]);
		var  currentcontent = document.getElementById(alltabs[x]+"_content");
		if (alltabs[x] != tabname) {
			if (alltabs[x] != 'default_tab') currenttab.className = 'btn-off';
			currentcontent.style.display = 'none';
		}
		else {
			if (alltabs[x] != 'default_tab') currenttab.className = 'btn-on';
			currentcontent.style.display = 'block';
		}
	}
}


// Tab function for Customer Service
var customerservicetabs = new Array();
customerservicetabs.push('email_tab');
customerservicetabs.push('phone_tab');
customerservicetabs.push('mail_tab');
customerservicetabs.push('online_tab');

function switchCustomerServiceTab(tabname) {
	for(var x=0; x < customerservicetabs.length; x++){
		var  currenttab = document.getElementById(customerservicetabs[x]);
		var  currentcontent = document.getElementById(customerservicetabs[x]+"_content");
		var  currenttabtext = document.getElementById(customerservicetabs[x]+"_text");
		if (customerservicetabs[x] != tabname) {
			currenttab.className = '';
			currentcontent.style.display = 'none';
			currenttabtext.style.color = 'white';
		}
		else {
			currenttab.className = 'primarytabs-currentpage';
			currentcontent.style.display = '';
			currenttabtext.style.color = '#000000';
		}
	}
}

//Retrieves specified parameter from URL string
function getURLParam(strParamName) {	
	// GetURL Params value from querystring
	var qs = location.search.split('?');
	if (qs.length > 1) {
	var pairs = qs[1].split("&");
		for (var i=0; i<pairs.length; i++) {
			var namevalue = pairs[i].split("=", 2);
			var name = unescape(namevalue[0]);
			var value = unescape(namevalue[1]);
			if (name.toUpperCase() == strParamName.toUpperCase()) {
				return value;
				//break;
			}
		}
	}
	return null;
}

//Default to Certain Section in Expand Sections
//Requirements:
//1. Sections need to be named "icon_XX" where XX is the variable
//2. Query parameter needs to be called "expand"
//3. Anchor tag section needs to be the same as the XX variable to auto scroll
function defaultExpand() {
	var browserName=navigator.appName; 
	var expand = getURLParam('expand') || '';
	if (expand != '' && document.getElementById("icon_" + expand)) {
		if (browserName=="Microsoft Internet Explorer") {
			document.getElementById("icon_" + expand).fireEvent("onclick");
		}
		else {
			var evt = document.createEvent("MouseEvents");
			evt.initEvent("click", true, true);
			document.getElementById("icon_" + expand).dispatchEvent(evt); 
	
		}		
		
		var link = '#' + expand;
		window.location.href += link;
	}
}


/***********************************************************************/
/* Expand/Collapse Content
/* - Rewritten from UOS version to allow explicit always expand or always collapse parameter
/* - Third parameter definition:
/*		0 - behaves normally as a toggle
/*		1 - opens all elements
/* 		2 - closes all elements
/***********************************************************************/
function toggleIconRevised(obj, a_id, state) {
	var opener = document.getElementById(a_id)
	var content = getElementsByClass(obj);
	iconState = opener.firstChild.alt;
	iconState = iconState.replace("Collapse","");
	iconState = iconState.replace("Expand","");

	for ( i=0;i<content.length;i++ ) {
		//Toggle
		if(state == 0) {
			if (content[i].style.display != "none" ) {
				content[i].style.display = 'none';
				opener.firstChild.src = opener.firstChild.src.replace("collapse","expand");
				opener.firstChild.alt = 'Expand' + iconState;
			} 
			else {
				content[i].style.display = '';
	           	opener.firstChild.src = opener.firstChild.src.replace("expand","collapse");
				opener.firstChild.alt = 'Collapse' + iconState;
	
			}	
		}
		//Open
		if(state == 1) {
			content[i].style.display = '';
           	opener.firstChild.src = opener.firstChild.src.replace("expand","collapse");
			opener.firstChild.alt = 'Collapse' + iconState;
		}	
		//Close
		if(state == 2) {
			content[i].style.display = 'none';
			opener.firstChild.src = opener.firstChild.src.replace("collapse","expand");
			opener.firstChild.alt = 'Expand' + iconState;	
		}		
	}
}

