﻿//******************
// Digiscribe/Digi Web Development
// StandardMaster.js - April 8, 2009
//
// Local functions for the Standard.Master template page
//
//******************

//Global variables
var timeout = 500;
var closetimer = 0;
var ddmenuitem = null;

// close layer when click-out
document.onclick = mclose;

//Show arrow on mouse rollover of menu item
function ShowArrow(id) {
    var imgArrow = document.getElementById(id);
    imgArrow.style.visibility = 'visible';
}

//Hide arrow on mouse rollout of menu item
function HideArrow(id) {
    var imgArrow = document.getElementById(id);
    imgArrow.style.visibility = 'hidden';
}

//Reset the menu image to its default off image
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;
}

//Preload the menu images
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]; }
    }
}
MM_preloadImages(ImgFindYourHomeDrop, ImgSmartDesignDrop, ImgContactUsDrop, ImgStepsDrop, ImgFindYourHomeBg, ImgSmartDesignBg, ImgContactUsBg, ImgStepsBg);

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;
}

//On mouse over of a menu item this function swaps the image with it's on image
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]; }
}

// open hidden layer
function mopen(id) {
    //Close open SD callouts
    if (typeof (closeSDWindows) == "function") {
        closeSDWindows();
    }
    // cancel close timer
    mcancelclosetime();

    // close old layer
    if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';


    // get new layer and show it
    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.visibility = 'visible';

    //if any other menus were selected deselect them
    if (id != "bzr_findHome_Menu") {
        $("#" + ImgFindYourHomeID + ",#" + ImgFindYourHomeIDv2 + ",#" + ImgFindYourHomeIDv3).attr("src", ImgFindYourHomeOff);
        //        imgFindYourHome =  document.getElementById(ImgFindYourHomeID);
        //        imgFindYourHome.src = ImgFindYourHomeOff;
    }
    if (id != "bzr_smartdesign_menu") {
        $("#" + ImgSmartDesignID + ",#" + ImgSmartDesignIDv2 + ",#" + ImgSmartDesignIDv3).attr("src", ImgSmartDesignOff);
        //        imgSmartDesign = document.getElementById(ImgSmartDesignID);
        //        imgSmartDesign.src = ImgSmartDesignOff;
    }
    if (id != "bzr_stepsToOwnership_menu") {
        $("#" + ImgStepsID + ",#" + ImgStepsIDv2 + ",#" + ImgStepsIDv3).attr("src", ImgStepsOff);
        //        imgSteps = document.getElementById(ImgStepsID);
        //        imgSteps.src = ImgStepsOff;
    }
    if (id != "bzr_contactUs_Menu") {
        $("#" + ImgContactUsID + ",#" + ImgContactUsIDv2 + ",#" + ImgContactUsIDv3).attr("src", ImgContactUsOff);
        //        imgContactUs = document.getElementById(ImgContactUsID);
        //        imgContactUs.src = ImgContactUsOff;
    }
}

// close showed layer
function mclose() {
    if (ddmenuitem) { ddmenuitem.style.visibility = 'hidden'; MM_swapImgRestore(); }
}

// go close timer
function mclosetime() {
    closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

// Keep the menu itemm in a selected state when the menu image is clicked
function emptyClick(e) {
    if (!e) var e = window.event;

    e.cancelBubble = true;

    if (e.stopPropagation) e.stopPropagation();
}


// Dynamic language switcher via SetLanguage.ashx
function SwitchLanguage() {
    var url = setLanguageUrl + "?lang=" + langCode + "&t=" + escape(document.location);
    document.location = url;
}


//Global search handler
function HandleGlobalSearch() {


    var criteria = document.getElementById("txtSearchBeazer").value;
    if (criteria.trim() == "" || criteria == siteSearchDefaultText)
    /*alert(siteSearchBlankMessage);*/ return;
    else document.location = siteSearchUrl + "?q=" + escape(criteria);
}

function HandleGlobalSearchTextbox(e) {
    var keycode;

    if (window.event) {
        keycode = window.event.keyCode;
    }
    else if (e) {
        keycode = e.which;
    }

    if (keycode == 13) {
        HandleGlobalSearch();
    }
}

//Unbind events from document on unload
$(window).unload(function() {
    $(document).unbind("click");
    document.MM_sr = null;
    document.MM_p = null;
});

//Attach keyup event to textbox
$(document).ready(function() {
    $("#txtSearchBeazer").keypress(function(event) {
        if (event.keyCode == 13) {
            HandleGlobalSearch();
            return false;
        }
    });

    $("#txtSearchBeazer").focus(function() {
        if ($(this).val() == siteSearchDefaultText)
            $(this).val("");
    });

    $("#txtSearchBeazer").blur(function() {
        if ($(this).val() == "")
            $(this).val(siteSearchDefaultText);
    });

    //Uncomment lines below to hide search textbox and search text
    //    $("#txtSearchBeazer").hide();
    //    $("#txtSearchBeazer").prev("span").hide();

    //Language specific updates
    if (langCode == "") {
        $("#bzr_contactUs_Menu A SPAN").css("marginLeft", "0px");
    }
    else {
        $("#mainNav div a").css("white-space", "nowrap");
        $("#bzr_contactUs_Menu A SPAN").css("marginLeft", "2px");
    }

    //back to top link event binding
    $("#lnkPageTop").click(function() {
        $(window).scrollTop(0);
    });

    if (navigator.userAgent.indexOf("Trident/5.") > -1 || navigator.userAgent.indexOf("Trident/4.") > -1) {
        $("div.clr").css({ "line-height": "1px" });
    }

    if (navigator.userAgent.indexOf("Mac OS") > -1) {
        if (langCode == "") {
            $(".footerV2 .outerColLeft .innerCol:not(.first)").css({ marginLeft: "20px" });
            $(".footerV3 .outerColRight").css({ width: "190px" });
        }
    }
});

/*For inline form*/
var InlineLightBox;
function InitializeInlineForm() {
    InlineLightBox = new YAHOO.widget.Overlay("InlineFormLightBox", { visible: false, width: "0px", height: "0px" });
    InlineLightBox.render();
}

function OpenInlineOverlay(ht, wdt) {

    Reposition_Curtain();

    var divCurtain = YAHOO.util.Dom.get("divCurtain");
    YAHOO.util.Dom.setStyle(divCurtain, "display", "block");

    InlineLightBox.cfg.setProperty("height", ht);
    InlineLightBox.cfg.setProperty("width", wdt);

    InlineLightBox.show();
    
    Reposition_InlineOverlay();

    if (typeof (TrackAction) == "function")
        TrackAction(ifTrackingPageName, false, true);
    
        
}

var Reposition_InlineOverlay = function() {
    InlineLightBox.center();
}

function CloseInlineOverlay() {
    var divCurtain = YAHOO.util.Dom.get("divCurtain");
    YAHOO.util.Dom.setStyle(divCurtain, "display", "none");

    InlineLightBox.cfg.setProperty("height", "0px");
    InlineLightBox.cfg.setProperty("width", "0px");

    InlineLightBox.hide();

 

}



var Reposition_Curtain = function() {
    var divCurtain = YAHOO.util.Dom.get("divCurtain");

    var docHeight = YAHOO.util.Dom.getDocumentHeight();
    var docWidth = YAHOO.util.Dom.getDocumentWidth();

    divCurtain.style.width = docWidth + "px";
    divCurtain.style.height = docHeight + "px";
}
/* End inline form */


/* Ad server support */

function GetRnd() {
    return Math.random() * 1000;
}


function ShowAd(locationCode, locationParamName, width, height, align, adServerUrl) {

    var args = ParseQueryString();

    var locationParamValue = "";
    if (locationParamName == "_page_") {
        var locationInfo = window.location.pathname.split('/');
        locationParamValue = locationInfo[locationInfo.length - 1];
    }
    else {
        locationParamValue = args[locationParamName];
    }
    locationParamValue = locationParamName;
    var ad_html = "<iframe id='ifrAd" + locationCode + "' scrolling='no' margintop='0' marginleft='0' style='visibility:hidden;' src='" + adServerUrl + "?LocationCode=" + locationCode + "&LocationParamValue=" + locationParamValue + "&Width=" + width + "&Height=" + height + "&R=" + GetRnd() + "' frameborder='0' border='0' width='" + width + "' height='" + height + "&Align=" + align + "' align='" + align + "'></iframe>";
    document.write(ad_html);

}

function ToggleAdVisibility(isVisible, locationCode) {

    var ifrAd = document.getElementById("ifrAd" + locationCode);


    if (ifrAd == null) {
        return;
    }

    if (isVisible) {
        ifrAd.style.visibility = "visible";
    }
    else {
        ifrAd.style.visibility = "hidden";
    }
}

function ParseQueryString(str) {
   
    str = str ? str : location.search;

    var query = str.charAt(0) == '?' ? str.substring(1) : str;

    var args = new Object();

    //Do nothing if the query parameter is used for Facebook interaction.
    //It does not need to parsed and processed.         
    if (query == 'fb_xd_fragment') {
        
        return false;
    }

    if (query) {
        var fields = query.split('&amp;');

        for (var f = 0; f < fields.length; f++) {

            var field = fields[f].split('=');

            args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
        }

    }

    return args;
}


String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

