function IsValueExist(strVal)
{
	nNoOfArguments = IsValueExist.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}
	
	
	
	strVal = new String(strVal);	//convert the value to a string object
	
	// if string contains no character
	if(strVal.length == 0) 
	{
		return false;
	}
	return true;
}

function IsFirstCharBlank(strVal)
{
	nNoOfArguments = IsFirstCharBlank.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return true;
	}
		
	strVal = new String(strVal);	//convert the value to a string object
	
	// if first character is blank
	if (strVal.charAt(0) == " ") 
	{
		return true;
	}
	return false;
}

function IsStringWithSpaces(strVal)
{
	nNoOfArguments = IsStringWithSpaces.arguments.length;
	
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	var strInValidChars = ' '; //invalid charaters i.e. space in this case
	
	bReturn = strVal.indexOf(strInValidChars);	//check for invalid characters in string
	
	if(bReturn != -1)//if any invalid character found
	{
		return true;
	}
	return false;
}

function checkUsername(strValue,nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//if string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{
		return (1);
	}

	//if the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}
	
	//if string value supplied contain spaces
	if(IsStringWithSpaces(strValue))
	{
		return (3);
	}
	
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) <= 0)
		{		
			return (6);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{	
			return (4);
		}		
		
	}	
	
	//if nMaxlen value supplied then
	if(nMaxlen)
	{
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		} 
		//if valid length supplied but string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{		
			return (5);
		}
	}	
	return (0);
}

function checkPassword(strValue, nMaxlen,nMinlen)
{
	//if nMinlen is equal to 0 and value i.e. strValue is not supplied return success code
	//else return error code
	if (0 == nMinlen)
	{
		if(!strValue)
		{
			return(0);
		}
	}
	else
	{
		if(!strValue)
		{
			return(1);
		}
	}
	
	//If string value supplied is empty or contains nothing
	if(!IsValueExist(strValue))
	{	
		return (1);
	}
	
	//If the first character of the string value supplied is space
	if(IsFirstCharBlank(strValue))
	{
		return (2);
	}	
	
	//if string value supplied contain spaces
	if(IsStringWithSpaces(strValue))
	{	
		return (3);
	}
		
	//if nMinlen value supplied then
	if(nMinlen)
	{
		//if invalid minimum length supplied
		if(isNaN(nMinlen) || parseInt(nMinlen) <= 0)
		{		
			return (6);
		}		
		//if valid length supplied but string length is less then nMinlen
		if(strValue.length < parseInt(nMinlen))	
		{
			return (4);
		}		
		
	}
	
	//if nMaxlen value supplied then	
	if(nMaxlen)
	{ 
		//if invalid maximum length supplied
		if(isNaN(nMaxlen) || parseInt(nMaxlen) <= 0)
		{	
			return (6);	
		}
		//if valid length supplied but string length is greater then nMaxlen
		if(strValue.length > parseInt(nMaxlen))
		{
			return (5);
		}
	}
	return (0);
}