animatedcollapse.ontoggle=function($, divobj, state){
 if (divobj.id=="paso2"){ //if "peter" DIV is being toggled
  if (state=="block") //if div is expanded
   document.getElementById('ajax_form').style.visibility='visible';
   document.getElementById('paso2_continuar').style.visibility="visible"
  }
  if (divobj.id=="paso3"){ //if "peter" DIV is being toggled
  if (state=="block") //if div is expanded
   document.getElementById('paso3_continuar').style.visibility="visible"
  }
  if (divobj.id=="paso4"){ //if "peter" DIV is being toggled
  if (state=="block") //if div is expanded
   document.getElementById('paso4_continuar').style.visibility="visible"
  }
}

function valEmail(valor){ 
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}

function valida_form(){
	if(document.form_orzamento.nome){
		nome = document.form_orzamento.nome.value.replace(/ /gi, "");
		if (nome.length==0){
			error=1;
			document.form_orzamento.nome.style.border="1px solid #FF0000";
		}else{
			document.form_orzamento.nome.style.border="1px solid #C7D0F8";
		}
	}
	
	if(document.form_orzamento.razon){
		razon = document.form_orzamento.razon.value.replace(/ /gi, "");
		if (razon.length==0){
			error=1;
			document.form_orzamento.razon.style.border="1px solid #FF0000";
		}else{
			document.form_orzamento.razon.style.border="1px solid #C7D0F8";
		}
	}
	
	if(document.form_orzamento.email){
		email = document.form_orzamento.email.value;
		if (!valEmail(email)){
			error=1;
			document.form_orzamento.email.style.border="1px solid #FF0000";
		}else{
			document.form_orzamento.email.style.border="1px solid #C7D0F8";
		}
	}
	
	if(document.form_orzamento.telefono){
		telefono = document.form_orzamento.telefono.value.replace(/ /gi, "");
		if (telefono.length==0){
			error=1;
			document.form_orzamento.telefono.style.border="1px solid #FF0000";
		}else{
			document.form_orzamento.telefono.style.border="1px solid #C7D0F8";
		}
	}
	if(document.form_orzamento.pcontacto){
		pcontacto = document.form_orzamento.pcontacto.value.replace(/ /gi, "");
		if (pcontacto.length==0){
			error=1;
			document.form_orzamento.pcontacto.style.border="1px solid #FF0000";
		}else{
			document.form_orzamento.pcontacto.style.border="1px solid #C7D0F8";
		}
	}
	
}
function cierra_alerta(){
	document.getElementById('alerta').style.display="none";
}
function cierra_alerta_descripcion(){
	document.getElementById('alerta_descripcion').style.display="none";
}
function paso2(perfil,idioma){
	switch(perfil){
		case "particular":
			document.getElementById('alerta').style.height="185px";
			break;
		default:
			document.getElementById('alerta').style.height="220px";
			break;
	}
	if (perfil_actual != perfil){
		MostrarConsulta('consulta.php',perfil,idioma);
		document.getElementById('ajax_form').style.visibility='hidden';
		animatedcollapse.hide('paso3');
		animatedcollapse.hide('paso4');
		animatedcollapse.hide('paso2');
		animatedcollapse.show('paso2');
	}
	perfil_actual=perfil;
	document.form_orzamento.perfil.value=perfil;
}

function paso3(){
	error=0;
	
	valida_form();
	
	
	if(error==0){
		animatedcollapse.show('paso3');
		document.getElementById('paso2_continuar').style.visibility="hidden";
	}else{
		//alert("Se han detectado errores durante la validacón del formulario.\n\nPor favor revise los campos en rojo e intentelo de nuevo.");
		document.getElementById('alerta').style.display="block";
	}
}
function paso4(){
	animatedcollapse.show('paso4');
	document.getElementById('paso3_continuar').style.visibility="hidden"
}

function objetoAjax(){
        var xmlhttp=false;
        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;

}

 

function MostrarConsulta(datos,perfil,idioma){

        divResultado = document.getElementById('ajax_form');

        ajax=objetoAjax();

        ajax.open("GET", datos+"?idioma="+idioma+"&perfil="+perfil);

        ajax.onreadystatechange=function() {

               if (ajax.readyState==4) {

                       divResultado.innerHTML = ajax.responseText

               }

        }

        ajax.send(null)

}

function valida_todo(){
	error=0;
	valida_form();
	
	if(error==1){
		document.getElementById('alerta').style.display="block";
	}else{
		valida_descripcion();
	}
}

function valida_descripcion(){
	if(document.form_orzamento.descripcion){
		descripcion = document.form_orzamento.descripcion.value.replace(/ /gi, "");
		if (descripcion.length==0){
			error=1;
			document.getElementById('alerta_descripcion').style.display="block";
		}else{
			document.form_orzamento.submit();
		}
	}
}
