// function for checking string
function checkString(str_temp, str_fld)
{
	temp=new String(str_temp);
	if(str_temp=="")
	{
		window.alert("Please enter the " + str_fld);
		return false;
	}
	
	if(temp.charAt(0)==" ")
	{
		window.alert("The " + str_fld + " cannot start with a space");
		return false;
	}
	
	str=new String("'\"");
	
	var flag=1;
	
	for (c=0; c<temp.length; c++)
	{
		if(str.indexOf(temp.charAt(c))>=0)
		{
			flag=0;
			break;
		}
	}
	
	if (flag==0)
	{
		window.alert("The " + str_fld + " cannot contain single/double quotes");
		return false;
	}
	return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

// function for checking number
function checkNumber(str_temp, str_fld)
{
	temp=new String(str_temp);
	if(str_temp=="")
	{
		window.alert("Please enter the " + str_fld);
		return false;
	}
	
	if(temp.charAt(0)==" ")
	{
		window.alert("The " + str_fld + " cannot start with a space");
		return false;
	}
	
	if (isNaN(str_temp))
	{
		window.alert("The " + str_fld + " can contain only numbers");
		return false;
	}
	return true;
}


function Trim(trimstr)
{
	if(trimstr.length < 1)
	{
		return"";
	}
	trimstr = RTrim(trimstr);
	trimstr = LTrim(trimstr);
	if(trimstr=="")
	{
		return "";
	}
	else
	{
		return trimstr;
	}
} //End Function

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;
	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function
function checkspecialcharacter(str)
{
	var iChars = "!@#$%^&*()+=[]\\\';,./{}|\":<>? ";
	for (var i = 0; i < str.length; i++) 
	{
		if (iChars.indexOf(str.charAt(i)) != -1) 
		{
			return false;
		}
	}
}
function checkspecialcharacterforaddress(str)
{
	var iChars = "!@#$%^&*()+=[]\\\';./{}|\":<>?";
	for (var i = 0; i < str.length; i++) 
	{
		if (iChars.indexOf(str.charAt(i)) != -1) 
		{
			return false;
		}
	}
}

function isEmailAddr(email)
{
	var result = false
  	var theStr = new String(email)
  	var index = theStr.indexOf("@");
 	if (index > 0)
  	{
    	var pindex = theStr.indexOf(".",index);
    	if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
 	}
  return result;
}
