var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17039761-15']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

function clearbx(id, value){
	var bx = document.getElementById(id);
	if(bx.value == value){
		bx.value = "";
	}
}

function fillbx(id, value){
	var bx = document.getElementById(id);
	if(bx.value == ""){
		bx.value = value;
	}
}

function addFav(){
    var url = "http://www.uniko.pt";
    var title = "UNIKO :: HomePage";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement("a");
        mbm.setAttribute("rel","sidebar");
        mbm.setAttribute("href",url);
        mbm.setAttribute("title",title);
        mbm.click();
    }
    else if(document.all){
		window.external.AddFavorite(url, title);
	}
}

function susp(){
	var bg_down = document.createElement("div");
	bg_down.setAttribute("id", "bg_down");
	bg_down.style.position = "fixed";
	bg_down.style.width = "100%";
	bg_down.style.height = "100%";
	bg_down.style.background = "url('imagens/bg_down.png')";
	bg_down.style.zIndex = "9999";
	
	document.body.appendChild(bg_down);
}

function tagPhoto(id,url,titulo,descr,w,h){
	if(id != ""){
		buildGalleryList(id);
	}
	
	var tagPhoto = document.createElement("div");
	tagPhoto.setAttribute("id", "tagPhoto");
	tagPhoto.style.position = "fixed";
	tagPhoto.style.width = w+"px";
	tagPhoto.style.height = h+"px";
	tagPhoto.style.left = "50%";
	tagPhoto.style.top = "50%";
	tagPhoto.style.marginTop = -(h/2)+"px";
	tagPhoto.style.marginLeft = -(w/2)+"px";
	tagPhoto.style.padding = "5px";
	tagPhoto.style.background = "#fff url('"+url+"') center center no-repeat";
	tagPhoto.style.zIndex = "99999";
	tagPhoto.style.display = "none";
	
	if(titulo != ""){
		var tagDescr = document.createElement("div");
		tagDescr.setAttribute("id", "tagDescr");
		tagDescr.style.position = "fixed";
		tagDescr.style.width = w+"px";
		tagDescr.style.height = "30px";
		tagDescr.style.left = "50%";
		tagDescr.style.top = "50%";
		tagDescr.style.marginTop = ((h/2)-30)+"px";
		tagDescr.style.marginLeft = -(w/2)+"px";
		tagDescr.style.padding = "5px";
		tagDescr.style.background = "#fff";
		tagDescr.style.color = "#000";
		tagDescr.innerHTML = "<b>"+titulo+"</b><br />"+descr;
		tagDescr.style.zIndex = "9999999";
		tagDescr.style.display = "none";
	}
	
	var btnClosePhoto = document.createElement("div");
	btnClosePhoto.setAttribute("id", "btnClosePhoto");
	btnClosePhoto.setAttribute("class", "cursor");
	btnClosePhoto.style.position = "fixed";
	btnClosePhoto.style.width = "30px";
	btnClosePhoto.style.height = "30px";
	btnClosePhoto.style.left = "50%";
	btnClosePhoto.style.top = "50%";
	btnClosePhoto.style.marginTop = -(h/2)+"px";
	btnClosePhoto.style.marginLeft = -(w/2)+(w-50)+"px";
	btnClosePhoto.style.background = "#fff url('imagens/fecharPhoto.png') center center no-repeat";
	btnClosePhoto.style.zIndex = "999999";
	btnClosePhoto.style.display = "none";
	btnClosePhoto.onclick = closeSusp;
	
	if(listImgs.length > 1){
		var btnPrevPhoto = document.createElement("div");
		btnPrevPhoto.setAttribute("id", "btnPrevPhoto");
		btnPrevPhoto.setAttribute("class", "cursor");
		btnPrevPhoto.style.position = "fixed";
		btnPrevPhoto.style.width = "30px";
		btnPrevPhoto.style.height = "30px";
		btnPrevPhoto.style.left = "50%";
		btnPrevPhoto.style.top = "50%";
		btnPrevPhoto.style.marginTop = "-5px";
		btnPrevPhoto.style.marginLeft = -(w/2)+"px";
		btnPrevPhoto.style.background = "#fff url('imagens/prevPhoto.png') center center no-repeat";
		btnPrevPhoto.style.zIndex = "999999";
		btnPrevPhoto.style.display = "none";
		btnPrevPhoto.onclick = prevImg;
		
		var btnNextPhoto = document.createElement("div");
		btnNextPhoto.setAttribute("id", "btnNextPhoto");
		btnNextPhoto.setAttribute("class", "cursor");
		btnNextPhoto.style.position = "fixed";
		btnNextPhoto.style.width = "30px";
		btnNextPhoto.style.height = "30px";
		btnNextPhoto.style.left = "50%";
		btnNextPhoto.style.top = "50%";
		btnNextPhoto.style.marginTop = "-5px";
		btnNextPhoto.style.marginLeft = ((w/2)-20)+"px";
		btnNextPhoto.style.background = "#fff url('imagens/nextPhoto.png') center center no-repeat";
		btnNextPhoto.style.zIndex = "999999";
		btnNextPhoto.style.display = "none";
		btnNextPhoto.onclick = nextImg;
	}
	
	document.body.appendChild(tagPhoto);
	if(titulo != ""){
		document.body.appendChild(tagDescr);
	}
	document.body.appendChild(btnClosePhoto);
	if(listImgs.length > 1){
		document.body.appendChild(btnPrevPhoto);
		document.body.appendChild(btnNextPhoto);
	}
	
	$('#tagPhoto').fadeIn(1200);
	if(titulo != ""){
		$('#tagDescr').fadeIn(1200);
	}
	$('#btnClosePhoto').delay(800).show('fast');
	if(listImgs.length > 1){
		$('#btnPrevPhoto').delay(800).show('fast');
		$('#btnNextPhoto').delay(800).show('fast');
	}
}

// CONTROLADOR *****
var listImgs = new Array();
var currentImg;

function prevImg(){
	if(currentImg > 0){
		currentImg--;
		alternarPhoto(listImgs[currentImg]);
	}else{
		currentImg = (listImgs.length-1);
		alternarPhoto(listImgs[currentImg]);
	}
}

function nextImg(){
	if(currentImg < (listImgs.length-1)){
		currentImg++;
		alternarPhoto(listImgs[currentImg]);
	}else{
		currentImg = 0;
		alternarPhoto(listImgs[currentImg]);
	}
}
// FIM CONTROLADOR *****

function tagDiv(w,h,htmlID,rturn){
	if(htmlID == 1){
		htmlContent = "<form action='enviar_sugira_site.php?r="+rturn+"' method='post'><div style='margin-top:30px;padding-bottom:6px;color:#000;'>Sugira este site a algum amigo:</div><div style='border-top:#999 solid 1px;padding-top:7px;'><div style='width:100%;float:left;'><input type='text' name='nome' value='Nome do amigo' style='width:220px;' /><input type='text' name='email' value='Endereço de e-mail do amigo' style='width:320px;' /><textarea name='mensagem' style='width:407px; height:80px;'>Escreva uma mensagem para o seu amigo</textarea><input type='submit' value='Enviar' class='input_sub_res' /></div></div></form>";
	}
	
	var tagDiv = document.createElement("div");
	tagDiv.setAttribute("id", "tagDiv");
	tagDiv.style.position = "fixed";
	tagDiv.style.width = w+"px";
	tagDiv.style.height = h+"px";
	tagDiv.style.left = "50%";
	tagDiv.style.top = "50%";
	tagDiv.style.marginTop = -(h/2)+"px";
	tagDiv.style.marginLeft = -(w/2)+"px";
	tagDiv.style.padding = "5px";
	tagDiv.style.background = "#ccc";
	tagDiv.style.zIndex = "99999";
	tagDiv.style.display = "none";
	tagDiv.style.border = "#fff solid 5px";
	tagDiv.innerHTML = htmlContent;
	
	var btnClosePhoto = document.createElement("div");
	btnClosePhoto.setAttribute("id", "btnClosePhoto");
	btnClosePhoto.setAttribute("class", "cursor");
	btnClosePhoto.style.position = "fixed";
	btnClosePhoto.style.width = "30px";
	btnClosePhoto.style.height = "30px";
	btnClosePhoto.style.left = "50%";
	btnClosePhoto.style.top = "50%";
	btnClosePhoto.style.marginTop = -(h/2)+"px";
	btnClosePhoto.style.marginLeft = -(w/2)+(w-27)+"px";
	btnClosePhoto.style.background = "#fff url('imagens/fecharPhoto.png') center center no-repeat";
	btnClosePhoto.style.zIndex = "999999";
	btnClosePhoto.style.display = "none";
	btnClosePhoto.onclick = closeSusp2;
	
	document.body.appendChild(tagDiv);
	document.body.appendChild(btnClosePhoto);
	
	$('#tagDiv').fadeIn(1200);
	$('#btnClosePhoto').delay(800).show('fast');
}

function closeSusp2(){
	var bg_down = document.getElementById("bg_down");
	var tagDiv = document.getElementById("tagDiv");
	var btnClosePhoto = document.getElementById("btnClosePhoto");
	
	document.body.removeChild(tagDiv);
	document.body.removeChild(btnClosePhoto);
	document.body.removeChild(bg_down);
}

function closeSusp(){
	var bg_down = document.getElementById("bg_down");
	var tagPhoto = document.getElementById("tagPhoto");
	if(document.getElementById("tagDescr")){
		var tagDescr = document.getElementById("tagDescr");
	}
	var btnClosePhoto = document.getElementById("btnClosePhoto");
	if(listImgs.length > 1){
		var btnPrevPhoto = document.getElementById("btnPrevPhoto");
		var btnNextPhoto = document.getElementById("btnNextPhoto");
	}
	
	document.body.removeChild(bg_down);
	document.body.removeChild(tagPhoto);
	if(document.getElementById("tagDescr")){
		document.body.removeChild(tagDescr);
	}
	document.body.removeChild(btnClosePhoto);
	if(listImgs.length > 1){
		document.body.removeChild(btnPrevPhoto);
		document.body.removeChild(btnNextPhoto);
	}
}

function diplay_sub(lbl_id, id, h){
	var curr_lbl = document.getElementById(lbl_id);
	var itenn = document.getElementById(id);
	
	if(itenn.style.display == "" || itenn.style.display == "none"){
		if(h != 0){
			curr_lbl.style.color = "#cf171f";
			curr_lbl.style.fontWeight = "700";
		}
		itenn.style.display = "block";
	}else{
		if(h != 0){
			curr_lbl.style.color = "#fff";
			curr_lbl.style.fontWeight = "normal";
		}
		itenn.style.display = "none";
	}
}

function addTree(lbl){
	var tree = document.getElementById("tree");
	if(lbl != ""){
		tree.innerHTML = "Área Cliente Profissional UNIKO » "+lbl;
	}else{
		tree.innerHTML = "Área Cliente Profissional UNIKO";
	}
}

function changeViewTagSubSectores(id_tag_div){
	var obj = document.getElementById(id_tag_div);
	
	if(obj.style.display == "" || obj.style.display == "none"){
		obj.style.display = "block";
	}else{
		obj.style.display = "none";
	}
}

//CARACTERISTICAS PRODUTOS POPUP

function popUpCaractProd(URLpage){
	window.open(URLpage, '', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,titlebar=0,directories=0,width=880,height=470,top=50,left=50');
}

function changeAspDiv(id){
	var element = document.getElementById(id);
	
	if(element.style.display == "" || element.style.display == "none"){
		element.style.display = "block";
	}else{
		element.style.display = "none";
	}
}

//*******

function popUpPrintProd(URLfile){
	window.open(URLfile, '', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,titlebar=0,directories=0,width=800,height=600,top=50,left=50');
}
