// JavaScript Document

/* 
    Document  	: functions.js
    Created on 	: Jan. 25, 2010,
    Update On	: Jan. 25, 2010, (Rémi Savard)
    Author     	: Rémi Savard, Luis M. Rivas
    Description	: all the javascript functions

*/

$(document).ready(function() {

	/* This is basic - uses default settings */

	//$(".teaserCinema").trigger('click');

	
	$("#votreRegion").change(getCinemas);

	  /*$(".teaserCinema").fancybox({
		'hideOnContentClick': false,
		'titleShow': false
		});*/
		
	$("#selectActions").hide();	
		
							
});


function getCinemas(){
	
	$("#votreCinema").html("<option value='-1'> -- Cinema -- </option>");
	$.post("/wp-content/themes/metropole/code/curl/getCinemas.php",{id : $("#votreRegion option:selected").attr("value") }, function(data){
	
		xml = processXml(data);
		$(xml).find("cinema").each(function(){
			option = "<option value='" + $(this).attr("id") + "'>" + $(this).attr("nom") + "</option>";
			$("#votreCinema").append(option);
			
		});
		
	 });
   
	$("#selectActions").show('fast');
	$(".cinema_error").hide();
			
}

function getRegions(){

	$.post("/wp-content/themes/metropole/code/curl/getRegions.php",{}, function(data){
		//alert(xml);
		xml = processXml(data);
		$("#votreRegion").html("<option value='-1'> -- Region -- </option>");
		$(xml).find("region").each(function(){
			//alert($(this).attr("id") + " " + $(this).attr("nom"));
			option = "<option value='" + $(this).attr("id") + "'>" + $(this).attr("nom") + "</option>";
			$("#votreRegion").append(option);
			
		});
		
		
	 });
   
 
}

function processXml(data){
// prepares the xml for IE

	var xml;
	
	//xml = data;
	
	 if (jQuery.browser.msie) {
		xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
		xml.loadXML(data);
	} else {
		xml = data;
	} 

	return xml;

}



