// JavaScript Document
function verify_brandname(input)
{
	var error="";
	if(input==""){
		error="You didn't input Brand Name or Model No or Part No!\n";
	}
	return error;
}

function verify_numericvalue(input)
{
	var error="";
	if(input==""){
		error="Stock quantity and Price can not be blank!\n";
	}
	var illcharacter=/[^0-9]/;
	if(illcharacter.test(input)){
		error="You should type only numeric values as stock quantity and price!\n";
	}
	return error;
}


function verify_email(email){
	var error="";
	if(email==""){
		error="You did not enter an email address!\n";
	}

	var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(email))) {
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (email.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;
}


/*
function verify_subject(subj,inquiry){
	var error="";
	if(subj==""){
		error="You did not enter subject!\n";
	}
	
	if(inquiry==""){
		error="You did not enter your inquiry!\n";
	}
	
	return error;
}
*/


function verify_address(addr){
	var error = "";
	if(addr == ""){
		error="You did not enter an address!\n";
	}
	if(addr.length > 50){
		error="Address length can not exceed 50 characters!\n";
	}
	return error;
}


function verify_contactno(contact){
	var error="";
	if (contact == ""){
		error="You did not enter your contact no!\n";
	}

//strip out acceptable non-numeric characters
	var stripped = contact.replace(/[\(\)\.\-\ ]/g, '');
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";

    }
    if (!(stripped.length == 10)) {
	    error = "The phone number is the wrong length. Make sure you included an area code.\n";
    }
	return error;
}



function verify_username(user){
	var error = "";
	if (user == "") {
	   error = "You didn't enter a username.\n";
	}
		var illegalChars = /\W/; // allow letters, numbers, and underscores
		if ((user.length < 6) || (user.length > 10)) {
		   error = "The username is the wrong length. It must be 6-10 characters.\n";
		}
		else if (illegalChars.test(user)) {
			error = "The username contains illegal characters.\n";
		}
	return error;

}

function verify_password (strng) {
	var error = "";
	if (strng == "") {
	   error = "You didn't enter a password.\n";
	}
		var illegalChars = /[\W_]/; // allow only letters and numbers
		if ((strng.length < 6) || (strng.length > 8)) {
		   error = "The password is the wrong length. It must be 6-8 characters.\n";
		}
		
		if (illegalChars.test(strng)) {
		  error = "The password contains illegal characters.\n";
		}
		
		var testchar = /[a-z]/;
		if (!(testchar.test(strng))){
		   error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
		}
		
		var testch = /[A-Z]/;
		if(!(testch.test(strng))){
			error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
		}
		
		var testc = /[0-9]/;
		if(!(testc.test(strng)))
		{
			error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
		}
	return error;
}

