// Initialise the panel vars
var mdePanel = "";
var puePanel = "";
var topPanel = "";


//This assigns the onclick actions to the button on the page
//Innitialize the YAHOO Panel
function initIndex()
{
	var event = YAHOO.util.Event;
	
	event.addListener('mde', 'click', ShowModeEmploi);
	event.addListener('pue', 'click', ShowPropEven);
	event.addListener('zlpd','click', ShowPlusDeman);
	
	if(isPostback){
		document.getElementById("msg").style.display = "block";
	}
	
	//$("input[@type=text]").click(function(){
	//		$(this).setValue("").addClass("active_input");
	//	})
	YAHOO.util.Event.addListener("txtEvent", "click", function(){ 
			document.getElementById("txtEvent").style.color = "black";
		});
}

//Show the YAHOO Panel with the Mode d'emploi content
function ShowModeEmploi()
{
	// if the panel exists, we destroy it. 
	if(mdePanel == ""){ 
		mdePanel = new YAHOO.widget.Panel('info_box',{
			width: "907px",
			height: "302px",
			close: true,	
			draggable: false,
			underlay: "shadow"
		});
	}
	mdePanel.render(document.getElementById('carte_cont'));
	$( '#info_box' ).addClass( 'campagne' );
	mdePanel.show();
	
	YAHOO.util.Event.addListener(document.getElementById("fermer_aide"), "click", function(){mdePanel.hide()});

	var rendered_panel_c = document.getElementById("info_box_c");
	rendered_panel_c.style.bottom = "115px";
	rendered_panel_c.style.left =  "3px";
	mdePanel.subscribe("hide",function (){if(!markers_init){loading();load_markers();}});
	$('#info_box .hd').click( function( ){ mdePanel.hide( ); } ).css( { cursor: 'pointer' } );
	$('#info_box .bd').click( function( ){ mdePanel.hide( ); } ).css( { cursor: 'pointer' } );
}
// Shows the YAHOO panel with the Proposer un évènement content
function ShowPropEven()
{

	YAHOO.util.Event.addListener("soum", "click", SendEvent);

	// if the panel exists, we destroy it. 
	if(puePanel == ""){ 
		puePanel = new YAHOO.widget.Panel('pue_box',{
			width: "392px",
			height: "250px",
			close: true,	
			draggable: false,
			underlay: "none"
		});
	}

	puePanel.setHeader("");
	puePanel.render(document.getElementById('carte_cont'));
	puePanel.show();
    $( '#pue_box' ).css('display', 'block' );
	var rendered_panel_c = document.getElementById("pue_box_c");
	rendered_panel_c.style.bottom = "200px";
	rendered_panel_c.style.left =  "280px";

}

// Shows the YAHOO panel with the Proposer un évènement content
function ShowPlusDeman()
{
	//if(topPanel != ""){ topPanel.hide; topPanel.destroy();}
	//YAHOO.util.Event.addListener("soum", "click", SendEvent);

	// if the panel exists, we destroy it. 
	if(topPanel == ""){ 
		topPanel = new YAHOO.widget.Panel('top_box',{
			width: "250px",
			height: "495px",
			close: true,
			draggable: false,
			underlay: "none"
		});
	}

	topPanel.setBody(top_zap_content);
	//topPanel.render(document.getElementById('carte_cont'));
	$( '#top_box' ).css('display', 'block' );
	topPanel.show();

	var rendered_panel_c = document.getElementById("top_box_c");
	rendered_panel_c.style.right = "0";
	rendered_panel_c.style.top =  "0";
}

function SendEvent()
{
	var callback = {success: Success}
	var transaction = YAHOO.util.Connect.asyncRequest('GET', url_root+"soumevent.php?event=" + escape(document.getElementById("txtEvent").value), callback, null); 
}

function Success(e)
{
	puePanel.setBody(e.responseText);
}

function DoneVoting()
{
	var courriel 	= document.getElementById('courriel').value;
	var cp 		= document.getElementById('codepostal').value;
	var ref 	= document.getElementById('ref').value;
	soumettreVotes(courriel,cp,ref);
}

function ConfirmVoting()
{
	var panel = new YAHOO.widget.Panel('ident_user', {
				width: "390px",
				height: "350px",
				close: true,
				draggable: false,
				fixedcenter: true,
				modal: true,
				underlay: "none"
		});
	document.getElementById("ident_user").style.zIndex = 11;
	panel.render();
	panel.show();
	document.getElementById("ident_user").style.display = "block";
	panel.body.style.height = "200px";
	//panel.cfg.setProperty("fixedcenter", true);
	document.getElementById('ident_user_mask').style.zIndex = 4;

}

function soum_votes()
{
soumettreVotes(
	document.getElementById('courriel').value,
	document.getElementById('codepostal').value,
	document.getElementById('ref').value);
}

YAHOO.util.Event.onDOMReady(initIndex);

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
 