// Crea una pop up window.
// Recibe el link, el ancho y el alto.
function popup(src,wd,hg,target){
	if(wd!=null && hg!=null)
		if(target==null)
			window.open(src,'',"width="+wd+", height="+hg+", top="+(screen.height-hg)/2+", left="+(screen.width-wd)/2+", toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no");
		else
			window.open(src,target,"width="+wd+", height="+hg+", top="+(screen.height-hg)/2+", left="+(screen.width-wd)/2+", toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no");
	else
		if(target==null)
			window.open(src);
		else
			window.open(src,target);
}

// Muestra Contenido.
// Recibe como parámetro un div.
function show(div){
	var content = document.getElementById(div);
	
	if(content.style.display == '')
		content.style.display = 'none';
	else
		content.style.display = '';
		
	return div;
}

// Funciones para desplazar valores de listas
function deleteOption(object,index){
	object.options[index] = null;
}

function addOption(object,text,value){
	var defaultSelected = true;
	var selected = true;
	var optionName = new Option(text, value, defaultSelected, selected)
	object.options[object.length] = optionName;
}

function copySelected(fromObject,toObject){
	for (var i=0, l=fromObject.options.length;i<l;i++){
		if (fromObject.options[i].selected)
			addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
	}
		
	for (var i=fromObject.options.length-1;i>-1;i--){
		if (fromObject.options[i].selected)
			deleteOption(fromObject,i);
	}
}

function copyAll(fromObject,toObject){
	for (var i=0, l=fromObject.options.length;i<l;i++){
		addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
	}
	
	for (var i=fromObject.options.length-1;i>-1;i--){
		deleteOption(fromObject,i);
	}
}

function arraytostr(array){
	var str='';
	for(i=0;i<array.length;i++){
		str+=array[i].value;
		if(i+1!=array.length)
			str+=', ';
	}
	return str;
}

// Funcion para el hxconn.js..
// Agarra el nombre de un formulario y agarra todos los campos y sus valores y los pone en una cadena tipo GET
function formtoget(formname){
	str='';
	for(cont=0;document.forms[formname].elements[cont];cont++){
		if(cont!=0)
			str+='&';
		str+=document.forms[formname].elements[cont].name+'='+document.forms[formname].elements[cont].value;
	}
	
	return str;
}

// Funcion para lodear imagenes...
// Example: preloadImages('file.gif', 'http://www.x.com/y.gif');
function preloadImages(){
	if(document.images){
		if(!document.imageArray)
			document.imageArray = new Array();
	
		var i,j = document.imageArray.length, args = preloadImages.arguments;
    
		for(i=0; i<args.length; i++){
			if (args[i].indexOf("#")!=0){
				document.imageArray[j] = new Image;
				document.imageArray[j++].src = args[i];
			}
		}
	}
}

// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

// Usando el hxconn.js muestra un div metiendole el contenido devuelto de una página especificada
function showcontent(divname, pagesend, datasend) {
	document.cursor='wait';
							
	var myConn = new xhconn();
							
	if(!myConn)
		alert('XMLHTTP no disponible. Se requiere un navegador mas reciente.');
		
	var fnWhenDone = function (oXML){
		div = document.getElementById(divname);
		div.innerHTML=oXML.responseText;
		div.style.display='';
		document.cursor='';
	};
	
	myConn.connect(pagesend, 'POST', datasend, fnWhenDone);
}
