// JavaScript Document
function check()
{
	var security_code = document.getElementById("security").value;
	var uname         = document.getElementById("uname").value;
	var pass         = document.getElementById("pass").value;
	var email         = document.getElementById("email").value;
	
	
	if(uname.length < 5)
	{
		alert("Please enter username at least 5 characters");
		document.getElementById("uname").focus();
		return false;
	}
	else if(pass.length < 5)
	{
		alert("Please enter password at least 5 characters");
		document.getElementById("pass").focus();
		return false;
	}
	
	
	
	if(email == "")
	{
		alert("Please enter email address.");
		document.getElementById("email").focus();
		return false;
	}
	else if(!checkEmail(email))
	{
		alert("Please enter valid email address.");
		document.getElementById("email").focus();
		return false;
	}
	else if(!checkLength(email))
	{
		alert("Please enter valid email address.");
		document.getElementById("email").focus();
		return false;
	}
	else if(security_code == "")
	{
		alert("Please enter security code");
		return false;
	}
	else
	{
		return true;
	}
}


/*Function for checking valid email id*/
function checkEmail(s)
{
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function')
	{
		var b = new RegExp('abc');
		if(b.test('abc') == true){a = true;}
	}

	if(a == true)
	{
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
						'(\\@)([a-zA-Z0-9\\-\\.]+)'+
						'(\\.)([a-zA-Z]{2,4})$');
		res = (reg.test(s));

		//alert("valid email adress");
	}
	else
	{
		res = (s.search('@') >= 1 &&
		s.lastIndexOf('.') > s.search('@') &&
		s.lastIndexOf('.') >= s.length-5)
	}

	if(res==false)
	{
		return false;
	}
	else
	{
		return true;
	}
}


function checkLength(s)
{
	//alert("call checkLength.....");
	indatrate = s.indexOf("@");
	stratrate = s.slice(indatrate + 1);
	ind = stratrate.indexOf(".");
	str = stratrate.slice(ind + 1);
	len = str.length;

	//alert("ind :"+ind+"str :"+str+"len : "+len);
	if (s.indexOf("@") < 1) //  must contain @, and it must not be the first character
	{ 
		return false;
	} 
	else if (s.lastIndexOf(".") <= s.indexOf("@")) // last dot must be after the @
	{  
		return false;
	} 
	else if (s.indexOf("@") == s.length)// @ must not be the last character
	{  
		return false;
	} 
	else if (s.indexOf("..") >=0)// two periods in a row is not valid
	{ 
		return false;
	} 
	else if (s.indexOf(".") == s.length) // . must not be the last character
	{ 
		return false;
	}
	else if(len == 5 )
	{
		//alert("len : "+ len);
		
		ind1 = str.indexOf(".");
		str1 = str.slice(ind1 + 1);
		len1 = str1.length;		
		if(len1 == 2)
		{
			//alert("len1 : "+ len1);
			return true;
			//checkRegistrationEmail();
		}
		else
		{
			return false;
		}
	}
	else if(len == 3)
	{
		//alert("len2 : "+ len);
		//checkRegistrationEmail();
		return true;
	}
	else
	{
		return false;
	}
	
}
