// JavaScript Document
function debugJS(HTMLstr){
	if (!document.getElementById('debug'))
		return false;
	document.getElementById('debug').innerHTML=HTMLstr+"<p>"+document.getElementById('debug').innerHTML;
	return true;
}
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
var returnVal=function(val){return val;}

var Url = {  
    encode : function (string) {return escape(this._utf8_encode(string));},// public method for url encoding
    decode : function (string) {return this._utf8_decode(unescape(string));},    // public method for url decoding
	_utf8_encode : function (string) {string = string.replace(/\r\n/g,"\n");var utftext = "";for (var n = 0; n < string.length; n++) {var c = string.charCodeAt(n);if (c < 128) {utftext += String.fromCharCode(c);}else if((c > 127) && (c < 2048)) {utftext += String.fromCharCode((c >> 6) | 192);              utftext += String.fromCharCode((c & 63) | 128);}else {utftext += String.fromCharCode((c >> 12) | 224);utftext += String.fromCharCode(((c >> 6) & 63) | 128);utftext += String.fromCharCode((c & 63) | 128);}}return utftext;},    // private method for UTF-8 encoding
    _utf8_decode : function (utftext) {var string = "";var i = 0;var c = c1 = c2 = 0;while ( i < utftext.length ) {c = utftext.charCodeAt(i);if (c < 128) {string += String.fromCharCode(c);i++;}else if((c > 191) && (c < 224)) {c2 = utftext.charCodeAt(i+1);string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));i += 2;}else {c2 = utftext.charCodeAt(i+1);c3 = utftext.charCodeAt(i+2);string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));i += 3;}}return string;}// private method for UTF-8 decoding
}

var searchByDate=function(sDate,eDate,lang){
	if (lang==undefined)  lang = 'fr';
	document.getElementById("startDateInputEvts").value=dateToLocaleString(sDate,lang);document.getElementById("endDateInputEvts").value=dateToLocaleString(eDate,lang);document.getElementById("DATE_DEBUT_FILTER").value=dateToITMString(sDate);document.getElementById("DATE_FIN_FILTER").value=dateToITMString(eDate);
}

var dateToITMString=function(dt) {var dStr = dt.getDate();var mStr = dt.getMonth()+1;var yStr = dt.getFullYear();return (yStr + "-"  + (mStr<10?"0":"") + mStr + "-" + (dStr<10?"0":"") + dStr );};

var dateToLocaleString=function(dt,lang) {
	if (lang==undefined) lang = 'fr';
	var dStr = dt.getDate();
	var mStr = dt.getMonth()+1;
	var yStr = dt.getFullYear();
	return (lang=='fr'?((dStr<10?"0":"") + dStr + "/"  + (mStr<10?"0":"") + mStr + "/" + yStr ):((mStr<10?"0":"") + mStr + "/" + (dStr<10?"0":"") + dStr + "/"  + yStr ));};

function updateCal(dtId,obj) {
	var txtDate1 = document.getElementById(dtId);
	if (txtDate1.value != "") {
//		YAHOO.example.calendar.cal1.select(txtDate1.value);
		calS.select(txtDate1.value);
        calS.cfg.setProperty("mindate", (firstDate.getMonth()+1) + "/" + (firstDate.getDate()) + "/" + firstDate.getFullYear()); 
		var selectedDates = calS.getSelectedDates();
		if (selectedDates.length > 0) {
			var firstDate = selectedDates[0];
			calS.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "/" + firstDate.getFullYear());
			calS.render();
		}
	}
}

var kwSearch= function (thisForm){if(Url.encode(thisForm.kwInput.value)!=''){debugJS(thisForm.action);thisForm.action+='#0'+'&SEARCH&KEYWORDS=1:'+Url.encode(thisForm.kwInput.value);return true;};return false;}

var dateSearch=function(thisForm,lang){
	if (lang==undefined)  lang = 'fr';
	
	thisForm.DATE_DEBUT_FILTER.value='';
	thisForm.DATE_DEBUT_FILTER.value+=thisForm.startDateInput.value.charAt(6);
	thisForm.DATE_DEBUT_FILTER.value+=thisForm.startDateInput.value.charAt(7);
	thisForm.DATE_DEBUT_FILTER.value+=thisForm.startDateInput.value.charAt(8);
	thisForm.DATE_DEBUT_FILTER.value+=thisForm.startDateInput.value.charAt(9);
	thisForm.DATE_DEBUT_FILTER.value+='-';
	thisForm.DATE_DEBUT_FILTER.value+=lang=='fr'?thisForm.startDateInput.value.charAt(3):thisForm.startDateInput.value.charAt(0);
	thisForm.DATE_DEBUT_FILTER.value+=lang=='fr'?thisForm.startDateInput.value.charAt(4):thisForm.startDateInput.value.charAt(1);
	thisForm.DATE_DEBUT_FILTER.value+='-';
	thisForm.DATE_DEBUT_FILTER.value+=lang=='fr'?thisForm.startDateInput.value.charAt(0):thisForm.startDateInput.value.charAt(3);
	thisForm.DATE_DEBUT_FILTER.value+=lang=='fr'?thisForm.startDateInput.value.charAt(1):thisForm.startDateInput.value.charAt(4);

	thisForm.DATE_FIN_FILTER.value='';
	thisForm.DATE_FIN_FILTER.value+=thisForm.endDateInput.value.charAt(6);
	thisForm.DATE_FIN_FILTER.value+=thisForm.endDateInput.value.charAt(7);
	thisForm.DATE_FIN_FILTER.value+=thisForm.endDateInput.value.charAt(8);
	thisForm.DATE_FIN_FILTER.value+=thisForm.endDateInput.value.charAt(9);
	thisForm.DATE_FIN_FILTER.value+='-';
	thisForm.DATE_FIN_FILTER.value+=lang=='fr'?thisForm.endDateInput.value.charAt(3):thisForm.endDateInput.value.charAt(0);
	thisForm.DATE_FIN_FILTER.value+=lang=='fr'?thisForm.endDateInput.value.charAt(4):thisForm.endDateInput.value.charAt(1);;
	thisForm.DATE_FIN_FILTER.value+='-';
	thisForm.DATE_FIN_FILTER.value+=lang=='fr'?thisForm.endDateInput.value.charAt(0):thisForm.endDateInput.value.charAt(3);
	thisForm.DATE_FIN_FILTER.value+=lang=='fr'?thisForm.endDateInput.value.charAt(1):thisForm.endDateInput.value.charAt(4);

	thisForm.action+='#0'+('&SEARCH&'+'DATE_DEBUT_FILTER=1:'+Url.encode(thisForm.DATE_DEBUT_FILTER.value)+':'+Url.encode(thisForm.from.value)+' '+Url.encode(thisForm.startDateInput.value)+'&DATE_FIN_FILTER=1:'+Url.encode(thisForm.DATE_FIN_FILTER.value)+':'+Url.encode(thisForm.to.value)+' '+Url.encode(thisForm.endDateInput.value));
//	debugJS(thisForm.DATE_DEBUT_FILTER.value);
//	debugJS(thisForm.DATE_FIN_FILTER.value);
//	debugJS(thisForm.startDateInput.value);
//	debugJS(thisForm.endDateInput.value);
	return true;
//	return false;
}

var letsGo=new function(url){
//	debugJS(url);
	return false;
}


