﻿function prevEmail(ID, emailserver, emailname, emailinner) {
    var span = document.getElementById(ID);
    if (span != null) {
        var str = "<a href='mailto:" + emailname + "@" + emailserver + "'>";
        if (emailinner == '') str += emailname + "@" + emailserver; else str += emailinner;
        str += "</a>";
        span.innerHTML = str;
    }
}

function MM_showHideLayers() { //v3.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v = 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}
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 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 oWin(theURL, name, height) {
    var winWidth = screen.availWidth / 2;
    var winHeight = (height <= screen.availHeight - 100 ? height : screen.availHeight - 100);
    var winLeft = 0;

    var winSettings = 'width=' + winWidth + ',height=' + winHeight + ',top=0,left=' + winLeft + ',toolbar=no,location=no,scrollbars=yes,resizable=no,titlebar=no,directories=no,status=no,menubar=no';

    oWinID = window.open(theURL, name, winSettings);
}

/* For UserControls/Contact.ascx.cs

- Limits number of characters in a TextBox (txtMessage) writing the number of characters remaining in lblCharLeftID

*/
function LimitTextMessage(txtMessageID, txtMessageMaxLength, lblCharLeftID) {
    var countText = document.getElementById(lblCharLeftID);
    var inputText = document.getElementById(txtMessageID);
    var curLen = inputText.value.length;
    var maxLen = txtMessageMaxLength;

    if (maxLen > curLen) {
        SetInnerText(countText, maxLen - curLen);
    }
    else {
        SetInnerText(countText, 0);
        inputText.value = inputText.value.substr(0, maxLen);
    }
}

//Assigns the text to an object's InnerText depending on MS IE or Firefox
function SetInnerText(obj, text) {
    if (obj.innerText)          // MS IE
    {
        obj.innerText = text
    }
    else if (obj.textContent)   // Firefox
    {
        obj.textContent = text
    }
}

/**********************************************
*  Start application specific scripting
***********************************************/

function oWinNews(uri) {
    window.open(uri, 'WinNews', 'width=800,height=400,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0');
    //window.open('about:blank',"holsearch","screenx=20,screeny=20,top=20,left=20,location=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,directories=no");
}

function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en' }, 'google_translate_element'); }

//called on page load (first 'full, non ajax' load);
$(document).ready(function () {
    main();
});

function main() {
    //disable right-click on entire document (copy-protect!)
    $(document).bind("contextmenu", function (e) { return false; });

    //disable right-click on just img elements (copy-protect!)
    //$('img').bind("contextmenu", function (e) { return false; });

    //change css class on form input fields when activated
    var inputs = $('input[type=text], input[type=password], select, textarea');
    inputs.triggerHandler("focus");
    inputs.focus(function () { $(this).addClass('input_onfocus'); });
    inputs.blur(function () { $(this).removeClass('input_onfocus'); });

    //track click-throughs to 3rd party pages via Google Analytics...
    //$("a[rel*='nofollow']").click(function() {
    $("a[target*='_blank']").click(function () {
        if (typeof (pageTracker) != "undefined")
            pageTracker._trackPageview('/outgoing/' + $(this).attr('href'));
    });

    //breakout of frames
    if (parent != window) { parent.location = location.href; }

    //googleTranslateElementInit();

    if ($().lightBox)
        $('a.lightbox').lightBox({ fixedNavigation: true }); // Select all links with lightbox class

    if ($().flash) {
        //		360_degree_feedback
        //		about
        //		clients
        //		coaching_masterclasses
        //		contact
        //		$('.default').flash({ swf: 'img/swf/default.swf', width: 610, height: 100, play: true, quality: 'high', wmode: 'transparent' });
        //		executive_coaching
        //		executive_coaching_case_studies
        //		executive_coaching_faqs
        //		executive_coaching_goals
    }

    //set-up search box
    var inputs = $("#q");
    //inputs.triggerHandler("focus");
    inputs.focus(function () {
        if ($(this).val() == "Search...") $(this).val("");
    });
    inputs.blur(function () {
        if ($(this).val().length == 0) $(this).val("Search...");
    });
    inputs.keypress(function (event) {
        if (event.keyCode == '13' && $(this).val().length > 0) {
            doSearch($(this).val());
            return false;
        }
    });

    /*
    inputs.mousedown(function () {
    if ($(this).val().length>0)
    doSearch($(this).val());
    });

    inputs.click(function () {
    if ($(this).val().length>0)
    doSearch($(this).val());
    //return false;
    });
    */
}

function doSearch(q) {
    //alert('wtf');
    if (q != "Search...") {
        //var prefix="search.aspx?q="+q;
        document.location = "search.aspx?q=" + q;
        //$('#iframeSearch').attr('src', prefix);
        //$('#dialog').dialog('open');
    }
}

function InsertFlashHeader(filePath) {
    document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0' id='index' width='610' height='129'>")
    document.write("<param name='movie' value='" + filePath + "' />");
    document.write("<param name='bgcolor' value='#FFFFFF' />");
    document.write("<param name='quality' value='high' />");
    document.write("<param name='allowscriptaccess' value='samedomain' />");
    document.write("<embed type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' name='index' width='610' height='129' src='" + filePath + "' bgcolor='#FFFFFF' quality='high' swliveconnect='true' allowscriptaccess='samedomain'><noembed></noembed></embed>");
    document.write("</object>");
}

function InsertFlashHeaderv2(filePath) {
    document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0' id='index' width='525' height='100'>")
    document.write("<param name='movie' value='" + filePath + "' />");
    document.write("<param name='bgcolor' value='#FFFFFF' />");
    document.write("<param name='quality' value='high' />");
    document.write("<param name='allowscriptaccess' value='samedomain' />");
    document.write("<embed type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' name='index' width='525' height='100' src='" + filePath + "' bgcolor='#FFFFFF' quality='high' swliveconnect='true' allowscriptaccess='samedomain'><noembed></noembed></embed>");
    document.write("</object>");
}
