﻿function AddToFavorites() {
    debugger;
    var ua = navigator.userAgent.toLowerCase();
    var isKonq = (ua.indexOf('konqueror') != -1);
    var isSafari = (ua.indexOf('webkit') != -1);
    var isMac = (ua.indexOf('mac') != -1);
    var buttonStr = isMac ? 'Command/Cmd' : 'CTRL';
    var url = window.location.href;
    var title = document.title;

    // IE4/Win generates an error when you
    // execute "typeof(window.external.AddFavorite)"
    // In IE7 the page must be from a web server, not directly from a local
    // file system, otherwise, you will get a permission denied error.
    if (window.external && (!document.createTextNode ||
      (typeof (window.external.AddFavorite) == 'unknown'))) {
        window.external.AddFavorite(url, title); // IE/Win
    } else if (isKonq) {
        alert('You need to press CTRL + B to bookmark our site.');
    }

    // This does work, but ends up re-opening the page in the sidebar of the browser instead of the main window
    // in Firefox
    //    } else if (window.sidebar) {
    //        window.sidebar.addPanel(title, url, '');
    //    }
    else if (window.opera) {
        //void (0); // do nothing here (Opera 7+)
        var bookmark = document.createElement('a');
        bookmark.setAttribute('rel', 'sidebar');
        bookmark.setAttribute('href', url);
        bookmark.setAttribute('title', title);
        bookmark.click();
    } else if (window.home || isSafari) { // Firefox, Netscape, Safari, iCab
        alert('You need to press ' + buttonStr + ' + D to bookmark our site.');
        
    } else if (!window.print || isMac) { // IE5/Mac and Safari 1.0
        alert('You need to press Command/Cmd + D to bookmark our site.');
    } else {
        alert('In order to bookmark this site you need to do so manually ' +
        'through your browser.');
    }
}

 function limitChars(textid, limit, infodiv)
 {
    var text = $('#' + textid).val();
    var textlength = text.length;

    if(textlength > limit)
    {
        $('#' + infodiv).html('You cannot write more then ' + limit + ' characters!');
        $('#' + textid).val(text.substr(0, limit));
        return false;
    }
    else
    {
        $('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
        return true;
    }
 }

// clears default text from a displayed textbox
function clearTextBox(control, text) {

    var c = document.getElementById(control);
    if (c) {
        if (c.value == text) {
            c.value = "";
        }
    }
}

function updateSearchTextboxText(control) {
    // change the color and alignment of the text inside the search textbox 
    // so it's more visible when a user is actually typing in the box.
    var c = document.getElementById(control);
    if (c) {
        c.style.color = "#000000";
        c.style.textAlign = "left";
        c.style.paddingTop = "4px";
    }
}
