var enableCache = false;
var loading1='<table  height="100%" width="100%" border="0"  align="center" valign="middle"><tr><td  width="100%" align="center" valign="middle"><img src="images/loading.gif" border="0" /></td></tr></table>';
var charset = "windows-1252";// Windows-1256    ISO-8859-1

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
///////////////////////////////////////////////////////

////**************datetimepicker*****************

var datePickerDivID = "datepicker";
var iFrameDivID = "datepickeriframe";

var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var monthArrayShort = new Array('Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul', 'Aut', 'Sep', 'Oct', 'Nov', 'Dec');
var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aout', 'Sept', 'Oct', 'Nov', 'Dec');
var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
 
// these variables define the date formatting we're expecting and outputting.
// If you want to use a different format by default, change the defaultDateSeparator
// and defaultDateFormat variables either here or on your HTML page.
var defaultDateSeparator = "-";        // common values would be "/" or "."
var defaultDateFormat = "ymd"    // valid values are "mdy", "dmy", and "ymd"
var dateSeparator = defaultDateSeparator;
var dateFormat = defaultDateFormat;

/////**************************************

var jsCache = new Array();
var dynamicContent_ajaxObjects = new Array();

function ajax_showContent(divId,ajaxIndex,url)
{
	var targetObj = document.getElementById(divId);
	targetObj.innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
	if(enableCache){
		jsCache[url] = 	dynamicContent_ajaxObjects[ajaxIndex].response;
	}
	dynamicContent_ajaxObjects[ajaxIndex] = false;
	
	ajax_parseJs(targetObj)
}

function ajax_showContent_parent(divId,ajaxIndex,url)
{
	
	var targetObj = window.parent.document.getElementById(divId);
	
	targetObj.innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
	if(enableCache){
		jsCache[url] = 	dynamicContent_ajaxObjects[ajaxIndex].response;
	}
	dynamicContent_ajaxObjects[ajaxIndex] = false;
	
	ajax_parseJs(targetObj)
}


function ajax_addContent(divId,ajaxIndex,url)
{
	var targetObj = document.getElementById(divId);
	targetObj.innerHTML += dynamicContent_ajaxObjects[ajaxIndex].response;
	if(enableCache){
		jsCache[url] = 	dynamicContent_ajaxObjects[ajaxIndex].response;
	}
	dynamicContent_ajaxObjects[ajaxIndex] = false;
	
	ajax_parseJs(targetObj)
}


function ajax_loadContent(divId,url)
{
	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		ajax_parseJs(document.getElementById(divId))
		evaluateCss(document.getElementById(divId))
		return;
	}
	
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	document.getElementById(divId).innerHTML = loading1;
        dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	
	if(url.indexOf('?')>=0){
		dynamicContent_ajaxObjects[ajaxIndex].method='GET';
		var string = url.substring(url.indexOf('?'));
		url = url.replace(string,'');
		string = string.replace('?','');
		var items = string.split(/&/g);
		for(var no=0;no<items.length;no++){
			var tokens = items[no].split('=');
			if(tokens.length==2){
				dynamicContent_ajaxObjects[ajaxIndex].setVar(tokens[0],tokens[1]);
			}	
		}	
		url = url.replace(string,'');
	}

	
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}




//////////////////////////////////////////////////////////////////


function get(divId,url)
{
	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		ajax_parseJs(document.getElementById(divId))
		evaluateCss(document.getElementById(divId))
		return;
	}
	
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	document.getElementById(divId).innerHTML = loading1;
        dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	
	if(url.indexOf('?')>=0){
		dynamicContent_ajaxObjects[ajaxIndex].method='GET';
		var string = url.substring(url.indexOf('?'));
		url = url.replace(string,'');
		string = string.replace('?','');
		var items = string.split(/&/g);
		for(var no=0;no<items.length;no++){
			var tokens = items[no].split('=');
			if(tokens.length==2){
				dynamicContent_ajaxObjects[ajaxIndex].setVar(tokens[0],tokens[1]);
			}	
		}	
		url = url.replace(string,'');
	}

	
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}

/////////////////////////////////////////////////////////////////////////
function get_parent(divId,url)
{
	 
	
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	window.parent.document.getElementById(divId).innerHTML = loading1;
        dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	
	if(url.indexOf('?')>=0){
		dynamicContent_ajaxObjects[ajaxIndex].method='GET';
		var string = url.substring(url.indexOf('?'));
		url = url.replace(string,'');
		string = string.replace('?','');
		var items = string.split(/&/g);
		for(var no=0;no<items.length;no++){
			var tokens = items[no].split('=');
			if(tokens.length==2){
				dynamicContent_ajaxObjects[ajaxIndex].setVar(tokens[0],tokens[1]);
			}	
		}	
		url = url.replace(string,'');
	}

	
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent_parent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}



//////////////////////////////////////////////////////////////////////////////


function silent_get(divId,url)
{
	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		ajax_parseJs(document.getElementById(divId))
		evaluateCss(document.getElementById(divId))
		return;
	}
	
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	//document.getElementById(divId).innerHTML = '<table  height="100%" width="100%" border="0"  align="center" valign="middle"><tr><td align="right" valign="middle" width="50%"><b>Chargement...</b></td><td  width="50%"align="left" valign="middle"><img src="inc_img/loading.gif" width="32" height="32" /></td></tr></table>';
        dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	
	if(url.indexOf('?')>=0){
		dynamicContent_ajaxObjects[ajaxIndex].method='GET';
		var string = url.substring(url.indexOf('?'));
		url = url.replace(string,'');
		string = string.replace('?','');
		var items = string.split(/&/g);
		for(var no=0;no<items.length;no++){
			var tokens = items[no].split('=');
			if(tokens.length==2){
				dynamicContent_ajaxObjects[ajaxIndex].setVar(tokens[0],tokens[1]);
			}	
		}	
		url = url.replace(string,'');
	}

	
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	//dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}



///////////////////////////////////////////////////////////////////


function ajax_parseJs(obj)
{
	var scriptTags = obj.getElementsByTagName('SCRIPT');
	var string = '';
	var jsCode = '';
	for(var no=0;no<scriptTags.length;no++){	
		if(scriptTags[no].src){
	        var head = document.getElementsByTagName("head")[0];
	        var scriptObj = document.createElement("script");
	
	        scriptObj.setAttribute("type", "text/javascript");
	        scriptObj.setAttribute("src", scriptTags[no].src);  	
		}else{
			if(navigator.userAgent.toLowerCase().indexOf('opera')>=0){
				jsCode = jsCode + scriptTags[no].text + '\n';
			}
			else
				jsCode = jsCode + scriptTags[no].innerHTML;	
		}
		
	}

	if(jsCode)ajax_installScript(jsCode);
}

//////////////////////////////////////////////////////////////////////////

function ajax_installScript(script)
{		
    if (!script)
        return;		
    if (window.execScript){        	
    	window.execScript(script)
    }else if(window.jQuery && jQuery.browser.safari){ // safari detection in jQuery
        window.setTimeout(script,0);
    }else{        	
        window.setTimeout( script, 0 );
    } 
}	

////////////////////////////////////////////////////////////////////////	
	
function evaluateCss(obj)
{
	var cssTags = obj.getElementsByTagName('STYLE');
	var head = document.getElementsByTagName('HEAD')[0];
	for(var no=0;no<cssTags.length;no++){
		head.appendChild(cssTags[no]);
	}	
}


/////////////////////////////////////////////////////////////////////////

function post(divId, url,donnee){


	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		ajax_parseJs(document.getElementById(divId))
		evaluateCss(document.getElementById(divId))
		return;
	}
	
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	document.getElementById(divId).innerHTML = loading1;
    dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	
	dynamicContent_ajaxObjects[ajaxIndex].method='POST';
	//dynamicContent_ajaxObjects[ajaxIndex].setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].URLString=donnee;
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}



function post_parent(divId,url,donnee){


	var ajaxIndex = dynamicContent_ajaxObjects.length;
	//window.parent.document.getElementById(divId).innerHTML = '<table  height="100%" width="100%" border="0"  align="center" valign="middle"><tr><td align="right" valign="middle" width="50%"><b>Chargement...</b></td><td  width="50%"align="left" valign="middle"><img src="inc_img/loading.gif" width="32" height="32" /></td></tr></table>';
    dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	
	dynamicContent_ajaxObjects[ajaxIndex].method='POST';
	//dynamicContent_ajaxObjects[ajaxIndex].setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent_parent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].URLString=donnee;
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}



function silent_post(divId,url,donnee)
{
	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		ajax_parseJs(document.getElementById(divId))
		evaluateCss(document.getElementById(divId))
		return;
	}
	
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	//document.getElementById(divId).innerHTML = '<table  height="100%" width="100%" border="0"  align="center" valign="middle"><tr><td align="right" valign="middle" width="50%"><b>Chargement...</b></td><td  width="50%"align="left" valign="middle"><img src="inc_img/loading.gif" width="32" height="32" /></td></tr></table>';
    dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	
	dynamicContent_ajaxObjects[ajaxIndex].method='POST';
	//dynamicContent_ajaxObjects[ajaxIndex].setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	//dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].URLString=donnee;
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}

////////////////////////////////testing//////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
/**********************Partie non modifiable**********************/

function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset="+charset)
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							/* These lines were added by Alf Magne Kalleland ref. info on the sack home page. It prevents memory leakage in IE */

							delete self.xmlhttp['onreadystatechange'];
							self.xmlhttp=null;
							self.responseStatus=null;
							self.response=null;
							self.responseXML=null;
														
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}



/////////*****************************fin ajax***************///////////////////////////////


















//////////////////************************debut des functions metier***********************///////////////////////









////////////////////////////functions date/////////////////




function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	
	//here tu jou 3la format of date
	var strDay=false
	var strMonth=false
	var strYear=false
	
	
	if(dtCh=='/')
	{ strDay=dtStr.substring(0,pos1)
	strMonth=dtStr.substring(pos1+1,pos2)
	strYear=dtStr.substring(pos2+1) 
	}else{
	  strMonth=dtStr.substring(pos1+1,pos2)
	 strDay=dtStr.substring(pos2+1)
	strYear=dtStr.substring(0,pos1) 
	}
	//
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Le format de la date doit etre jj/mm/aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Tapez Un Mois Valide")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Tapez Un Jour Valide")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Tapez Une Annee Valide")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Tapez Une date valide")
		return false
	}
return true
}

//////////////////////fin functions  dates//////////////////////








///////////////////////Functions du temps///////////////

function addTime(oldtime,toadd) {
//oldtime  = '14:20:10'   HH:MM:SS  => l'heure de base
//toadd = '01:00:00'  HH:MM:SS  =>  durée à ajouter
//return l'heure aprés l'ajout de la durée toadd

  var addH = parseInt(toadd.substr(0,2));
  var addM = parseInt(toadd.substr(3,2));
  var addS = parseInt(toadd.substr(6,2));
  
  var H = parseInt(oldtime.substr(0,2));
  var M = parseInt(oldtime.substr(3,2));
  var S = parseInt(oldtime.substr(6,2));

  hour3 = H + addH;
  min3 = M + addM;
  sec3 = S + addS;

  if (sec3>=60) { sec3 = -(60 - sec3); min3 = parseInt(min3)+1; }
  if (min3>=60) { min3 = -(60 - min3); hour3 = parseInt(hour3)+1; }
  if (hour3>=24) { hour3 = -(24 - hour3); }
  if (sec3<=9) { sec3="0"+sec3; }
  if (min3<=9) { min3="0"+min3; }
  if (hour3<=9) { hour3="0"+hour3; }
  if ((addS>59) || (addM>59) || (addH>23)) { window.alert('Invalid Input!!'); return false; }
  if ((addS.length > 2) || (addM.length > 2) || (addH.length > 2)) { window.alert('Invalid Input!!'); return false; }
  return  hour3 +":" + min3 +":" + sec3;
}


///////////////////////// fin Functions du temps//////////////////////


//////////////////////////functions forms///////////////////////////
function get_Combo_selected(obj,needed)
{//val= l'objet combo (this)  ou l'id de ce combo 'id_combo'
//needed = 'i' pour index   'v' pour value   't' pour text
//retourn la valeur selectionner ou false

var select=null;
if(isString(obj))
	select = document.getElementById(obj);
else
	select = obj;

 
if(needed=='v')
	return  select.options[select.selectedIndex].value;
			
if(needed=='i')
	return  select.selectedIndex;
				
if(needed=='t')
	return  select.options[select.selectedIndex].text;

}


function get_listbox_Values(obj) 
{//val= l'objet list (this)  ou l'id de cette list 'id_list'
//retourne tous les valeurs selectionner dans une liste box
var select=null;
if(isString(obj))
	select = document.getElementById(obj);
else
	select = obj;

    var selection = '';
    for (var i = 0; i < select.options.length; ++i) {
        if (select.options[i].selected) {
            selection+= select.options[i].value+',';
        }
    }
    return selection;
}

function get_selection_multiple(obj) 
{//val= l'objet list (this)  ou l'id de cette list 'id_list'
//retourne tous les valeurs selectionner dans une liste box
var select=null;
if(isString(obj))
	select = document.getElementById(obj);
else
	select = obj;

    var selection = '';
    for (var i = 0; i < select.options.length; ++i) {
        if (select.options[i].selected) {
            selection+= URLEncode(select.options[i].value)+',';
        }
    }
	
	selection=selection.substring(0,selection.length);
    return selection;
}


function get_obj(id_obj)
{return  document.getElementById(id_obj);
}

function get_html(obj)
{
 var select=null;
if(isString(obj))
	select = document.getElementById(obj);
else
	select = obj;
return select.innerHTML;
}


function set_html(obj,contenu)
{
 var select=null;
if(isString(obj))
	select = document.getElementById(obj);
else
	select = obj;
select.innerHTML=contenu;
}

function isEmpty(obj,message)
{
var select=null;
if(isString(obj))
	select = document.getElementById(obj);
else
	select = obj;
	
if(select.value=='')
{
alert(message);
return true;
}else{
return false;
}
}

function isString(a) {
    return typeof a == 'string';
}

function lst_to_lst(srce, tart,laisser) 
{
var source=null;
if(isString(srce))
	source = document.getElementById(srce);
else
	source = srce;
	
var target=null;
if(isString(tart))
	target = document.getElementById(tart);
else
	target = tart;


	// recuperation des enciens element 
	var tab_traget = new Array();
	for (var i = 0; i < target.options.length; ++i) {
		tab_traget[i] = new Array();
		tab_traget[i]['value'] = target.options[i].value;
		tab_traget[i]['text'] = target.options[i].text;
	}
	
	// recuperation des nouveau element 
	var taille=tab_traget.length;
	var x=0;
	for (var i = 0; i < source.options.length; ++i) {
		if (source.options[i].selected){
		
		// si existe déja 
		for (var j = 0; j < target.options.length; ++j) {
		if ((source.options[i].value == target.options[j].value) || (source.options[i].value=='0'))
			{
			 return;
			}
		}
		if ( source.options[i].value!='0')
			{
			tab_traget[taille+x] = new Array();
			tab_traget[taille+x]['value'] = source.options[i].value;
			tab_traget[taille+x]['text'] = source.options[i].text;
			++x;
			}
			
			if(laisser==false)
				source.options[i]=null;
		}
	}
	
	// recuperation des nouveau element 
	for (var i=0;i<tab_traget.length;i++)
	{
		target.options[i]=new Option(tab_traget[i]['text'],tab_traget[i]['value']);
	}

return false;
}

function removelist_elements(srce) {
	 
	var source=null;
	if(isString(srce))
	source = document.getElementById(srce);
	else
	source = srce;
	
	
    var selection = get_listbox_Values(source);
    if (selection.length > 0) {
        for (var j = selection.length - 1; j >= 0; --j) {
            for (i = selection[j] + 1; i < source.length; ++i) {
                source.options[i - 1].text = source.options[i].text;
                source.options[i - 1].value = source.options[i].value;
            }
            --source.length;
        }
        source.selectedIndex = -1;
    }
    return false;
}

function pop(page,largeur,hauteur,options)
{
var top=(screen.height-hauteur)/2;
var left=(screen.width-largeur)/2;
window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}









function URLEncode(obj)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = null;
	 
	if(isString(obj))
	plaintext = obj;
	else
	plaintext = obj.value;
	
	
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
 
}

function URLDecode(obj)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   
   	var encoded = null;
	 
	if(isString(obj))
	encoded = obj;
	else
	encoded = obj.value;
 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return  plaintext;
 
 
    
}


function serialize(obj)
{


var frm=null;
if(isString(obj))
	frm = document.getElementById(obj);
else
	frm = obj;

var data='';

var elements=frm.getElementsByTagName('INPUT');
for(i=0;i<elements.length;++i )
{

	switch(elements[i].type)
	{
		case 'text':{data += elements[i].name +'=' + URLEncode(elements[i].value) + '&';}break;
		case 'radio':{	if(elements[i].checked==true)
						data += elements[i].name +'=' + elements[i].value + '&';
					}break;
		case 'checkbox':{	if(elements[i].checked==true)
						data += elements[i].name +'=' + elements[i].value + '&';
						}break;
	}
	
	
}

elements=frm.getElementsByTagName('SELECT');
for(i=0;i<elements.length;++i )
{

	switch(elements[i].type)
	{
		case 'select-one':{data += elements[i].name +'=' + URLEncode(get_Combo_selected(elements[i],'v')) + '&';}break;
		case 'select-multiple':{data += elements[i].name+'='+get_selection_multiple(elements[i]);}break;
	}
	
	
}



elements=frm.getElementsByTagName('TEXTAREA');
for(i=0;i<elements.length;++i )
	data += elements[i].name +'=' + URLEncode(elements[i].value) + '&';



 data=data.substring(0,data.length-1);
 
return data; 
}
/////////////////////////fin Functions forms////////////////////////




/////////////////////Functions styles////////////////////////////////

function set_visible(obj,show)
 {	//obj='div_concerner'
	//show=optionel  true false
	
	var la_div=null;
	if(isString(obj))
	la_div = document.getElementById(obj);
	else
	la_div = obj;
	 
	if(!show)
	{	if( la_div.style.display=='block')
			la_div.style.display='none';
		else
			la_div.style.display='block';
	}else{
		if( show=='t')
			la_div.style.display='block';
		if( show=='f')
			la_div.style.display='none';
	
	}
}

function set_classname(obj,cls)
{ 	//id_div='div_concerner'
	//cls = 'classname'  => le nom de la nouvele class
	var la_div=null;
	if(isString(obj))
	la_div = document.getElementById(obj);
	else
	la_div = obj;
	
	la_div.className=cls;
}
///////////////////////fin Functions styles///////////////////////////



















function selectAll(aList, state) {

if(isString(aList))
	aList = document.getElementById(aList);


  for (var i=0; i<aList.options.length; i++) {
    aList.options[i].selected = state;
  }
}

// ------------------------------------
function compare(aText, bText) {
  var  i = 0;
  aString = aText.toString(); aString.toLowerCase();
  bString = bText.toString(); bString.toLowerCase();
  if (aString < bString) return -1;
  else if (aString > bString) return 1;
  return 0;
}

// ------------------------------------
// removeItems() - remove selected options from a <SELECT> list
// ------------------------------------
function removeItems( sel ) {
  if( sel.selectedIndex < 0 ) return 0;
  var len = sel.options.length;
  var oo=0;  // oo - old indexes
  var nn=0;  // nn - new indexes
  while (oo < len) {
    // go through the list skipping selected options
    if( ! sel.options[oo].selected ) {
      sel.options[nn].text = sel.options[oo].text;
      sel.options[nn].value = sel.options[oo].value;
      sel.options[nn].selected = false;
      nn++;
    }
    oo++;
  }
  sel.options.length = nn; // cut the length to new smaller value
  return 1; // returns 1 on success, 0 on failure
}

// --------------------------------------
// moveItems(fromList, toList, toSort, toSelect)
//   - moves selected items from from List to toList
//   toSort (boolean) - sort the toList if true
//   toSelect (boolean) - select moved items in toList if true
//
//   needs these functions:
//        selectAll(), compare(),  removeItems()
// --------------------------------------
function moveItems(fromList, toList, toSort, toSelect) {
  
 
if(isString(fromList))
	fromList = document.getElementById(fromList);

 if(isString(toList))
	toList = document.getElementById(toList); 
  
  if (fromList.selectedIndex < 0) return;
  selectAll(toList, false);
  for(var i=0; i < fromList.options.length; i++) {
    if (! fromList.options[i].selected) continue;
    addOption = fromList.options[i];
    var exist = false;
    for( var l = 0; l < toList.options.length; l++ ) {
      if( (addOption.text == toList.options[l].text)
         && (addOption.value == toList.options[l].value) ) {
                 exist = true;
                 break;
      }
    }

    if( exist ) continue;

    var newOption =
      new Option(addOption.text, addOption.value, false, toSelect);
                 // text,       value,   defaultSelected, selected

    if (toSort) {
      var j;
      var to_length = toList.length;
      toList.options[to_length] = new Option('tt','vv');
      for (j=0; j<to_length; j++) {
        if (compare(newOption.text, toList[j].text) < 0) {
          for (k=to_length; k>j; k--) {
            toList.options[k].value = toList.options[k-1].value;
            toList.options[k].text = toList.options[k-1].text;
          }
          break;
        }
      }
      toList.options[j] = newOption;
    } else { // no sorting
      toList.options[toList.options.length] = newOption; // add to the end
    }

  } // for cycle

  removeItems(fromList); // remove selected items from the fromList
  //return 1; // success

}
 

 
 
 
 
function equaliserList(fromList, toList)
{

if(isString(fromList))
	fromList = document.getElementById(fromList);

 if(isString(toList))
	toList = document.getElementById(toList); 

 for(var i=0; i < toList.options.length; i++) {
 
	 for(var j=0; j < fromList.options.length; j++) {

		if (fromList.options[j].value== toList.options[i].value)
			{fromList.options[j].selected=true;
			// alert (toList.options[i].text);  
			break;}
 
	}
 }
	
removeItems(fromList);

}
 
 
 
 
 
 function moveALL(fromList, toList, toSort, toSelect) {
  

if(isString(fromList))
	fromList = document.getElementById(fromList);

 if(isString(toList))
	toList = document.getElementById(toList); 
 
 selectAll(fromList,true);
 
  if (fromList.selectedIndex < 0) return;
  selectAll(toList, false);
  for(var i=0; i < fromList.options.length; i++) {
    if (! fromList.options[i].selected) continue;
    addOption = fromList.options[i];
    var exist = false;
    for( var l = 0; l < toList.options.length; l++ ) {
      if( (addOption.text == toList.options[l].text)
         && (addOption.value == toList.options[l].value) ) {
                 exist = true;
                 break;
      }
    }

    if( exist ) continue;

    var newOption =
      new Option(addOption.text, addOption.value, false, toSelect);
                 // text,       value,   defaultSelected, selected

    if (toSort) {
      var j;
      var to_length = toList.length;
      toList.options[to_length] = new Option('tt','vv');
      for (j=0; j<to_length; j++) {
        if (compare(newOption.text, toList[j].text) < 0) {
          for (k=to_length; k>j; k--) {
            toList.options[k].value = toList.options[k-1].value;
            toList.options[k].text = toList.options[k-1].text;
          }
          break;
        }
      }
      toList.options[j] = newOption;
    } else { // no sorting
      toList.options[toList.options.length] = newOption; // add to the end
    }

  } // for cycle

  removeItems(fromList); // remove selected items from the fromList
  //return 1; // success

}
// note about creating new options and assigning them values/text in Internet Explorer:
//   1. you have to create a new object for each new option (you can't use the same object for more than one option)
//   2. you can't write option[i]=option[j];  you have to explicitely assign each property:
//        option[i].text=option[j].text;
//        option[i].value=option[j].value;

// Note about removing options from select lists:
// The standard documented way to remove list items from a select-list is to set them to null:
// 
//   some_select.options[i] = null 
//
//  This works fine in IE and in most cases in Netscape.
// But sometimes (not always) Netscape crashes when:
//  - multiple items (as little as 2) were selected for removal
//   AND
//  - they were selected in the middle of the list
//








/////////////////////////*******************fin functions metier***********************///////////////////////////////








////////////////////////////////////////////date timepicker///////////////////////////////////////////

function displayDatePicker(dateFieldName, displayBelowThisObject, dtFormat, dtSep)
{
  var targetDateField = document.getElementsByName (dateFieldName).item(0);
 
  // if we weren't told what node to display the datepicker beneath, just display it
  // beneath the date field we're updating
  if (!displayBelowThisObject)
    displayBelowThisObject = targetDateField;
 
  // if a date separator character was given, update the dateSeparator variable
  if (dtSep)
    dateSeparator = dtSep;
  else
    dateSeparator = defaultDateSeparator;
 
  // if a date format was given, update the dateFormat variable
  if (dtFormat)
    dateFormat = dtFormat;
  else
    dateFormat = defaultDateFormat;
 
  var x = displayBelowThisObject.offsetLeft;
  var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
 
  // deal with elements inside tables and such
  var parent = displayBelowThisObject;
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop ;
  }
 
  drawDatePicker(targetDateField, x, y);
}


/**
Draw the datepicker object (which is just a table with calendar elements) at the
specified x and y coordinates, using the targetDateField object as the input tag
that will ultimately be populated with a date.

This function will normally be called by the displayDatePicker function.
*/
function drawDatePicker(targetDateField, x, y)
{
  var dt = getFieldDate(targetDateField.value );
 
  // the datepicker table will be drawn inside of a <div> with an ID defined by the
  // global datePickerDivID variable. If such a div doesn't yet exist on the HTML
  // document we're working with, add one.
  if (!document.getElementById(datePickerDivID)) {
    // don't use innerHTML to update the body, because it can cause global variables
    // that are currently pointing to objects on the page to have bad references
    //document.body.innerHTML += "<div id='" + datePickerDivID + "' class='dpDiv'></div>";
    var newNode = document.createElement("div");
    newNode.setAttribute("id", datePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
 
  // move the datepicker div to the proper x,y coordinate and toggle the visiblity
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = x + "px";
  pickerDiv.style.top = y + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
  pickerDiv.style.zIndex = 10000;
 
  // draw the datepicker table
  refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate());
}


/**
This is the function that actually draws the datepicker calendar.
*/
function refreshDatePicker(dateFieldName, year, month, day)
{
  // if no arguments are passed, use today's date; otherwise, month and year
  // are required (if a day is passed, it will be highlighted later)
  var thisDay = new Date();
 
  if ((month >= 0) && (year > 0)) {
    thisDay = new Date(year, month, 1);
  } else {
    day = thisDay.getDate();
    thisDay.setDate(1);
  }
 
  // the calendar will be drawn as a table
  // you can customize the table elements with a global CSS style sheet,
  // or by hardcoding style and formatting elements below
  var crlf = "\r\n";
  var TABLE = "<table cols=7 class='dpTable'>" + crlf;
  var xTABLE = "</table>" + crlf;
  var TR = "<tr class='dpTR'>";
  var TR_title = "<tr class='dpTitleTR'>";
  var TR_days = "<tr class='dpDayTR'>";
  var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
  var xTR = "</tr>" + crlf;
  var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var TD_title = "<td colspan=5 class='dpTitleTD'>";
  var TD_buttons = "<td class='dpButtonTD'>";
  var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>";
  var TD_days = "<td class='dpDayTD'>";
  var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var xTD = "</td>" + crlf;
  var DIV_title = "<div class='dpTitleText'>";
  var DIV_selected = "<div class='dpDayHighlight'>";
  var xDIV = "</div>";
 
  // start generating the code for the calendar table
  var html = TABLE;
 
  // this is the title bar, which displays the month and the buttons to
  // go back to a previous month or forward to the next month
  html += TR_title;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "&lt;") + xTD;
  html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "&gt;") + xTD;
  html += xTR;
 
  // this is the row that indicates which day of the week we're on
  html += TR_days;
  for(i = 0; i < dayArrayShort.length; i++)
    html += TD_days + dayArrayShort[i] + xTD;
  html += xTR;
 
  // now we'll start populating the table with days of the month
  html += TR;
 
  // first, the leading blanks
  for (i = 0; i < thisDay.getDay(); i++)
    html += TD + "&nbsp;" + xTD;
 
  // now, the days of the month
  do {
    dayNum = thisDay.getDate();
    TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
    
    if (dayNum == day)
      html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
    else
      html += TD + TD_onclick + dayNum + xTD;
    
    // if this is a Saturday, start a new row
    if (thisDay.getDay() == 6)
      html += xTR + TR;
    
    // increment the day
    thisDay.setDate(thisDay.getDate() + 1);
  } while (thisDay.getDate() > 1)
 
  // fill in any trailing blanks
  if (thisDay.getDay() > 0) {
    for (i = 6; i > thisDay.getDay(); i--)
      html += TD + "&nbsp;" + xTD;
  }
  html += xTR;
 
  // add a button to allow the user to easily return to today, or close the calendar
  var today = new Date();
  var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[ today.getMonth()] + " " + today.getDate();
  html += TR_todaybutton + TD_todaybutton;
  html += "<button class='dpTodayButton' onClick='refreshDatePicker(\"" + dateFieldName + "\");'>this month</button> ";
  html += "<button class='dpTodayButton' onClick='updateDateField(\"" + dateFieldName + "\");'>close</button>";
  html += xTD + xTR;
 
  // and finally, close the table
  html += xTABLE;
 
  document.getElementById(datePickerDivID).innerHTML = html;
  // add an "iFrame shim" to allow the datepicker to display above selection lists
  adjustiFrame();
}


/**
Convenience function for writing the code for the buttons that bring us back or forward
a month.
*/
function getButtonCode(dateFieldName, dateVal, adjust, label)
{
  var newMonth = (dateVal.getMonth () + adjust) % 12;
  var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
  if (newMonth < 0) {
    newMonth += 12;
    newYear += -1;
  }
 
  return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</button>";
}


/**
Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator
variables at the beginning of this script library.
*/
function getDateString(dateVal)
{
  var dayString = "00" + dateVal.getDate();
  var monthString = "00" + (dateVal.getMonth()+1);
  dayString = dayString.substring(dayString.length - 2);
  monthString = monthString.substring(monthString.length - 2);
 
  switch (dateFormat) {
    case "dmy" :
      return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
    case "ymd" :
      return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
    case "mdy" :
    default :
      return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
  }
}


/**
Convert a string to a JavaScript Date object.
*/
function getFieldDate(dateString)
{
  var dateVal;
  var dArray;
  var d, m, y;
 
  try {
    dArray = splitDateString(dateString);
    if (dArray) {
      switch (dateFormat) {
        case "dmy" :
          d = parseInt(dArray[0], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
        case "ymd" :
          d = parseInt(dArray[2], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[0], 10);
          break;
        case "mdy" :
        default :
          d = parseInt(dArray[1], 10);
          m = parseInt(dArray[0], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
      }
      dateVal = new Date(y, m, d);
    } else if (dateString) {
      dateVal = new Date(dateString);
    } else {
      dateVal = new Date();
    }
  } catch(e) {
    dateVal = new Date();
  }
 
  return dateVal;
}


/**
Try to split a date string into an array of elements, using common date separators.
If the date is split, an array is returned; otherwise, we just return false.
*/
function splitDateString(dateString)
{
  var dArray;
  if (dateString.indexOf("/") >= 0)
    dArray = dateString.split("/");
  else if (dateString.indexOf(".") >= 0)
    dArray = dateString.split(".");
  else if (dateString.indexOf("-") >= 0)
    dArray = dateString.split("-");
  else if (dateString.indexOf("\\") >= 0)
    dArray = dateString.split("\\");
  else
    dArray = false;
 
  return dArray;
}

/**
Update the field with the given dateFieldName with the dateString that has been passed,
and hide the datepicker. If no dateString is passed, just close the datepicker without
changing the field value.

Also, if the page developer has defined a function called datePickerClosed anywhere on
the page or in an imported library, we will attempt to run that function with the updated
field as a parameter. This can be used for such things as date validation, setting default
values for related fields, etc. For example, you might have a function like this to validate
a start date field:

function datePickerClosed(dateField)
{
  var dateObj = getFieldDate(dateField.value);
  var today = new Date();
  today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
 
  if (dateField.name == "StartDate") {
    if (dateObj < today) {
      // if the date is before today, alert the user and display the datepicker again
      alert("Please enter a date that is today or later");
      dateField.value = "";
      document.getElementById(datePickerDivID).style.visibility = "visible";
      adjustiFrame();
    } else {
      // if the date is okay, set the EndDate field to 7 days after the StartDate
      dateObj.setTime(dateObj.getTime() + (7 * 24 * 60 * 60 * 1000));
      var endDateField = document.getElementsByName ("EndDate").item(0);
      endDateField.value = getDateString(dateObj);
    }
  }
}

*/
function updateDateField(dateFieldName, dateString)
{
  var targetDateField = document.getElementsByName (dateFieldName).item(0);
  if (dateString)
    targetDateField.value = dateString;
 
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.visibility = "hidden";
  pickerDiv.style.display = "none";
 
  adjustiFrame();
  targetDateField.focus();
 
  // after the datepicker has closed, optionally run a user-defined function called
  // datePickerClosed, passing the field that was just updated as a parameter
  // (note that this will only run if the user actually selected a date from the datepicker)
  if ((dateString) && (typeof(datePickerClosed) == "function"))
    datePickerClosed(targetDateField);
}


/**
Use an "iFrame shim" to deal with problems where the datepicker shows up behind
selection list elements, if they're below the datepicker. The problem and solution are
described at:

http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
*/
function adjustiFrame(pickerDiv, iFrameDiv)
{
  // we know that Opera doesn't like something about this, so if we
  // think we're using Opera, don't even try
  var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
  if (is_opera)
    return;
  
  // put a try/catch block around the whole thing, just in case
  try {
    if (!document.getElementById(iFrameDivID)) {
      // don't use innerHTML to update the body, because it can cause global variables
      // that are currently pointing to objects on the page to have bad references
      //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
      var newNode = document.createElement("iFrame");
      newNode.setAttribute("id", iFrameDivID);
      newNode.setAttribute("src", "javascript:false;");
      newNode.setAttribute("scrolling", "no");
      newNode.setAttribute ("frameborder", "0");
      document.body.appendChild(newNode);
    }
    
    if (!pickerDiv)
      pickerDiv = document.getElementById(datePickerDivID);
    if (!iFrameDiv)
      iFrameDiv = document.getElementById(iFrameDivID);
    
    try {
      iFrameDiv.style.position = "absolute";
      iFrameDiv.style.width = pickerDiv.offsetWidth;
      iFrameDiv.style.height = pickerDiv.offsetHeight ;
      iFrameDiv.style.top = pickerDiv.style.top;
      iFrameDiv.style.left = pickerDiv.style.left;
      iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
      iFrameDiv.style.visibility = pickerDiv.style.visibility ;
      iFrameDiv.style.display = pickerDiv.style.display;
    } catch(e) {
    }
 
  } catch (ee) {
  }
 
}
///////////////////////////fin datetimepicker//////////////////////////////////////////////
