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) {
	var r = G.dom.$("respuesta");
	if (r) {
		if (error) {
			r.className = "falla";
		} else {
			r.className = "exito";
		}
		r.innerHTML = t;
	}
}
function esInt(el, nombre) {
	return errorField(traduccion("JS_HOME1") + nombre + traduccion("JS_HOME2"),
			el, G.valid.isInt, true);
}
function esFloat(el, nombre) {
	return errorField(traduccion("JS_HOME1") + nombre + traduccion("JS_HOME3"),
			el, G.valid.isFloat, true);
}
function esVacio(el, nombre) {
	return errorField(traduccion("JS_HOME1") + nombre + traduccion("JS_HOME4"),
			el, G.valid.isEmpty);
}

function sonIguales(els, nombres) {
	return errorField(
			traduccion("JS_HOME1") + nombres + traduccion("JS_HOME5"), els,
			G.valid.areEquals, true);
}

function esEmail(el, nombre) {
	return errorField(traduccion("JS_HOME1") + nombre + traduccion("JS_HOME6"),
			el, G.valid.isEmail, true);
}

function errorField(m, el, f, dir, clase) {
	if (f) {
		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) {
	if (json) {
		if (json.success) {
			mensaje(json.mensaje);
			if (this.formRequest) {
				this.formRequest.reset();
			}
		} else if (json.error) {
			mensaje(json.error, true);
			if (json.tabla && json.campo) {
				if (json.tabla === "proyecto") {
					json.campo = "proy__" + 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) {
	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("");
					return true;
				} else {
					mensaje(traduccion("JS_HOME1") + this.title
							+ traduccion("JS_HOME7") + this.types, true);
				}
			}
			return false;
		} else {
			return true;
		}
	};
	el.types = ex;
	el.title = t;
	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('" + traduccion("JS_HOME8") + "')", 100);
	}
	return false;
}

G.util.ready(function() {
	if (G.url._GET("s") !== "admin" && G.url._GET("s") !== "soporte"
			&& (G.url._GET("s") !== "productos" || !G.url._GET("ss"))) {
		$("#submenu ul li ul").css( {
			display : "none"
		});
		$("#submenu ul li.sel").removeClass("sel");
	}
	if (G.url._GET("ot")) {
		var lis = $("#submenu ul li");
		$(lis.get(lis.length - 1)).addClass("sel");
	}
	cargarTraducciones();
	igualarPaneles();
});

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 traduccion(t) {
	return traducciones[t] ? traducciones[t] : t;
}

function desplegarFamilias() {
	$("#submenu ul li.sel").removeClass("sel");
	$("#submenu ul li ul").css( {
		display : "none"
	}).parent().removeClass("sel2");
	$(this).parent().find("ul").css( {
		display : "block"
	}).parent().addClass("sel2");
	igualarPaneles();
	return false;
}
function igualarPaneles() {
	var s = G.dom.$("submenu");
	if (s) {
		var h = s.parentNode.offsetHeight;
		var l = G.dom.$("left");
		var c = G.dom.$("center");
		var r = G.dom.$("right");
		if (c.offsetHeight < h) {
			c.style.height = h + "px";
		}
		if (r.offsetHeight + 10 < h) {
			r.style.height = (h - 10) + "px";
		}
		if (c.offsetHeight - 40 > l.offsetHeight) {
			l.style.height = (c.offsetHeight - 40) + "px";
		}
	}
}

function verVideo(id, dos) {
	var a = new G.ajax( {
		pagina : dos ? "vervideo2.php" : "vervideo.php",
		post : {
			id : id
		},
		accion : function() {
			$("#videoVista").dialog("open");
		}
	});
	$("#videoVista").dialog( {
		width : 520,
		modal : true,
		bgiframe : true,
		autoOpen : false
	});
	a.recibir("videoVista");
	return false;
}

function readLanguage(lang) {
	location.href = G.url._setGET("lg", lang);
}

function enviarEmailNews() {
	if (esEmail(this.emailnews, "Email")) {
		var a = new G.ajax(
				{
					pagina : "interceptor.php",
					post : {
						__quien : "mantenimiento",
						__tabla : "newsletteremails",
						__accion : "insertar",
						email : this.emailnews.value
					},
					json : true,
					form : this,
					accion : function() {
						var json = this.JSON;
						if (json) {
							G.dom.$("respuestaEmailNews").innerHTML = "Se Suscribio con Exito";
							this.form.reset();
						} else {
							G.dom.$("respuestaEmailNews").innerHTML = "error en el servicio intentelo mas tarde";
						}
					}
				});
		a.enviar();
	} else {
		G.dom.$("respuestaEmailNews").innerHTML = traduccion("JS_HOME1")
				+ "Email" + traduccion("JS_HOME6");
	}
	return false;
}