function prechargerNav()
{
	i1 = new Image;
	i1.src = "images/btn_produits_bis.gif";
	i2 = new Image;
	i2.src = "images/btn_vendeurs_bis.gif";
	i3 = new Image;
	i3.src = "images/btn_clients_bis.gif";
	i4 = new Image;
	i4.src = "images/btn_agents_bis.gif";
	i5 = new Image;
	i5.src = "images/btn_recherches_bis.gif";
	i6 = new Image;
	i6.src = "images/btn_documents_bis.gif";
	i7 = new Image;
	i7.src = "images/btn_quitter_bis.gif";
	i8 = new Image;
	i8.src = "images/btn_pub_bis.gif";
	i9 = new Image;
	i9.src = "images/btn_archives_bis.gif";
}

//Ouverture d'une pop up
function ouvreFenetre(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}

function confirmation(URL,MSG)
{
	if(confirm(MSG))
	{
		document.location.href=URL;
	}
}

function MailBz(adresse,delimiteur)
{
	tabMail = adresse.split(delimiteur)
	adresse_modif = tabMail[0]+tabMail[1];
	document.location.href='mailto:'+adresse_modif;
}

function ConfirmModal(URL,MSG)
{
	if(confirm(MSG))
	{
		ouvreFenetre(URL,'EnvoiMailing',800,450,'yes','center'); return false;
	}
}

function compter(target, nomchamp)
{
	strlen = target.value.length
	nomchamp.value = strlen;
}

var marked_row = new Array;
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

var isMozilla = (navigator.userAgent.toLowerCase().indexOf('gecko')!=-1) ? true : false;
var regexp = new RegExp("[\r]","gi");

function insertCode(selec,FormName,InputName)
{
	oField = document.forms[FormName].elements[InputName];
	if (isMozilla) 
	{
		objectValue = oField.value;
		deb = oField.selectionStart;
		fin = oField.selectionEnd;
		objectValueDeb = objectValue.substring( 0 , oField.selectionStart );
		objectValueFin = objectValue.substring( oField.selectionEnd , oField.textLength );
		objectSelected = objectValue.substring( oField.selectionStart ,oField.selectionEnd );	
		oField.value = objectValueDeb + "[" + selec + "]" + objectSelected + "[/" + selec + "]" + objectValueFin;
		oField.selectionStart = objectValueDeb.length;
		oField.selectionEnd = (objectValueDeb + "[" + selec + "]" + objectSelected + "[/" + selec + "]").length;
		oField.focus();
		oField.setSelectionRange(
			objectValueDeb.length + selec.length + 2,
			objectValueDeb.length + selec.length + 2);
	}
	else
	{
	// Si on est sur IE
		var str = document.selection.createRange().text;
		if (str.length>0)
		{
		// Si on a selectionné du texte
			var sel = document.selection.createRange();
			sel.text = "[" + selec + "]" + str + "[/" + selec + "]";
			sel.collapse();
			sel.select();
		}
		else
		{
			oField.focus(oField.caretPos);
			oField.focus(oField.value.length);
			oField.caretPos = document.selection.createRange().duplicate();
			var bidon = "%~%";
			var orig = oField.value;
			oField.caretPos.text = bidon;
			var i = oField.value.search(bidon);
			oField.value = orig.substr(0,i) + "[" + selec + "][/" + selec + "]" + orig.substr(i, oField.value.length);
			var r = 0;
			for(n = 0; n < i; n++)
			{if(regexp.test(oField.value.substr(n,2)) == true){r++;}};
			pos = i + 2 + selec.length - r;
			var r = oField.createTextRange();
			r.moveStart('character', pos);
			r.collapse();
			r.select();
		}
	}
}

function download_pdf2(pdf,msgPopup,buttName)
{
	var msgBox = msgPopup;
	msgBox += '<form name="formCookie" method="POST">';
	msgBox += '<input type="hidden" name="CO_type" value="Visiteur" />';
	msgBox += '<input type="text" name="CO_email" value="" style="width:250px;" />';
	msgBox += '<input type="submit" name="btCookie" value="ok" style="width:60px;margin-left:5px;" />';
	msgBox += '</form>';
	
	var btns = {};
	btns[buttName] = true;
	$.prompt(msgBox,
	{
		buttons:btns,
		opacity:0.8,
		submit:function(v,m,f)
		{
			if(v)
			{
				$(location).attr('href','/contact-pdf.html');
			}
		}
	});
}


function download_pdf(pdf,msgPopup1,msgPopup2,buttName1,buttName2,buttName3,buttName4)
{		
	var msgBox1 = msgPopup1;	
	var msgBox2 = msgPopup2;
	msgBox2 += '<form name="formCookie" method="POST">';
	msgBox2 += '<input type="hidden" name="CO_type" value="Visiteur" />';
	msgBox2 += '<input type="text" name="CO_email" value="" class="backoffice" style="width:250px;" />';
	msgBox2 += '<input type="submit" name="btCookie" value="ok" class="SubmitPrompt" style="width:60px;" />';
	msgBox2 += '</form>';
	
	var btnState0 = {};
	btnState0[buttName1] = 1;
	btnState0[buttName2] = 2;
	
	var btnState1 = {};
	btnState1[buttName3] = -1;
	btnState1[buttName4] = 0;
	
	var myPrompt = {
		  state0: {
				html:msgBox1,
				buttons:btnState0,
				focus:1,
				submit:function(v,m,f) { 
					  if(v==1) { $(location).attr('href','/contact-pdf.html'); }
					  if(v==2) { $.prompt.goToState('state1'); }
					  return false;
				}
		  },
		  state1: {
				html:msgBox2,
				buttons:btnState1,
				focus: 1,
				submit:function(v,m,f){ 
					  if(v==0) $.prompt.close()
					  else if(v=-1)
							$.prompt.goToState('state0');
					  return false; 
				}
		  }
	};

	$.prompt(myPrompt);
}