var win = null;

function abrirPopup(url, w, h){
	if (win != null && win.open) win.close();
	win=window.open(url,'popup','toolbar=0,location=0,status=0,menubar=0,resizable=yes,scrollbars=yes,width='+w+',height='+h);
	if(window.focus) win.focus();
}


function toggleRow(id, hover){
	destTop = document.getElementById("destTop"+id);
	dest = document.getElementById("dest"+id);
	
	if(hover)
	{
		destTop.className='destTopHover';
		dest.className='destHover';
	}
	else
	{
		destTop.className='destTop';
		dest.className='dest';
	}
}

function validaRegisto() {
	var vValida = new Array(7);
	vValida[0] = new ObjectoValida("emailU", 'Email',"Email","Obrigatorio","","","");
	vValida[1] = new ObjectoValida("nomeU",  'Nome',"String","Obrigatorio","4","","");
	vValida[2] = new ObjectoValida("empresaU",  'Empresa',"String","Obrigatorio","8","","");
	vValida[3] = new ObjectoValida("codigoPostal",  'Código Postal',"String","Obrigatorio","4","8","");
	vValida[4] = new ObjectoValida("contactoU",  'Contacto',"Number","Obrigatorio","9","","");
	vValida[5] = new ObjectoValida("pwdU",  'Password',"String","Obrigatorio","6","","");
	vValida[6] = new ObjectoValida("confPwdU",  'Confirmação Password',"String","Obrigatorio","6","","");
	if (verificaForm("registo",vValida,false)){
		pwd=document.registo.pwdU.value
		confPwd=document.registo.confPwdU.value
		if (pwd != confPwd ) 
				alert ("As password´s têm que ser iguais.")
			else{
				document.registo.target="_self" 
				document.registo.action='gUser.php'
				document.registo.submit()
			}
	
		document.dados.submit()										
	}
	return false;
}

function enviaForm(url,cod,idOp){
	document.dados.codigo.value = cod	
	document.dados.idOp.value = idOp	
	document.dados.target="_self"
	document.dados.action=url
	document.dados.submit()		
}

function enviaFormDel(url,cod,idOp){		
	if(confirm("Deseja mesmo apagar o registo?")){
		document.dados.codigo.value = cod	
		document.dados.idOp.value = idOp	
		document.dados.action=url
		document.dados.submit()	
	}
}		
	
function mudaStyle(p,op){
	if (op==0) document.getElementById("DivImg"+p).className ='img200On'
	else document.getElementById("DivImg"+p).className ='img200Off'
}

function enviaLogin(){
	user=document.frmLogin.user.value
	pwd=document.frmLogin.pwd.value
	if ((user=="") || (pwd=="") || (user=="Username") || (pwd=="Password") )
		alert(" Os dados tem que estar preenchidos")
		
	else {
		document.frmLogin.action='validaUser.php'
		document.frmLogin.submit()
	}
}

function changeFoto(){
	document.getElementById("imgSrc").src="<?=$portal?>/php/img/pics/fotos/"+document.getElementById("foto").value

}


function gotFocus(elem, text){
	if(elem.value == text) elem.value = ''
}


function lostFocus(elem, text){
	if(elem.value == '') elem.value = text
}


function detalhe(cod,iopt){
	document.noticia.codigo.value=cod
	document.noticia.idOp.value=iopt
	document.noticia.action='dNews.php'
	document.noticia.submit()
	
}

function verVideo(caminho){
	document.frmVideo.caminho.value=caminho	
	document.frmVideo.action='index.php'
	document.frmVideo.submit()
	
}


function searchP(){
	document.frmSearch.idOp.value=3
	inpSearch=document.frmSearch.inpSearch.value		
	if ((inpSearch=="") || (inpSearch=="Procurar produto") )
		alert("O campo deve estar preenchido!")			
	else {
		document.frmSearch.submit()
	}		
	
}

	
function changeSize(elemID, newWidth, newHeight){
	if(newWidth) document.getElementById(elemID).width = newWidth
	if(newHeight) document.getElementById(elemID).height = newHeight
}

//função que abre uma POPUP (janela)
function openWinPost( windowURL, windowName, width, height ) { 
	largura=0
	altura=0
	if (!document.all){
		largura=window.innerWidth
		altura=window.innerHeight
	}else{
		largura=screen.width
		altura=screen.height
	}
	esquerda=(largura/2)-(width/2)
	topo=(altura/2)-(height/2)

	comScroll="1"

	argv = openWinPost.arguments
	if (argv.length>=5) comScroll="1"

	indexForm=0
	argv = openWinPost.arguments
	if (argv.length>=6) indexForm=argv[5]
	
	windowFeatures="width="+width+",height="+height+",left="+esquerda+",top="+topo+",toolbar=0,location=0,directories=0,status=0,menuBar=1,scrollBars="+comScroll+",resizable=yes"
	
	var janela = window.open('',windowName,windowFeatures);
	janela.focus();
	document.forms[indexForm].method='POST';
	document.forms[indexForm].action=windowURL;
	document.forms[indexForm].target=windowName;
	document.forms[indexForm].submit();
}



