﻿


/* -----------------------------  Dealer Locator ----------------------------------------- */

function handleViewMap(argDealerID, argTargLat, argTargLng)
{
	document.getElementById("dealerMap" + currentDealerID).style.display = "none";
	document.getElementById("dealerLoc" + currentDealerID).className = "";
	
	document.getElementById("dealerMap" + argDealerID).style.display = "block";
	document.getElementById("dealerLoc" + argDealerID).className = "active";

	displayPreferredMap(("dealerMap" + argDealerID), argTargLat, argTargLng);
	
	location.href = "#dealerLoc" + argDealerID + "a";
	currentDealerID = argDealerID;
}

var currentDealerID = '0';
function displayPreferredMap(argMapElement, argTargLat, argTargLng)
{
	if (GBrowserIsCompatible())
	{
		var prefMap = new GMap2(document.getElementById(argMapElement));
		prefMap.setCenter(new GLatLng(argTargLat, argTargLng), 15);
		
		var prefMarkCenter = prefMap.getCenter();
		var prefMarker = new GMarker(prefMarkCenter);
		prefMap.addOverlay(prefMarker);
		
		prefMap.addControl(new GMapTypeControl());
		prefMap.addControl(new GSmallMapControl());
	};
};

window.onunload = function()
{
	GUnload();
};



/* -----------------------------  PRODUCT RELATED  ----------------------------------------- */

function swapMainCollectionImage(argMainID, argThumbID)
{
	document.getElementById(argMainID).src = document.getElementById(argThumbID).getAttribute("asset");
}

function openSearchAreaFromLink() { if ($(".largeSearchBtn").attr("src") != "/assets/images/searchBtn_over.gif") { $("#searchArea").fadeIn("fast"); $(".largeSearchBtn").attr("src", "/assets/images/searchBtn_over.gif"); $("#searchForm .searchWordsText").focus(); } };
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); } }



/* -----------------------------  MY PROFILE  ----------------------------------------- */

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 = "#fcfcfc";
	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
		}
	}
}






/* -----------------------------  Modal Stuff??  ----------------------------------------- */



var MODAL_MIN_FROM_TOP = 35;
function PositionModal(argModalId)
{
	if ($(window).height() < document.getElementById(argModalId).clientHeight)
	{
		document.getElementById('overlayContentDiv').style.height = ($(window).height() - 50) + "px";
		document.getElementById('overlayContentDiv').style.overflow = "auto";
	}

	newPosition = Math.round(($(window).height() - document.getElementById(argModalId).clientHeight) / 2);

	if (newPosition < MODAL_MIN_FROM_TOP)
	{
		newPosition = MODAL_MIN_FROM_TOP;
	}

	if ($.browser.msie && (parseInt($.browser.version) < 7)) { }
	else
	{
		document.getElementById(argModalId).style.top = newPosition + "px";
	}
}



/*
* jqModal - Minimalist Modaling with jQuery
*   (http://dev.iceburg.net/jquery/jqModal/)
*
* Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
* 
* $Version: 07/06/2008 +r13
*/
(function($)
{
	$.fn.jqm = function(o)
	{
		var p = {
			overlay: 63,
			overlayClass: 'jqmOverlay',
			closeClass: 'jqmClose',
			trigger: '.jqModal',
			ajax: F,
			ajaxText: '',
			target: F,
			modal: F,
			toTop: F,
			onShow: F,
			onHide: F,
			onLoad: F
		};
		return this.each(function()
		{
			if (this._jqm) return H[this._jqm].c = $.extend({}, H[this._jqm].c, o); s++; this._jqm = s;
			H[s] = { c: $.extend(p, $.jqm.params, o), a: F, w: $(this).addClass('jqmID' + s), s: s };
			if (p.trigger) $(this).jqmAddTrigger(p.trigger);
		});
	};

	$.fn.jqmAddClose = function(e) { return hs(this, e, 'jqmHide'); };
	$.fn.jqmAddTrigger = function(e) { return hs(this, e, 'jqmShow'); };
	$.fn.jqmShow = function(t) { return this.each(function() { $.jqm.open(this._jqm, t); }); };
	$.fn.jqmHide = function(t) { return this.each(function() { $.jqm.close(this._jqm, t) }); };

	$.jqm = {
		hash: {},
		open: function(s, t)
		{
			var h = H[s], c = h.c, cc = '.' + c.closeClass, z = (parseInt(h.w.css('z-index'))), z = (z > 0) ? z : 3000, o = $('<div></div>').css({ height: '100%', width: '100%', position: 'fixed', left: 0, top: 0, 'z-index': z - 1, opacity: c.overlay / 100 }); if (h.a) return F; h.t = t; h.a = true; h.w.css('z-index', z);
			if (c.modal) { if (!A[0]) L('bind'); A.push(s); }
			else if (c.overlay > 0) h.w.jqmAddClose(o);
			else o = F;

			h.o = (o) ? o.addClass(c.overlayClass).prependTo('body') : F;
			if (ie6) { $('html,body').css({ height: '100%', width: '100%' }); if (o) { o = o.css({ position: 'absolute' })[0]; for (var y in { Top: 1, Left: 1 }) o.style.setExpression(y.toLowerCase(), "(_=(document.documentElement.scroll" + y + " || document.body.scroll" + y + "))+'px'"); } }

			if (c.ajax)
			{
				var r = c.target || h.w, u = c.ajax, r = (typeof r == 'string') ? $(r, h.w) : $(r), u = (u.substr(0, 1) == '@') ? $(t).attr(u.substring(1)) : u;
				r.html(c.ajaxText).load(u, function() { if (c.onLoad) c.onLoad.call(this, h); if (cc) h.w.jqmAddClose($(cc, h.w)); e(h); });
			}
			else if (cc) h.w.jqmAddClose($(cc, h.w));

			if (c.toTop && h.o) h.w.before('<span id="jqmP' + h.w[0]._jqm + '"></span>').insertAfter(h.o);
			(c.onShow) ? c.onShow(h) : h.w.show(); e(h); return F;
		},
		close: function(s)
		{
			var h = H[s]; if (!h.a) return F; h.a = F;
			if (A[0]) { A.pop(); if (!A[0]) L('unbind'); }
			if (h.c.toTop && h.o) $('#jqmP' + h.w[0]._jqm).after(h.w).remove();
			if (h.c.onHide) h.c.onHide(h); else { h.w.hide(); if (h.o) h.o.remove(); } return F;
		},
		params: {}
	};
	var s = 0, H = $.jqm.hash, A = [], ie6 = $.browser.msie && ($.browser.version == "6.0"), F = false,
i = $('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({ opacity: 0 }),
e = function(h) { if (ie6) if (h.o) h.o.html('<p style="width:100%;height:100%"/>').prepend(i); else if (!$('iframe.jqm', h.w)[0]) h.w.prepend(i); f(h); },
f = function(h) { /*try{$(':input:visible',h.w)[0].focus();}catch(_){}*/ },
L = function(t) { $()[t]("keypress", m)[t]("keydown", m)[t]("mousedown", m); },
m = function(e) { var h = H[A[A.length - 1]], r = (!$(e.target).parents('.jqmID' + h.s)[0]); if (r) f(h); return !r; },
hs = function(w, t, c)
{
	return w.each(function()
	{
		var s = this._jqm; $(t).each(function()
		{
			if (!this[c]) { this[c] = []; $(this).click(function() { for (var i in { jqmShow: 1, jqmHide: 1 }) for (var s in this[i]) if (H[this[i][s]]) H[this[i][s]].w[i](this); return F; }); } this[c].push(s);
		});
	});
};
})(jQuery);



/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* $LastChangedDate: 2007-06-19 20:25:28 -0500 (Tue, 19 Jun 2007) $
* $Rev: 2111 $
*
* Version 2.1
*/
(function($) { $.fn.bgIframe = $.fn.bgiframe = function(s) { if ($.browser.msie && parseInt($.browser.version) <= 6) { s = $.extend({ top: 'auto', left: 'auto', width: 'auto', height: 'auto', opacity: true, src: 'javascript:false;' }, s || {}); var prop = function(n) { return n && n.constructor == Number ? n + 'px' : n; }, html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="' + s.src + '"' + 'style="display:block;position:absolute;z-index:-1;' + (s.opacity !== false ? 'filter:Alpha(Opacity=\'0\');' : '') + 'top:' + (s.top == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')' : prop(s.top)) + ';' + 'left:' + (s.left == 'auto' ? 'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')' : prop(s.left)) + ';' + 'width:' + (s.width == 'auto' ? 'expression(this.parentNode.offsetWidth+\'px\')' : prop(s.width)) + ';' + 'height:' + (s.height == 'auto' ? 'expression(this.parentNode.offsetHeight+\'px\')' : prop(s.height)) + ';' + '"/>'; return this.each(function() { if ($('> iframe.bgiframe', this).length == 0) this.insertBefore(document.createElement(html), this.firstChild); }); } return this; }; if (!$.browser.version) $.browser.version = navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1]; })(jQuery);


/**
* jQuery-Plugin "preloadCssImages"
* by Scott Jehl, scott@filamentgroup.com
* http://www.filamentgroup.com
* reference article: http://www.filamentgroup.com/lab/update_automatically_preload_images_from_css_with_jquery/
* demo page: http://www.filamentgroup.com/examples/preloadImages/index_v2.php
* 
* Copyright (c) 2008 Filament Group, Inc
* Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
*
* Version: 5.0, 10.31.2008
* Changelog:
* 	02.20.2008 initial Version 1.0
*    06.04.2008 Version 2.0 : removed need for any passed arguments. Images load from any and all directories.
*    06.21.2008 Version 3.0 : Added options for loading status. Fixed IE abs image path bug (thanks Sam Pohlenz).
*    07.24.2008 Version 4.0 : Added support for @imported CSS (credit: http://marcarea.com/). Fixed support in Opera as well. 
*    10.31.2008 Version: 5.0 : Many feature and performance enhancements from trixta
* --------------------------------------------------------------------
*/

; jQuery.preloadCssImages = function(settings)
{
	settings = jQuery.extend({
		statusTextEl: null,
		statusBarEl: null,
		errorDelay: 999, // handles 404-Errors in IE
		simultaneousCacheLoading: 2
	}, settings);
	var allImgs = [],
		loaded = 0,
		imgUrls = [],
		thisSheetRules,
		errorTimer;

	function onImgComplete()
	{
		clearTimeout(errorTimer);
		if (imgUrls && imgUrls.length && imgUrls[loaded])
		{
			loaded++;
			if (settings.statusTextEl)
			{
				var nowloading = (imgUrls[loaded]) ?
					'Now Loading: <span>' + imgUrls[loaded].split('/')[imgUrls[loaded].split('/').length - 1] :
					'Loading complete'; // wrong status-text bug fixed
				jQuery(settings.statusTextEl).html('<span class="numLoaded">' + loaded + '</span> of <span class="numTotal">' + imgUrls.length + '</span> loaded (<span class="percentLoaded">' + (loaded / imgUrls.length * 100).toFixed(0) + '%</span>) <span class="currentImg">' + nowloading + '</span></span>');
			}
			if (settings.statusBarEl)
			{
				var barWidth = jQuery(settings.statusBarEl).width();
				jQuery(settings.statusBarEl).css('background-position', -(barWidth - (barWidth * loaded / imgUrls.length).toFixed(0)) + 'px 50%');
			}
			loadImgs();
		}
	}

	function loadImgs()
	{
		//only load 1 image at the same time / most browsers can only handle 2 http requests, 1 should remain for user-interaction (Ajax, other images, normal page requests...)
		// otherwise set simultaneousCacheLoading to a higher number for simultaneous downloads
		if (imgUrls && imgUrls.length && imgUrls[loaded])
		{
			var img = new Image(); //new img obj
			img.src = imgUrls[loaded]; //set src either absolute or rel to css dir
			if (!img.complete)
			{
				jQuery(img).bind('error load onreadystatechange', onImgComplete);
			} else
			{
				onImgComplete();
			}
			errorTimer = setTimeout(onImgComplete, settings.errorDelay); // handles 404-Errors in IE
		}
	}

	function parseCSS(sheets, urls)
	{
		var w3cImport = false,
			imported = [],
			importedSrc = [],
			baseURL;
		var sheetIndex = sheets.length;
		while (sheetIndex--)
		{//loop through each stylesheet

			var cssPile = ''; //create large string of all css rules in sheet

			if (urls && urls[sheetIndex])
			{
				baseURL = urls[sheetIndex];
			} else
			{
				var csshref = (sheets[sheetIndex].href) ? sheets[sheetIndex].href : 'window.location.href';
				var baseURLarr = csshref.split('/'); //split href at / to make array
				baseURLarr.pop(); //remove file path from baseURL array
				baseURL = baseURLarr.join('/'); //create base url for the images in this sheet (css file's dir)
				if (baseURL)
				{
					baseURL += '/'; //tack on a / if needed
				}
			}
			if (sheets[sheetIndex].cssRules || sheets[sheetIndex].rules)
			{
				thisSheetRules = (sheets[sheetIndex].cssRules) ? //->>> http://www.quirksmode.org/dom/w3c_css.html
					sheets[sheetIndex].cssRules : //w3
					sheets[sheetIndex].rules; //ie 
				var ruleIndex = thisSheetRules.length;
				while (ruleIndex--)
				{
					if (thisSheetRules[ruleIndex].style && thisSheetRules[ruleIndex].style.cssText)
					{
						var text = thisSheetRules[ruleIndex].style.cssText;
						if (text.toLowerCase().indexOf('url') != -1)
						{ // only add rules to the string if you can assume, to find an image, speed improvement
							cssPile += text; // thisSheetRules[ruleIndex].style.cssText instead of thisSheetRules[ruleIndex].cssText is a huge speed improvement
						}
					} else if (thisSheetRules[ruleIndex].styleSheet)
					{
						imported.push(thisSheetRules[ruleIndex].styleSheet);
						w3cImport = true;
					}

				}
			}
			//parse cssPile for image urls
			var tmpImage = cssPile.match(/[^\("]+\.(gif|jpg|jpeg|png)/g); //reg ex to get a string of between a "(" and a ".filename" / '"' for opera-bugfix
			if (tmpImage)
			{
				var i = tmpImage.length;
				while (i--)
				{ // handle baseUrl here for multiple stylesheets in different folders bug
					var imgSrc = (tmpImage[i].charAt(0) == '/' || tmpImage[i].match('://')) ? // protocol-bug fixed
						tmpImage[i] :
						baseURL + tmpImage[i];

					if (jQuery.inArray(imgSrc, imgUrls) == -1)
					{
						imgUrls.push(imgSrc);
					}
				}
			}

			if (!w3cImport && sheets[sheetIndex].imports && sheets[sheetIndex].imports.length)
			{
				for (var iImport = 0, importLen = sheets[sheetIndex].imports.length; iImport < importLen; iImport++)
				{
					var iHref = sheets[sheetIndex].imports[iImport].href;
					iHref = iHref.split('/');
					iHref.pop();
					iHref = iHref.join('/');
					if (iHref)
					{
						iHref += '/'; //tack on a / if needed
					}
					var iSrc = (iHref.charAt(0) == '/' || iHref.match('://')) ? // protocol-bug fixed
						iHref :
						baseURL + iHref;

					importedSrc.push(iSrc);
					imported.push(sheets[sheetIndex].imports[iImport]);
				}


			}
		} //loop
		if (imported.length)
		{
			parseCSS(imported, importedSrc);
			return false;
		}
		var downloads = settings.simultaneousCacheLoading;
		while (downloads--)
		{
			setTimeout(loadImgs, downloads);
		}
	}
	parseCSS(document.styleSheets);
	return imgUrls;
};
