﻿// JScript File
var dynamicZoomURL = "";
function ChangeImage( imgID, imgsrc, imgwidth, imgheight )
{
   if( document.getElementById( imgID ) ){ 
	   (document.getElementById(imgID)).src = imgsrc; 
	   (document.getElementById(imgID)).width = imgwidth; 
	   (document.getElementById(imgID)).height = imgheight; }
}
function ChangeImageSrc( imgObj, imgsrc ){imgObj.src = imgsrc;}
function ChangeImageOnCLick( imgID, onclickStr ){ if( document.getElementById( imgID ) ){ (document.getElementById( imgID )).onclick = onclickStr; } }
function SwapProdImg(  imgID, imgsrc, zoomurl, imgwidth, imgheight  )
{
   if( document.getElementById( imgID ) ){ 
	   (document.getElementById(imgID)).src = imgsrc; 
	   (document.getElementById(imgID)).width = imgwidth; 
	   (document.getElementById(imgID)).height = imgheight; 
	   dynamicZoomURL = zoomurl;}  
}
function ZoomImage( imgurl ){window.open( imgurl,'_Zoom','menubar=no,height=500,width=450,scrollbars=yes,resizable=yes,top=10,left=10');}
function ProductImageZoom( zoomURL ){
   if( dynamicZoomURL.length == 0 ){window.open( zoomURL, '_Zoom','menubar=no,height=550,width=450,scrollbars=yes,resizable=yes,top=10,left=10');}
   else{window.open( dynamicZoomURL, '_Zoom','menubar=no,height=550,width=450,scrollbars=yes,resizable=yes,top=10,left=10');}}
function clearTxtBox( elemObj ){if (elemObj.defaultValue == elemObj.value) {elemObj.value = ""}}
function HelpLoad( zoomURL, width, height ){ window.open( zoomURL, '_Zoom','menubar=no,height=' + height + ',width=' + width + ',scrollbars=yes,resizable=yes,top=10,left=10');   }
function HideDiv( divID ){if( document.getElementById(divID) ){(document.getElementById(divID)).style.display = "none";}}
function ShowDiv( divID ){if( document.getElementById(divID) ){(document.getElementById(divID)).style.display = "";}}
function ShowDivImgZoom( divID, imgID, imgsrc ){if( document.getElementById(divID) ){(document.getElementById(divID)).style.display = "";if( document.getElementById( imgID ) ){ (document.getElementById(imgID)).src = imgsrc; }}}
$(document).ready(function() {
	$('.hover').hover(
		function() {
			$(this).attr('src', $(this).attr('src').replace('.jpg', '_hover.jpg').replace('.gif', '_hover.gif'));
		},
		function() {
			$(this).attr('src', $(this).attr('src').replace('_hover.jpg', '.jpg').replace('_hover.gif', '.gif'));
		}
	);
	$('.tbLabel, .emailsu').focus(function(){
		if ($(this).val()==$(this).attr("title"))
		{
			$(this).val('').css('color', '#000');
		}
	}).blur(function(){
		if ($(this).val()=='')
		{
			$(this).val($(this).attr("title")).css('color', '#666');
		}
	});
	$('.clickPrice').click(
		function() {
			$(this).hide();
			$('.hideprice').show();
		}
	);	
	$('#Searchtb').focus(function(){
		if ($(this).val()=="Search by brand, club & more.")
		{
			$(this).val('').css('color', '#000');
		}
	}).blur(function(){
		if ($(this).val()=='')
		{
			$(this).val("Search by brand, club & more.").css('color', '#666');
		}
	}).keydown(function(e) {
		if(e.keyCode == 13) {
			doSearch();
			return false;
		}
	});
	$('.searchSubmit').click(doSearch);
	
	$('#promoBanner').click(function () 
	{
		$("#promoHideCntnt").slideToggle(200);
   });

});
function doSearch()
{
	if( $('#Searchtb').val() != "Search by brand, club & more." )
	{
		window.location=BaseUrl+"/search.aspx?searchstr=" + $('#Searchtb').val();
	}
}
//Shoe Size Selector
var sizeList = readCookie("ShoeSizeList");
sizeList = (sizeList==null)?'':sizeList;
var widthList = readCookie("ShoeWidthList");
widthList = (widthList==null)?'':widthList;
$(document).ready(function() {
	$('#WidthSelect div, #SizeSelect div, #SizeSelectEcco div').hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		}
	);
	$('#SizeSelect div').click(
		function() {
			if ($(this).hasClass("disabled"))
			{
				return;
			}
			$('#ShoeCategoryDisplay').fadeTo(250,.01);
			var sizes = this.id.split('-')[1].split('_');
			for (var x=0; x<sizes.length; x++)
			{
				if ($(this).hasClass("active"))
				{
					sizeList = sizeList.replace(sizes[x]+',', '');
				}
				else
				{
					sizeList += sizes[x]+',';
				}
			}
			$(this).toggleClass("active");
			$.get(BaseUrl+"/shoesload.aspx?"+$('#QSParamList').val(), {szl:sizeList,w:widthList,gt:$('#GalleryTitle').text()}, shoegetCallback);
			createCookie("ShoeSizeList",sizeList,30);
		}
	);
	$('#WidthSelect div').click(
		function() {
			if ($(this).hasClass("disabled"))
			{
				return;
			}
			$('#ShoeCategoryDisplay').fadeTo(250,.01);
			if ($(this).hasClass("active"))
			{
				widthList = widthList.replace(this.id.split('-')[1]+',', '');
			}
			else
			{
				widthList += this.id.split('-')[1]+',';
			}
			$(this).toggleClass("active");
			$.get(BaseUrl+"/shoesload.aspx?"+$('#QSParamList').val(), {sz:sizeList,w:widthList,gt:$('#GalleryTitle').text()}, shoegetCallback);
			createCookie("ShoeWidthList",widthList,30);
		}
	);
	$('.pagenum').click(pagenumClick);
});
function shoegetCallback(data)
{
	$('#ShoeCategoryDisplay').html(data);
	$('#ShoeCategoryDisplay').fadeTo(250,1);
	$('.pagenum').click(pagenumClick);
}
function pagenumClick()
{
	$('#ShoeCategoryDisplay').fadeTo(250,.01);
	$.get($(this).attr("href").replace("shoes.aspx", "shoesload.aspx"), shoegetCallback);
	return false;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; domain=shop.pgatoursuperstore.com; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}


