var SHOPZILLA = YAHOO;

SHOPZILLA.util.Dom.userAgent = navigator.userAgent.toLowerCase(),
SHOPZILLA.util.Dom.isOpera = (SHOPZILLA.util.Dom.userAgent.indexOf('opera') > -1),
SHOPZILLA.util.Dom.isSafari = (SHOPZILLA.util.Dom.userAgent.indexOf('safari') > -1),
SHOPZILLA.util.Dom.isGecko = (!SHOPZILLA.util.Dom.isOpera && !SHOPZILLA.util.Dom.isSafari && SHOPZILLA.util.Dom.userAgent.indexOf('gecko') > -1),
SHOPZILLA.util.Dom.isIE = (!SHOPZILLA.util.Dom.isOpera && SHOPZILLA.util.Dom.userAgent.indexOf('msie') > -1); 
SHOPZILLA.util.Dom.isMac = (navigator.appVersion.toLowerCase().indexOf("macintosh")!=-1);
SHOPZILLA.util.Dom.appVersion = navigator.appVersion.toLowerCase();

/**
 * SHOPZILLA.widget.InternationalRedirector object
 */

SHOPZILLA.widget.InternationalRedirector = function(oConfigs) {
	if(oConfigs && (oConfigs.constructor == Object)) {
		for(var sConfig in oConfigs) {
			if(sConfig) {
				this[sConfig] = oConfigs[sConfig];
			}
		}
	}
};

SHOPZILLA.widget.InternationalRedirector.prototype.init = function() {
	if (this.active) {
		this.open();
/*
		var objLayer = document.getElementById('redirect_popup');
		var objClose = document.createElement('div');
		objLayer.appendChild(objClose);
		objClose.innerHTML = 'Close';
		objClose.style.cursor = 'pointer';
		objClose.onclick = function() {
			SHOPZILLA.widget.InternationalRedirector.prototype.close();
		};
*/
	}
};

SHOPZILLA.widget.InternationalRedirector.prototype.open = function() {
	this.redirectForeignIP();
	this.openOverlay();
};

SHOPZILLA.widget.InternationalRedirector.prototype.close = function() {
	this.closeRedirectPopup();
	this.closeOverlay();
};

SHOPZILLA.widget.InternationalRedirector.prototype.redirectForeignIP = function() {
	var width = parseInt(document.getElementById('redirect_popup').style.width);
	var height = parseInt(document.getElementById('redirect_popup').style.height);
	document.getElementById('coversheet').style.width = width;
	document.getElementById('coversheet').style.height = height;
	doc_obj = SHOPZILLA.util.Dom.isSafari ? document : document.body;

	if(SHOPZILLA.util.Dom.isIE && !SHOPZILLA.util.Dom.isMac) {
		document.getElementById('coversheet').style.left = ((doc_obj.clientWidth - width) / 2);
		document.getElementById('coversheet').style.top = ((doc_obj.clientHeight - height) / 2);
		document.getElementById('coversheet').style.display = 'block';
		document.getElementById('coversheet').style.visibility = 'visible';
	}
	document.getElementById('redirect_popup').style.visibility = 'visible';
	document.getElementById('redirect_popup').style.left = ((doc_obj.clientWidth - width) / 2);
	document.getElementById('redirect_popup').style.top = ((doc_obj.clientHeight - height) / 2);
	this.tryToPreventScrolling(this);
};

SHOPZILLA.widget.InternationalRedirector.prototype.closeRedirectPopup = function() {
	if(SHOPZILLA.util.Dom.isIE && !SHOPZILLA.util.Dom.isMac) {
		document.getElementById('coversheet').style.display = 'none';
		document.getElementById('coversheet').style.visibility = 'hidden';
	}
	document.getElementById('redirect_popup').style.visibility = 'hidden';
};

SHOPZILLA.widget.InternationalRedirector.prototype.tryToPreventScrolling = function(obj) {
	window.scrollTo(0,obj.topPos);
	if( obj.isVisible() ) {
		setTimeout( function() { obj.tryToPreventScrolling(obj); }, 150);
	}
};

SHOPZILLA.widget.InternationalRedirector.prototype.getScrollVertical = function() {
	var position
	if (window.innerHeight)	{
		position = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		position = document.documentElement.scrollTop;
	} else if (document.body) {
		position = document.body.scrollTop;
	}
	return position;
};

SHOPZILLA.widget.InternationalRedirector.prototype.openOverlay = function() {
	document.getElementById('overlay').style.display = 'block';
};

SHOPZILLA.widget.InternationalRedirector.prototype.closeOverlay = function() {
	document.getElementById('overlay').style.display = 'none';
};

SHOPZILLA.widget.InternationalRedirector.prototype.isVisible = function() {
	if (document.getElementById('redirect_popup')) {
		return document.getElementById('redirect_popup').style.visibility == 'visible';
	} else {
		return false;
	}
};
SHOPZILLA.widget.InternationalRedirector.prototype.active = false;

SHOPZILLA.widget.InternationalRedirector.prototype.topPos = SHOPZILLA.widget.InternationalRedirector.prototype.getScrollVertical();

/**
 * SHOPZILLA.widget.RightNav object
 */

SHOPZILLA.widget.RightNav = function(oConfigs) {
	if(oConfigs && (oConfigs.constructor == Object)) {
		for(var sConfig in oConfigs) {
			if(sConfig) {
				this[sConfig] = oConfigs[sConfig];
			}
		}
	}
};

SHOPZILLA.widget.RightNav.prototype.init = function() {
	this.obj = document.getElementById('RightNav');
	if (this.obj) {
		this.items = this.obj.getElementsByTagName('li');
		this.cacheImages();
		for (i = 0; i < this.items.length; i++) {
			this.items[i].onmouseover = function() {
				this.className = 'over';
			};
			this.items[i].onmouseout = function() {
				this.className = '';
			};
			this.items[i].onclick = function() {
				document.location.href = this.getElementsByTagName('a')[0].href;
			};
		}
	}
};

SHOPZILLA.widget.RightNav.prototype.cacheImages = function() {
	this.images = new Array();
	this.images[this.images.length] = new Image(240,90);
	this.images[this.images.length] = new Image(240,90);
	this.images[this.images.length] = new Image(240,90);
	this.images[0].src = 'http://img.shopzilla.com/sz/us/testing/1000304/images/tabs/ff7200.gif';
	this.images[1].src = 'http://img.shopzilla.com/sz/us/testing/1000304/images/tabs/00cc00.gif';
	this.images[2].src = 'http://img.shopzilla.com/sz/us/testing/1000304/images/tabs/ffffff.gif';
};

/**
 * SHOPZILLA.widget.Page object
 */

SHOPZILLA.widget.Page = function(oConfigs) {
	if(oConfigs && (oConfigs.constructor == Object)) {
		for(var sConfig in oConfigs) {
			if(sConfig) {
				this[sConfig] = oConfigs[sConfig];
			}
		}
	}
};

SHOPZILLA.widget.Page.prototype.init = function() {
	this.Dom = SHOPZILLA.util.Dom;
	this.bookmarkKey = "D";
	this.bookmarkKeyModifier = "Ctrl";
	if (this.Dom.isOpera) { this.bookmarkKey = "T"; }
	if (this.Dom.isMac) { this.bookmarkKeyModifier = "Command"; }
	this.bookmarkKeyCombination = this.bookmarkKeyModifier+'-'+this.bookmarkKey;

	this.objForms = document.forms;
	for (i = 0; i < this.objForms.length; i++) {
		this.form = this.objForms[i];
		if (this.form.id == 'searchForm') {
			this.form.method = 'get';
			this.form.name = 'sf';
			this.form.onsubmit = function() {
				return myPage.switchAction(this);
			};
		}
	}

	if ((typeof(this.frameBusterActive) == 'boolean') && this.frameBusterActive) { this.checkForFrames(); };
	if ((typeof(this.frameBusterActive) == 'undefined')) { this.checkForFrames(); };
	myInternationalRedirector.init();
	this.setFocus();
	if (this.token == '2') { myRightNav.init(); };
};

SHOPZILLA.widget.Page.prototype.setFocus = function() {
	myObj = document.getElementById(this.focusElementId);
	if (this.focusActive && myObj) {
		myObj.focus();
	} else {
		return false;
	}
};

SHOPZILLA.widget.Page.prototype.checkForFrames = function() {
	if (top != self) top.location.href = self.location.href;
};

SHOPZILLA.widget.Page.prototype.bookmarkThisPage = function() {
	if ((this.Dom.isIE) && (parseInt(this.Dom.appVersion) >= 4) && (!this.Dom.isMac)) {
		window.external.AddFavorite(this.DLURL,this.DLDESC);
	} else {
		this.local_message = this.local_message.replace(/%keystroke%/g, this.bookmarkKeyCombination);
		this.local_message = this.local_message.replace(/&#xFC\;/g, 'ü');
		alert(this.local_message);
	}
	return false;
};

SHOPZILLA.widget.Page.prototype.switchAction = function(formObj) {
	if (formObj.cat_id.value == "offers") {
		formObj.action = this.actions.offers;
		formObj.cat_id.value = 1;
	} else if (formObj.cat_id.value == "stores") {
		formObj.action = this.actions.stores;
		formObj.cat_id.value = 1;
	} else if (formObj.cat_id.value == "marketplace") {
		formObj.action = this.actions.marketplace;
		formObj.cat_id.value = 1;
	} else {
		formObj.action = this.actions.default_action;
		if (this.sfsk == 1) { this.appendNWYLF(formObj); }
	}
	return true;
};

SHOPZILLA.widget.Page.prototype.appendNWYLF = function(formObj) {
	if (formObj.keyword.value == this.currentKeyword) {
		var nwylf_element = document.createElement("input");
		nwylf_element.setAttribute("type", "hidden");
		nwylf_element.setAttribute("name", "nwylf");
		nwylf_element.setAttribute("value", "1");
		formObj.appendChild(nwylf_element)
	}
}

function openPopup(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function openPopup2(theURL,winName,features) {
	windowHandle =  window.open(theURL,winName,features);
	if (!windowHandle.opener)
		windowHandle.opener = self;
	windowHandle.focus ();
}

function refine_search (baseURL, kwURL) {
	var kw = document.getElementById('refine_search_form').refine_keyword.value;
	if (kw && kwURL) {
		var newURL = kwURL.replace('REFINE_REPLACE', kw);
		document.location.href = newURL;
	} else {
		document.location.href = baseURL;
	}
}

SHOPZILLA.widget.SponsoredLinks = function(oConfigs) {
	if(oConfigs && (oConfigs.constructor == Object)) {
		for(var sConfig in oConfigs) {
			if(sConfig) {
				this[sConfig] = oConfigs[sConfig];
			}
		}
	}
};

SHOPZILLA.widget.SponsoredLinks.prototype.init = function() {
	for (j = 0; j < this.SponsoredLinksArray.length; j++) {
		objSponsoredLinks = document.getElementById(this.SponsoredLinksArray[j]);
		SponsoredLinksArrayListItems = objSponsoredLinks.getElementsByTagName(mySponsoredLinks.HightlightTagName);
		for (i = 0; i < SponsoredLinksArrayListItems.length; i++) {
			SponsoredLinksArrayListItems[i].onmouseover = function() {
				this.className = mySponsoredLinks.HightlightClassName;
			}
			SponsoredLinksArrayListItems[i].onmouseout = function() {
				this.className = mySponsoredLinks.UnHightlightClassName;
			}
		}
	}
};

function show_more_searches(link) {
	document.getElementById('more_searches').style.display = 'inline';
	link.onclick = function () {};
}

/* NetPromoter BEGIN */

SHOPZILLA.widget.NetPromoterPopup = function(oConfigs) {
	if(oConfigs && (oConfigs.constructor == Object)) {
		for(var sConfig in oConfigs) {
			if(sConfig) {
				this[sConfig] = oConfigs[sConfig];
			}
		}
	}
};

SHOPZILLA.widget.NetPromoterPopup.prototype.init = function() {
	this.popUP = (window.name == "netPromoterPopUP");
	if (this.activatePopUp) {
		this.launchPopUp();
	}
}

SHOPZILLA.widget.NetPromoterPopup.prototype.launchPopUp = function() {
	mySessionCookie = SHOPZILLA.util.Cookie;
	if (!(mySessionCookie.get('net_promoter_pop_once'))) {
		this.openSurveyInvite();
	}
};

SHOPZILLA.widget.NetPromoterPopup.prototype.openSurveyInvite = function() {
	this.popupWin = window.open('/popup/netpromotersurvey','netPromoterPopUP', 'width='+this.PopUpWidth+',height='+this.PopUpHeight+',left=200,top=200');
	this.createSessionCookie('pop_once_per_session');
};


SHOPZILLA.widget.NetPromoterPopup.prototype.closePopUP = function(timeout) {
	setTimeout('window.close()',timeout);
};


SHOPZILLA.widget.NetPromoterPopup.prototype.noThanks = function() {
	this.createCookie('no_thank_you');
	if (this.popUP) {
		this.closePopUP(0);
	} else {
		this.closePopIN();
		this.toggleSelects('visible');
	}
	return false;
};

SHOPZILLA.widget.NetPromoterPopup.prototype.takeSurvey = function() {
	this.createCookie('took_survey');
	if (this.popUP) {
		this.closePopUP(100);
		if (window.opener) {
			window.opener.myNetPromoterPopup.openSurveyFromPopUp();
		} else {
			this.openSurveyFromPopUp();	
		}
		return false;
	} else {
		this.closePopIN();
		this.toggleSelects('visible');
		return true;
	}
};

SHOPZILLA.widget.NetPromoterPopup.prototype.openSurveyFromPopUp = function() {
	this.newWindow = window.open(this.SurveyURL);
};

SHOPZILLA.widget.NetPromoterPopup.prototype.openPrivacyPolicyFromPopUp = function() {
	this.newWindow = window.open(this.PrivacyPolicyURL);
};

SHOPZILLA.widget.NetPromoterPopup.prototype.showPrivacyPolicy = function() {
	if (this.popUP) {
		if (window.opener) {
			window.opener.myNetPromoterPopup.openPrivacyPolicyFromPopUp();
		} else {
			this.openPrivacyPolicyFromPopUp();	
		}
		return false;
	} else {
		return true;
	}
};

SHOPZILLA.widget.NetPromoterPopup.prototype.createCookie = function(value) {
	myCookie = SHOPZILLA.util.Cookie;
	myAttributes = {
		name:this.CookieName,
		expires:this.CookieExpires,
		path:this.CookiePath,
		domain:this.CookieDomain,
		value:value
	};
	myCookie.set(myAttributes);
};

SHOPZILLA.widget.NetPromoterPopup.prototype.createSessionCookie = function(value) {
	mySessionCookie = SHOPZILLA.util.Cookie;
	myAttributes = {
		name:this.SessionCookieName,
		expires:'',
		path:this.CookiePath,
		domain:this.CookieDomain,
		value:value
	};
	mySessionCookie.set(myAttributes);
};


/* NetPromoter END */

/* Browse Departments RollOver BEGIN */

SHOPZILLA.widget.BrowseDepartments = function(oConfigs) {
	if(oConfigs && (oConfigs.constructor == Object)) {
		for(var sConfig in oConfigs) {
			if(sConfig) {
				this[sConfig] = oConfigs[sConfig];
			}
		}
	}
};

SHOPZILLA.widget.BrowseDepartments.prototype.init = function() {
	this.toggleOff();
	this.myBrowsePod = document.getElementById('sbrowsePod1');
	this.myBrowseButton = document.getElementById('browseButton');
	this.myBrowsePodCloseButton = document.getElementById('browsePodCloseBox');

	if (this.myBrowsePod) {
		this.myBrowsePod.onmouseover = this.toggleOn;
		this.myBrowsePod.onmouseout = this.toggleOff;
	}
	
	if (this.myBrowseButton) {
		this.myBrowseButton.onclick = this.toggleOn;
	}
	
	if (this.myBrowsePodCloseButton) {
		this.myBrowsePodCloseButton.onclick = this.toggleOff;
	}
}

SHOPZILLA.widget.BrowseDepartments.prototype.toggleOff = function() {
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('sbrowsePod'+i)) {document.getElementById('sbrowsePod'+i).style.display='none';}
	}
	return false;
}

SHOPZILLA.widget.BrowseDepartments.prototype.toggleOn = function() {
	var d = document.getElementById('sbrowsePod1');
	myBrowseDepartments.toggleOff();
	if (d) {d.style.display='block';}
	return false;
}

/* function for Browse Departments RollOver */
	window.onload=bttn_browse;
	function bttn_browse(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('sbrowsePod'+i)) {document.getElementById('sbrowsePod'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
	}
/* END function for Browse Departments RollOver */

/* Browse Departments RollOver END */

/* BEGIN Cool Search 2.0 Scrolling Categories */

SHOPZILLA.widget.CoolSearch = function(oConfigs) {
	if(oConfigs && (oConfigs.constructor == Object)) {
		for(var sConfig in oConfigs) {
			if(sConfig) {
				this[sConfig] = oConfigs[sConfig];
			}
		}
	}
};

SHOPZILLA.widget.CoolSearch.prototype.init = function() {
	this.myPanel = document.getElementById(this.myPanelID);
	if (this.myPanel) {
		this.myPanel = new SHOPZILLA.util.Motion(this.myPanel, this.myPanelAttributes, 1, SHOPZILLA.util.Easing.easeOut);
		this.myPanel.setAttribute('width',this.totalItems*this.itemWidth,'px');
	
		this.myNextButton = document.getElementById(this.myNextButtonID);
		this.myPreviousButton = document.getElementById(this.myPreviousButtonID);

		if (this.totalNumberOfGroups > 1) {
			this.myNextButton.direction = -1;
			this.myNextButton.onmouseover = this.assignPointerCursor;
			this.myNextButton.onmouseout = this.assignDefaultCursor;
			this.myNextButton.onclick = this.moveItems;
			this.myNextButton.style.visibility = 'visible';

			this.myPreviousButton.direction = 1;
			this.myPreviousButton.onclick = this.moveItems;
		}
	
		this.myPanel.onStart.subscribe(myCoolSearch.reclculateAttributes);
		this.myPanel.onComplete.subscribe(myCoolSearch.setCurrentGroupShowing);
	}
	this.centerPagination();
};

SHOPZILLA.widget.CoolSearch.prototype.reclculateAttributes = function() {
	myCoolSearch.myPanelAttributes.left = { to:myCoolSearch.scrollHorizontalBy*(myCoolSearch.groupToShowNext) };
	if (myCoolSearch.groupToShowNext == myCoolSearch.totalNumberOfGroups - 1) {
		myCoolSearch.myNextButton.onmouseover = myCoolSearch.assignDefaultCursor;
		myCoolSearch.myNextButton.style.visibility = 'hidden';
	} else {
		myCoolSearch.myNextButton.onmouseover = myCoolSearch.assignPointerCursor;
		myCoolSearch.myNextButton.style.visibility = 'visible';
	}
	if (myCoolSearch.groupToShowNext == 0) {
		myCoolSearch.myPreviousButton.onmouseover = myCoolSearch.assignDefaultCursor;
		myCoolSearch.myPreviousButton.style.visibility = 'hidden';
	} else {
		myCoolSearch.myPreviousButton.onmouseover = myCoolSearch.assignPointerCursor;
		myCoolSearch.myPreviousButton.style.visibility = 'visible';
	}
};

SHOPZILLA.widget.CoolSearch.prototype.setCurrentGroupShowing = function() {
	myCoolSearch.currentGroupShowing = myCoolSearch.groupToShowNext;
};

SHOPZILLA.widget.CoolSearch.prototype.moveItems = function() {
	if (((myCoolSearch.currentGroupShowing > 0) && (this.direction == 1)) || ((myCoolSearch.currentGroupShowing != myCoolSearch.totalNumberOfGroups - 1) && (this.direction == -1))) {
		myCoolSearch.groupToShowNext = myCoolSearch.currentGroupShowing - this.direction;
		myCoolSearch.myPanel.animate();
	}
	return false;
};

SHOPZILLA.widget.CoolSearch.prototype.assignPointerCursor = function() {
	this.style.cursor = 'pointer';
};

SHOPZILLA.widget.CoolSearch.prototype.assignDefaultCursor = function() {
	this.style.cursor = 'default';
};

SHOPZILLA.widget.CoolSearch.prototype.centerPagination = function() {
	paginationObj = document.getElementById(this.myPaginationID);
	if (paginationObj) {
		itemsArray = paginationObj.getElementsByTagName('li');
		totalWidth = 0;
		for (i = 0;i<itemsArray.length;i++) {
			totalWidth = totalWidth + itemsArray[i].offsetWidth + 4;
		}
		paginationObj.style.width = totalWidth + 2;
	}
};


/* END Cool Search 2.0 Scrolling Categories */

/* Hot Refinement Price Range Sliders */

myPriceRange = function() {
	return {
		init:function() {
			this.mySlider = document.getElementById('slider');
			if (this.mySlider) {
				this.myFullDistance = parseInt(this.mySlider.offsetWidth) - 11;

				this.myFormFieldLow = document.getElementById('price_lower');
				this.myStartValueLow = parseInt(this.myFormFieldLow.value);

				this.myFormFieldHigh = document.getElementById('price_upper');
				this.myStartValueHigh = parseInt(this.myFormFieldHigh.value);

				this.myScale = (this.myStartValueHigh - this.myStartValueLow) / (this.myFullDistance);

				this.myHandleLower = YAHOO.widget.Slider.getHorizSlider("slider","handle_lower",0,this.myFullDistance - 10,1);
				this.myHandleLower.animate = true;
				this.myHandleLower.backgroundEnabled = false;
				this.myHandleLower.enableKeys = false;
				this.myHandleLower.myScale = this.myScale;
				this.myHandleLower.myLowerBound = 0;
				this.myHandleLower.myUpperBound = this.myFullDistance - 10;
				this.myHandleLower.myFormField = this.myFormFieldLow;
				this.myHandleLower.myFormField.onfocus = this.clearField;
				this.myHandleLower.myFormField.onblur = this.updateUsingForm;
				this.myHandleLower.myFormField.onkeypress = this.validateUserInput;
				this.myHandleLower.myFormField.onchange = this.updateUsingForm;
				this.myHandleLower.subscribe("change",this.updateLowerValue);
				this.myHandleLower.subscribe("slideStart",this.slideStart);
				this.myHandleLower.subscribe("slideEnd",this.slideEnd);
				this.myHandleLower.onDrag = '';

				this.myHandleUpper = YAHOO.widget.Slider.getHorizSlider("slider","handle_upper",-10,this.myFullDistance,1);
				this.myHandleUpper.animate = true;
				this.myHandleUpper.backgroundEnabled = false;
				this.myHandleUpper.enableKeys = false;
				this.myHandleUpper.myScale = this.myScale;
				this.myHandleUpper.myLowerBound = -10;
				this.myHandleUpper.myUpperBound = this.myFullDistance;
				this.myHandleUpper.myFormField = this.myFormFieldHigh;
				this.myHandleUpper.myFormField.onfocus = this.clearField;
				this.myHandleUpper.myFormField.onblur = this.updateUsingForm;
				this.myHandleUpper.myFormField.onkeypress = this.validateUserInput;
				this.myHandleUpper.myFormField.onchange = this.updateUsingForm;
				this.myHandleUpper.subscribe("change",this.updateUpperValue);
				this.myHandleUpper.subscribe("slideStart",this.slideStart);
				this.myHandleUpper.subscribe("slideEnd",this.slideEnd);
				this.myHandleUpper.setValue(this.myFullDistance,true,true,true);
				this.myHandleUpper.onDrag = '';
				
				this.myHandleLower.myPartner = this.myHandleUpper;
				this.myHandleUpper.myPartner = this.myHandleLower;
				
				this.mySubmitButton = document.getElementById('submit_prices');
				this.mySubmitButton.onclick = function() {
					window.location.href = this.form.action + '&minprice=' + this.form.elements['minprice'].value + '&maxprice=' + this.form.elements['maxprice'].value;
					return false;
				}
			}
		},
		updateLowerValue:function(offsetFromStart) {
			var new_value = myPriceRange.myStartValueLow + (offsetFromStart * this.myScale);
			this.myFormField.value = parseInt(new_value);
			if (this.getValue() <= this.myPartner.getValue()) {
				this.myPartner.getThumb().setXConstraint(-this.getValue() - 10,this.myPartner.myUpperBound,1);
			}
		},
		updateUpperValue:function(offsetFromStart) {
			var new_value = myPriceRange.myStartValueLow + (offsetFromStart * this.myScale);
			this.myFormField.value = parseInt(new_value);
			if (this.getValue() >= this.myPartner.getValue()) {
				this.myPartner.getThumb().setXConstraint(this.myPartner.myLowerBound,this.getValue() - 10,1);
			}
		},
		slideStart:function() {
		},
		slideEnd:function() {
		},
		validateUserInput:function(evt) {
			evt = (evt) ? evt : event;
			var target = evt.srcElement || evt.target;
			var key = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
			if (myPriceRange.keyPressedIsNumeric(key)) {
				return true;
			} else if (myPriceRange.keyPressedIsEnter(key)) {
				this.blur();
				return false;
			} else {
				alert('Please use only numeric values for price.');
				return false;
			}
		},
		clearField:function() {
			this.myOriginalValue = this.value;
			this.value = '';
		},
		keyPressedIsNumeric:function(key) {
			if ((key >= 48) && (key <= 57)) {
				return true;
			} else {
				return false;
			}
		},
		keyPressedIsEnter:function(key) {
			if (key == 3 || key == 13) {
				return true;
			} else {
				return false;
			}
		},
		updateUsingForm:function() {
			if (this == myPriceRange.myFormFieldLow) {
				if (this.value == '') {
					this.value = this.myOriginalValue;
				} else if (parseInt(this.value) >= parseInt(myPriceRange.myFormFieldHigh.value)) {
					alert('Lower Price Limit must be less than Upper Price Limit.');
					this.value = this.myOriginalValue;
				}
				myPriceRange.myHandleLower.setValue((this.value - myPriceRange.myStartValueLow)/myPriceRange.myScale);
			} else if (this == myPriceRange.myFormFieldHigh) {
				if (this.value == '') {
					this.value = this.myOriginalValue;
				} else if (parseInt(this.value) <= parseInt(myPriceRange.myFormFieldLow.value)) {
					alert('Upper Price Limit must be greater than Lower Price Limit.');
					this.value = this.myOriginalValue;
				}
				myPriceRange.myHandleUpper.setValue((myPriceRange.myStartValueHigh - this.value)/myPriceRange.myScale);
			}
		}
	}
}();




/* Rate this Page functionality */


function Trim(s) {
   var maxlength = 255;
   if (s.value.length > maxlength) 
   s.value = s.value.substring(0,maxlength);
} 

//<![CDATA[

var oForm = YAHOO.util.Dom.get('lolform');
//var msg_div = YAHOO.util.Dom.get('lolresponse');

var submit_form = function (e) {

   var callbacks = {

      success : function (o) { },
   	failure : function (o) { },
   	// might want to set this lower?
   	timeout : 9000
   };

	// form values to pass to the url we are calling
   var q_token_id          = oForm.elements['token_id'].value;
   var q_cat_id            = oForm.elements['cat_id'].value;
   var q_attribute_filters = encodeURIComponent(oForm.elements['attribute_filters'].value);
   var q_rf                = oForm.elements['rf'].value;
   var q_keyword           = encodeURIComponent(oForm.elements['keyword'].value);
   var q_hitcount          = oForm.elements['hitcount'].value;
   var q_sort_order        = oForm.elements['sort_order'].value;
   var q_products_shown    = oForm.elements['products_shown'].value;
   var q_page_number       = oForm.elements['page_number'].value;
   var q_page_total        = oForm.elements['page_total'].value;
   var q_breadcrumb        = encodeURIComponent(oForm.elements['breadcrumb'].value);
   var q_is_repeat_user    = oForm.elements['is_repeat_user'].value;
   var q_session_redirects = oForm.elements['session_redirects'].value;
   var q_cs_id             = oForm.elements['cs_id'].value;
   var q_template          = oForm.elements['template'].value;
   var q_thumb_up_down     = getCheckedValue(oForm.elements['thumb_up_down']);
   var q_review_text       = encodeURIComponent(oForm.elements['review_text'].value);

	// the url we are submitting to
   var entryPoint = '/rate-this-page';

	// append query params
   var queryString = encodeURI('?token_id=' + q_token_id + '&cat_id=' + q_cat_id + '&attribute_filters=' + q_attribute_filters + '&rf=' + q_rf + '&keyword=' + q_keyword + '&hitcount=' + q_hitcount + '&sort_order=' + q_sort_order + '&products_shown=' + q_products_shown + '&page_number=' + q_page_number + '&page_total=' + q_page_total + '&breadcrumb=' + q_breadcrumb + '&is_repeat_user=' + q_is_repeat_user + '&session_redirects=' + q_session_redirects + '&cs_id=' + q_cs_id + '&template=' + q_template + '&thumb_up_down=' + q_thumb_up_down + '&review_text=' + q_review_text );
   var sUrl = entryPoint + queryString;

	// make the callback
   YAHOO.util.Connect.asyncRequest('GET', sUrl, callbacks);
   return false;
}

//]]>

function $(id) {
  return document.getElementById(id);
}

function validate_form() {
   valid = true;

   if (( document.ratePageForm.thumb_up_down[0].checked == false ) && ( document.ratePageForm.thumb_up_down[1].checked == false )) {
      valid = false;
   }
   return valid;
}

function showRatePageForm() {
   var ratePage = $('ratePageWrap')
   var ratePageConf = $('ratePageConfirm')
   var ratePageErrMsg = $('ratePageErrMsg')

   switch (ratePage.style.display) {
      case 'none':
         ratePage.style.display = 'block';
         break;
      case 'block':
         ratePage.style.display = 'none';
         ratePageConf.style.display = 'none';
         ratePageErrMsg.style.display = 'none';
         break;
      default:
         // in case of something we don't expect, do nothing
         break;
   }
}

function validateRatePage() {
   var isValid = validate_form()
   var ratePage = $('ratePageWrap')
   var ratePageConf = $('ratePageConfirm')
   var ratePageErrMsg = $('ratePageErrMsg')

   if (isValid == true) {
      ratePage.style.display = 'none';
      ratePageConf.style.display = 'block';
      ratePageErrMsg.style.display = 'none';
      YAHOO.util.Event.on(oForm,'click',submit_form);
   } else {
      ratePage.style.display = 'block';
      ratePageConf.style.display = 'none';
      ratePageErrMsg.style.display = 'block';
   }

}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


