var http;
var outObj;

function getHTTPObject() {

  var xmlhttp;

  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
        xmlhttp = false;
        }
      }
  @else
  xmlhttp = false;
  @end @*/

  	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	    try {
	      xmlhttp = new XMLHttpRequest();
	      } catch (e) {
	      xmlhttp = false;
	      }
		}
  	return xmlhttp;
}

function ajax(method,url,param,fonction) {

  var f = fonction;

  http.open(method, url, true);
  http.onreadystatechange = f;
  if (param != null) {
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", param.length);
    http.setRequestHeader("Connection", "close");
  }
  http.send(param);
}

/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}


//Fontion Input Identification
function ClsIn(ChIn,IdIn) {
	var inCont = document.getElementById(IdIn);
	if (inCont.value == "" && inCont.value != ChIn) {
		inCont.value = ChIn;
	} else {
		if (inCont.value == ChIn) {
			inCont.value = "";
		}
	}
}


function CmdAdd(NbDisp) {
	var InObj = document.getElementById("gNb");
	if (parseInt(InObj.value) < NbDisp) {
		InObj.value = parseInt(InObj.value) + 1;
	}
}

function CmdDel() {
	var InObj = document.getElementById("gNb");
	if (parseInt(InObj.value) > 1) {
		InObj.value = parseInt(InObj.value) - 1;
	}
}

function GdsSel(inId,outId) {

	http = getHTTPObject();
	var inObj = document.forms[1].elements[inId];
	outObj = document.forms[1].elements[outId];
	var i;
	var iMax = outObj.length;
	var param = "mode=" + encodeURI(inId) + "&idExt=" + encodeURI(inObj.options[inObj.selectedIndex].value);

	if (inObj.options[0].value != "X") {

		ajax('POST','action/gdsort.php',param,GdsView);

		for (i=0;i<iMax;i++) {
			outObj.options[0] = null;
		}

	}
}




function GdsView(){


	if (http.readyState == 4) {
		var result = http.responseText;

		var gItem = result.split("|");
		var iItem;
		var iVal;
		var iTxt;
		var iNew;
		var o;
		var oMax = gItem.length - 1;

		iNew = new Option("Tout","X");
		outObj.options[outObj.length] = iNew;

		for (o=0;o<oMax;o++) {

			iItem = gItem[o].split("{");
			iVal = iItem[0];
			iTxt = iItem[1];

			if (iVal == "0") {
				outObj.options[0].value = "0";
			} else {
				iNew = new Option(iTxt,iVal);
				outObj.options[outObj.length] = iNew;
			}
		}
	}
}


function BtqModif(idFull,dirImg) {

	var ImgFull = document.getElementById(idFull);
	ImgFull.src = "images/boutique/" + dirImg;

}

function affichage_popup(nom_de_la_page, nom_interne_de_la_fenetre)
{
window.open (nom_de_la_page, nom_interne_de_la_fenetre, config='height=700, width=740, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no')
}


