function gotoServicePro(sendTo) {
	if (sendTo == 'SP') {
		document.getElementById("learnmore").action='/websites/bestcontractors/general/servicepro.cfm';
		}
	else {
		document.getElementById("learnmore").action='/websites/bestcontractors/general/faqs.cfm';
	}
	document.getElementById("learnmore").submit();
}

function setPanels(menuItem){
	if	(menuItem == "all_subcategories") {
		window.location = "/templates/consumers/homeowner_to_contractor_search.cfm";
		}
	else {
		document.getElementById("projectbuttons").style.display = "none";
		document.getElementById("primarycategorydisplay").style.display = "block";
		if (document.getElementById(menuItem)) {
			document.getElementById(menuItem).style.display = "block";
			}
		resetSub();
		if (arguments[1]) {
			showSub(arguments[1]);
			}
		//eval(menuItem + "_sub").style.display = "block";
		selectedSuper = menuItem;
		}
}

function resetPanels(){
	if (document.getElementById("projectbuttons")) {
		document.getElementById("projectbuttons").style.display = parentCatPanelDisp;
		}
	if (document.getElementById("primarycategorydisplay")) {
		document.getElementById("primarycategorydisplay").style.display = "none";
		}
	if (document.getElementById(selectedSuper)) {
		document.getElementById(selectedSuper).style.display = "none";
		}
	if (document.getElementById("magazinecovers")) {
		document.getElementById("magazinecovers").style.display = "block";
		}
	if (document.getElementById(subCatPanelId)) {
		document.getElementById(subCatPanelId).style.display = "none";
		}
	resetSub();
	setSecondRowPos(secondRowPx);
	displayStep('3','none');
	if (document.ParentCategoryForm.select_parent_category_id) {
		for (a=0; a < document.ParentCategoryForm.select_parent_category_id.length; a++) {
			document.ParentCategoryForm.select_parent_category_id[a].checked = false;
			}
		}
	if (document.getElementById("category_id")) {
		for (b=0; b < document.searchForm.category_id.length; b++) {
			document.searchForm.category_id[b].checked = false;
			}
		}
	document.getElementById("zipcode").value = "";
	if (document.getElementById("source").selectedIndex) {
		document.getElementById("source").selectedIndex = 0;
		document.getElementById("source").length = 1;
		}
	document.getElementById("TOSPP").checked = false;
	document.getElementById("step3_part2").style.display = projectStep3PanelDisp;
}

function resetSub() {
if (selectedSub != "") {
	document.getElementById(selectedSub).style.display = "none";
	}
}

function displayStep(step,disp) {
step_div = "project_start_step_" + step;
document.getElementById(step_div).style.display = disp;
}

function setSecondRowPos(pos) {
document.getElementById("secondrow").style.top = pos;
}

function showSub(catId) {
subCatId = "Layer_" + catId;
selCatId = "select_" + catId + "_";
resetSub();

if (document.getElementById(subCatId)) {
	document.getElementById(subCatId).style.display = "block";
	}
selectedSub = subCatId;
totalSubCats = getSubCategoryCount(selCatId);

global_category_id = catId.replace("category_id","");

//alert(totalSubCats);
if (totalSubCats > 5) {
	addCats = totalSubCats - 5;
	addPx = addCats * 18;
	topPx = parseInt(secondRowPx) + parseInt(addPx);
	pxStr = topPx + "px";
	setSecondRowPos(pxStr);
	heightPx = subCatPanelHeight + addPx;
	}
else {
	setSecondRowPos(secondRowPx);
	heightPx = subCatPanelHeight;
	}
displayStep('3','block');
if (document.getElementById(subCatPanelId)) {
	document.getElementById(subCatPanelId).style.height = heightPx;
	}
document.getElementById("magazinecovers").style.display = magPanelDisp;
document.getElementById(subCatPanelId).style.display = "block";
document.searchForm.parent_category_id.value = catId.replace("category_id","");
}

function getSubCategoryCount(catId) {
inputArray = document.body.getElementsByTagName("input");
counter = 0;
catTxt = "";
lcounter = 0
for (a=0; a < inputArray.length; a++) {
	inputId = inputArray[a].id;
	inputLabel = "label_" + inputId;
	if (inputId.indexOf(catId) != -1) {
		catTxt = document.getElementById(inputLabel).innerHTML;
		if (catTxt.length > 41) {
			lcounter++;
			}
		counter++;
		}
	}
if (lcounter > 1) {
	counter = counter + Math.round(lcounter/2);
	}
//alert(catTxt);
return counter;
}

function activateZip() {
document.getElementById(zipField).disabled = false;
//document.getElementById(zipField).focus();
}

function activateSearch(val) {
butBool = true;
if (val != "") {
	butBool = false;
	}
document.getElementById("SaveButton").disabled = butBool;
}


function browserDetection() {
if (document.getElementById && document.createElement) {
	return true;
	}
else {
	window.location="index_browser.cfm";
	}
}

var resetFieldsList="";

function formValidate() {

var alertText="";
eval(resetFieldsList);

if (document.searchForm.zipcode.value == "") {
	document.searchForm.zipcode.className = 'miniformfieldsalert';
	alertText+="\n*ZIPCODE: Please enter a zipcode.";
	resetFieldsList+="document.forms[formName].zipcode.className = 'miniformfields';"
	}

if (validateZip(document.searchForm.zipcode.value) == false) {
	document.searchForm.zipcode.className = 'miniformfieldsalert';
	alertText+="\n*ZIPCODE: Invalid zipcode format. Please enter the correct format '00000'.";
	resetFieldsList+="document.forms[formName].zipcode.className = 'miniformfields';"
	}

if (global_category_id != "") {
	catArray = new Array();
	catOpt = document.searchForm.category_id;
	catChecked = 0;
	if (catOpt.length > 1) {
		for (a=0;a < catOpt.length; a++) {
			if (catOpt[a].id.indexOf("select_category_id" + global_category_id + "_") != -1) {
				if (catOpt[a].checked == true) {
					catChecked++;
					}
				}
			}
		}
	else {
		if (catOpt.checked == true) {
			catChecked++;
			}
		}
	
	if (catChecked == 0) {
		alertText+="\n*CATEGORY: Please select a category.";
		}
	}

if(alertText.length > 0){
	alertText = "Please Correct the following:\n" + alertText;
	alert(alertText);
	return false;
	}
}
	
function submitSearch() {

resetZipInterval();

if (formValidate() == false) {
	return false;
	}
//if (document.searchForm.parent_category_id.value == emergencyId) {
//	document.searchForm.action ="/templates/projects/emergency_services_profile.cfm";
//	}
if (document.getElementById("source").style.display == "none") {
	checkZipcode();
	}
}

function activateForms() {
pCatObj = document.ParentCategoryForm.select_parent_category_id;
catObj = document.searchForm.category_id;
for (a=0; a < pCatObj.length; a++) {
	pCatObj[a].disabled = false;
	}
document.getElementById("parent_category_loading").style.display = "none";

for (aa=0; aa < catObj.length; aa++) {
	catObj[aa].disabled = false;
	}
document.getElementById("category_loading").style.display = "none";

if (document.getElementById("zipcode")) {
	document.getElementById("zipcode").disabled = false;
	}
}

function viewItems() {
linkId = "ViewItemsLink";
linkTxt = document.getElementById(linkId).innerHTML;
linkIdentifier = "Less";
display_items = "block";
display_class = "panel1b_repeater";
second_row_class = "secondrow_expand";
third_row_class = "thirdrow_expand";

divArray = document.getElementsByTagName("div");

if (linkTxt.indexOf(linkIdentifier) != -1) {
	linkIdentifier = "All";
	display_items = "none";
	display_class = "panel1a_repeater";
	second_row_class = "secondrow_shrunk";
	third_row_class = "thirdrow";
	}

if (arguments[0]) {
	if (arguments[0] == "ALL") {
		linkIdentifier = "Less";
		display_items = "block";
		display_class = "panel1b_repeater";
		second_row_class = "secondrow_expand";
		third_row_class = "thirdrow_expand";
		}
	if (arguments[0] == "LESS") {
		linkIdentifier = "All";
		display_items = "none";
		display_class = "panel1a_repeater";
		second_row_class = "secondrow_shrunk";
		third_row_class = "thirdrow";
		}
	}

for (a=0; a < divArray.length; a++) {
	if (divArray[a].id == "item_display_type_0") {
		divArray[a].style.display = display_items;
		}
	}

document.getElementById("second_row").className = second_row_class;
document.getElementById("third_row").className = third_row_class;
document.getElementById("item_panel").className = display_class;
document.getElementById(linkId).innerHTML = "View " + linkIdentifier + " Projects";
}

function selectCategory(catId,catTxt,parentTxt) {
viewItems('LESS');
if (catTxt != "" && catTxt != "NONE") {
	catTitle = parentTxt.toUpperCase() + " - " + catTxt;
	}
else {
	catTitle = parentTxt.toUpperCase();
	}
document.getElementById("panel1a_box").style.display = "none";
document.getElementById("panel1c_box").style.display = "block";
document.getElementById("category_id").value = catId;
document.getElementById("selected_project_name").innerHTML = catTitle;
//if (arguments[3]) {
//	if (arguments[3] != "1") {
//		emergencyId = "";
//		}
//	else {
//		emergencyId = "#emergency_services_cat_id#";
//		}
//	document.getElementById("parent_category_id").value = emergencyId;
//	}
//else {
//	emergencyId = "#emergency_services_cat_id#";
//	}
}

function selectProject(val) {
params = val.split("|");
//selectCategory(params[0],params[1],params[2])

catId = params[0];
pCatAliasId = params[1];
catAliasId = params[2];

if (params.length != 3) {
	pCatAliasId = 0;
	pCatAliasId = 0;
	catAliasId = 0;
	}

if(catId == "" || catId == "undefined"){
	catId = 0;
	}
if(pCatAliasId == "" || pCatAliasId == "undefined"){
	pCatAliasId = 0;
	}
if(catAliasId == "" || catAliasId == "undefined"){
	catAliasId = 0;
	}

	/*
win_loc = "/indexc.cfm?category_id=" + catId +
				"&parent_category_alias_id=" + pCatAliasId +
				"&category_alias_id=" + catAliasId;

if (arguments[1]) {
	win_loc += "&entity_tracking_id=" + arguments[1];
	}
*/

win_loc = val;

window.location = win_loc;
}

function selectAffiliateProject(val) {
document.forms["Affiliate"].action = val;
document.forms["Affiliate"].submit();
}

function showProjects() {
viewItems('ALL');
document.getElementById("panel1a_box").style.display = "block";
document.getElementById("panel1c_box").style.display = "none";
document.getElementById("availproj").selectedIndex = 0;
}
