//--------------------------------------------------------------------
// Funciones y Constantes Utilizadas para Remax City
//
// (c) 1999 Vilulfo Gaspar
//
// Codigo JavaScript
//
//--------------------------------------------------------------------

//---------------------------------------------------------
//---- Funcion validaKeyCode: Valida caracter generado por el evento event.KeyCode
//---- Entradas:  pKeyCode - caracter en ASCII, pTipoValidacion - Tipo de Validacion
//---- Salida:    true si el caracter no es valido
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function validaKeyCode(pKeyCode,pTipoValidacion) {
	switch (pTipoValidacion){
		case 0:
			// Solo Digitos y letras, sin espacio
			if ( !(((event.keyCode >= 48) && (event.keyCode <= 57))  
				|| ((event.keyCode >= 65) && (event.keyCode <= 90))
				|| ((event.keyCode >= 97) && (event.keyCode <= 122)))
				|| event.keyCode == 39 ) return true;
			break;
		case 1:
			// Solo Digitos
			if ( !((event.keyCode >= 48) && (event.keyCode <= 57))) 
			return true;
			break;
		case 2: 
			// Solo Digitos y punto decimal
			if ( !((event.keyCode >= 48) && (event.keyCode <= 57))
				&& event.keyCode != 46 ) return true;
			break;
		case 3:
			// Solo Digitos y punto decimal y signo -
			if ( !((event.keyCode >= 48) && (event.keyCode <= 57))
				&& event.keyCode != 46 && event.keyCode != 45 ) return true;
			break;
		case 4:
			// Solo Digitos y letras, con espacio, sin enter, eņes, coma
			if ( !(((event.keyCode >= 40) && (event.keyCode <= 90))  
				|| ((event.keyCode >= 92) && (event.keyCode <= 95))
				|| ((event.keyCode >= 97) && (event.keyCode <= 125))
				|| (event.keyCode == 32) 
				|| (event.keyCode == 209) || (event.keyCode == 241) )
				|| event.keyCode == 39 ) return true;
			break;
		case 5:
			// Solo Digitos y letras, con espacio, enter, eņes, coma, acento, comillas
			if ( !(((event.keyCode >= 40) && (event.keyCode <= 90))  
				|| ((event.keyCode >= 92) && (event.keyCode <= 95))
				|| ((event.keyCode >= 97) && (event.keyCode <= 125))
				|| (event.keyCode == 32) || (event.keyCode == 225) 
				|| (event.keyCode == 13) 
				|| (event.keyCode == 233) || (event.keyCode == 237) 
				|| (event.keyCode == 243) || (event.keyCode == 250) 
				|| (event.keyCode == 209) || (event.keyCode == 241) 
				|| (event.keyCode == 34) || (event.keyCode == 39) )
				 ) return true;
			break;
		case 6:
			// Solo Digitos y letras, subguion, guion, punto; para usarse en mail
			if ( !(((event.keyCode >= 48) && (event.keyCode <= 57))  
				|| ((event.keyCode >= 64) && (event.keyCode <= 90))
				|| ((event.keyCode >= 97) && (event.keyCode <= 122))
				|| (event.keyCode == 45) || (event.keyCode == 46) 
				|| (event.keyCode == 95) )
				 ) return true;
			break;
		default: break;
	}
//|| (event.keyCode == 13)
}

//---------------------------------------------------------
//---- Funcion validapresiona: Valida el avance del focus al siguiente campo
//---- Entradas:  pinKeyCode - Tab, FDown, FUp, Enter
//---- 		  fcampo - campo a de movimiento, fthis campo actual
//---- Salida:    aplica focus en caso de pinKeyCode valido
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function validapresiona(pinKeyCode,fcampo,fthis) {
	
	var muevecursor = 0;
	switch (pinKeyCode){
		case 9:	
			//Tabulador
			muevecursor = 0;
			// Nada
			break;
		case 40: 	
			//Flecha abajo
			muevecursor = 1;
			break;
		case 13: 
			// Enter
			muevecursor = 1;
			break;
		case 38:
			// Flecha arriba
			muevecursor = -1;
			break;
		default:
			muevecursor = 0;
			// Nada
			break;
	}

	if(typeof(fcampo.length)!='undefined')
		if (muevecursor>0) {
			if(fthis.tabIndex<fcampo.length-1) {
				if (fcampo(fthis.tabIndex+muevecursor).type == 'text') 
					fcampo(fthis.tabIndex+muevecursor).focus() }
			else {if (fcampo(0).type == 'text') 
				fcampo(0).focus()}
		} else {	
		if (muevecursor<0) {
			if(fthis.tabIndex==0) {
				if (fcampo(fcampo.length-1).type == 'text')
					fcampo(fcampo.length-1).focus() }
			else {if (fcampo(fthis.tabIndex+muevecursor).type == 'text')
				fcampo(fthis.tabIndex+muevecursor).focus();}
			}
		}


}


//---------------------------------------------------------
//---- Funcion isEmpty: Valida si una cadena esta vacia
//---- Entradas:  str - cadena a validar
//---- Salida:    true si la cadena esta vacia, false si no esta vacia
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function isEmpty(str) {
	// Check whether string is empty.	
	for (var intLoop = 0; intLoop < str.length; intLoop++)
		if (" " != str.charAt(intLoop))
         	return false;
         return true;
}

//---------------------------------------------------------
//---- Funcion checkRequired: Valida campos requeridos de un formulario
//---- Entradas:  f - formulario
//---- Salida:    true si un campo esta vacio
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function checkRequired(f) {
	var strError = true;
			
        for (var intLoop = 0; intLoop<f.elements.length; intLoop++)
        	if (null!=f.elements[intLoop].getAttribute("required")) 
                	if (!isEmpty(f.elements[intLoop].value))
                     		strError = false;
            		if (strError) {
               			return false;
            		}
}

//---------------------------------------------------------
//---- Funcion doSection: display
//---- Entradas:  secNum - seccion
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function doSection(secNum){
	if (secNum.style.display=="none")
			{secNum.style.display=""}
		else{secNum.style.display="none"}
}


//---------------------------------------------------------
//---- Funcion newpartentPage: link partent
//---- Entradas:  page - Pagina
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function newpartentPage(page){
	parent.presenta.location=page;
}

//---------------------------------------------------------
//---- Funcion newPage: link top
//---- Entradas:  page - Pagina
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function newtopPage(page){
	top.location=page;
}

//---------------------------------------------------------
//---- Funcion newblankPage: Link Padron de Entidades
//---- Entradas:  page - Link
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function newblankPage(page){
	blank.location=page;
}


//---------------------------------------------------------
//---- Funcion pathArchivo: Separa un archivo en path o archivo
//---- Entradas:  inPathArchivo - Archivo con su ruta
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function pathArchivo(inPathArchivo,pMetodo){
	var retpathArchivo;
	switch (pMetodo){
		case "path":
			return inPathArchivo.substr(0,inPathArchivo.lastIndexOf("\\"));
			break ;
		case "file":
			return inPathArchivo.substr(inPathArchivo.lastIndexOf("\\")+1);
			break ;
	};
}


//---------------------------------------------------------
//---- Funcion sinEspacios: valida un string sin espacios
//---- Entradas:  sinEspacios - true sin espacios
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function sinEspacios(inpsinEspacios){

	if(inpsinEspacios.indexOf(" ")==-1) { return true; }
	else { return false; };
}


//---------------------------------------------------------
//---- Funcion quitaCaracter: quita caracteres
//---- Entradas:  str - cadena a validar
//---- Salida:    string sin caracter
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function quitaCaracter(str,caracter) {
	var strReturn = "";
	for (var intLoop = 0; intLoop < str.length; intLoop++)
		if (caracter != str.charAt(intLoop))
			strReturn = strReturn + str.charAt(intLoop);
	return strReturn;
}


//---------------------------------------------------------
//---- Funcion formatNumber: formato a decimales
//---- Entradas:  str - cadena a convertir
//---- Salida:    string cadena
//---- Viliulfo Gaspar, diciembre 1999
//---------------------------------------------------------
function formatNumber(str,numdecimales) {
	tmpsplit = str.split(".")
	if(tmpsplit.length>1) 
		return tmpsplit[0]+"."+tmpsplit[1].substr(0,2) 
	else return tmpsplit[0]+".00";

}


