function valButton(btn) {
var cnt = -1;
for (var i=btn.length-1; i > -1; i--) {
   if (btn[i].checked) {cnt = i; i = -1;}
   }
if (cnt > -1) return btn[cnt].value;
else return null;
}

function check_validation_login()
{	

	if(removeAllSpaces(document.getElementById("email").value)	==	'')
	{

			alert('Please enter Email Address');
			document.getElementById("email").value='';
			document.getElementById("email").focus();
			return false;
	}
	
	if(removeAllSpaces(document.getElementById("email").value)	!=	'')
		{

			if(!validateEmailv2(document.getElementById("email").value))

			{

				alert('Please enter Valid Email Address');

				document.getElementById("email").value='';

				document.getElementById("email").focus();

				return false;

			}

	

		}



		if(removeAllSpaces(document.getElementById("pwd").value)=='')
		{

			alert('Please enter Password');

			document.getElementById("pwd").value='';

			document.getElementById("pwd").focus();

			return false;

		}
		
 if (document.form_login.r1[0].checked == false && document.form_login.r1[1].checked == false ){
alert('Please Select User Type');
return false;
}
 //   {
		

	//		

		//	return false;

		//}
		return true;		
}	

function removeAllSpaces(str)
{

   str = removeLeadingSpaces(str); //Remove Leading Spaces

   str = removeTrailingSpaces(str); //Remove Trailing Spaces

   return str;

}



//### Function for removing the leading and trailing space



function removeLeadingSpaces(str)

{

   var whitespace = new String(" \t\n\r");

   var s = new String(str);



   if (whitespace.indexOf(s.charAt(0)) != -1)

    {

      var j=0, i = s.length;

      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)  j++;

      s = s.substring(j, i);

    }

   return s;

}



function removeTrailingSpaces(str)

{

   var whitespace = new String(" \t\n\r");

   var s = new String(str);



   if (whitespace.indexOf(s.charAt(s.length-1)) != -1)

   {

      var i = s.length - 1;       // Get length of string

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;



      // Get the substring from the front of the string to

      // where the last non-whitespace character is...

      s = s.substring(0, i+1);

   }



   return s;

}

//######################################################################################################

function validateEmailv2(email)

{

// a very simple email validation checking. 

// you can add more complex email checking if it helps 

    if(email.length <= 0)

	{

	  return true;

	}

    var splitted = email.match("^(.+)@(.+)$");

    if(splitted == null) return false;

    if(splitted[1] != null )

    {

      var regexp_user=/^\"?[\w-_\.]*\"?$/;

      if(splitted[1].match(regexp_user) == null) return false;

    }

    if(splitted[2] != null)

    {

      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;

      if(splitted[2].match(regexp_domain) == null) 

      {

	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;

	    if(splitted[2].match(regexp_ip) == null) return false;

      }// if

      return true;

    }

return false;

}
