var xmlhttp = false;
 
try{
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    //alert ("Estas usando Internet Explorer");
}catch (e){
    try{
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      //  alert ("Estas usando Internet Explorer");
    }catch (E){
        xmlhttp = false;
    }
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    xmlhttp = new XMLHttpRequest();
    //alert ("Estas usando Mozilla Firefox");
}
function makerequest(serverPage, objID) {
    var obj = document.getElementById(objID);
	document.getElementById(objID).innerHTML = "<img src='/img/carrega.gif' border=0>";
    xmlhttp.open("GET", serverPage,true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {		
        document.getElementById(objID).innerHTML = xmlhttp.responseText;
    }
}
xmlhttp.send(null);
}
function makerequest_form(url,formid,objID,url2,objID2){
 var Formulario = document.getElementById(formid);
 var longitudFormulario = Formulario.elements.length;
 var cadenaFormulario = ""
 var sepCampos
 sepCampos = ""
document.getElementById(objID).innerHTML = "<img src='/img/carrega.gif' border=0>";
 for (var i=0; i <= Formulario.elements.length-1;i++) {
 
 campo1=Formulario.elements[i].name;
 if (campo1.substr(0,2)=="S_") {
 	campo1=document.getElementById(campo1);
	var ab="";
 	for (var j=0;j<campo1.length;j++)
  	{
		if (campo1.options[j].selected)
		{
			ab += campo1.options[j].value + '|';
		}
	}
	k=ab.length;
	ab=ab.substr(0,k-1);
	cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(ab);
 } else {
	 cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
 }
 sepCampos="&";
}

  xmlhttp.open("POST", url, true);
  xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  xmlhttp.onreadystatechange = function () {
  if (xmlhttp.readyState == 4) {
     document.getElementById(objID).innerHTML = xmlhttp.responseText;
}
}
//alert(cadenaFormulario);
xmlhttp.send(cadenaFormulario);
if(url2){
makerequest(url2,objID2);
}
}
function DesplegaMenu(idCapa,totalCapes){
	alert('aa');
	document.getElementById(idCapa).style.display='';
}

function campobligatori(formid,accepta) {	
var Formulario = document.getElementById(formid);
var longitudFormulario = Formulario.elements.length;

 for (var i=0; i <= Formulario.elements.length-1;i++) {
	estil=Formulario.elements[i].className;	
	if ((estil=="obligatori" || estil=="obligatoridata") && (Formulario.elements[i].value=="")) {
		alert("Falten camps obligatoris!");
		Formulario.elements[i].focus();	
		enviar=0;
		break;
 	} else {
		enviar=1;
	}
 }
 if (accepta=="true") {
	 if (Formulario.accepta.checked==false) {
  	 	alert("Accepti les condicions de privacitat de dades!");		
		enviar=0;
	 }
 }
	 
 if (enviar==1) { 	 
		 Formulario.submit(); 
 }
}
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
function slideSwitch2() {
    var $active = $('#slideshow2 IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow2 IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow2 IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
function slideSwitch3() {
    var $active = $('#slideshow3 IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow3 IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow3 IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
function init_form(){
$('#form_contacte').submit(function(e){
		e.preventDefault();
		var seguir=1;
		$("#form_contacte").find(':input').each(function() {
			if (this.value=="") {
				seguir=0;
				alert('Els camps amb * són obligatoris');
				this.focus();
				return false;
			}
		});
		if (seguir==1) {
			$.ajax({//captcha
				type: "POST",
				url: "/securimage/comprova_captcha.php",
				data: $("#form_contacte").serialize(),
				success: function(response){											
					if(response=="correcte"){
						
						$.ajax({
							type: "POST",
							url: "/club/operacions.php",
							data: $("#form_contacte").serialize(),
							success: function(response){											
								$('#resultatsContacte').html(response); 								
							}
						});
					}else{
						alert('Codi de seguretat incorrecte!');
						$("[name=captcha_code]").val("");
						$("[name=captcha_code]").focus();
						var ruta='/securimage/securimage_show.php?' + Math.random();
						$("#captcha").attr("src",ruta);
					}
				}
			});
		}
	});		
}
