var BIZRATE = YAHOO;

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

/**
 * BIZRATE.widget.InternationalRedirector object
 */

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

BIZRATE.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() {
			BIZRATE.widget.InternationalRedirector.prototype.close();
		};
*/
	}
};

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

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

BIZRATE.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 = BIZRATE.util.Dom.isSafari ? document : document.body;

	if(BIZRATE.util.Dom.isIE && !BIZRATE.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);
};

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

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

BIZRATE.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;
};

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

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

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

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

/**
 * BIZRATE.widget.Page object
 */

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

BIZRATE.widget.Page.prototype.init = function() {
	this.Dom = BIZRATE.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();
};

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

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

BIZRATE.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;
};

BIZRATE.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;
};

BIZRATE.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 ();
}

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

BIZRATE.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 */

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

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

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

BIZRATE.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');
};


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


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

BIZRATE.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;
	}
};

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

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

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

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

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


/* NetPromoter END */

/* DHTML Product Details POD for CSP (Template #50) BEGIN */

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

BIZRATE.widget.myProductDetailsPod.prototype.init = function() {
	this.myProductDetailsObj = document.getElementById('product_details_pod');
	this.myTabs = this.myProductDetailsObj.getElementsByTagName('dt');
	this.myTabsContents = this.myProductDetailsObj.getElementsByTagName('dd');
	this.myNewDefinitionListObj = document.createElement('dl');
	this.myTotalNumberOfTabs = this.myTabs.length;
	for (i = 0; i < this.myTotalNumberOfTabs; i++) {
		this.myTabs[0].myIndex = i;
		this.myTabs[0].onclick = this.clickMyTab;
		this.myNewDefinitionListObj.appendChild(this.myTabs[0]);
	}
	for (i = 0; i < this.myTotalNumberOfTabs; i++) {
		this.myTabsContents[0].className = 'behind';
		this.myNewDefinitionListObj.appendChild(this.myTabsContents[0]);
	}
	this.myProductDetailsObj.appendChild(this.myNewDefinitionListObj);
	this.myProductDetailsObj.removeChild(this.myProductDetailsObj.getElementsByTagName('dl')[0]);
	this.myTabs[this.myStaringTabIndex].onclick();
};

BIZRATE.widget.myProductDetailsPod.prototype.clickMyTab = function() {
	myProductDetailsPod.myTabs[myProductDetailsPod.mySelectedTabIndex].className = '';
	myProductDetailsPod.myTabsContents[myProductDetailsPod.mySelectedTabIndex].className = 'behind';
	if (myProductDetailsPod.mySelectedTabIndex < myProductDetailsPod.myTotalNumberOfTabs - 1) {
		myProductDetailsPod.myTabs[myProductDetailsPod.mySelectedTabIndex + 1].className = '';
		myProductDetailsPod.myTabsContents[myProductDetailsPod.mySelectedTabIndex + 1].className = 'behind';
	}
	myProductDetailsPod.myTabs[this.myIndex].className = 'selected';
	myProductDetailsPod.myTabsContents[this.myIndex].className = 'selected';
	myProductDetailsPod.myTabs[myProductDetailsPod.myTotalNumberOfTabs - 1].className += ' last';
	myProductDetailsPod.mySelectedTabIndex = this.myIndex;
};

/* DHTML Product Details POD for CSP Template #50) END */


/* function dart_is_one_px to hide header and footer banners when 1x1.gif pixel is returned */
function dart_is_one_px(div_id)  {
        var cid,img;
        if (cid = document.getElementById(div_id)) {
                if (img = cid.getElementsByTagName('img')[0]) {
                        if (img.src.match(/817-grey/i) || img.src.match(/2x1/i)) {
                                return true;
                        }
                }
        }
        return false;
}

function toggle_dart_div(tdiv) {
	if ( dart_is_one_px(tdiv) ) {
		document.getElementById(tdiv).style.height = '0px';
        document.getElementById(tdiv).style.display = 'none';
	}
}
/* END header/footer banner disable */


/* THE FOLLOWING IS THE FUNCTIONALITY FOR THE ALL DEPARTMENTS OVERLAY FOR THE NEW BIZRATE HEADER - BEGIN */

var sliderIntervalId = 0;	// holds the id of the interval that will be animating the slider
var sliderHeight = 0;	// the height of AllDepartmentsSlider
var sliding = false;		// will not slide again if the user clicks the bttn while it is already sliding
var slideSpeed = 80;	// controls how fast the window will contract and expand

// Slide() function determines if the window is open or closed
function allDepartsSlide() {
   if (sliding)
      return;
   sliding = true;
   if (sliderHeight == 184)
      sliderIntervalId = setInterval('allDepartsSlideUp()', 10);
   else
      sliderIntervalId = setInterval('allDepartsSlideDown()', 10);
}

function allDepartsSlideUp() {
   slider = document.getElementById('AllDepartmentsSlider');
   if (sliderHeight <= 0) {
      sliding = false;
      sliderHeight = 0;
      slider.style.height = '1px';
      clearInterval(sliderIntervalId);
   }
   else {
      sliderHeight -= slideSpeed;
      if(sliderHeight < 0)
      	sliderHeight = 0;
      	slider.style.height = sliderHeight + 'px';
   }
}

function allDepartsSlideDown() {
   slider = document.getElementById('AllDepartmentsSlider');
   if (sliderHeight >= 184) {
      sliding = false;
      sliderHeight = 184;
      slider.style.height = '184px';
      clearInterval(sliderIntervalId);
   }
   else {
      sliderHeight += slideSpeed;
      if (sliderHeight > 184)
         sliderHeight = 184;
      slider.style.height = sliderHeight + 'px';
   }
}

/* toggleHiddenLayer() function to show/hide a <div> box */
function toggleHiddenLayer(divid) {
        // layer is hidden by default (when style.display is null)
	if (document.getElementById(divid).style.display == 'block') {
		document.getElementById(divid).style.display = 'none';
	} else {
		document.getElementById(divid).style.display = 'block';
	};
}
/* END toggleHiddenLayer() function to show/hide a <div> box */



// BEGIN - HOMEPAGE FEATURED HOT PRODUCTS POD

// displays highlighted category in centre pod

function highlightCategory(category) {
    // highlight CATEGORY
    var highlightedCategory = document.getElementById(category);
    var unhighlightedCategory = document.getElementById(currentHighlightedCategory);
    
    unhighlightedCategory.className = (unhighlightedCategory.className == "curved_on") ? "curved" : "";
    highlightedCategory.className = (highlightedCategory.className == "curved") ? "curved_on" : "on";
    
    currentHighlightedCategory = category;

    // highlight CONTENT
    var highlightedContent = document.getElementById(category + '_content');
    var unhighlightedContent = document.getElementById(currentHighlightedContent);
    
    unhighlightedContent.className = "hidden";
    highlightedContent.className = "shown";
    
    currentHighlightedContent = category + '_content';

    // highlight first PRODUCT and first PRODUCT DETAIL
    highlightProduct(category + '_product1');
}

// displays details of selected product in centre pod

function highlightProduct(product) {
    // highlight PRODUCT
    var highlightedProduct = document.getElementById(product);
    var unhighlightedProduct = document.getElementById(currentHighlightedProduct);
    
    unhighlightedProduct.className = "unhighlighted_subproduct";
    highlightedProduct.className = "highlighted_subproduct";
    
    currentHighlightedProduct = product;


    // highlight PRODUCT DETAILS
    var highlightedProductDetails = document.getElementById(product + '_detail');
    var unhighlightedProductDetails = document.getElementById(currentHighlightedProductDetails);
    
    unhighlightedProductDetails.className = "hidden";
    highlightedProductDetails.className = "shown";
    
    currentHighlightedProductDetails = product + '_detail';
}


// END - HOMEPAGE FEATURED HOT PRODUCTS POD



function viewOffers(pod_id) {
  var offers_popup = document.getElementById(pod_id)

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

