

// email
function checkEmail(strng) 
{
	error = false;
	if (strng == "") 
	{
   		error = true;
	}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) 
	{ 
       error = true;
    }
    else 
	{
		//test email for illegal characters
        var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (strng.match(illegalChars)) 
		{
        	error = true;
        }
    }
	return error;    
}


// phone number - strip out crap and check for 10 digits

function checkPhone(strng) 
{
	error = false;
	if (strng == "") 
	{
	    error = true;
	}
	
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) 
	{
		error = true;
	}
	if (!(stripped.length == 10)) 
	{
		error = true;
	} 
	return error;
}


// password - between 6-8 chars, uppercase, lowercase, and number

function checkPassword(strng) 
{
	error = false;
	if (strng == "") 
	{
	   error = true;
	}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) 
	{
       error = true;
    }
    else if (illegalChars.test(strng)) 
	{
      error = true;
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) 
	{
       error = true;
    }  
	return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername(strng) 
{
	error = false;
	if (strng == "") 
	{
	   error = true;
	}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) 
	{
       error = true;
    }
    else if (illegalChars.test(strng)) 
	{
    	error = true;
    } 
	return error;
}       


// non-empty textbox

function isEmpty(strng) 
{
	error = false;
	if (strng.length == 0) 
	{
		error = true;
	}
	return error;	  
}

// textbox is not empty and contains numbers only

function isNumber(strng) 
{
	error = false;
	if (strng.length == 0) 
	{
		error = true;
	}
	var numericExpression = /^[0-9]+$/;
    if (strng.search(numericExpression) == -1) 
	{
       error = true;
    }  
	return error;	  
}


// was textbox altered

function isDifferent(strng) 
{
	error = false;
	if (strng != "Can\'t touch this!") 
	{
		error = true;
	}
	return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) 
{
	error = false;
	if (!(checkvalue)) 
	{
    	error = true;
    }
	return error;
}

// valid selector from dropdown list

function checkDropdown(choice) 
{
	error = false;
    if (choice == 0 || choice == "0" || choice == "novalue") 
	{
    	error = true;
    }    
	return error;
}


// valid selector from dropdown list with multiple bad indices

function checkDropdownMultipleIndices(choice, indexarray) 
{
	error = false;
    if (choice == 0 || choice == "0" || choice == "novalue") 
	{
    	error = true;
    }
	for(i=0; i<indexarray.length;i++)
	{
		if (choice == indexarray[i])
		{
			error = true;
		}
	}
	return error;
}
