/* JS to include in sections of the site external to the store. */

function displayProductPopup(code, elToHide) {
	trackClick(storeURL + '/ajax/productdetail/' + code);

	var t = this.title || this.name || null;
	var a = storeURL + '/ajax/productdetail?sku=' + code + '&width=430&height=460&closer=no';
	var g = this.rel || false;
	//document.getElementById('player').style.display='none'
	tb_show(t,a,g);
}

function displayProductPopupByFilm(filmID, elToHide, code) {
	trackClick(storeURL + '/ajax/productdetail/' + code);

	var t = this.title || this.name || null;
	var a = storeURL + '/ajax/productdetail?filmID=' + filmID + '&width=430&height=460&closer=no';
	var g = this.rel || false;
	//document.getElementById('player').style.display='none'
	tb_show(t,a,g, elToHide);
}

function onDemandRestrictPopup(filmID, elToHide, code) {
	trackClick(storeURL + '/ajax/ondemandrestrict/' + code);

	var t = this.title || this.name || null;
	var a = storeURL + '/ajax/ondemandrestrict?filmID=' + filmID + '&width=380&height=220&closer=no';
	var g = this.rel || false;
	//document.getElementById('player').style.display='none'
	tb_show(t,a,g, elToHide);
}

function onDemandPopupByFilm(filmID, elToHide, code) {
	trackClick(storeURL + '/ajax/ondemand/' + code);

	var t = this.title || this.name || null;
	var a = storeURL + '/ajax/ondemand?filmID=' + filmID + '&width=430&height=400&closer=no';
	var g = this.rel || false;
	//document.getElementById('player').style.display='none'
	tb_show(t,a,g, elToHide);
}

function displayHhofDVDBuyPopup(filmID, elToHide, code) {
	trackClick(storeURL + '/ajax/hhofdvdbuy/' + code);

	var t = this.title || this.name || null;
	var a = storeURL + '/ajax/hhofdvdbuy?filmID=' + filmID + '&width=430&height=240&closer=no';
	var g = this.rel || false;
	//document.getElementById('player').style.display='none'
	tb_show(t,a,g, elToHide);
}

function addToCart(sku, elprefix) {

	xmlHttp=getXmlHttpObject();

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {
			if (xmlHttp.responseText == "success") {
				var premium = document.getElementById('isPremium').value;
				if(premium == '1') {
					window.location = siteURL + '/store/cart?code=PREMSTR20';
				} else {
					window.location = siteURL + '/store/cart';
				}
				/*document.getElementById(elprefix + 'AddToCartAJAXField').style.display = 'none';
				document.getElementById(elprefix + 'AddToCartField').style.display = 'none';
				document.getElementById(elprefix + 'InCartField').style.display = 'block';*/
			} else {
				document.getElementById(elprefix + 'AddToCartAJAXField').innerHTML = 'Failed!';
			}
		} else {
			document.getElementById(elprefix + 'AddToCartAJAXField').style.display = 'block';
			document.getElementById(elprefix + 'AddToCartField').style.display = 'none';
			document.getElementById(elprefix + 'AddToCartAJAXField').innerHTML = 'Loading... ' + loadingGraphic2;
		}
	}

	var url = storeURL;

	url=url+'/ajax/addtocart/'+sku;

	trackClick(url);

	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);

}

function displayUpgradePopupDispatch() {
	//I don't think you can put javascript inside the google multivariate AB testing blocks
	//so we'll check for the existence of an undisplayed element with a particular instead
	if (document.getElementById('multivariateIndicatorBig')) {
		displayUpgradePopup(new Array('FilmPlayer', 'FilmCardLauncher', 'filmPlayerFlashContainer'));
	} else {
		displayUpgradePopupSmall(new Array('FilmPlayer', 'FilmCardLauncher'));
	}
	
	
}

function displayUpgradePopupSmall(elToHide) {
	var t = this.title || this.name || null;
	var a = '#TB_inline?height=230&width=380&inlineId=upgradePopupSmall&closer=no';
	var g = this.rel || false;
	tb_show(t,a,g, elToHide);
}

function displayUpgradePopup(elToHide) {
	var t = this.title || this.name || null;
	var a = '#TB_inline?height=559&width=954&inlineId=upgradePopup&closer=no';
	var g = this.rel || false;
	tb_show(t,a,g, elToHide);
}
