﻿function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function sniffer() {

    var windowWidth = (screen.availWidth - 100) + "px";
    var windowHeight = screen.availHeight / 4 * 3 + "px";
    var mleft = document.body.clientWidth;
    var el = document.getElementById("PanelDef");

    el.style.width = mleft - (mleft / 15);
    el.style.left = (mleft / 15) / 2;
    el.style.margin = "auto";

}

function fn_SlowDownMarquee() {
    var Marquee = document.getElementById("LinksMarquee");
    Marquee.scrollDelay = 1000;   //scrollDelay="100"
}

function fn_SpeedUpMarquee() {
    var Marquee = document.getElementById("LinksMarquee");
    Marquee.scrollDelay = 100;   //scrollDelay="100"
}

function OpenBreakingNews(NewsID) {
    if (NewsID > 0) {
        var newwindow = window.open("DocOpen.aspx?NewsID=" + NewsID, '', 'resizable,scrollbars');
    }
}

function OpenGalleryImg(ImgID) {
    var newwindow = window.open("DocOpen.aspx?TypeID=2&ImgID=" + ImgID, '', 'resizable,scrollbars');
}

function OpenPackageDoc(DocID) {
    var newwindow = window.open("DocOpen.aspx?TypeID=7&DocID=" + DocID, '', 'resizable,scrollbars');
}

function fn_OpenWindow(winpath) {
    var newwindow = window.open(winpath, '', 'resizable,scrollbars');
}

function OpenTestimonial(TestimonialID) {
    var newwindow = window.open("DocOpen.aspx?TypeID=1&TestimonialID=" + TestimonialID, '', 'resizable,scrollbars');
}

function OpenTestimonialCompanyImage(TestimonialID) {
    var newwindow = window.open("TestimonialsSDM.aspx?Action=ViewImage&TestimonialID=" + TestimonialID, '', 'resizable,scrollbars');
}

function OpenInfoCentrePDF(InfoID) {
    var newwindow = window.open("DocOpen.aspx?TypeID=4&InfoID=" + InfoID, '', 'resizable,scrollbars');
}

function fn_Validation() {
    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyName').value == "") {
        alert("Please fill in your Company Name!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtCompanyName").focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtFirstName').value == "") {
        alert("Please fill in your Firstname!");
        document.getElementById('_ctl0_ContentPlaceHolder2_txtFirstName').focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').value == "") {
        alert("Please fill in your Email address!");
        document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').value.length > 100) {
        alert("Your email address is too long!");
        document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').value != "") {
        entered = document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').value;
        apos = entered.indexOf("@");
        dotpos = entered.lastIndexOf(".");
        lastpos = entered.length - 1;
        if (apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2) {
            alert("Your email address is not in a correct format!");
            document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').focus();
            window.event.returnValue = false; return (false);
        }
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtRequest').value == "") {
        alert("Please fill in your Request!");
        document.getElementById('_ctl0_ContentPlaceHolder2_txtRequest').focus();
        window.event.returnValue = false; return (false);
    }
}

function fn_SubscribeVal() {

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtLegalCompanyName').value == "") {
        alert("Please fill in your Legal Company Name!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtLegalCompanyName").focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtTradingCompanyName').value == "") {
        alert("Please fill in your Trading Company Name!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtTradingCompanyName").focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtContactPerson').value == "") {
        alert("Please fill in your Contact Person's name and surname!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtContactPerson").focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').value == "") {
        alert("Please fill in your Email address!");
        document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').value.length > 100) {
        alert("Your email address is too long!");
        document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').value != "") {
        entered = document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').value;
        apos = entered.indexOf("@");
        dotpos = entered.lastIndexOf(".");
        lastpos = entered.length - 1;
        if (apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2) {
            alert("Your email address is not in a correct format!");
            document.getElementById('_ctl0_ContentPlaceHolder2_txtEmailAddr').focus();
            window.event.returnValue = false; return (false);
        }
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtTelephoneNo').value == "") {
        alert("Please fill in your Contact Person's Telephone number!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtTelephoneNo").focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtFaxNo').value == "") {
        alert("Please fill in your Contact Person's Fax number!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtFaxNo").focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtCellNo').value == "") {
        alert("Please fill in your Contact Person's Cellphone number!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtCellNo").focus();
        window.event.returnValue = false; return (false);
    }   
    
    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtVAT').value == "") {
        alert("Please fill in your Company's VAT Number!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtVAT").focus();
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_cbType').value == false) {
        alert("Please select a Business Type!");
        window.event.returnValue = false; return (false);
    }

    if (document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyReg').value == "") {
        alert("Please fill in your Company Registration Number!");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtCompanyReg").focus();
        window.event.returnValue = false; return (false);
    }
    else {
        fn_CheckRegNo();
    }
}

function fn_CheckOption(obj, msg) {
    alert(obj.value);
    if (obj.selectedIndex == 0) {
        alert(msg);
        obj.focus();
        window.event.returnValue = false; return (false);
    }
    else
    { return (true); }
}

function fn_CheckRegNo() {
    var inputStr = document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyReg').value;
    var list = document.getElementById('_ctl0_ContentPlaceHolder2_cbType');
    var bType = list.options[list.selectedIndex].text;

    if (inputStr != "") {
        switch (bType) {
            case "Private Company Mpy":
                if (!(/(^(\d{4})\/(\d{5,6})\/(0(6|7))$)/.test(inputStr))) {
                    alert("Company registration number does not match that of a Private Company Mpy");
                    document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyReg').focus();
                    window.event.returnValue = false;
                    return (false);
                }
                break
 
            case "Closed Corporation CC":
                if (!(/(^(\d{4})\/(\d{5,6})\/(23)$)/.test(inputStr))) {
                    alert("Company registration number does not match that of a Closed Corporation");
                    document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyReg').focus();
                    window.event.returnValue = false;
                    return (false);
                }
                break
            case "Public Company":
                if (!(/(^(\d{4})\/(\d{5,6})\/(0(6|7))$)/.test(inputStr))) {
                    alert("Company registration number does not match that of a Public Company");
                    document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyReg').focus();
                    window.event.returnValue = false;
                    return (false);
                }
                break
            case "Trust":
                if (!(/(^(\d{3,4})\/(\d{2,4})$)/.test(inputStr))) {
                    alert("Company registration number does not match that of a Trust");
                    document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyReg').focus();
                    window.event.returnValue = false;
                    return (false);
                }
                break
            case "Sole Trader":
                var strID = document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyReg').value;
                CheckValidID(strID);
                break
            default:
                if (!(/(^(\d{4})\/(\d{6})\/(\d{2})$)/.test(inputStr))) {
                    alert("Company registration number in incorrect format!");
                    document.getElementById('_ctl0_ContentPlaceHolder2_txtCompanyReg').focus();
                    window.event.returnValue = false;
                    return (false);
                }
                break
        }
    }
}

function fn_LoadInfoCentreDetail(GroupID) {
    var myDiv = document.getElementById("div" + GroupID).id;

    if (document.getElementById(myDiv).style.display == "block") {
        document.getElementById(myDiv).style.display = "none";

    }
    else {
        document.getElementById(myDiv).style.display = "block";
    }
}

function fn_Loaded() {
    //    try {
    //        document.getElementById("_ctl0_ContentPlaceHolder1_iframePanes").src = "WheatherAddIn.aspx";
    //    }
    //    catch (e) { }

    //    try {
    //        document.getElementById("iframePanes").src = "WheatherAddIn.aspx";
    //    }
    //    catch (e) { }
}

function fn_OpenWindow(winpath) {
    var newwindow = window.open(winpath, '', 'resizable,scrollbars');
}


function fn_DisplayReadMore() {
    var MyDiv = document.getElementById("_ctl0_ContentPlaceHolder2_divReadMore");

    if (MyDiv.style.display == "block") {
        MyDiv.style.display = "none";
    }
    else {
        MyDiv.style.display = "block";
    }
}

function fn_SubscriptionID(SubscriptID) {
    document.getElementById("_ctl0_ContentPlaceHolder2_txtSubscription").value = SubscriptID;
}

function CheckValidID(strIDNum) {
    var val1 = 0;
    var val2 = 0;
    var iLoop;
    var cTmp;
    var strID = new String(strIDNum);
    if (strID.length == 13) {
        for (iLoop = 0; iLoop < 13; iLoop = iLoop + 2) {
            cTmp = strID.charAt(iLoop);
            if (isNaN(cTmp)) {
                alert("ID cannot contain non-numeric characters");
                document.getElementById("_ctl0_ContentPlaceHolder2_txtCompanyReg").focus();
                window.event.returnValue = false;
                return (false);
            }
            val1 = val1 + eval(cTmp);
        }
        for (iLoop = 1; iLoop < 12; iLoop = iLoop + 2) {
            cTmp = strID.charAt(iLoop);
            if (isNaN(cTmp)) {
                alert("ID cannot contain non-numeric characters");
                document.getElementById("_ctl0_ContentPlaceHolder2_txtCompanyReg").focus();
                window.event.returnValue = false;
                return (false);
            }
            cTmp = eval(cTmp) * 2;
            if (cTmp >= 10) {
                cTmp = (cTmp - 10) + 1;
            }
            val2 = val2 + cTmp;
        }
        var iTotal = ((val1 + val2) / 10);
        cTmp = iTotal.toString(10);
        var sTmp = ".";
        var iValid = cTmp.indexOf(sTmp, 0);
        if (iValid == -1) {
            //alert("Valid ID !!");
            return true;
        }
        else {
            alert("Please enter a valid ID #");
            document.getElementById("_ctl0_ContentPlaceHolder2_txtCompanyReg").focus();
            return false;
        }
    }
    else {
        alert("Please, enter a thirteen digit number.");
        document.getElementById("_ctl0_ContentPlaceHolder2_txtCompanyReg").focus();
        window.event.returnValue = false;
        return (false);
    }
}
