
function switchMenu(obj)
{
	var el = document.getElementById(obj);
	if ( el.style.display != "none" )
	{
		el.style.display = 'none';
	}
	else
	{
		el.style.display = '';
	}
}
function SwapImage1(objt)
{
	var checka=document.getElementById(objt).src;

	if(checka.substring(checka.length-22) == "images/expand_icon.gif")
	{
		document.getElementById(objt).src="images/unexpand_icon.gif";
	}
	else
	{
		document.getElementById(objt).src="images/expand_icon.gif";
	}
}
function validatecheckoutFormOnSubmit(theform)
{
	if(theform.terms.checked == true)
	{
		return true;
	}
	else
	{
	    alert("You must accept our terms and condidtions before procedding.\n");
	    return false;
	}
}
function validatenewdeliveryFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.delname);
  reason += validateEmpty(theForm.delcode);
  reason += validateNumber(theForm.delprice);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}
function validatecontactFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.email);
  reason += validateEmpty(theForm.name);
  reason += validateEmpty(theForm.comments);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}

function validatecheckoutAddressFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.b_fname);
  reason += validateEmpty(theForm.b_sname);
  reason += validateEmpty(theForm.b_building);
  reason += validateEmpty(theForm.b_add1);
  reason += validateEmpty(theForm.b_city);
  reason += validateEmpty(theForm.b_pcode);

  reason += validateEmpty(theForm.d_fname);
  reason += validateEmpty(theForm.d_sname);
  reason += validateEmpty(theForm.d_building);
  reason += validateEmpty(theForm.d_add1);
  reason += validateEmpty(theForm.d_city);
  reason += validateEmpty(theForm.d_pcode);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}

function validatecategoryFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.catname);
  reason += validateEmpty(theForm.catdesc);
  reason += validateEmpty(theForm.catimage);
  reason += validateNonRequiredNumber(theForm.catpri);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}

function validateeditcategoryFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.catname);
  reason += validateEmpty(theForm.catdesc);
  reason += validateNonRequiredNumber(theForm.catpri);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}

function validatenewcolourFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.colourname);
  reason += validateNonRequiredNumber(theForm.colourpri);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}
function validatenewmaterialFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.materialname);
  reason += validateNonRequiredNumber(theForm.materialpri);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}
function validatenewfinishFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.finishname);
  reason += validateNonRequiredNumber(theForm.finishpri);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}
function validatenewsizeFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.sizename);
  reason += validateNonRequiredNumber(theForm.sizepri);
  reason += validateNumber(theForm.sizeheight);
  reason += validateNumber(theForm.sizewidth);
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}
function validatenewuserFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.userfname);
  reason += validateEmpty(theForm.usersname);
  reason += validateEmpty(theForm.userbuilding);
  reason += validateEmpty(theForm.useradd1);
  reason += validateEmpty(theForm.userpcode);
  reason += validateEmpty(theForm.userreferer);
  reason += validateEmail(theForm.useremail);
  reason += validateEmail(theForm.useremail_confirm);
  
  if(theForm.useremail.value != theForm.useremail_confirm.value)
  {
  	reason += "Email addresses don't match\n";
        theForm.useremail.style.background = '#FA5858'; 
        theForm.useremail_confirm.style.background = '#FA5858'; 
  }
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}
function validatenewclientFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.firstname);
  reason += validateEmpty(theForm.surname);
  reason += validateEmpty(theForm.add1);
  reason += validateEmpty(theForm.add2);
  reason += validateEmpty(theForm.add6);
  reason += validateEmpty(theForm.referer);
  reason += validateEmail(theForm.email1);
  reason += validateEmail(theForm.email2);
  reason += validatePassword(theForm.pass1);
  reason += validatePassword(theForm.pass2);
  
  if(theForm.email1.value != theForm.email2.value)
  {
  	reason += "Email addresses don't appear to match\n";
        theForm.email1.style.background = '#FA5858'; 
        theForm.email2.style.background = '#FA5858'; 
  }
      
        
if(theForm.pass1.value != theForm.pass2.value)
{
	reason += "Passwords don't appear to match\n";
      theForm.pass1.style.background = '#FA5858'; 
      theForm.pass2.style.background = '#FA5858'; 
}
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}
function validateupdateclientFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.firstname);
  reason += validateEmpty(theForm.surname);
  reason += validateEmpty(theForm.add1);
  reason += validateEmpty(theForm.add2);
  reason += validateEmpty(theForm.add6);
  reason += validateEmail(theForm.email1);
  reason += validateEmail(theForm.email2);
  
  if(theForm.email1.value != theForm.email2.value)
  {
  	reason += "Email addresses don't appear to match\n";
        theForm.email1.style.background = '#FA5858'; 
        theForm.email2.style.background = '#FA5858'; 
  }
      
    
      
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}

function validatenewitemFormOnSubmit(theForm) {
var reason = "";

  reason += validateEmpty(theForm.itemtitle);
  reason += validateEmpty(theForm.itemshortcode);
  reason += validateNumber(theForm.itemprice);
  reason += validateNumber(theForm.itemweight);
  reason += validateNumber(theForm.itemqnty);
  reason += validateEmpty(theForm.itemdesc);
  reason += validateEmpty(theForm.itemimage);
  reason += validateEmpty(theForm.itemdeliverytype);
  reason += validateEmpty(theForm.itemcolour);
  reason += validateEmpty(theForm.itemfinish);
  reason += validateEmpty(theForm.itemmaterial);
  reason += validateEmpty(theForm.itemcategory);
  reason += validateEmpty(theForm.itemsize);
  
  if (reason != "") {
    alert("Error submitting form:\n" + reason);
    return false;
  }

  return true;
}


function validateNumber(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = '#FA5858'; 
        error = "The required field has not been filled in.\n"
    } else if (isNaN(parseInt(fld.value))) {
        fld.style.background = '#FA5858'; 
        error = "The required field must be numeric.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}
function validateNonRequiredNumber(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = 'White';
        return error;
    }
    
    if (isNaN(parseInt(fld.value))) {
        fld.style.background = '#FA5858'; 
        error = "The field must be numeric.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}


function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = '#FA5858'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = '#FA5858';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FA5858';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FA5858';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#FA5858'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = '#FA5858'; 
        error = "The username must be between 5 and 15 characters.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#FA5858'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}
function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#FA5858';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password must be between 7 and 15 characters. \n";
        fld.style.background = '#FA5858';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = '#FA5858';
    } else {
        fld.style.background = 'White';
    }
   return error;
}   


function submitjobform()
{
  document.jobdata.submit();
}


function chkstr(chk, str)
{
	str.value = "";

	if(chk.checked == true)
		{
			str.disabled = false;
			str.focus();
		}
	else
		str.disabled = true;
}