

function submitenter(myfield,e,url)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
 
if (keycode == 13)
   {
   return performSearch(myfield.id,url);
   }
else
   return true;
}

function performSearch(id, url)
{
    var query = document.getElementById(id).value;
    if(query != '' && query != 'Trouvez un article paru depuis 1999' && query != 'Recherchez dans tout le site')
    {
        document.location.replace(url + '?q=' + query);
    }
        
    return false;
}

function loginsubmitenter(e,itemid)
{
if (document.getElementById) {
    var button = document.getElementById(itemid);
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13)
       {
       button.click();
       }
    else
       return true;
    }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_blockHideLayers() { //v6.0
  var i,p,v,obj,args=MM_blockHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}


var menu_status;

function showHide(itemid){
    //alert(itemid);
    //alert(document.getElementById(itemid).className);
    if(_pageLoadingIsCompleted)
    {
        if (document.getElementById) {
	        var switch_id = document.getElementById(itemid);
	        if(menu_status != 'show') 
	        {
		        // switch_id.className = 'show';
		        //alert('Show');
		        removeClass(switch_id, 'hide');
		        addClass(switch_id, 'show');
		        menu_status = 'show';
    			
	        }
	        else
	        {
		        // switch_id.className = 'hide';
		        //alert('Hide');
		        removeClass(switch_id, 'show');
		        addClass(switch_id, 'hide');
		        menu_status = 'hide';
	        }
        }
    }
}

function hasClass(el, className) {
    var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
    return re.test(el.className);
}

function addClass(el, className) {
    if (hasClass(el, className)) { return; } // already present

    el.className = [el.className, className].join(' ');
}

function removeClass(el, className) {
    var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)', 'g');

    if (!hasClass(el, className)) { return; } // not present

    var c = el.className;
    el.className = c.replace(re, ' ');
    if ( hasClass(el, className) ) { // in case of multiple adjacent
	    removeClass(el, className);
    }
}

function writeOffer(path,id,width,height) {
    var so = new SWFObject(path, id, width, height, "6", "#ffffff");
    so.addParam("wmode", "transparent");
    so.write(id);
} 				

function fermerVolet(itemid) {
	if (document.getElementById) {
		var switch_id = document.getElementById(itemid);
		removeClass(switch_id, 'show');
		addClass(switch_id, 'hide');
	}
}

function ouvrirVolet(itemid){
	if (document.getElementById) {
		var switch_id = document.getElementById(itemid);
		removeClass(switch_id, 'hide');
		addClass(switch_id, 'show');
	}
}

//TODO: Completer cette logique pour envoyer a un ami
function Suggerer(pURL, pDocumentID, pParams)
{
	jsURL= pURL + '?pDocumentID=' + pDocumentID + '&pParams=' + pParams;
	jsNom='suggerer';
	jsParam='toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,history=no,resizable=yes,width=405,height=510,left=1,top=1';
	window.open(jsURL, jsNom, jsParam)
}

function Hein()
{
    jsURL = "/Templates/EnvoyerTrouvailles.aspx";
	jsParam='toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,history=no,resizable=no,width=405,height=330,left=1,top=1';
	window.open(jsURL, "trouvailles", jsParam);
}

function Print(pURL, pDocumentID, pNodeTypeID)
{
	jsURL=pURL+'?pDocumentID='+pDocumentID+'&pNodeTypeID='+pNodeTypeID;
	jsNom='print';
	jsParam='toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=405,height=510,left=1,top=1';
	window.open(jsURL, jsNom, jsParam)
}

//DateSelection
function pv_daysinmonth(lnMonth,lnYear) {
    var dt1, cmn1, cmn2, dtt, lflag, dycnt, lmn
    lmn = lnMonth-1
    dt1 = new Date(lnYear,lmn,1)
    cmn1 = dt1.getMonth()
    dtt=dt1.getTime()+2332800000
    lflag = true
    dycnt=28
    while (lflag) {
       dtt = dtt + 86400000
       dt1.setTime(dtt)
       cmn2 = dt1.getMonth()
       if (cmn1!=cmn2) {
          lflag = false }
       else {dycnt = dycnt + 1}}
    if (dycnt > 31) {dycnt = 31}
    return dycnt
}

function pv_setdays(sobjname, datemode){
    var dobj = $get(sobjname + "D")
    var mobj = $get(sobjname + "M")
    var yobj = $get(sobjname + "Y")
    
    var hobj = $get(sobjname)
    var monthdays = pv_daysinmonth(mobj.options[mobj.selectedIndex].value,yobj.options[yobj.selectedIndex].value)
    var selectdays = dobj.length
    var curdy = dobj.options[dobj.selectedIndex].value
    if (curdy.length==1) {curdy = "0"+curdy}
    var curmn = mobj.options[mobj.selectedIndex].value
    if (curmn.length==1) {curmn = "0"+curmn}
    var curyr = yobj.options[yobj.selectedIndex].value
    if (selectdays > monthdays) {
       for (var dlp=selectdays; dlp > monthdays; dlp--) {
           dobj.options[dlp-1] = null }}
    else if (monthdays > selectdays) {
       for (var dlp=selectdays; dlp < monthdays; dlp++) {
           dobj.options[dlp] = new Option(dlp+1,dlp+1) }}       
    if (curdy > monthdays) {
       dobj.options[monthdays-1].selected = true
       curdy = monthdays }
    if (datemode==1) {
       var curdate = curmn+"/"+curdy+"/"+curyr }
    else if (datemode==2) {
       var curdate = curdy+"/"+curmn+"/"+curyr }
    else if (datemode==3) {
       var curdate = curyr+curmn+curdy }
    else if (datemode==4) {
       var cdate = new Date(curyr,curmn-1,curdy)
       var curdate = cdate.toGMTString() }
   }

function ValidateLength(source, arguments) {
   arguments.IsValid = arguments.Value.length >= 6;
}