
function despachar(aDef,aParam) {
	
	eval(aDef[0] + '(aDef,aParam)');
	
}


function menu_mostrar(BOTON) {
	
	if (arguments.length>1) {
		APAGAR=arguments[1];
	} else {
		APAGAR=true;
	}
	
	
	nb=BOTON.getAttribute("id");
	
	
	p=BOTON.parentNode;
	np=p.getAttribute("id");
	var ddiv=$('area_' + np.split("_")[1]);
	//alert('area_' + np.split("_")[1]);
	var children=ddiv.childNodes;
	//alert(children.length);
	if (APAGAR) {
		for (var i=0;i<children.length;i++){
			//alert(children[i].nodeName);
			if (children[i].nodeName=='DIV') {
			   $(children[i]).style.display='none';
			}
		}
	}
	var children=p.getElementsByTagName("span");
	for (var i=0;i<children.length;i++){
		t=children[i].getAttribute("id");
		if (t)
			document.getElementById(t).className=document.getElementById(t).className.replace(' activo','');
		
	}
	document.getElementById('area_' + nb.split("_")[1]).style.display='';
	BOTON.className=BOTON.className + ' ' + 'activo';
}

function showRow(el) {
   el.style.background="#ffffff";
   //el.style.color="#008";
}

function showRowStop(el) {
   el.style.background="";
   //el.style.color="";
 }
 
function resaltar_clase(obj,sino) {
	if (sino) {
		$(obj).className=$(obj).className + ' resaltar';
	} else {
		$(obj).className=$(obj).className.replace(' resaltar','');		
	}
	
}
 

// liveGrid
function aux_abookmark(elemento, liveGrid, offset ) {
      
	   if (liveGrid.metaData.getTotalRows()<offset+liveGrid.metaData.getPageSize()) {
		hasta=liveGrid.metaData.getTotalRows();
	   } else {
		hasta=offset+liveGrid.metaData.getPageSize();   
	   }
      $(elemento).innerHTML = "Listado " + (offset+1) + " - " + (hasta+1) + " de " + 
      		liveGrid.metaData.getTotalRows();

}


function agergarDiv(nombre,estilo,padre,html) {
    var newdiv = document.createElement("div");
    newdiv.className = estilo;
    newdiv.id = nombre;
    newdiv.innerHTML=html;
    padre.appendChild(newdiv);
    return newdiv;
  }
  
  
  function sustituirInnerHTML(elemento,nuevoHTML) {
	  $(elemento).innerHTML=nuevoHTML;
  }
  
  
  
function ampliar_foto(FotoSrc,wx,wy){
	
	nv=nv+1;
	var win = new Window(
		'nv'+nv, 
		{className: "mac_os_x", 
			width:wx+30,
			height:wy+30,
			zIndex: 100, 
			resizable: true, 
			maximizable:false,
			pinchable: false, 
			title: "Foto", 
			url:"../imgs/" + FotoSrc,
		draggable:true}
		); 
		//win.setStatusBar(""); 
		win.setDestroyOnClose();
		win.show();
		win.toFront();
}

// desplegables
function cargar_op(selectid,vector){
	
//	alert('va'+selectid);
//	insertar_op(selectid,1,"tutut");
//	quitartodos_op(selectid);
//	alert('listo');
	// carga los datos de un vector en un desplegable
	var opcion_cero=1;
	if(arguments.length>2)
		opcion_cero=arguments[2]; // espera 0 o 1
	
	var texto_cero="";
	if(arguments.length>4)
		texto_cero=arguments[4]; // espera 0 o 1
	
	var opcion_posicion=0; // por defecto si el valor del array es un vector toma la primera posicion
	if(arguments.length>3)
		opcion_posicion=arguments[3]; // espera que posicion tomar si es vector
	
	quitartodos_op(selectid);
	if(opcion_cero==1){
		insertar_op(selectid,0,texto_cero);
	}
	
	
	for(keyvar in vector){
		if(''+keyvar!=='extend'){
			var vtexto=vector[keyvar];
			var texto='';
			if (typeof vtexto == 'string')
				texto=vtexto;
			else
				texto=vtexto[opcion_posicion];
			
			
			//new Insertion.Bottom(selectid, "<option value="+keyvar+">"+texto+"</option>");
			insertar_op(selectid,keyvar,texto);
			
		}
	}
	
}



function seleccionar_op(elemento,clave){
	
	for(var i=0;i<$(elemento).options.length;i++){
		if($(elemento).options[i].value==clave)
			$(elemento).selectedIndex=i;
		
	}
	
	
}


function insertar_op(selectid,valor,texto){
	  var elOptNew = document.createElement('option');
	  elOptNew.text = texto;
	  elOptNew.value = valor;
	  var elSel = document.getElementById(selectid);
	
	  try {
	    elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
	  }
	  catch(ex) {
	    elSel.add(elOptNew); // IE only
	  }
	
}

function quitartodos_op(selectid){
	  var elSel = document.getElementById(selectid);
	
	  try {
	    elSel.innerHTML=""; // standards compliant; doesn't work in IE
	  }
	  catch(ex) {
		  for(opts in elSel.childNodes){
			  elSel.remove(opts);
		  }
	  }
	
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Ingrese un email\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Verifique el email ingresado.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "Verifique el email ingresado.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "No ingreso un numero de teléfono.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "Error en el número teléfonico ingresado.\n";
        fld.style.background = 'Yellow';
    } else if (stripped.length<6) {
        error = "Verifique el número de teléfono ingresado.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
