﻿//=========================================
//      Landing page functions
//=========================================
function DisplayAbstract(id) {
    document.getElementById(id).style.display = 'block';
}

function ETrainingProgram(id, width, height) {
    var height = height; 							    // define the popup's height;
    var width = width; 							        // define the popup's width;
    var top = (screen.availHeight - height) / 2; 	    // define the popup's vertical position on screen;
    var left = (screen.availWidth - width) / 2; 		// define the popup's horizontal position on screen;
    window.open("/common/shared/webseminar/etraining/program.aspx?id=" + id, "program", "width=" + width + ",height=" + height + ",toolbar=no,scrollbars=yes,status=no,resizable=no,top=" + top + ",left=" + left);
}

function SpeakerDescription(id) {
    var height = "300"; 							    // define the popup's height;
    var width = "400"; 							        // define the popup's width;
    var top = (screen.availHeight - height) / 2; 	    // define the popup's vertical position on screen;
    var left = (screen.availWidth - width) / 2; 		// define the popup's horizontal position on screen;
    window.open("/common/shared/webseminar/speaker.aspx?id=" + id, "speaker", "width=" + width + ",height=" + height + ",toolbar=no,scrollbars=yes,status=no,resizable=no,top=" + top + ",left=" + left);
}

function ChangeStyle(layer, layerstyle) {
    if (document.all && document.all[layer])
        document.all[layer].style.color = layerstyle;
    else if (document.getElementById(layer))
        document.getElementById(layer).style.color = layerstyle;
}

function DisplayMultiSeatOffers() {
    document.getElementById('etcfeemultiseatoffer1').style.display = 'block';
    document.getElementById('etcfeemultiseatoffer2').style.display = 'block';
}

//=========================================
//      Tabs Navigation Management
//=========================================
function ShowTab(index) {
    var list = document.getElementById("etctablist").childNodes;
    for (var i = 1; i <= 5; i++) {
        if (document.getElementById("etctab" + i) && document.getElementById("tab" + i))
        {
            document.getElementById("etctab" + i).style.display = "none";
            document.getElementById("tab" + i).className = "";
        }
    }

    if (document.getElementById("etctab" + index) && document.getElementById("tab" + index)) {
        document.getElementById("etctab" + index).style.display = "block";
        document.getElementById("tab" + index).className = "current";
    }

    if (index == 5) {
        document.getElementById("etctabgreenborder").style.display = "block";
        document.getElementById("etctabblueborder").style.display = "none";
        moveTo('#form');
    }
    else {
        document.getElementById("etctabblueborder").style.display = "block";
        document.getElementById("etctabgreenborder").style.display = "none";
    }

    BackUpTab(index);
}


//=========================================
//      Tabs Navigation Track
//=========================================
function InitEtrainingTabs() {
    if (GetValueFromURL("tab") != null) {
        var tab = GetValueFromURL("tab");
        switch (tab) {
            case "1":
                ShowTab('1');
                break;
            case "2":
                ShowTab('2');
                break;
            case "3":
                ShowTab('3');
                break;
            case "4":
                ShowTab('4');
                break;
            case "5":
                ShowTab('5');
                break;
        }
    }
    else {
        BackUpTab(1);
    }
}

function createRequestObject() {
    var req;
    if (window.XMLHttpRequest) {
        // Firefox, Safari, Opera...
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // Internet Explorer 5+
        req = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        // There is an error creating the object,
        // just as an old browser is being used.
        //alert('Problem creating the XMLHttpRequest object');
    }
    return req;
}

// Make the XMLHttpRequest object
var http = createRequestObject();

function BackUpTab(tab) {
    var id = GetValueFromURL("id");

    try {
        http.open('get', '/common/shared/webseminar/etraining/backuptab.aspx?t=' + tab + '&id=' + id);
        //http.onreadystatechange = handleResponse;
        http.send(null);
    }
    catch (err) { }
}

//=========================================
//      Registration Form Validation
//=========================================
function isPhoneNumber(aStr) {
    var index;
    var reg = "0123456789()+/\\-_. "
    for (index = 0; index < aStr.length; index++)
        if (reg.indexOf(aStr.charAt(index)) == -1)
        return false;
    return true;
}

function checkphone(champ, message) {
    if (!isPhoneNumber(champ.value)) {
        alert(message);
        champ.select();
    }
}

function Validation() {
    var FirstName   = getObjFormField("WsSignUp", "FirstName");
    var LastName    = getObjFormField("WsSignUp", "LastName");
    var Company     = getObjFormField("WsSignUp", "Company");
    var Country     = getObjFormField("WsSignUp", "Country");
    var Email       = getObjFormField("WsSignUp", "Email");
    var InterPhone  = getObjFormField("WsSignUp", "InterPhone");
    var Phone       = getObjFormField("WsSignUp", "PhoneNumber");
    var Address     = getObjFormField("WsSignUp", "Address");
    var Job         = getObjFormField("WsSignUp", "Job");
    var Zip         = getObjFormField("WsSignUp", "ZipCode");
    var City        = getObjFormField("WsSignUp", "City");
    var Activity    = getObjFormField("WsSignUp", "Activity");
    var VAT         = getObjFormField("WsSignUp", "VAT");
    var form        = getObjForm("WsSignUp");
    // First Name
    if (isNull(FirstName.value)) {
        alert("First Name is required.");
        FirstName.focus();
        return;
    }
    // Last Name
    if (isNull(LastName.value)) {
        alert("Last Name is required.");
        LastName.focus();
        return;
    }
    // Email
    if (isNull(Email.value)) {
        alert("E-Mail is required.");
        Email.focus();
        return;
    }
    if (!checkmail(Email.value)) {
        alert("Email address does not seem to be valid.");
        Email.focus();
        return;
    }
    // Company Name
    if (isNull(Company.value)) {
        alert("Company is required.");
        Company.focus();
        return;
    }
    // Job
    if (Job.selectedIndex == 0) {
        alert("Job is required.");
        Job.focus();
        return;
    }
    // Activity
    if (Activity.selectedIndex == 0) {
        alert("Main activity is required.");
        Activity.focus();
        return;
    }
    // Address
    if (isNull(Address.value)) {
        alert("Address is required.");
        Address.focus();
        return;
    }
    // Area/Zip Code
    if (Zip && isNull(Zip.value)) {
        alert("Area / Zip Code is required.");
        Zip.focus();
        return;
    }
    // City
    if (isNull(City.value)) {
        alert("City is required.");
        City.focus();
        return;
    }
    // Country
    if (Country.selectedIndex == 0) {
        alert("Country is required.");
        Country.focus();
        return;
    }
    // Phone number
    if (isNull(Phone.value)) {
        alert("Phone is required.");
        Phone.focus();
        return;
    }
    else if (isNull(InterPhone.value)) {
        alert("International code for phone is required.");
        InterPhone.focus();
        return;
    }

    //VAT
    if (!isNull(VAT.value)) {
        if (!CheckVATValue(VAT.value)) {
            alert("Please check your VAT identification number.");
            VAT.focus();
            return;
        }
    }

    // CkeckBoxes
    check = false;
    ctr = 0;
    for (i = 0; i < form.length; i++) {
        if ((form[i].type == "checkbox") && (form[i].name.indexOf("SessionDate") > -1)) {
            ctr++;
            if (form[i].checked) {
                check = true;
            }
        }
    }
    if (ctr > 0) {
        if (!check) {
            alert("Please choose a session date.");
            return;
        }
    }

    form.submit();
}

//=========================================
//      VAT Code Validation
//=========================================
function SelectCountry() {
    var obj = getObjFormField("WsSignUp", "Country");
    var VAT = getObjFormField("WsSignUp", "VATIDNumber");

    switch (obj.options[obj.selectedIndex].value) {
        case "39": //Austria
        case "40": //Belgium
        case "85": //Cyprus
        case "67": //Czech Republic
        case "44": //Germany
        case "41": //Denmark
        case "68": //Estonia
        case "47": //Greece
        case "57": //Spain
        case "42": //Finland
        case "60": //United Kingdom
        case "69": //Hungary
        case "49": //Ireland
        case "50": //Italy
        case "71": //Lithuania
        case "51": //Luxembourg
        case "70": //Latvia
        case "209": //Malta
        case "53": //Netherlands / Holland
        case "74": //Poland
        case "55": //Portugal
        case "58": //Sweden
        case "78": //Slovenia
        case "77": //Slovak Republic
            VAT.disabled = false;
            ChangeStyle("vatlayer", "#000000");
            break;
        default:
            VAT.value = "";
            VAT.disabled = true;
            ChangeStyle("vatlayer", "#CCCCCC");
            break;
    }
}
function CheckVATValue(value) {
    var obj = getObjFormField("WsSignUp", "Country");

    var regex = null;
    switch (obj.options[obj.selectedIndex].value) {
        case "39": //Austria
            regex = /^(ATU)(\d){8}$/;
            break;
        case "40": //Belgium
            regex = /^(BE)(\d){9,10}$/;
            break;
        case "85": //Cyprus
            regex = /^(CY)(\d){8}[A-Z]$/;
            break;
        case "67": //Czech Republic
            regex = /^(CZ)(((\d){8})|((\d){9})|((\d){10}))$/;
            break;
        case "44": //Germany
            regex = /^(DE)(\d){9}$/;
            break;
        case "41": //Denmark
            regex = /^(DK)(\d){8}$/;
            break;
        case "68": //Estonia
            regex = /^(EE)(\d){9}$/;
            break;
        case "47": //Greece
            regex = /^(EL)(\d){8,9}$/;
            break;
        case "57": //Spain
            regex = /^(ES)[0-9A-Z](\d){7}[0-9A-Z]$/;
            break;
        case "42": //Finland
            regex = /^(FI)(\d){8}$/;
            break;
        case "60": //United Kingdom
            regex = /^(GB)(((\d){9})|((\d){12})|((GD|HA)(\d){3}))$/;
            break;
        case "69": //Hungary
            regex = /^(HU)(\d){8}$/;
            break;
        case "49": //Ireland
            regex = /^(IE)\d[0-9A-Z+*](\d){5}[A-Z]$/;
            break;
        case "50": //Italy
            regex = /^(IT)(\d){11}$/;
            break;
        case "71": //Lithuania
            regex = /^(LT)(((\d){9})|((\d){12}))$/;
            break;
        case "51": //Luxembourg
            regex = /^(LU)(\d){8}$/;
            break;
        case "70": //Latvia
            regex = /^(LV)(\d){11}$/;
            break;
        case "209": //Malta
            regex = /^(MT)(\d){8}$/;
            break;
        case "53": //Netherlands / Holland
            regex = /^(NL)(\d){9}(B)(\d){2}$/;
            break;
        case "74": //Poland
            regex = /^(PL)(\d){10}$/;
            break;
        case "55": //Portugal
            regex = /^(PT)(\d){9}$/;
            break;
        case "58": //Sweden
            regex = /^(SE)(\d){12}$/;
            break;
        case "78": //Slovenia
            regex = /^(SI)(\d){8}$/;
            break;
        case "77": //Slovak Republic
            regex = /^(SK)(\d){10}$/;
            break;
    }
    if (regex != null) {
        var vat = value.toUpperCase().replace(" ", "");
        return regex.test(vat);
    }
    return false;
}

//=========================================
//      Alerts
//=========================================
function UnCheckAlerts() {
    var form = getObjForm("Form1");
    for (var i = 0; i < form.length; i++) {
        if (form[i].type == "checkbox") {
            form[i].checked = false;
        }
    }
}
