﻿function CallMe(src, dest) {
    //alert(src.value+" dest="+dest);
    var ctrl = src; //document.getElementById(src);
    // call server side method
    PageMethods.SayHelloWorld(ctrl.value, CallSuccess, CallFailed, dest);
    //alert('call me finished');
}

// set the destination textbox value with the ContactName
function CallSuccess(res, destCtrl) {
    //alert('success['+res+'] destctrl='+destCtrl);
    var dest = document.getElementById(destCtrl);
    alert(dest.ID);
    dest.innerHTML = res;
}

// alert message on some failure
function CallFailed(res, destCtrl) {
    alert('Error occurred : ' + res.get_message());
}


function ShowDiv(divId) {
    var elem, vis;
    elem = GetDiv(divId)
    vis = elem.style;
    vis.display = 'block';
}

function HideDiv(divId) {
    var elem, vis;
    elem = GetDiv(divId)
    vis = elem.style;
    vis.display = 'none';
}

function GetDiv(divId) {
    var elem;
    if (document.getElementById) // this is the way the standards work
        elem = document.getElementById(divId);
    else if (document.all) // this is the way old msie versions work
        elem = document.all[divId];
    else if (document.layers) // this is the way nn4 works
        elem = document.layers[divId];
    return elem;
}
/*
 * Checking If Username is available
 */
function CheckIfUserNameExists(userName, obj) {
    
    if (userName == '') {
        var dest = document.getElementById(obj.userNameNotAvailableDisplayDivId);    
        dest.className = '';
    } else {
        PageMethods.CheckUserNameExists(userName, CheckIfUserNameExistsCallSuccess, CallFailed, obj);
        setTimeout("document.getElementById('password').focus();", 2000);
    }
}

function CheckIfUserNameExistsCallSuccess(res, obj, userNameUnavailableErrorMessage) {
    var dest = document.getElementById(obj.userNameNotAvailableDisplayDivId);
    if (res == true) {
        //dest.style.color = 'red';
        dest.className = 'error';
        dest.innerHTML = obj.userNameNotAvailableErrorMessage;
    } else {
        dest.className = '';
        //dest.style.color = '';
        dest.innerHTML = '';
    }
}

