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];}
}

function fnOpWinAviso() {
	var lW = screen.availWidth;
	var lH = screen.availHeight;
	var lSW = (lW / 2);
	var lSH = (lH / 2);
	var lLeft = lSW - 290;
	var lTop = lSH - 155;
	
	window.open("aviso/aviso.html","AvisoDeRobo","left=" + lLeft + ",top=" + lTop + ",screenX=0,screenY=0,width=580,height=310,resizable=no");
}

function validaForm(eventTarget, eventArgument) {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.frmAviso;
	} else {
		theform = document.forms["frmAviso"];
	}
	theform.submit();
}

function validateEmail (address) {
	if (address.length>=7) {
		if (address.indexOf("@")>0) {
			if ((address.indexOf("@")+2)<address.lastIndexOf(".")) {
				if (address.lastIndexOf(".")<(address.length-2)) {
					return (true);
				}
			}
		}
	}
	return (false);
}

function FnFecha() {
	var hoy = new Date()
	var fec1 = document.frmAviso.txtFecRobo.value;
	var len1 = fec1.length
	if (len1 == 10) {
		var diade = fec1.substring(0,2)
		var mesde = fec1.substring(3,5)
		var anode = fec1.substring(6,10)
		var dhoy = hoy.getDate()
		var mhoy = hoy.getMonth() + 1
		var ahoy = hoy.getFullYear()
		var d1fec1 = fec1.substring(2,3)
		var d2fec1 = fec1.substring(5,6)
		if (d1fec1 == "/") {
			if (d2fec1 == "/") {
				if (diade <= 31) {
					if (mesde <= 12) {
						if (anode <= ahoy) {
							var nfec1 = new Date(anode, mesde - 1, diade)
							if (nfec1 <= hoy) {
								return true;
							} else {
								alert("La fecha no puede ser mayor a la fecha actual");
								return false;
							}
						} else {
							alert("El año no puede ser mayor al de la fecha acutal");
							return false;
						}
					} else {
						alert("El mes no puede ser mayor a 12");
						return false;
					}
				} else {
					alert("El día no puede ser mayor a 31");
					return false;
				}
			} else {
				alert("La fecha no tiene un formato valido. El formato es dd/mm/aaaa");
				return false;
			}
		} else {
			alert("La fecha no tiene un formato valido. El formato es dd/mm/aaaa");
			return false;
		}
	} else {
		alert("Introduzca formato de fecha: dd/mm/aaaa");
		return false;
	}
}

function fnValidarAviso(){
	if (document.frmAviso.txtFecRobo.value == "") {
		alert("Por favor ingrese la fecha de robo");
		document.frmAviso.txtFecRobo.focus();
	} else if (document.frmAviso.cmbEstado.value == 0) {
		alert("Por favor seleccione un estado");
		document.frmAviso.cmbEstado.focus();
	} else if (document.frmAviso.txtNombre.value == "") {
		alert("Por favor ingrese el nombre del asegurado");
		document.frmAviso.txtNombre.focus();
	} else if (document.frmAviso.txtPoliza.value == "") {
		alert("Por favor ingrese el no. de poliza del vehículo");
		document.frmAviso.txtPoliza.focus();
	} else if (document.frmAviso.txtSerie.value == "") {
		alert("Por favor ingrese el no. de serie del vehículo");
		document.frmAviso.txtSerie.focus();
	} else if (document.frmAviso.cmbCompania.value == "Sel") {
		alert("Por favor seleccione una compania aseguradora");
		document.frmAviso.cmbCompania.focus();
	} else {
		if ((document.frmAviso.txtFecRobo.value != "") && (document.frmAviso.cmbEstado.value != 0) && (document.frmAviso.txtNombre.value != "") && (document.frmAviso.txtPoliza.value != "") && (document.frmAviso.txtSerie.value != "") && (document.frmAviso.cmbCompania.value != "Sel")) {
			var incorrect = false;
			if (document.frmAviso.txtEmail.value != "") {
				if (!validateEmail(document.frmAviso.txtEmail.value)) {
					alert("El correo no es válido");
					document.frmAviso.txtEmail.focus();
					incorrect = true;
				}
			}
			if (incorrect == false) {
				if (FnFecha() == true) {
					if (confirm("¿Confirma que desea enviar los datos?")){
						return true;
					} else {
						return false;
					}
				} else {
					document.frmAviso.txtFecRobo.focus();
				}
			}
		}
	}
}

function fnBorrarAviso() {
	document.frmAviso.txtFecRobo.value = "";
	document.frmAviso.cmbEstado.value = 0;
	document.frmAviso.txtNombre.value = "";
	document.frmAviso.txtEmail.value = "";
	document.frmAviso.txtPoliza.value = "";
	document.frmAviso.txtSerie.value = "";
	document.frmAviso.cmbCompania.value = "Sel";
	document.frmAviso.txtFecRobo.focus();
}

function fnReporteRobo(){
	var lW = screen.availWidth;
	var lH = screen.availHeight;
	var lSW = (lW / 2);
	var lSH = (lH / 2);
	var lLeft = lSW - 290;
	var lTop = lSH - 155;
	
	window.open("http://www.amis.org.mx/InformaWeb/ReporteRobo.html","ReporteRoboAMIS","left=" + lLeft + ",top=" + lTop + ",screenX=0,screenY=0,width=400,height=350,resizable=no");
}