function isNotNULL2(a,b){
	a = trimString(a.value);
	if (a.length==0)
		return b;
	return '';
}

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function isDropDownSelected2(a,b,isFirstValid){
	var compareWith = (isFirstValid == 'yes')? 0 : 1;
		
	if (a.selectedIndex >= compareWith)
		return ''
	else
		return b;
}

function isValidEmail2(a, b, alsoCheckNULL){
	var v = trimString(a.value);
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (alsoCheckNULL == 'yes'){
		var err =  isNotNULL2(a,b);
		if (err.length > 0)
			return b;
			
	}

	if (!(emailFilter.test(v))) { 
       return b;
    }
    else {
		//test email for illegal characters
     	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (v.match(illegalChars)) {
          return b;
       }
    }
	return '';
}

function isValidLength2(a,b,m,alsoCheckNULL){
	var v = trimString(a.value);
	if (alsoCheckNULL == 'yes'){
		var err =  isNotNULL2(a,m);
		if (err.length > 0)
			return m;
			
	}
	if (v.length <= b)
		return m;
	return '';
}

function compareStrings(s1,s2,m){
	var s1 = trimString(s1.value);
	var s2 = trimString(s2.value);
	if (s1==s2)
	 	return '';
	 return m;
}

function isNotNULL(pvStrFormName, pvStrFieldName, pvStrErrMsg){
	var lLogRetVal = false;
	var pvStrData = document.forms[pvStrFormName].elements[pvStrFieldName].value;
		
	if(pvStrData.charAt(0) != " ")
	{
		if(pvStrData != "")
		{
			lLogRetVal = true;
		}
		else
		{
			return pvStrErrMsg;
		}
	}	
	else
	{
			return pvStrErrMsg;
	}
	return '';
}
function isDropDownSelected(pvStrFormName,pvStrFieldName, pvStrErrMsg, bIsFirstValid) 
{
	var objField = 	document.forms[pvStrFormName].elements[pvStrFieldName];
	var i_comparewith = 0
	
	if (bIsFirstValid == 'yes' )
		i_comparewith = 0
	else
		i_comparewith = 1;
	
	if (objField.selectedIndex >= i_comparewith)
		return ''
	else
		return pvStrErrMsg ;
}

function doComparePassword(pvStrFormName,pvStrPassword1, pvStrPassword2, pvStrErrMsg) 
{
	var from = document.forms[pvStrFormName].elements[pvStrPassword1];
	var to = document.forms[pvStrFormName].elements[pvStrPassword2];
	
	if (from.value == to.value) 
	{
		return '';
	}
	else 
	{
		return pvStrErrMsg
   	}
}

function isCheckBoxSelected(pvStrFormName,pvStrFieldName,pvStrErrMsg,iMin,iMax)
{

	var objField = document.forms[pvStrFormName].elements[pvStrFieldName];
	var chkcount = 0;
	if (objField.length) {
		for(i=0;i<objField.length;i++)
		{
			if (objField[i].checked == true)
				chkcount++;
		}
	}
	else{
		// there is only one checkbox
		if (objField.checked == true)
			chkcount++;
	}
	
	if(chkcount >= iMin)
	{
		
		if(iMax >= 0 && chkcount > iMax)
		{
			return pvStrErrMsg;
		}
		else
		{
			return '';
		}
	}
	else
	{
		return pvStrErrMsg;
	}
}

function isValidEmail(pvStrFormName, pvStrEmail, pvStrErrMsg, bAlsoCheckNULL)
{
	var objEmail = document.forms[pvStrFormName].elements[pvStrEmail].value;
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (bAlsoCheckNULL == 'yes'){
		var err_chknull =  isNotNULL(pvStrFormName, pvStrEmail, pvStrErrMsg);
		if (err_chknull.length > 0)
			return pvStrErrMsg;
			
	}
	if (!(emailFilter.test(objEmail))) { 
       return pvStrErrMsg;
    }
    else {
		//test email for illegal characters
     	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (objEmail.match(illegalChars)) {
          return pvStrErrMsg;
       }
    }
	return '';
}

function getSelectedRadioValue(pvStrFormName,pvStrFieldName)
{
	var objField = document.forms[pvStrFormName].elements[pvStrFieldName];

	for(var i = 1; i <= objField.length ; i++){
		if(objField[i - 1].checked == true)
			return objField[i-1].value;
	}
}

function isRadioSelected(pvStrFormName,pvStrFieldName,pvStrErrMsg)
{
	var objField = document.forms[pvStrFormName].elements[pvStrFieldName];
	var lflag = false;

	for(var i = 1; i <= objField.length ; i++)
		if(objField[i - 1].checked == true)
		{
			lflag = true;
		}
		
	if(lflag == true)
		return ''
	else
		return pvStrErrMsg;
}
