// Initialise popup pointer

var s1 = "inf";
var s2 = "xd";
var s3 = "ub";
var s4 = "o@bo";
var s5 = ".co.uk";
var scramble = s1 + s4 + s2 + s3 + s5;

var popupWin = null;

function chooseLabel(prefix){
	var label;
	label = document.getElementById("chooseLabel");
	window.location = prefix+"/"+label.value;
}

function playPopup(popupWin) {
	if (location.host == "localhost"){
		var playerPath = "/boxdub";
	}else{
		var playerPath = "";
	}

	var url = playerPath + "/player.asp";
	var leftPos = this.screen.width-350;
	popupWin = open( "", "popupWin", "width=318,height=183,left="+leftPos );
	if( !popupWin || popupWin.closed || !popupWin.doSomething ) {
		popupWin = window.open( url, "popupWin", "width=318,height=183,status=0,toolbar=0,left="+leftPos  );
	} else {
		popupWin.close();
		popupWin = window.open( url, "popupWin", "width=318,height=183,status=0,toolbar=0,left="+leftPos  );
	return popupWin
	}
}

function cuePopup(popupWin) {
	var url = "/player.asp";
	popupWin = open( "", "popupWin", "width=318,height=183,status=0,toolbar=0,left="+leftPos  );
	var leftPos = window.innerWidth-350;
	if( !popupWin || popupWin.closed || !popupWin.doSomething ) {
		popupWin = window.open( url, "popupWin", "width=318,height=183,status=0,toolbar=0,left="+leftPos  );
	} else {
		popupWin.focus();
		popupWin.opener.history.back();
	}
	return popupWin
}

function ajaxPlayASP(track){
}

function playButtonHandler(track, sessionID){
	ajaxPlayASP(track, sessionID);
	playPopup();
}

function ajaxPlayASP(track, sessionID)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  //When going live remove "/boxdub"
  if (location.host == "localhost"){
		var playerPath = "/boxdub";
	}else{
		var playerPath = "";
	}
  xmlHttp.open("GET",playerPath+"/play.asp?track="+track+"&sessionID="+sessionID,true);
  xmlHttp.send(null);
  }

  
 function ppAdjust(total){
	var ppAmount;
	var totalAmount;
	var ppDisplay = document.getElementById("ppAmount");
	var ppHidden = document.getElementById("hdnShipping");
	var ppHiddenName = document.getElementById("hdnShippingName");
	var totalWithPP = document.getElementById("totalWithPP");
	var region = document.getElementById("selectRegion").value;
	if (region == "UK"){ displayAmount = "2.50"; ppAmount = 2.5 }
	if (region == "EU"){ displayAmount = "6.00";  ppAmount = 6 }
	if (region == "RW"){ displayAmount = "10.00";  ppAmount = 10 } 
	ppDisplay.innerHTML = displayAmount ;
	ppHidden.value = ppAmount;
	ppHiddenName.value = region;
	totalAmount = total+ppAmount;
	totalWithPP.innerHTML = totalAmount.toFixed(2);
 }
 
function validatePaymentMethod()
{
	var paymentPaypal = document.getElementById("paymentPaypal");
	var paymentGoogle = document.getElementById("paymentGoogle");
	if ((paymentPaypal.checked) || (paymentGoogle.checked))
	{
		return true;
	}
	else
	{
		alert("You must choose a payment method.");
		return false;
	}
}

function switchImage(id, img){
	
	var imageToHide = document.getElementById(id + "-f");
	imageToHide.style.visibility = "hidden";
	imageToHide = document.getElementById(id + "-b");
	imageToHide.style.visibility = "hidden";
	imageToHide = document.getElementById(id + "-e");
	imageToHide.style.visibility = "hidden";
	imageToHide = document.getElementById(id + "-e2");
	imageToHide.style.visibility = "hidden";
	var imageToShow = document.getElementById(id + "-" + img);
	imageToShow.style.visibility = "visible";
	
	}

function switchImageEnlarge(img){
	var imageEnlargeLink = document.getElementById("enlargeImageLink");
	imageEnlargeLink.href = img
}
	
function checkSize(depth, id){
	var sizeSelector = document.getElementById("sizeSelect");
	var sizeSelectorValue = sizeSelector.value; 
	if (sizeSelectorValue == 0){
		alert("Please choose a size");
		return false;
	}else{
		windowLocation = depth+"buy.asp?id="+id+"&size="+sizeSelectorValue;
		window.location = windowLocation; 
	} 
	
}

function swapThreeColImage(depth, boxdubCode, show, hide){
	var imageToShow = document.getElementById(show + "-" + boxdubCode);
	var imageToHide = document.getElementById(hide + "-" + boxdubCode);
	imageToHide.style.visibility = "hidden";
	imageToShow.style.visibility = "visible";
}

function mouseOver(id)
{
	var imageToSwap = document.getElementById(id);
	var source = imageToSwap.src;
	source = source.replace(".gif", "-over.gif"); 
	imageToSwap.src = source; 
}

function mouseOut(id)
{
	var imageToSwap = document.getElementById(id);
	var source = imageToSwap.src;
	source = source.replace("-over.gif", ".gif"); 
	imageToSwap.src = source; 
}
