// Keren Yu created Mar 7, 2010
// Keren Yu modified Apr 8, 2010
//          added checkbox array
   
   function restoreCookies(obj) {
      var cookieValue;
      var childObj;
      var grandChildObj;
      var sel;
      
      // restore premiums
      result = readCookie("premiums");
      if (result) {
          result = result.split(",");
          childObj = obj.getElementsByTagName("tt");
          for (i=0; i<childObj.length; i++) {
              childObj[i].innerHTML = result[i];
          }
      }            
      
      // restore input data
      childObj = obj.getElementsByTagName("input");
      chechbox_number = 0;
      chechbox_name = "";
      for (i=0; i<childObj.length; i++) {
            grandChildObj = childObj[i];
      
                if (grandChildObj.type == "text") {
                      cookieValue = readCookie(grandChildObj.name);
                      grandChildObj.value = cookieValue;
                }
                
                // restore checkboxes
                if (grandChildObj.type == "checkbox") {
                  if (chechbox_name != grandChildObj.name) {
                    chechbox_name = grandChildObj.name;
                    chechbox_number = 0;
                  } else {
                    chechbox_number++;
                  }
                  cookieValue = readCookie(grandChildObj.name + chechbox_number);
                  if (cookieValue != null) {
                    if (cookieValue != "off") {
                      grandChildObj.checked = true;
                    } else {
                      grandChildObj.checked = false;
                    }
                  }
                }
                
                // restore radios
                if (grandChildObj.type == "radio") {
                   cookieValue = readCookie(grandChildObj.name);
                   if (cookieValue != null) {
                      if ( cookieValue == grandChildObj.value) {
                           grandChildObj.checked = true;
                      } else {
                           grandChildObj.checked = false;
                      }
                   }
               }
           
      }
      
      // restore select items
      childObj = obj.getElementsByTagName("select");
      for (i=0; i<childObj.length; i++) {
            sel = childObj[i];
            cookieValue = readCookie(sel.name);
            if (cookieValue) {
                for (j=0; j<sel.options.length; j++) {
                    if (sel.options[j].value == cookieValue) {
                        sel.selectedIndex = j;
                    }
                }
            } 
      }
      
   }
 

