﻿//global.js - javscript helper functions
function WriteBackHyperLink(label, postbacks)
{
    document.write("<div class=\"pageBack\">");
    document.write("<a href=\"javascript:history.go(-" + postbacks + ");\" onkeypress=\"javascript:history.go(-" + postbacks + ");\">");
    document.write("<div class=\"pageBackLinkAuxItem\">");
    document.write("</div>");
    document.write("<div class=\"pageBackLinkText\">");
    document.write(label);
    document.write("</div>");
    document.write("</a>");
    document.write("</div>");
}

function WritePrintHyperlink(label)
{
	document.write("<div class=\"printLink\">");
	document.write("<a href=\"#\" onclick=\"javascript:window.print();return false;\" onkeypress=\"javascript:window.print();return false;\">");
	document.write("<div class=\"printLinkAuxItem\">");
	document.write("</div>");
	document.write("<div class=\"printLinkText\">");
	document.write(label);
	document.write("</div>");
    document.write("</a>");
    document.write("</div>");
}

//MI --> 20100120 - esta função funciona com FF mas a configuração signed.applets.codebase_principal_support tem que estar 
//enabled no about:config
//function SetAsHomepage(url) {
//    if (document.all) {
//        document.body.style.behavior = 'url(#default#homepage)';
//        document.body.setHomePage(url);

//    }
//    else if (window.sidebar) {
//        if (window.netscape) {
//            try {
//                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
//            }
//            catch (e) {
//                alert("this action was aviod by your browser，if you want to enable，please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
//            }
//        }
//        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
//        prefs.setCharPref('browser.startup.homepage', url);
//    }
//}


function SetAsDefaultHomePage(url, label)
{
//    document.write("<a href=\"#\" onclick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('" + url + "');\" onkeypress=\"this.style.behavior='url(#default#homepage)';this.setHomePage('" + url + "');\">");
//	document.write("<span class=\"setHomePageLinkAuxItem\"></span>");
//    document.write("<span class=\"setHomePageLinkText\">");
//    document.write(label);
//    document.write("</span></a>");
    if(!window.sidebar)
    {
        document.write("<a href=\"#\" onclick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('" + url + "');\" onkeypress=\"this.style.behavior='url(#default#homepage)';this.setHomePage('" + url + "');\">");
        //document.write("<a href=\"#\" onclick=\"this.style.behavior='url(#default#homepage)';SetAsHomepage('" + url + "');\" onkeypress=\"this.style.behavior='url(#default#homepage)';SetAsHomepage('" + url + "');\">");
        
	    document.write("<span class=\"setHomePageLinkAuxItem\"></span>");
        document.write("<span class=\"setHomePageLinkText\">");
        document.write(label);
        document.write("</span></a>");
    }
}

function AddToFavorites(label)
{
//    document.write("<a href=\"#\" onclick=\"javascript:window.external.addFavorite(location.href,document.title);\" onkeypress=\"javascript:window.external.addFavorite(location.href,document.title);\">");
//    document.write("<span class=\"addToFavoritesLinkAuxItem\"></span>");
//    document.write("<span class=\"addToFavoritesLinkText\">");
//    document.write(label);
//    document.write("</span></a>");
if(window.sidebar)
document.write("<a href=\"javascript:window.sidebar.addPanel(document.title, location.href, '');\">");  
    
else
document.write("<a href=\"javascript:window.external.addFavorite(location.href,document.title);\">");
         
    document.write("<span class=\"addToFavoritesLinkAuxItem\"></span>");
    document.write("<span class=\"addToFavoritesLinkText\">");
    document.write(label);
    document.write("</span></a>");
}


function ClearTextBox(textBoxID, defaultValue) {
    for (i = 0; i < document.forms[0].length; i++) {
        if (document.forms[0].elements[i].name.indexOf(textBoxID) != -1) {
            if (document.forms[0].elements[i].value == defaultValue)
                document.forms[0].elements[i].value = "";
        }
    }
}
