// JavaScript Document
function valMail(parTexto)
{	var Template = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; //Formato de direccion de correo electronico
	var Clase=parTexto.className;
	if(parTexto.value!="") 
	{	if (Template.test(parTexto.value)) 
		{	document.getElementById('msj'+parTexto.name).innerHTML=''; 
		}
		else
		{
			document.getElementById('msj'+parTexto.name).innerHTML='<br /><div class="onlineAlert1"><span>Formato incorrecto</span></div>';
			parTexto.value='';
			parTexto.focus();
			parTexto.select();
		}		
	}
	return false;
}
function valNumeros(parNumero)
{	var Template = /^[0-9]+$/i //Formato de alfanumerico	
	if(parNumero.value!="") 
	{	if (Template.test(parNumero.value)) 
		{	document.getElementById('msj'+parNumero.name).innerHTML=''; 
		}
		else
		{
			document.getElementById('msj'+parNumero.name).innerHTML='<br /><div class="onlineAlert1"><span style="color=#ffffff;">Formato incorrecto</span></div>';
			parNumero.value='';
			parNumero.focus();
			parNumero.select();
		}	
	}
	return false;
}
function valRUC(parNumero)
{	var Template = /^[0-9]+$/i //Formato de alfanumerico	
	if(parNumero.value!="") 
	{	if (Template.test(parNumero.value)&&parNumero.value.length==11) 
		{	document.getElementById('msj'+parNumero.name).innerHTML=''; 
		}
		else
		{
			document.getElementById('msj'+parNumero.name).innerHTML='<br /><div class="onlineAlert1"><span style="color=#ffffff;">RUC incorrecto</span></div>';
			parNumero.value='';
			parNumero.focus();
			parNumero.select();
		}	
	}
	return false;
}
function valUrl(parTexto)
{	var Template =/^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)( [a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$/; 
					
	var Clase=parTexto.className;
	if(parTexto.value!="") 
	{	if (Template.test(parTexto.value)) 
		{	document.getElementById('msj'+parTexto.name).innerHTML=''; 
		}
		else
		{
			document.getElementById('msj'+parTexto.name).innerHTML='<div class="onlineAlert1"><span>Formato incorrecto</span></div>';
			parTexto.value='';
			parTexto.focus();
			parTexto.select();
		}		
	}
	return false;
}
function valCorreo(YourMail)
{	var Template = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; //Formato de direccion de correo electronico
	if(YourMail.value!="") 
	{
		if (Template.test(YourMail.value)) 
		{							}
		else
		{   alert("Email incorrecto. Por favor vuelva a intentarlo");
			YourMail.focus();
			YourMail.select();
		}		
	}
	return false;
}

function linkear(parEnlace)
{	document.location.href=parEnlace;
}

function linkeate(dat)
{	alert(dat);
	switch (dat) { 
		case "1": 
			///alert(dat);
			// document.getElementById('FichaAgregarPrincipal').className = "layout Paso1";
			document.getElementById('formulario_1').style.display = "inline";
			document.getElementById('formulario_2').style.display = "none";
			//document.getElementById('formulario_3').style.display = "none";
			break;
		case "2": 
			//document.getElementById('FichaAgregarPrincipal').className = "layout Paso2";
			document.getElementById('formulario_1').style.display = "none";
			document.getElementById('formulario_2').style.display = "inline";
			// document.getElementById('formulario_3').style.display = "none";
			break;
		case "3": 
			if(ValidaForm_1() && ValidaForm_2())
			{	//document.getElementById('FichaAgregarPrincipal').className = "layout Paso3";
				document.getElementById('formulario_1').style.display = "none";
				document.getElementById('formulario_2').style.display = "none";
				//document.getElementById('formulario_3').style.display = "inline";
			}
		   	break;
	} 
}

		
		
		
/*
function IsPhone(YourPhone)
{
	var Template = /^[0-9- ]+$/i //Formato de alfanumerico
	
	if(YourPhone.value!="") 
	{
		if (Template.test(YourPhone.value)) 
		{							}
		else
		{   alert("El Tel�fono que ha Ingresado tiene Caracteres Inv�lidos");
			YourPhone.focus();
			YourPhone.select();
		}		
	}
	return false;
}

function IsPassword(pass)
{	var Template = /^[0-9a-zA-Z]+$/i //Formato de alfanumerico
	
	if(pass.value!="") 
	{
		if (Template.test(pass.value)) 
		{							}
		else
		{   alert("Contrase�a err�nea, vuelvalo a intentar");
			pass.focus();
			pass.select();
		}		
	}
	return false;
}

function IsTexto(texto)
{
	var Template = /^[a-zA-Z������������, ]+$/i //Formato de alfanumerico
		if(texto.value!="") 
	{
		if (Template.test(texto.value)) 
		{							}
		else
		{   alert("Solo puede ingresar texto");
			texto.focus();
			texto.select();
		}		
	}		
	return false;
}

function IsTexto1(texto)
{
	var Template = /^[a-zA-Z������������, ]+$/i //Formato de alfanumerico
		if(texto.value!="") 
	{
		if (Template.test(texto.value)) 
		{							}
		else
		{   alert("Solo puede ingresar texto");
			texto.focus();
			texto.select();
		}		
	}		
	return false;
}

function IsDay(day)
{
	if(day.value!="") 
	{
	if ( (isNaN(day.value)) || (day.value<1) || (day.value >31) )
		{
			alert("No es un Dia V�lido");
			day.focus();
			day.select();			
		}
	}
	
	return false;	
}

function IsMonth(month)
{
	if(month.value!="") 
	{
	if ( (isNaN(month.value)) || (month.value<1) || (month.value >12) )
		{
			alert("No es un Mes V�lido");
			month.focus();
			month.select();
		}
	}	
	return false;	
}

function IsYear(year)
{
	if(year.value!="") 
	{
	if ( (isNaN(year.value)) || (year.value<1990) || (year.value >2020) )
		{
			alert("No es un a�o V�lido. A�o m�nimo 1990");
			year.focus();
			year.select();
		}		
	}	
	return false;	
}

function IsYearNac(year)
{
	if(year.value!="") 
	{
	if ( (isNaN(year.value)) || (year.value<1910) || (year.value >1990) )
		{
			alert("No es un a�o V�lido.");
			year.focus();
			year.select();
		}		
	}	
	return false;	
}


function roundOff(value, precision,fieldName)
{
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = 0;
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
		fieldName.value=result;
        //return result;
}

function checkDecimals(fieldName, fieldValue) 
{	decallowed = 2;  // how many decimals are allowed?
	if (isNaN(fieldValue)) 
	{	alert("Ingresa solo n�meros y/o decimales");
		fieldName.select();
		fieldName.focus();
	}
	else 
	{	if (fieldValue.indexOf('.') == -1) fieldValue += ".";
			dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
		if (dectext.length > decallowed)
		{	roundOff(fieldValue, decallowed,fieldName)
			//alert ("OJO!! Introduce un numero con " + decallowed + " decimales.  Intentalo de nuevo.");
			//fieldName.select();
			//fieldName.focus();
		}
	}
}

function validarPasswd(pass) 
{	var espacios = true;
 	var cont = 0;
	
	// Este bucle recorre la cadena para comprobar que no todo son espacios
	while (espacios && (cont < pass.length)) 
	{  	if (pass.charAt(cont) != " ") 
		{	alert ("La contrase�a no puede ser todo espacios en blanco");
			pass.focus();
			pass.select();
    	}
	    cont++;
	}
}

function anyoBisiesto(anyo)
{	if (anyo < 100)
		var fin = anyo + 1900;
	else
		var fin = anyo ;

	if (fin % 4 != 0)
		return false;
	else
	{	if (fin % 100 == 0)
		{	if (fin % 400 == 0)
				return true;
			else
				return false;
		}
		else
		{	return true;	}
	}
}

function validaFloat(value){
	return(value.match(/^[0-9]+(.[0-9]+)?$/))
}

function validaInputFloat(oInput){
	if(oInput.value!="") 
	{	if (!validaFloat(oInput.value) )	
		{
			alert(oInput.value + " no es una cantidad v�lida");
			try
			{	oInput.value='';
				oInput.focus();
				oInput.select();				
			}catch(ex){
			   //me "como" la excepci�n porque se producir� 
				//en caso de que al control no se le pueda
				//pasar el foco
			}
			return(false);
		}
		return(true);
	}
}

function validaInputFloatEsp(oInput){
	if(oInput.value!="") 
	{	if (!validaFloat(oInput.value) )	
		{	alert(oInput.value + " no es una cantidad v�lida");
			try
			{	oInput.value='';
				oInput.focus();
				oInput.select();				
			}catch(ex){
			   //me "como" la excepci�n porque se producir� 
				//en caso de que al control no se le pueda
				//pasar el foco
			}
			return(false);
		}
		//obtMantenimiento(oInput.value);
	}
}*/
