

function unselectIfUnchecked(checkbox, optionClassName)
{
	if(!checkbox.checked)
		$("."+optionClassName+":selected").each(function (i) {
			this.selected = false;
		  });
}

function checkIfSelected(checkbox, optionClassName)
{
	if($("."+optionClassName+":selected").length>0)
		checkbox.checked = true;
}

function afficherCarte(){
    Shadowbox.open({
        player:     'html',
        content:    '<div id="shadowbox-googlemap" style="height:400px;"></div>',
        height:     400,
        width:      600,
        options:    {
            onFinish: function(item){
                if(GBrowserIsCompatible()){
                    var body = document.getElementById("shadowbox-googlemap");
                    var shadowbox_map = new GMap2(body);
					
					shadowbox_map.setMapType(G_PHYSICAL_MAP);
					
					if(tabMarkers.length==1)
						shadowbox_map.setCenter(tabMarkers[0].marker.getLatLng(), 10);
					else
						shadowbox_map.setCenter(new GLatLng(46.8000, 2.8125), 5);
					
					
					shadowbox_map.setUIToDefault();
					
					for(var cptM=0; cptM<tabMarkers.length; cptM++)
					{
						shadowbox_map.addOverlay(tabMarkers[cptM].marker);
					}
					
                }
            }
        }
    });
}

function afficherListeLettre(lettre)
{
	$(".liste_profils").hide();
	$("#liste_lettre_"+lettre).show();
	
	$("#lettres a").removeClass("selected");
	$("#lettre_"+lettre).addClass("selected");
	
	document.location = "#" + lettre;
}


/* DATES */

function setTwoDigits(number)
{
	if ( parseInt(number,10) < 10) return "0" + number;
	else return ""+number;
}

function isDate(year, month, day) {
	// month argument must be in the range 1 - 12
	month = month - 1; // javascript month range : 0- 11
	var tempDate = new Date(year,month,day);
	if ((year == tempDate.getFullYear()) && 
		(month == tempDate.getMonth()) &&
		(day == tempDate.getDate()) )
		return true;
	else
		return false
}

function isValidDateString(d /* dd/mm/yyyy */) {
	var dateFormat = /^(\d{2})\/(\d{2})\/(\d{4})$/;
	if (!dateFormat.test(d)) return false;
	var _d = dateFormat.exec(d);
	return isDate(parseInt(RegExp.$3, 10), parseInt(RegExp.$2, 10), parseInt(RegExp.$1, 10));
}

function parse_inputdate(d /* String : dd/mm/yyyy */)
{
	if ((d == "")) return null;
	if(!isValidDateString(d)) return null;
	
	var dateFormat = /^(\d{2})\/(\d{2})\/(\d{4})$/;
	var _d = dateFormat.exec(d);
	_d = new Date(parseInt(RegExp.$3, 10), parseInt(RegExp.$2, 10)-1, parseInt(RegExp.$1, 10));
	
	return _d;
}

function parse_sqldate(d /* String : yyyy-mm-dd hh:mm:ss */)
{
	if (!d) return null;
	var dateFormat = /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
	var datetimeFormat = /^(\d{4})\-(\d{2})\-(\d{2})$/;
	var _d;
	
	if(dateFormat.test(d))
	{
		_d = dateFormat.exec(d);
		return new Date(parseInt(RegExp.$1, 10), parseInt(RegExp.$2, 10)-1, parseInt(RegExp.$3, 10), parseInt(RegExp.$4, 10), parseInt(RegExp.$5, 10), parseInt(RegExp.$6, 10));
	}
	if(datetimeFormat.test(d))
	{
		_d = datetimeFormat.exec(d);
		return new Date(parseInt(RegExp.$1, 10), parseInt(RegExp.$2, 10)-1, parseInt(RegExp.$3, 10), 0, 0, 0);
	}
	
	 return null;
}

function convert_inputdate(d /* Date */)
{
	if (!d) return "";
	return setTwoDigits(d.getDate())+"/"+setTwoDigits(d.getMonth()+1)+"/"+d.getFullYear();
}
