

//A function to write to a div layer in the different browsers.
function writeLayer(ID,parentID,sText) 
{ 
	if (document.layers) 
  { 
  	var oLayer; 
  	if(parentID)
  		oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); 
  	else
  		oLayer = document.layers[ID].document; 
  	oLayer.open(); 
  	oLayer.write(sText); 
  	oLayer.close(); 
  } 
  else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") 
  { 
    document.getElementById(ID).innerHTML = sText; 
  } 
  else if (document.all) 
  {
    document.all[ID].innerHTML = sText; 
  }
  return;
}   //end function writeLayers



//THIS FUNCTION IS USING THE SCRIPTACULOUS LIBRARY EFFECTS
function switchDisplay(fromEl,toEl)
{
  //this will hide the element
  Element.hide(fromEl);
  //the content will appear in form of a fade in
  Effect.Appear(toEl,{duration:1.5});
}
/*
function switchDisplay(fromEl,toEl) 
{
  Element.hide(fromEl);
  //This will show the div content without any special effects
  //Element.show(toEl);
  
  //the content will appear sliding down on the page
  //Effect.BlindDown(toEl);
  
  //the content will appear in form of an fade in
  Effect.Appear(toEl,{duration:1.5});
}

*/

function getElementValue(ID,parentID)
{
  var value = '';
  if (document.layers) 
  { 
  	var oLayer; 
  	if(parentID)
  		oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); 
  	else
  		oLayer = document.layers[ID].document; 
  	//oLayer.open(); 
  	//oLayer.write(sText); 
  	//oLayer.close(); 
  	value = oLayer.value;
  } 
  else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") 
    value = document.getElementById(ID).value;
  else if (document.all) 
    value = document.all[ID].value;
  
  return value;
} //end function getElementValue


function getElementObj(ID,parentID)
{
  var obj = '';
  if (document.layers) 
  { 
  	if(parentID)
  		obj = eval('document.' + parentID + '.document.' + ID + '.document'); 
  	else
  		obj = document.layers[ID].document; 
  } 
  else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") 
    obj = document.getElementById(ID);
  else if (document.all) 
    obj = document.all[ID];
  
  return obj;
} //end function getElementObj

//THIS FUNCTION WILL CHANGE THE NAME OF A CLASS FOR A DIV
function changeClassName(ID, parentID, newClassName)
{
  if (document.layers) 
  { 
  	var oLayer; 
  	if(parentID)
  		oLayer = eval('document.' + parentID + '.document.' + ID + '.document'); 
  	else
  		oLayer = document.layers[ID].document; 
  	//oLayer.open(); 
  	//oLayer.write(sText); 
  	//oLayer.close(); 
  	alert('oops, error!');
  } 
  else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") 
  { 
    //CHANGE THE DIV CLASS
    document.getElementById(ID).className = newClassName;
  } 
  else if (document.all) 
  {
    document.all[ID].className = newClassName;
  }
  return;
} //end function 

function serializeArray(a)
{
	var a_php = "";
	var total = 0;
	for (var key in a){
		if (++total > a.length)
			break;
		a_php = a_php + "i:" + (total-1) + ";" + "s:" +
			//String(key).length + ":\"" + String(key) + "\";s:" +
			String(a[key]).length + ":\"" + String(a[key]) + "\";";
	}
	a_php = "a:" + (total-1) + ":{" + a_php + "}";
	return a_php;
}

/*
function getSelectedRadio(buttonGroup) 
{
  //returns the array number of the selected radio button or -1 if no button is selected
  if (buttonGroup[0]) 
  { // if the button group is an array (one button is not an array)
    for (var i=0; i<buttonGroup.length; i++) 
    {
      if (buttonGroup[i].checked) 
      {
        return i
      }
    }
  } 
  else 
  {
    if (buttonGroup.checked)
    return 0;  // if the one button is checked, return zero
  }
  // if we get to this point, no radio button is selected
  return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) 
{
  // returns the value of the selected radio button or "" if no button is selected
  var i = getSelectedRadio(buttonGroup);
  if (i == -1) 
    return "";
  else 
  {
    if (buttonGroup[i]) 
    { // Make sure the button group is an array (not just one button)
     return buttonGroup[i].value;
    } 
    else 
    { // The button group is just the one button, and it is checked
     return buttonGroup.value;
    }
  }
} // Ends the "getSelectedRadioValue" function
*/
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}



function getSelectedCheckbox(buttonGroup) 
{
  // Go through all the check boxes. return an array of all the ones
  // that are selected (their position numbers). if no boxes were checked,
  // returned array will be empty (length will be zero)
  var retArr = new Array();
  var lastElement = 0;
  if (buttonGroup[0]) 
  { // if the button group is an array (one check box is not an array)
    for (var i=0; i<buttonGroup.length; i++) 
    {
     if (buttonGroup[i].checked) 
     {
        retArr.length = lastElement;
        retArr[lastElement] = i;
        lastElement++;
     }
    }
  } 
  else 
  { // There is only one check box (it's not an array)
    if (buttonGroup.checked) 
    { // if the one check box is checked
     retArr.length = lastElement;
     retArr[lastElement] = 0; // return zero as the only array value
    }
  }
  return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) 
{
  // return an array of values selected in the check box group. if no boxes
  // were checked, returned array will be empty (length will be zero)
  var retArr = new Array(); // set up empty array for the return values
  var selectedItems = getSelectedCheckbox(buttonGroup);
  if (selectedItems.length != 0) 
  { // if there was something selected
    retArr.length = selectedItems.length;
    for (var i=0; i<selectedItems.length; i++) 
    {
      if (buttonGroup[selectedItems[i]]) 
      { // Make sure it's an array
        retArr[i] = buttonGroup[selectedItems[i]].value;
      } 
      else 
      { // It's not an array (there's just one check box and it's selected)
        retArr[i] = buttonGroup.value;// return that value
      }
    }
  }
  return retArr;
} // Ends the "getSelectedCheckBoxValue" function

/* USEAGE FOR getSelectedCheckbox(buttonGroup)
var checkBoxArr = getSelectedCheckbox(document.forms[0].MyCheckBox);
if (checkBoxArr.length == 0)
  alert("No check boxes selected");
*/

//FUNCTION TO CHECK IF AN OBJECT EXISTS ON A PARENT PAGE OR IN A POPUP WINDOW
// IF YOU WOULD LIKE TO SEE IF AN OBJECT EXISTS WITHIN A DOCUMENT SET inParent TO false, IF IT IS A POP-UP WINDOW SET IT TO true
// theVal WILL BE THE NAME OF THE OBJECT
function chkObject(inParent,theVal) 
{
  if(inParent)
  {
    if (window.opener.document.getElementById(theVal) != null) 
      return true;
    else
      return false;
  }
  else
  {
    if (document.getElementById(theVal) != null)
      return true;
    else
      return false;
  }
} //end function chkObject()
