/*function isFieldBlank(fValue,fName)
{
	alert('isFieldBlank value = ' + fValue.value);
	if (fValue.value == "")
		{
		    alert("Please enter your "+fName+".");
			fValue.focus();
			return (true);
		}
}
*/
function isRadioChecked(fValue,fName)
{
if (!((fValue[0].checked)||(fValue[1].checked)))
		{
		    alert("Please specify whether "+fName+".");
			fValue[0].focus();
			return (true);
		}
}

function isTandCChecked(fValue)
{

	if (!(fValue.checked))
		{
		    alert("You must accept our Terms and Conditions");
			fValue.focus();
			return (true);
		}
}

function isInputFieldBlank(fValue,fName)
{
	if (Trim(fValue.value) == "")
		{
		    alert("Please enter your "+fName+".");
			fValue.focus();
			return (true);
		}
}

function isString(fValue,fName)
{
	
	var checkOK = "-'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzӨՀыʬۘęæ܃Ώ泝 \t\r\n\f";
		var checkStr = fValue.value;
		var allValid = true;
		
		for (var i = 0;  i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
	    
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
		}
		
		if (!allValid)
		{
		    alert("Please enter only letter and whitespace characters in the '"+fName+"' field.");
			fValue.focus();
			return (true);
		}
}

function isNumber(fValue,fName)
{
	
	var checkStr = Trim(fValue.value);
	
	if (checkStr.length < 8)
		{
		    alert("Please enter "+fName+".");
			fValue.focus();
			return (true);
		}
		
		var checkOK = "0123456789-+- \t\r\n\f";
		var allValid = true;
		
		for (i = 0;  i < checkStr.length;  i++)
		{
		    ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
					break;
					
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
		}

		if (!allValid)
		{
		    alert("Please enter "+fName+".");
			fValue.focus();
			return (true);
		}

}

function isEmail(fValue)
{

		var EmailOk  = true;
		var Temp     = Trim(fValue.value);
		var AtSym    = Temp.indexOf('@')
		var Period   = Temp.lastIndexOf('.')
		var Space    = Temp.indexOf(' ')
		var Length   = Temp.length - 1   // Array is from 0 to length-1

		if ((AtSym < 1) ||                     // '@' cannot be in first position
			(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
			(Period == Length ) ||             // Must be atleast one valid char after '.'
			(Space  != -1))                    // No empty spaces permitted
		{  
	      EmailOk = false
	      alert('Please enter a valid e-mail address!')
	      fValue.focus()
		  return (true);
		}
	
}

function isEmail2(fValue,fText)
{
	//alert('fText = ' + fText);
		var EmailOk  = true;
		var Temp     = fValue;
		var AtSym    = Temp.value.indexOf('@')
		var Period   = Temp.value.lastIndexOf('.')
		var Space    = Temp.value.indexOf(' ')
		var Length   = Temp.value.length - 1   // Array is from 0 to length-1

		if ((AtSym < 1) ||                     // '@' cannot be in first position
			(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
			(Period == Length ) ||             // Must be atleast one valid char after '.'
			(Space  != -1))                    // No empty spaces permitted
		{  
	      EmailOk = false
	      alert('Please enter a valid e-mail address!')
	      //alert('Please enter ' + fText);
	      Temp.focus()
		  return (true);
		}
	
}

function isSelected(fValue,fName)
{
	if (fValue.selectedIndex <= 0)
		{
		    alert("Please enter "+fName+".");
			fValue.focus();
			return (true);
		}    
}

function isSelectDepend(fValue,fValue2,fName)
{
if ((fValue.checked)&&(fValue2.selectedIndex < 0))
		{
		    alert("Please enter "+fName+ "Cheque Account Held.");
			fValue2.focus();
			return (true);
		} 
}

function isAgentNumber(fValue){
	if (fValue.value !=""){
		var myacc = Trim(fValue.value);
		var valid1 = myacc.search(/^[A-Za-z]\d{7}$/);
		var valid2 = myacc.search(/^[A-Za-z]\d{9}$/);
		if (valid1 != "0" & valid2 != "0")

		{
			alert("Please enter your Customer Number in the correct format\n(e.g A1234567, A123456789)\nwithout any special characters or spaces.");
			fValue.focus();
			return (true);
		}
		else
		{
			return (false);
		}
	}		
}

function isLDAPPassword(fValue,fName)
{
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var checkStr = fValue.value;
	var allValid = true;
		
	for (var i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
	    
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}
		
	if (!allValid)
	{
	    alert("Please enter only letter and number characters in the '"+fName+"' field.");
		fValue.focus();
		return (true);
	}
}

function isLoginEmail(fValue)
{

		var EmailOk  = true;
		var Temp     = Trim(fValue.value);
		var AtSym    = Temp.indexOf('@')
		var Period   = Temp.lastIndexOf('.')
		var Space    = Temp.indexOf(' ')
		var Length   = Temp.length - 1   // Array is from 0 to length-1

		if ((AtSym < 1) ||                     // '@' cannot be in first position
			(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
			(Period == Length ) ||             // Must be atleast one valid char after '.'
			(Space  != -1))                    // No empty spaces permitted
		{  
	      EmailOk = false
		}	
	return (EmailOk);
}

function isLoginAgentNumber(fValue){
	if (fValue.value !=""){
		var myacc = Trim(fValue.value);
			var valid1 = myacc.search(/^[A-Za-z]\d{7}$/);
		var valid2 = myacc.search(/^[A-Za-z]\d{9}$/);
		if (valid1 != "0" & valid2 != "0")

		{
			alert("Please enter your Customer Number in the correct format\n(e.g A1234567, A123456789)\nwithout any special characters or spaces.");
			fValue.focus();
			return (true);
		}
		else
		{
			return (true);
		}
	}		
}

function isComment(fValue)
{
	if (Trim(fValue.value)=="")
 {
  	alert("Don't forget to tell us what you want!");
	fValue.focus();
	return (true);
  }
}

function isCardBlank(fValue)
{
 if (fValue.value.length < 12)
  {
    alert("Please enter a valid credit card number.");
    fValue.focus();
    return (true);
  }
}
function isItemBlank(fValue)
{
	if (Trim(fValue)==""){return (true)}
}

function isTelephoneNumber(fValue,fName)
{
	if (fValue.value.length < 10)
	{
	    alert('Please enter ' + fName + ', including area code.');
		fValue.focus();
		return (false);
	}
	
	var checkOK = "0123456789 ";
	var checkStr = fValue.value;
	var allValid = true;
		
	for (i = 0;  i < checkStr.length;  i++)
	{
	    ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
					
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
	}

	if (!allValid)
	{
	    alert("Please enter a valid "+fName+".");
		fValue.focus();
		return (false);
	}
	
	return(true);
}

function Trim(s) 
{
	
	//alert ('Trimming "' + s + '"');
	
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	{ 
		s = s.substring(1,s.length);
	}
     
	// Remove trailing spaces and carriage returns
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	{
		s = s.substring(0,s.length-1);
	}

		return s;
}
