var xmlHttp;function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");     //For internet explorer
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();                       //For Mozilla
    }
}

function startProfileRequest(url) {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleProfileStateChange;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);}

function startEmailRequest(url){
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleEmailStateChange;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);}

function elp(id)
{
    return document.getElementById(id);
}

function  elm(id)
{
    return document.getElementById(id);
}

function handleProfileStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            if (response.toLowerCase().indexOf("ProfileSection")>-1) {
                elp('ProfileSection').innerHTML = xmlHttp.responseText;
            }
            else {
                elp('ProfileSection').innerHTML =xmlHttp.responseText;
            }
        }
    }
}

function handleEmailStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
           /* if (response.toLowerCase().indexOf("EmailSection")>-1) {
                elm('EmailSection').innerHTML = xmlHttp.responseText;
            }
            else {
                 elm('EmailSection').innerHTML =xmlHttp.responseText;
            }*/
        }
    }
}

function validateProfile(This) {
    var url='/profileregistration/reg?pval=' + This;
    startProfileRequest(url);}

function validateEmail(This) {
    var url='/emailregistration/reg?eval=' + This;
    startEmailRequest(url);}

function submitForm() {
        document.location="startregister.do?dispatch=register"
}

function submitForm1() {
        document.location="saveNewRegister.do?dispatch=saveUser"
}

function submitProfileForm() {
        document.location="saveNewProfileRegister.do?dispatch=saveUser"
}

// Removes leading whitespaces
function LTrim(value1) {
	var re = /\s*((\S+\s*)*)/;
    return value1.replace(re, '$1');

}

// Removes ending whitespaces
function RTrim(value1) {
	var re = /((\s*\S+)*)\s*/;
    return value1.replace(re, '$1');

}
// Removes leading and ending whitespaces
String.prototype.trim=function(){
    return LTrim(RTrim(this));
}

function sendVerificationEmail(id){
    var url='/verifyEmail/email?';
    createXMLHttpRequest();
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);

    if( id != undefined){
        document.getElementById(id).innerHTML = "New Verification Email is sent your Email Account.Please verify your email by following the instructions sent to your email account.";
        document.getElementById(id).color = 'coral';
        document.getElementById(id).textAlign ='justify';
    }
}
