//Javascript

/*Preload de alguna imatge*/
pic1 = new Image(56,21); 
pic1.src = "http://www.comerciantspalau.com/ims/loadingAnimation.gif"; 



function opf(url_imagen,titulo,ancho,alto){

 	var img = new Image();

 	img.src = url_imagen;
	win=window.open('','','width='+ancho+',height='+alto+',scrollbars=no,resizable=1,toolbar=0');
	win.document.write ('<html>\n');
	win.document.write (' <head>\n');
	win.document.write ('  <title>'+titulo+'</title>\n');
	win.document.write (' </head>\n');
	win.document.write (' <body onclick="return window.close();" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n');
	win.document.write ('  <img src="' + url_imagen + '" />\n');
	win.document.write (' </body>\n');
	win.document.write ('</html>\n');
	
}

function menu(){


            YAHOO.example.onMenuBarReady = function(p_oEvent) {

                // Animation object

                var oAnim;


                // Utility function used to setup animation for submenus

                function setupMenuAnimation(p_oMenu) {

                    if(!p_oMenu.animationSetup) {

                        var aItems = p_oMenu.getItemGroups();
    
                        if(aItems && aItems[0]) {
    
                            var i = aItems[0].length - 1;
                            var oSubmenu;

                            do {

                                oSubmenu = p_oMenu.getItem(i).cfg.getProperty("submenu");
        
                                if(oSubmenu) {
        
                                    oSubmenu.beforeShowEvent.subscribe(onMenuBeforeShow, oSubmenu, true);
                                    oSubmenu.showEvent.subscribe(onMenuShow, oSubmenu, true);
        
                                }
                            
                            }
                            while(i--);
                        
                        }

                        p_oMenu.animationSetup = true;

                    }

                }


                // "beforeshow" event handler for each submenu of the menu bar

                function onMenuBeforeShow(p_sType, p_sArgs, p_oMenu) {

                    if(oAnim && oAnim.isAnimated()) {
                    
                        oAnim.stop();
                        oAnim = null;
                    
                    }

                    YAHOO.util.Dom.setStyle(this.element, "overflow", "hidden");
                    YAHOO.util.Dom.setStyle(this.body, "marginTop", ("-" + this.body.offsetHeight + "px"));

                }


                // "show" event handler for each submenu of the menu bar

                function onMenuShow(p_sType, p_sArgs, p_oMenu) {

                    oAnim = new YAHOO.util.Anim(
                        this.body, 
                        { marginTop: { to: 0 } },
                        .5, 
                        YAHOO.util.Easing.easeOut
                    );

                    oAnim.animate();

                    var me = this;
                        
                    function onTween() {

                        me.cfg.refireEvent("iframe");
                    
                    }

                    function onAnimationComplete() {

                        YAHOO.util.Dom.setStyle(me.body, "marginTop", ("0px"));
                        YAHOO.util.Dom.setStyle(me.element, "overflow", "visible");

                        setupMenuAnimation(me);

                    }
                    

                    /*
                         Refire the event handler for the "iframe" 
                         configuration property with each tween so that the  
                         size and position of the iframe shim remain in sync 
                         with the menu.
                    */

                    if(this.cfg.getProperty("iframe") == true) {

                        oAnim.onTween.subscribe(onTween);

                    }

                    oAnim.onComplete.subscribe(onAnimationComplete);
                
                }


                // "render" event handler for the menu bar

                function onMenuRender(p_sType, p_sArgs, p_oMenu) {

                    setupMenuAnimation(p_oMenu);

                }


                // Instantiate and render the menu bar

                var oMenuBar = new YAHOO.widget.MenuBar("productsandservices", { autosubmenudisplay:true, hidedelay:750, lazyload:true });


                // Subscribe to the "render" event

                oMenuBar.renderEvent.subscribe(onMenuRender, oMenuBar, true);

                oMenuBar.render();

            }


            // Initialize and render the menu bar when it is available in the DOM

            YAHOO.util.Event.onContentReady("productsandservices", YAHOO.example.onMenuBarReady);

}

function nuevoAjax(){
	var xmlhttp=false; 
	try { 
		// Creación del objeto ajax para navegadores diferentes a Explorer 
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	} catch (e) { 
		// o bien 
		try { 
			// Creación del objet ajax para Explorer 
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { 
			xmlhttp = false; 
		} 
	} 

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
		xmlhttp = new XMLHttpRequest(); 
	}
	
	return xmlhttp; 
}

function mostra_associat(id){

	window.parent.myLightWindow.deactivate();
	
}

function comprova_solicitud(form){

	if(form.nom.value.length==0){ alert("Nom buit");document.form.nom.focus();return false;}
	//if(form.telf.value.length==0){ alert("Telèfon buit");document.form.telf.focus();return false;}
	
	return true;

}

function comprovaInscripcio(form){

	if(form.nomComerc.value.length==0){ alert("Nom del comerç buit");  form.nomComerc.focus();return false;}
	if(form.adreca.value.length==0){ alert("Ompli l' adreça"); form.adreca.focus();return false;}
	if(form.cif.value.length==0){ alert("Omplir el CIF del comerç"); form.cif.focus();return false;}
	if(form.activitat.value.length==0){ alert("Ompli l' activitat a la que es dedica el comerç"); form.activitat.focus();return false;}
	if(form.responsable.value.length==0){ alert("Ompli el camp del titular"); form.responsable.focus();return false;}
	if(form.telfComerc.value.length==0){ alert("Ompli el camp telèfon"); form.telfComerc.focus();return false;}
	
	if(form.entitat.value.length!=4){ alert("La entitat no es correcte."); form.entitat.focus();return false;}
	if(form.oficina.value.length!=4){ alert("La oficina no es correcte"); form.oficina.focus();return false;}
	if(form.dc.value.length!=2){ alert("El digit de control no es correcte."); form.dc.focus();return false;}
	if(form.cc.value.length!=10){ alert("El nombre de compte corrent no es correcte."); form.cc.focus();return false;}
	
	return true;

}

function loader(){

	if(document.all == undefined){
		document.getElementById('loader').style.height = "100%";
	}
	
	document.body.style.overflow	=	'hidden';
	document.getElementById('loader').style.visibility 	= "visible";
	document.getElementById('loader').innerHTML 		= "<table align='center' cellpadding=0 cellspacing=0 height='80' width='300' style='border:3px solid black;background-color:white;z-index:100' cellpadding='0' cellspacing='0'><tr><td align='center'><img src='ims/ajax-loader.gif' name='img1'></td><td align='center'><b>Enviant, si us plau esperi...</b></td></tr></table>";

}

function end_preload(){

	document.getElementById('loader').style.opacity = "hidden";

}
