﻿//function Trim(str)
//{
//   return str.replace(/^\s*|\s*$/g,"");
//}
     
function ValidateUser()
{
    var username = true;
    var password = true; 
    var isInvalid = true;
    var ctr = document.getElementById('txtUser');
    
    if(ctr == null)
        ctr = document.getElementById('txtUser');

    if(ctr != null)
    {
        var trimmed = ctr.value; //Trim(ctr.value);
        if(trimmed == "")
        {
            username = false;
            ctr.focus();
        }
        else
        {
            var emailPat =  /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
            var emailid = ctr.value;
            if(!emailid.match(emailPat))
            {
                ctr.focus();
                isInvalid = false;
            }
            if(document.all.divUser != null)
                document.all.divUser.innerHTML = "";
        }
    }
	        		        
    ctr = document.getElementById('txtPassword');
    
    if(ctr == null)
        ctr = document.getElementById('txtPassword');

    if(ctr != null)
    {
        var trimmed = ctr.value; //Trim(ctr.value);
        if(trimmed == "")
        {		     
            password = false;
            ctr.focus();
        }
        else
        {
            if(document.all.divUser != null)
                document.all.divPass.innerHTML = "";
        }
    }
    
    if((username == false) && (password == false ))
    {
        document.all.lblErrorMsg.innerHTML = "Enter Username and Password";
        
        if(document.all.divUser != null)
        {
            document.all.divUser.innerHTML = "*";
            document.all.divPass.innerHTML = "*";
        }
        return false;
    }
    else if(username == false)
    {
        document.all.lblErrorMsg.innerHTML = "Enter Username";
        if(document.all.divUser != null)
            document.all.divUser.innerHTML = "*";
        return false;
    }
    else if(password == false)
    {
        document.all.lblErrorMsg.innerHTML = "Enter Password";
        if(document.all.divUser != null)
            document.all.divPass.innerHTML = "*";
        return false;
    }
    else if(isInvalid == false)
    {
        document.all.lblErrorMsg.innerHTML = "Invalid Username or Password";
        if(document.all.divUser != null)
            document.all.divUser.innerHTML = "*";
        return false;
    }
    return true; 
}

//function ValidateCheckBox() 
//{
//    //ctl00$ContentPlaceHolder2$ChkAgree
//    //ctl00_ContentPlaceHolder2_ChkAgree
//    if (document.getElementById('ctl00_ContentPlaceHolder2_ChkAgree') != null && document.getElementById('ContentPlaceHolder2_ChkAgree').checked == true) 
//    { 
//        document.getElementById('ctl00_ContentPlaceHolder2_txtForCheckBox').value = "1";
//    }
//    else {
//        if(document.getElementById('ctl00_ContentPlaceHolder2_txtForCheckBox')!=null)
//            document.getElementById('ctl00_ContentPlaceHolder2_txtForCheckBox').value = "";
//    }
//}

//function ValidateCheckBox123()
//{
//    if (document.getElementById('ctl00_ContentPlaceHolder2_ChkAgree') != null && document.getElementById('ContentPlaceHolder2_ChkAgree').checked == true)
//    {
//        document.getElementById('ctl00_ContentPlaceHolder2_txtForCheckBox').value = "1";
//    }
//    else {
//        if (document.getElementById('ctl00_ContentPlaceHolder2_txtForCheckBox') != null)
//                document.getElementById('ctl00_ContentPlaceHolder2_txtForCheckBox').value = "";
//        //ctl00_
//    }
//}
