var ruta_procesador = "http://"+document.URL.split("/")[2]+"/procesador.php";
var ruta_mail = "http://"+document.URL.split("/")[2]+"/mailer.php";
//document.URL.split("index.php");
//alert(document.URL.split("index.php")[0]);
//   =========================================================
//   || Funcion que muestra o oculta las secciones del menu ||
//   =========================================================
function muestra(id){
	obj=document.getElementById(id);
	if(obj.style.display=="block") obj.style.display="none";
	else obj.style.display="block";
}

//   =======================================================
//   || Funcion para cambiar de estilo al pasar el cursor ||
//   =======================================================
function mOvr(src,clrOver,txt) {
	window.status = txt;
	document.getElementById(src).className= clrOver;
}

//   ==================================================================
//   || Funcion para cambiar de estilo al quitar el cursor de encima ||
//   ==================================================================
function mOut(src,clrIn) {
	window.status='';
	document.getElementById(src).className= clrIn;
}

//   ==================================================================
//   || Funcion para cambiar de estilo al quitar el cursor de encima ||
//   ==================================================================
function contenido(id){
	var obj=document.getElementById("contenido");
	obj.style.display='none';
	var ojeto=document.getElementById("cargando");
	ojeto.style.display='block';
	var objcon = true;
	objcon = objeto();
//	alert("hola");
	if (objcon){
		var parametros = "?funcion=contenido&valor="+id;
		objcon.open("GET",ruta_procesador+parametros,true);
		objcon.onreadystatechange = function(){
			if (objcon.readyState==1){
				obj.innerHTML = "";
			}
			else{
				if (objcon.readyState==4){
					if (objcon.status==200){
						obj.innerHTML = "";
						obj.innerHTML = objcon.responseText;
						ojeto.style.display='none';
						obj.style.display='block';
					}
				}
			}
		}
		objcon.send(null);
	}
	else{
		alert("Ha ocurrido un error");
	}
}

//   ==================================================================
//   || Funcion para enviar un POST asíncrono para enviar los mails  ||
//   ==================================================================
function mail(){
		var empresa=document.getElementById("empresa").value;
		var emilio=document.getElementById("email").value;
		var programa=document.getElementById("programa").value;
		if(empresa!="" && emilio!="" && programa!=""){
			var objcon = true;
			objcon = objeto();
			if (objcon){
				var parameters = "empresa="+empresa;
				parameters += "&contacto="+document.getElementById("contacto").value;
				parameters += "&telefono="+document.getElementById("telefono").value;
				parameters += "&direccion="+document.getElementById("direccion").value;
				parameters += "&cp="+document.getElementById("cp").value;
				parameters += "&email="+emilio;
				parameters += "&comentarios="+document.getElementById("comentarios").value;
				parameters += "&tipo=contacto";
				objcon.open("POST",ruta_mail,true);
		      objcon.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		      objcon.setRequestHeader("Content-length", parameters.length);
		      objcon.setRequestHeader("Connection", "close");
		      objcon.send(parameters);
				objcon.onreadystatechange = function(){
					if (objcon.readyState==1){
						obj.innerHTML = "";
					}
					else{
						if (objcon.readyState==4){
							if (objcon.status==200){
								document.getElementById("infomail").innerHTML = "<font color=\"green\">Mensaje enviado correctamente.</font>";
								alert(objcon.responseText);
							}
						}
					}
				}
				objcon.send(null);
			}
			else{
				alert("Ha ocurrido un error");
			}
		}
		else{
			alert("Debes introducir al menos la empresa, el email o teléfono y el programa sobre el que trata el email");
		}
}
//   ==================================================================
//   || Funcion para enviar un POST asíncrono para enviar los mails  ||
//   ==================================================================
function distribuidores(){
	if(confirm("Estas seguro?")){
		var empresa=document.getElementById("empresa").value;
		var emilio=document.getElementById("email").value;
		if(empresa!="" && emilio!=""){
			var objcon = true;
			objcon = objeto();
			if (objcon){
				var parameters = "empresa="+empresa;
				parameters += "&contacto="+document.getElementById("contacto").value;
				parameters += "&cargo="+document.getElementById("cargo").value;
				parameters += "&telefono="+document.getElementById("telefono").value;
				parameters += "&direccion="+document.getElementById("direccion").value;
				parameters += "&poblacion="+document.getElementById("poblacion").value;
				parameters += "&cp="+document.getElementById("cp").value;
				parameters += "&email="+email;
				parameters += "&act_emp="+document.getElementById("act_emp").value;
				parameters += "&producto="+document.getElementById("producto").value;
				parameters += "&sector="+document.getElementById("sector").value;
				parameters += "&tipo=distribuidor";
				objcon.open("POST",ruta_mail,true);
		      objcon.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		      objcon.setRequestHeader("Content-length", parameters.length);
		      objcon.setRequestHeader("Connection", "close");
		      objcon.send(parameters);
				objcon.onreadystatechange = function(){
					if (objcon.readyState==1){
						obj.innerHTML = "";
					}
					else{
						if (objcon.readyState==4){
							if (objcon.status==200){
								document.getElementById("infomail").innerHTML = "<font color=\"green\">Mensaje enviado correctamente.</font>";
								alert(objcon.responseText);
							}
						}
					}
				}
				objcon.send(null);
			}
			else{
				alert("Ha ocurrido un error");
			}
		}
		else{
			alert("Debes introducir al menos un nombre de Empresa y una direccion de E-Mail");
		}
	}
}
//   ==================================================================
//   || Funciónn AJAX de conexión									 ||
//   ==================================================================
function objeto(){
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
////                      Funcion para situar un objeto sobre otro                                 ////
///////////////////////////////////////////////////////////////////////////////////////////////////////
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var ret = new Array(curleft,curtop);
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
////               Funcion para situar una capa sobre otra con desplazamiento x e y                ////
///////////////////////////////////////////////////////////////////////////////////////////////////////
function situa_capa(kual,donde,dondex,dondey){
	var obj = document.getElementById(kual);
	var obj_donde = document.getElementById(donde);
	
	var xy = findPos(obj_donde);
	
	if (dondex!=-1){
		obj.style.left = (xy[0]+dondex) + 'px';
	}
	if (dondey!=-1){
		obj.style.top = (xy[1]+dondey) + 'px';
	}
}
function descargar (str)
{
if (confirm("Es necesario solicitar la clave de registro temporal para el funcionamiento del programa.")){
 pageTracker._trackPageview(str);
 document.location=str;
} else return false;
}

