function enviarEvento(urn, nome, valor){
	EPCM.raiseEvent( urn, nome, valor );
}

function enviarinformacao(url, target){
  parent.document.frames(target).location = url;
}

function addStyleSheet(url){
	//document.styleSheets(0).addImport(url)
}

function open_url_in_window(url){
	var xinfo = ""; 
	xinfo = window.open(url);
}  

function HrefSubmit(event, resource, control){
	document.getElementById(control).submit_event.value=event; 
	document.getElementById(control).submit_resource.value=resource; 
	document.getElementById(control).submit();
}

function setPropriedades(control,dataControl,msgErro){
	if (document.getElementById(control).value != "" && document.getElementById(control).value.length < 250){
		document.getElementById(dataControl).value = document.getElementById(control).value;
		return true;
	}
	else{
		alert(msgErro);
		return false;
	}
	
}

function setPropriedadesSemMsg(control,dataControl){
	if (document.getElementById(control).value != ""){
		document.getElementById(dataControl).value = document.getElementById(control).value;
	}
}

function setPropriedadesTBPSemMsg(control,dataControl){
	if (document.getElementById(control).value != ""){
		document.getElementById(dataControl).value = document.getElementById(control).value + " 23:59:59";
	}
}

function setPropriedadesCombobox(control,dataControl){
	if (document.getElementById(control).value != ""){
		document.getElementById(dataControl).value = document.getElementById(control).value;
	}
}

function setPropriedadesCatalogo(resControl, resDataControl, resMsgErro, imgControlPath, imgControl, imgDataControl, prodControl, prodDataControl){
	retSetPropriedades = setPropriedades(resControl, resDataControl, resMsgErro);
	if (retSetPropriedades)
	{
		document.getElementById(imgDataControl).value = document.getElementById(imgControlPath).value + "/" + document.getElementById(imgControl).value;
		document.getElementById(prodDataControl).value = document.getElementById(prodControl).value;
		return true;
	}else{
	 	 submitOK="False"
		return false;
	}
}

function open_url_in_self_window(url) { 
   	self.location = url;
}

function open_url_in_window_help(url){
	window.open(url, "_blank", "width=660,fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no");
}

function open_url_in_window_personalized(url){
	window.open(url, "_blank", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no");
}

function changeImage(cur, path){
	cur.src = path; 
}

function selectUNSPC(servername, id,idValue, queryString){
	var url = "/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/etc/xmlforms/catalogo/" + servername + ".html"
	
	windowModal = window.showModalDialog(url,'','DialogWidth=35;DialogHeight=30;status:no;Help:no;');
	if (windowModal != null){
		document.getElementById(id).value = windowModal[0];
		document.getElementById(idValue).value = windowModal[1];

		//Adicionar Informação ao DataBag
		EPCM.storeClientData( "urn:pt.empresa.catalogo", "path", windowModal[0]);
		EPCM.storeClientData( "urn:pt.empresa.catalogo", "valor", windowModal[1]);

		self.location = queryString + windowModal[0];
	}
}

function seleccionarPastaPrograma(url, queryString, urn){
	windowModal = window.showModalDialog(url,'','DialogWidth=35;DialogHeight=30;status:no;Help:no;');
	if (windowModal != null){
		//Adicionar Informação ao DataBag
		EPCM.storeClientData( "urn:pt." + urn, "path", windowModal[0]);
		EPCM.storeClientData( "urn:pt." + urn, "valor", windowModal[1]);
		
		self.location = queryString + windowModal[0];
	}
}

function botaoHover(name){
	var img_left	= document.getElementById(name + "_left");
	var img			= document.getElementById(name);
	var img_right	= document.getElementById(name + "_right");

	img_left.src			= "/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/etc/xmlforms/Common/imagens/left_hover.gif";
	img.style.background	= "url('/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/etc/xmlforms/Common/imagens/img_hover.gif')";
	img_right.src			= "/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/etc/xmlforms/Common/imagens/right_hover.gif";
}

function botaoOut(name){
	var img_left	= document.getElementById(name + "_left");
	var img			= document.getElementById(name);
	var img_right	= document.getElementById(name + "_right");

	img_left.src			= "/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/etc/xmlforms/Common/imagens/left.gif";
	img.style.background	= "url('/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/etc/xmlforms/Common/imagens/img.gif')";
	img_right.src			= "/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/etc/xmlforms/Common/imagens/right.gif";
}

function HrefGuardar(){
	document.getElementById("Servlet_post_button").click();
}

function HrefCancelar(){
	document.getElementById("Servlet_cancel_button").click();
}

function enderecosPortal(id, url){	
	windowModal = window.showModalDialog(url,'','DialogWidth=25;DialogHeight=15;status:no;Help:no;');
	if (windowModal != null)
	{
		editRange = document.getElementById(id + "htmlbeditor").document.selection.createRange();
		editRange.execCommand("CreateLink",false, windowModal);                
		editRange.parentElement().target = "_top";
	}
}

function enderecosDocumentacao(id, path){	
	var url="/irj/servlet/prt/portal/prtroot/documentBrowser.default?rootpath=" + path + "&XslPath=/etc/documentBrowser/documentBrowserDocumentacao.xsl&PageCount=10";
	windowModal = window.showModalDialog(url,'','DialogWidth=35;DialogHeight=25;status:no;Help:no;');
	if (windowModal != null)
	{
		editRange = document.getElementById(id + "htmlbeditor").document.selection.createRange();
		editRange.execCommand("CreateLink",false, "/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs" + path + "/" + windowModal);                
		editRange.parentElement().target = "_blank";
	}
}

function open_url_in_modal_window(controlo, url, repositorio){
	windowModal = window.showModalDialog(url,window,'DialogWidth=55;DialogHeight=37;status:no;Help:no;');
	if (windowModal != null){
		document.getElementById(controlo).value = repositorio+windowModal;
	}
}

function open_url_in_modal_window_room(controlo, url){
	//var localizacao = url + "&controlo=" + controlo;
	//window.open(localizacao, "roomBrowser", 'toolbar,width=800,height=500');
	windowModal = window.showModalDialog(url + "&controlo=" + controlo,window,'DialogWidth=55;DialogHeight=37;status:no;Help:no;');
	if (windowModal != null){
		document.getElementById(controlo).value = windowModal[0];
	}
}

function open_url_out_modal_window(controlo, url, repositorio){
	window.open(url,'','');
}

function confirmar() {
	
	var x=window.confirm('Tem a certeza que quer eliminar?')		
	if (x)		
	return true;
	else
	return false;		
}

