function calendar(container,path,place)
{
	var iframe=document.createElement("iframe");
	fdroite=document.getElementById(container);
	iframe.style.backgroundColor =fdroite.style.backgroundColor;
	
	iframe.width=200;
	iframe.height=130;
	iframe.scrolling = "no";
	iframe.frameBorder = 0;
	iframe.border = 0;
	//iframe.style.border = 0;
	//iframe.className="L200H130";
	iframe.src=path;
	//fdroite.appendChild(iframe);
	//obj=document.getElementById("droite1");
	eval('fdroite.insert'+place+'(iframe,fdroite.firstChild)');
	//alert(fdroite.lastChild.id);
}

function openListChild(parentName,parentIDfldname,childName)
{
	parentID=document.getElementById(parentIDfldname).value;
	eval(childName+'=window.open("../'+childName+'/'+childName+'.php?parentID='+parentID+'","'+childName+'","menubar=no");');
	fen=eval(childName);
	fen.focus();
}

/** * Encode a string as URL */
function URLencode(sStr) 
{
	if(window.ActiveXObject)
		sStr=sStr.replace(/\r/g,"'+char(13)+'").replace(/\n/g,"'+char(10)+'");
	else
		sStr=sStr.replace(/\n/g,"'+char(13)+char(10)+'");
	sStr=escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27');
    return sStr;
}

/** * Get datetime in "dd/mm/yyyy hh:mm:ss" format */
function getDateTime()
{
	curDate=new Date();
	an=curDate.getYear();
	an+=1900;
	return curDate.getDate()+"/"+(curDate.getMonth()+1)+"/"+an+" "+curDate.getHours()+":"+curDate.getMinutes()+":"+curDate.getSeconds();
	
}

/** * Erase all first and last space caracters of a string value "val" */ 
function trim(val)
{
	try
	{
		re=new RegExp("\^\\s+\|\\s+\$")
		while (re.test(val))
		{
			val=val.replace(re,"");
		}
	}
	catch(er)
	{
		alert("Une erreur est survenue  dans la fonction trim !"+"\nNom:"+er.name+"\nMsg:"+er.message);
	};
	return val;
}

/** * Test if a string is an email address */
function testmail(val)
{
	if(val!="")
	{
		alpha =/\S.+\w.+/;
		res_alpha= alpha.test(val);//test si c'est de l'alpahanumerique sans espace, retour chariot, tabulation, etc...
		point = /\./;
		res_point = point.test(val);//test s'il y a au moins 1 .
		arobase_point = /@.+\./;
		res_arobase_point = arobase_point.test(val);//test si il y a un @ avant un .
		interdit1 = /(\.@|@\.|^@|@$)/;//Interdit un mail qui commence ou finit par @
		interdit2 = /(^\.|\.$|\.\.+)/;//Interdit un mail qui commence ou finit . ou n . d'affiler, etc
		interdit3 = /[éèàùêâôïëäöÿüç^¨\[\]\{\}\##\&\,\;\:\/\!\$\%\*\!\+\=\?\|\/\°\(\)\\\s]/;//ces caractères sont interdits
		car=/(\.{2,})/;
		while (car.test(val))
		{
			val=val.replace(car,".");
		}
		car=/(@{2,})/;
		while (car.test(val))
		{
			val=val.replace(car,"@");
		}
		arobase = /@/g;
		resultat = val.match(arobase);//compte le nombre d'@ (erreur si > 1)
		//alert("alpha="+res_alpha+"\nPoint="+res_point+"\nArob_Point="+res_arobase_point+"\nNbRes="+resultat.length);
		if(res_alpha && res_point && res_arobase_point && resultat.length==1 && !interdit1.test(val) && !interdit2.test(val) && !interdit3.test(val))
			return true;
		else
			return false;
	}
	else
		return true;
}


/**
* Need datatype attribute to be set in the form's object , ex : <input name="test" id="test" value="test" datatype="varchar">
* Check if the type of the objects value match the datatype attribute
*/
function isFormValide(f)
{
	for(i=0;i<f.length;i++)
	{
		//el=f.elements(i);
		el=f[i];
		
		if(typeof(el.datatype)!="undefined" && el.value!="" && el.name.search(/^PARAM_/)==-1)
		{//alert(el.name+" "+ el.name.search(/^PARAM_/));
			switch(el.datatype)
			{
				case "int":
				case "smallint":
				case "float":
				case "decimal":
				case "numeric":
				case "real":
					if(isNaN(el.value))return false;
				break;
				case "date":
				case "datetime":
				case "smalldatetime":
					if(!isDateFormat(el.value))return false;
				break;
				case "mail":
					if(!testmail(el.value))return false;
				break;
			}
		}
		
		//alert(f.elements(i).name);
	}
	return true;
}

/**
* Set the value elementValue in the "elementName" object if it exists in the document
* Exception : the Name can't be PARAM_RECH (used to post SQL data)
*/
function setFormElements(elementName,elementValue)
{
	// && el.type!="submit" && el.type!="button"
	//alert(document.getElementById(trim(elementName))+" : ["+trim(elementName)+"]="+elementValue);
	if(document.getElementById(trim(elementName)))
	{
		el=document.getElementById(trim(elementName));
		//alert(el.name+ " type:"+el.type+ "? "+el.value+" = "+elementValue);
		if(el.name!="PARAM_RECH")
		{
			switch(el.type)
			{
				case "radio":
					el=eval(el.form.name+"."+el.name);
					for(elIndex=0;elIndex<el.length;elIndex++)
						el[elIndex].checked=(elementValue==el[elIndex].value);
				break;
				case "checkbox":
					el.checked=(elementValue==el.value);
				break;
				case "select-multiple":
					elementValue=elementValue.split(",");
					for(j=0;j<elementValue.length;j++)
					{
						for(k=0;k<el.length;k++)
							for(k=0;k<el.length;k++)
								el.options[j].selected=(el.options[k].value == elementValue[j]);
					}
				break;
				default:
					el.value=elementValue;
				break;
			}
		}
	}
}

function changeXSL(f,format)
{
	/*paramrech=document.createElement("input");
	f.appendChild(paramrech);
	paramrech.type="hidden";
	paramrech.name="PARAM_RECH";
	paramrech.id="PARAM_RECH";*/
	/*alert(document.getElementById("PARAM_RECH").type);*/
	paramrech=document.getElementById("PARAM_RECH");
	if(typeof(sql)!="undefined" && sql!="")
	{
		paramrech.value=sql;
		openWin("ListingModel","about:blank",[800,300]);
		f.target="ListingModel";
		f.action="?format="+format;
		f.submit();
	}
}

function openXLS()
{
	f=document.getElementById("form1");
	f.action="?format=xls";
	f.submit();
}
