function clearform(){
  document.getElementById('roomlength').value = '';
  document.getElementById('roomwidth').value = '';
  //document.getElementById('roomarea2').value = '';
  document.getElementById('roomarea').value = '';
  document.getElementById('productamount').value = '';
}
function checkticks(){
  alert('hello');
  var total=0;
  var inputs = document.getElementById('theForm').getElementsByTagName('input');
  for(var i=0;i<inputs.length; i++){
    var regex = new RegExp('samples',"i");
    if(regex.test(inputs[i].getAttribute("name"))){
      if(inputs[i].checked == true){
        total+=1;
      }
    }
  }
  alert(total);
  if(total>3){
    alert('Sorry you can only order 3 samples at a time.');
    return false;
  } else if(total < 1){
    alert('You must choose at least one sample to continue.');
    return false;
  }
}
function open_window_centred(win_url, win_name, win_w, win_h) {

  var win_left = (screen.width - win_w) / 2;
  var win_top = (screen.height - win_h) / 2;
  
  win_style = "location=no, menubar=no, status=no, resizable=yes, toolbar=no, scrollbars=yes,";
  win_style += 'width=' + win_w;
  win_style += ',height=' + win_h;
  win_style += ',left=' + win_left;
  win_style += ',top=' + win_top;

  var newwin = window.open(win_url, win_name, win_style);
  newwin.focus();
  return;

}

function showhide(theid){
  var tmp = document.getElementById(theid);
  var newstyle='';
  if(document.getElementById(theid).style.display == 'none'){
    document.getElementById(theid).style.display = '';
  } else {
    document.getElementById(theid).style.display = 'none';
  }
}
function url_decode(psEncodeString) 
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  var newString = String(psEncodeString).replace(lsRegExp, " ");
  return String(newString).replace("%99","™"); 
}

function changecurrency(thedrop){
  thedrop.form.submit();
}
function removefrombasket(basketid){
  window.location.href='ecom_data.php?dw=removefrombasket&basketid=' + basketid;
}
function addtobasket(basketid){
  window.location.href='ecom_data.php?dw=addtobasket&productid=' + basketid;
}
var _w = null;
function createNew(thispic) {
mypic = thispic;
  _w = window.open();
  _w.document.open();
_w.document.write('<html><head><title>Full Image Preview</title></head><body><a href="javascript:window.close();">Close Window</a><br>');
  _w.document.write('<img src = "');
  _w.document.write (mypic);
  _w.document.write ('">');
  
  _w.document.write('</body></html>');
  _w.document.close();
}

function chkcheckout1()
{
fieldlist=new Array();
fielderrorlist=new Array();

fieldlist = ["clientfname","clientsname","clientaddress1","clienttown","clientpostcode","clientemail"];
fielderrorlist = ["First Name","Surname","Address","Town","Postcode","Email"];

for (i=0; i < fieldlist.length; i++){
formitem=fieldlist[i];
if (document.forms.theform[formitem].value.length<3){
alert("Please ensure " + fielderrorlist[i] + " is entered!");
return false;
break;
}
}
}


function validate_registerform()
{
fieldlist=new Array();
fielderrorlist=new Array();

fieldlist = ["registeremail","registerpassword","registerconfirmpassword","registerfname","registersname","registeraddress1","registertown","registerpostcode"];
fielderrorlist = ["Email","Password","Password Confirmation","First Name","Surname","Address","Town","Postcode"];

for (i=0; i < fieldlist.length; i++){
  formitem=fieldlist[i];
  if (document.forms.registerform[formitem].value.length<2){
    alert("Please ensure " + fielderrorlist[i] + " is entered!");
    document.forms.registerform[formitem].focus();
    return false;
    break;
  }
}
if (document.forms.registerform['registerpassword'].value!=document.forms.registerform['registerconfirmpassword'].value){
  alert("Please ensure Password is confirmed correctly!");
  document.forms.registerform['registerpassword'].focus();
  return false;
}
if (document.forms.registerform['registerpassword'].value.length<6){
  alert("Please ensure Password is at least 6 characters long!");
  document.forms.registerform['registerpassword'].focus();
  return false;
}
}


function clear_text(obj) {
  document.getElementById(obj).value = "";
  document.getElementById(obj).focus();
}


function GetXmlHttpObject() { 
  var objXMLHttp=null;
  if (window.XMLHttpRequest) {
    objXMLHttp=new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
   objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  return objXMLHttp;
}
var current = '';
function showprodinfo(pid,thei) {


document.getElementById("clicked").value="clicked";

  xmlHttp = GetXmlHttpObject();
  var url = "./ajax.php";
  url = url+"?dw=prodinfo&pid="+pid;
  url = url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=function() {


    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 


      document.getElementById("prodinfo").innerHTML = url_decode(xmlHttp.responseText);
      updateimage(pid);
      document.getElementById("pid").value = pid;
    } 
  } 
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  if(current!=''){
    document.getElementById('thelink'+current).style.color = '';
  }
  document.getElementById('thelink'+thei).style.color = '#0000FF';
  document.getElementById('thelink'+thei).blur();
  document.getElementById('theimglink'+thei).blur();
  current = thei;
}

function updateimage(pid) {

  xmlHttp = GetXmlHttpObject();
  var url = "./ajax.php";
  url = url+"?dw=prodimage&pid="+pid;
  url = url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=function () {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
      document.getElementById("prodimage").src = url_decode(xmlHttp.responseText);
    } 
  } 
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);

}
function calculate_area(pid,width,length) {

      xmlHttp = GetXmlHttpObject();
      var url = "./ajax.php?dw=calculatearea";
      url = url+"&pid="+pid+"&roomwidth="+width+"&roomlength="+length;
      url = url+"&sid="+Math.random();
      xmlHttp.onreadystatechange=function () {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
          document.getElementById("roomarea").value = xmlHttp.responseText;
        } 
      } 
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);

}

function checkamountrequired() {

  if( document.getElementById("productamount").value != "" ) {
    return true;
  }
  else {
    alert("You need to calculate the amount needed, or enter the amount required before going to the checkout.");
    return false;
  }

} 

function checkcolour() {

  var form = document.forms.buyonline2;

  for($i=0; $i<form.elements.length; $i++) {
    
    param = form.elements[$i];
    if( param.checked ) { return true; }
    
  }

  alert("No Colour was selected. Please choose a colour before continuing.");
  return false;

}

function samplecheckform() {

  var form = document.forms.sampleform;

  if( form.fname.value.length < 1 ) {
    alert("Please ensure your First Name is filled in!");
    return false;
  }
  if( form.sname.value.length < 1 ) {
    alert("Please ensure Surname is filled in!");
    return false;
  }
  if( form.address1.value.length < 1 ) {
    alert("Please ensure Address 1 is filled in!");
    return false;
  } 
  if( form.city.value.length < 1 ) {
    alert("Please ensure City is filled in!");
    return false;
  }
  if( form.postcode.value.length < 1 ) {
    alert("Please ensure Postcode is filled in!");
    return false;
  }
  if( form.email.value.length < 1 ) {
    alert("Please ensure Email is filled in!");
    return false;
  }
  if( form.telephone.value.length < 1 ) {
    alert("Please ensure Telephone is filled in!");
    return false;
  }

}

function checkcheckout() {

  var form = document.forms.theform;
  if( form.clienttelephone.value.length < 1 ) {
    alert("Please ensure Telephone is filled in.");
    return false;
  }
  if( form.clientaddress1.value.length < 1 ) {
    alert("Please ensure Address is filled in.");
    return false;
  }


}

function select_thumb(newImg,newSize,newAlt) {
 
  var newBigImg = '<img src="'+newImg+'" '+newSize+' alt="'+newAlt+'"/>';
  document.getElementById("galleryimg").innerHTML = newBigImg;

}

function openclose(obj) {
  
  if( document.getElementById(obj).style.display == "none" ) {
    document.getElementById(obj).style.display = "block";
  }
  else {
    document.getElementById(obj).style.display = "none";
  }

}