function trim(sString)
{
  while (sString.substring(0,1) == ' ')
  {
    sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ')
  {
    sString = sString.substring(0,sString.length-1);
  }
  return sString;
}

function ValidateEmail(str) 
{

	if (str.indexOf("@")==-1 || str.indexOf("@")==0 || str.indexOf("@")==str.length - 1)
	{
		return false
	}
	if (str.indexOf(".")==-1 || str.indexOf(".")==0 || str.indexOf(".")==str.length - 1)
	{
		return false
	}
	if (str.indexOf("@",(str.indexOf("@")+1))!=-1)
	{
		return false
	}
	if (str.substring(str.indexOf("@")-1,str.indexOf("@"))=="." || str.substring(str.indexOf("@")+1,str.indexOf("@")+2)==".")
	{
		return false
	}
	if (str.indexOf(".",(str.indexOf("@")+2))==-1)
	{
		return false
	}	
	if (str.indexOf(" ")!=-1)
	{
		return false;
	}

 	return true;					
}

function ValidatePassword(str)
{
	if (str.length < 6)
	{
		return false;
	}
	
	var NumCount = 0;
	
	for (i = 0;  i < str.length;  i++)
	{
		if ((str.charAt(i) >= "0")  && (str.charAt(i) <= "9"))
		{
			NumCount = NumCount + 1
		}
	}
	
	if (NumCount < 2)
	{
		return false;
	}
}

function IsCurrency(sText)
{

   if (sText == '')
   {
   	return false;   
   }
   
   //ok if 0
   if (sText == '0')
   {
   	return true;
   }
   
   //remove leading dollar sign
   if (sText.substr(0,1) == "$")
   {
   	sText = sText.substr(1,sText.length - 1)
   }
   
   //remove . and leading numbers
   if (sText.indexOf('.') >= 0)
   {
   	if (sText.length < 4)
   	{
   		return false;
   	}
   	
   	if (sText.indexOf('.') != sText.length - 3)
   	{
             return false;
   	}
   	
   	if ((sText.substr(sText.length - 2,1) < '0') || (sText.substr(sText.length - 2,1) > '9'))
   	{
   		return false;
   	}
   	
   	if (sText.substr(sText.length - 1,1) < '0' || sText.substr(sText.length - 1,1) > '9')
	{
		return false;
   	}
   	
   	sText = sText.substr(0,sText.indexOf('.'))
   }

   //invalid if leading comma
   if (sText.substr(0,1) == ",")
   {
      return false;
   }
   
   
   if (sText == '')
   {
      	return false;   
   }

   //verify commas are in proper places
   if (sText.indexOf(',') >=0)
   {
   	var iComma = 0;
   	
   	for (iIC = sText.length - 1; iIC >= 0; iIC--)
   	{
   		if (sText.charAt(iIC) == ',' && iComma != 3)
   		{
   			return false;
   		}
   		else if (iComma == 3 && sText.charAt(iIC) != ',')
   		{
   			return false;
   		}
   		else if (sText.charAt(iIC) == ',' && iComma == 3)
   		{
   			iComma = 0;
   		}
   		else
   		{
   			iComma = iComma + 1;
   		}
   	}

   	//remove commas from string
   	sText = sText.replace(/,/g, "")
   }

   if (sText == '')
   {
         return false;   
   }
   
   //invalid if leading 0
   if (sText.substr(0,1) == "0")
   {
   	return false;
   }

   var ValidChars = '0123456789';
   
   for (iIC = 0; iIC < sText.length; iIC++)
   {
   	if (ValidChars.indexOf(sText.charAt(iIC)) < 0)
   	{	
   		return false;
   	}
   	
   }
   
   return true;
}

function IsValidMBLNO(sBLNo)
{
	sBLNo = trim(sBLNo)
	sBLNo = sBLNo.toUpperCase();

	if (sBLNo.length <=9){return false;}

	sBLNo = sBLNo.replace("APLU", "");
	sBLNo = sBLNo.replace("CHHKDLL", "");
	sBLNo = sBLNo.replace("COSU", "");
	sBLNo = sBLNo.replace("EGLV", "");
	sBLNo = sBLNo.replace("HDMUHMUS", "");
	sBLNo = sBLNo.replace("HDMUJTWB", "");
	sBLNo = sBLNo.replace("HDMUKHCA", "");
	sBLNo = sBLNo.replace("HDMUQSLB", "");
	sBLNo = sBLNo.replace("HJSCDLCA", "")
	sBLNo = sBLNo.replace("HJSCPUSA", "");
	sBLNo = sBLNo.replace("HJSCSGNA", "");
	sBLNo = sBLNo.replace("HJSCSHAA", "");
	sBLNo = sBLNo.replace("HLCUSEL", "");
	sBLNo = sBLNo.replace("KKLUTAO", "");
	sBLNo = sBLNo.replace("MAEU", "");
	sBLNo = sBLNo.replace("MATS", "");
	sBLNo = sBLNo.replace("MOLU", "");
	sBLNo = sBLNo.replace("MSCUDL", "");
	sBLNo = sBLNo.replace("MSCUS", "");
	sBLNo = sBLNo.replace("NYKS", "");
	sBLNo = sBLNo.replace("SAFMDAIZ", "");
	sBLNo = sBLNo.replace("WHLC", "");
    sBLNo = sBLNo.replace("YMLUW", "");

	var iIVMB;

    for (iIVMB=0; iIVMB < sBLNo.length; iIVMB++)
    {
	   	if (!((sBLNo.substr(iIVMB, 1) >= "0") && (sBLNo.substr(iIVMB, 1) <= "9")))
	   	{
	   		switch(sBLNo.substr(iIVMB, 1))
	   		{
	   			case "-":
					if (iIVMB != 3){return false;}
	   				break;
	   			default:
				return false;
	   		}
      	}
    }
	return true;
}