var mis_imagenes = new Array();
function precarga()
{
	for (x = 0; x > precarga.arguments.length; x++)
	{
		mis_imagenes[x] = new Image();
		mis_imagenes[x].src = precarga.arguments[x];
	}
}

function cambiar(imgObjName,imgName)
{
	document.images[imgObjName].src = "imagenes/fotos/" + imgName;
}

function AppForm(id)
{
	if (id == 0)
	{
		window.open("appform.php?st=1","","height=800,width=930,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,left=150,top=10");
	}
	else
	{
		window.open("appform.php?st=1&id=" + id,"","height=800,width=930,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,left=150,top=10");
	}
}

function Estatus(id)
{
	window.open("estatus.php?id=" + id,"","height=250,width=600,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,left=300,top=300");
}

function Mapa(url)
{
	window.open(url,"","height=600,width=600,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,left=300,top=150");
}

function Print(id)
{
	window.open("imprimir.php?id=" + id,"","height=700,width=900,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,left=150,top=10");
}

function Sube()
{
	window.document.getElementById('cargando').style.display = "block";
	window.document.media.submit();
}

function Contenido(id)
{
	window.location = "index.php?id=" + id;
}

function Muestra(div)
{
	document.getElementById(div).style.display = "block";
}

function Edit(que,id)
{
	switch (que)
	{
		case "seccion":
		{
			window.location = "index.php?id_sec=" + id;
			break;
		}
		case "subseccion":
		{
			window.location = "index.php?id_ss=" + id;
			break;
		}
		case "plantilla":
		{
			window.location = "ofertas.php?mod=Add1&tmp=" + id;
			break;
		}
		case "jt":
		{
			window.location = "ofertas.php?mod=" + que + "&id=" + id;
			break;
		}
		case "Add1":
		{
			elementos = window.document.ofertas.elements.length;
			checado = false;
			for(i = 0; i < elementos; i++)
			{
    			if (window.document.ofertas.elements[i].checked)
				{
					window.location = "ofertas.php?mod=" + que + "&id=" + window.document.ofertas.elements[i].value;
					checado = true;
				}
			}
			if (checado == false)
			{
				alert("Debes seleccionar una oferta a editar");
			}
			break;
		}
		case "plantilla":
		{
			window.location = "ofertas.php?mod=Add1&tmp=" + id;
			break;
		}
		default:
		{
			window.location = que + ".php?mod=Edit&id=" + id;
			break;
		}
	}
}

function Destroy(modulo,id)
{
	if (confirm("Are you sure you want to delete this record?"))
	{
		if (modulo == "oferta")
		{
			elementos = window.document.ofertas.elements.length;
			cadena = "";
			for(i = 0; i < elementos; i++)
			{
    			if (window.document.ofertas.elements[i].checked)
				{
					cadena += "&id" + i + "=" + window.document.ofertas.elements[i].value;
				}
			}
			if (cadena == "")
			{
				alert("You must select at least one oportunity to remove");
			}
			else
			{
				window.location = "managedata.php?mod=oferta1&act=Destroy" + cadena;
			}
		}
		else
		{
			window.location = "managedata.php?mod=" + modulo + "&act=Destroy&id=" + id;
		}
	}
}

function MM_jumpMenu(targ,selObj,restore)
{
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function OLF()
{
	window.open("fo.php","","height=800,width=930,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,left=150,top=10");
}

function Comprueba_Disponibilidad()
{
	window.open("comprueba_disp.php?us=" + window.document.Registro.username.value,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=250,height=200,screenX=150,screenY=150,top=150,left=150");
}

function Chat()
{
	alert("COMMING SOON!");
	/*window.open('chat.php','_blank','height=350,width=540,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,left=150,top=50');*/
}

function SelectAll()
{
	elementos = window.document.ofertas.elements.length;
	if (elementos > 0)
	{
		for(i = 0; i < elementos; i++)
		{
    		window.document.ofertas.elements[i].checked = true;
		}
	}
}

function ActDes(id)
{
	if (confirm("Are you sure you want to activate / deactivate this user?"))
	{
		window.location = "managedata.php?mod=user&act=Destroy&id=" + id;
	}
}

function Valida(formulario,que)
{
	switch (que)
	{
		case "registro_new":
		{
			if (formulario.nombre.value == "") { alert("All fields are required"); formulario.nombre.focus(); return false; }
			if (formulario.telefono.value == "") { alert("All fields are required"); formulario.telefono.focus(); return false; }
			if (formulario.email.value == "") { alert("All fields are required"); formulario.email.focus(); return false; }
			if (formulario.password.value == "") { alert("All fields are required"); formulario.password.focus(); return false; }
			if (formulario.imagetext.value == "") { alert("You have not typed in the security code"); formulario.imagetext.focus(); return false; }
			if (formulario.email.value != formulario.c_email.value) { alert("There is a difference between the E-mail address and confirmation");  formulario.email.focus(); return false; }
			if (formulario.password.value != formulario.c_password.value) { alert("There is a difference between the Password and confirmation");  formulario.password.focus(); return false; }
			break;
		}
		case "registro_edit":
		{
			if (formulario.nombre.value == "") { alert("All fields are required"); formulario.nombre.focus(); return false; }
			if (formulario.email.value == "") { alert("All fields are required"); formulario.email.focus(); return false; }
			if (formulario.email.value != formulario.c_email.value) { alert("There is a difference between the E-mail address and confirmation");  formulario.email.focus(); return false; }
			break;
		}
		case "mod_pass":
		{
			if (formulario.password_ac.value == "") { alert("There can not be empty passwords"); formulario.password_ac.focus(); return false; }
			if (formulario.password_ne.value == "") { alert("There can not be empty passwords"); formulario.password_ne.focus(); return false; }
			if (formulario.password_ne.value != formulario.c_password_ne.value) { alert("There is a difference between the Password address and confirmation");  formulario.password_ne.focus(); return false; }
			break;
		}
		case "busqueda":
		{
			if (formulario.texto.value == "") { alert("You have not provided any search criteria"); formulario.texto.focus(); return false; }
			break;
		}
		case "login":
		{
			if (formulario.username.value == "") { alert("You have not provided a username"); formulario.username.focus(); return false; }
			if (formulario.password.value == "") { alert("You have not provided your password"); formulario.password.focus(); return false; }
			break;
		}
		case "contacto":
		{
			if (formulario.nombre.value == "") { alert("The fields marked with * are required"); formulario.nombre.focus(); return false; }
			if (formulario.telefono.value == "") { alert("The fields marked with * are required"); formulario.telefono.focus(); return false; }
			if (formulario.email.value == "") { alert("The fields marked with * are required"); formulario.email.focus(); return false; }
			if (formulario.comentarios.value == "") { alert("The fields marked with * are required"); formulario.comentarios.focus(); return false; }
			break;
		}
		case "ai":
		{
			if (formulario.fname.value == "") { alert("The fields marked with * are required"); formulario.fname.focus(); return false; }
			if (formulario.lname.value == "") { alert("The fields marked with * are required"); formulario.lname.focus(); return false; }
			if (formulario.edad.value == "") { alert("The fields marked with * are required"); formulario.edad.focus(); return false; }
			if (formulario.e_civil.value == "") { alert("The fields marked with * are required"); formulario.e_civil.focus(); return false; }
			if (formulario.telefono.value == "") { alert("The fields marked with * are required"); formulario.telefono.focus(); return false; }
			if (formulario.cp.value == "") { alert("The fields marked with * are required"); formulario.cp.focus(); return false; }
			if (formulario.year.value == "") { alert("The fields marked with * are required"); formulario.year.focus(); return false; }
			if (formulario.hecho.value == "") { alert("The fields marked with * are required"); formulario.hecho.focus(); return false; }
			if (formulario.modelo.value == "") { alert("The fields marked with * are required"); formulario.modelo.focus(); return false; }
			if (formulario.e_civil.value == "") { alert("The fields marked with * are required"); formulario.e_civil.focus(); return false; }
			break;
		}
		case "claims":
		{
			if (formulario.fecha1.value == "") { alert("The fields marked with * are required"); formulario.fecha1.focus(); return false; }
			if (formulario.tiempo1a.value == "") { alert("The fields marked with * are required"); formulario.tiempo1a.focus(); return false; }
			if (formulario.poliza1.value == "") { alert("The fields marked with * are required"); formulario.poliza1.focus(); return false; }
			if (formulario.quien.value == "") { alert("The fields marked with * are required"); formulario.quien.focus(); return false; }
			if (formulario.conductor1.value == "") { alert("The fields marked with * are required"); formulario.conductor1.focus(); return false; }
			if (formulario.owner.value == "") { alert("The fields marked with * are required"); formulario.owner.focus(); return false; }
			if (formulario.domicilio.value == "") { alert("The fields marked with * are required"); formulario.domicilio.focus(); return false; }
			if (formulario.tel_casa1.value == "") { alert("The fields marked with * are required"); formulario.tel_casa1.focus(); return false; }
			if (formulario.reporte.value == "") { alert("The fields marked with * are required"); formulario.reporte.focus(); return false; }
			if (formulario.lugar.value == "") { alert("The fields marked with * are required"); formulario.lugar.focus(); return false; }
			if (formulario.ciudad2.value == "") { alert("The fields marked with * are required"); formulario.ciudad2.focus(); return false; }
			if (formulario.fecha2.value == "") { alert("The fields marked with * are required"); formulario.fecha2.focus(); return false; }
			if (formulario.tiempo2a.value == "") { alert("The fields marked with * are required"); formulario.tiempo2a.focus(); return false; }
			if (formulario.descripcion.value == "") { alert("The fields marked with * are required"); formulario.descripcion.focus(); return false; }
			break;
		}
		case "recupera_ps":
		{
			if (formulario.email.value == "") { alert("You have not provided an e-mail"); formulario.email.focus(); return false; }
			break;
		}
	}
}

function Suma(input,cantidad)
{
	temp = parseInt(document.getElementById(input).value);
	valor = temp + parseInt(cantidad);
	document.getElementById(input).value = valor;
}

function RevisaView(input,prefijo)
{
	if (prefijo == "mai" || prefijo == "op" || prefijo == "u")
	{
		v = prefijo + "v";
		c = prefijo + "c";
		e = prefijo + "e";
		d = prefijo + "d";
		if (!(document.getElementById(v).checked))
		{
			document.getElementById(v).checked = true;
			Suma(input,'1');
		}
	}
	else
	{
		document.getElementById(c).checked = false;
		document.getElementById(e).checked = false;
		document.getElementById(d).checked = false;
		document.getElementById(input).value = 0;
	}
}

function AbreVentana(pagina,ancho,alto)
{
	window.open(pagina,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=" + ancho + ",height=" + alto + ",screenX=50,screenY=50");
}
