﻿function browserCheck()
{
        var b = navigator.appName;
        if (b=="Netscape") this.b = "ns";
        else if (b=="Microsoft Internet Explorer") this.b = "ie";
        else if (b=="Konqueror") this.b = "konqueror";
        else this.b = b;
        
        this.v = parseInt(navigator.appVersion);
        
        this.opera = (navigator.userAgent.indexOf('Opera')>0);
        if (this.opera) this.b = "opera";
        
        this.ns = (this.b=="ns" && this.v>=4);
        this.ns4 = (this.b=="ns" && this.v==4);
        this.ns5 = (this.b=="ns" && this.v==5);
        
        this.ie = (this.b=="ie" && this.v>=4);
        this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0);
        this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
        this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0);
        this.ie7 = (navigator.userAgent.indexOf('MSIE 7')>0);
        if (this.ie) this.v = parseFloat(navigator.appVersion.split("MSIE")[1]) ;
 
        this.konqueror = (this.b=="konqueror" && this.v>=4);
        this.k4 = (this.b=="konqueror" && this.v==4);
        this.k5 = (this.b=="konqueror" && this.v==5);
		
		// detect Apple Safari browser        
        var agent 	= navigator.userAgent.toLowerCase();
		this.safari	= (agent.indexOf('safari') != -1);
		this.safari2 = (this.safari && (parseFloat(agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).substring(0,agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).indexOf(' '))) >=  300));  
       
        this.min = (this.ns||this.ie);
        // window.status= agent + ' - ' + this.safari + ' - ' + this.safari2;
}
is = new browserCheck();


function getClientWidth()
{
  var x = window.innerWidth ||
          document.documentElement.clientWidth ||
          document.body.clientWidth;

  return x ? x : 0;
}

function changePropertyValue(seletor,property,value) 
{
	if (is.ie) var CSSRules = 'rules' ; 
		else var CSSRules =  'cssRules' ; 

	if (is.ie || is.safari2) seletor = seletor.toUpperCase() ; 
	
	for (i = 0; i < document.styleSheets.length; i++) 
	{ 
		for (j = 0; j < document.styleSheets[i][CSSRules].length; j++) {
			
			if (document.styleSheets[i][CSSRules][j].selectorText == seletor) {
				document.styleSheets[i][CSSRules][j].style[property] = value ;
				//window.status = document.styleSheets[i][CSSRules][j].selectorText + ': ' + document.styleSheets[i][CSSRules][j].style[property] + ' - ' + value ;
			}
		} 
	}  
		
}

function getCookie(NameOfCookie) { 
	if (document.cookie.length > 0) 
	{ 
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) 
		{ 
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return null;
}

function setCookie(NameOfCookie, value, expiredays) { 
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + 
		((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) { 
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


function setMeFont()
{
	var pixelFontCurrent = Math.round((getClientWidth()*10/800)*10)/10 ;	
	if (pixelFontCurrent < 10)  { pixelFontCurrent = 10;	}
	if (getCookie('widthWin') != pixelFontCurrent) 
	{
	    setCookie('widthWin', pixelFontCurrent);  // function setCookie(NameOfCookie, value, expiredays)
	}
	changePropertyValue('body','fontSize', ((is.ie) ? pixelFontCurrent : pixelFontCurrent + "px"));	
		
	//window.status = pixelFontCurrent  + "px";
}

// Comentado por Rafael Lima em 22/12/2009 para evitar bug do IE8
//window.onresize = setMeFont;
//window.onload = setMeFont;