function check_max(memo,tope){
	if(elemento(memo).value.length > tope) {
	   alert('La descripción ingresada es demasiado larga. No puede superar los 500 caracteres');
	   return false; 
  	} else return true;
}

function VerFoto(uid) {
	var foto = window.open("/ampliarfoto.php?uid=" + uid, "foto", "width=500, height=400, top=50, left=50, scrollbars=yes");
	foto.focus();
}

function elemento(id){
	var r = document.getElementById(id);
	//alert(id+r);
	if(r == null){r = document.getElementsByName(id)[0];}
	return r;
}

function reemplazar_text_por_area(nombre_text , cols , rows ){
	x = elemento(nombre_text);
	p = x.parentNode;
	val = x.value;
	p.removeChild(x);
	texto = document.createElement("textarea");
	texto.setAttribute('name',nombre_text);
	texto.setAttribute('id',nombre_text);
	texto.setAttribute('rows',rows);
	texto.setAttribute('cols',cols);
	texto.value = val;
	p.appendChild(texto);
}

function mostrar_ocultar(id_item , visible){
	elemento(id_item).style.visibility = (visible)? 'visible' : 'hidden';
	//alert(document.getElementById(id_item).style.visibility);
}

function texto_combo_to_edit(combo,edit,titulo,vacio,lleno){
 	var com = elemento(combo);
 	var ed = elemento(edit);
 	ed.value = com.options[com.selectedIndex].text;
 	
 	if (!titulo==""){
 		var tit = elemento(titulo);
	 	if (ed.value==""){tit.innerHTML = vacio; }
 		else{tit.innerHTML = lleno; } 
 	}
}

function marcar_combo(combo , marca){
 	var com = elemento(combo);
 	var hijos = com.options;
 	var elem = elemento(marca);
 	//alert(elemento(marca));
 /*	for(i=1 ; i < hijos.length; i++){
 		if(com[i].id == marca){var elem = com[i];}
 	}*/
 	if(com != undefined && elem!= undefined){com.selectedIndex = elem.index;}
 }

function move(fbox,tbox) {
	for(var i=0; i<fbox.options.length; i++) {
		if(fbox.options[i].selected && fbox.options[i].value != "") {
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;
			tbox.options[tbox.options.length] = no;
			fbox.options[i].value = "";
			fbox.options[i].text = "";
   		}
	}
	BumpUp(fbox);
	if (sortitems) SortD(tbox);
}

function BumpUp(box)  {
	for(var i=0; i<box.options.length; i++) {
		if(box.options[i].value == "")  {
			for(var j=i; j<box.options.length-1; j++)  {
				box.options[j].value = box.options[j+1].value;
				box.options[j].text = box.options[j+1].text;
			}
		var ln = i;
		break;
   		}
	}
	if(ln < box.options.length)  {
		box.options.length -= 1;
		BumpUp(box);
   }
}

function SortD(box)  {
	var temp_opts = new Array();
	var temp = new Object();
	for(var i=0; i<box.options.length; i++)  {
		temp_opts[i] = box.options[i];
	}
	for(var x=0; x<temp_opts.length-1; x++)  {
		for(var y=(x+1); y<temp_opts.length; y++)  {
			if(temp_opts[x].text > temp_opts[y].text)  {
				temp = temp_opts[x].text;
				temp_opts[x].text = temp_opts[y].text;
				temp_opts[y].text = temp;
				temp = temp_opts[x].value;
				temp_opts[x].value = temp_opts[y].value;
				temp_opts[y].value = temp;
		     }
	   }
	}
	for(var i=0; i<box.options.length; i++)  {
		box.options[i].value = temp_opts[i].value;
		box.options[i].text = temp_opts[i].text;
   }
}
