//This function takes in the form field as well as string name for this field.  It checks the length of the form field
//to make sure that it is not blank.  If it is, it returns a string that will be concatenated to the errmsg on the //requesting page, //else it returns a null string.
function checkMandatory(field, str)
{
	if(field.value.length==0)
	{
		return str + " is required.\n";
	}
	else
	{
		return "";
	}
}

function checkNumber(field, str)
{

	if(isNaN(field.value) && field.value != "")
	{
		return str + " must be a number.\n";
	}
	else
	{
		return "";
	}
}


function checkPhone(area, pre, post, str)
{
	if(area.value.length==0 || pre.value.length==0 || post.value.length==0)
	{
		return str + " is required.\n";
	}
	else
	{
		return "";
	}
}

//This functions takes in the email form field from the requesting page.  It checks for the location of the @ and . in the 
//address as well as checks for blank spaces.  If the email address has an error, the function returns a error string, else it
//will return a null string.
function checkEmail(field, strMsg) {

	var strValue = field.value;
	var emailReg = "^[\\w-\.]*[\\w\.]\@[\\w-\.]+[\.]+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);

	if (regex.test(strValue) == false && strValue.length > 0) { 
		return strMsg;
	} else {
		return "";
	}
	
}
 

//This function takes in the form field from the requesting page.  It comapares the string against illegal characters and 
//will return 
function hasIllegalCharacters(field)
{
	illegal_string="!#$%^&*()?:;,+.";

	var the_char="";
	
	for (var loop=0; loop < illegal_string.length; loop++)
	{
		the_char = illegal_string.charAt(loop);
		if(field.indexOf(the_char) != -1)
		{
			return "Please NO periods, dollar signs or commas in Revenue field.\n";
		}
	}
	return "";
}

function tooBig(field, value)
{
	if(field.length > value)
	{
		return "Overview contains too many characters.\n";
	}
	else
	{
		return "";
	}
}

function matchPwds(pwd1,pwd2)
{
	if(pwd1 != pwd2)
	{
		return "Your passwords do not match.\n";
	}
	else
	{
		return "";
	}
}

function isValidURL(str,blnRequired)
{
        if (isEmpty(str) && (blnRequired))
		{ 
			return "Invalid URL.\n";
		}
        if (!isEmpty(str))
		{
               if (str.search(" ") > -1)
			   { 
			   		return "Invalid URL.\n";
			   }
               if (str.search(/\./) == -1)
			   { 
			   		return "Invalid URL.\n"; 
			   }
               for(i=0;i<=str.length;i++)
			   { 
			   		if(str.charCodeAt(i) > 128)
					{ 
						return "Invalid URL.\n"; 
					} 
			   }
        }
		
        // List of invalid extensions separated by "|"
		
        var strArray = "avi|css|doc|exe|gif|jpeg|jpg|js|mpg|mpeg|pdf|swf|rar|rtf|wav|zip";
        var extArray = strArray.split("|");
		
		for (var i=0; i < extArray.length; i++)  
		{
               if (str.substring(str.length-extArray[i].length-1, str.length) == "."+extArray[i]) 
			   {
                       return "Invalid URL.\n";
               }
        }
        return "";
}
 
function isEmpty(str)
{
	if (str.length <=0)
	{
		return true;
	}
	else 
	{
		return false;
	}
}



function checkPwdSize(field)
{
	if (field.length < 5 )
	{
		return "Your password must be longer than 6 characters.\n";
	}
	else
	{
		return "";
	}
}

function checkScrollableList(field, str)
{
	if (field.selectedIndex<0)
	{
		return str + " needs to be selected.\n";
	}
	
	else
	{
		return "";
	}
}

function checkIsNumber(field, str)
{
	if(isNaN(field))
	{
		return str + " must be a number.\n";
	}
	
	else
	{
		return "";
	}
}


function checkChkBox(field, str)
{
	var count;
	count=0;
	
	if (field.length > 1) {
		for(var i=0; i<field.length; i++)
		{
			if(field[i].checked)
			{
				count++;
			}
		}
	} else {
		if(field.checked) {
			count++;
		}
	}
	
	
	if(count <= 0)
	{
		return str;
	}
	else
	{
		return "";
	}
	
}

function checkRadio(field, str)
{
	var count = 0;

	if (field.length > 1) {
		for(var i=0; i<field.length; i++)
		{
			if(field[i].checked)
			{
				count++;
			}
		}
	} else {
		if(field.checked)
			{
				count++;
			}
	}
	
	
	if(count <= 0)
	{
		return str;
	}
	else
	{
		return "";
	}
	
}


function checkForNone(field, str)
{
	var none = false;
	var count;
	count = 0;
	for(var i=0; i<field.length; i++)
	{
		if(field[i].value =="" && field[i].checked)
		{
			 none=true;
		}
		
		if(field[i].checked)
		{
			count++;
		}
	}
	if (none==true && count > 1)
	{
		return str;
	}
	else
	{
		return "";
	}
}
 
function checkDate(strMonth, strDay, strYear)
{

	var strDateStr = strMonth + '/' + strDay + '/' + strYear;
	var dDate = new Date( strDateStr );
	var strMonth2 = dDate.getMonth() + 1;
	
	if ( strMonth2 != strMonth ) 
	{
 	 return '"' + strDateStr + '" is NOT a valid date.\n';
	} 
	else 
	{
 	 return  '';
	}
} 


function count_text(e,lmax, str){	
	if(e.value.length > lmax) 	{
	
		alert(str);	
		e.value = e.value.substr(0,lmax);

	}
}