function openPopup (id, popoptions) {
	url    = document.getElementById(id).getAttribute('href');
	target = id+'_popup';
	var nw = window.open(url, target, popoptions+',scrollbars=yes,resizable=yes,status=yes');
	if (nw) { return false; }
	return false;
}

function printVersion () {
	url    = document.getElementById("versaoimpressora").getAttribute('href');
	target = 'versaoimpressora_popup';
	var nw = window.open(url, target, 'width=600,height=480,scrollbars=yes,resizable=yes,status=yes');
	if (nw) { return false; } 
}

function sendFriend () {
 url    = document.getElementById("recomendaramigo").getAttribute('href');
 target = 'recomendaramigo_popup';
 var nw = window.open(url, target, 'width=500,height=400,scrollbars=yes,resizable=yes,status=yes');
 if (nw) { return false; } 
}

function doPopUp(e) {
	//set defaults - if nothing in rel attrib, these will be used
	var t = "standard";
	var w = "600";
	var h = "480";
	//look for parameters
	attribs = this.rel.split(" ");
	if (attribs[1]!=null) {t = attribs[1];}
	if (attribs[2]!=null) {w = attribs[2];}
	if (attribs[3]!=null) {h = attribs[3];}
	//call the popup script
	popUpWin(this.href,t,w,h);

	return false;
}
function popUpWin(url, type, strWidth, strHeight){
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
var newWindow = null;
function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}
//dinamiza popups
Event.observe(window, 'load', findPopUps, false);
function findPopUps() {
	
	popupx= $$('a.popup')

	popupx.each(
		function(s) {
			s.onclick = doPopUp;
			s.title = s.title + " [Abre em nova janela]";
		}
	)
}

//para dinamizar inputs pre-preenchidos
Event.observe(window, "load", function(){
	
	inputx= $$('input.ctrlVal')

	inputx.each(
		function(s){

			s.setAttribute('valueIni', s.value)
			Event.observe(s, "click", function(){if(s.value==s.getAttribute("valueIni")) s.value= ""})
			Event.observe(s, "blur", function(){if(s.value=="") s.value= s.getAttribute("valueIni")})
		}
	);
	inputxF= $$('form.ctrlValF')
	inputxF.each(
		function(s){
			Event.observe(s, "submit",
				function(){
					document.getElementsByClassName("ctrlVal").each(
						function(s, index) {if(s.value==s.getAttribute("valueIni")){s.value= "";}}
					);
				}
			)
		}
	);
});