function toggleDivs(divid){
  if (document.getElementById(divid).style.display=="none"){
    document.getElementById(divid).style.display="block";
  }else if (document.getElementById(divid).style.display=="block"){
    document.getElementById(divid).style.display="none";
  }
}

function checkTcs(){
  if(document.getElementById("email").value==false){
    alert("Please enter an email address.");
    document.getElementById("email").focus();
    return false;
  }else if (echeck(document.getElementById("email").value)==false){
    alert("The email address you have entered is not a valid email.");
    document.getElementById("email").focus();
    return (false);
  }else if (document.getElementById("security_code").value==false){
    alert("Please enter the security code.");
    document.getElementById("security_code").focus();
    return (false);
  }else if(document.getElementById("agree").checked==false){
    alert("You must agree to be contacted by Argyle Sports and Work Wear Ltd.");
    document.getElementById("agree").focus();
    return false;
  }
}


function getAjax(inid, infunction,field1, value1){
  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;
      }
    }
  }                   
  
  xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){
      document.getElementById(inid).innerHTML=xmlHttp.responseText;
              
    }
  }        
  xmlHttp.open("GET",infunction+"?"+field1+"="+value1,true);
  xmlHttp.send(null);
}

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){
    return false;
  }else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    return false;
  }else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    return false;
  }else if (str.indexOf(at,(lat+1))!=-1){
    return false;
  }else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    return false;
  }else if (str.indexOf(dot,(lat+2))==-1){
    return false;
  }else if (str.indexOf(" ")!=-1){
    return false;
  }else{
    return true;
  }	
}

function checkSingle(divid, message){
  if (document.getElementById(divid).value==""){
    alert(message);
    document.getElementById(divid).focus();
    return (false);
  }
}

function checkSingleEmail(divid, message){
  if (document.getElementById(divid).value==""){
    alert(message);
    document.getElementById(divid).focus();
    return (false);
  }else if (echeck(document.getElementById(divid).value)==false){
    alert("The email entered is not a valid email address.");
    document.getElementById(divid).focus();
    return (false);
  }
}

function confirmBox(inmessage){
  var answer=confirm(inmessage)
  return (answer);
}

function defaultText(startphrase,inputbox,status){
  if (status=="on"){
    if (document.getElementById(inputbox).value==startphrase){
      document.getElementById(inputbox).style.color="#000000";
      document.getElementById(inputbox).value="";
    }
  }else{
    if (document.getElementById(inputbox).value==""){
      document.getElementById(inputbox).style.color="#999999";
      document.getElementById(inputbox).value=startphrase;
    }
  }
}

function checkRegDefault(){
  if (document.getElementById("reg_first_name").value=="First Name"){
    alert("You must enter a contact first name.");
    document.getElementById("reg_first_name").value="";
    document.getElementById("reg_first_name").focus();
    return (false);
  }else if (document.getElementById("reg_last_name").value=="Last Name"){
    alert("You must enter a contact last name.");
    document.getElementById("reg_last_name").value="";
    document.getElementById("reg_last_name").focus();
    return (false);
  }else if (document.getElementById("reg_county").value==""){
    alert("You must select a county.");
    document.getElementById("reg_county").focus();
    return (false);
  }else if (document.getElementById("reg_postcode").value==""){
    alert("You must enter your postcode.");
    document.getElementById("reg_postcode").focus();
    return (false);
  }else if (document.getElementById("reg_email").value==""){
    alert("You must enter your email address.");
    document.getElementById("reg_email").focus();
    return (false);
  }else if (echeck(document.getElementById("reg_email").value)==false){
    alert("The email entered is not a valid email address.");
    document.getElementById("reg_email").focus();
    return (false);
  }else if (document.getElementById("reg_username").value==""){
    alert("You must choose a username.");
    document.getElementById("reg_username").focus();
    return (false);
    }else if (document.getElementById("reg_username").value.length<=5){
    alert("Your username must be between 6 and 12 characters in length.");
    document.getElementById("reg_username").focus();
    return (false);
  }else if (document.getElementById("reg_password").value==""){
    alert("You must enter a password.");
    document.getElementById("reg_password").focus();
    return (false);
   }else if (document.getElementById("reg_password").value.length<=5){
    alert("Your password must be between 6 and 12 characters in length.");
    document.getElementById("reg_password").focus();
    return (false);
  }else if (document.getElementById("reg_password2").value==""){
    alert("You must retype your password.");
    document.getElementById("reg_password2").focus();
    return (false);
  }else if (document.getElementById("reg_password").value!=document.getElementById("reg_password2").value){
    alert("Your typed passwords do not match.");
    document.getElementById("reg_password2").focus();
    return (false);
  }else if (document.getElementById("reg_security_answer").value==""){
    alert("You must enter an answer to the security question.");
    document.getElementById("reg_security_answer").focus();
    return (false);
  }
}

function checkForm(){
  if (document.getElementById("lgn_user").value==""){
    alert("You must enter a username.");
    document.getElementById("lgn_user").focus();
    return (false);
  }else if (document.getElementById("lgn_pass").value==""){
    alert("You must enter a password.");
    document.getElementById("lgn_pass").focus();
    return (false);
  }
}

function letternumber(e)
{
  var key;
  var keychar;
  
  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
     return true;
  keychar = String.fromCharCode(key);
  keychar = keychar.toLowerCase();
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
      (key==9) || (key==13) || (key==27) )
     return true;
  
  // alphas and numbers
  else if ((("abcdefghijklmnopqrstuvwxyz0123456789-_.").indexOf(keychar) > -1))
     return true;
  else
     return false;
}

function telnumber(e)
{
  var key;
  var keychar;
  
  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
     return true;
  keychar = String.fromCharCode(key);
  keychar = keychar.toLowerCase();
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
      (key==9) || (key==13) || (key==27) )
     return true;
  
  // alphas and numbers
  else if ((("0123456789 ").indexOf(keychar) > -1))
     return true;
  else
     return false;
}

function floatprice(e)
{
  var key;
  var keychar;
  
  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
     return true;
  keychar = String.fromCharCode(key);
  keychar = keychar.toLowerCase();
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
      (key==9) || (key==13) || (key==27) )
     return true;
  
  // alphas and numbers
  else if ((("0123456789 .").indexOf(keychar) > -1))
     return true;
  else
     return false;
}
