/* 
-----------------------------------------------------------------------------------------------
Name:			utilities.js
Description: 	Utilidades Javascript
Creator:		PBP - pbp@firedune.com.ar

FUNCIONES:
	Delete(id,nombrevariable)		Confirm Delete
	miniReload()					Colocado en el body recarla la pagina onfocus
	OpenAdminWindow(url)			Abre una ventana nueva con parametos predefinidos
	AddFavorite(strName, strUrl)	Agrega la pagina a favoritos colocar en onclick de un boton
	SetAction(accion, formulario)	Realiza un submit del formulario previamente cargando el valor accion en el campo accion
	ChangeMedia()					Cambia imagen
	Go($newpage)					Redirecciona hacia newpage
	PrintAndBack()					Imprime y vuelve a la pagina anterior

HTML:
	<body onfocus="miniReload();">

MORE JAVASCRIPTS:
	document.title - title of the document (defined by the <title> tag)
 	document.referrer  - the page the visitor came from
 	document.lastModified - the date the page was last modified (sent from the server, so Javascript depends on server accuracy and support for this feature)
 	history.go()  - used for back and forward buttons, use history.go(-1) for back and history.go(1) for forward
 	location.pathname  - location of the window (the location in the address bar, ex. http://w3nation.com/)
 	document.location - location of the document (the location of the page)
 	parent.frames["nav"].window.location.reload(true);

Choose the selected
the_select = document.FormArticulos.midcatid;
//alert(the_select.options.length);
for (loop=0; loop < the_select.options.length; loop++){
	//alert(the_select.options[loop].value);
	if(the_select.options[loop].value == "<? print($objNews->intMidCatid); ?>"){
		the_select.options[loop].selected = true;
	}
}


Version History:
	v1		2004-10-25	PBP		Created	
	v2		2004-10-30	PBP		Agregue funcion SetAccion
	v3		2007-03-30	PBP		Agregue funcion PrintAndBack($newpage) y Ir($newpage)
	v4		2007-03-30	PBP		Modifique PrintAndBack(newpage,time) para que incluya tiempo
	
-----------------------------------------------------------------------------------------------
*/

var objwindow;

function ChangeMedia(strurl){
	//alert(strurl);
	document.media.src = strurl;	
}

function Go(newpage){
	//alert("Ir: "+newpage);
	window.location = newpage;
}

function ShowImages(){
	document.getElementById("images").style.visibility = "visible";
	document.getElementById("images_background").style.visibility = "visible";
}

function HideImages(){
	document.getElementById("images").style.visibility = "hidden";
	document.getElementById("images_background").style.visibility = "hidden";
}

function PrintAndBack(newpage,time){
	print();
	setTimeout(back(),time);
}


function Delete(url) {
	var answer = confirm ("Are you sure you want to delete?");
	if (answer){
		//alert(url);
		window.location.href = url;	
	};
}


function ConfirmaIr(url,mensaje) {
	var answer = confirm (mensaje);
 	if (answer){
		location.href = url;	
	}
}


function miniReload() {
	if (objwindow) {
		objwindow.close;
		window.location.reload();
		objwindow = null;
	}
}


function OpenAdminWindow(url) {
	objwindow = window.open(url, 'adm','scrollbars=yes,width=600,height=500');
}


function AddFavorite(strName, strUrl) {
	if (!strUrl) {
		strUrl = location.href;
	}
	if (!strName) {
		strName = document.title;
	}
	if (document.all) {
		window.external.AddFavorite(strUrl, strName);
	}else{
		alert ("Para agregar " + strName + " al bookmark presione Ctrl+D");
	}
}


function SetAction(accion, formulario){
	if(!formulario){
		formulario = "form";
	}
	formulario = eval("document." + formulario);
	formulario.FormAccion.value = accion;
	
	formulario.submit();
	return true;
}
