//Roll-Overs--------------------------------------------------------------------------------------------------

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Validaciones-------------------------------------------------------------------------------------------------

function EMailAddressIsValid(strVal) {
	var x = strVal;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x))
		return true;
	else
		return false;
}

function SoloNumeros(strVal) {
	var x = strVal;
	var filter = /^([0-9])*$/;
	if (filter.test(x))
		return true;
	else
		return false;
}

function CedIsValid(strVal) {
	var x = strVal;
	var filter = /^([0-9\-])*$/;
	if (filter.test(x))
		return true;
	else
		return false;
}

function checkCamposSearch (form) {
	if (form.ano_inicio.value != "" || form.ano_final.value != "") {
		if (form.ano_inicio.value == "") {
			alert ("Debe ingresar el año mínimo por el cual usted desea filtrar su busqueda.");
			form.ano_inicio.focus();
			return false;
		}
		else {
			if (YearIsValid(form.ano_inicio.value)) {
			//return true;
			}
			else {
				alert ("El año debe ser escrito en formato de 4 dígitos, ejemplo: 2009.");
				form.ano_inicio.focus();
				return false;
			}
		}
		if (form.ano_final.value == "") {
			alert ("Debe ingresar el año máximo por el cual usted desea filtrar su busqueda.");
			form.ano_final.focus();
			return false;
		}
		else {
			if (YearIsValid(form.ano_final.value)) {
			//return true;
			}
			else {
				alert ("El año debe ser escrito en formato de 4 dígitos, ejemplo: 2009.");
				form.ano_final.focus();
				return false;
			}
		}
	}
	
	if (form.p_inicio.value != "" || form.p_final.value != "") {
		if (form.p_inicio.value == "") {
			alert ("Debe ingresar el precio mínimo por el cual usted desea filtrar su busqueda.");
			form.p_inicio.focus();
			return false;
		}
		else {
			if (PriceIsValid(form.p_inicio.value)) {
			//return true;
			}
			else {
				alert ("Por favor ingrese un número entero sin símbolos para el precio del vehículo, ejemplo: 3000000, para tres millones.");
				form.p_inicio.focus();
				return false;
			}
		}
		if (form.p_final.value == "") {
			alert ("Debe ingresar el precio máximo por el cual usted desea filtrar su busqueda.");
			form.p_final.focus();
			return false;
		}
		else {
			if (PriceIsValid(form.p_final.value)) {
			//return true;
			}
			else {
				alert ("Por favor ingrese un número entero sin símbolos para el precio del vehículo, ejemplo: 3000000, para tres millones.");
				form.p_final.focus();
				return false;
			}
		}
	}
}

function checkCamposCita (form) {
	if (form.nombre.value == "") {
		alert( "Debe ingresar su nombre y apellidos." );
		form.nombre.focus();
		return false ;
	}
	
	if (form.cedula.value == "") {
		alert( "Debe ingresar su número de cédula." );
		form.cedula.focus();
		return false ;
	}
	else {
		if (CedIsValid(form.cedula.value)) {
		//return true;
		}
		else {
			alert ("El número de cédula debe contener solo números y separados por - (guiones)");
			form.cedula.focus();
			return false;
		}
	}
	
	if (form.placa.value == "") {
		alert( "Debe ingresar el número de placa del auto." );
		form.placa.focus();
		return false ;
	}
	
	if (form.tel.value == "") {
		alert( "Debe ingresar un teléfono para contactarlo." );
		form.tel.focus();
		return false ;
	}
	else {
		if (SoloNumeros(form.tel.value)) {
		//return true;
		}
		else {
			alert ("El número de teléfono debe contener solo números");
			form.tel.focus();
			return false;
		}
	}
	
	if (form.mail.value == "") {
		alert( "Debe ingresar su e-mail." );
		form.mail.focus();
		return false ;
	}
	else {
		if (EMailAddressIsValid(form.mail.value)) {
		//return true;
		}
		else {
			alert ("El e-mail es inválido, por favor revisar.");
			return false;
		}
	}
}

//Ventana Popup ----------------------------------------------------------------------------------------------

function abrir(direccion, pantallacompleta, herramientas, direcciones, directorios, estado, barramenu, barrascroll, cambiatamano, ancho, alto, sustituir){
	 LeftPosition = (screen.width-ancho)/2;;
  	 TopPosition = (screen.height-alto)/2;
     var opciones = "fullscreen=" + pantallacompleta + 
                 ",toolbar=" + herramientas + 
                 ",location=" + direcciones + 
				 ",directories=" + directorios +
                 ",status=" + estado + 
                 ",menubar=" + barramenu + 
                 ",scrollbars=" + barrascroll + 
                 ",resizable=" + cambiatamano + 
                 ",width=" + ancho + 
                 ",height=" + alto + 
                 ",left=" + LeftPosition + 
                 ",top=" + TopPosition; 
     var ventana = window.open(direccion,"venta",opciones,sustituir); 

}