// JavaScript Document
var strOff = "-bt";
var strOver = "-bt-over";

function swapImg(target){
	if(target!=""){
		var strImg = target.src;
	   if (strImg.indexOf(strOver) != -1){ 
		   var newImg = new Image();
		  target.src = strImg.replace(strOver,strOff);
	   }else{
		  target.src = strImg.replace(strOff,strOver);
	   }
	}
}

function SwitchImage(name, ext) {
  document.images[name].src= "Images/Header/" + name + 'Link' + ext + '.gif';
}

function PopWindow(width, height, address) {
 window.open(address, "Pop", "top=20,height=" + height + ",width=" + width + ",location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no")
}

function switchImage(style, newcolour, id){

	currentsrc = document.getElementById(style + "mainImage").src;
	currentsrc = currentsrc.replace("http://shift.abacus.local/shift/Image.aspx?Size=140&Image=","");
	currentsec = currentsrc.replace(".jpg","");
	oldcolour = currentsrc.substr(6,3);

	document.getElementById(style + "mainImage").src = "http://shift.abacus.local/shift/Image.aspx?Size=140&Image=" + style + "-" + newcolour + ".jpg";
	document.getElementById(style + "swatch" + id).src = "http://shift.abacus.local/shift/Image.aspx?Size=15&Image=" + style + "-" + oldcolour + ".jpg"

	currentlink = document.getElementById(style + "link").href;
	newlink = currentlink.replace(oldcolour,newcolour);
	document.getElementById(style + "link").href = newlink;
	currentfunction = document.getElementById(style + "swatchlink" + id).href;
	newfunction = currentfunction.replace(newcolour,oldcolour);
	document.getElementById(style + "swatchlink" + id).href = newfunction;
}

function StockStatus() {
  var divStock = $('divStock');
  var divPrice = $('divPrice');
  for (n=0; n<maxsize; n++) {
	if (sza[0][n] == document.forms['CartCtrl'].Size.value) {
	  divStock.innerHTML = sza[1][n];
	  divPrice.innerHTML = "&pound;" + sza[2][n];
	  document.forms['CartCtrl'].Price.value = sza[2][n];
	}
  }
}

function AddToCart() {
  var divStock = $('divStock');

  if (document.CartCtrl.Size.value == "Cho") {
	alert("You must choose a Size.")
  } else if(divStock.innerHTML == "Item Out of Stock") {
	alert("The product you are trying to order is out of stock.");
  } else {
	document.forms['CartCtrl'].submit()
  }
}
function ViewProduct(productCode) {
	window.open("ViewProduct.asp?Product=" + productCode, "ViewProduct", "top=20,height=405,width=350,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no")
}

function ValidateForm() {
 if(document.forms['Details'].Forenames.value == '') {
  alert('You must fill in the Forenames field.');
  return false;
 } else if(document.forms['Details'].Surname.value == '') {
  alert('You must fill in the Surname field.');
  return false;
 } else if(document.forms['Details'].EMail.value == '') {
  alert('You must fill in the EMail field.');
  return false;
 } else if(document.forms['Details'].Telephone.value == '') {
  alert('You must fill in the Contatct Number field.');
  return false;
 } else if(document.forms['Details'].Address.value == '') {
  alert('You must fill in the Address field.');
  return false;
 } else if(document.forms['Details'].Town.value == '') {
  alert('You must fill in the Town/City field.');
  return false;
 } else if(document.forms['Details'].County.value == '') {
  alert('You must fill in the County field.');
  return false;
 } else if(document.forms['Details'].PostCode.value == '') {
  alert('You must fill in the Post Code field.');
  return false;
 } else if(document.forms['Details'].Country.value == '') {
  alert('You must choose a Country.');
  return false;
 } else {
  return true;
 }
}

function ValidatePaymentForm() {
 if(document.forms['Payment'].CardNumber.value == '') {
  alert('You must fill in the Card Number field.');
  return false;
 } else if(document.forms['Payment'].CardType.value == '') {
  alert('You must select a Card Type.');
  return false;
 } else if(document.forms['Payment'].ExpiryMonth.value == '') {
  alert('You must select an Expiry Date.');
  return false;
 } else if(document.forms['Payment'].ExpiryYear.value == '') {
  alert('You must select an Expiry Date.');
  return false;
 } else if(document.forms['Payment'].NameOnCard.value == '') {
  alert('You must fill in the Card Holders Name field.');
  return false;
 } else if(document.forms['Payment'].CVV2.value == '') {
  alert('You must fill in the CVV2/CVC2 field.');
  return false;
 } else if(isNaN(document.forms['Payment'].IssueNumber.value) == true && document.forms['Payment'].IssueNumber.value != '') {
  alert('You must enter a NUMBER in the Issue Number field, or leave it blank.');
  return false;
 } else {
  return true;
 }
}

function OneClickOnly() {

  if (document.forms['OneOnly'].elements['Clicked'].value == "No") {
    document.forms['OneOnly'].elements['Clicked'].value = "Yes";
    return true;
  } else {
    alert('You can only click the Confirm button once.  Confirmation may take a little time, if you recieve no response then refresh this page and click the button again.');
    return false;
  }

}
