

function validate(  ){

    retval = false;
    errors = false;

    var aErrors = new Array();
    var enquiry = document.forms[0];

   document.getElementById("name").style.color = "#00346D";
   document.getElementById("email").style.color = "#00346D";
   document.getElementById("telephone").style.color = "#00346D";

    if ((enquiry.name.value == null)  ||  enquiry.name.value == '' ){
            errors = true;
            aErrors.push("name");
     }

    if ( ((enquiry.contactEmail.value == null ) || enquiry.contactEmail.value=='') &&
         ((enquiry.tel.value == null ) || enquiry.tel.value =='' )  ) {

          errors = true;
          if (enquiry.contactEmail.value == null  || enquiry.contactEmail.value==''){
              aErrors.push("email");
          }
          if(enquiry.tel.value == null  || enquiry.tel.value ==''   ){
             aErrors.push("telephone");
          }
    }
    else{

        if ( (enquiry.contactEmail.value != null ) && enquiry.contactEmail.value !='' ){
             var email = enquiry.contactEmail.value;


            if( email.indexOf('@')== -1 ){
                errors = true;
                aErrors.push("email");
            }
             if( email.indexOf('.') == -1){
                errors = true;
                aErrors.push("email");
            }

        }

        if ((enquiry.tel.value != null ) && (enquiry.tel.value != '') ){
            tel = enquiry.tel.value;

            if( (isNaN(tel.replace(/ /, ""))) || (tel.length <6 || tel.length>14) ) {
                              errors = true;
                              aErrors.push("telephone");
            }
        }
    }

    for( loop=0; loop< aErrors.length; loop=loop+1 ) {

            document.getElementById(aErrors[loop]).style.color = "#990000";
        }
        //alert(  getValidationString( errors ));

        var problemsDIV = document.getElementById("problems");


           problemsDIV.style.backgroundColor="#ffffff";

        problemsDIV.innerHTML =  getValidationString( errors );


        if(aErrors.length == 0 ){
         retval = true;
        }

    return retval;
}

  function getValidationString( errors ){

   var  strVal = '';
   var  strValidation = '';

            if ( errors == true ) {
         strVal =  'Errors exist .. Please retry';



        document.getElementById("problems").style.color = "#990000";
        document.getElementById("problems").style.backgroundColor="#ffffff";

        strValidation =  '&nbsp;<img src=\"images/cross.gif\" width=\"11\" height=\"9\" />&nbsp;&nbsp;'
        strValidation += strVal;

     }
     else{
         strValidation =  '&nbsp;<img src=\"images/tick.gif\" width=\"12\" height=\"10\" /> &nbsp;&nbsp;';
         strValidation += 'Thankyou for your enquiry.';

         document.getElementById("problems").style.color = "#336699";

     }

     return  strValidation
}

 function openTransferTariffWindow( ){

  var win = window.open('transfers.htm','Transfers', 'width=525,height=550,left=125,top=55');
  win.focus();

  /*, 'Stock Enquiry', 'width=600,height=650,right=60,top=30');*/

}




