/* - register_function.js - */
/* Essential javascripts, used a lot. 
 * These should be placed inline
 * We have to be certain they are loaded before anything that uses them
 * http://www.mpu.gov.br/portal_javascripts/Plone%20Default/register_function.js 
 */

// check for ie5 mac
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    &&
    navigator.userAgent.indexOf('Mac') != -1
)

// check for W3CDOM compatibility
var W3CDOM = (!bugRiddenCrashPronePieceOfJunk &&
               typeof document.getElementsByTagName != 'undefined' &&
               typeof document.createElement != 'undefined' );


/* - styleswitcher.js - */
function setActiveStyleSheet(title, reset, first) {
    // terminate if we hit a non-compliant DOM implementation
    if (!W3CDOM){return false};

    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
            a.disabled = true;
            if (a.getAttribute("title") == title) {
                a.disabled = false;
            }
        }
    }
    
    var taxa;
    if (first == 1) {
    	taxa = (title == 'Large Text') ? 1.25 : (title == 'Small Text')? 0.90 : 1.00;
    } else {
	    var actualStyle = readCookie("wstyle");
	    if (actualStyle != null && actualStyle!=title) {
	    	if (actualStyle == 'Large Text') {  
				taxa = (title == 'Small Text') ? (0.90*0.80) : 0.80;    
	    	} else if (actualStyle == 'Small Text') { 
	    		taxa = (title == 'Large Text') ? (1.25*1.112) : 1.112;
	    	} else { // Default Text
	    		taxa = (title == 'Large Text') ? 1.25 : 0.90;		
	    	}
	    }
    }
	setMenu2Size(taxa);
	
    if (reset == 1) {
        createCookie("wstyle", title, 365);
    }
    
};

function setStyle() {
    var style = readCookie("wstyle");
    if (style != null) {
        setActiveStyleSheet(style, 0, 1);
    }
};


function setMenu2Size(ptaxa ) {
	
	var menus = getElementsByName_iefix("div", "menu2");
	var largura = '';
	for(var i = 0; i < menus.length; i++) {
   		largura = menus[i].style.width;
   		menus[i].style.width = (parseInt(largura) * ptaxa) + "px";
	}
};
function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

/* - cookie_functions.js - */
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    } else {
        expires = "";
    }
    document.cookie = name+"="+escape(value)+expires+"; path=/;";
};

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') {
            c = c.substring(1,c.length);
        }
        if (c.indexOf(nameEQ) == 0) {
            return unescape(c.substring(nameEQ.length,c.length));
        }
    }
    return null;
};


