﻿/**************************************/
// Author: Shivarudraswamy
// Description : This JS Includes methods to 
//              1. Validation for Login Page.
//              2. Validation for Forgot password Page.
//              3. Validation for New User.
/**************************************/

var d = document;
var RegExpEmail = /^\w+([\._]?\w+)*@\w+([\._]?\w+)*\.(\w{2}|(com|net|org|edu|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;


/*------------------------------Validation For Login Page-------------------------------*/
function ValidateLogin()
{
    var errmsg = ""; 
    var txtemail = d.getElementById ("ctl00_ContentRegion_txtUserName");
    var upwd = d.getElementById ("ctl00_ContentRegion_txtPassWord");    
    if (txtemail.value=="")
    {
        errmsg+="- Enter user name\n";
    }    
    if (upwd.value=="")
    {
        errmsg+="- Enter password\n";
    }
    
    if (errmsg!="")
    {
	    alert(errmsg);
		if( txtemail.value=="")
		{
		    txtemail.focus();
		}
		else if( upwd.value == "")
		{
		    upwd.focus();
		}
        return false;	
    }
}
    
/*----------------------------------Validation For ForGot Password Page-------------------------------------*/
function ValidateForgotPassword()
{
    var txtemail = d.getElementById ("ctl00_ContentRegion_txtEmail");
    if (txtemail.value == "")
    {
        alert("- Enter E-mail ID");
        txtemail.focus();
	    return false;
    }   
    else
    {
        if(RegExpEmail.test(txtemail.value) == false)
	    {
	        alert("- Enter a valid E-mail ID");
		    txtemail.focus();
		    return false;
	    }
	    else
	    {
	        return true;
	    }
    }
}

/*To Avoid PageRefresh*/
function KeyCheck(buttonName,e)
{
    var key;
    if(event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13)
    {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null)
        { //If we find the button click it
            btn.click();
            event.keyCode = 0
        }
    }     
}
function checkFocus()
{
    var txtUserName = d.getElementById ("ctl00_ContentRegion_txtUserName");
    var txtPWD = d.getElementById ("ctl00_ContentRegion_txtPassWord");
    var txtEmail = d.getElementById ("ctl00_ContentRegion_txtEmail");
    var Sub_txtEmail = d.getElementById ("ctl00_ContentRegion_UCSubscribe_txtMailId");
    var FirstSub_txtEmail = d.getElementById ("ctl00_ContentRegion_UCFirstSubscribes_txtEducationalEmail");
    
    if(FirstSub_txtEmail!= null)    
    {
        if(FirstSub_txtEmail.value == "")
            FirstSub_txtEmail.focus();    
    }    
    if(Sub_txtEmail != null)
    {
        if(Sub_txtEmail.value == "")
            Sub_txtEmail.focus();    
    }    
    if(txtUserName != null)
    {
        if (txtUserName.value=="")
            txtUserName.focus();
        else
            txtPWD.focus();
    }
    if(txtEmail != null)
    {
        if (txtEmail.value=="")
            txtEmail.focus();
    }
}

function checkUncheckAll(theElement) 
{
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++)
	 {
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
        {
	        theForm[z].checked = theElement.checked;
        }
     }
}

function confirmDelete(msgAlert)
{
    return confirm(msgAlert);
}

function openDivNearMouse(divId)
{
    var d = document.getElementById(divId);
    d.style.left = window.event.x + document.body.parentElement.scrollLeft;// - mouseX;
    d.style.top =  window.event.y + document.body.parentElement.scrollTop;// - mouseY;
}

function showHideDiv(divId)
{
    var d = document.getElementById(divId);
    if(d.style.display == 'none')
        d.style.display = 'block';
    else
        d.style.display = 'none';
}
    
function ToggleDisplay(id)
{
    var elem = document.getElementById('d' + id);
    if (elem) 
    {
      if (elem.style.display != 'block') 
      {
        elem.style.display = 'block';
        elem.style.visibility = 'visible';
      } 
      else
      {
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
      }
    }
}
