//<![CDATA[	

/************************************************************************/
/*       					WEB CINUR		  							*/
/*						Fichero: funciones.js 				            */
/* 				Ultima actualización: 12 de julio de 2006 			    */
/************************************************************************/


var bConfirmacion = true;
var popUpWin=0;
var popUpWinEdicion = 0;
var popUpWinListado = 0;

function popUpWindow(URLStr, left, top, width, height)
{
	if(popUpWin)
	{
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpWindowEdicion(URLStr)
{
	var left = (screen.width - 840)/2;
	var top = (screen.height - 620)/2;
	var width = 840;
	var height = 620;
	if(popUpWinEdicion)
	{
		if(!popUpWinEdicion.closed) popUpWinEdicion.close();
	}
	popUpWinEdicion = open(URLStr, 'popUpWinEdicion', 'toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popUpWindowListado(URLStr)
{
	var left = (screen.width - 840)/2;
	var top = (screen.height - 620)/2;
	var width = 840;
	var height = 620;
	if(popUpWinListado)
	{
		if(!popUpWinListado.closed) popUpWinListado.close();
	}
	popUpWinListado = open(URLStr, 'popUpWinListado', 'toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function nothing() {}



/* ---------------------------------------------------------------------------------------- */
// Funcion que redirige a la url selecionada de un select
/* ---------------------------------------------------------------------------------------- */
function go(obj)
{
	destination = obj.options[obj.selectedIndex].value;
	if (destination) location.href = destination;
}




/* ---------------------------------------------------------------------------------------- */
// Añadir evento al window-onload respetando los eventos existentes
/* ---------------------------------------------------------------------------------------- */

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}




/* Carga de página */

function parentGoto(page)
{
	window.parent.location.href = page;
}

function Goto(page)
{
	window.location.href = page;
}





function confirmar(sTexto)
{
	bConfirmacion = confirm(sTexto);
}


/* AMPLIACION Cambio de Class */
function updateClassName(Elemento, class1, class2)
{
	if($(Elemento).hasClassName(class1))
		$(Elemento).removeClassName(class1);

	$(Elemento).addClassName(class2);
}

function changeAllClassName(classname, oldclass)
{
	var allNodes = document.getElementsByClassName(classname);
	for(i = 0; i < allNodes.length; i++)
	{
		Element.classNames(allNodes[i]).set(oldclass);
	}
}

function changeClassName(oLink, newclass, oldclass)
{
	changeAllClassName(newclass, oldclass)
	oLink.className = newclass;
}

function cambiaEstilo(enlace, op)
{
	for ( var count = 0 ; count < document.links.length; count++ ) 
	{
		if (document.links[count].className == "enlace3activo")
			document.links[count].className = "enlace3";
		if (document.links[count].className == "enlace4activo")
			document.links[count].className = "enlace4";
	} 
	
	switch (op)
	{
		case 4:	enlace.className = "enlace3activo";
			break;
		case 3:	default: enlace.className = "enlace3activo";
			break;
	}
}






/* FUNCIONES AJAX */
/* Usando Prototype */

function getHTML(url, pars, placeholder)
{
	var myAjax = new Ajax.Updater(placeholder, url, { method: 'get', parameters: pars });
	//alert($(placeholder).innerHTML);
}

function PeticionAjaxEliminar(url, param, urlRecarga)
{
	//alert(url + " " + param);
	//alert(urlRecarga);
	new Ajax.Request(encodeURIComponent(url), {
	method: 'get',
	parameters: param,
	onLoading: function(request) {
			//$(placeholder).innerHTML += "onLoading";
			//$(placeholder).innerHTML += request.responseText;
		},
	onLoaded: function(request) {
			//$(placeholder).innerHTML += "onLoaded";
			//$(placeholder).innerHTML += request.responseText;
		},
	onInteractive: function(request) {
			//$(placeholder).innerHTML += "onInteractive";
			//$(placeholder).innerHTML = request.responseText;
		},		
	onComplete: function(request) {
		if(request.status != 200)
		{
			alert("Unavailable. " + request.status + url);
		}
		else
		{
			if(request.responseText == "ok")
			{
				//request.responseText;
				document.location = urlRecarga;
				alert("Elemento eliminado");
			}
			else
			{
			}
		}
		}
	});
}



/* Funciones de establecimiento del Status del navegador */
function setStatus(s)
{
	window.status = s;
	return true;
}




/* Funcion para mostrar la fecha del servidor */
/* Realiza una petición AJAX */
function mostrarReloj(sOBJ)
{
	new Ajax.Request('/controls/clientes/getDateTime.aspx', {
		method: 'get',
		onSuccess: function(sDate) {
			var aDate = $w(sDate.responseText);
			var date = new Date(aDate[0], aDate[1], aDate[2], aDate[3], aDate[4], aDate[5]);
			hora = date.getHours();
			minuto = date.getMinutes();
			segundo = date.getSeconds();
			str_segundo = new String (segundo);
			if (str_segundo.length == 1)
				segundo = "0" + segundo;
			str_minuto = new String (minuto);
			if (str_minuto.length == 1)
				minuto = "0" + minuto;
			str_hora = new String (hora);
			if (str_hora.length == 1)
				hora = "0" + hora;
			horaImprimible = hora + ":" + minuto + ":" + segundo;
			$(sOBJ).innerHTML = horaImprimible;
		}
	});
}



//]]>

