function expandLink1(){
		$(".searchExpanderTitle1").removeClass("off");
		$(".searchExpanderTitle1").addClass("on");
		$(".searchExpander1").removeClass("collapsed");
		$(".searchExpander1").addClass("expanded");
		$(".searchExpanderContent1").show();
		$(".image1").attr("src", "/fap/img/icon-collapse-bg_white.gif");
		$(".image1").attr("alt", "-");
		return false;
		}
function collapseLink1(){
		$(".searchExpanderTitle1").removeClass("on");
		$(".searchExpanderTitle1").addClass("off");
		$(".searchExpander1").removeClass("expanded");
		$(".searchExpander1").addClass("collapsed");
		$(".searchExpanderContent1").hide();
		$(".image1").attr("src", "/fap/img/icon-expand-bg_white.gif");
		$(".image1").attr("alt", "+");
		return false;
		}

function expandLink2(){
		$(".searchExpanderTitle2").removeClass("off");
		$(".searchExpanderTitle2").addClass("on");
		$(".searchExpander2").removeClass("collapsed");
		$(".searchExpander2").addClass("expanded");
		$(".searchExpanderContent2").show();
		$(".image2").attr("src", "/fap/img/icon-collapse-bg_white.gif");
		$(".image2").attr("alt", "-");
		return false;
		}
function collapseLink2(){
		$(".searchExpanderTitle2").removeClass("on");
		$(".searchExpanderTitle2").addClass("off");
		$(".searchExpander2").removeClass("expanded");
		$(".searchExpander2").addClass("collapsed");
		$(".searchExpanderContent2").hide();
		$(".image2").attr("src", "/fap/img/icon-expand-bg_white.gif");
		$(".image2").attr("alt", "+");
		return false;
		}

$(document).ready(function() {
	$(".searchExpanderContent1").hide();
	$(".searchExpanderContent2").hide();

	$(".link1").click(function(){
		if ($(".image1").attr("alt") == "-") {
			collapseLink1();
		} else {
			expandLink1();
		}
		return false;
	});

	$(".link2").click(function(){
		if ($(".image2").attr("alt") == "-") {
			collapseLink2();
		} else {
			expandLink2();
		}
		return false;
	});
});

var intMaxResults = 2;
var intPopupHeight = 160;
var intX = 0;
var intY = 0;
var intZ = 1;

function initVars() {
	if (document.getElementById('popup1')) {
		intPopupHeight = (document.getElementById('popup1').style.height) ? parseInt(getElementById('popup1').style.height) + 50 : 270;
	}
	intX = (((windowWidth() - 1004) / 2) + 249 >= 0) ? parseInt(((windowWidth() - 1004) / 2) + 249) : 0;
	intY = ((windowHeight() / intMaxResults) - intPopupHeight > 0) ? parseInt((windowHeight() / intMaxResults) - intPopupHeight) : parseInt(windowHeight() / intMaxResults);
}

function resetX() {
	intX = (((windowWidth() - 1004) / 2) + 249 >= 0) ? parseInt(((windowWidth() - 1004) / 2) + 249) : 0;
	return intX;
}

function resetY() {
	intY = ((windowHeight() / intMaxResults) - intPopupHeight > 0) ? parseInt((windowHeight() / intMaxResults) - intPopupHeight) : parseInt(windowHeight() / intMaxResults);
	return intY;
}

function setY(intArg) {
	if (intArg <= intMaxResults) {
		intY = (((windowHeight() / intMaxResults) * intArg) - intPopupHeight > 0) ? parseInt(((windowHeight() / intMaxResults) * intArg) - intPopupHeight) : 10 /* parseInt(windowHeight() / (intMaxResults * 2))*/ ;
		return intY;
	} else {
		return resetY();
	}
}

function removeVisibility(strArg) {
	var objArg;
	objArg = document.getElementById(strArg);
	objArg.style.visibility = 'hidden';
	var objArgFrame = document.getElementById(strArg+"Frame");
	objArgFrame.style.display="none";
}

function removeVisibilityAll() {
	var intCount = 1;
	for (intCount = 1; intCount <= intMaxResults; intCount++) {
		removeVisibility('popup' + intCount);
	}
}

function toggleVisibility(strArg) {
//init
	var objArg;
	var intMarginY = 0;
//	resetX();
//	resetY();
//	intIndexPopup = parseInt(strArg.substr(strArg.length - 1, 1));
	/* This is replaced by setY();
	intMarginY = parseInt(strArg.substr(strArg.length - 1, 1)) * 70;
	intY += intMarginY;
	*/
//	setY(intIndexPopup);
	intZ++;
	objArg = document.getElementById(strArg);
	removeVisibilityAll();
	
//New style settings
	objArg.style.zIndex = intZ;
	objArg.style.visibility = (objArg.style.visibility == 'visible') ? 'hidden' : 'visible';
	if (document.documentElement) {
		intLeft = document.documentElement.scrollLeft;
		intTop = document.documentElement.scrollTop;
	}
	else if (document.body) {
		intLeft = document.body.scrollLeft;
		intTop = document.body.scrollTop;
	}
	intLeft += intX;
	intTop += intY;
	/* This cis maybe to ensure that popups appear a certain distance from the page top
	 * (rather than the window top, which is what setY() does).
	intTop = (intTop > 200) ? intTop : 200;
	*/
	objArg.style.left = intLeft + 'px';
	objArg.style.top = intTop + 'px';
	strArgFrame = document.getElementById(strArg+"Frame");
	strArgFrame.style.left = intLeft + 'px';
	strArgFrame.style.top = intTop + 'px';
	strArgFrame.style.display = "block";
	return false;
}

function placePopup(strArg) {
	var objArg;
	var intLeft = 0;
	var intTop = 0;
	var intMarginY = 0;
	resetX();
	resetY();
	intMarginY = parseInt(strArg.substr(strArg.length - 1, 1)) * 50;
	intY += intMarginY;
	objArg = document.getElementById(strArg);
	if (document.documentElement) {
		intLeft = document.documentElement.scrollLeft;
		intTop = document.documentElement.scrollTop;
	}
	else if (document.body) {
		intLeft = document.body.scrollLeft;
		intTop = document.body.scrollTop;
	}
	intLeft += intX;
	intTop += intY;
	objArg.style.left = intLeft + 'px';
	objArg.style.top = intTop + 'px';
	/* setTimeout("placePopup('" + strArg + "')", 500); */
	/* placePopup(strArg); */
}


$(document).ready(function() {
initVars();
/*
resetX();
resetY();

window.onscroll = setTimeout("placePopup('popup1')", 500);
window.onscroll = setTimeout("placePopup('popup2')", 500);
window.onscroll = setTimeout("placePopup('popup3')", 500);
window.onscroll = setTimeout("placePopup('popup4')", 500);
*/
});

/////////////////////////////////////////////////////////////////////////////

function validateUserInput()
{
	var zip_pattern=/(^\d{5}$)/;
	var areacode_pattern=/(^\d{3}$)/;
	var city_pattern=/(^[a-zA-Z.,\/\- ]+$)/;
	var zip_flag;
	var email_flag;
	var areacode_flag;
	zip_flag=1;
	email_flag=1;

buildInclude();

if ((document.MemberSearch.zipCode.value.length == 0) && (document.MemberSearch.city.value.length == 0)&&	(document.MemberSearch.state.selectedIndex == 0))
{
	alert('Please complete the required fields: Missing zip code, city/state');
			return false;

}

	if (document.MemberSearch.zipCode.value.length > 0)
	{
	   if(zip_pattern.test(document.MemberSearch.zipCode.value))
		{
			zip_flag=0;
		    }
	    else
		{
		    alert("Please enter your 5-digit zipCode Code");
		    document.MemberSearch.zipCode.focus();
		    return false;
		}
		   document.MemberSearch.placetext.value=' zip code ' + document.MemberSearch.zipCode.value;
	}



	if ((zip_flag == 0))
		{
			fireOmnitureEvents();
			sendClickEvent("FindPA_Options-Method_ZipCode");
			document.MemberSearch.submit();
		}
		else
		{
			if ((document.MemberSearch.city.value.length > 0) && (document.MemberSearch.state.selectedIndex > 0))
			{
				    document.MemberSearch.placetext.value=document.MemberSearch.city.value + ', ' + document.MemberSearch.state.value;
					sendClickEvent("FindPA_Options-Method_CityState");
					fireOmnitureEvents();
				document.MemberSearch.submit();
			}
			else{
			    if((document.MemberSearch.city.value.length > 0) && (document.MemberSearch.state.selectedIndex == 0))
			    {
			       alert('Please complete the required fields: Missing state');
			       document.MemberSearch.state.focus();
			       return false;

			    }

			    if((document.MemberSearch.city.value.length == 0) && (document.MemberSearch.state.selectedIndex > 0))
			    {
			       alert('Please complete the required fields: Missing City');
			       document.MemberSearch.city.focus();
			       return false;

			    }

			}
		}
}

function omnitureLicenses()
{
	var qbLicences = document.getElementById("qbLicenses");
	switch (qbLicences.value)
	{
		case "":
			return "";
		case "0":
			return "Licenses_0";
		case "1-5":
			return "Licenses_1-5";
		case "6+":
			return "Licenses_6plus";
		default:
			return "Licenses_Invalid";
	}
}

function omnitureCode(id)
{
	switch (id)
	{
		case "10":
			return "Products_QB-SS";
		case "20":
			return "Products_QB_Basic-Pro-Prem";
		case "30": 
			return "Products_QB_Mac";
		case "40":
			return "Products_QB_Prem-Contractor";
		case "50":
			return "Products_QB_Prem-Mfg";
		case "60":
			return "Products_QB_Prem-Retail";
		case "70":
			return "Products_QB_Prem-ProService";
		case "80":
			return "Products_QB_Prem-Non-Profit";
		case "90":
			return "Products_QB_Online";
		case "100":
			return "Products_QBPOS";
		case "110":
			return "Products_QBES";
		case "120":
			return "Products_3rdParty";
		case "170":
			return "Products_Quicken";
		case "190":
			return "Products_TurboTax";
		case "680":
			return "Products_QB_Payroll";
		case "690":
			return "Products_Intuit_Payroll";
		case "550":
			return "Services_Acctg-Audits";
		case "700":
			return "Services_Acctg-Bookkeeping";
		case "570":
			return "Services_Acctg-Payroll";
		case "710":
			return "Services_Acctg-WriteUp";
		case "580":
			return "Services_QB-Setup";
		case "590":
			return "Services_QB-Phone";
		case "600":
			return "Services_QB-Remote";
		case "610":
			return "Services_QB-Training";
		case "620":
			return "Services_QB_Payroll";
		case "630":
			return "Services_Finance_IncomeTax";
		case "640":
			return "Services_Finance_Invest";
		case "650":
			return "Services_Finance_Fixed";
		case "660":
			return "Services_Comp_Network";
		case "670":
			return "Services_Comp_HWSWSales";
		case "200":
			return "Industry_Farm";
		case "210":
			return "Industry_Auto";
		case "220":
			return "Industry_Computer";
		case "230":
			return "Industry_Construction";
		case "240":
			return "Industry_Consulting";
		case "250":
			return "Industry_Engineering";
		case "260":
			return "Industry_Financial";
		case "270":
			return "Industry_Government";
		case "280":
			return "Industry_Hospitality";
		case "290":
			return "Industry_Insurance";
		case "300":
			return "Industry_Landscaping";
		case "310":
			return "Industry_Legal";
		case "320":
			return "Industry_Manufacturing";
		case "330":
			return "Industry_Health";
		case "340":
			return "Industry_Non-Profit";
		case "350":
			return "Industry_Property";
		case "360":
			return "Industry_Real-Estate";
		case "370":
			return "Industry_Restaurant";
		case "380":
			return "Industry_Retail";
		case "390":
			return "Industry_Beauty";
		case "400":
			return "Industry_Telecom";
		case "410":
			return "Industry_Transportation";
		case "420":
			return "Industry_Wholesale";
		case "430":
			return "Industry_Other";
		default:
			return "Invalid";
	}
}

function fireOmnitureEvents()
{
	var lastName=document.getElementById("lastName");
	lastName.value = lastName.value.replace(/^\s+|\s+$/g, '');
	if (lastName.value.length>0)
	{
		sendClickEvent("FindPA_Options-LastName");
	}
	
	var include=document.getElementById("include");
	if (include.value.length > 0)
	{
		var options = include.value.split(",");
		for (i=0; i<options.length; i++)
		{
			sendClickEvent("FindPA_Options-" + omnitureCode(options[i]));
		}
	}
	if (omnitureLicenses().length > 0)
	{
		sendClickEvent("FindPA_Options-" + omnitureLicenses());
	}
}

function buildInclude()
{
	var include=document.getElementById("include");
	
	include.value="";
	

	var industry=document.getElementById("industry");
	var selectAttributeText=document.getElementById("selectAttributeText");
	selectAttributeText.value="";
	
	if (industry.value != "")
		include.value=industry.value;
	
	if (industry.value!="")
		if (selectAttributeText.value == "")
			selectAttributeText.value="who support " + industry.options[industry.selectedIndex].text;
		else
			selectAttributeText.value=selectAttributeText.value + "and who support " + industry.options[industry.selectedIndex].text;

	var products_attrib_include=document.getElementsByName("products_attrib_include");
	for (var i=0; i<products_attrib_include.length; i++)
	{
		if (products_attrib_include[i].checked)
		{
			if (include.value=='')
				include.value=products_attrib_include[i].value
			else
				include.value=include.value + ',' + products_attrib_include[i].value
		}
	}
	var services_attrib_include=document.getElementsByName("services_attrib_include");
	for (var i=0; i<services_attrib_include.length; i++)
	{
		if (services_attrib_include[i].checked)
		{
			if (include.value=='')
				include.value=services_attrib_include[i].value
			else
				include.value=include.value + ',' + services_attrib_include[i].value
		}
	}
}
function buildProducts()
{
	var products_include=document.getElementById("products_include");	
	products_include.value='';
	
	var products_attrib_include=document.getElementsByName("products_attrib_include");
	for (var i=0; i<products_attrib_include.length; i++)
	{
		if (products_attrib_include[i].checked)
		{
			if (products_include.value=='')
			products_include.value=products_attrib_include[i].value;
			else
			products_include.value=products_include.value + ',' + products_attrib_include[i].value
		}
	}
}

function buildServices()
{
	var services_include=document.getElementById("services_include");
	services_include.value='';
	
	var services_attrib_include=document.getElementsByName("services_attrib_include");
	for (var i=0; i<services_attrib_include.length; i++)
	{
		if (services_attrib_include[i].checked)
		{	if (services_include.value=='')
			services_include.value=services_attrib_include[i].value;
			else
			services_include.value=services_include.value + ',' + services_attrib_include[i].value
		}
	}

}

function selectProducts()
{
	var products_include=document.getElementById("products_include");
	var products_arr_include=products_include.value.split(",");
	
	var products_attrib_include=document.getElementsByName("products_attrib_include");
	
	for (var i=0; i<products_attrib_include.length; i++)
	{	var check=false;
		for(var j=0; j<products_arr_include.length; j++)
		{
			if (products_arr_include[j] == products_attrib_include[i].value)
			{	products_attrib_include[i].checked=true;
				check=true;
			}		
		}
		if(!check)
		products_attrib_include[i].checked=false;
	}

}

function selectServices()
{
	var services_include=document.getElementById("services_include");
	var services_arr_include=services_include.value.split(",");
	
	var services_attrib_include=document.getElementsByName("services_attrib_include");
	
	for (var i=0; i<services_attrib_include.length; i++)
	{	var check=false;
		for(var j=0; j<services_arr_include.length; j++)
		{
			if(services_arr_include[j] == services_attrib_include[i].value)
			{	services_attrib_include[i].checked=true;
				check=true;
			 }
		}
		if(!check)
		services_attrib_include[i].checked=false;
	}
}

function toggleProductsImages()
{
	var products_attrib_include=document.getElementsByName("products_attrib_include");
	var resetProductsImage = true;	
	for (var i=0; i<products_attrib_include.length; i++)
	{
		if(products_attrib_include[i].checked)
		{
		 resetProductsImage = false;
		 break;
		}
	}
	
	if(resetProductsImage)	
		document.getElementById("selectProductsImageId").src="/fap/img/button-select_products-bg_white.gif";
	else
		document.getElementById("selectProductsImageId").src="/fap/img/button-change_products-bg_white.gif";
	
}
function preLoadImages()
{
	image1= new Image(10,10)
	image1.src = "/fap/img/button-change_products-bg_white.gif"

	image2 = new Image(10,10)
	image2.src = "/fap/img/button-change_services-bg_white.gif"
}

function toggleServicesImages()
{	
	var services_attrib_include=document.getElementsByName("services_attrib_include");
	var resetServicesImage = true;	
	for (var i=0; i<services_attrib_include.length; i++)
	{
		if(services_attrib_include[i].checked)
		{
		 resetServicesImage =  false;
		 break;
		}
	}
	if(resetServicesImage)
		document.getElementById("selectServicesImageId").src="/fap/img/button-select_services-bg_white.gif";
	else
		document.getElementById("selectServicesImageId").src="/fap/img/button-change_services-bg_white.gif";

}


