// JavaScript Document

function getQueryStrings()
{
	var url = window.location.toString();
	//get the parameters
	url.match(/\?(.+)$/);
	var params = RegExp.$1;
	// split up the query string and store in an
	// associative array
	var params = params.split("&");
	var queryStringList = {};
 
	for(var i=0;i<params.length;i++)
	{
		var tmp = params[i].split("=");
		queryStringList[tmp[0].toUpperCase()] = unescape(tmp[1]);
	}
	
	return queryStringList;
	
}
function addQueryStringToLink()
{
	var qString = window.location.toString();
	
	if (qString.indexOf("?") > 0){
		qString = qString.substring(qString.indexOf("?"),qString.length);
		
		// pos is only used for the privacy-full.html page to find a location to scroll to according to the link clicked in privacy.html
		// this conditional removes any previous pos item from the querystring as it is not used anywere else and if privacy has a pos item 
		// in its querystring it looks sloppy because there are 2 pos items added to the querystring.  It would still work, but it looks bad.
		if (qString.indexOf("pos=") > 0){
			qString = qString.substring(0, qString.indexOf("pos=") - 1);
		}
		for (i=0; i < document.links.length; i++)
		{
			if (document.links[i].href.indexOf("?") > 0){
				linkString = document.links[i].href.substring(0, document.links[i].href.indexOf("?"));
				positionString = document.links[i].href.substring(document.links[i].href.indexOf("?") + 1,document.links[i].href.length);
				if (qString.length == 0){
					document.links[i].href = linkString + "?" + positionString;
				}
				else{
					document.links[i].href = linkString + qString + "&" + positionString;
				}
				
			}
			else{
				document.links[i].href = document.links[i].href + qString; 
			}
		}
	}
	
}
function startDynamicFunctionality()
{
	var qList = getQueryStrings();
	if (qList["LOC"]){
		var loc = qList["LOC"];
		doDynamicLOCFunctionality(loc);
	}
	if (qList["REF"]){
		var ref = qList["REF"];
		doDynamicREFFunctionality(ref);
	}
	if (qList["POS"]){
		var url = window.location.toString();
		if (url.indexOf("privacy-full.html") > 0){
			var pos = qList["POS"];
			doDynamicPOSFunctionality(pos);
		}
	}
		
	addQueryStringToLink();

}

function doDynamicREFFunctionality(ref){
	if (ref == "1")
	{
		setPhone("");
		hideRequestInformationPage();
	}
	if (ref == "2")
	{
		setPhone("888-838-6782 Ext. 6001");
		hideRequestInformationPage();
	}
	if (ref == "3")
	{
		setPhone("800-342-4386");
		hideRequestInformationPage();
	}
	if (ref == "4")
	{
		setPhone("800-321-3848");
		hideRequestInformationPage();
	}
}
function doDynamicLOCFunctionality(loc){
	if (loc == "DB59*1-1XZKIB")
	{
		setPhone("888-229-2441");
	}
	if (loc == "DB59*1-1XZKAU")
	{
		setPhone("");
		hideRequestInformationPage();
	}
	if (loc == "DB17*1-1WUX1Z")
	{
		setPhone("800-946-2818");
	}
	if (loc == "DB59*1-1WUX8J")
	{
		setPhone("888-229-2631");
	}
	if (loc == "DB59*1-1XZKHL")
	{
		setPhone("888-229-2634");
	}
	if (loc == "DB59*1-1XZKHF")
	{
		setPhone("888-229-2635");
	}
	if (loc == "DB59*1-1ZR038")
	{
		setPhone("866-389-1463");
	}
	if (loc == "DB59*1-1XZKDR")
	{
		setPhone("888-209-5557");
	}
	if (loc == "DB59*1-1XZKFB")
	{
		setPhone("888-516-5480");
	}
	if (loc == "DB59*1-1ZIUW8")
	{
		setPhone("800-445-0849");
	}
	if (loc == "DB59*1-1ZIV1G")
	{
		setPhone("866-300-3009");
	}
	if (loc == "DB59*1-2024BI")
	{
		setPhone("800-527-1917");
	}
	if (loc == "DB59*1-202188")
	{
		setPhone("866-389-1464");
	}
	if (loc == "DB59*1-202185")
	{
		setPhone("800-983-4218");
	}
	if (loc == "DB59*1-202PQD")
	{
		setPhone("800-983-0324");
	}
	if (loc == "DB59*1-205PQG")
	{
		setPhone("800-983-0324");
	}
	if (loc == "DB17*1-202185")
	{
		setPhone("800-983-4218");
	}
	if (loc == "DB02*1-20TJSX")
	{
		setPhone("888-240-3263");
	}
	if (loc == "DB02*1-29PE72")
	{
		setPhone("800-353-7089");
	}
	if (loc == "DB17*1-20210O")
	{
		setPhone("800-983-4216");
		showAssociatePage();
	}
	if (loc == "DB59*1-20JA1T")
	{
		setPhone("800-256-6495");
		showAssociatePage();
	}
	if (loc == "DB59*1-23E9SI")
	{
		setPhone("877-513-4386");
	}
}
function doDynamicPOSFunctionality(pos){
	self.scrollTo(0, findPos(document.getElementById(pos)));
}
function hideOwnerSpecialsPage()
{
	document.getElementById("owner").style.display = "none";
}
function showOwnerSpecialsPage()
{
	document.getElementById("owner").style.display = "";	
}
function hideRequestInformationPage(){
	document.getElementById("requestInfo").style.display = "none";
}
function hideFoundingMembersPage(){
	document.getElementById("founding").style.display = "none";	
}
function showAssociatePage()
{
	document.getElementById("associate").style.display = "";
}
function showFoundingMembersPage(){
	document.getElementById("founding").style.display = "";	
}


function setPhone(number)
{
	document.getElementById("dPhone").innerHTML = number;
	if (number.length > 12){
		document.getElementById("dPhone").style.fontSize = "14px";	
		document.getElementById("dPhone").style.paddingTop = "70px";
	}
	if (number.length > 1)
	{
		document.getElementById("callBlock").style.display = "";
	}
}

function findPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	return curtop;
}