/*
 * Scripts JS pour info-auto.fr
 * @author : x.delpech@telemaque-edition.com
 * @date   : 2007.06.06 14:02:29 
 *
 */

/*function IBM!!!!!!!*/
function getElement(aID){ 
     return (document.getElementById) ? document.getElementById(aID)
                                      : document.all[aID];
}

function getYearsSelect(){
	var now = new Date();
	var year_now = now.getFullYear();
	var year_select = document.createElement("select");
	year_select.id = "year_select";
	year_select.setAttribute('class', "cote_form_select");
	year_select.setAttribute('style', "margin-right:4px;");
	//year_select.setAttribute('onchange', 'updateMakeLinks();');
	year_select.onchange = updateMakeLinks;
	
	var tmp_opt = new Option('Sélectionner une année','nullval',true);
	try{ // IE
			year_select.add(tmp_opt);
		}
		catch (e){ // NICE BROWSERS
			year_select.add(tmp_opt,null);
		}	
	
	for (var i=year_now-10; i<=year_now; i++){
		tmp_opt = new Option(i,i);
		try{ // IE
			year_select.add(tmp_opt);
		}
		catch (e){ // NICE BROWSERS
			year_select.add(tmp_opt,null);
		}	
	}
	return year_select;
}

function getMonthsSelect(){
	var tab_month = new Array('janvier','février','mars','avril','mai','juin','juillet','aout','septembre','octobre','novembre','décembre');
	var month_select = document.createElement("select");
	month_select.id = "month_select";
	month_select.setAttribute('class', "cote_form_select");
	month_select.setAttribute('style', "margin-left:4px;");
	//month_select.setAttribute('onchange', 'updateMakeLinks();');
	month_select.onchange = updateMakeLinks;
	
	var tmp_opt = new Option('Sélectionner un mois','nullval',true);
	try{ // IE
			month_select.add(tmp_opt);
		}
		catch (e){ // NICE BROWSERS
			month_select.add(tmp_opt,null);
		}
	
	for (var i=0; i<tab_month.length; i++){
		var value = i+1;//pour commmencer a 1 (et pas 0)
		//pour etre coherent des date eurotax
		if(value<10){
			value = '0'+value;
		}
		tmp_opt = new Option(tab_month[i],value);
		try{ // IE
			month_select.add(tmp_opt);
		}
		catch (e){ // NICE BROWSERS
			month_select.add(tmp_opt,null);
		}	
	}
	return month_select;
}

function	updateMakeLinks(){
	var li = document.getElementsByTagName("li");
	var index = getElement("month_select").selectedIndex;
	var month = getElement("month_select").options[index].value;
	var index = getElement("year_select").selectedIndex;
	var year = getElement("year_select").options[index].value;
	var params = "";
	if (year != "nullval" && month != "nullval"){
		var params =  "?month_circulation="+month+"&year_circulation="+year;
	}
	for (i=0;i < li.length; i++){
		var link = li[i].getElementsByTagName("a");
		for (j=0; j<link.length;j++){		
			link[j].href = link[j].href+params;
			
		}
	}
}

function drawDateSelect(){
	getElement("date_select").appendChild(getYearsSelect());
	getElement("date_select").appendChild(getMonthsSelect());
}

/*
 * OS detection
 */
function osDetect() {
	var os = '';
	var osStr = new Array(	'Windows NT 6.0', // window Vista
							'Windows NT 6.1', // windows Seven as Vista
							'Windows NT 5.1', // windows xp
							'Linux', // Linux
							'Mac'  // Mac
						 );
	var hOsStr = new Array(	'vista', // window vista
							'vista', // windows Seven as Vista
							'xp', // windows xp
							'linux', // Linux
							'mac'  // Mac
						 );
	for (var i=0;i<osStr.length;i++) {
		if (navigator.userAgent.indexOf(osStr[i]) > -1) {
			os = hOsStr[i];
		}
		if (os == '') {
			os = 'unknown';
		}
	}
	return os;
}
/*
 * Predicat determinant si windows ou pas
 */
function isWindows(os) {
	return (os.indexOf('vista') > -1 || os.indexOf('xp') > -1);
}
