﻿// JScript File
$(document).ready(function() {
    createMenu();
});

function createMenu() {
    var submenuoffset = 0;
    var ultags = document.getElementById("menu-list").getElementsByTagName("ul");
    for (var t = 0; t < ultags.length; t++) {
        ultags[t].style.top = ultags[t].parentNode.offsetHeight + submenuoffset + "px";
        ultags[t].parentNode.onmouseover = function() {
            this.style.zIndex = 100
            this.getElementsByTagName("ul")[0].style.visibility = "visible";
            this.getElementsByTagName("div")[0].style.visibility = "visible";
            var h = this.getElementsByTagName("ul")[0].offsetHeight + 10;
            this.getElementsByTagName("div")[0].style.height = h + "px";
            this.getElementsByTagName("div")[0].style.marginTop = "34px";     
            if (jQuery.browser.msie) {
                if(parseInt(jQuery.browser.version) < 8)
                    this.getElementsByTagName("div")[0].style.marginTop = "0px";     
            }
        }
        ultags[t].parentNode.onmouseout = function() {
            this.style.zIndex = 0
            this.getElementsByTagName("ul")[0].style.visibility = "hidden";
            this.getElementsByTagName("div")[0].style.visibility = "hidden";
        }
    }
}

function showPersonnelContent(id) {
    var s = $('#personnel-content-' + id + ' > .pi-content-short').css('display');
    if (s != 'none') {
        $('#personnel-content-' + id + ' > .pi-content-short').hide(500);
        $('#personnel-content-' + id + ' > .pi-content-full').slideDown(500);
        $('#personnel-content-' + id + ' > .personnel-show-content > img').attr('src', 'app_themes/web/images/arrow-bullet-up.png');
    } else {
        $('#personnel-content-' + id + ' > .pi-content-full').slideUp(500);
        $('#personnel-content-' + id + ' > .pi-content-short').show(500);
        $('#personnel-content-' + id + ' > .personnel-show-content > img').attr('src', 'app_themes/web/images/arrow-bullet-down.png');
    }
}

function showDownloadContent(id) {
    var s = $('#download-content-' + id + ' > .download-content-short').css('display');
    if (s != 'none') {
        $('#download-content-' + id + ' > .download-content-short').hide(500);
        $('#download-content-' + id + ' > .download-content-full').slideDown(500);
        $('#download-content-' + id + ' > .download-show-content > img').attr('src', 'app_themes/web/images/arrow-bullet-up.png');
    } else {
        $('#download-content-' + id + ' > .download-content-full').slideUp(500);
        $('#download-content-' + id + ' > .download-content-short').show(500);
        $('#download-content-' + id + ' > .download-show-content > img').attr('src', 'app_themes/web/images/arrow-bullet-down.png');
    }
}

function showRecruitmentContent(id) {
    var s = $('#recruitment-item-' + id + ' > .recruitment-content-short').css('display');
    if (s != 'none') {
        $('#recruitment-item-' + id + ' > .recruitment-content-short').hide(500);
        $('#recruitment-item-' + id + ' > .recruitment-content-full').slideDown(500);
        $('#recruitment-item-' + id + ' > .recruitment-show-content > img').attr('src', 'app_themes/web/images/arrow-bullet-up.png');
    } else {
        $('#recruitment-item-' + id + ' > .recruitment-content-full').slideUp(500);
        $('#recruitment-item-' + id + ' > .recruitment-content-short').show(500);
        $('#recruitment-item-' + id + ' > .recruitment-show-content > img').attr('src', 'app_themes/web/images/arrow-bullet-down.png');
    }
}

function openEnquiry(str) {
    $("#txtPosition").val(str);
    $("#txtName").css('background-color', '#f2f2f2');
    $("#txtEmail").css('background-color', '#f2f2f2');
    $("#txtPhone").css('background-color', '#f2f2f2');
    $("#txtName").val('');
    $("#txtEmail").val('');
    $("#txtPhone").val('');
    $("#txtAddress").val('');
    $("#txtComment").val('');
    $("#enquiry-form").dialog('open');
}

function emailRecruitmentEnquiry() {
    $("#txtName").css('background-color', '#f2f2f2');
    $("#txtEmail").css('background-color', '#f2f2f2');
    $("#txtPhone").css('background-color', '#f2f2f2');
    var _valid = true;
    if ($("#txtName").val() == '') {
        _valid = false;
        $("#txtName").css('background-color', '#f4c6c0');
    }
    if ($("#txtEmail").val() == '') {
        _valid = false;
        $("#txtEmail").css('background-color', '#f4c6c0');
    }
    if ($("#txtPhone").val() == '') {
        _valid = false;
        $("#txtPhone").css('background-color', '#f4c6c0');
    }
    if (_valid) {
        $.ajax({
            url: 'Ajax/RecruitmentEnquirySend.aspx',
            type: "POST",
            cache: false,
            data: ({ txtPosition: $("#txtPosition").val(), txtName: $("#txtName").val(), txtEmail: $("#txtEmail").val(),
                txtPhone: $("#txtPhone").val(), txtAddress: $("#txtAddress").val(), txtComment: $("#txtComment").val()
            }),
            success: function(data) {
                if (data != 'success') {
                    alert('Message Failed');
                }
            }
        });
        $("#enquiry-form").dialog('close');
    }
    else
        return false;
}

function emailContactEnquiry() {
    $("#txtName").css('background-color', '#f2f2f2');
    $("#txtEmail").css('background-color', '#f2f2f2');
    $("#txtPhone").css('background-color', '#f2f2f2');
    var _valid = true;
    if ($("#txtName").val() == '') {
        _valid = false;
        $("#txtName").css('background-color', '#f4c6c0');
    }
    if ($("#txtEmail").val() == '') {
        _valid = false;
        $("#txtEmail").css('background-color', '#f4c6c0');
    }
    if ($("#txtPhone").val() == '') {
        _valid = false;
        $("#txtPhone").css('background-color', '#f4c6c0');
    }
    if (_valid) {
        $.ajax({
            url: 'Ajax/ContactEnquirySend.aspx',
            type: "POST",
            cache: false,
            data: ({ txtName: $("#txtName").val(), txtEmail: $("#txtEmail").val(),
                txtPhone: $("#txtPhone").val(), txtAddress: $("#txtAddress").val(), txtComment: $("#txtComment").val()
            }),
            success: function(data) {
                if (data != 'success') {
                    alert('Message Failed');
                }
            }
        });
        $("#contact-form").fadeOut(500, function() { $("#contact-thankyou").fadeIn(500) });
    }
    else
        return false;
}
