function changeImage(inid,inpath){
    var iElement=document.getElementById(inid);
    iElement.src="/management/phpThumb/phpThumb.php?src="+inpath+"&w=240&h=240&zc=1";
}

function checkContactForm(){
    if (document.getElementById("name").value==""){
        alert("You need to enter your name.");
        document.getElementById("name").focus();
        return false;
    }else if (document.getElementById("email").value==""){
        alert("You need to enter your email address.");
        document.getElementById("email").focus();
        return false;
    }else if(echeck(document.getElementById("email").value)==false){
        alert("Email address entered is invalid.");
        document.getElementById("email").focus();
        return false;
    }else if (document.getElementById("telephone").value==""){
        alert("You need to enter your telephone number.");
        document.getElementById("telephone").focus();
        return false;
    }else if (document.getElementById("contact_pref_email").checked=="false" && document.getElementById("contact_pref_telephone").checked=="false"){
        alert("You need to select a preferred contact method.");
        document.getElementById("contact_pref_email").focus();
        return false;
    }else if (document.getElementById("contact_time").value=="0"){
        alert("You need to select the best time for us to contact you.");
        document.getElementById("contact_time").focus();
        return false;
    }else if (document.getElementById("hear_about").value=="0"){
        alert("You need to select where you heard about us.");
        document.getElementById("hear_about").focus();
        return false;
    }else if (document.getElementById("service_start").value=="0"){
        alert("You need to select when you want the service to start.");
        document.getElementById("service_start").focus();
        return false;
    }else if (document.getElementById("driveways").checked==false&&document.getElementById("driveways").checked==false&&document.getElementById("gutters").checked==false&&document.getElementById("conservatories").checked==false&&document.getElementById("commercial").checked==false&&document.getElementById("warehouses").checked==false&&document.getElementById("garage_forecourts").checked==false&&document.getElementById("public_houses").checked==false&&document.getElementById("other").checked==false){
        alert("You need to select what product or service you require.");
        document.getElementById("driveways").focus();
        return false;
    }
}

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