var RC_Img =
[
// Repertoire des images
 "/images/formulaires/",
// Images Radio ( Off - On )
 ["r_0.gif", "r_1.gif"],
// Images CheckBox ( Off - On )
 ["CHECKBOX_0.gif", "CHECKBOX_1.gif"],
// Images Submit ( Off - On )
 ["s_0.gif", "s_1.gif"],
// Images Browse ( Off - On )
 ["b_0.gif", "b_1.gif"]
];

var RC_Data_identification =
[
 [ "CHECKBOX", "identification", "reconnaitre_hidden", "reconnaitre_btn", "petit", [ ["Toujours me reconnaître", "1", "0", "false"] ] ]
// ,
// [ "RADIO", "RC_Form", "f_age", "d_age", "bbb", [ ["18-25 ans", "18-25", "selected"], ["25-30 ans", "25-30", ""], ["30-35 ans", "30-35", ""], ["35-40 ans", "35-40", ""], ["+ 40 ans", "+40", ""] ] ], 
// [ "FILE", "s_file", "d_file", "ccc" ],
// [ "BUTTON", "s_submit", "d_submit", "GetValues();" ]
// SE RENDRE SUR http://www.asp-php.net/scripts/scripting/jsrdochkb.php POUR EXPLICATIONS
];

var RCArray = new Array();

function Radio_CheckBox( inIMAGES, inDATA, inNum ) {
 this.imgPath = inIMAGES[0];
 this.img = new RC_Images(inIMAGES, this);
 this.data = new RC_Read(inDATA, this, inNum);
 RCArray[inNum] = this;
 this.SwapImage = function( inDIV, inIMG, inOBJ)
 {
  if (document.images) {
   if (document.layers && inDIV != null) {
    eval("document." + inDIV + ".document.images['" + inIMG + "'].src = " + inOBJ + ".src;");
   } else {
    document.images[inIMG].src  = eval(inOBJ + ".src");
   }
  }
 };
 this.ToggleCheckBox = function( inINDX )
 {
  var oCB, iObj;
  oCB = this.data.aRead[inINDX];
  if (oCB.state == 1) {
   oCB.state = 0;
   eval("document." + oCB.oForm + "." + oCB.oInput + ".value = '" + oCB.off + "';");
   iObj = this.img.aImg[1][0];
  } else { 
   oCB.state = 1;
   eval("document." + oCB.oForm + "." + oCB.oInput + ".value = '" + oCB.on + "';");
   iObj = this.img.aImg[1][1];
  }
  this.SwapImage(oCB.oDiv, "chkb_" + inNum + "_" + inINDX, "this.img." + iObj);
 };
 this.ToggleRadio = function( inINDX, inRDO, inVALUE)
 {
  var oRdo, i;
  oRdo = this.data.aRead[inINDX];
  eval("document." + oRdo.oForm + "." + oRdo.oInput + ".value = '" + inVALUE + "';");
  for (i = 0; i < oRdo.nb; i++) {
   this.SwapImage(oRdo.oDiv, "rdo_" + inNum + "_" + inINDX + "_" + i, "this.img." + this.img.aImg[0][0]);
  };
  this.SwapImage(oRdo.oDiv, "rdo_" + inNum + "_" + inINDX + "_" + inRDO, "this.img." + this.img.aImg[0][1]);
 };
 this.Init = function()
 {
  var i = 0, iDiv;
  for (i = 0; i < this.data.aRead.length; i++) {
   iDiv = document.getElementById(this.data.aRead[i].oDiv);
   if (iDiv.innerHTML != "") {
    iDiv.insertAdjacentHTML("beforeend", "<br>" + this.data.aRead[i].str);
   } else {
    iDiv.innerHTML = this.data.aRead[i].str;
   }
  };
 };
 this.Init();
};

function RC_Images( inIMAGES, inOBJ ) {
 this.rc = inOBJ;
 this.aImg = new Array();
 this.Preload = function()
 {
  var i = 0;
  if (document.images) {
   for (i = 1; i < inIMAGES.length; i++) {
    eval("this." + (inIMAGES[i][0].substring(0, inIMAGES[i][0].indexOf('.'))) + " = new Image();");
    eval("this." + (inIMAGES[i][1].substring(0, inIMAGES[i][1].indexOf('.'))) + " = new Image();");
    eval("this." + (inIMAGES[i][0].substring(0, inIMAGES[i][0].indexOf('.'))) + ".src = '" + this.rc.imgPath + inIMAGES[i][0] + "';");
    eval("this." + (inIMAGES[i][1].substring(0, inIMAGES[i][1].indexOf('.'))) + ".src = '" + this.rc.imgPath + inIMAGES[i][1] + "';");
    this.aImg[this.aImg.length] = new Array((inIMAGES[i][0].substring(0, inIMAGES[i][0].indexOf('.'))), (inIMAGES[i][1].substring(0, inIMAGES[i][1].indexOf('.'))));
   };
  }
 };
 this.Preload();
};

function RC_Read( inDATA, inOBJ, inNum) {
 this.rc = inOBJ;
 this.aRead = new Array();
 this.Read = function()
 {
  var i = 0;
  for (i = 0; i < inDATA.length; i++) {
   switch (inDATA[i][0].toUpperCase()) {
    case "CHECKBOX": this.aRead[this.aRead.length] = new RC_CheckBox(inDATA[i], this.rc, this.aRead.length, inNum);break;
    case "RADIO": this.aRead[this.aRead.length] = new RC_Radio(inDATA[i], this.rc, this.aRead.length, inNum);break;
    case "BUTTON": this.aRead[this.aRead.length] = new RC_Button(inDATA[i], this.rc, this.aRead.length, inNum);break;
    case "FILE": this.aRead[this.aRead.length] = new RC_File(inDATA[i], this.rc, this.aRead.length, inNum);break;
   }
  };
 };
 this.Read();
};

function RC_CheckBox(inDATA, inOBJ, inINDX, inNum) {
 this.rc = inOBJ;
 this.indx = inINDX;
 this.oForm = inDATA[1];
 this.oInput = inDATA[2];
 this.oDiv = inDATA[3];
 this.str = "";
 this.state = -1;
 this.on = inDATA[5][0][1];
 this.off = inDATA[5][0][2];
 this.Init = function()
 {
  var h_value, i_value;
  if (inDATA[5][0][3].toUpperCase() == "TRUE") {
   h_value = inDATA[5][0][1];
   i_value = this.rc.img.aImg[1][1];
   this.state = 1;
  } else {
   h_value = inDATA[5][0][2];
   i_value = this.rc.img.aImg[1][0];
   this.state = 0;
  }
  this.str += "<a href=\"javascript:RCArray['" + inNum + "'].ToggleCheckBox(" + this.indx + ");\"";
  this.str += " border=\"0\"";
  if (inDATA[4] != "") {
   this.str += " class=\"" + inDATA[4] + "\"";
  }
  this.str += " onMouseOver=\"window.status=' ';return true;\"";
  this.str += " onMouseOut=\"window.status=' ';return true;\">";
  this.str += "<img name=\"chkb_" + inNum + "_" + this.indx + "\" src=\"" + eval("this.rc.img." + i_value + ".src") + "\" border=\"0\" align=\"absmiddle\">";
  this.str += "&nbsp;" + inDATA[5][0][0];
  this.str += "</a>";
  this.str += "<input type=\"hidden\" name=\"" + this.oInput + "\" value=\"" + h_value + "\">";
 };
 this.Init();
};

function RC_Radio(inDATA, inOBJ, inINDX, inNum) {
 this.rc = inOBJ;
 this.indx = inINDX;
 this.oForm = inDATA[1];
 this.oInput = inDATA[2];
 this.oDiv = inDATA[3];
 this.nb = inDATA[5].length;
 this.str = "";
 this.Init = function()
 {
  var i = 0, i_value, h_value, isSelected = 0;
  for (i = 0; i < inDATA[5].length; i++) {
   if (inDATA[5][i][2].toUpperCase() == "SELECTED") {
    if (isSelected == 0) {
     i_value = this.rc.img.aImg[0][1];
     h_value = inDATA[5][i][1];
     isSelected = 1;
    } else {
     i_value = this.rc.img.aImg[0][0];
    }
   } else {
    i_value = this.rc.img.aImg[0][0];
   }
   this.str += "<a href=\"javascript:RCArray['" + inNum + "'].ToggleRadio(" + this.indx + ", " + i + ", '" + inDATA[5][i][1] + "');\"";
   this.str += " border=\"0\"";
   if (inDATA[4] != "") {
    this.str += " class=\"" + inDATA[4] + "\"";
   }
   this.str += " onMouseOver=\"window.status=' ';return true;\"";
   this.str += " onMouseOut=\"window.status=' ';return true;\">";
   this.str += "<img name=\"rdo_" + inNum + "_" + this.indx + "_" + i + "\" src=\"" + eval("this.rc.img." + i_value + ".src") + "\" border=\"0\" align=\"absmiddle\">";
   this.str += "&nbsp;" + inDATA[5][i][0];
   this.str += "</a>";
   this.str += "<br>";
  };
  this.str += "<input type=\"hidden\" name=\"" + this.oInput + "\" value=\"" + h_value + "\">";
 };
 this.Init();
};

function RC_Button(inDATA, inOBJ, inINDX, inNum) {
 this.rc = inOBJ;
 this.indx = inINDX;
 this.oInput = inDATA[1];
 this.oDiv = inDATA[2];
 this.onClick = inDATA[3];
 this.str = "";
 this.Init = function()
 {
  this.str += "<a href=\"javascript:" + this.onClick + "\"";
  this.str += " border=\"0\"";
  this.str += " onMouseUp=\"RCArray['" + inNum + "'].SwapImage('" + this.oDiv + "', 'but_" + inNum + "_" + this.indx + "', 'this.img." + this.rc.img.aImg[2][0] + "');window.status=' ';return true;\"";
  this.str += " onMouseDown=\"RCArray['" + inNum + "'].SwapImage('" + this.oDiv + "', 'but_" + inNum + "_" + this.indx + "', 'this.img." + this.rc.img.aImg[2][1] + "');window.status=' ';return true;\"";
  this.str += " onMouseOver=\"window.status=' ';return true;\"";
  this.str += " onMouseOut=\"RCArray['" + inNum + "'].SwapImage('" + this.oDiv + "', 'but_" + inNum + "_" + this.indx + "', 'this.img." + this.rc.img.aImg[2][0] + "');window.status=' ';return true;\">";
  this.str += "<img src=\"" + eval("this.rc.img." + this.rc.img.aImg[2][0] + ".src") + "\" name=\"but_" + inNum + "_" + this.indx + "\" border=\"0\">";
  this.str += "</a>";
 };
 this.Init();
};

function RC_File(inDATA, inOBJ, inINDX, inNum) {
 this.rc = inOBJ;
 this.indx = inINDX;
 this.oInput = inDATA[1];
 this.oDiv = inDATA[2];
 this.str = "";
 this.Init = function()
 {
  this.str += "<input type=\"file\" name=\"" + this.oInput + "\" id=\"" + this.oInput + "\" style=\"display:none;\" onChange=\"document.all['file_" + inNum + "_" + this.indx + "'].value=document.all['" + this.oInput + "'].value;\">";
  this.str += "<input type=\"text\" class=\"" + inDATA[3] + "\" name=\"file_" + inNum + "_" + this.indx + "\" id=\"file_" + inNum + "_" + this.indx + "\" readonly>";
  this.str += "&nbsp;<a href=\"javascript:document.all['" + this.oInput + "'].click();\"";
  this.str += " border=\"0\"";
  this.str += " onMouseUp=\"RCArray['" + inNum + "'].SwapImage('" + this.oDiv + "', 'ifl_" + inNum + "_" + this.indx + "', 'this.img." + this.rc.img.aImg[3][0] + "');window.status=' ';return true;\"";
  this.str += " onMouseDown=\"RCArray['" + inNum + "'].SwapImage('" + this.oDiv + "', 'ifl_" + inNum + "_" + this.indx + "', 'this.img." + this.rc.img.aImg[3][1] + "');window.status=' ';return true;\"";
  this.str += " onMouseOver=\"window.status=' ';return true;\"";
  this.str += " onMouseOut=\"RCArray['" + inNum + "'].SwapImage('" + this.oDiv + "', 'ifl_" + inNum + "_" + this.indx + "', 'this.img." + this.rc.img.aImg[3][0] + "');window.status=' ';return true;\">";
  this.str += "<img src=\"" + eval("this.rc.img." + this.rc.img.aImg[3][0] + ".src") + "\" name=\"ifl_" + inNum + "_" + this.indx + "\" border=\"0\" align=\"absmiddle\">";
  this.str += "</a>";
  this.str += "";
 };
 this.Init();
};
