/**
 * Copyright (c) 2006, ARC Technologies.
 * All Rights Reserved
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * File     $Id: HtmlFactory.js 916 2007-06-11 07:59:40Z emann $ <br />
 * Author   Ed Mann <ed.mann at arctechnologies dot net>
 * Last Changed By   $LastChangedBy: emann $ <br />
 * Last Changed Date $LastChangedDate: 2007-06-11 02:59:40 -0500 (Mon, 11 Jun 2007) $ <br />
 * Description:  File will build different html page objects.
 * @package eve.javascript.factory
 */
 
/**
 * do Fill Page
 * 
 * Function will take an xmlDoc return and a list of elements to fill. It will loop
 * through the element list and pull the corisponding xmlDoc value. If it is found it will
 * fill the page with an id of the same name as the element name and place that value in it.
 * 
 * @param {mixed} xmlDoc value
 * @param {array} page element array
 * @throws {string} Field that error is on as alert.
 */
function doFillPage(xmlDoc, elements){
    try{
      for(var i = 0; i < elements.length; i++){
          var item = elements[i];
    	    /**
             * check our values comming back from the server
             */
         if( xmlDoc.item(0).getElementsByTagName(item).item(0).firstChild ){
 	        document.getElementById(item).innerHTML = xmlDoc.item(0).getElementsByTagName(item).item(0).firstChild.data;
 	    } else {
 	        document.getElementById(item).innerHTML = "";
 	    }
      }
      } catch(e) {
          alert(e+" on page element "+item);
      }
}

/**
 * do Set Checkbox
 */
function doSetCheckboxes(xmlDoc, elements){
    try{
      for(var i = 0; i < elements.length; i++){
          var item = elements[i];
    	    /**
             * check our values comming back from the server
             */
         if( xmlDoc.item(0).getElementsByTagName(item).item(0).firstChild ){
             var state = xmlDoc.item(0).getElementsByTagName(item).item(0).firstChild.data;
             if(state == 1){
 	              document.getElementById(item).checked = true;
             } else {
                 document.getElementById(item).checked = false;
             }
 	    } else {
 	        document.getElementById(item).checked = false;
 	    }
      }
      } catch(e) {
          alert(e+" on page element "+item);
      }
}

/**
 * Empty List
 * Function will empty the given dropdown list
 * @param string list id name
 */
 function emptyList(list) {
        // Set each option to null thus removing it
        while ( list.options.length ) list.options[0] = null;
}

/**
 * fill List
 * Function will fill the given dropdown list with the passed in xml. Xml needs to have list_opt with the option
 * for the list and list_val for the value to display.
 * @param string list id name
 * @param string xml code to use to fill dropdown list.
 */
function fillList(list,values) {
         count = values.getElementsByTagName("list_item")
        for (var i = 0 ; i < count.length ; i++) {
        var len = list.length++; // Increase the size of list and return the size
        list.options[len].value = values.getElementsByTagName('list_opt').item(i).firstChild.data;
        list.options[len].text = values.getElementsByTagName('list_val').item(i).firstChild.data;
        }

}

 
