﻿var submitted = false;
function emailCheck (emailStr) {
/* Verificar si el email tiene el formato user@dominio. */
var emailPat=/^(.+)@(.+)$/ 
/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" 
/* Verifica los caracteres que son válidos en una dirección de email */
var validChars="\[^\\s" + specialChars + "\]" 
var quotedUser="(\"[^\"]*\")" 
/* Verifica si la dirección de email está representada con una dirección IP Válida */ 
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* Verificar caracteres inválidos */ 
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
//alert("Email address seems incorrect (check @ and .'s)")
return false
}
var user=matchArray[1]
var domain=matchArray[2]
// Si el user "user" es valido 
if (user.match(userPat)==null) {
// Si no
//alert("El nombre de usuario no es válido.")
return false
}
/* Si la dirección IP es válida */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
//alert("IP de destino inválida")
return false
}
}
return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
//alert("El dominio parece no ser válido.")
return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
domArr[domArr.length-1].length>3) { 
//alert("La dicrección debe tener 3 letras si es ."com" o 2 si en de algún pais.")
return false
}
if (len<2) {
var errStr="La direcci\u00f3n es erronea"
//alert(errStr)
return false
}
// La dirección de email ingresada es Válida
return true;
}

function retInt(fieldValue) {
  var i=0;
  var ClearfieldValue ="";
  var iChars="1234567890-.()+/";
  for (i=0; i < fieldValue.length;i++) { 
    if (!(iChars.indexOf(fieldValue.charAt(i)) == -1)) { 
		ClearfieldValue = ClearfieldValue+""+ fieldValue.charAt(i);
    }
  }
  return ClearfieldValue;
}


function IsNumeric(valor) 
{ 
var log=valor.length; var sw="S"; 
for (x=0; x<log; x++) 
{ v1=valor.substr(x,1); 
v2 = parseInt(v1); 
//Compruebo si es un valor numérico 
if (isNaN(v2)) { sw= "N";} 
} 
if (sw=="S") {return true;} else {return false; } 
} 

function SubmitTheForm() {
msg=""
some=0
var maximo ="<%=year(now())+1%>"

if (document.myform.nombre.value==""){
	msg="- " +vpartic76+".\n"
	some=1
}
if (document.myform.apellido.value==""){
	msg=msg+"- " +vpartic77+".\n"
	some=1
}
if (document.myform.telefono.value==""){
	msg=msg+"- " +vpartic78+".\n"
	some=1

}else{
	document.myform.telefono.value=retInt(document.myform.telefono.value)
}

if (document.myform.tipofono.value=="0"){
	msg=msg+"- "+vpartic79+"\n"
	some=1
}

if (document.myform.email.value==""){
	msg=msg+"- "+vpartic80+".\n"
	some=1
}else{
  if (emailCheck(document.myform.email.value)==false) {
	msg=msg+"- "+vpartic81+".\n"
	some=1
  }
}

if (document.myform.email2.value==""){
	msg=msg+"- "+vpartic82+".\n"
	some=1
}else{
	if (document.myform.email.value!=document.myform.email2.value){
		msg=msg+"- "+vpartic83+".\n"
		some=1
	}
}

if (document.myform.prov.value==""){
	msg=msg+"- "+vpartic84+".\n"
	some=1
}else{
	if (document.myform.ciudad.value==0){
		msg=msg+"- "+vpartic85+".\n"
		some=1
	}else if(document.myform.ciudad.value==1){
		if(document.myform.ciudadotra.value==""){
				msg=msg+"- "+vpartic86+".\n"
				some=1
		}
	}
}

if (document.myform.Pass.value==""){
	msg=msg+"- "+vpartic87+".\n"
	some=1
 //alert("No ingres\u00f3 la Contrase\u00f1a en el formulario.");
 //return false;
}else{
	if (document.myform.Pass2.value==""){
	msg=msg+"- "+vpartic88+".\n"
	some=1
	 //alert("Debe reingresar la Contrase\u00f1a en el formulario.");
	 //return false;
	}else{
		if (document.myform.Pass2.value!=document.myform.Pass.value){
			msg=msg+"- "+vpartic89+".\n"
			some=1
		 //alert("Las Contrase\u00f1as ingresadas son diferentes revise el formulario.");
		 //return false;
		}

	}
}
if (document.myform.cod_marca.value==""){
	msg=msg+"- "+vpartic90+".\n"
	some=1
 //alert("No Selecciono la Marca en el formulario.");
 //return false;
}

if (document.myform.modelo.value==""){
	msg=msg+"- "+vpartic91+".\n"
	some=1
 //alert("No ingres\u00f3 un Modelo en el formulario.");
 //return false;
}

if (document.myform.ano.value==""){
	msg=msg+"- "+vpartic92+".\n"
	some=1
 //alert("No ingres\u00f3 un A\u00f1o en el formulario.");
 //return false;
}

if (document.myform.km.value != ""){
	if(parseInt(document.myform.km.value) != document.myform.km.value){
		msg=msg+"- "+vpartic93+".\n"
		some=1
	 //alert("Por favor, el kilometraje debe ser numerico.");
	 //return false;
	}
}
if (document.myform.milla.value != ""){
	if(parseInt(document.myform.milla.value) != document.myform.milla.value){
		msg=msg+"- "+vpartic94+".\n"
		some=1
	 //alert("Por favor, las Millas deben ser numericas.");
	 //return false;
	}
}

if (document.myform.pesos.value==""){
	msg=msg+"- "+vpartic95+".\n"
	some=1
 //alert("No ingres\u00f3 el precio del veh\u00edculo en el formulario.");
 //return false;
}
if (document.myform.foto1.value!=""){

	var valor=document.myform.foto1.value
	var pat1=/jpg/;
	var pat2=/jpeg/;
	var pat3=/gif/;
	var pat4=/png/;
	var pat5=/bmp/;
	var pat6=/JPG/;
	var pat7=/JPEG/;
	var pat8=/GIF/;
	var pat9=/PNG/;
	var pat10=/BMP/;

	if (pat1.test(valor)==true||pat2.test(valor)==true||pat3.test(valor)==true||pat4.test(valor)==true||pat5.test(valor)==true||pat6.test(valor)==true||pat7.test(valor)==true||pat8.test(valor)==true||pat9.test(valor)==true||pat10.test(valor)==true)
	{
	
	}else{
	msg=msg+"- "+vpartic96+".\n"
	some=1
	}
}	
if (document.myform.foto2.value!=""){

	var valor=document.myform.foto2.value
	var pat1=/jpg/;
	var pat2=/jpeg/;
	var pat3=/gif/;
	var pat4=/png/;
	var pat5=/bmp/;
	var pat6=/JPG/;
	var pat7=/JPEG/;
	var pat8=/GIF/;
	var pat9=/PNG/;
	var pat10=/BMP/;

	if (pat1.test(valor)==true||pat2.test(valor)==true||pat3.test(valor)==true||pat4.test(valor)==true||pat5.test(valor)==true||pat6.test(valor)==true||pat7.test(valor)==true||pat8.test(valor)==true||pat9.test(valor)==true||pat10.test(valor)==true)
	{
	
	}else{
	msg=msg+"- "+vpartic97+".\n"
	some=1
	}
}	
if (document.myform.foto3.value!=""){

	var valor=document.myform.foto3.value
	var pat1=/jpg/;
	var pat2=/jpeg/;
	var pat3=/gif/;
	var pat4=/png/;
	var pat5=/bmp/;
	var pat6=/JPG/;
	var pat7=/JPEG/;
	var pat8=/GIF/;
	var pat9=/PNG/;
	var pat10=/BMP/;

	if (pat1.test(valor)==true||pat2.test(valor)==true||pat3.test(valor)==true||pat4.test(valor)==true||pat5.test(valor)==true||pat6.test(valor)==true||pat7.test(valor)==true||pat8.test(valor)==true||pat9.test(valor)==true||pat10.test(valor)==true)
	{
	
	}else{
	msg=msg+"- "+vpartic98+".\n"
	some=1
	}
}	
if (document.myform.foto4.value!=""){

	var valor=document.myform.foto4.value
	var pat1=/jpg/;
	var pat2=/jpeg/;
	var pat3=/gif/;
	var pat4=/png/;
	var pat5=/bmp/;
	var pat6=/JPG/;
	var pat7=/JPEG/;
	var pat8=/GIF/;
	var pat9=/PNG/;
	var pat10=/BMP/;

	if (pat1.test(valor)==true||pat2.test(valor)==true||pat3.test(valor)==true||pat4.test(valor)==true||pat5.test(valor)==true||pat6.test(valor)==true||pat7.test(valor)==true||pat8.test(valor)==true||pat9.test(valor)==true||pat10.test(valor)==true)
	{
	
	}else{
	msg=msg+"- "+vpartic99+".\n"
	some=1
	}
}	
if (document.myform.foto5.value!=""){

	var valor=document.myform.foto5.value
	var pat1=/jpg/;
	var pat2=/jpeg/;
	var pat3=/gif/;
	var pat4=/png/;
	var pat5=/bmp/;
	var pat6=/JPG/;
	var pat7=/JPEG/;
	var pat8=/GIF/;
	var pat9=/PNG/;
	var pat10=/BMP/;

	if (pat1.test(valor)==true||pat2.test(valor)==true||pat3.test(valor)==true||pat4.test(valor)==true||pat5.test(valor)==true||pat6.test(valor)==true||pat7.test(valor)==true||pat8.test(valor)==true||pat9.test(valor)==true||pat10.test(valor)==true)
	{
	
	}else{
	msg=msg+"- "+vpartic100+".\n"
	some=1
	}
}	
if (document.myform.foto6.value!=""){

	var valor=document.myform.foto6.value
	var pat1=/jpg/;
	var pat2=/jpeg/;
	var pat3=/gif/;
	var pat4=/png/;
	var pat5=/bmp/;
	var pat6=/JPG/;
	var pat7=/JPEG/;
	var pat8=/GIF/;
	var pat9=/PNG/;
	var pat10=/BMP/;

	if (pat1.test(valor)==true||pat2.test(valor)==true||pat3.test(valor)==true||pat4.test(valor)==true||pat5.test(valor)==true||pat6.test(valor)==true||pat7.test(valor)==true||pat8.test(valor)==true||pat9.test(valor)==true||pat10.test(valor)==true)
	{
	
	}else{
	msg=msg+"- "+vpartic101+".\n"
	some=1
	}
}	
if (document.myform.foto7.value!=""){

	var valor=document.myform.foto7.value
	var pat1=/jpg/;
	var pat2=/jpeg/;
	var pat3=/gif/;
	var pat4=/png/;
	var pat5=/bmp/;
	var pat6=/JPG/;
	var pat7=/JPEG/;
	var pat8=/GIF/;
	var pat9=/PNG/;
	var pat10=/BMP/;

	if (pat1.test(valor)==true||pat2.test(valor)==true||pat3.test(valor)==true||pat4.test(valor)==true||pat5.test(valor)==true||pat6.test(valor)==true||pat7.test(valor)==true||pat8.test(valor)==true||pat9.test(valor)==true||pat10.test(valor)==true)
	{
	
	}else{
	msg=msg+"- "+vpartic102+".\n"
	some=1
	}
}	
if (document.myform.foto8.value!=""){

	var valor=document.myform.foto8.value
	var pat1=/jpg/;
	var pat2=/jpeg/;
	var pat3=/gif/;
	var pat4=/png/;
	var pat5=/bmp/;
	var pat6=/JPG/;
	var pat7=/JPEG/;
	var pat8=/GIF/;
	var pat9=/PNG/;
	var pat10=/BMP/;

	if (pat1.test(valor)==true||pat2.test(valor)==true||pat3.test(valor)==true||pat4.test(valor)==true||pat5.test(valor)==true||pat6.test(valor)==true||pat7.test(valor)==true||pat8.test(valor)==true||pat9.test(valor)==true||pat10.test(valor)==true)
	{
	
	}else{
	msg=msg+"- "+vpartic103+".\n"
	some=1
	}
}	

if (some==1){
	alert (""+vpartic104+" \n"+msg);
}else if (some==0){
	document.myform.submit() 
}
}
//*********************************************************
function AvisajeSubmitTheForm() {
	msg=""
	some=0
	var maximo ="<%=year(now())+1%>"
	
	if (document.myform.categoria.value==0){
		msg="- "+vpavisaje0+".\n"
		some=1
	}
	if (document.myform.titular.value==""){
		msg=msg+"- "+vpavisaje1+".\n"
		some=1
	}
	if (document.myform.precio.value==""){
		msg=msg+"- "+vpavisaje2+".\n"
		some=1
	}
	if (document.myform.ciudad.value==0){
		msg=msg+"- "+vpavisaje3+"\n"
		some=1
	}
	if (document.myform.nombre.value==""){
		msg=msg+"- "+vpavisaje3+"\n"
		some=1
	}
	if (document.myform.apellido.value==""){
		msg=msg+"- "+vpavisaje4+"\n"
		some=1
	}
	if (document.myform.telefono.value=="" && document.myform.email.value==""){
		msg=msg+"- "+vpavisaje6+"\n"
		some=1
	}
	if (document.myform.email.value!=""){
		if (emailCheck(document.myform.email.value)==false) {
			msg=msg+"- "+vpavisaje7+".\n"
			some=1
		}
	}
	if (document.myform.login.value==""){
		msg=msg+"- "+vpavisaje8+"\n"
		some=1
	}
	if (some==1){
		alert (""+vpavisaje9+" \n"+msg);
	}else if (some==0){
		document.myform.submit() 
	}
}

function ModVehiSubmitTheForm() {
	msg=""
	some=0
	var maximo ="<%=year(now())+1%>"
	
	if (document.modifico.modelo.value==""){
		msg="- "+vpopciones0+".\n"
		some=1
	}
	if (document.modifico.pesos.value=="" && document.modifico.valor_ref.value==""){
		msg=msg+"- "+vpopciones1+".\n"
		some=1
	}
	if (document.modifico.fonauto.value=="" && document.modifico.emailpart.value==""){
		msg=msg+"- "+vpopciones2+"\n"
		some=1
	}
	if (document.modifico.emailpart.value!=""){
		if (emailCheck(document.modifico.emailpart.value)==false) {
			msg=msg+"- "+vpopciones3+".\n"
			some=1
		}
	}
	if (document.modifico.fonauto.value!=""){
		document.modifico.fonauto.value=retInt(document.modifico.fonauto.value)
	}
	if (document.modifico.nomauto.value==""){
		msg=msg+"- "+vpopciones4+".\n"
		some=1
	}
	if (document.modifico.nom.value==""){
		msg=msg+"- "+vpopciones5+"\n"
		some=1
	}
	if (document.modifico.pass.value==""){
		msg=msg+"- "+vpopciones6+"\n"
		some=1
	}
	if (document.modifico.km.value != ""){
		if(parseInt(document.modifico.km.value) != document.modifico.km.value){
			msg=msg+"- "+vpopciones7+".\n"
			some=1
		}
	}
	if (document.modifico.milla.value != ""){
		if(parseInt(document.modifico.milla.value) != document.modifico.milla.value){
			msg=msg+"- "+vpopciones8+".\n"
			some=1
		}
	}
	if (some==1){
		alert (""+vpopciones9+" \n"+msg);
	}else if (some==0){
		document.modifico.submit() 
	}
}

function CliModVehiSubmitTheForm() {
	msg=""
	some=0
	var maximo ="<%=year(now())+1%>"
	
	if (document.form_modifica.modelo.value==""){
		msg="- "+vpopcionesc0+".\n"
		some=1
	}
	if (document.form_modifica.pesos.value=="" && document.form_modifica.valor_ref.value==""){
		msg=msg+"- "+vpopcionesc1+".\n"
		some=1
	}
	if (document.form_modifica.km.value != ""){
		if(parseInt(document.form_modifica.km.value) != document.form_modifica.km.value){
			msg=msg+"- "+vpopcionesc2+".\n"
			some=1
		}
	}
	if (document.form_modifica.milla.value != ""){
		if(parseInt(document.form_modifica.milla.value) != document.form_modifica.milla.value){
			msg=msg+"- "+vpopcionesc3+".\n"
			some=1
		}
	}
	if (some==1){
		alert (""+vpopcionesc4+" \n"+msg);
	}else if (some==0){
		document.form_modifica.submit() 
	}
}

//*********************************************************
function barra(texto){
   window.status=texto
}
function popup(ventana)
{ win = window.open(ventana,
'_blank','width=500,height=400,resizable=0,scrollbars=1');}

function popup2(ventana)
{ win = window.open(ventana,
'_blank','width=500,height=400,resizable=0,scrollbars=1');}

function plim(ventana)
{ win = window.open(ventana,
'_blank','width=500,height=200,resizable=0,scrollbars=1');}
