//JavaScript js_AjaxenviaForm  

//---------------------------------------------------------------------------------------//
function validaEvento(e){
//---------------------------------------------------------------------------------------//
	var keynum;
	if(window.event){ 
		keynum = e.keyCode;
	}
	else if(e.which){ 
		keynum = e.which;
	}
	return keynum;
}

//---------------------------------------------------------------------------------------//
function verCalendario(auxForm,auxText){
//---------------------------------------------------------------------------------------//
	var strFeatures = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=350,height=230,screenX=150,screenY=150,top=50,left=50';
	//alert (aux.name);
	window.open('../pages/calendario.php?nombreForm='+auxForm.name+'&nombreControl='+auxText.name,"myWin", strFeatures);
}

//---------------------------------------------------------------------------------------//
function validaNumero(texto,evento){//permite digitar solo numeros y el punto
//---------------------------------------------------------------------------------------//    
	var key = validaEvento(evento);
	if(key == 8){ return true; }
    if ((key < 48 || key > 57)&&(key!=46)){
        if(window.event){ 
			evento.keyCode = 0;
			respuesta = false;
		}
		else if(evento.which){			
			return false;
		}
    }
    if((key==46)&&(texto.value.indexOf('.') > -1)){
        if(window.event){ 
			evento.keyCode = 0;
			respuesta = false;
		}
		else if(evento.which){ 
			return false;
		}
    }	
}//end function validaNumero

//---------------------------------------------------------------------------------------//
function validaNumeroHora(texto,evento){//permite digitar solo numeros y el punto 
//---------------------------------------------------------------------------------------//
	//window.event.keyCode valor ascii de tecla pulsada
	var key = validaEvento(evento);
	if ((key < 48 || key > 57)&&(key!=58)){
		if(window.event){ 
			evento.keyCode = 0;
			respuesta = false;
		}
		else if(evento.which){ 
			return false;
		}
	}
	if((key==58)&&(texto.value.indexOf(':') > -1)){
		if(window.event){ 
			evento.keyCode = 0;
			respuesta = false;
		}
		else if(evento.which){ 
			return false;
		}
	}
}//end function validaNumeroHora

//---------------------------------------------------------------------------------------//
function validaEnter(evento){//permite digitar solo numeros y el punto 
//---------------------------------------------------------------------------------------//
	//window.event.keyCode valor ascii de tecla pulsada
	var flag = false;
	var key = validaEvento(evento);
	if(key==13){
		flag =  true;
	}
	return flag;
}//end function validaNumeroHora

//---------------------------------------------------------------------------------------//
function validaNumeroFecha(texto,evento){//permite digitar solo numeros y el punto 
//---------------------------------------------------------------------------------------//
	//window.event.keyCode valor ascii de tecla pulsada
	var key = validaEvento(evento);
	if ((key < 48 || key > 57)&&(key!=47)){
		if(window.event){ 
			evento.keyCode = 0;
			respuesta = false;
		}
		else if(evento.which){ 
			return false;
		}
	}
	guion = texto.value.indexOf('/');
	if(guion > -1){
		if((key==45)&&(texto.value.indexOf('/',guion+1) > 0)){
			if(window.event){ 
				evento.keyCode = 0;
				respuesta = false;
			}
			else if(evento.which){ 
				return false;
			}
		}
	}
}//end function validaNumeroFecha

//---------------------------------------------------------------------------------------//
function validaTipoPorc(texto){//permite digitar solo "V,P,v,p,E,e" 
//---------------------------------------------------------------------------------------//
	//window.event.keyCode valor ascii de tecla pulsada
	var key = window.event.keyCode;	
	//alert(key);
	if (!((key==80)||(key==86)||(key==112)||(key==118)||(key==69)||(key==101))){
		window.event.keyCode = 0;
	}// end if
}//end function validaTipoPorc

//---------------------------------------------------------------------------------------//
function validaPunto(texto){
//---------------------------------------------------------------------------------------//
    if(texto.value.indexOf('.') == 0){
        texto.value = texto.value.substr(1);
    }    
}//end function validaPunto

//---------------------------------------------------------------------------------------//
function validaSoloNumero(evento){	
//---------------------------------------------------------------------------------------//
	var key = validaEvento(evento);
	if(key == 8){ return true; }
	if(key == 13){ return true; }
	//if ((key < 48 || key > 57)&&(key!=46)){
	if (key < 48 || key > 57){
        if(window.event){ 
			evento.keyCode = 0;
			respuesta = false;
		}
		else if(evento.which){			
			return false;
		}
    }	
}//end function validaNumero

//---------------------------------------------------------------------------------------//
function validaNumeroLetra(){
//---------------------------------------------------------------------------------------//
	//window.event.keyCode valor ascii de tecla pulsada
	var key = window.event.keyCode;
	if ((key < 48 || key > 57)){		
		if ((key <65  || key > 90)&&(key <97  || key > 122)){			
			window.event.keyCode = 0;
		}
	}	
}//end function validaNumero

//---------------------------------------------------------------------------------------//
function validaFecha(){//permite digitar solo numeros y el guión (-)
//---------------------------------------------------------------------------------------//
	//window.event.keyCode valor ascii de tecla pulsada
	var key = window.event.keyCode;	
	if ((key < 48 || key > 57)&&(key!=45)){
		window.event.keyCode = 0;
	}	
	
}//end function validaNumero

//---------------------------------------------------------------------------------------//
function validaFono(){
//---------------------------------------------------------------------------------------//
	//window.event.keyCode valor ascii de tecla pulsada
	var key = window.event.keyCode;
	//alert(key);
	if ((key < 48 || key > 57)&&(key!=43&&key!=32)){
		window.event.keyCode = 0;
	}	
}//end function validaNumero

//---------------------------------------------------------------------------------------//
function noEspacio(){
//---------------------------------------------------------------------------------------//
	//window.event.keyCode valor ascii de tecla pulsada
	//rango de caracteres no numericos ni alfabeticos: 33-47; 58-64; 91-96; 123-127
	var key = window.event.keyCode;
	//alert(key);
	if (key==32){
		window.event.keyCode = 0;
	}	
}//end function validaNumero

//---------------------------------------------------------------------------------------//
function validaLetra(frm){	
//---------------------------------------------------------------------------------------//
	var key = window.event.keyCode;
//if (key != 13)	{	
	if ( key != 32){
		if ((key <65  || key > 90)&&(key <97  || key > 122)){			
			window.event.keyCode = 0;
		}
	}	
}

//---------------------------------------------------------------------------------------//
function noAccion(){
//---------------------------------------------------------------------------------------//
	window.event.keyCode = 0;
}

//verificar @ y . en una direccion e-mail
//---------------------------------------------------------------------------------------//
function validar_email(txt){	
//---------------------------------------------------------------------------------------//
	//expresion regular
        var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/
        
    //comentar la siguiente linea si no se desea que aparezca el alert()
    alert("Email " + (b.test(txt)?"":"no ") + "válido.")
        
    //devuelve verdadero si validacion OK, y falso en caso contrario
    return b.test(txt)
}

//---------------------------------------------------------------------------------------//
function email_valido(texto){
//---------------------------------------------------------------------------------------//
	var txt = texto.value;
	//expresion regular
    var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/
        
	if(!b.test(txt)){
	    alert("Email no válido.");
		texto.focus();
	}
        
    return b.test(txt)
}

//---------------------------------------------------------------------------------------//
function ventanaDialogo(pagina,width,height){
//---------------------------------------------------------------------------------------//
	  if(!width){ width = 400; }
	  if(!height){ height = 350; }
	  var strFeatures = "dialogWidth="+ width +"px;dialogHeight="+height+"px;center=yes;help=no;status=no;scroll=no;edge=sunken;unadorned=yes";
	  window.showModalDialog(pagina,"myWin", strFeatures);	  
}// end ventanaDialogo

///////////////////////////////////
// Rutina para validar Fecha	//

//---------------------------------------------------------------------------------------//
function esDigito(sChr){
//---------------------------------------------------------------------------------------//
	var sCod = sChr.charCodeAt(0);
	return ((sCod > 47) && (sCod < 58));
}

//---------------------------------------------------------------------------------------//
function valSep(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = false;
	bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
//	bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-"));
	//bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
	return bOk;
}

//---------------------------------------------------------------------------------------//
function finMes(oTxt){
//---------------------------------------------------------------------------------------//
	var nMes = parseInt(oTxt.value.substr(3, 2), 10);
	var nRes = 0;
	switch (nMes){
		case 1: nRes = 31; break;
		case 2: nRes = 29; break;
		case 3: nRes = 31; break;
		case 4: nRes = 30; break;
		case 5: nRes = 31; break;
		case 6: nRes = 30; break;
		case 7: nRes = 31; break;
		case 8: nRes = 31; break;
		case 9: nRes = 30; break;
		case 10: nRes = 31; break;
		case 11: nRes = 30; break;
		case 12: nRes = 31; break;
	}
	return nRes;
}

//---------------------------------------------------------------------------------------//
function valDia(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = false;
	var nDia = parseInt(oTxt.value.substr(0, 2), 10);
	//alert(finMes(oTxt));
	//var nDia = parseInt(oTxt.value.substr(0, 2), 10);
	bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
	return bOk;
}

//---------------------------------------------------------------------------------------//
function valMes(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = false;
	var nMes = parseInt(oTxt.value.substr(3, 2), 10);
	
	//var nMes = parseInt(oTxt.value.substr(3, 2), 10);
	bOk = bOk || ((nMes >= 1) && (nMes <= 12));
	return bOk;
}

//---------------------------------------------------------------------------------------//
function valAno(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = true;
	var nAno = oTxt.value.substr(6,4);
//	var nAno = oTxt.value.substr(6);

	bOk = bOk && ((nAno.length == 4));
//	bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
	if (bOk){
		for (var i = 0; i < nAno.length; i++){
		bOk = bOk && esDigito(nAno.charAt(i));
		}
		if (bOk){
			var anio = parseInt(nAno);
			bOk = ((anio >= 1900) && (anio <= 2777));
		}
	}
	return bOk;
}

//---------------------------------------------------------------------------------------//
function valFecha(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = true;
	if (oTxt.value != ""){
		bOk = bOk && (valAno(oTxt));
		bOk = bOk && (valMes(oTxt));
		bOk = bOk && (valDia(oTxt));
		bOk = bOk && (valSep(oTxt));
		if (!bOk){
			alert("Fecha no valida");
			oTxt.value = "";
			oTxt.focus();
			return false;
		}
	}
}

// Fin Rutina para validar Fecha
///////////////////////////////////
// Rutina para validar Fecha	//
//---------------------------------------------------------------------------------------//
function valSepHora(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = false;
	bOk = bOk || ((oTxt.value.charAt(2) == ":"));
	return bOk;
}
//---------------------------------------------------------------------------------------//
function valHora(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = false;
	var nHora = parseInt(oTxt.value.substr(0, 2), 10);
	bOk = bOk || ((nHora >= 0) && (nHora <= 23));
	return bOk;
}
//---------------------------------------------------------------------------------------//
function valMinuto(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = false;
	var nMin = parseInt(oTxt.value.substr(3, 2), 10);
	bOk = bOk || ((nMin >= 0) && (nMin <= 59));
	return bOk;
}
//---------------------------------------------------------------------------------------//
function valHoras(oTxt){
//---------------------------------------------------------------------------------------//
	var bOk = true;
	if (oTxt.value != ""){
		bOk = bOk && (valHora(oTxt));
		bOk = bOk && (valMinuto(oTxt));
		bOk = bOk && (valSepHora(oTxt));
		if (!bOk){
			alert("Hora Invalida");
			oTxt.value = "";
			oTxt.focus();
			return false;
		}
	}
}
// Fin Rutina para validar Hora

// habilita o deshabilita un campo de un formulario mediante un Check
//---------------------------------------------------------------------------------------//
function disabledCampo(check,campo){
//---------------------------------------------------------------------------------------//
	if (document.getElementById(check).checked){
		document.getElementById(campo).disabled = false;
	}else{
		document.getElementById(campo).disabled = true;
	}// end if
}// end function

var elementos = new Array();
//---------------------------------------------------------------------------------------//
function ajaxCambiarTextos (dir_pagina, refrescar, destinos) {
//---------------------------------------------------------------------------------------//		
		var aux_destinos = new Array();
		var aux_contenidos = new Array();
		var contenido = "";
		
		var fecha = new Date(); 	
		var url = dir_pagina;
		/*-- Establecer los elementos de destino --*/
		
		aux_destinos = destinos.split(';');
		
		elementos.length = 0;//restablecer la variable
		
		for(i=0;i<aux_destinos.length;i++){			
			elementos[i] = $(aux_destinos[i]);
		}		
		/*-- Limpiar elementos de destino --*/
		for(i=0;i<elementos.length;i++){
			if(elementos[i]){
				elementos[i].value = "";
			}
		}//enf for contenido
		
		if (refrescar == 'S'){
			url = url+'/fecha/'+fecha;
		}//end if		
		//prompt('',url);
		//peticion.open("GET", url,sincroniza);
		new Ajax.Request(url, {
					  method: 'GET',
					  asynchronous: true,
					  onSuccess: datosHandler // si peticion se realizo correctamente ejecutar funcion js_successListadoHandler
					 //onFailure: muestraError
					});
		
		//peticion.onreadystatechange = 
	   //peticion.send(null);
	}//end ajaxCambiarTextos

//---------------------------------------------------------------------------------------//
	function datosHandler(transport) {
//---------------------------------------------------------------------------------------//		
	contenido = transport.responseText;
	//alert(peticion.responseText);
	txt = unescape(contenido);
	//txt2 = txt.replace(/\+/gi," ");				
	//alert(txt);
	if(contenido.length == 0 || contenido==""){
	alert("No se encontro el registro");
	return false;
	}
	aux_contenidos = txt.split(';');
	var k=0;
	for(i=0;i<aux_contenidos.length;i++){	
	
		if(elementos[i]){	
			//alert(elementos[i].id + " " + aux_contenidos[i]);
			elementos[i].value = aux_contenidos[i];	
		//-------------esta parte solo es para el detalle de la pantalla de facfacturaMantView.php----------------------------------// 	
			if (elementos[i].id.substring(0,7)=='ckb_iva'){
		
			    if (elementos[i].value==1){
				elementos[i].checked=true;
				k=1;
				
				}else{
				elementos[i].checked=false;	
			    k=0
				
				}
				
			}// end if 
			
			if (elementos[i].id.substring(0,7)=='hid_iva'){
		
			    if (k==1){
				elementos[i].value='1';
				}else{
				elementos[i].value='0';	
				}
			}// end if 
		
		//-------------------------------------------------------------------------------------------------------------------------//	
	
		}
		
	}//enf for contenido				
			
	}//end onreadystatechange 

//---------------------------------------------------------------------------------------//
	function consulta(ruta,destinos){ 
//---------------------------------------------------------------------------------------//
		ajaxCambiarTextos(ruta,'N',destinos);		
	}//end function

//---------------------------------------------------------------------------------------//
	function examinaDoc(destino){
//---------------------------------------------------------------------------------------//
		document.getElementById(destino).click();
	}

//---------------------------------------------------------------------------------------//
	function redondear(cantidad, decimales) {
//---------------------------------------------------------------------------------------//
		var cantidad = parseFloat(cantidad);
		var decimales = parseFloat(decimales);		
		var resultado = 0;
		decimales = (!decimales ? 2 : decimales);
		resultado = Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);		
		return resultado;
	}

//---------------------------------------------------------------------------------------//
	function infoDoc(){
//---------------------------------------------------------------------------------------//
		return true;		 
	}//end if

//---------------------------------------------------------------------------------------//
	function limpiarForm(idFrm){
//---------------------------------------------------------------------------------------//
		//alert(document.forms[idFrm].elements.length);
		for (i=0;i<document.forms[idFrm].elements.length;i++){			
			if(document.forms[idFrm].elements[i].length>0){				
				for(j=0;j<document.forms[idFrm].elements[i].length;j++){
					if ( document.forms[idFrm].elements[i].name.substring(0,3)== "txt" ) {
						document.forms[idFrm].elements[i][j].value="";
					}					
					if ( document.forms[idFrm].elements[i].name.substring(0,3)== "cmb" ) {
						document.forms[idFrm].elements[i][j].selected=false;
						document.forms[idFrm].elements[i].selectedIndex=0;
					}
					if ( document.forms[idFrm].elements[i].name.substring(0,3)== "lst" ) {
						document.forms[idFrm].elements[i][j].selected=false;
						//document.forms[idFrm].elements[i].selectedIndex=0;
					}
					if (document.forms[idFrm].elements[i].name.substring(0,3)== "chk" ||  document.forms[idFrm].elements[i].name.substring(0,3)== "rbt") {
						document.forms[idFrm].elements[i][j].checked=false;
					}
				}
			}else{				
				if ( document.forms[idFrm].elements[i].name.substring(0,3)== "txt" ) {
					document.forms[idFrm].elements[i].value="";
				}					
				if ( document.forms[idFrm].elements[i].name.substring(0,3)== "cmb" ) {
					document.forms[idFrm].elements[i].value=0;
				}
				if ( document.forms[idFrm].elements[i].name.substring(0,3)== "chk" ) {
					document.forms[idFrm].elements[i].checked=false;
				}
			}
		}
	}//end funcion limpiarForm
	
//---------------------------------------------------------------------------------------//	
  function addZero(vNumber){ 
//---------------------------------------------------------------------------------------//
    return ((vNumber < 10) ? "0" : "") + vNumber 
  } 

//---------------------------------------------------------------------------------------//
  function formatDate(vDate, vFormat){
//---------------------------------------------------------------------------------------//
    var vDay              = addZero(vDate.getDate()); 
    var vMonth            = addZero(vDate.getMonth()+1); 
    var vYearLong         = addZero(vDate.getFullYear()); 
    var vYearShort        = addZero(vDate.getFullYear().toString().substring(3,4)); 
    var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
    var vHour             = addZero(vDate.getHours()); 
    var vMinute           = addZero(vDate.getMinutes()); 
    var vSecond           = addZero(vDate.getSeconds()); 
    var vDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
    vDateString           = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 
    return vDateString 
  } 

//---------------------------------------------------------------------------------------//
function calculaEdadOtro(fecha,idControlx){	
//---------------------------------------------------------------------------------------//
	//fecha actual 
	var hoy = new Date(); 
    //alert('hoy'+hoy) ;	
	var mes = parseInt(hoy.getMonth());//0 es enero y 11 es diciembre
	var dia = parseInt(hoy.getDate());
	var anio = parseInt(hoy.getFullYear());
	var edad = 0;
	mes = mes+1;
	
	if (fecha=='00/00/0000' || fecha=='0000-00-00' || fecha==''){
		//document.getElementById(idControlx).value = 0;	
		return false;
	}

    //la fecha que recibo la descompongo en un array 
    var array_fecha = fecha.split("/");
    //si el array no tiene tres partes, la fecha es incorrecta 
    if (array_fecha.length!=3){ 
       return false; 
	}
    //compruebo que los anios, mes, dia son correctos 
    var anionaz; 
    anionaz = parseInt(array_fecha[2],10); 
    if (isNaN(anionaz)){ 
       return false; }
    var mesnaz; 
    mesnaz = parseInt(array_fecha[1],10);
	
    if (isNaN(mesnaz)){ 		
       return false }
    var dianaz; 
    dianaz = parseInt(array_fecha[0],10); 
    if (isNaN(dianaz)){ 
       return false; }
	
	//si el mes es el mismo pero el dia inferior aun no ha cumplido años, le quitaremos un año al actual
	if ((mesnaz == mes) && (dianaz > dia)) { 
	anio=(anio-1); } 
	//si el mes es superior al actual tampoco habra cumplido años, por eso le quitamos un año al actual
	//alert('mesnaz = '+mesnaz+' mes = '+mes)
	if (mesnaz > mes) { 
	anio=(anio-1);} 	
	//ya no habria mas condiciones, ahora simplemente restamos los años y mostramos el resultado como su edad
	
	edad=(anio-anionaz); 
	if(edad < 0){ edad = 0; }
	//alert(edad);
	return edad; 
	//document.getElementById(idControlx).value = edad;
}

//---------------------------------------------------------------------------------------//
function setFondo(idTabla,op,numTabs){
//---------------------------------------------------------------------------------------//
	var tbl = document.getElementById(idTabla);
    var lastRow = tbl.rows.length;
	//alert(tbl.rows[0].childNodes.length);//return false;
	if(!numTabs){ numTabs=tbl.rows[0].childNodes.length; }
	for(i=0;i<numTabs;i++){
		tbl.rows[0].childNodes[i].background = "../../INMOWEB-PHP/images/index/fondotdindex.png";
		tbl.rows[0].childNodes[i].style.color = "#FFFFFF";
		if(op==(i+1)){
			tbl.rows[0].childNodes[i].background = "../../INMOWEB-PHP/images/forms/fondo_menusupe.jpg";			
			tbl.rows[0].childNodes[i].style.color = "#000000";
		}
	}
}

//---------------------------------------------------------------------------------------//
function setFondo2(idTabla,idTab,numTabs){
//---------------------------------------------------------------------------------------//
	var tbl = document.getElementById(idTabla);
    var lastRow = tbl.rows.length;
	//alert(tbl.rows[0].childNodes.length);//return false;
	if(!numTabs){ numTabs=tbl.rows[0].childNodes.length; }
	for(i=0;i<numTabs;i++){
		tbl.rows[0].childNodes[i].className = "mantMenu";			
	}
	document.getElementById(idTab).className = "mantMenu2";
}

//---------------------------------------------------------------------------------------//
function setFondoFila(idTabla,ind){
//---------------------------------------------------------------------------------------//	
	var tbl = document.getElementById(idTabla);	
	var color = "";
	color = "#FFFFFF";
	//bgcolor="#CC9999"	
	var indice = parseInt(ind);
	//alert(indice);
	
	if(tbl){
		if(tbl.rows){
    		var Rows = tbl.rows.length;	
		}
	}
	
	//tbl.rows[indice].style.backgroundColor = "#CC9999";

	for(i=0;i<Rows;i++){
		if(i != indice){
			if(document.getElementById('rowSolicitud'+i)){
				document.getElementById('rowSolicitud'+i).style.backgroundColor = "#FFFFFF";
			}
		}else{
			if(document.getElementById('rowSolicitud'+i)){
				document.getElementById('rowSolicitud'+i).style.backgroundColor = "#CC9999";
			}
		}
	}//end for

}

//---------------------------------------------------------------------------------------//
function verificarCambios(tipo){
//---------------------------------------------------------------------------------------//
	if(document.getElementById('hid_estadoGrabar')){
		if(document.getElementById('hid_estadoGrabar').value == "S"){
			if(window.confirm('Desea guardar los cambios?')){
				document.getElementById('hid_estadoGrabar').value = 'N';
				document.getElementById('lnkGrabar').click();
				return false;
			}
		}
	}	
	frm.hid_estadoGrabar.value = 'N';	
}

//---------------------------------------------------------------------------------------//
function obtenerTextoCombo(combo,destino){
//---------------------------------------------------------------------------------------//	
	var selec = document.getElementById(combo).options; 
	var indice = document.getElementById(combo).selectedIndex;
	if (document.getElementById(combo).value != "0"){
		document.getElementById(destino).value = selec[indice].text;
	}
}//end function

//---------------------------------------------------------------------------------------//
function setValorTexto(valor,destino){
//---------------------------------------------------------------------------------------//	
	if(document.getElementById(destino)){
		document.getElementById(destino).value = valor;
	}
	return true;
}//end function

//---------------------------------------------------------------------------------------//
function currencyFormat(fld, milSep, decSep, e) {
//---------------------------------------------------------------------------------------//
	var sep = 0; 
	var key = ''; 
	var i = j = 0; 
	var len = len2 = 0; 
	var strCheck = '0123456789'; 
	var aux = aux2 = ''; 
	var whichCode = (window.Event) ? e.which : e.keyCode; 
	if (whichCode == 13) return true; // Enter 
	key = String.fromCharCode(whichCode); // Get key value from key code 
	if (strCheck.indexOf(key) == -1) return false; // Not a valid key 
	len = fld.value.length; 
	for(i = 0; i < len; i++) 
	 if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; 
	aux = ''; 
	for(; i < len; i++) 
	 if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); 
	aux += key; 
	len = aux.length; 
	if (len == 0) fld.value = ''; 
	if (len == 1) fld.value = '0'+ decSep + '0' + aux; 
	if (len == 2) fld.value = '0'+ decSep + aux; 
	if (len > 2) { 
	 aux2 = ''; 
	 for (j = 0, i = len - 3; i >= 0; i--) { 
	  if (j == 3) { 
	   aux2 += milSep; 
	   j = 0; 
	  } 
	  aux2 += aux.charAt(i); 
	  j++; 
	 } 
	 fld.value = ''; 
	 len2 = aux2.length; 
	 for (i = len2 - 1; i >= 0; i--) 
	  fld.value += aux2.charAt(i); 
	 fld.value += decSep + aux.substr(len - 2, len); 
	} 
	return false; 
} //end function
//<input type="text" name="test" length="15" onKeyPress="return(currencyFormat(this,',','.',event))">

//---------------------------------------------------------------------------------------//
function formatNmb(nNmb){ 
//---------------------------------------------------------------------------------------//
	var sRes = ""; 
	for (var j, i = nNmb.length - 1, j = 0; i >= 0; i--, j++) 
	 sRes = nNmb.charAt(i) + ((j > 0) && (j % 3 == 0)? ".": "") + sRes; 
	return sRes; 
} //end function	

//---------------------------------------------------------------------------------------//
function SimularPopUpModal(){
//---------------------------------------------------------------------------------------//
	//alert(self.focus);
	if (window.opener && window.opener.focus){ 
		window.opener.focus = false; 
		self.focus(); 
	} 
} 

//---------------------------------------------------------------------------------------//
function disabledForm2(flag){
//---------------------------------------------------------------------------------------//	
	var tabName = '';
	if(document.getElementById('hid_tab')){
		tabName = document.getElementById('hid_tab').value;
	}
	if(tabName=='seguimiento' || tabName == 'condiciones'){
		disabledForm(false);
		/*document.getElementById('txt_referencia').readOnly = true;
		document.getElementById('cmb_tipoInmueble').disabled = true;
		document.getElementById('cmb_operacion').disabled = true;
		document.getElementById('txt_precio').readOnly = true;
		document.getElementById('btn_calculadora').disabled = true;
		document.getElementById('cmb_estOperacion').disabled = true;*/
		document.getElementById('btn_alquiler').disabled = true;
		document.getElementById('hid_accion').value = 'updG';
		return;
	}
	for (i=0;i < document.frm.elements.length; i++) { 	  	
		if ( document.frm.elements[i].name.substring(0,3)!= "hid" ) {
			document.frm.elements[i].disabled = false;
			document.frm.elements[i].tabIndex = -1;						
			if (document.frm.elements[i].name.substring(0,3)== "txt"){
				document.frm.elements[i].readOnly = true;
			}else{			
				//document.frm.elements[i].disabled = true;
			}			
			//alert(document.frm.elements[i].tabIndex);
		}
	}// end for
	document.getElementById('btn_alquiler').disabled = true;
}// end function disabledForm2

//---------------------------------------------------------------------------------------//
function compararFechas(Obj1,Obj2){//devuelve true si son iguales
//---------------------------------------------------------------------------------------//
	var retorno = true;
	
	var fecha = Obj1.value;
	var fecha2 = Obj2.value;
	//las fechas que recibo la descompongo en un array 
	var array_fecha = fecha.split("-");
	var array_fecha2 = fecha2.split("-");
	//si el array no tiene tres partes, la fecha es incorrecta 
	if (array_fecha.length!=3){ 
		return false; 
	}
	if (array_fecha2.length!=3){ 
		return false; 
	}
	//compruebo que los anios, mes, dia son correctos 
	var anio; 
	anio = parseInt(array_fecha[0],10); 
	if (isNaN(anio)){ 
		return false; }
	var anio2; 
	anio2 = parseInt(array_fecha2[0],10); 
	if (isNaN(anio2)){ 
		return false; }
		
	var mes; 
	mes = parseInt(array_fecha[1],10); 
	if (isNaN(mes)){ 
		return false }
	var mes2; 
	mes2 = parseInt(array_fecha2[1],10); 
	if (isNaN(mes2)){ 
		return false }
		
	var dia; 
	dia = parseInt(array_fecha[2],10); 
	if (isNaN(dia)){ 
		return false; }
	var dia2; 
	dia2 = parseInt(array_fecha2[2],10); 
	if (isNaN(dia2)){ 
		return false; }

	if (anio>anio2){ 
		retorno = false;
	}

	if ((anio==anio2) && (mes>mes2)){
		retorno = false;
	}
	if ((anio==anio2) && (mes==mes2) && (dia>dia2)){
		retorno = false;
	}
	if(retorno == false){
		return false;
	}
	return true;
}//end function compararFechas

//---------------------------------------------------------------------------------------//
function compararFechas2(Obj1,Obj2){//devuelve 0 si son iguales -1 si la fecha1 es mayor y 1 si la fecha2 es mayor
//---------------------------------------------------------------------------------------//
	var retorno = true;
	
	var fecha = Obj1.value;
	var fecha2 = Obj2.value;
	//las fechas que recibo la descompongo en un array 
	var array_fecha = fecha.split("-");
	var array_fecha2 = fecha2.split("-");
	//si el array no tiene tres partes, la fecha es incorrecta 
	if (array_fecha.length!=3){ 
		return false; 
	}
	if (array_fecha2.length!=3){ 
		return false; 
	}
	//compruebo que los anios, mes, dia son correctos 
	var anio; 
	anio = parseInt(array_fecha[0],10); 
	if (isNaN(anio)){ 
		return false; }
	var anio2; 
	anio2 = parseInt(array_fecha2[0],10); 
	if (isNaN(anio2)){ 
		return false; }
		
	var mes; 
	mes = parseInt(array_fecha[1],10); 
	if (isNaN(mes)){ 
		return false }
	var mes2; 
	mes2 = parseInt(array_fecha2[1],10); 
	if (isNaN(mes2)){ 
		return false }
		
	var dia; 
	dia = parseInt(array_fecha[2],10); 
	if (isNaN(dia)){ 
		return false; }
	var dia2; 
	dia2 = parseInt(array_fecha2[2],10); 
	if (isNaN(dia2)){ 
		return false; }

	if (anio > anio2){ 
		retorno = -1;
	}
	if (anio2 > anio){ 
		retorno = 1;
	}

	if (anio == anio2){
		retorno = 0;
		if(mes > mes2){
			retorno = -1;
		}
		if(mes2 > mes){
			retorno = 1;
		}
		if(mes == mes2){
			retorno = 0;
			if(dia > dia2){
				retorno = -1;
			}
			if(dia2 > dia){
				retorno = 1;
			}
			if(dia == dia2){
				retorno = 0;
			}
		}//end if mes == mes2		
	}//end if anio == anio2
	return retorno;
}//end function compararFechas2

//---------------------------------------------------------------------------------------//
function previewImage(pathField, previewName){
//---------------------------------------------------------------------------------------//
	var imgRe = /^.+\.(jpg|jpeg)$/i;
    var path = pathField.value;
	
    if (path.search(imgRe) != -1){   
        //document[previewName].src = 'file://'+path;
		if(document.getElementById(previewName)){
			document.getElementById(previewName).src = 'file://'+path;
			document.getElementById(previewName).style.display = 'inline';
		}
    }else{   
        alert("Solo archivos JPG!");
		return false;
    }   
}//end function previewImage

//---------------------------------------------------------------------------------------//
function valorMinMax(obj,minimo,maximo){
//---------------------------------------------------------------------------------------//
	if(obj.value < minimo){
		alert('Valor no permitido');
			obj.value = "";
			obj.focus();
			return false;
	}else{
		if(obj.value > maximo){
			alert('Valor no permitido');
			obj.value = "";
			obj.focus();
			return false;
		}
	}
	return true;
}

//---------------------------------------------------------------------------------------//
function clearControles(destinos){
//---------------------------------------------------------------------------------------//
	var aux_destinos = new Array();	
	var elementosform = new Array();
	/*-- Establecer los elementos de destino --*/
	aux_destinos = destinos.split(';');
	for(i=0;i<aux_destinos.length;i++){
		elementosform[i] = document.getElementById(aux_destinos[i]);
	}		
	/*-- Limpiar elementos de destino --*/
	for(i=0;i<elementosform.length;i++){
		if(elementosform[i]){ 
			elementosform[i].value = "";			
		}
	}//enf for contenido	
}

//---------------------------------------------------------------------------------------//
function verCriterio(cajacheck,destino){
//---------------------------------------------------------------------------------------//	
	if(cajacheck.checked == true){
		visualizar = 'inline';	
	}else{
		visualizar = 'none';
	}
	
	document.getElementById(destino).style.display = visualizar;
}

//---------------------------------------------------------------------------------------//
function checkearDatoContacto(frm_check,frm_hid){
//---------------------------------------------------------------------------------------//
		var estado = document.getElementById(frm_hid).value;
		switch(estado){
				case 'con':
					document.getElementById(frm_hid).value = "ins";
				break;
				case 'ins':
					document.getElementById(frm_hid).value = "con";
				break;
				case 'del':
					document.getElementById(frm_hid).value = "upd";
				break;
				case 'upd':
					document.getElementById(frm_hid).value = "del";
				break;
		}//end switch
	}// end function checkearDatoContacto

//---------------------------------------------------------------------------------------//
function cambiarEstDisabled (destinos,estado) {
//---------------------------------------------------------------------------------------//		
		var aux_destinos = new Array();
		var elementosform = new Array();
		
		/*-- Establecer los elementos de destino --*/		
		aux_destinos = destinos.split(';');
		
		elementosform.length = 0;//restablecer la variable
		
		for(i=0;i<aux_destinos.length;i++){			
			elementosform[i] = $(aux_destinos[i]);
		}		
		/*-- Cambiar estado disabled en elementos de destino --*/
		for(i=0;i<elementosform.length;i++){
			if(elementosform[i]){
				elementosform[i].disabled = estado;
			}
		}//enf for contenido		
		
	}//end cambiarEstDisabled

//---------------------------------------------------------------------------------------//
function getRadioValue(idOrName) {
//---------------------------------------------------------------------------------------//
        var value = null;
        var element = $(idOrName);
        var radioGroupName = null;  
        
        // if null, then the id must be the radio group name
        if (element == null) {
                radioGroupName = idOrName;
        } else {
                radioGroupName = element.name;     
        }
        if (radioGroupName == null) {
                return null;
        }
        //var radios = document.getElementsByTagName('input');
       // for (var i=0; i<radios.length; i++) {
		$$('body input').each( function(input){
                //var input = radios[ i ];    
                if (input.type == 'radio' && input.name == radioGroupName && input.checked) {                          
                        value = input.value;
                        throw $break;
                }
        });
        return value;
}

//---------------------------------------------------------------------------------------//
function checkNIFNIE(nif) { // funcion para validar la letra del nif o nie
//---------------------------------------------------------------------------------------//
	if (!nif) return false;

	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
	if (nif.length != 9) return false;
	else {
		letra = nif.substr(8, 1); letra = letra.toUpperCase();
		dni = nif.substr(0, 8);
		dni = dni.toUpperCase(); 
                dni = dni.replace('X','0');
                dni = dni.replace('Y','1');
		dni -= parseInt(dni/23) * 23;
		if (letras.charAt(dni) != letra) return false; 
		else return true;
	 }//end if
}//end function 

//---------------------------------------------------------------------------------------//
function letra_NIF(nif) {
//	residuo=dni%23; 
//	letra=("TRWAGMYFPDXBNJZSQVHLCKE").substr(residuo, 1);  
//	return letra;
	if (!nif) return false;

	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
	letra = nif.substr(8, 1); letra = letra.toUpperCase();
	dni = nif.substr(0, 8);
	dni = dni.toUpperCase(); 
        dni = dni.replace('X','0');
        dni = dni.replace('Y','1');
	dni -= parseInt(dni/23) * 23;
	return letras.charAt(dni); 
}
//---------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------
function setCalendario(idBoton,idTxt,fechaMin){
//---------------------------------------------------------------------------------------------------------------------------
	if(fechaMin>0){		
		Calendar.setup({
			trigger: idBoton,
			inputField: idTxt,			
			onSelect: function(){ this.hide(); },
			animation: false,
			align: 'bl',
			min: fechaMin,
			dateFormat: '%d/%m/%Y'
		});
	}else{
		
		Calendar.setup({
			trigger: idBoton,
			inputField: idTxt,
			
			onSelect: function(){ this.hide(); },
			animation: false,
			align: 'bl',
			dateFormat: '%d/%m/%Y'
		});
	}
}//end function

var seleccionados = 0;




//---------------------------------------------------------------------------------------------------------------------------
function resaltarSubTabs(){
//---------------------------------------------------------------------------------------------------------------------------
	var color_actual = '';
	/*$$('td.subtab').each(function(item) { 	
		var color_actual = item.getStyle('backgroundColor');
		
		item.observe('mouseover', function() {
			item.setStyle({ backgroundColor: '#F7F7F7' });
		});
		item.observe('mouseout', function() {
			item.setStyle({backgroundColor: color_actual });
		});
		item.observe('click', function() { 
			$$('td.subtab').each(function(item2) { 
				item2.setStyle({backgroundColor: color_actual});
			});
			item.setStyle({backgroundColor: '#E1E1E1' });
		});
	});*/
}//end function resaltar

//---Esta funcion es un estandar para recargar con ajax-----//
function recargar(elemento,pagina,formu){
//------------------------------------------------------------------------------------------------------------------//
 
	var element =  $(elemento);
	var parametros=$(formu).serialize();
	element.innerHTML = '<option value="" selected>Procesando...</option>'; 
	new Ajax.Updater(elemento, pagina, { method: 'post',  asynchronous: true,
		 			 parameters:parametros, encoding:'iso-8859-1', evalScripts: true });
}//end if