/*
** Colour Inc Ltd.  © 2006
** 20060728
** Dan Richards - Orpheus Software Ltd
*/

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];}
}

function isDefined(v) {
  return (typeof(window[v]) == "undefined")?  false: true;
}

function popup(file) {
	popupWin = window.open(file, 'popup', 'scrollbars=yes,status=1,menubar=yes,resizable=yes,width=658,height=520');
  myTimer = setTimeout("popupWin.focus()",1000);
}

function bigimg(img_name) {
	new_win = window.open("","new_win","toolbar=0,scrollbars=0,location=0,resizable=1,width=300,height=300,left=40,top=40");
	new_win.document.open();
	new_win.document.writeln('<html><head><title>CanvasInc - '+img_name+'</title></head>');
	new_win.document.writeln('<body onLoad="resizePage();" bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onClick="self.close()" onBlur="self.close()">');
	new_win.document.writeln('<img src="'+img_name+'" id=imgID alt="Click to close">');
	new_win.document.writeln('<script>function resizePage() { img = document.images[0]; window.resizeTo(img.width,img.height) } </\script>');
	new_win.document.writeln('</body></html>');
	new_win.document.close();
	new_win.focus();
}
	
function addToBasket(iP) {
 var f=document.forms[0];
 var q=eval('f.qty'+iP);
 if (q.value=="") {
 	 alert("Please enter a valid quantity");
 	 q.focus();
 	 return;
 }

 f.process.value = "add";
 f.product_id.value = iP;
 f.submit(); 
}


function delFromBasket(id) {
 var f=document.forms[0];
 f.process.value = "del";
 f.item_id.value = id;
 f.submit(); 
}


function updBasket(id) {
 var f=document.forms[0];
 var o=eval("f.qty" + id);
 if ( !isNumeric(o.value) ) {
   alert("Please enter a valid number");
   o.focus();
   return;
 }
 f.process.value = "upd";
 f.item_id.value = id;
 f.submit();   
}

function editBasket() {
 location = "your_order.php";
}

function checkout() {
 var f=document.forms[0];
 document.getElementById('checkoutcontainer').innerHTML = '<img src="images/continue_disabled.gif" width="107" height="37" border="0" />';
 f.action = "checkout.php";
 f.submit();
}

function updBrowse() {
  var f=document.forms[0];
  if (f.browse.value != "") {
    var fn = f.browse.value;
    var fna = fn.split("\\");
    var fnb = fna[fna.length-1];
    var fnc = fnb.split("/");
    var fnd = fnc[fnc.length-1];
    var fne = fnd.split(".");
    var fnf = fne[0];
    if (fne[1].toUpperCase()!="JPG" && fne[1].toUpperCase()!="JPEG") {
      alert("I'm afraid we can only accept JPG images at this moment in time.\n" +
          "Please call us to see if we can help you convert this image.");
      return false;
    }
    f.yp_title.value = fnf;
    f.yp_title.focus();
    return;
  }
}



function upload() {
  var f=document.form_upload;
  if (f.browse.value == "") {
    alert("Please select your file to upload");
    f.browse.focus();
    return;
  }
  document.getElementById('progress_div').style.visibility = 'visible';
  document.getElementById('yp_blurb').style.visibility = 'hidden';
  document.getElementById('yp_blurb').style.height = 160;

	if(window.opera){ 
		imbedded_progress_bar = false;
		f.imbedded_progress_bar.value = 0; 
	}

	if(imbedded_progress_bar){ f.imbedded_progress_bar.value = 1; }
	else{ f.imbedded_progress_bar.value = 0; }
	
	f.submit();
	f.yp_title.disabled = true;
	f.browse.disabled = true;
	document.getElementById('uploadcontainer').innerHTML = '<img src="images/upload_disabled.gif" width="108" height="37" border="0" />';

  var pd = document.getElementById('progress_div');
  pd.style.height = 260;
  pd.innerHTML = "<iframe name='progress_iframe' background-color='#eef4f8' src='" + progress_link + " 'frameborder='0' scrolling='no' width='480' height='260'></iframe>";
	return false;
}

function submitCheckout() {
  var f=document.forms[0];
  var m=new Array("name","address","town","postcode","email");
  
  for (var i=0; i<5; i++) { 
    o = eval("f." + m[i]);
    if ( o.value == "" ) {
      alert("Please enter your " + m[i]);
      o.focus();
      return;
    }
  }
/*
  if (f.delivery.selectedIndex == 0) {
    alert("Please select a delivery option.");
    f.delivery.focus();
    return;
  } else {
*/
    if (f.delivery.selectedIndex > 1 && f.country.value == "") {
      alert("Please enter the country.");
      f.country.focus();
      return;
    }

  document.getElementById('checkoutcontainer').innerHTML = '<img src="images/continue_disabled.gif" width="108" height="37" border="0" />';
  f.submit();
}

function submitCheckout2() {
  var f=document.forms[0];
  //var m=new Array("cctype","ccnumber","month","year","securitycode");
  var m=new Array("name","address","town","postcode","email");

  for (var i=0; i<5; i++) { 
    o = eval("f." + m[i]);
    if ( o.value == "" ) {
      alert("Please enter your billing " + m[i]);
      o.focus();
      return;
    }
  }
  document.getElementById('checkoutcontainer').innerHTML = '<img src="images/continue_disabled.gif" width="108" height="37" border="0" />';
  f.submit();
}

function updMand() {
  var f=document.forms[0];
  var m=new Array("name","address","town","postcode","email");

  for (var i=0; i<5; i++) { 
    o = eval("f." + m[i]);
    if ( o.value != "" ) {
      o.className = "optfield";
    } else {
      o.className = "mandfield";
    }
  }
}

function updDel() {
  var f=document.forms[0];
  var price=parseFloat(f.amount.value);
  price = eval(parseFloat(f.amount.value) + parseFloat(f.delivery.value));
  switch(f.delivery.selectedIndex) {
    case 0:
      f.country.value = "UK";
      break;
    default:
      f.country.value = "";
  }
  document.getElementById('total_price').innerHTML = price.toFixed(2);
}

function handleEnter(nextControl) {
  // IE only
  if (typeof(event)!="undefined") {
    var e = window.event;
    var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    if (keyCode == 13 || keyCode == 3) {
      var f=document.forms[0];  
      var o = eval("f." + nextControl);
      o.focus();
    }
  }
}

function ismaxlength(obj) {
  var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
  if (obj.getAttribute && obj.value.length>mlength)
  obj.value=obj.value.substring(0,mlength)
}

function isNumeric(entry){
  var validChar='0123456789';
  var strlen=entry.length;
  if (strlen < 1) {
    return false;
  }
  for (i=0; i<strlen; i++){
    if( validChar.indexOf( entry.charAt(i) ) < 0 ) {
      return false;
    }
  }  
  return true;
}

var firsttime;
function validator(theForm) {
  if (firsttime == "Y") {
    alert("Please wait your payment is being processed.");
    return (false);
  }
  firsttime = "Y";
  return (true);
}



sIFR.prefetch(myriadpro);
sIFR.activate();

sIFR.replace(myriadpro, {
  selector: 'h1'
  ,css: [
    '.sIFR-root { font-weight: bold; color: #1a2575; background-color: #EEF4F9; }'
  ]
  ,verticalSpacing: 20,
	wmode: 'transparent'
});

/*

sIFR.replace(myriadpro, {
  selector: 'h2'
  ,css: [
    '.sIFR-root { font-weight: bold; color: #6699cc; background-color: #EEF4F9; text-align: center; }'
  ]
  ,verticalSpacing: 20,
	wmode: 'transparent'
});
*/


/*
sIFR.replace(myriadpro, {selector: 'h1'});
sIFR.replace(myriadpro, {selector: 'h2'});

sIFR.replace(myriadpro, {
  selector: '.menu_item'
  ,css: [
    '.sIFR-root { font-weight: bold; color: #1a2575; }'
  ]
	,wmode: 'transparent'
});

sIFR.replace(myriadpro, {selector: '.menu_item'});
*/