// JavaScript Document
//RRD®

//iniciando
//trp = 0;
//portmax = 0;

//menu button
function vai(url) {
	//alert(url);
	parent.principal.location = url;
}
//logo button
function gohome(url) {
	//alert(url);
	document.location = url;
}
/*portfólio main*/
function plus(url) {
	redir = new Array();
	redir = url.split("/");
	var patt = new RegExp("[0-9]?[0-9]");
    num = patt.exec(redir[2]);
	if (num == null) {
		alert("página não econtrada num = " + num);
	} else {	
		uri = redir[0] + "/" + redir[1] + "/trabalho" + num + "/" + redir[2]; 
		tr = num[0] + "";
		//alert("setCookie: " + tr);
		setCookie("trabalho", tr, 3);
		parent.parent.principal.location = "../trabalhos/trabalho.html";
		//document.getElementById("titrabalho").style.display = "none";
		//trabalhomain.location = "../trabalhos/trabalho2/trabalho2.html";
		//alert(parent.parent.principal.document.getElementById('logo').style);
		//trabalho.trabalhomain.location = uri;
	}
}
//Carregando página de trabalhos
function carregaTitulo(){                                                                                                                                                                             
	trp = getCookie("trabalho");
	portmax = getCookie("portmax");
	//alert(trp);
	if (trp) {
		//alert("carregando portfolio: " + trp);
	} else {
		trp = 1;
	}
	//alert("nome da imagem: " + "trabalho"+trp+"/trabalho"+trp+".jpg");
	document.getElementById("trabalhoImg").src = "trabalho"+trp+"/trabalho"+trp+".jpg";
	document.getElementById("titrabalho").style.visibility = "visible";
	document.getElementById("titrabalho").style.display = "block";
	carregaTitFrame();
}

function carregaPortFolio() {
	portmax = document.getElementsByName("job").length;
	setCookie("portmax", portmax, 1);
	//alert('trabahlhos ' + portmax);
}

//carrega o imagem do cabeçalho 
function carregaTitFrame() {
	//alert("frame com fonte numero " + trp); // src="trabalho1/trabalho1.html"
	document.getElementById("trabalhomain").src =  "trabalho"+trp+"/trabalho"+trp+".html";
	document.getElementById("trabalhomain").style.visibility = "visible";
	document.getElementById("trabalhomain").style.display = "block";
}

function abreTrabalho() {
	amplia = getCookie("trabalho");
	//parent.parent.principal.getElementById()
	//parent.parent.principal.location = "trabalho"+amplia+"/trabalho"+amplia+".html";
	//file:///D:/site%20Rapha/html/trabalhos/trabalho.html
	abrindo = document.URL.split('.html');
	novaurl = abrindo[0] + amplia + "/trabalho" + amplia + ".html";
	window.open(novaurl);
	
	//document.open("trabalho"+amplia+"/trabalho"+amplia+".html");
}

/*
function qual() {
	//alert(portmax);
	//x = document.getElementsByName(c);
	//alert(x.length);
	//alert(tr);
	//alert(num);
}// */
function proximo(){
	if (trp == portmax){trp = 0;}
	trp++;
	setCookie("trabalho", trp, 3);
	document.getElementById("trabalhoImg").src = "trabalho"+trp+"/trabalho"+trp+".jpg";
	document.getElementById("titrabalho").style.visibility = "visible";
	document.getElementById("titrabalho").style.display = "block";
	carregaTitFrame();
		
}

function anterior(){
	trp--;
	if (trp == 0){trp = portmax;}
	setCookie("trabalho", trp, 3);
	document.getElementById("trabalhoImg").src = "trabalho"+trp+"/trabalho"+trp+".jpg";
	document.getElementById("titrabalho").style.visibility = "visible";
	document.getElementById("titrabalho").style.display = "block";
	carregaTitFrame();
		
}

//Cookies Getters e Setters
function getCookie(c_name) {
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++) {
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  	  x=x.replace(/^\s+|\s+$/g,"");
      if (x==c_name) {
	    return unescape(y);
      }
   }
}

function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value + "; path=/";
}

function checkCookie() {
	var username=getCookie("username");
	if (username!=null && username!="") {
	  alert("Welcome again " + username);
  	} else {
	  username=prompt("Please enter your name:","");
  	  if (username!=null && username!="") {
	    setCookie("username",username,365);
      }
   }
}
