function logout() {
	var ajax = new G.ajax( {
		pagina : "interceptor.php",
		post : {
			__quien : "admin",
			__accion : "logout"
		},
		accion : function() {
			redirectHimself();
		}
	});
	ajax.enviar();
	return false;
}
function procesarRespuesta() {
	var doc = this.contentWindow.document;
	if (doc) {
		var body = G.dom.$$$("body", 0, doc);
		if (body) {
			var json;
			try {
				eval("json=" + body.innerHTML);
				if (this.onjsonready) {
					this.onjsonready(json);
				}
			} catch (e) {

			}
		}
	}
	return true;
}

function mensaje(t, error, idres) {
	if (!idres) {
		idres = "respuesta";
	}
	var r = G.dom.$(idres);
	if (r) {
		if (error) {
			r.className = "falla";
		} else {
			r.className = "exito";
		}
		r.innerHTML = t;
	}
}
function esInt(el, nombre) {
	return errorField(traducir("JS_HOME1") + " " + nombre + " "
			+ traducir("JS_HOME2"), el, G.valid.isInt, true);
}
function esFloat(el, nombre) {
	return errorField(traducir("JS_HOME1") + " " + nombre + " "
			+ traducir("JS_HOME3"), el, G.valid.isFloat, true);
}
function esVacio(el, nombre) {
	return errorField(traducir("JS_HOME1") + " " + nombre + " "
			+ traducir("JS_HOME4"), el, G.valid.isEmpty);
}

function sonIguales(els, nombres) {
	return errorField(traducir("JS_HOME1") + " " + nombres + " "
			+ traducir("JS_HOME5"), els, G.valid.areEquals, true);
}

function esEmail(el, nombre) {
	return errorField(traducir("JS_HOME1") + " " + nombre + " "
			+ traducir("JS_HOME6"), el, G.valid.isEmail, true);
}

function esHora(el, nombre) {
	return errorField(traducir("JS_HOME1") + " " + nombre + " "
			+ traducir("JS_HOME8"), el, G.valid.isHour, true);
}

function esURL(el, nombre) {
	return errorField(traducir("JS_HOME1") + " " + nombre + " "
			+ traducir("JS_HOME9"), el, G.valid.isURL, true);
}

function errorField(m, el, f, dir, clase) {
	if (f) {
		if (!clase) {
			clase = "requerido";
		}
		var res;
		var val = el.value;
		if (el.length > 0) {
			val = el;
		}
		if (dir) {
			res = !f(val);
		} else {
			res = f(val);
		}
		if (res) {
			mensaje(m, true);
			if (el.length > 0) {
				el = el[0].focus();
			}
			el.focus();
			if (clase) {
				el.className += " " + clase;
				el.clase = clase;
				G.event.addEvent(el, "blur", campoRequerido);
			}
			return (dir ? false : true);
		}

	}
	mensaje("");
	return (dir ? true : false);
}
function campoRequerido(event) {
	if (G.util.trim(this.value) !== "") {
		this.className = this.className.replace(" " + this.clase, "");
		G.event.removeEvent(this, "blur", campoRequerido);
	}
}
function processJSON(json, idres) {
	if (!idres) {
		idres = "respuesta";
	}
	if (json) {
		if (json.success) {
			mensaje(json.mensaje, false, idres);
			if (this.formRequest) {
				this.formRequest.reset();
			}
		} else if (json.error) {
			mensaje(json.error, true, idres);
			if (json.tabla && json.campo) {
				var el = G.dom.$(json.campo);
				if (el) {
					el.clase = "requerido";
					el.className += " " + el.clase;
					G.event.addEvent(el, "blur", campoRequerido);
					el.focus();
				}
			}
		}
		return json.success;
	}
	return false;
};
function processLogin() {
	this.onjsonready = function(json) {
		if (json.success) {
			redirectHimself();
		} else {
			mensaje(json.error, true);
		}
	};
	return procesarRespuesta.call(this);
}

function redirectHimself() {
	var dir = location.href;
	dir = dir.split("#");
	location.href = dir[0];
}

function lookExtension(ex, el, t, idres) {
	if (!idres) {
		idres = "respuesta";
	}
	var f = function() {
		if (G.util.trim(this.value) != "") {
			if (this.types) {
				var ext = G.util.getExt(this.value);
				if (G.util.arraySearch(this.types, ext, true) >= 0) {
					mensaje("", false, this.idrespuesta);
					return true;
				} else {
					mensaje(traducir("JS_HOME1") + " " + this.title
							+ traducir("JS_HOME7") + this.types, true,
							this.idrespuesta);
				}
			}
			return false;
		} else {
			return true;
		}
	};
	el.types = ex;
	el.title = t;
	el.idrespuesta = idres;
	return f;
}
function noRealizar() {
	return false;
}

function agregarFavoritos() {
	var dir = location.href;
	dir = dir.split("/");
	dir = "http://" + dir[2];
	nom = "Red Line Motors Sports";
	if (G.nav.isIE) {
		window.external.AddFavorite(dir, mom);
	} else if (G.nav.isNS) {
		window.sidebar.addPanel(nom, dir, '');
	} else if (G.nav.isOP) {
		this.href = dir;
		return true;
	} else {
		setTimeout("alert('Presione [Ctrl]+[D] para aņadir a faboritos')", 100);
	}
	return false;
}

function readLanguage(lang) {
	location.href = G.url._setGET("lg", lang);
}

function cargarTraducciones() {
	var a = new G.ajax( {
		pagina : "interceptor.php",
		post : {
			__quien : "diccionario",
			__accion : "darTraducciones"
		},
		json : true,
		accion : function() {
			if (this.JSON && this.JSON.traducciones) {
				traducciones = this.JSON.traducciones;
			}
		}
	});
	a.enviar();
}

var traducciones = {};
function traducir(t) {
	return traducciones[t] ? traducciones[t] : t;
}

function desplegarFamilias() {
	$("#submenu ul li ul").css( {
		display : "none"
	}).parent().removeClass("sel2");
	$(this).parent().find("ul").css( {
		display : "block"
	}).parent().addClass("sel2");
	return false;
}
function verVideo(id) {
	var a = new G.ajax( {
		pagina : "vervideo.php",
		post : {
			id : id
		},
		accion : function() {
			$("#videoVista").dialog("open");
		}
	});
	$("#videoVista").dialog( {
		width : 420,
		modal : true,
		bgiframe : true,
		autoOpen : false
	});
	a.recibir("videoVista");
	return false;
}

function verGaleria(idio, datoofe, soyinmo, img) {
	var a = new G.ajax( {
		pagina : "vergaleria.php",
		get : {
			idio : idio,
			datoofe : datoofe,
			soyinmo : soyinmo,
			img : img
		},
		accion : function() {
			$("#galeriaVista").dialog("open");
			agal = $("a.galeria");
			agal.click(function() {
				stopSlide();
				asignarImagen(this);
				return false;
			});
			var gi = G.dom.$("galeria_izq");
			if (gi) {
				gi.innerHTML = "";
				var img = G.dom.create("img");
				img.id = "galeria_izq_img";
				img.style.display = "none";
				gi.appendChild(img);
				if (this.get.img) {
					for ( var i = 0; i < agal.length; i++) {
						var dir = agal[i].href;
						var path = dir.split("/").pop();
						if (path === this.get.img) {
							seleccionado = i;
						}
					}
				} else {
					seleccionado = 0;
				}
				tiempo = 5;
				abrirPaginaLista(0);
				animarDiapositivas();
			}
		}
	});
	$("#galeriaVista").dialog( {
		width : 860,
		height : 650,
		modal : true,
		bgiframe : true,
		autoOpen : false
	});
	a.recibir("galeriaVista");
	return false;
}

function abrirPaginaLista(n) {
	$(".galeria_fila").not("#listaPag" + n).css( {
		display : "none"
	});
	$("#listaPag" + n).css( {
		display : "block"
	});
	if(this!==window){
		$(".pagLista a.active").removeClass("active");
		this.className="active";
	}
	return false;
}

function verAmigo(idio, datoofe, soyinmo, mipromocion) {
	var a = new G.ajax( {
		pagina : "veramigo.php",
		get : {
			idio : idio,
			datoofe : datoofe,
			soyinmo : soyinmo,
			mipromocion : mipromocion
		},
		accion : function() {
			$("#amigoVista").dialog("open");
			agal = $("a.galeria");
			agal.click(function() {
				stopSlide();
				asignarImagen(this);
				return false;
			});
			var gi = G.dom.$("galeria_izq");
			if (gi) {
				gi.innerHTML = "";
				var img = G.dom.create("img");
				img.id = "galeria_izq_img";
				img.style.display = "none";
				gi.appendChild(img);
				animarDiapositivas();
				playSlide();
			}
		}
	});
	$("#amigoVista").dialog( {
		width : 500,
		height : 450,
		modal : true,
		bgiframe : true,
		autoOpen : false
	});
	a.recibir("amigoVista");
	return false;
}

function verMeinteresa(idio, datoofe, soyinmo, mipromocion) {
	var a = new G.ajax( {
		pagina : "verinteresa.php",
		get : {
			idio : idio,
			datoofe : datoofe,
			soyinmo : soyinmo,
			mipromocion : mipromocion
		},
		accion : function() {
			$("#interesaVista").dialog("open");
			agal = $("a.galeria");
			agal.click(function() {
				stopSlide();
				asignarImagen(this);
				return false;
			});
			var gi = G.dom.$("galeria_izq");
			if (gi) {
				gi.innerHTML = "";
				var img = G.dom.create("img");
				img.id = "galeria_izq_img";
				img.style.display = "none";
				gi.appendChild(img);
				animarDiapositivas();
				playSlide();
			}
		}
	});
	$("#interesaVista").dialog( {
		width : 500,
		height : 400,
		modal : true,
		bgiframe : true,
		autoOpen : false
	});
	a.recibir("interesaVista");
	return false;
}

G.util.ready(function() {
	cargarTraducciones();
});