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; 
	if (whichCode == 0) return true; 
	key = String.fromCharCode(whichCode); // Get key value from key code
	if (strCheck.indexOf(key) == -1 && whichCode!=8) return false; // Not a valid key
	if (fld.value.length<14)
		len = fld.value.length;
	else
		len = 13;
	//alert(len);
	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 && whichCode!=8)
			aux += fld.value.charAt(i);
	if (whichCode!=8)
		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; 
	} 


function tecla(fld, e)
	{
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode==8)
		fld.value='';
	}
	
function trim(S)
{
var A = S;
var i;
var P1 = 1;
var P2 = A.length;
 
for (i=1; i <= A.length; i++)
{
  if (A.charAt(i) != ' ')
   {
    P1 = i;
    break;
   }
}
 
for (i = A.length; i >= 1; i--)
{
   if (A.charAt(i) != ' ')
   {
    P2 = i;
    break;
   }
}
 
A = A.substring(P1, P2);
 
return A;
}	
	
function valida_precio_inicial(precio,inicial)
	{
	var encabezado="Se ha encontrado los siguientes errores:\n\n";
	var errores="";
	
	if ((precio=="Precio")||((precio.length==0) && (precio!="Precio")))
		{
		errores=errores+"Debe escribir el precio del vehiculo\n";
		}
	if ((inicial=="Inicial")||((inicial.length==0) && (inicial!="Precio")))
		{
		errores=errores+"Debe escribir la inicial del vehiculo\n";
		}
	if (errores!="")
		alert(encabezado+errores+"\n");
	else
		{
		preciov_para_calcular = precio.replace(/[.]/g,'');
		inicial_para_calcular = inicial.replace(/[.]/g,'');
		if(parseFloat(preciov_para_calcular)<=parseFloat(inicial_para_calcular))
		alert("La inicial debe ser menor al precio del vehiculo");
		else
			{
			return true;
			//window.open('http://desanet/widget/paso_principal.php?precio='+precio+'&inicial='+inicial,'ventana', 'width=451,height=455,dependent=yes,screenX=0,screenY=0,titlebar=yes,directories=no,menubars=no,status=yes,scrollbars=yes,resizable=no');
			}
		}
	return false;
	}
	
function valida_precio_recalcular(precio,inicial)
	{
	var encabezado="Se ha encontrado los siguientes errores:\n\n";
	var errores="";
	if (precio=="")
		{
		errores=errores+"Debe escribir el precio del vehiculo\n";
		}
	if (inicial=="")
		{
		errores=errores+"Debe escribir la inicial del vehiculo\n";
		}
	if (errores!="")
		alert(encabezado+errores+"\n");
	else
		{
		preciov_para_calcular = precio.replace(/[.]/g,'');
		inicial_para_calcular = inicial.replace(/[.]/g,'');
		if(parseFloat(preciov_para_calcular)<=parseFloat(inicial_para_calcular))
			{
			alert("La inicial debe ser menor al precio del vehiculo");
			
			}
		else
			{
			
			return true;
			
			}
		}
	return false;
	}	
	
function desactivaWidget()
	{
	var contenedor=parent.document.getElementById('contenedor');
	contenedor.style.display="none";
	var contenedor2=parent.document.getElementById('contenedor2');
	contenedor2.style.display="none";
	}
	
function pin()
	{
	var contenedor=document.getElementById('pin_widget');
	if (contenedor==null)
		return true
	else
		{
		if (contenedor.value=="")
			{
			alert("Debe escribir su clave de Acceso");
			return false;
			}
		else
			{
			document.getElementById('pin2').value=contenedor.value;
			return true;
			}
			
		}
	}

function paso2()
	{
	var valor1=document.getElementById('precio');
	var valor2=document.getElementById('inicial');
	var textos="";
	var radio=document.paso1.plazo;
	for (i=0; i<radio.length; i++) 
		{
		if (radio[i].checked) { textos=radio[i].value; }
		}
	document.forms["paso1"].submit();
	//document.location.href="paso_principal.php?opcion=2&precio="+valor1.value+"&inicial="+valor2.value+"&plazo="+textos;
	}
	

function validarEmail(valor) 
	{
	if (/^[0-9a-z_\-\.]+@[0-9a-z\-\.]+\.[a-z]{2,4}$/i.test(valor))
		{
		return 1;
		} 
	else 
		{
		return 0;
		}
	}
	
function paso3()
	{
	
	var encabezado="Se ha encontrado los siguientes errores:\n\n";
	var errores="";
	var valor1=document.getElementById('nombre');
	var valor2=document.getElementById('cedula');
	var valor3=document.getElementById('datepicker_widget');
	var valor8=document.getElementById('codigo_tel');
	var valor4=document.getElementById('telefono');
	var valor5=document.getElementById('antiguedad');
	var valor9=document.getElementById('estados');
	var valor6=document.getElementById('ingresos');
	var valor10=document.getElementById('profesion');
	var valor7=document.getElementById('email');
	var valor11=document.getElementById('reemail');
	
	if (valor1.value=="Nombre y Apellido")
		{
		errores=errores+"Debe ingresar su nombre\n";
		}
	if (isNaN(valor2.value))
		{
		errores=errores+"Debe ingresar su Cedula\n";
		}
	if (valor3.value=="Fecha de Nacimiento")
		{
		errores=errores+"Debe ingresar su Fecha de Nacimiento\n";
		}
	if (valor8.value=="COD")
		{
		errores=errores+"Debe ingresar el codigo de area del Telefono\n";
		}
	if (isNaN(valor4.value))
		{
		errores=errores+"Debe ingresar su Telefono\n";
		}
	if (isNaN(valor5.value))
		{
		errores=errores+"Debe ingresar los a\xF1os de Antiguedad\n";
		}
	if (valor9.value=="")
		{
		errores=errores+"Debe seleccionar ciudad de residencia\n";
		}
	if (valor6.value=="Ingresos Netos")
		{
		errores=errores+"Debe ingresar sus Ingresos Netos\n";
		}
	if (valor10.value=="")
		{
		errores=errores+"Debe seleccionar su Ocupacion\n";
		}
	if (!validarEmail(valor7.value))
		errores=errores+"Debe ingresar una direccion de email valida\n";
	if (valor7.value!=valor11.value)
		{
		errores=errores+"La direccion de E-mail no coinciden\n";
		}	
	if (errores!="")
		{
		alert(encabezado+errores+"\n");
		return 0;
		}
	else
		return 1;
	}
	
function abrir_ventana2(name,ancho,alto){
	window.name="Tope";
	window.open(name, "ventana", "width="+ancho+",height="+alto+",dependent=yes,screenX=0,screenY=0,titlebar=no,directories=no,menubars=no,status=no,scrollbars=yes,resizable=no"); 
}

function mayuscula(id)
	{
	var imput= document.getElementById(id);
	imput.value=imput.value.toUpperCase();
	}
	
function solo_numeros(e)
	{
	var key=(document.all) ? e.keyCode : e.which; 
	if (key==8) return true;
	if (key==0) return true;
	if (key < 48 || key > 57)
		{
		return false;
		}
	}
	
function valida_ingresos(valor)
{
	//alert(valor);
	var tipo=document.getElementById("valida_ing");
	
	if (tipo.value=="0")
		{
		$('#ingresos').autoNumeric({aSep:'.',aDec: ','})
		tipo.value="1";
		}
	
	
}
