

var xxmyHeight;
var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all
var url_default = "bemvindo.html";
var xWidth = 940, xHeight = 620;

function bookmarksite(){
	var title = "Os Caramelos - Creche e Jardim de Infância"
	var url = "http://www.oscaramelos.pt"
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function openwin(url) {
	window.open(url,'mywin',
'left=20,top=20,width=640,height=480,toolbar=0,resizable=0,location=0,directories=0,status=0,menubar=0,scrollbars=0');
}

function show_hide(id, op) {
	if(op == 'change') {
		op2 = document.getElementById(id).style.visibility;
		if(op2 == 'hidden') op = 'visible';
		else if(op2 == 'visible') op = 'hidden';
	} else if(op == 'show') op = 'visible';
	else if(op == 'hide') op = 'hidden';
	document.getElementById(id).style.visibility=op;
}


function show_titulo(val_T) {
	document.getElementById('titulo').innerHTML = val_T;
	document.getElementById('titulo').style.visibility='visible';
}

function content(ac) {
	if(ac == 'show') {
		document.getElementById('loading').style.visibility='hidden';
		document.getElementById('main').style.visibility='visible';
		time = '';//setTimeout("content('titulo')", 150);
	} else if(ac == 'intro') {
		document.getElementById('loading').style.visibility='hidden';
		document.getElementById('loading').innerHTML = "";
		document.getElementById('intro').style.visibility='visible';
		make_intro();
		time = setTimeout("content('main')", 600);
	} else if(ac == 'main') {
		document.getElementById('main').style.visibility='visible';
		time = '';
	}
}

function zoom(wat) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	xxmyHeight = myHeight;
	xWidth = myWidth;
	xHeight = myHeight;
	show_hide('hide', 'hide');
	document.body.style.width=xWidth+"px"
	document.body.style.height=xHeight+"px"
	document.getElementById("hide").style.left=-0+"px";
	document.getElementById("hide").style.top=0+"px";
	document.getElementById("hide").style.width=xWidth+"px"
	document.getElementById("hide").style.height=xHeight+"px"
	document.getElementById("intro").style.left=-0+"px";
	document.getElementById("intro").style.top=0+"px";
	document.getElementById("intro").style.width=xWidth+"px"
	document.getElementById("intro").style.height=xHeight+"px"
	document.getElementById("main").style.left=xWidth/2-940/2+"px";
	document.getElementById("main").style.top=xHeight/2-620/2+"px";
	document.getElementById("titulo").style.top=xHeight/2-620/2+37+"px";
	if(wat == "intro") {
		time = setTimeout("content('intro')", 720);
		ajax2('extra.html');
	}
}

function iecompattest(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e){
	if (ie5&&dragapproved&&event.button==1){
		document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
	} else if (ns6&&dragapproved){
		document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
	}
}

function initializedrag(e){
	offsetx=ie5? event.clientX : e.clientX
	offsety=ie5? event.clientY : e.clientY
	document.getElementById("dwindowcontent").style.display="none" //extra
	tempx=parseInt(document.getElementById("dwindow").style.left)
	tempy=parseInt(document.getElementById("dwindow").style.top)
	
	dragapproved=true
	document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height){
	if (!ie5&&!ns6)
		window.open(url,"","width=width,height=height,scrollbars=1")
	else{
		show_hide('hide', 'show');//document.getElementById("hide").style.display=''
		document.getElementById("dwindow").style.display=''
		document.getElementById("dwindow").style.width=initialwidth=width+"px"
		document.getElementById("dwindow").style.height=initialheight=height+"px"
		document.getElementById("dwindowcontent").style.width=initialwidth=width-20+"px"
		document.getElementById("dwindowcontent").style.height=initialheight=height-18+"px"
		document.getElementById("dwindow").style.left=xWidth/2-width/2+"px"
		document.getElementById("dwindow").style.top=xHeight/2-height/2-14+"px";//ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
		document.getElementById("cframe").src=url
		//document.getElementById("title").innerHTML=url
	}
}

function maximize(){
	if (minrestore==0){
		minrestore=1 //maximize window
		document.getElementById("maxname").setAttribute("src","images/restore.gif")
		document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
		document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
	} else{
		minrestore=0 //restore window
		document.getElementById("maxname").setAttribute("src","images/max.gif")
		document.getElementById("dwindow").style.width=initialwidth
		document.getElementById("dwindow").style.height=initialheight
	}
	document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
	document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
	show_hide('hide', 'hide');//document.getElementById("hide").style.display="none"
	document.getElementById("dwindow").style.display="none"
	document.getElementById("cframe").src=url_default
}

function stopdrag(){
dragapproved=false;
	document.getElementById("dwindow").onmousemove=null;
	document.getElementById("dwindowcontent").style.display="" //extra
}

function procurar(url, w, h) {
	queryx = document.getElementById("query").value;
	if(queryx != '' && queryx != "o que procura?") loadwindow(url+queryx,w,h);
}
function ler_url() {
	queryy = document.getElementById("url_load").value;
	www = document.getElementById("ww").value;
	hhh = document.getElementById("hh").value;
	if(www == '' ) www = 940;
	if(hhh == '' ) hhh = 620;
	if(queryy != '' && queryy != 'http://') loadwindow(queryy,www,hhh);
}

function ajax2(url) {
	req = null;
	// Procura por um objeto nativo (Mozilla/Safari)
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange2;
		req.open("GET",url,true);
		req.send(null);
		// Procura por uma versão ActiveX (IE)
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange2;
			req.open("GET",url,true);
			req.send();
		}
	}
}

function processReqChange2() {
	show_hide('main', 'show');
	document.getElementById('main').innerHTML = loading('loading');
	// apenas quando o estado for "completado"
	if (req.readyState == 4) {
	
		// apenas se o servidor retornar "OK"
		
		if (req.status ==200) {
		
		// procura pela div id="pagina" e insere o conteudo
		// retornado nela, como texto HTML
			if(req.responseText == "") {
				document.getElementById('main').innerHTML = '<ul><li>0</li></ul>';
				show_hide('main', 'hide');
			} else {
				//var pub = req.responseText;
				//var pub_all = pub.split('|[#]|');
				//var pug_size = pub_all.length;
				//var pub_now = pub_all[get_random(pug_size)];
				document.getElementById('main').innerHTML = '<span class="titulo">'+req.responseText+'</span>';//pub_now;
			}
		} else {
			alert("Houve um problema ao obter os dados\n" + req.statusText);
			show_hide('main', 'hide');
		}
	}
} 

function get_random(n) {
	var ranNum = Math.floor(Math.random()*n);
	return ranNum;
}

function make_intro() {
	var fo = new SWFObject("intro_def.swf", "intro", xWidth, xHeight, "8", "#DAE8FE");
	fo.altTxt = '<h1><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BUIGP" target="_blanck" class="fundo_pg">You need to upgrade your Flash Player!</a></h1>';
	fo.addParam("menu", "false");
	fo.addParam("quality", "best");
	fo.addParam("scale", "noscale");
	fo.addParam("wmode", "transparent");
	fo.write('intro');
}

function loading(place) {
	var fo = new SWFObject("loading.swf", place, "25", "25", "8", "#DAE8FE");
	fo.altTxt = '<h1><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BUIGP" target="_blanck" class="fundo_pg">You need to upgrade your Flash Player!</a></h1>';
	fo.addParam("menu", "false");
	fo.addParam("quality", "best");
	fo.addParam("scale", "noscale");
	fo.addParam("wmode", "transparent");
	fo.write(place);
}

function load_content(valor) {
	url=valor+'.html?get=all';//"dirtree.php?valor="+
	//document.getElementById('pesquisa').value = valor;
	ajax(url);
}
