﻿/*********************************OLD flash init***********************************/
var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
function popupClipboard(url) {
    window.open(url, 'clipboard', 'status=1,width=960,height=' + screen.height + ',scrollbars=yes,menubar=yes,resizable=yes');
    return false;
}
function popupAfrica() {
    if (hasReqestedVersion)
        window.open('Flash/flvvideos/bikesAfricaMov.html', 'africa', 'status=1,width=822,height=450,scrollbars=no,menubar=no,resizable=yes');
    else
        location.href = 'BikeAfrica.aspx';
    return false;
}


/********************Custom Alerts************************************************************************/
function ValidationSummaryOnSubmit(validationGroup) {
    if (typeof (Page_ValidationSummaries) == "undefined") {
        return;
    }
    var summary, sums, s;
    for (sums = 0; sums < Page_ValidationSummaries.length; sums++) {
        summary = Page_ValidationSummaries[sums];
        summary.style.display = "none";
        if (!Page_IsValid && IsValidationGroupMatch(summary, validationGroup)) {
            var i;
            if (summary.showsummary != "False") {
                summary.style.display = "";
                if (typeof (summary.displaymode) != "string") {
                    summary.displaymode = "BulletList";
                }
                switch (summary.displaymode) {
                    case "List":
                        {
                            headerSep = "<br>";
                            first = "";
                            pre = "";
                            post = "<br>";
                            end = "";
                            break;
                        }
                    case "BulletList":
                    default:
                        {
                            headerSep = "";
                            first = "<ul>";
                            pre = "<li>";
                            post = "</li>";
                            end = "</ul>";
                            break;
                        }
                    case "SingleParagraph":
                        {
                            headerSep = " ";
                            first = "";
                            pre = "";
                            post = " ";
                            end = "<br>";
                            break;
                        }
                }

                s = "";
                if (typeof (summary.headertext) == "string") {
                    s += summary.headertext + headerSep;
                }
                s += first;
                for (i = 0; i < Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid && typeof (Page_Validators[i].errormessage) == "string") {
                        s += pre + Page_Validators[i].errormessage + post;
                    }
                }
                s += end;
                summary.innerHTML = s;
                window.scrollTo(0, 0);
            }

            if (summary.showmessagebox == "True") {
                s = "";
                if (typeof (summary.headertext) == "string") {
                    s += summary.headertext + "<br>";
                }
                var ctrId;
                var lastValIndex = Page_Validators.length - 1;
                for (i = 0; i <= lastValIndex; i++) {
                    if (!Page_Validators[i].isvalid && typeof (Page_Validators[i].errormessage) == "string") {
                        switch (summary.displaymode) {
                            case "List":
                                {
                                    s += "<p>" + Page_Validators[i].errormessage + "</p>";

                                    break;
                                }
                            case "BulletList":
                            default:
                                {

                                    s += "<div class=\"msg\"> " + Page_Validators[i].errormessage + "</div>";
                                    if (!ctrId) {
                                        ctrId = Page_Validators[i].controltovalidate;
                                    }

                                    break;
                                }
                            case "SingleParagraph":
                                {
                                    s += Page_Validators[i].errormessage + " ";
                                    break;
                                }
                        }
                    }
                }
                showAlert(s, ctrId, "error");

            }

        }

    }

}


function showAlert(innerMsg, controlId, msgType, userAction) {
    var msg = innerMsg;
    if (typeof (innerMsg) == "object") {
        msg = "";
        for (var i = 0; i < innerMsg.length; i++) {
            msg += "<div class=\"msg\"> " + innerMsg[i].Message + "</div>";

        }

    }
    if (typeof (msgType) != "string") {
        msgType = "error";
    }

    //e.preventDefault();
    var popUp = $(".bf-msg");
    popUp.attr("class", "bf-msg " + msgType);
    popUp.find(".text").html(msg);

    //Get the screen height and width  
    var maskHeight = $(document).height();
    var maskWidth = $(document).width();

    var winH = $(window).height();
    var winW = $(window).width();


    $(".m-pop-up-background").height(maskHeight);
    $(".m-pop-up-background").width(maskWidth);
    $(".m-pop-up-background").fadeTo("slow", 0.6);

    popUp.show();
    popUp.css('top', winH / 2 - popUp.height() / 2 + 'px');
    popUp.css('left', winW / 2 - popUp.width() / 2 + 'px');
    popUp.find(".close-button").focus();
    $(window).resize(function() {
        winH = $(window).height();
        winW = $(window).width();
        $(".m-pop-up-background").width(winW);
        popUp.css('top', winH / 2 - popUp.height() / 2 + 'px');
        popUp.css('left', winW / 2 - popUp.width() / 2 + 'px');
    });

    $(".close-button").bind("click", function() {
        popUp.hide();
        $(".m-pop-up-background").fadeOut("slow");
        $(this).unbind("click");
        if (controlId) {
            document.getElementById(controlId).focus();
        }
        messageAcction({ "MsgType": msgType, "Button": "ok", "Action": userAction });
        userAction = "";
    });

    $(".submit-button.yes").bind("click", function() {
        messageAcction({ "MsgType": msgType, "Button": "yes", "Action": userAction });
        userAction = "";
        popUp.hide();
        $(".m-pop-up-background").fadeOut("slow");
        $(this).unbind("click");
        if (controlId) {
            document.getElementById(controlId).focus();
        }

    });

}
function messageAcction(acction) {

}





/************************************Init Hide text*********************************************************/
function initHideText(controlId, initText) {
    var text = initText;

    $("[id$='" + controlId + "']").focus(function() {

        var value = $(this).val();
        if (value == text) {
            $(this).val("");

        }
    });

    $("[id$='" + controlId + "']").blur(function() {
        var value = $(this).val();
        if (!value) {
            $(this).val(text);
        }
    });

}
/*******************************Most Requested Action******************************************************/

function MostRequestedAction(link, e) {
    //e.preventDefault(); 
    var popUp = $(".most-requested");

    //Get the screen height and width  
    var maskHeight = $(document).height();
    var maskWidth = $(document).width();

    var winH = $(window).height();
    var winW = $(window).width();

    $(".m-pop-up-background").height(maskHeight);
    $(".m-pop-up-background").width(maskWidth);
    $(".m-pop-up-background").fadeTo("slow", 0.8);

    popUp.show();
    popUp.css('top', winH / 2 - popUp.height() / 2 + 'px');
    popUp.css('left', winW / 2 - popUp.width() / 2 + 'px');

    $(window).resize(function() {
        winH = $(window).height();
        winW = $(window).width();
        $(".m-pop-up-background").width(winW);
        $(".leaving-pop-up").css('top', winH / 2 - popUp.height() / 2 + 'px');
        $(".leaving-pop-up").css('left', winW / 2 - popUp.width() / 2 + 'px');
    });
    $("a.close-link").click(function() {
        popUp.hide();
        $(".m-pop-up-background").fadeOut("slow");
    });

}

/****************************check box *************************************/


function swithCheckBox(checkbox, load) {

    if (!load) {
        if ($("[id$='_" + checkbox + "']").attr("checked") == true) {

            $("div[name='" + checkbox + "']").attr("class", "checkboxOff")
            $("[id$='_" + checkbox + "']").attr("checked", false);
        }
        else {
            $("div[name='" + checkbox + "']").attr("class", "checkboxOn");
            $("[id$='_" + checkbox + "']").attr("checked", true);
        }
    } else {
        if (!$("[id$='_" + checkbox + "']").attr("checked")) {

            $("div[name='" + checkbox + "']").attr("class", "checkboxOff")
        }
        else {
            $("div[name='" + checkbox + "']").attr("class", "checkboxOn");
        }

    }
}

/********************************** Print Page************************************/
function printPage() {
    var prefex = "_" + Math.random() * 1000;
    prefex = prefex.replace(".", "");
    var styleLinks = $("<p>").append($("link[rel='stylesheet']").clone()).html();
    if ($(".print-section").length > 0) {
        if (w = window.open("about:blank", "Print" + prefex)) {


            var obj = buidPrintHtmlEvent($(".print-section").clone());

            if (obj) {
                new_html = obj.html();
            }

            var html =
                    "<html>" +
                        "<head>" +
                            styleLinks +
                            "<link rel=\"stylesheet\" type=\"text/css\" href=\"css/print.css\">" +
                        "</head>" +
                        "<body onload=\"window.print();\">" +
                            new_html +
                        "</body>" +

                    "</html>";

            w.document.write(html);
            w.document.close();
        }
    }

    else {
        window.print();
    }
}

function buidPrintHtmlEvent(targetObject) {
    return targetObject;
}


//$(document).ready(function() {
//    $.sifr({
//        path: 'JS/JQuery/Plugins/sIFR/',
//        save: true
//    });
//});


//$(document).ready(function() {

//    if (typeof sIFR == "function") {

//        // This is the preferred "named argument" syntax
//        //sIFR.replaceElement(named({ sSelector: "body h1", sFlashSrc: "tradegothic.swf", sColor: "#000000", sLinkColor: "#000000", sBgColor: "#FFFFFF", sHoverColor: "#CCCCCC", nPaddingTop: 20, nPaddingBottom: 20, sFlashVars: "wmode=transparent&textalign=center&offsetTop=6" }));

//        // This is the older, ordered syntax
//        sIFR.replaceElement("h5#pullquote", "tradegothic.swf", "#000000", "#000000", "#FFFFFF", "#FFFFFF", 0, 0, 0, 0, "wmode=transparent");
//        sIFR.replaceElement("h2", "tradegothic.swf", "#000000", null, null, null, 0, 0, 0, 0, "wmode=transparent");
//        sIFR.replaceElement("h4.subhead", "tradegothic.swf", "#660000", null, null, null, 0, 0, 0, 0);
//        sIFR.replaceElement("h3.sidebox", "tradegothic.swf", "#000000", "#000000", "#DCDCDC", "#DCDCDC", 0, 0, 0, 0, null);
//        //        sIFR.replaceElement("h3", "tradegothic.swf", "#000000", null, null, null, 0, 0, 0, 0, null);
//       


//    };


//});




