var ajax=null;
var bloqueo=false;
var bloqueo_portfolio=false;
var altura_cuerpo;
var alturaEncabezadoPie=450;
var estado=false;
var scroll_seccion=false;
var scroll_opcion=null;
var scroll_velocidad=3;



window.onresize = function()
{
	if(document.documentElement.clientHeight && estado==false)
	{
	document.getElementById("regulador").style.height=(document.documentElement.clientHeight-alturaEncabezadoPie)+"px";
	altura_cuerpo=document.documentElement.clientHeight-alturaEncabezadoPie;
	}else if(estado==false){
	document.getElementById("regulador").style.height=(window.innerHeight-alturaEncabezadoPie)+"px";
	altura_cuerpo=window.innerHeight-alturaEncabezadoPie;
	}
}



function crear_ajax()
{	//Cargamos codigo para boton compartir de facebook
	//incluir_javascript("http://static.ak.fbcdn.net/connect.php/js/FB.Share");
	//Cargamos codigo para boton compartir de Twitter
	//incluir_javascript("http://platform.twitter.com/widgets.js");
try
{
ajax=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
//Si no, utilizar el antiguo objeto ActiveX.
try
{
ajax=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
//Si no, debemos estar utilizando un navegador que no es IE.
ajax=false;
}
}
//Si no estamos usando IE, creamos una instancia JavaScript del objeto.
if(!ajax && typeof XMLHttpRequest!="undefined")
{
ajax=new XMLHttpRequest();
}
}

//Procesar peticiones AJAX
function procesar_ajax(pagina,objeto,getorpost,datos)
{
	if (ajax==null)
	{
		objeto=document.getElementById(objeto);
		crear_ajax();
	if(getorpost=="get")
	{
		ajax.open("GET",pagina);
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=ISO-8859-1");
		ajax.onreadystatechange=function(){
		if(ajax.readyState==4 && ajax.status==200)
		{
			if(objeto){objeto.innerHTML=ajax.responseText;}
			ajax=null;
			bloqueo=false;
		}
		}
		ajax.send(null);
	}else{
		ajax.open("POST",pagina);
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=ISO-8859-1");
		ajax.onreadystatechange=function(){
		if(ajax.readyState==4 && ajax.status==200)
		{
			if(objeto){objeto.innerHTML=ajax.responseText;}
			ajax=null;
			bloqueo=false;
		}
		}
		ajax.send(datos);
	}
	}else{    
	setTimeout("procesar_ajax('"+pagina+"','"+objeto+"','"+getorpost+"','"+datos+"')",10);
	}
}

function obtener_datos_formulario(formulario)
{
	var str="";
	var valor="";
	for(var i=0;i<formulario.elements.length;i++)
	{
		if(formulario.elements[i].type=="radio")
		{
			if(formulario.elements[i].checked==true){str+=formulario.elements[i].name + "=" + escape(formulario.elements[i].value) + "&";}
		}else if(formulario.elements[i].type=="checkbox"){
			if(formulario.elements[i].checked==true){str+=formulario.elements[i].name + "=" + escape(formulario.elements[i].value) + "&";}
		}else if(formulario.elements[i].type!="button" && formulario.elements[i].type!="submit"){
		if(escape(formulario.elements[i].value)==""){valor=" ";}else{valor=escape(formulario.elements[i].value);}
		str+=formulario.elements[i].name + "=" + valor + "&";
		}
	}
	return str;
}


function menu(boton,id)
{
if(bloqueo==false)
{
bloqueo=true;
estado=true;

vaciar_contenido();

if(boton!="gestionar_portfolio" && boton!="gestionar_presupuestos")
{
login_ocultar(boton,700);
//ocultar(boton);
//regulador(700,boton);
//contraer(boton);
//expandir(boton);
//posicion_principal(boton)
//iconos(boton,null);
}else{
login_ocultar(boton,870,id);
//regulador(870,boton);
//contraer(boton);
//iconos(boton,null);
}
}

}


function posicion_principal(boton)
{
var control=false;

if(parseInt(document.getElementById(boton).style.top)>20  && parseInt(document.getElementById(boton).style.left)==180)
{
document.getElementById(boton).style.top=(parseInt(document.getElementById(boton).style.top)-10)+"px";
control=true;
}
if(parseInt(document.getElementById(boton).style.left)!=180)
{
if(parseInt(document.getElementById(boton).style.left)<180)
{
document.getElementById(boton).style.left=(parseInt(document.getElementById(boton).style.left)+10)+"px";
control=true;
}else{
document.getElementById(boton).style.left=(parseInt(document.getElementById(boton).style.left)-10)+"px";
control=true;
}
}
if(control==true){setTimeout(function(){posicion_principal(boton);},15);}else{expandir(boton);}
}


function regulador(limite,boton,id)
{
var control=false;

if(parseInt(document.getElementById("regulador").style.height)<limite)
{
document.getElementById("regulador").style.height=(parseInt(document.getElementById("regulador").style.height)+20)+"px";
if(parseInt(document.getElementById("regulador").style.height)>limite){document.getElementById("regulador").style.height=limite+"px";}
control=true;
}
if(parseInt(document.getElementById("regulador").style.height)>limite && altura_cuerpo<parseInt(document.getElementById("regulador").style.height))
{
document.getElementById("regulador").style.height=(parseInt(document.getElementById("regulador").style.height)-20)+"px";
if(parseInt(document.getElementById("regulador").style.height)<limite){document.getElementById("regulador").style.height=limite+"px";}
control=true;
}
if(control==true){setTimeout(function(){regulador(limite,boton,id);},15);}else{if(boton!=null){contraer(boton,id);}}
}


function contraer(boton,id)
{
var i,control=false;

for(i=1;i<=5;i++)
{
if(parseInt(document.getElementById("boton"+i).style.width)>150 && document.getElementById("boton"+i).id!=boton)
{
document.getElementById("boton"+i).style.width=(parseInt(document.getElementById("boton"+i).style.width)-30)+"px";
document.getElementById("anchura"+i).style.width=(parseInt(document.getElementById("anchura"+i).style.width)-30)+"px";
control=true;
}
if(parseInt(document.getElementById("boton"+i).style.height)>150 && document.getElementById("boton"+i).id!=boton)
{
document.getElementById("boton"+i).style.height=(parseInt(document.getElementById("boton"+i).style.height)-30)+"px";
document.getElementById("altura_izq"+i).style.height=(parseInt(document.getElementById("altura_izq"+i).style.height)-30)+"px";
document.getElementById("altura_der"+i).style.height=(parseInt(document.getElementById("altura_der"+i).style.height)-30)+"px";
control=true;
}
}
if(control==true){setTimeout(function(){contraer(boton,id);},15);}else{iconos(boton,id);if(boton!="gestionar_portfolio" && boton!="gestionar_presupuestos"){posicion_principal(boton);}}
}


function expandir(boton)
{
var control=false;

if(parseInt(document.getElementById(boton).style.width)<810)
{
document.getElementById(boton).style.width=(parseInt(document.getElementById(boton).style.width)+30)+"px";
document.getElementById("anchura"+boton.substr(boton.length-1,1)).style.width=(parseInt(document.getElementById("anchura"+boton.substr(boton.length-1,1)).style.width)+30)+"px";
control=true;
}
if(parseInt(document.getElementById(boton).style.height)<660)
{
document.getElementById(boton).style.height=(parseInt(document.getElementById(boton).style.height)+30)+"px";
document.getElementById("altura_izq"+boton.substr(boton.length-1,1)).style.height=(parseInt(document.getElementById("altura_izq"+boton.substr(boton.length-1,1)).style.height)+30)+"px";
document.getElementById("altura_der"+boton.substr(boton.length-1,1)).style.height=(parseInt(document.getElementById("altura_der"+boton.substr(boton.length-1,1)).style.height)+30)+"px";
control=true;
}

if(control==true){setTimeout(function(){expandir(boton);},15);}else{/*bloqueo=false;*/subir(330,boton);}
}


function iconos(boton,id)
{
var i,j,posicion_y=20,control,control2,botones=new Array();

if(boton!="gestionar_portfolio" && boton!="gestionar_presupuestos")
{
posicion_y=20;

for(i=1;i<=5;i++)
{
if(document.getElementById("boton"+i).id!=boton && parseInt(document.getElementById("boton"+i).style.left)>10 && parseInt(document.getElementById("boton"+i).style.top)==posicion_y)
{
document.getElementById("boton"+i).style.left=(parseInt(document.getElementById("boton"+i).style.left)-10)+"px";
control=true;
}
if(document.getElementById("boton"+i).id!=boton){posicion_y+=170;}
}

for(i=1;i<=5;i++)
{
posicion_y=20;

for(j=1;j<=5;j++)
{
control2=false;
if(document.getElementById("boton"+j).id!=boton && parseInt(document.getElementById("boton"+j).style.top)>posicion_y && control2==false)
{
document.getElementById("boton"+j).style.top=(parseInt(document.getElementById("boton"+j).style.top)-10)+"px";
control2=true;
control=true;
}
if(document.getElementById("boton"+j).id!=boton && parseInt(document.getElementById("boton"+j).style.top)<posicion_y && control2==false)
{
document.getElementById("boton"+j).style.top=(parseInt(document.getElementById("boton"+j).style.top)+10)+"px";
control2=true;
control=true;
}
if(document.getElementById("boton"+j).id!=boton){posicion_y+=170;}
}
}
if(control==true){setTimeout(function (){iconos(boton);},15);}else{/*expandir(boton);posicion_principal(boton);*/}
}else{

posicion_y=20;

for(i=1;i<=5;i++)
{
if(parseInt(document.getElementById("boton"+i).style.left)>10 && parseInt(document.getElementById("boton"+i).style.top)==posicion_y)
{
document.getElementById("boton"+i).style.left=(parseInt(document.getElementById("boton"+i).style.left)-10)+"px";
control=true;
}
posicion_y+=170;
}

for(i=1;i<=5;i++)
{
posicion_y=20;

for(j=1;j<=5;j++)
{
control2=false;
if(document.getElementById("boton"+j).id!=boton && parseInt(document.getElementById("boton"+j).style.top)>posicion_y && control2==false)
{
document.getElementById("boton"+j).style.top=(parseInt(document.getElementById("boton"+j).style.top)-10)+"px";
control2=true;
control=true;
}
if(document.getElementById("boton"+j).id!=boton && parseInt(document.getElementById("boton"+j).style.top)<posicion_y && control2==false)
{
document.getElementById("boton"+j).style.top=(parseInt(document.getElementById("boton"+j).style.top)+10)+"px";
control2=true;
control=true;
}
if(document.getElementById("boton"+j).id!=boton){posicion_y+=170;}
}
}
if(control==true){setTimeout(function (){iconos(boton,id);},15);}else{/*bloqueo=false;*/subir(400,boton,id);}
}
}


function galeria_portfolio(num,opcion)
{
	if(bloqueo_portfolio==false)
	{
		bloqueo_portfolio=true;
		ocultar_imagen_portfolio(num,opcion)
	}
}


function ocultar_imagen_portfolio(num,opcion)
{
	var control=false;
	var extension;
	var numero;

	if(opcion=="mas"){numero=num-1;}else{numero=num+1;}
	if(document.getElementById("imagen"+(num)))
	{
	extension=document.getElementById("imagen"+(num)).src.split(".");
	extension=extension[extension.length-1].toLowerCase();
	}else{
	extension="nada";	
	}
	
	if(extension=="jpg" || extension=="jpeg")
	{
	if(document.getElementById("imagen"+(numero)).filters)
	{
		if(document.getElementById("imagen"+(numero)).filters.alpha.opacity>0 && document.getElementById("imagen"+(numero)).style.opacity>0)
		{
		document.getElementById("imagen"+(numero)).filters.alpha.opacity-=15;
		control=true;
		}
	}
	if(document.getElementById("imagen"+(numero)).style.MozOpacity>0)
	{
		document.getElementById("imagen"+(numero)).style.MozOpacity=(Math.round(parseFloat(document.getElementById("imagen"+(numero)).style.MozOpacity)*100)/100)-0.2;
		control=true;
	}
	if(document.getElementById("imagen"+(numero)).style.opacity>0)
	{
		document.getElementById("imagen"+(numero)).style.opacity=(Math.round(parseFloat(document.getElementById("imagen"+(numero)).style.opacity)*100)/100)-0.2;
		//document.getElementById("boton_menu").style.MozOpacity=(Math.round(parseFloat(document.getElementById("boton_menu").style.MozOpacity)*100)/100)+0.2;
		control=true;
	}
	if(control==true){setTimeout(function (){ocultar_imagen_portfolio(num,opcion);},15);}else{document.getElementById("imagen"+(num)).style.display="inline";document.getElementById("imagen"+(numero)).style.display="none";mostrar_imagen_portfolio(num);}
	}else{
		bloqueo_portfolio=false;
	}
}

function mostrar_imagen_portfolio(num)
{
	var control=false;
	
	if(document.getElementById("imagen"+(num)).filters)
	{
		if(document.getElementById("imagen"+(num)).filters.alpha.opacity<100 && document.getElementById("imagen"+(num)).style.opacity<1)
		{
		document.getElementById("imagen"+(num)).filters.alpha.opacity+=15;
		control=true;
		}
	}
	if(document.getElementById("imagen"+(num)).style.MozOpacity<1)
	{
		document.getElementById("imagen"+(num)).style.MozOpacity=(Math.round(parseFloat(document.getElementById("imagen"+(num)).style.MozOpacity)*100)/100)+0.2;
		control=true;
	}
	if(document.getElementById("imagen"+(num)).style.opacity<1)
	{
		document.getElementById("imagen"+(num)).style.opacity=(Math.round(parseFloat(document.getElementById("imagen"+(num)).style.opacity)*100)/100)+0.2;
		//document.getElementById("boton_menu").style.MozOpacity=(Math.round(parseFloat(document.getElementById("boton_menu").style.MozOpacity)*100)/100)+0.2;
		control=true;
	}
	if(control==true){setTimeout(function (){mostrar_imagen_portfolio(num);},15);}else{document.getElementById("siguiente").innerHTML="<a href='javascript://' onclick=\"galeria_portfolio("+(num+1)+",'mas');\"><div class='boton_portfolio' style='float:right;width:20%;height:40px'><img src='diseno/flecha_derecha.png' style='margin-top:7px'></div></a>";document.getElementById("anterior").innerHTML="<a href='javascript://' onclick=\"galeria_portfolio("+(num-1)+",'menos');\"><div class='boton_portfolio' style='float:left;width:20%;height:40px'><img src='diseno/flecha_izquierda.png' style='margin-top:7px'></div></a>";document.getElementById("num_imagen").innerHTML=num;bloqueo_portfolio=false;}
}


function mostrar(boton,id)
{
	var control=false;

	document.getElementById("boton_menu").style.display="block";
	if(document.getElementById("boton_menu").filters)
	{
		if(document.getElementById("boton_menu").filters.alpha.opacity<100 && document.getElementById("boton_menu").style.opacity<1)
		{
		document.getElementById("boton_menu").filters.alpha.opacity+=15;
		control=true;
		}
	}
	if(document.getElementById("boton_menu").style.MozOpacity<1)
	{
		document.getElementById("boton_menu").style.MozOpacity=(Math.round(parseFloat(document.getElementById("boton_menu").style.MozOpacity)*100)/100)+0.2;
		control=true;
	}
	if(document.getElementById("boton_menu").style.opacity<1)
	{
		document.getElementById("boton_menu").style.opacity=(Math.round(parseFloat(document.getElementById("boton_menu").style.opacity)*100)/100)+0.2;
		//document.getElementById("boton_menu").style.MozOpacity=(Math.round(parseFloat(document.getElementById("boton_menu").style.MozOpacity)*100)/100)+0.2;
		control=true;
	}
	if(control==true){setTimeout(function (){mostrar(boton,id);},15);}else{
		if(boton=="gestionar_portfolio")
		{
		document.title="Gestionar Portfolio | Cyrux";
		procesar_ajax("gestionar_portfolio.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"","contenido_menu","get");
		}
		if(boton=="gestionar_presupuestos" && !id)
		{
		document.title="Gestionar Presupuestos | Cyrux";
		procesar_ajax("gestionar_presupuestos.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"","contenido_menu","get");
		}
		if(boton=="gestionar_presupuestos" && id)
		{
		document.title="Presupuesto | Cyrux";
		procesar_ajax("ver_presupuesto.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&id="+id+"","contenido_menu","get");
		}
		}
}


function ocultar(boton,regular,id)
{	
	var control=false;

	if(document.getElementById("boton_menu").filters)
	{
		if(document.getElementById("boton_menu").filters.alpha.opacity>0 && document.getElementById("boton_menu").style.opacity>0)
		{
		document.getElementById("boton_menu").filters.alpha.opacity-=15;
		control=true;
		}
	}
	if(document.getElementById("boton_menu").style.MozOpacity>0)
	{
		document.getElementById("boton_menu").style.MozOpacity=(Math.round(parseFloat(document.getElementById("boton_menu").style.MozOpacity)*100)/100)-0.2;
		control=true;
	}
	if(document.getElementById("boton_menu").style.opacity>0)
	{
		document.getElementById("boton_menu").style.opacity=(Math.round(parseFloat(document.getElementById("boton_menu").style.opacity)*100)/100)-0.2;
		//document.getElementById("boton_menu").style.MozOpacity=(Math.round(parseFloat(document.getElementById("boton_menu").style.MozOpacity)*100)/100)+0.2;
		control=true;
	}
	if(control==true){setTimeout(function (){ocultar(boton,regular,id);},15);}else{document.getElementById("boton_menu").style.display="none";document.getElementById("contenido_menu").innerHTML="";regulador(regular,boton,id);}
}

function altura_cuerpo()
{
if(document.documentElement.clientHeight)
{
document.getElementById("regulador").style.height=(document.documentElement.clientHeight-alturaEncabezadoPie)+"px";
altura_cuerpo=document.documentElement.clientHeight-alturaEncabezadoPie;
}else{
document.getElementById("regulador").style.height=(window.innerHeight-alturaEncabezadoPie)+"px";
altura_cuerpo=window.innerHeight-alturaEncabezadoPie;
}
}

function subir(limite,boton,id)
{
	var altura,control=false;
	
	if(document.documentElement.clientHeight)
	{
		altura=document.documentElement.clientHeight;
	}else{
		altura=window.innerHeight;
	}

		if(scrollactual()<limite-10 && altura<800)
		{
			control=true;
			window.scrollTo(0,scrollactual()+((limite-scrollactual())*0.3));
			setTimeout(function (){subir(limite,boton,id);},10);
		}
		if(scrollactual()>limite+10 && altura<800)
		{
			control=true;
			window.scrollTo(0,scrollactual()-((limite+scrollactual())*0.05));
			setTimeout(function (){subir(limite,boton,id);},10);
		}

		if(control==false)
		{
			if(boton=="gestionar_portfolio" || boton=="gestionar_presupuestos"){mostrar(boton,id);}else{cargar_contenido(boton);}
		}
		//window.scrollTo(0,0);  	

}//window.scrollTo(0,scrollactual()-(scrollactual()*0.2));


function scrollactual() {
    // Firefox, Chrome, Opera, Safari
    if (self.pageYOffset) return self.pageYOffset;
    // Internet Explorer 6 - standards mode
    if (document.documentElement && document.documentElement.scrollTop)
        return document.documentElement.scrollTop;
    // Internet Explorer 6, 7 and 8
    if (document.body.scrollTop) return document.body.scrollTop;
    return 0;
}



function login_mostrar()
{
	var control=false;
	bloqueo=true;
	
	if(parseInt(document.getElementById("login").style.right)<0)
	{
		//document.getElementById("login_cuerpo").style.display="block";
		document.getElementById("login").style.right=(parseInt(document.getElementById("login").style.right)+10)+"px";
		//document.getElementById("login_cuerpo").style.right=(parseInt(document.getElementById("login_cuerpo").style.right)+10)+"px";
		control=true;
	}
	if(control==true){setTimeout(function (){login_mostrar();},15);}else{document.getElementById("login_boton").innerHTML="<a class='linkmenu' href='javascript://' onclick=\"login_ocultar(false,'null')\"><img src='diseno/flecha_derecha.png'/></a>";bloqueo=false;}
}

function login_ocultar(boton,regular,id)
{
	var control=false;

	if(parseInt(document.getElementById("login").style.right)>-170)
	{
		document.getElementById("login").style.right=(parseInt(document.getElementById("login").style.right)-10)+"px";
		//document.getElementById("login_cuerpo").style.right=(parseInt(document.getElementById("login_cuerpo").style.right)-10)+"px";
		control=true;
	}
	if(control==true){setTimeout(function (){login_ocultar(boton,regular,id);},15);}else{document.getElementById("login_boton").innerHTML="<a class='linkmenu' href='javascript://' onclick=\"login_mostrar()\"><img src='diseno/flecha_izquierda.png'/></a>";
	//document.getElementById("login_cuerpo").style.display="none";
	if(boton!=false){ocultar(boton,regular,id);}
	}
}

function cargar_contenido(boton)
{
	vaciar_contenido();

	if(boton=="boton1")
	{
		document.title="Qué es Cyrux | Cyrux";
		document.getElementById("titulo1").innerHTML="<h1>Qué es Cyrux</h1>";
		document.getElementById("titulo1").style.background="url(diseno/fondotituloseccion2.png) no-repeat center center";
		procesar_ajax("que_es_cyrux.php?altura="+parseInt(document.getElementById(boton).style.height)+"","contenido1","get");
	}
	if(boton=="boton2")
	{
		document.title="Diseño | Cyrux";
		document.getElementById("titulo2").innerHTML="<h1>Diseño</h1>";	
		document.getElementById("titulo2").style.background="url(diseno/fondotituloseccion2.png) no-repeat center center";
		procesar_ajax("diseno.php?altura="+parseInt(document.getElementById(boton).style.height)+"","contenido2","get");
	}
	if(boton=="boton3")
	{
		document.title="Programación | Cyrux";
		document.getElementById("titulo3").innerHTML="<h1>Programación</h1>";
		document.getElementById("titulo3").style.background="url(diseno/fondotituloseccion2.png) no-repeat center center";
		procesar_ajax("programacion.php?altura="+parseInt(document.getElementById(boton).style.height)+"","contenido3","get");
	}
	if(boton=="boton4")
	{
		document.title="Portfolio | Cyrux";
		document.getElementById("titulo4").innerHTML="<h1>Portfolio</h1>";
		document.getElementById("titulo4").style.background="url(diseno/fondotituloseccion2.png) no-repeat center center";
		procesar_ajax("portfolio.php?altura="+parseInt(document.getElementById(boton).style.height)+"","contenido4","get");
	}
	if(boton=="boton5")
	{
		document.title="Contacto | Cyrux";
		document.getElementById("titulo5").innerHTML="<h1>Contacto</h1>";
		document.getElementById("titulo5").style.background="url(diseno/fondotituloseccion2.png) no-repeat center center";
		procesar_ajax("contacto.php?altura="+parseInt(document.getElementById(boton).style.height)+"","contenido5","get");
	}		
}

function vaciar_contenido()
{
	document.getElementById("titulo1").innerHTML="";
	document.getElementById("contenido1").innerHTML="";
	document.getElementById("titulo2").innerHTML="";	
	document.getElementById("contenido2").innerHTML="";
	document.getElementById("titulo3").innerHTML="";	
	document.getElementById("contenido3").innerHTML="";
	document.getElementById("titulo4").innerHTML="";	
	document.getElementById("contenido4").innerHTML="";
	document.getElementById("titulo5").innerHTML="";	
	document.getElementById("contenido5").innerHTML="";
}



function scroll_contenido()
{	
	if(scroll_opcion=="abajo" && scroll_seccion==true)
	{
		document.getElementById("seccion").scrollTop=document.getElementById("seccion").scrollTop+scroll_velocidad;
	}
	if(scroll_opcion=="arriba" && scroll_seccion==true)
	{
		document.getElementById("seccion").scrollTop=document.getElementById("seccion").scrollTop-scroll_velocidad;
	}
	setTimeout(function (){scroll_contenido();},15);
}

function iniciar_sesion()
{
	var control=false;
	var str="";

	document.getElementById("Elogin").innerHTML="";

	if(document.login.Luser.value=="" || document.login.Lpass.value=="")
	{
		document.getElementById("Elogin").innerHTML="<span class='letra4' style='color:#ccc'>Introduce usuario y contraseña</span>";
		control=true;
	}

	if(control==false)
	{
	str=obtener_datos_formulario(document.login);
	procesar_ajax("login.php","login_cuerpo","post",str);
	}
}

function cerrar_sesion()
{
	str=obtener_datos_formulario(document.cerrar);
	procesar_ajax("login.php","login_cuerpo","post",str);
	
	if(document.getElementById("contenido_menu").innerHTML!=""){menu('boton1');}
}

function insertar_portfolio()
{
	var control=false;
	var extension;
	document.getElementById("Eportfolio").innerHTML="";
	
	if(document.nuevo_portfolio.Pnombre.value=="")
	{
		document.getElementById("Eportfolio").innerHTML+="El nombre es obligatorio";
		control=true;
	}

	if(document.nuevo_portfolio.Penlace.value=="")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>La URL es obligatoria";
		control=true;
	}

	if(document.nuevo_portfolio.Pimagen1.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen1.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 1 debe ser jpg";
		control=true;
	}
	}else{
		document.getElementById("Eportfolio").innerHTML+="<br>La Imagen 1 es obligatoria";
		control=true;
	}
	if(document.nuevo_portfolio.Pimagen2.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen2.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 2 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen3.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen3.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 3 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen4.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen4.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 4 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen5.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen5.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 5 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen6.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen6.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 6 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen7.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen7.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 7 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen8.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen8.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 8 debe ser jpg";
		control=true;
	}
	}
	if(control==false)
	{
		document.nuevo_portfolio.submit();
	}
}

function gestionar_portfolio(opcion)
{
	procesar_ajax("gestionar_portfolio.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&opcion="+opcion+"","contenido_menu","get");
}

function ver_datos(id)
{	
	var altura;

	//if(document.body.scrollHeight){altura=window.document.documentElement.scrollTop;}else{altura=window.pageYOffset;}
	//alert(altura);
	altura=scrollactual();
	procesar_ajax("ver_datos.php?id="+id+"","formularios","get");
	document.getElementById("fondo_formularios").style.height="100%";
	document.getElementById("fondo_formularios").style.visibility="visible";
	document.getElementById("fondo_formularios").style.marginTop=altura+"px";
	document.getElementById("formularios").style.marginTop=altura+"px";
	document.getElementById("formularios").style.visibility="visible";
	document.body.style.overflow="hidden";
	//subir();
}

function ver_portfolio(id)
{	
	var altura;
	//if(document.body.scrollHeight){altura=window.document.documentElement.scrollTop;}else{altura=window.pageYOffset;}
	//alert(altura);
	altura=scrollactual();

	procesar_ajax("ver_portfolio.php?id="+id+"","formularios","get");
	document.getElementById("fondo_formularios").style.height="100%";
	document.getElementById("fondo_formularios").style.visibility="visible";
	document.getElementById("fondo_formularios").style.marginTop=altura+"px";
	document.getElementById("formularios").style.marginTop=altura+"px";
	document.getElementById("formularios").style.visibility="visible";
	document.body.style.overflow="hidden";
	//subir();
}

function cerrar_formulario()
{
	document.getElementById("formularios").style.height=document.body.clientHeight;
	document.getElementById("formularios").innerHTML="";
	document.getElementById("formularios").style.visibility="hidden";
	document.getElementById("fondo_formularios").style.visibility="hidden";
	document.body.style.overflow="scroll";
}

function modificar_portfolio(id)
{
	subir_div();
	procesar_ajax("gestionar_portfolio.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&modificar="+id+"","nuevo_modificar","get");
}

function subir_div()
{
		if(document.getElementById("seccion").scrollTop!=0)
		{
			document.getElementById("seccion").scrollTop=document.getElementById("seccion").scrollTop-(document.getElementById("seccion").scrollTop*0.2);
			setTimeout(subir_div,10);
		}
}

function cancelar_modificar_portfolio()
{
	procesar_ajax("gestionar_portfolio.php?cancelar=cancelar","nuevo_modificar","get");
}

function validar_modificar_portfolio()
{
	var control=false;
	var extension;
	document.getElementById("Eportfolio").innerHTML="";

	if(document.nuevo_portfolio.Pnombre.value=="")
	{
		document.getElementById("Eportfolio").innerHTML+="El nombre es obligatorio";
		control=true;
	}

	if(document.nuevo_portfolio.Penlace.value=="")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>La URL es obligatoria";
		control=true;
	}

	if(document.nuevo_portfolio.Pimagen1.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen1.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 1 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen2.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen2.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 2 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen3.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen3.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 3 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen4.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen4.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 4 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen5.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen5.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 5 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen6.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen6.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 6 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen7.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen7.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 7 debe ser jpg";
		control=true;
	}
	}
	if(document.nuevo_portfolio.Pimagen8.value!="")
	{
	extension=document.nuevo_portfolio.Pimagen8.value.split(".");
	extension=extension[extension.length-1].toLowerCase();
	if(extension!="jpg" && extension!="jpeg")
	{
		document.getElementById("Eportfolio").innerHTML+="<br>El formato de la Imagen 8 debe ser jpg";
		control=true;
	}
	}
	if(control==false)
	{
		document.nuevo_portfolio.submit();
	}
}

function eliminar_portfolio(id,portfolio)
{
	if (!confirm('¿Seguro que desea eliminar el portfolio "'+portfolio+'"?'))
	{ 
		return false;
	}else{
		procesar_ajax("gestionar_portfolio.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&opcion=eliminar&id="+id+"","contenido_menu","get");
	}
}

function enviar_formulario()
{
	var control=false;
	var str="";

	if(document.contacto.Cnombre.value=="" || document.contacto.Cnombre.style.color=="red")
	{
		document.contacto.Cnombre.value="El nombre es obligatorio";
		document.contacto.Cnombre.style.color="red";
		control=true;
	}
	if(document.contacto.Cemail.value=="" || document.contacto.Cemail.style.color=="red")
	{
		document.contacto.Cemail.value="El e-mail es obligatorio";
		document.contacto.Cemail.style.color="red";
		control=true;
	}
	if(document.contacto.Cmensaje.value=="" || document.contacto.Cmensaje.style.color=="red")
	{
		document.contacto.Cmensaje.value="El mensaje es obligatorio";
		document.contacto.Cmensaje.style.color="red";
		control=true;
	}

	if(control==false)
	{
	str=obtener_datos_formulario(document.contacto);
	procesar_ajax("contacto.php","contenido5","post",str);
	}
}

function gestionar_presupuestos(opcion)
{
	procesar_ajax("gestionar_portfolio.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&opcion="+opcion+"","contenido_menu","get");
}

function insertar_presupuesto()
{
	var control=false;

	document.getElementById("Epresupuesto").innerHTML="";
	
	if(document.nuevo_presupuesto.Pnombre.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML="El nombre es obligatorio";
		control=true;
	}
	if(document.nuevo_presupuesto.Pproyecto.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>El nombre del proyecto es obligatorio";
		control=true;
	}
	if(document.nuevo_presupuesto.Pobjetivo.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>El objetivo es obligatorio";
		control=true;
	}
	if(document.nuevo_presupuesto.Pestructura.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>La estructura propuesta es obligatoria";
		control=true;
	}
	if(document.nuevo_presupuesto.Pfases.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>Las fases y tiempo de desarrollo del proyecto son obligatorias";
		control=true;
	}
	if(document.nuevo_presupuesto.Ptiempo.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>El tiempo de desarrollo es obligatorio";
		control=true;
	}
	if(document.nuevo_presupuesto.Pgarantias.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>Las garantias del proyecto son obligatorias";
		control=true;
	}
	if(document.nuevo_presupuesto.Pcoste.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>El coste es obligatorio";
		control=true;
	}

	if(control==false)
	{
		str=obtener_datos_formulario(document.nuevo_presupuesto);
		procesar_ajax("gestionar_presupuestos.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&opcion=insertado","contenido_menu","post",str);
	}
}

function modificar_presupuesto(id)
{
	subir_div();
	procesar_ajax("gestionar_presupuestos.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&modificar="+id+"","nuevo_modificar","get");
}

function modificar_presupuestos()
{
	var control=false;

	document.getElementById("Epresupuesto").innerHTML="";
	
	if(document.nuevo_presupuesto.Pnombre.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML="El nombre es obligatorio";
		control=true;
	}
	if(document.nuevo_presupuesto.Pproyecto.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>El nombre del proyecto es obligatorio";
		control=true;
	}
	if(document.nuevo_presupuesto.Pobjetivo.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>El objetivo es obligatorio";
		control=true;
	}
	if(document.nuevo_presupuesto.Pestructura.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>La estructura propuesta es obligatoria";
		control=true;
	}
	if(document.nuevo_presupuesto.Pfases.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>Las fases y tiempo de desarrollo del proyecto son obligatorias";
		control=true;
	}
	if(document.nuevo_presupuesto.Ptiempo.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>El tiempo de desarrollo es obligatorio";
		control=true;
	}
	if(document.nuevo_presupuesto.Pgarantias.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>Las garantias del proyecto son obligatorias";
		control=true;
	}
	if(document.nuevo_presupuesto.Pcoste.value=="")
	{
		document.getElementById("Epresupuesto").innerHTML+="<br>El coste es obligatorio";
		control=true;
	}

	if(control==false)
	{
		str=obtener_datos_formulario(document.nuevo_presupuesto);
		procesar_ajax("gestionar_presupuestos.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&opcion=modificado","contenido_menu","post",str);
	}
}

function cancelar_modificar_presupuesto()
{
	procesar_ajax("gestionar_presupuestos.php?cancelar=cancelar","nuevo_modificar","get");
}

function eliminar_presupuesto(id,presupuesto)
{
	if (!confirm('¿Seguro que desea eliminar el presupuesto de "'+presupuesto+'"?'))
	{ 
		return false;
	}else{
		procesar_ajax("gestionar_presupuestos.php?altura="+parseInt(document.getElementById("boton_menu").style.height)+"&opcion=eliminar&id="+id+"","contenido_menu","get");
	}
}

function ver_presupuesto(id)
{
	menu('gestionar_presupuestos',id);
}
