
function checkSelect(fieldObj)
{
	var errIds =""
	
	if (fieldObj.selectedIndex != 0) 		
	{	
		return true;
	}
	else
		return false;
}

function checkRadio(fieldObj)
{
	var i = 0;
	// iterate through all the radio items
	i=0;
	while (i < fieldObj.length)
	{
		if (fieldObj[i].checked == true)
			return true;
		i++;
	}
	return false;
}

function checkCheckbox(fieldObj)
{
	if (fieldObj.checked)
		return true;
	else
		return false;
}

function checkText(fieldObj)
{
	if (fieldObj.value=="") 			
		return false;
	else
		return true;
}

function EmailError(EmailAddress) {
	var errorMsg = "";
	var intPos;
//	alert( EmailAddress.value);
	if ( EmailAddress.value != "" ) {		
	
		intPos = EmailAddress.value.indexOf("@");
		if (intPos != -1) {
			// check for @ at the beginning or the end 
			if ( intPos == 0 ) {
				errorMsg = errorMsg + "The '@' symbol cannot be the first symbol" 
						+ " in the email address.\n"
						+ "Typically, the account name of the receipient precedes"
						+ " the '@' symbol, e.g. Name@InternetService.com.";
			}
			else if ( intPos == (EmailAddress.value.length - 1)) {
				errorMsg = errorMsg + "The '@' symbol cannot be the last symbol" 
						+ " in the email address.\n"
						+ "Typically, the domain of the mail server follows"
						+ " the '@' symbol, e.g. Name@InternetService.com.";		
			}
			// check for more than one @
			if ( EmailAddress.value.indexOf("@", intPos+1) != -1 ) {
				errorMsg = errorMsg + "There is only ONE '@' symbol allowed in a valid"
						+ " email address.\n"
						+ "Typically, the domain of the mail server follows"
						+ " the '@' symbol, e.g. Name@InternetService.com.";	
			}
			
			//check for a .after@
			
			i=0;
			for(i=0;i< EmailAddress.value.length;i++){
			
				if ( EmailAddress.value.indexOf("@",i)==-1){
					i=i+1;
					if (EmailAddress.value.indexOf(".",i+1)==-1)
					
					errorMsg = errorMsg + "The typical format for an email is Name@InternetService.com.";
					break;	
						
					}
								
			}									
						
			// check for ,
			if ( EmailAddress.value.indexOf(",") != -1) {
				errorMsg = errorMsg + "There are no commas allowed in a valid email address.";
			}
			// check for ;
			if ( EmailAddress.value.indexOf(";") != -1) {
				errorMsg = errorMsg + "There are no semicolons allowed in a valid email address.";
			}
			// check for . at the beginning
			if ( EmailAddress.value.charAt(0) == '.' ) {
				errorMsg = errorMsg + "The first character of an email address cannot be a dot.";
			}
			// check for . at the end
			if ( EmailAddress.value.charAt(EmailAddress.value.length - 1) == '.'){
				errorMsg = errorMsg + "The last character of an email address cannot be a dot.";		
			}
		}	
		else {
			errorMsg = errorMsg + "The typical format for an email is Name@InternetService.com.";	
		}		
	}	
		return errorMsg;			
}	

function trim(field)
{	
	if(field.value != "")
	{
		// left trim
		while(field.value.charAt(0) == " ")
		{
			field.value = field.value.substring(1,field.value.length);
		}
	
		// right trim
		while(field.value.charAt(field.value.length-1) == " ")
		{
			field.value = field.value.substring(0,field.value.length-1);
		}
	} // end if 
} // end trim

function confirmPwd(form)
{			

	var pw,cpw;var m="";
	if (form.Password)
	{
		pw = form.Password.value;
		cpw = form.confirm.value;
		if (pw != cpw) 
		{
			m="Please enter Confirm Password correctly.\n"
		}
	}
	return m;
}  

function selectList(fieldObj, item)
{
	if (fieldObj)
	{
		var i = 0;
		while (i < fieldObj.options.length)
		{
			if (fieldObj.options[i].value == item)
			{
				fieldObj.options[i].selected = true;
				return;
			}
			i++;
		}
	}
}

function selectRadio(fieldObj, item)
{
	if (fieldObj)
	{
		var i = 0;
		while (i < fieldObj.length)
		{
			if (fieldObj[i].value == item)
			{
				fieldObj[i].checked = true;
				return;
			}
			i++;
		}
	}
}


function blockKey(evt, keys) {
	var returnVal = true;
	var i;
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    for (i = 0; i < keys.length; i++) {
		if (charCode == keys[i]) {
		    returnVal =  false;
		}
	}
	return returnVal;
}

function setupErrorStr(errors) {
	var j = 0;
	var eList = "";
	
	if (errors.length == 1)
	{
		// only one argument
		eList = "question " + errors[0] + ".";
	}
						
	if ( errors.length == 2)
	{
		// only one and two
		eList = "questions " + errors[0] + " and " + errors[1] + ".";
	}
	
	if ( errors.length > 2)
	{
		eList = "questions "						
		while (j < errors.length)
		{				
			// many more arguments
			if (j < errors.length-1)
			{
				// not last argument
				eList = eList + errors[j] + ", ";
			}
			else
			{
				// last argument
				eList = eList + "and " + errors[j] + ".";
			}									
			j++;
							
		} // end while j < errors.length
	}	
	return eList;						
}


function LTrim(expression)
{
	while (expression != "" && expression.substring(0,1) == " ")
		expression = expression.substring(1, expression.length);
		
	return expression;
}
function RTrim(expression)
{
	while (expression != "" && expression.substring(expression.length -1,expression.length) == " ")
		expression = expression.substring(0, expression.length -1);
	return expression;
}
function trim(expression)
{
	return LTrim(RTrim(expression));
}

function isNum(expression)
{
	var returnVal = true;
	var i;
	var ch;
	var charCode;
	
    for (i = 0; i < expression.length; i++) {
		ch = expression.substring(i, i+1);
		if (isNaN(parseInt(ch))) {
		    returnVal =  false;
		}
	}	
	return returnVal;
}


