
/*************************

Cross Browser Gradient Backgrounds
v1.0
Last Revision: 11.03.2005
steve@slayeroffice.com

please leave this notice in tact.

should you improve upon this code, please
let me know so that I may update the version
hosted on slayeroffice

--- to use --
reference this file (on your own server) as a javascript src
in the head of your document. give the elements
you want a gradient background applied to a class as such:

class="gradient 000000 ffffff horizontal"

See http://slayeroffice.com/code/gradient/ for more examples.


*************************/

window.addEventListener?window.addEventListener("load",createGradient,false):window.attachEvent("onload",createGradient);

function createGradient() {
	if(!document.getElementById)return;
	
	objArray = getGradientObjects();
	if(!objArray.length) return;
	
	for(i=0;i<objArray.length;i++) {
		params = objArray[i].className.split(" ");
		if(document.all && !window.opera) {
			objArray[i].style.width = objArray[i].offsetWidth + "px";
			params[3] == "horizontal"?gType = 1:gType = 0;
			objArray[i].style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType="+gType+",StartColorStr=\"#" + params[1] + "\",EndColorStr=\"#" + params[2] + "\")";
	} else {
			colorArray = createColorPath(params[1],params[2]);
			x=0;y=0;
			if(params[3] == "horizontal") {
				w=Math.round(objArray[i].offsetWidth/colorArray.length);
				if(!w)w=1;
				h = objArray[i].offsetHeight;
			} else {
				h = Math.round(objArray[i].offsetHeight/colorArray.length);
				if(!h) h =1;
				w = objArray[i].offsetWidth;
			}
			makeGrandParent(objArray[i]);
			tmpDOM = document.createDocumentFragment();
			for(p=0;p<colorArray.length;p++) {
				g = document.createElement("div");
				g.setAttribute("style","position:absolute;z-index:0;top:" + y + "px;left:" + x + "px;height:" + h + "px;width:" + w + "px;background-color:rgb(" + colorArray[p][0] + "," + colorArray[p][1] + "," + colorArray[p][2] + ");");
				params[3] == "horizontal"?x+=w:y+=h;
				tmpDOM.appendChild(g);
				if(y>=objArray[i].offsetHeight || x >= objArray[i].offsetWidth) break;
			}
			objArray[i].appendChild(tmpDOM);
			tmpDOM = null;
		}
	}
}

function getGradientObjects() {
	a = document.getElementsByTagName("*");
	objs = new Array();
	for(i=0;i<a.length;i++) {
		c = a[i].className;
		if(c != "") if(c.indexOf("gradient") == 0) objs[objs.length] = a[i];
	} 
	return objs;
}
	
function createColorPath(color1,color2) {
	colorPath = new Array();
	colorPercent = 1.0;
	do {
		colorPath[colorPath.length]=setColorHue(longHexToDec(color1),colorPercent,longHexToDec(color2));
		colorPercent-=.01;
	} while(colorPercent>0);
	return colorPath;
}
		
function setColorHue(originColor,opacityPercent,maskRGB) {
	returnColor=new Array();
	for(w=0;w<originColor.length;w++) returnColor[w] = Math.round(originColor[w]*opacityPercent) + Math.round(maskRGB[w]*(1.0-opacityPercent));
	return returnColor;
}

function longHexToDec(longHex) {
	return new Array(toDec(longHex.substring(0,2)),toDec(longHex.substring(2,4)),toDec(longHex.substring(4,6)));	
}

function toDec(hex) {	
	return parseInt(hex,16);
}
	
function makeGrandParent(obj) {
	disp = document.defaultView.getComputedStyle(obj,'').display;
	disp == "block"?nSpan = document.createElement("div"):	nSpan = document.createElement("span");
	mHTML = obj.innerHTML;
	obj.innerHTML = "";
	nSpan.innerHTML = mHTML;
	nSpan.setAttribute("style","position:relative;z-index:10;");
	obj.appendChild(nSpan);
}

//**********************************************************************************

function fotoVer(str) {
	var w = 650
	var h = 500
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	alert("O álbum será visualizado em uma nova janela.");
	window.open("fotos/fotos_ver.asp?galeria="+str,"fotoVer","width="+screen.width+",height="+h+",left=0,top="+wint);
	}

//**********************************************************************************

function verMarca(str) {
	window.open("portifolio_marcas.asp?img="+str,"_blank","width=30,height=30,left=100,top=100");
	}

//**********************************************************************************

var URLSite = window.location.href;
var TituloSite = document.title;
function addfav(){
if (document.all) window.external.AddFavorite(URLSite,TituloSite);
}

//**********************************************************************************

function linkLivros(str) {
	alert("O website a seguir contém informações sujeitas a mudanças.");
	window.open(str,"_blank")
	}

//**********************************************************************************

function mudaTitulo() {
	var he3 = document.getElementsByTagName('h2');
	var titulo

	if (he3&&he3[0]&&he3[0].innerHTML) {
		var tit = he3[0].innerHTML;
		titulo = tit + " - Hugo Dias @ Consultor em TI [Adobe Certified Instructor e professional; Professor do Instituto Infnet nas áreas de webdesign, usabilidade e arquitetura da informação; Consultor em gestão de projetos em TI; Palestrante e articulista]";
		if (document.title!=titulo) {
			document.title=titulo;
		}
	}

	window.setTimeout("mudaTitulo()", 200);
}

//**********************************************************************************

function enviarAmigo()
{
	window.open("_enviar.asp?t=" + document.title + "&p=" + window.location,"_blank","width=290,scrollbars=yes,height=350");
}

//**********************************************************************************

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve conter um endereço de e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é obrigatório.\n'; }
  } if (errors) alert('Confira os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function janela800x600() {
	if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
		  winW = window.innerWidth;
		  winH = window.innerHeight;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
		  winW = document.body.offsetWidth;
		  winH = document.body.offsetHeight;
		 }
	}
		if (winW < 700) {
		document.getElementById("geral").style.left = "392px";
		}

	
	}
	
//**********************************************************************************
	
// Copyright 2003 Eddie Traversa
// http://www.dhtmlnirvana.com/
// free to use as long as this copyright notice stays intact
var tags = new Array( 'p', 'ul', 'li', 'th', 'td', 'h5');
var pixelArray =  new Array('13','14','15');
var emArray =  new Array('0.7','0.9','1.0','1.5','2.0','2.5','3');
var initSize = 0;

function fontSizer(inc,unit) {
	if (!document.getElementById) 
		return;
	var size = initSize;
		size += inc;
	if (size < 0 ) {
		size = 0;
}
	if (size > 2 ) {
		size = 2;
}
		initSize = size;
		getBody = document.getElementsByTagName('body')[0];
	for (i = 0 ; i < tags.length ; i++ ) {
		getallTags = getBody.getElementsByTagName(tags[i]);
	for (k = 0 ; k < getallTags.length ; k++) 
		getallTags[k].style.fontSize = (unit=='px') ? pixelArray[size]+unit: emArray[size]+unit;
	}
}

//**********************************************************************************

over = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", over);

overCursos = function() {
	var sfEls2 = document.getElementById("subProfessor").getElementsByTagName("LI");
	for (var i=0; i<sfEls2.length; i++) {
		sfEls2[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls2[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", overCursos);

//***********************************************************************************************


/* Funções Ajax
 * Por Tiago Madeira
 * http://tiagomadeira.net
 *
 * Usando idéias de:
 * - Elcio Ferreira, o cara que escreveu os artigos que me ensinaram Ajax
 * - Mike Stenhouse e seu artigo "Fixing the back button and enabling
 *   bookmarking for Ajax Apps"
 *
 */

// Estático
var fila=[]
var ini=0
var fim=0
var local

// Depende da aplicação...
var query="pag="
var tamQuery=4
var prefixo="http://"+ location.host +"/"
//var prefixo="http://"+ location.host +"/hugodias/"
var msgCarregando="<p class='carregando'></p>"
var indexPadrao="home.asp"
var iframeURL="_iframe.asp"
var iframeID='iframe_invisivel'
var ajaxID='cont'

// Elemento xmlHttpRequest
try {
	var xmlhttp=new XMLHttpRequest();
} catch(ee) {
	try {
		var xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(E) {
			var xmlhttp=false;
		}
	}
}

// Função que insere na fila a página "conteudo" no document.getElementById("id")
function carrega(id, conteudo) {
	if (document.getElementById(id)) {
		document.getElementById(id).innerHTML=msgCarregando;

		fila[fim++]=[id, conteudo];
		if (ini+1==fim) {
			proximo();
		}
	}
}

// Função que vai para o próximo na fila...
function proximo() {
	if (fila[ini][1].indexOf("#")>-1) {
		var vetor=fila[ini][1].split("#");
		var anc=vetor[vetor.length-1]
		fila[ini][1]=vetor[0]
	}
	xmlhttp.open("GET", fila[ini][1], true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			retorno=unescape(xmlhttp.responseText.replace(/\+/g, " "));
			document.getElementById(fila[ini++][0]).innerHTML=retorno;
			fixBack();
			if (anc) {
				location.href="#"
				location.href="#"+anc
			}
			if (ini<fim) {
				setTimeout("proximo()", 10);
			}
		}
	}
	xmlhttp.send(null);
}

// Função que descobre em que endereço estamos...
function endereco() {
	var temp=location.href.split("#");
	return temp[0];
}

// Função que descobre com que âncora estamos...
function ancora() {
	if (location.href.indexOf("#")>-1) {
		var temp=location.href.split("#");
		return temp[temp.length-1];
	} else {
		return ''
		return indexPadrao;
	}
}

function clique(e) {
    //Correção para eventos quebrados da Microsoft
    if(typeof(e)=='undefined')var e=window.event
    source=e.target?e.target:e.srcElement
    //Correção para o bug do Konqueror/Safari
    if(source.nodeType==3)source=source.parentNode

    //Obtém o número quebrando a url
    var href=source.getAttribute("href")
    var er = /main\.asp\?pag=/
    if (er.test(href)) {
	var hash = href.substr(href.indexOf(query)+tamQuery);
	var e2 = /&/
	if (e2.test(hash)) {
		hash=hash.replace(/&/, '?');
	}
	var e3 = /#/
	if (!e3.test(hash)) {
		window.location='#'+hash
		document.getElementById(iframeID).setAttribute('src', iframeURL+"?pag="+hash)
		return false
	}
    }
}

// Função que fixa links para navegadores normais.
function fixarlinks() {
	var links = document.getElementsByTagName("a");

	for (var i=0; i<links.length; i++) {
		links[i].onclick=clique;
	}
}

function lvalido(l) {
	if (l=='') {
		return false;
	}
	var er = /asp$/
	var er2 = /htm$/
	var er3 = /asp\?.*/
	if (!er.test(l) && !er2.test(l) && !er3.test(l)) {
		return false;
	}

	if (document.getElementById(l)) {
		return false;
	}

	return true;
}

// Função que checa mudanças para navegadores normais.
function checarmudancas() {
	if (ancora()!=local) {
		local=ancora();
		if (lvalido(local)) {
			carrega(ajaxID, prefixo+local);
		}
	}
	window.setTimeout("checarmudancas()", 200);
}

// Agora lá vamos ao IE...

function fixarlinksIE() {
        var links = document.getElementsByTagName("a");
        for (var i=0; i<links.length; i++) {
	        links[i].onclick=clique
        }
}

function checarmudancasIE() {
        window.setTimeout("checarmudancasIE()", 200);
        if (document.frames[iframeID]&&document.frames[iframeID].getLocation()!=local) {
                local=document.frames[iframeID].getLocation();
		if (lvalido(local)) {
                window.location=endereco()+"#"+local
                carrega(ajaxID, prefixo+local);
		}
        }
}

// Função final:

function fixBack() {
        if (!document.getElementById || !document.getElementsByTagName) return;
        if (document.all) { //if IE
                fixarlinksIE();
        } else {
                fixarlinks();
        }
}

function checarmudancasC() {
        if (!document.getElementById || !document.getElementsByTagName) return;

	if (lvalido(ancora())) {
	        local=ancora();
	        document.getElementById(iframeID).src=iframeURL+"?pag="+local
	        carrega(ajaxID, prefixo+local);
	} else if (location.href.indexOf("?pag=")>-1) {
		var temp=location.href.split("?pag=");
		var ooo=temp[1]
		location.href='main.asp#'+ooo
	} else {
		local=indexPadrao
	        document.getElementById(iframeID).src=iframeURL+"?pag="+local
		carrega(ajaxID, prefixo+local);
	}
        if (document.all) { //if IE
                checarmudancasIE();
        } else {
                checarmudancas();
        }
}

/* FIM ================-------------======================
 * Funções Ajax
 * Por Tiago Madeira
 * http://tiagomadeira.net
 *
 * Usando idéias de:
 * - Elcio Ferreira, o cara que escreveu os artigos que me ensinaram Ajax
 * - Mike Stenhouse e seu artigo "Fixing the back button and enabling
 *   bookmarking for Ajax Apps"
 *
 */


//***********************************************************************************************




window.onload=function() {
	
	fixBack();
    checarmudancasC();
	janela800x600();
	mudaTitulo();
}





