﻿/****************************************************************************************
Product:	  PowerVolt Inc.
Copyright:	  PowerVolt Inc., All rights reserved.
File Type:	  Ajax File (.js)
Source:		  ajaxregistereduser.js
Created Date: 12/09/2008
Author:		  Justin Arun
Version:	  1.0.0
Description:  Ajax script file for Validating Registered User


CR / Issue No      Modified By       Modified On       Version         Reason
****************************************************************************************/

function UserIdExistorNot(obj) 
{   
    var ctrl = document.getElementById(obj); 
    if ($get("errortxtEmail").innerHTML != "") 
    {
        $get("errortxtEmail").innerHTML = ""
    }
    if (ctrl.value.trim() != "")     //to check whether Textbox field is empty or not
    {        
        PageMethods.CheckUserIdExist(ctrl.value, OnUserIdDontExist, OnUserIdExist);
    }
}

function OnUserIdDontExist() {
    $get("errortxtEmail").innerHTML = notExist;
}

function OnUserIdExist(error) {
    __doPostBack(document.getElementById('btnRegister').name, '');
}

var checkEventFired;
//Used in Scubscribe.ascx file for Subscription userid already exists
function SubscriptionIdExistorNot(obj, eventFired) 
{       
    var ctrl = document.getElementById(obj);
    var localClientId = clientID;
    checkEventFired=eventFired;
    clientID = ASCXClientID;
    errMsg = "";
    
    if (ValidateRequired("txtEmailId", emptyEmail))
    {
        if(ValidateEmail("txtEmailId", invalidEmail))
        {
            clientID = localClientId;
            PageMethods.CheckSubscriptionIdExist(ctrl.value, OnSubscriptionIdDontExist, OnSubscriptionIdExist);
        }
    }   

    if (firstErrorControl != '') 
    {
        SetControlFocus(firstErrorControl);
        if(errMsg!="")
        {
            errMsg = "<table border='0' width='285px' cellspacing='0' cellpadding='0' class='validation'>" + errMsg + "</table>";
            document.getElementById("divNLErrorMessage").innerHTML = errMsg;
        }
        clientID = localClientId;
        return false;
    }
}

function OnSubscriptionIdDontExist() 
{       
    document.getElementById("divNLErrorMessage").innerHTML = "";
    
    if(checkEventFired=="button")
        __doPostBack(document.getElementById(ASCXClientID+'btnRegister').name, '');
}

function OnSubscriptionIdExist(error) 
{   
    var existErrMsg = "<table border='0' width='285px' cellspacing='0' cellpadding='0' class='validation'>";
    existErrMsg += "<tr><td onClick=\"SetControlFocus('" + ASCXClientID + "txtEmailId')\"><span class='hand'>";
    existErrMsg += idExists;
    existErrMsg += "</span></td></tr></table>";
    
    document.getElementById("divNLErrorMessage").innerHTML = existErrMsg;
}