﻿function LSPRegisstrationPostEdit() {

    var txtRegPostFirstName = document.getElementById("txtRegPostFirstName");
    var txtRegPostFamilyName = document.getElementById("txtRegPostFamilyName");
    var txtRegPostTitle = document.getElementById("txtRegPostTitle");
    var txtRegPostOrganization = document.getElementById("txtRegPostOrganization");
    var txtRegPostEmail = document.getElementById("txtRegPostEmail");
    var lblMsgErrorPostEdit = document.getElementById("lblMsgErrorPostEdit");

    lblMsgErrorPostEdit.innerText = "";
    
    if (txtRegPostFirstName.value == "") {
        lblMsgErrorPostEdit.innerText = "First Name is required.";
        return false
    }
    if (txtRegPostFamilyName.value == "") {
        lblMsgErrorPostEdit.innerText = "Family Name is required.";
        return false
    }
    if (txtRegPostTitle.value == "") {
        lblMsgErrorPostEdit.innerText = "Title/Occupation is required.";
        return false
    }
    if (txtRegPostOrganization.value == "") {
        lblMsgErrorPostEdit.innerText = "Organization is required.";
        return false
    }
    if (txtRegPostEmail.value == "") {
        lblMsgErrorPostEdit.innerText = "Email is required.";
        return false
    }
    else {
        if (!CheckEmail(txtRegPostEmail.value)) {
            lblMsgErrorPostEdit.innerText = "Invalid E-mail.";
            return false
        }
    }
    
    var param = new Array();
    param[0] = txtRegPostFirstName.value;
    param[1] = txtRegPostFamilyName.value;
    param[2] = txtRegPostTitle.value;
    param[3] = txtRegPostOrganization.value;
    param[4] = txtRegPostEmail.value;

    window.location = encodeURI("LanguageStudioProBetaRegistration.aspx?p=" + param);
}


function LSPRegisstrationPro() {

    var txtRegProFirstName = document.getElementById("txtRegProFirstName");
    var txtRegProFamilyName = document.getElementById("txtRegProFamilyName");
    var txtRegProTitle = document.getElementById("txtRegProTitle");
    var txtRegProOrganization = document.getElementById("txtRegProOrganization");
    var txtRegProEmail = document.getElementById("txtRegProEmail");
    var lblMsgErrorPro = document.getElementById("lblMsgErrorPro");

    lblMsgErrorPro.innerText = "";

    if (txtRegProFirstName.value == "") {
        lblMsgErrorPro.innerText = "First Name is required.";
        return false
    }
    if (txtRegProFamilyName.value == "") {
        lblMsgErrorPro.innerText = "Family Name is required.";
        return false
    }
    if (txtRegProTitle.value == "") {
        lblMsgErrorPro.innerText = "Title/Occupation is required.";
        return false
    }
    if (txtRegProOrganization.value == "") {
        lblMsgErrorPro.innerText = "Organization is required.";
        return false
    }
    if (txtRegProEmail.value == "") {
        lblMsgErrorPro.innerText = "Email is required.";
        return false
    }
    else {
        if (!CheckEmail(txtRegProEmail.value)) {
            lblMsgErrorPro.innerText = "Invalid E-mail.";
            return false
         }
     }
     
    var param = new Array();
    param[0] = txtRegProFirstName.value;
    param[1] = txtRegProFamilyName.value;
    param[2] = txtRegProTitle.value;
    param[3] = txtRegProOrganization.value;
    param[4] = txtRegProEmail.value;
    
    window.location = encodeURI("LanguageStudioProBetaRegistration.aspx?p=" + param);
}

function AsiaOnlineWebinarRegisstration() {

    var txtRegLSPsFirstName = document.getElementById("txtRegLSPsFirstName");
    var txtRegLSPsFamilyName = document.getElementById("txtRegLSPsFamilyName");
    var txtRegLSPsTitle = document.getElementById("txtRegLSPsTitle");
    var txtRegLSPsOrganization = document.getElementById("txtRegLSPsOrganization");
    var txtRegLSPsEmail = document.getElementById("txtRegLSPsEmail");

    var txtRegLSPsIndustry = document.getElementById("txtRegLSPsIndustry");
    var ddlContry = document.getElementById("ddlContry");
    var txtRegLSPsPhone = document.getElementById("txtRegLSPsPhone");
    
    var Radio1 = document.getElementById("Radio1");
    var Radio2 = document.getElementById("Radio2");
    var lblMsgErrorLSPs = document.getElementById("lblMsgErrorLSPs");

    lblMsgErrorLSPs.innerText = "";

    if (txtRegLSPsFirstName.value == "") {
        lblMsgErrorLSPs.innerText = "First Name is required.";
        lblMsgErrorLSPs.textContent = "First Name is required.";
        return false
    }
    if (txtRegLSPsFamilyName.value == "") {
        lblMsgErrorLSPs.innerText = "Family Name is required.";
        lblMsgErrorLSPs.textContent = "Family Name is required.";
        return false
    }
    if (txtRegLSPsTitle.value == "") {
        lblMsgErrorLSPs.innerText = "Title/Occupation is required.";
        lblMsgErrorLSPs.textContent = "Title/Occupation is required.";

        return false
    }
    if (txtRegLSPsOrganization.value == "") {
        lblMsgErrorLSPs.innerText = "Organization is required.";
        lblMsgErrorLSPs.textContent = "Organization is required.";

        return false
    }
    if (txtRegLSPsEmail.value == "") {
        lblMsgErrorLSPs.textContent = "Email is required.";
        return false
    }
    else {
        if (!CheckEmail(txtRegLSPsEmail.value)) {
            lblMsgErrorLSPs.innerText = "Invalid E-mail.";
            lblMsgErrorLSPs.textContent = "Invalid E-mail.";

            return false
        }
    }
    if (txtRegLSPsIndustry.value == "") {
        lblMsgErrorLSPs.innerText = "Industry is required.";
        lblMsgErrorLSPs.textContent = "Industry is required.";

        return false
    }
    if (ddlContry[ddlContry.selectedIndex].text == "-") {
        lblMsgErrorLSPs.innerText = "Country is required.";
        lblMsgErrorLSPs.textContent = "Country is required.";

        return false
    }
    if (txtRegLSPsPhone.value == "") {
        lblMsgErrorLSPs.innerText = "Phone is required.";
        lblMsgErrorLSPs.textContent = "Phone is required.";

        return false
    }

    var param = new Array();
    param[0] = txtRegLSPsFirstName.value;
    param[1] = txtRegLSPsFamilyName.value;
    param[2] = txtRegLSPsTitle.value;
    param[3] = txtRegLSPsOrganization.value;
    param[4] = txtRegLSPsEmail.value;
    param[5] = Radio1.checked;
    param[6] = Radio2.checked;
    param[7] = txtRegLSPsIndustry.value;
    param[8] = ddlContry[ddlContry.selectedIndex].text;
    param[9] = txtRegLSPsPhone.value;

    window.location = encodeURI("WebinarsRegistration.aspx?p=" + param);
}

function AsiaOnlineWebinarVideoReplayRegisstration() {

    var txtRegLSPsVideoFirstName = document.getElementById("txtRegLSPsVideoFirstName");
    var txtRegLSPsVideoFamilyName = document.getElementById("txtRegLSPsVideoFamilyName");
    var txtRegLSPsVideoTitle = document.getElementById("txtRegLSPsVideoTitle");
    var txtRegLSPsVideoOrganization = document.getElementById("txtRegLSPsVideoOrganization");
    var txtRegLSPsVideoEmail = document.getElementById("txtRegLSPsVideoEmail");

    var txtRegLSPsVideoIndustry = document.getElementById("txtRegLSPsVideoIndustry");
    var ddlContry = document.getElementById("ddlContry");
    var txtRegLSPsVideoPhone = document.getElementById("txtRegLSPsVideoPhone");

    var lblMsgErrorLSPsVideo = document.getElementById("lblMsgErrorLSPsVideo");
    
    lblMsgErrorLSPsVideo.innerText = "";

    if (txtRegLSPsVideoFirstName.value == "") {
        lblMsgErrorLSPsVideo.innerText = "First Name is required.";
        lblMsgErrorLSPsVideo.textContent = "First Name is required.";
        return false
    }
    if (txtRegLSPsVideoFamilyName.value == "") {
        lblMsgErrorLSPsVideo.innerText = "Family Name is required.";
        lblMsgErrorLSPsVideo.textContent = "Family Name is required.";
        return false
    }
    if (txtRegLSPsVideoTitle.value == "") {
        lblMsgErrorLSPsVideo.innerText = "Title/Occupation is required.";
        lblMsgErrorLSPsVideo.textContent = "Title/Occupation is required.";

        return false
    }
    if (txtRegLSPsVideoOrganization.value == "") {
        lblMsgErrorLSPsVideo.innerText = "Organization is required.";
        lblMsgErrorLSPsVideo.textContent = "Organization is required.";

        return false
    }
    if (txtRegLSPsVideoEmail.value == "") {
        lblMsgErrorLSPsVideo.textContent = "Email is required.";
        return false
    }
    else {
        if (!CheckEmail(txtRegLSPsVideoEmail.value)) {
            lblMsgErrorLSPsVideo.innerText = "Invalid E-mail.";
            lblMsgErrorLSPsVideo.textContent = "Invalid E-mail.";

            return false
        }
    }
    if (txtRegLSPsVideoIndustry.value == "") {
        lblMsgErrorLSPsVideo.innerText = "Industry is required.";
        lblMsgErrorLSPsVideo.textContent = "Industry is required.";

        return false
    }
    if (ddlContry[ddlContry.selectedIndex].text == "-") {
        lblMsgErrorLSPsVideo.innerText = "Country is required.";
        lblMsgErrorLSPsVideo.textContent = "Country is required.";

        return false
    }
    if (txtRegLSPsVideoPhone.value == "") {
        lblMsgErrorLSPsVideo.innerText = "Phone is required.";
        lblMsgErrorLSPsVideo.textContent = "Phone is required.";

        return false
    }

    var param = new Array();
    param[0] = txtRegLSPsVideoFirstName.value;
    param[1] = txtRegLSPsVideoFamilyName.value;
    param[2] = txtRegLSPsVideoTitle.value;
    param[3] = txtRegLSPsVideoOrganization.value;
    param[4] = txtRegLSPsVideoEmail.value;
    param[5] = txtRegLSPsVideoIndustry.value;
    param[6] = ddlContry[ddlContry.selectedIndex].text;
    param[7] = txtRegLSPsVideoPhone.value;

    window.location = encodeURI("WebinarsVideoReplayRegistration.aspx?p=" + param);
}



function CheckEmail(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    
    if (str.indexOf(at) == -1) {
        return false        
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false
    }

    if (str.indexOf(" ") != -1) {
        return false
    }

    return true
}
function OnkeyPressLogin(evt) {
    if (evt.keyCode == 13) {
        return LoginProcess();
    }
    return true;
}

function LoginProcess() {
    var browser = GetTypeofBrowser();
    if (browser != 'msie' && browser != 'firefox') {
        alert('Language Studio Enterprise officially supports Firefox and Internet Explorer browsers only. Other browsers my not function correctly. If you are experiencing display or function issues, please switch to either Firefox or Internet Explorer.');
        return false;
    } 
    
    var txtUsername = document.getElementById("txtUsername");
    var txtPassword = document.getElementById("txtPassword");
    
    if (txtUsername.value == "") {
        alert("Please enter your user name.");
        return false;
    }
    if (txtPassword.value == "") {
        alert("Please enter password.");
        return false;
    }
    
//var url = TranslationURL + "/Ajax/Services/ProcessLogin.aspx?username=" + txtUsername.value + "&password=" + txtPassword.value; //+ "&debug=" + new Date();
//GetLoginProcess(url)
    
    $.get("ProcessLogin.aspx", { username: txtUsername.value, password: txtPassword.value, debug: new Date() },
    function(responseText, textStatus, req) {       
    if (textStatus == "error") {
    alert('Sorry. This process is not complete ,please try again.');
    } else {
    var ret = responseText.split("|");
    if (ret[0] == "1") {
    window.location = TranslationURL;
    } else {
    txtUsername.value = "";
    txtPassword.value = "";
    txtUsername.focus();
    alert(ret[1]);
    }
    }
    });
    return false;
}

function GetTypeofBrowser() {
    var browserName = "";

    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf("opera") != -1) {
        browserName = "opera";
    } else if (ua.indexOf("msie") != -1) {
        browserName = "msie";
    } else if (ua.indexOf("safari") != -1) {
        browserName = "safari";
    } else if (ua.indexOf("mozilla") != -1) {
        if (ua.indexOf("firefox") != -1) {
            browserName = "firefox";
        } else {
            browserName = "mozilla";
        }
    }

    return browserName;
}; 
//function GetLoginProcess(url) {

//    var xmlhttp = GetXmlHttp();

//    xmlhttp.onreadystatechange = function() {

//    if (xmlhttp.readyState == 4) {
//        if (xmlhttp.status == 200) {

//                alert('success');
//            }
//        }
//    }
//    xmlhttp.open("GET", url, true);
//    xmlhttp.send(null);

//}


//function GetXmlHttp() {

//    var xmlHttpRequest = null;

//    if (window.XMLHttpRequest) {
//        try {
//            xmlHttpRequest = new XMLHttpRequest();
//        }
//        catch (e) {
//            xmlHttpRequest = false;
//        }
//    }
//    else {
//        try {
//            xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
//        }
//        catch (e) {
//            try {
//                xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
//            }
//            catch (e) {
//                xmlHttpRequest = false;
//            }
//        }
//    }

//    return xmlHttpRequest;

//}

