﻿
/* -----------------------------  downer and dirtier js functions ----------------------------------------- */

function show(argElementId) { document.getElementById(argElementId).style.display = 'block'; }
function hide(argElementId) { document.getElementById(argElementId).style.display = 'none'; }
function toggle(argElementId) { obj = document.getElementById(argElementId); if (obj.style.display == 'block') { hide(argElementId); } else { show(argElementId); } }

/* -----------------------------  Image Swap function ----------------------------------------- 
* assumes that an image is inside of a link for example
* <a href=""><img src="someimage.gif" /></a>
* 
* DOES NOT WORK FOR INPUTS USE swapImagesInput
*/

function swapImages(btnName, imgName, imgType) {
	var imgNorm = "/assets/images/" + imgName + "." + imgType;
	var imgOver = "/assets/images/" + imgName + "_over." + imgType;


	$(btnName).hover(
		function () { $(this).find('img').attr({ src: imgOver }); },
		function () { $(this).find('img').attr({ src: imgNorm }); }
	);
}

/* -----------------------------  Image Swap for Inputs and Img tags ----------------------------------------- */

function swapImagesInput(btnName, imgName, imgType) {
	var imgNorm = "/assets/images/" + imgName + "." + imgType;
	var imgOver = "/assets/images/" + imgName + "_over." + imgType;

	$(btnName).hover(
		function () { $(this).attr({ src: imgOver }); },
		function () { $(this).attr({ src: imgNorm }); }
	);
}


/* -----------------------------  document.ready (i.e. onload) ----------------------------------------- */
$(document).ready(function () {

	$('a.roll').each(function (e) {
		var imgObj = $(this).find('img');
		if (imgName) {
			var imgName = imgObj.attr('src');
			imgName = imgName.replace('/assets/images/', '');

			var imgType = imgName.substr(imgName.lastIndexOf('.') + 1, 3);
			imgName = imgName.replace('.' + imgType, '');

			swapImages($(this), imgName, imgType);
		}
	});

	/*
	$('input.roll').each(function(e) {
	var imgName =  $(this).attr('src'); // note, this assumes it is an ImageButton
	imgName = imgName.replace('/assets/images/','');
		
	var imgType = imgName.substr(imgName.lastIndexOf('.')+1,3);
	imgName = imgName.replace('.'+imgType,'');
		
	swapImagesInput($(this),imgName,imgType);
	});
	*/

	$('img.roll').each(function (e) {
		var imgName = $(this).attr('src'); // note, this assumes it is an img tag
		imgName = imgName.replace('/assets/images/', '');

		var imgType = imgName.substr(imgName.lastIndexOf('.') + 1, 3);
		imgName = imgName.replace('.' + imgType, '');

		swapImagesInput($(this), imgName, imgType);
	});

	/* pulled from unkown
	$('.mainNav li').hover(
	function() {
	//$('div.dropdownOuter', this).css('display', 'block');
	$('div.dropdownOuter', this).fadeIn('fast');
	$('div.dropdownOuter', this).css('z-index', '100');
	//$('.mainContent').css('z-index', '1');
	},
	function() {
	$('div.dropdownOuter', this).css('display', 'none');
	}
	);
	*/

	/* ------------------------------   Drop Down Stuff ------------------------ */

	$('.header ul.mainNav li.mainNavMenu').hover(
	function () {
		$('div.subLinks', this).css('display', 'block');
	},
	function () {
		$('div.subLinks', this).css('display', 'none');
	});

	/*** product listing profile lists menu ***/

	$('.productThListBtn').click(function () {
		$('.productThListMenu').hide();
		//$(this).parent().find('.productThListMenu').css('display','block');
		$(this).parent().find('.productThListMenu').fadeIn('normal');
	});

	$('.productThListMenu').hover(
		function () { $(this).show(); },
		function () { $('.productThListMenu').hide(); }
	);

	/*** dealer search input fields ***/

	$('.dealerClickInput').focus(function () {
		if ($(this).val()) {
			var inputVal = jQuery.trim($(this).val());

			if (inputVal == 'Zip/Postal Code' || inputVal == 'City') {
				$(this).val('');
			}
		} else {

		}
	});

	$('.dealerInputZip').blur(function () {
		if ($(this).val()) {
			var inputVal = jQuery.trim($(this).val());

			if (inputVal == '') {
				$(this).val('Zip/Postal Code');
			}
		} else {
			$(this).val('Zip/Postal Code');
		}
	});

	$('.dealerInputCity').blur(function () {
		if ($(this).val()) {
			var inputVal = jQuery.trim($(this).val());

			if (inputVal == '') {
				$(this).val('City');
			}
		} else {
			$(this).val('City');
		}
	});


	/* --------------------------   Product Detail Tabs  ----------------------- */

	$('div#prodTabs a').click(function () {
		var imgid = $(this).attr('targ').replace('#', '');
		$('#prodDetailContent .prodTabContent').hide();
		$('#prodDetailContent #' + imgid).show();
		$('div#prodTabs a').removeClass('selectedTab');
		$(this).addClass('selectedTab');
	});

	$(function () {
		$('#prodDetailContent .prodTabContent:eq(0)').show();
	});


	/* -----------------------------   display product images  ---------------------------- */
	$('div.detailLeft div.largeImage').each(function (i) {
		var currID = $(this).attr('id');
		var imgSRC = $(this).find('img.mainProdImg').attr('src');
		var imgAlt = $(this).find('img.mainProdImg').attr('alt');
		imgAlt = Replace(imgAlt, "\"", "''");
		$('div.detailLeft ul.prodImages').append('<li><a targ="' + currID + '" href="#' + currID + '" class="' + currID + '"><img src="' + imgSRC + '" alt="' + imgAlt + '" title="' + imgAlt + '" /></a></li>');
	});

	$('div.detailLeft ul.prodImages li a').click(function () {
		var imgid = $(this).attr('targ').replace('#', '');
		$('div.detailLeft div.largeImage').hide();
		$('div.detailLeft .prodStandardImages div#' + imgid).show();
		$('div.detailLeft ul.prodImages li a').removeClass('selectedImg');
		$(this).addClass('selectedImg');
	});

	$(function () {
		$('div.detailLeft div.largeImage:eq(0)').show();
	});
});



/* --------------------------   tab swappers?  ----------------------- */

function swapTabClass(argTabId) {
	obj = document.getElementById(argTabId);
	if (obj.className.indexOf("pdTabSelected") != -1) {
		obj.className = obj.className.replace("pdTabSelected", "pdTabDeSelected");
	} else {
		obj.className = obj.className.replace("pdTabDeSelected", "pdTabSelected");
	}
}

function toggleTab(argTabID, argTabContentID) {
	if (argTabID != currentProdTabID) {
		swapTabClass(currentProdTabID);
		swapTabClass(argTabID);
		hide(currentProdTabContentID);
		show(argTabContentID);
		currentProdTabID = argTabID;
		currentProdTabContentID = argTabContentID;
	}
}

function pdImagesTabShow(argImageID, argTabID) {
	/*
	if (argTabID != currentImageTabID) {
	// switch tabs look
	if (argTabID == "pdImagesTabColors") {
	show("pdImagesTabColorLimg");
	document.getElementById("pdImagesTabImagesInner").className = "pdImagesTabInnerOff";
	document.getElementById("pdImagesTabImages").className = "";
	document.getElementById("pdImagesTabImagesB").className = "";
	document.getElementById("pdImagesTabColorBL").className = "";
	document.getElementById("pdImagesTabColors").className = "";
	document.getElementById("pdImagesTabBM").className = "";
	document.getElementById("pdImagesTabColorsB").className = "";
	document.getElementById("pdImagesTabColorsInner").className = "pdImagesTabInnerOn";
	} else {
	hide("pdImagesTabColorLimg"); 
	document.getElementById("pdImagesTabColorBL").className = "off";
	document.getElementById("pdImagesTabColors").className = "off";
	document.getElementById("pdImagesTabBM").className = "off";
	document.getElementById("pdImagesTabColorsB").className = "off";
	document.getElementById("pdImagesTabColorsInner").className = "pdImagesTabInnerOff";
	document.getElementById("pdImagesTabImages").className = "on";
	document.getElementById("pdImagesTabImagesB").className = "on";
	document.getElementById("pdImagesTabImagesInner").className = "pdImagesTabInnerOn";
	}
		
	currentImageTabID = argTabID;
	}
	*/

	// hides the current main image
	$("#pdImageMain" + currentImageID).hide();

	// shows the passed main image
	//show("pdImageMain" + argImageID);
	$("#pdImageMain" + argImageID).fadeIn("normal");

	// turns off the current thumbnail
	document.getElementById("pdImageThumb" + currentImageID).className = " ";

	// turns on the passed thumbnail
	document.getElementById("pdImageThumb" + argImageID).className = "pdSelectedImg";

	currentImageID = argImageID;
}

if ($.browser.msie && (parseInt($.browser.version) < 7)) {
	$(document).ready(function () {
		$("div.zoomIcon img").css('display', 'block');
		$("div.zoomIcon img").attr("src", "/assets/images/products/zoomIcon.gif");
	});
}



/* -------------------------------- MODAL OVERLAY FUNCTIONS ---------------- */

var arrayOfProductsToCompare = [];

function findIndexInArray(argValue, argArray) {
	var returnValue = -1;
	for (var i = 0; i < argArray.length; i++) {
		if (argValue == argArray[i]) {
			returnValue = i;
			break;
		}
	}

	return returnValue;
}

function toggleCompareCell(argElementID) {
	prodObj = document.getElementById(argElementID);

	if (prodObj.className == "selected") {
		prodObj.className = "unselected";

		var elementIndex = findIndexInArray(argElementID, arrayOfProductsToCompare)
		if (elementIndex != -1) {
			arrayOfProductsToCompare.splice(elementIndex, 1);
		}
	} else {
		if (arrayOfProductsToCompare.length < 4) {
			prodObj.className = "selected";
			arrayOfProductsToCompare.push(argElementID);
		} else {
			alert("You can only select 4 items to compare.");
		}
	}

	document.getElementById("selectedCount").innerHTML = arrayOfProductsToCompare.length;
	//alert(arrayOfProductsToCompare);

	if (arrayOfProductsToCompare.length > 1 && arrayOfProductsToCompare.length <= 4) {
		var htmlStr = "<a href=\"/profile/compare.aspx?ids=";
		htmlStr = htmlStr + arrayOfProductsToCompare;
		if (newQS != "") {
			htmlStr = htmlStr + "&" + newQS;
		}

		htmlStr = htmlStr + "\"><img src=\"/assets/images/interface/compare_small.png\" onmouseover=\"this.src='/assets/images/interface/compare_small_over.png'\" onmouseout=\"this.src='/assets/images/interface/compare_small.png'\" alt=\"Compare\" title=\"Compare\" /></a>";
	} else {
		var htmlStr = "<img src=\"/assets/images/interface/compare_small_over.png\" alt=\"You need to select at least 2 items to compare.\" title=\"You need to select at least 2 items to compare.\" />";
	}

	document.getElementById("compareAction").innerHTML = htmlStr;
}


/* -------------------------------- PROFILE FUNCTIONS ---------------- */

function hideAllEditButtons() {
	hide("pLoginEdit");
	hide("pProfileEdit");
	hide("pSubscriptionsEdit");
	hide("pTellUsEdit");
}

function showAllEditButtons() {
	show("pLoginEdit");
	show("pProfileEdit");
	show("pSubscriptionsEdit");
	show("pTellUsEdit");
}

function formElementsToggle(argElementsArray, argType) {
	// if the argType is Text, then the Text items are hidden and the Input are shown
	// if the the argType is the opposite, then the opposite happens
	if (argType == "Text") {
		for (i = 0; i < argElementsArray.length; i++) {
			hide(argElementsArray[i] + "Text");
			show(argElementsArray[i] + "Input");
		}
	} else {
		for (i = 0; i < argElementsArray.length; i++) {
			hide(argElementsArray[i] + "Input");
			show(argElementsArray[i] + "Text");
		}
	}
}

function turnOnForm(argElementId) {
	document.getElementById(argElementId).style.backgroundColor = "#f7f4ed";
	hideAllEditButtons();

	switch (argElementId) {
		case "pLogin":
			hide("pLoginEdit");
			show("pLoginButtons");

			formElementsToggle(pLoginElements, "Text")
			break;
		case "pProfile":
			hide("pProfileEdit");
			show("pProfileButtons");

			formElementsToggle(pProfileElements, "Text")
			break;
		case "pSubscriptions":
			hide("pSubscriptionsEdit");
			show("pSubscriptionsButtons");

			formElementsToggle(pSubscriptionsElements, "Text")
			break;
		case "pTellUs":
			hide("pTellUsEdit");
			show("pTellUsButtons");

			hide("pTellUsText");
			show("pTellUsForm");

			//formElementsToggle(pTellUsElements, "Text")
			break;
	}
}

function turnOffForm(argElementId, formElementsArray) {
	document.getElementById(argElementId).style.backgroundColor = "transparent";

	switch (argElementId) {
		case "pLogin":
			hide("pLoginButtons");
			show("pLoginEdit");

			formElementsToggle(pLoginElements, "Input")
			break;
		case "pProfile":
			hide("pProfileButtons");
			show("pProfileEdit");

			formElementsToggle(pProfileElements, "Input")
			break;
		case "pSubscriptions":
			hide("pSubscriptionsButtons");
			show("pSubscriptionsEdit");

			formElementsToggle(pSubscriptionsElements, "Input")
			break;
		case "pTellUs":
			hide("pTellUsButtons");
			show("pTellUsEdit");

			hide("pTellUsForm");
			show("pTellUsText");

			//formElementsToggle(pTellUsElements, "Input")
			break;
	}

	showAllEditButtons();
}

function validateSurvey() {
	var inputArry = document.getElementsByTagName("input");
	for (var inputLoop = 0; inputLoop < inputArry.length; inputLoop++) {
		inpObj = document.getElementById(inputArry[inputLoop].id);
		if (inpObj.parentNode.tagName.toLowerCase() == "div") {
			if (inpObj.parentNode.style.display == "none") {
				switch (inpObj.type.toLowerCase()) {
					case "radio":
						inpObj.checked = false;
						break;
					case "checkbox":
						inpObj.checked = false;
						break;
					case "text":
						inpObj.value = "";
						//alert(inpObj.parentNode.parentNode.style.display);
						break;
					default:
						//alert(inpObj.type.toLowerCase());
				}
			}
		}
	}

	inputArry = document.getElementsByTagName("select");
	for (var inputLoop = 0; inputLoop < inputArry.length; inputLoop++) {
		inpObj = document.getElementById(inputArry[inputLoop].id);
		if (inpObj.parentNode.tagName.toLowerCase() == "div") {
			if (inpObj.parentNode.style.display == "none") {
				inpObj.selectedIndex = 0;
			}
		}
	}
	return true;
	//document.surveyForm.submit();
}

function validateSurveyForElearn(argSubmitButton, argButtonUse) {
	var formIsValid = false;
	var inputArry = document.getElementsByTagName("input");
	var tInputName = '';

	for (var inputLoop = 0; inputLoop < inputArry.length; inputLoop++) {
		inpObj = document.getElementById(inputArry[inputLoop].id);
		tInputName = $('#' + inputArry[inputLoop].id).attr('name');

		if (inpObj.parentNode.tagName.toLowerCase() == "div") {
			if (inpObj.parentNode.style.display == "none") {
				switch (inpObj.type.toLowerCase()) {
					case "radio":
						inpObj.checked = false;
						break;
					case "checkbox":
						inpObj.checked = false;
						break;
					case "text":
						inpObj.value = "";
						//alert(inpObj.parentNode.parentNode.style.display);
						break;
					default:
						//alert(inpObj.type.toLowerCase());
				}
			} else {
				if (inpObj.type.toLowerCase() == "radio") {
					if (inpObj.checked == true && (tInputName.charAt(0) == "Q" || tInputName.charAt(0) == "A")) {
						formIsValid = true;
						//formIsValid = inpObj.checked;
						//formIsValid += ($('#'+inputArry[inputLoop].id).attr('name'));
					}
				}
			}
		}
	}

	inputArry = document.getElementsByTagName("select");
	for (var inputLoop = 0; inputLoop < inputArry.length; inputLoop++) {
		inpObj = document.getElementById(inputArry[inputLoop].id);
		tInputName = $('#' + inputArry[inputLoop].id).attr('name');

		if (inpObj.parentNode.tagName.toLowerCase() == "div") {
			if (inpObj.parentNode.style.display == "none") {
				inpObj.selectedIndex = 0;
			} else {
				if ((inpObj.selectedIndex == 0) && (tInputName.charAt(0) == 'Q' || tInputName.charAt(0) == 'A')) {
					formIsValid = false;
				}


				//formIsValid = (inpObj.selectedIndex != 0);
			}
		}
	}

	if (!formIsValid) {
		$('#elearnSurveyValidator').css('display', 'block');
	} else {
		$('#elearnSurveyValidator').css('display', 'none');
	}

	if (formIsValid) {
		if (argButtonUse == 'register') {
			WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(argSubmitButton, "", true, "eregForm", "", false, false));
		} else {
			return true;
		}
	} else {
		return false;
	}
}

function qDDChange(question, answerStr) {
	var currentValue = document.getElementById("QS" + question + "").value
	var answerArray = new Array()
	answerArray = answerStr.split(",")
	for (var anLoop = 0; anLoop < answerArray.length; anLoop++) {
		sdStr = "surveyD" + answerArray[anLoop]
		sdObj = document.getElementById(sdStr)
		divStyle = "none"
		if (answerArray[anLoop] == currentValue) {
			divStyle = "block"
		}
		if (sdObj != null) {
			sdObj.style.display = divStyle
		}
	}
}

function qRadioCboxChange(eType, question, answerStr) {
	var answerArray = new Array()
	answerArray = answerStr.split(",")
	for (var anLoop = 0; anLoop < answerArray.length; anLoop++) {
		if (eType == "R") {
			eleStr = "QR" + answerArray[anLoop] + ""
		}
		if (eType == "C") {
			eleStr = "AC" + answerArray[anLoop] + ""
		}
		eleObj = document.getElementById(eleStr)

		divStr = "surveyD" + answerArray[anLoop]
		divObj = document.getElementById(divStr)

		divStyle = "none"
		if (eleObj.checked) {
			divStyle = "block"
		}
		if (divObj != null) {
			divObj.style.display = divStyle
		}
	}
}
