/*SKIPPY FUNCTIONS*/

/*function maxOut() {
	
	if(screen.width > self.outerWidth || screen.height > self.outerHeight)
	{
		self.moveTo(0,0);
		self.resizeTo(screen.width,screen.height);
	}
}*/

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=620,height=620,left = 100,top = 100');");
}
function popUp3(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=770,height=150,left = 100,top = 100');");
}
function popPrint(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=300,left = 100,top = 100');");
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
// window.onload = externalLinks;

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
/*image preloads*/

/*FORM VALIDATION*/

/** email validation **/
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail address")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail address")
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail address")
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail address")
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail address")
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail address")
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail address")
		    return false
		 }
 		 return true					
	}

function ValOrder(form){
		if(form.sordername.value == '') {
			alert('Please fill in your name');
			form.sordername.focus();
			return false;
		}
		if(form.sorderaddress.value == '') {
			alert('Please fill in your address');
			form.sorderaddress.focus();
			return false;
		}
		if(form.sordertel.value == '') {
			alert('Please fill in your tel number (landline or mobile)');
			form.sordertel.focus();
			return false;
		}
		if(form.sorderquantity.value == '') {
			alert('Please fill in the number of discs to be repaired');
			form.sorderquantity.focus();
			return false;
		}
		if(form.sordertitles.value == '') {
			alert('Please fill ALL disc titles');
			form.sordertitles.focus();
			return false;
		}
	return true
 }
	
function ValSKIPSign(form) {
		if(form.skipfullname.value == '') {
			alert('Please fill in your name (in full)');
			form.skipfullname.focus();
			return false;
		}
		if(form.skipemail.value == '') {
			alert('Please fill in your email address so we can contact you');
			form.skipemail.focus();
			return false;
		}
		return true;
	}
	
function disableLot() {
	if (document.all){ 
		document.onkeydown = function (){ 
		var key_f5 = 116; // 116 = F5 
			if (key_f5==event.keyCode){ 
			event.keyCode = 27; 
			
			return false; 
			} 
		} 
	}  
}

function disableRighty() {
//disable right mouse click Script
document.onmousedown="if (event.button==2) return false";
document.oncontextmenu=new Function("return false");
document.onkeydown = showDown;
}

function showDown(evt) {
evt = (evt)? evt : ((event)? event : null);
	if (evt) {
		if (event.keyCode == 8 && (event.srcElement.type!= "text" && event.srcElement.type!= "textarea" && event.srcElement.type!= "password")) {
		// When backspace is pressed but not in form element
		cancelKey(evt);
		}
		else if (event.keyCode == 116) {
		// When F5 is pressed
		cancelKey(evt);
		}
		else if (event.keyCode == 122) {
		// When F11 is pressed
		cancelKey(evt);
		}
		else if (event.ctrlKey && (event.keyCode == 78 || event.keyCode == 82)) {
		// When ctrl is pressed with R or N
		cancelKey(evt);
		}
		else if (event.altKey && event.keyCode==37 ) {
		// stop Alt left cursor
		return false;
		}
	}
}

function cancelKey(evt) {
	if (evt.preventDefault) {
	evt.preventDefault();
	return false;
	}
	else {
	evt.keyCode = 0;
	evt.returnValue = false;
	}
} 


var orderBuild_nextTitleId = 0;
var orderBuild_numberOfTitles = 0;
var orderBuild_numberOfDiscs = 0;

function orderBuild_addTitleClick()
{
	// Validate the input
	var newDiscQuantityElement = document.getElementById( 'newDiscQuantity' );
	var newTitleElement = document.getElementById( 'newDiscTitle' );
	
	if (newDiscQuantityElement.value == '' || newTitleElement.value == '')
	{
		alert( 'You must supply a valid title and quantity.' );
		return true;
	}
	
	var quantity = parseInt( newDiscQuantityElement.value );
	if ( isNaN( quantity ) || quantity < 1 )
	{
		alert( 'Please supply a valid quantity.');
		newDiscQuantityElement.focus();
		return true;
	}
	

	// Increment the number of unique titles
	orderBuild_numberOfTitles++;
	orderBuild_nextTitleId++;
	
	// Add the new title row to the table
	orderBuild_addRow();
	
	// Update the quantity
	orderBuild_numberOfDiscs += quantity;
	
	// Update the price
	orderBuild_updatePrice();
	
	newTitleElement.value = '';
	newTitleElement.focus();
	
	var newDiscQuantityElement = document.getElementById( 'newDiscQuantity' );
	newDiscQuantityElement.value = 1;
}

function orderBuild_removeTitleClick( titleId )
{
	// Decrement the number of titles
	orderBuild_numberOfTitles--;
		
	// Update the number of discs
	var titleQuantityElement = document.getElementById( 'title' + titleId + 'Quantity' );
	orderBuild_numberOfDiscs -= parseInt( titleQuantityElement.innerHTML );
	
	// Update the price
	orderBuild_updatePrice();
	
	// Remove the title from the table
	orderBuild_removeRow( titleId );	
}

function orderBuild_addRow()
{
	var tableElement = document.getElementById( 'orderTitlesTable' );
	var newTitleElement = document.getElementById( 'newDiscTitle' );
	var newDiscQuantityElement = document.getElementById( 'newDiscQuantity' );
	
	var orderTotalRow = tableElement.rows.length;
	
	var newRow = tableElement.insertRow( orderTotalRow - 2 );
	newRow.id = 'title' + orderBuild_nextTitleId + 'Row';
	
	var titleCell = newRow.insertCell( 0 );
	titleCell.innerHTML = '<a href="#" onclick="javascript:orderBuild_removeTitleClick(' + orderBuild_nextTitleId + ');">[x]</a> <span id="title' + orderBuild_nextTitleId + '">' + newTitleElement.value + '</span>';
	titleCell.innerHTML += '<input name="frmTitle' + orderBuild_nextTitleId + '" type="hidden" id="frmTitle' + orderBuild_nextTitleId + '" value="' + newTitleElement.value + '" />';
	
	var quantityCell = newRow.insertCell( 1 );
	quantityCell.innerHTML = '<span id="title' + orderBuild_nextTitleId + 'Quantity">' + newDiscQuantityElement.value + '</span>';
	quantityCell.innerHTML += '<input name="frmQuantity' + orderBuild_nextTitleId + '" type="hidden" id="frmQuantity' + orderBuild_nextTitleId + '" value="' + newDiscQuantityElement.value + '" />';
}

function orderBuild_removeRow( titleId )
{
	var tableElement = document.getElementById( 'orderTitlesTable' );
	
	var rowToRemove = document.getElementById( 'title' + titleId + 'Row' );
	
	tableElement.deleteRow( rowToRemove.rowIndex );
}

function orderBuild_updatePrice()
{
	var orderTotalElement = document.getElementById( 'orderTotal' );
	if ( orderBuild_numberOfDiscs < 6 )
	{
		orderTotalElement.innerHTML = (orderBuild_numberOfDiscs * 2.99).toFixed( 2 );
	}
	else if ( orderBuild_numberOfDiscs < 11 )
	{
		orderTotalElement.innerHTML = orderBuild_currentPrice = (orderBuild_numberOfDiscs * 2.49).toFixed( 2 );
	}
	else
	{
		orderTotalElement.innerHTML = orderBuild_currentPrice = (orderBuild_numberOfDiscs * 1.99).toFixed( 2 );
	}
	
	var discsTotalElement = document.getElementById( 'totalDiscs' );
	discsTotalElement.innerHTML = orderBuild_numberOfDiscs;
}

function orderBuild_validate()
{
	if (orderBuild_numberOfDiscs == 0)
	{
		alert( 'You must add at least one disc to your order.' );
		return false;
	}
	
	return true;
}

function orderDelivery_validate(formElement)
{
	var problems = '';

	if ( isFieldBlank( formElement.name ) )
	{
		problems += "- Name must be filled in\r\n";
	}
	
	if ( isFieldBlank( formElement.address1 ) )
	{
		problems += "- You must fill in the first line of the address\r\n";
	}
	
	if ( isFieldBlank( formElement.country ) )
	{
		problems += "- You must fill in the country\r\n";
	}
	
	if ( !isFieldBlank( formElement.postcode ) && !checkPostCode( formElement.postcode.value ) )
	{
		problems += "- The post code you included was not a valid UK post code\r\n";
	}
	
	if ( isFieldBlank( formElement.orderEmail ) || !isValidEmail( formElement.orderEmail.value ) )
	{
		problems += "- The email address you entered is not valid\r\n";
	}
	
	if ( formElement.createAccount.checked && formElement.newAccountPassword.value.length < 8 )
	{
		problems += "- The account password must be at least 8 characters long\r\n";
	}
	
	if ( problems != '' )
	{
		alert('The following problems occurred with your delivery address:\r\n\r\n' +  problems + '\r\n');
		return false;
	}
	
	return true;	
}

function isFieldBlank(formField)
{
	return formField.value == null || formField.value == "";
}

function orderDelivery_createAccountClicked()
{
	var accountSection = document.getElementById( 'createAccountSection' );
	var createAccountCheckbox = document.getElementById( 'createAccountBox' );
	
	if (createAccountCheckbox.checked)
	{
		accountSection.style.display = 'block';
	}
	else
	{
		accountSection.style.display = 'none';
	}
	
}

function orderSummary_showPayPalInfo()
{
	alert('Once payment is complete, YOU MUST CLICK "RETURN TO SITE", so that you can print your prepaid envelope cover and order reference number');
	
	return true;
}

function isValidEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

   if(reg.test(email) == false) {
      return false;
   }
   
   return true;
}

/*==============================================================================
	Author:		John Gardner
	Source:		http://www.braemoor.co.uk/software/postcodes.shtml
==============================================================================*/
function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}

/*SCROLL*/
function init_dw_Scroll() {
    // arguments: id of div container, id of div to scroll
    var wndo = new dw_scrollObj('wn', 'lyr1');
    wndo.setUpScrollControls('scroll_links');
}

/*ENABLE MULTIPLE LOADS WITHOUT PLACING 3 FTNS IN BODY TAG*/
function start() {
  externalLinks();
  MM_preloadImages();
}
window.onload = start;