﻿
function validate_login()
{
var a=document.getElementById("HomeHeaderControl1$txtUserName").value; 
var b=document.getElementById("HomeHeaderControl1$txtPassword").value; 
var k=a.indexOf(' ');
if(a=="")
{
alert("Enter user id");
document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
return false;
}
//else if (stringEmpty(a)==true) 
//{
//alert("Wrong Email id");
//document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
//return false;
//} 
//else if (noAtSign(a)==true) 
//{      
//alert("Wrong Email id");
//document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
//return false;
//} 
//else if (nothingBeforeAt(a)==true)
//{
//alert("Wrong Email id");
//document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
//return false;
//} 
//else if (noLeftBracket(a)==true)
//{
//alert("Wrong Email id");
//document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
//return false;
//} 
//else if (noRightBracket(a)==true)
//{
//alert("Wrong Email id");
//document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
//return false;
//} 
//else if (noValidPeriod(a)==true)
//{
//alert("Wrong Email id");
//document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
//return false;
//} 
//else if (noValidSuffix(a)==true)
//{
//alert("Wrong Email id");
//document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
//return false;
//} 
else if(k>=0)
{
alert("Wrong user id");
document.getElementById("HomeHeaderControl1$txtUserName").focus(); 
return false;
}	
else if(b=="")
{
alert("Enter Password");
document.getElementById("HomeHeaderControl1$txtPassword").focus(); 
return false;
}
else
{
return true;
}
}




function stringEmpty (formField) {
    // CHECK THAT THE STRING IS NOT EMPTY
    if ( formField.length < 1 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function noAtSign (formField) {
    // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
    if (formField.indexOf ('@', 0) == -1) {
        return ( true )
    } else {
        return ( false );
    }
}

function nothingBeforeAt (formField) {
    // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
    if ( formField.indexOf ( '@', 0 ) < 1 ) {
        return ( true )
    } else {
        return ( false );
    }
}

function noLeftBracket (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR LEFT BRACKET
    if ( formField.indexOf ( '[', 0 ) == -1 && formField.charAt (formField.length - 1) == ']') {
        return ( true )
    } else {
        return ( false );
    }
}

function noRightBracket (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN CHECK FOR RIGHT BRACKET
    if (formField.indexOf ( '[', 0 ) > -1 && formField.charAt (formField.length - 1) != ']') {
        return ( true );
    } else {
        return ( false );
    }
}

function noValidPeriod (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if (formField.indexOf ( '@', 0 ) > 1 && formField.charAt (formField.length - 1 ) == ']')
        return ( false );

    // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
    if (formField.indexOf ( '.', 0 ) == -1)
        return ( true );

    return ( false );
}

function noValidSuffix(formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if (formField.indexOf('@', 0) > 1 && formField.charAt(formField.length - 1) == ']') {
        return ( false );
    }

    // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
    var len = formField.length;
    var pos = formField.lastIndexOf ( '.', len - 1 ) + 1;
    if ( ( len - pos ) < 2 || ( len - pos ) > 4 ) {
        return ( true );
    } else {
        return ( false );
    }
}
