function Set_Cookie( name, value, expires, path, domain, secure )
{
	//http://techpatterns.com/downloads/javascript_cookies.php
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


function GetCookie(name) {
    if (document.cookie) { // Le cookie est-il valide ?
      index = document.cookie.indexOf(name);
      if ( index != -1) {
           nDeb = (document.cookie.indexOf("=", index) + 1);
           nFin = document.cookie.indexOf(";", index);
           if (nFin == -1) {nFin = document.cookie.length;}
           return unescape(document.cookie.substring(nDeb, nFin));
      }
    }
    return null;
}

function chMenu(id){

    var lid = GetCookie("itemid");
    document.getElementById("m1_" + lid).className = "monglet";
    //document.getElementById("t1_" + lid).style.display = "none";

    var mid = "m1_" + id;
    var tid = "t1_" + id;
    document.getElementById(mid).className = "mongletActif";
    document.getElementById("menuContainer").innerHTML = document.getElementById(tid).innerHTML;
    
    document.cookie = "itemid=" + id;

}

function ldMenu(){

    var lid = GetCookie("itemid");
    document.getElementById("m1_" + lid).className = "mongletActif";
    document.getElementById("menuContainer").innerHTML = document.getElementById("t1_" + lid).innerHTML;
}

function pageLoad(position,page){
		Loading(position);
		$(position).load(page);
}

function LoadPgm(position,page,param){
		Loading(position);
		//$(position).load('/_app/pgm.php?pgm='+page+'&param='+param);
		
		var html = $.ajax({
			  type: "GET",
			  url: '/_app/pgm.php?pgm='+page+'&param='+param,
			  async: false
			}).responseText;

		$(position).html(html);

}

function LoadPgmCallback(position,page,param,callback){
		Loading(position);
		//$(position).load('/_app/pgm.php?pgm='+page+'&param='+param+'&callback='+callback);
		
		var html = $.ajax({
			  type: "GET",
			  url: '/_app/pgm.php?pgm='+page+'&param='+param+'&callback='+callback,
			  async: false
			}).responseText;

		$(position).html(html);
		
}

function Loading(position){
	$(position).html('<img src="/_img/loader.gif" width="16" height="16">');
	$('#e').html('');
}

function keyPress(callback,e){
	var key = e.keyCode;
	if(callback != ''){
		if(key == 107){
			window[callback]();
		}
	}
	return
}

function validate(id,uid,class1,class2){
	var class1 = class1 || 'formInput';
	var class2 = class2 || 'formInputMissing';
	var uid = uid || '';
	a = true
	
	var fields = id.split(":");
	
	for(i=0;i<fields.length;i++) {
		if($("#"+fields[i]+uid).val() == ''){
			$("#"+fields[i]+uid).addClass(class2).removeClass(class1);
			$("#"+fields[i]+uid).focus();
			a = false;
		}else{
			$("#"+fields[i]+uid).addClass(class1).removeClass(class2);
		}
  	}
	
	return a;
}

function postValues(id,uid){
	var uid = uid || '';
	
	var fields = id.split(":");
	var e = '';
	
	for(i=0;i<fields.length;i++) {
		e += fields[i] + ':' + $("#"+fields[i]+uid).val() + ',';
  	}
	
	e = e.substring(0, e.length-1);
	
	return e;
}

function showTiny(){
		
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "safari,style,layer,table,advhr,advimage,advlink,emotions,inlinepopups,insertdatetime,media,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,codehighlighting",
	
		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage,codehighlighting",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		extended_valid_elements: "textarea[name|class|cols|rows]",  
    	remove_linebreaks : false, 
		theme_advanced_resizing : true,
		relative_urls : false,
		remove_script_host : false,
		document_base_url : "http://sa1.ca/datas/"

	
		// Example content CSS (should be your site CSS)
		//content_css : "/_css/css_general.css",
	
	
	});
}


