﻿//Created by :- Pranav dave.
//For Forgot Password.

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
function Trim(pstr)
{ 
  pstr = pstr.replace(/^\s+|\s+$/ig, ''); //trim function
  return pstr;
}
 
 function fnEmailValidation(objEmail)
 {
    var validRegExp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    if(objEmail.value.search(validRegExp) == -1)
	{
		return false;
	}
	else
	{  
	    return true;
	}
}
 
 function ValidEmail()
 {
    var txtEmail = document.getElementById('ctl00_ContentPlaceHolder_txtEmail');    
    var lblMsg = document.getElementById('ctl00_ContentPlaceHolder_lblMsg');   
    if(Trim(txtEmail.value) == "")
    {
        lblMsg.innerHTML = "Please enter email id";
        txtEmail.focus();        
        return false;        
    }    
    
    if(Trim(txtEmail.value) != "")
    {
        if(fnEmailValidation(txtEmail) == false)
        {
            lblMsg.innerHTML = "Enter valid username";
		    txtEmail.focus();
		    window.scroll();
		    return false;
        }
    }    
 }
 
/**************************************************************************************************************/
//For Change Password.


function validcontrols()
{
    var txtOpassword = document.getElementById('ctl00_ContentPlaceHolder_txtOpassword');
    var txtNpasword = document.getElementById('ctl00_ContentPlaceHolder_txtNpasword');
    var txtCpasword = document.getElementById('ctl00_ContentPlaceHolder_txtCpasword');
    var lblMsg = document.getElementById('ctl00_ContentPlaceHolder_lblMsg');
    
    if(Trim(txtOpassword.value) == "")
    {
        lblMsg.innerHTML = "Please enter your current password";
        txtOpassword.focus();        
        return false;  
    }
    if(Trim(txtNpasword.value) == "")
    {
        lblMsg.innerHTML = "Please enter new password";
        txtNpasword.focus();        
        return false; 
    }
    if(Trim(txtCpasword.value) == "")
    {
        lblMsg.innerHTML = "Please enter confirm password";
        txtCpasword.focus();        
        return false; 
    }     
    if(Trim(txtNpasword.value) != Trim(txtCpasword.value))
    {
        lblMsg.innerHTML = "New password and confirm password does not match";
        txtCpasword.focus();        
        return false; 
    }     
    if(txtNpasword.value.length < 7 )
    {
        lblMsg.innerHTML = "Password should be of minimum 7 characters and maximum 20 characters";
        return false;
    }
    if(txtNpasword.value.length > 20 )
    {
        lblMsg.innerHTML = "Password should be of minimum 7 characters and maximum 20 characters";
        return false;
    }
    
   regExpralpha = new RegExp("[a-z/_/$]{1}","i");
   if(!regExpralpha.test(txtNpasword.value))
   {
    lblMsg.innerHTML = "Password should contain atleast 1 alphanumeric character.";
    txtNpasword.focus();
    return false;
   }
   
   regExprnum = new RegExp("[0-9]{1}","i");
   if(!regExprnum.test(txtNpasword.value))
   {
    lblMsg.innerHTML = "Password should contain atleast 1 numeric character.";
    txtNpasword.focus();
    return false;
   }
}

function ConfirmPass()
{
    alert("Your password has been changed successfully.");
    document.location.href="Home.aspx";
}
/**************************************************************************************************************/
//For Login page.

function validateLogin()
{
    var txtLogin = document.getElementById('ctl00_ContentPlaceHolder_txtLogin');
    var txtpasword = document.getElementById('ctl00_ContentPlaceHolder_txtpasword');
    var lblMsg = document.getElementById('ctl00_ContentPlaceHolder_lblMsg');  
    lblMsg.style.color="Red";
    if(txtLogin.value == "")
    {
        lblMsg.innerHTML = "Please enter Username";
        txtLogin.focus();        
        return false;  
    }
    if(txtpasword.value == "")
    {
        lblMsg.innerHTML = "Please enter Password";
        txtpasword.focus();        
        return false; 
    }
}


/********************************************************************************************************/
//For showing popupmessage in home page

var d = new Date();
var ID = d.getDate()+""+d.getMonth() + 1+""+d.getFullYear()+""+d.getHours()+""+d.getMinutes()+""+d.getSeconds();

//function popup()
//{		
//	var height = 75;
//	var width = 500;
//	var left = (screen.availWidth - width)/2;
//	var top = (screen.availHeight - height)/2;
//	if (window.showModalDialog)
//	{
//		var dialogArguments = new Object();
//		var _R = window.showModalDialog("popup.aspx", dialogArguments, "dialogWidth=500px;dialogHeight=75px;scroll=no;status=no;");
//        if ("undefined" != typeof(_R))
//		{
//			SetName(_R.strName);	
//		}
//	}		
//	else	//NS			
//	{  	
//		var left = (screen.width-width)/2;
//		var top = (screen.height-height)/2;
// 		winHandle = window.open("popup.aspx", ID, "modal,toolbar=false,location=false,directories=false,status=false,menubar=false,scrollbars=no,resizable=no,left="+left+",top="+top+",width="+width+",height="+height);
//		winHandle.focus();
//	}
//	return false;
//}

function popup(msg,login,isExpired) {
    var height = 75;
    var width = 500;
    var left = (screen.availWidth - width) / 2;
    var top = (screen.availHeight - height) / 2;
//    var msg = 'Your account has expired. Please reactivate your account';
//    var login = document.getElementById('ctl00_ContentPlaceHolder_txtLogin').value;
    if (window.showModalDialog) {
        var dialogArguments = new Object();
        var _R = window.showModalDialog("popup.aspx?msg=" + msg + "&IsExpired=" + isExpired + "&login=" + login, dialogArguments, "dialogWidth=500px;dialogHeight=130px;scroll=no;status=no;");
        if ("undefined" != typeof (_R)) {
            SetName(_R.strName);
        }
    }
    else	//NS			
    {
        var left = (screen.width - width) / 2;
        var top = (screen.height - height) / 2;
        winHandle = window.open("popup.aspx?msg=" + msg + "&IsExpired=" + isExpired + "&login=" + login, ID, "modal,toolbar=false,location=false,directories=false,status=false,menubar=false,scrollbars=no,resizable=no,left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
        winHandle.focus();
    }
    return false;
}

function SetName(strName)
{
	document.location.href = strName;//="UserLogin.aspx";
}

