var Hidable=new Array();
var show_image="http://www.change2it.com/mci/explode.gif";
var hide_image="http://www.change2it.com/mci/implode.gif";
var rowShow=(document.all?'block':'table-row');

function shEl(target) {
  document.getElementById(target).style.display=rowShow;
}
function hiEl(target) {
  document.getElementById(target).style.display='none';
}
function show_div(element,innerText){
		state=('none'==document.getElementById(element).style.display?1:0);
		document.getElementById(element).innerHTML=innerText;		
		//change the style of the element (visiblue-invisible)
		document.getElementById(element).style.display=(state==1?'block':'none');
}

function toggle_element_with_label(element,detonator_el,on_text,Off_text,innerText){
		state=('none'==document.getElementById(element).style.display?1:0);
		document.getElementById(element).innerHTML='<img src="http://www.change2it.com/mci/help_ico.gif" align="absmiddle" > '+innerText;
                //window.alert(innerText);		
		//change the style of the element (visiblue-invisible)
		document.getElementById(element).style.display=(state==1?'block':'none');
		//change the text of the link that triggered this change
        document.getElementById(detonator_el).innerHTML=(state?on_text:Off_text);
}


function add_2_hidable(key)
{
  // adds a new empty array in the "key" position of the global Hidable array
   Hidable[key]=new Array();
}

function add_2_key(key,element_string){
 var temp_array;
 
 temp_array=Hidable[key];
 Hidable[key][temp_array.length]=element_string;
 
}

function changeLabel(element,btn_label_show,btn_label_hide,element_type, state) {

	//change the button caption if element_type is "button"
	if (element_type=="button"){
		document.getElementById(element).value=(state==1?btn_label_hide:btn_label_show);
	}
	//change the text caption if element_type is "text"
	if (element_type=="text"){ 
		document.getElementById(element).innerHTML=(state==1?btn_label_hide:btn_label_show);
	}
	//change the image if element_type is "image"
	if (element_type=="image"){
		document.getElementById(element).src=(state==1?hide_image:show_image);
	}	
}
// Toggles an element from visible to invisible and vice versa
// element_type must be "button" , "image" or "text"
// If "image" then the globals show_image / hide_image variables are used
// if "button" or "text" the btn_label_show, btn_label_hide variables must contain the desired text without HTML code
function toggleElements(prefix,element,btn_label_show,btn_label_hide,element_type) {

	var el,i,state;
	
	//DEBUG alert ("Hidable["+prefix+"]="+Hidable[prefix].length);
	var temp_array=Hidable[prefix];
	for (i=0; i<temp_array.length; i++) {
		el=document.getElementById(temp_array[i]);
		//DEBUG alert ("temparray["+i+"]="+temp_array[i]);
	    // get the current display state of the element 
		state=('none'==el.style.display?1:0);
		//change the style of the element (visiblue-invisible)
		el.style.display=(state?rowShow:'none');
	}
	changeLabel(element,btn_label_show,btn_label_hide,element_type, state)
	//change the button caption if element_type is "button"
//	if (element_type=="button"){
		//document.getElementById(element).value=(state==1?btn_label_hide:btn_label_show);
	//}
	//change the text caption if element_type is "text"
	//if (element_type=="text"){ 
		//document.getElementById(element).innerHTML=(state==1?btn_label_hide:btn_label_show);
	//}
	//change the image if element_type is "image"
	//if (element_type=="image"){
		//document.getElementById(element).src=(state==1?hide_image:show_image);
	//}	
}


// This routine makes an element visible/invisible explicitly
// using the state variable
function SetElements(prefix,state) {
	var el,i;
// alert ("Hidable["+prefix+"]="+Hidable[prefix].length);
	var temp_array=Hidable[prefix];
	for (i=0; i<temp_array.length; i++) {
		el=document.getElementById(temp_array[i]);
// alert ("temparray["+i+"]="+temp_array[i]);
		el.style.display=state;
	}
}

//Changes the appearence of the controls (buttons, images,text)
// controls_array contains the id's of the elements
// control_type may be "button", "text" or "image"
// caption_string is applicable to "button" and "text" only
function set_expand_controls(controls_array,control_type,state,caption_string){
 var i,el;
 
 	for (i=0; i<controls_array.length; i++){
	
 			el=document.getElementById(controls_array[i]);

			//change the button caption if element_type is "button"
			if (control_type=="button"){
				el.value=caption_string;
			}

			//change the text caption if element_type is "text"
			if (control_type=="text"){ 
				el.innerHTML=caption_string;
			}

			//change the image if element_type is "image"
			if (control_type=="image"){
				el.src=(state==1?hide_image:show_image);
			}
 	}
}

// Toggles a group of elements to visible/invisible NOT just an element
// and is used to EXPAND ALL - HIDE ALL
function toggle_group(group_array,thecontrol,thecontrol_type,btn_label_show,btn_label_hide,control_type,control_array){
	//thecontrol_tpye can be text or button.  It cannot be an image
	var i;
        var inputcontrol;       
			//Get the value of the label on the 'thecontrol'
			if (thecontrol_type=="button"){
				inputcontrol=document.getElementById(thecontrol).value;
			}
			else {if (thecontrol_type=="text"){ 
				inputcontrol=document.getElementById(thecontrol).innerHTML;
			}}
       
       
       //alert (inputcontrol);
	   if (inputcontrol!=btn_label_show) {	        // HIDE EVERYTHING
 			for (i=0; i<group_array.length; i++){
				SetElements(group_array[i],'none');
			}	
			set_expand_controls(control_array,control_type,0,btn_label_show);
                        changeLabel(thecontrol,btn_label_show,btn_label_hide,thecontrol_type, 0)
	   }else{
	        // SHOW EVERYTHING
   			for (i=0; i<group_array.length; i++){
	   			SetElements(group_array[i],rowShow);		
			}	
			set_expand_controls(control_array,control_type,1,btn_label_hide);
                        changeLabel(thecontrol,btn_label_show,btn_label_hide,thecontrol_type, 1)
	   }	
	
}
// this routine clears out a listbox or combo box
function clearlistbox(listboxstr){
  var el;
  el = document.getElementById(listboxstr);
  for (var i = el.options.length; i >= 0; i--){
   	el.options[i] = null;
  }
  el.selectedIndex = -1;
}
 // this routine adds a new item to our listbox
function add_option_2_listbox(listboxstr, nValue, sText){
  var el = document.getElementById(listboxstr);
  el.options[el.options.length] =new Option(sText, nValue);
}
 // this routine chooses the selected value of a listbox
function choose_selected_value(listboxstr, sValue){
  var el = document.getElementById(listboxstr);
  el.selectedIndex = sValue;
}
function resizeMe(obj,hite){ 
 document.getElementById(obj).height = hite + 'px';
} 
function chht(target, sText){
  document.getElementById(target).innerHTML=sText;
}
function chfi(target, sText){
  document.getElementById(target).value=sText;
}
function set_checkbox(the_checkbox, checked){
  var el=document.getElementById(the_checkbox);
  el.checked=checked;
}