function getNodeValue( node, tag )
{
  var ret_val = "";
  var req_node = node.getElementsByTagName(tag).item(0);
  
  if ( req_node )
    ret_val = req_node.text;
    
  return ret_val;
}

function clear_birthdate()
{
  document.getElementById('birth_month').selectedIndex  = 0;
  document.getElementById('birth_day').selectedIndex    = 0;
  document.getElementById('birth_year').selectedIndex   = 0;
}

function getPosition(args) 

{ 

  // Gets IE browser position 

  if (document.all) 

  { 

    X = event.clientX + document.body.scrollLeft 

    Y = event.clientY + document.body.scrollTop 

  } 

  // Gets position for other browsers 

  else 

  {  

    X = args.pageX 

    Y = args.pageY 

  }  

}



function lock_screen( obj, level )
{
  var lck_screen = obj.getElementById('scr_lock');
  if ( lck_screen )
  {
    var scr_width = screen.width;
    var scr_height   = screen.height;
    
    lck_screen.style.width  = scr_width;
    lck_screen.style.height = scr_height;
    
    switch (level)
    {
      case 1: lck_screen.className = "lock_screen_1"; break;
      case 2: lck_screen.className = "lock_screen_2"; break;
      case 3: lck_screen.className = "lock_screen_3"; break;
    }
    
    lck_screen.style.display = "block";
  }
}

function unlock_screen(obj)
{
  var lck_screen = obj.getElementById('scr_lock');
  if ( lck_screen )
  {
    lck_screen.style.width  = 0;
    lck_screen.style.height = 0;
    lck_screen.className = "";
    
    lck_screen.style.display = "none";
  }  
}


function getXMLHttpObject()
{
  //Check if we are using IE.
  try
  {
    //If the javascript version is greater than 5.
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } 
  catch (e) 
  {
    //If not, then use the older active x object.
    try 
    {
      //If we are using IE.
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    catch (E) 
    {
      //Else we must be using a non-IE browser.
      xmlhttp = false;
    }
  }
  
  //If we are using a non-IE browser, create a JavaScript instance of the object.
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
  {
    xmlhttp = new XMLHttpRequest();
  }
  
  return xmlhttp;
}

function getformvalues (fobj, valfunc)
{
  var str = "";
  aok = true;
  var val;
  
  //Run through a list of all objects contained within the form.
  for(var i = 0; i < fobj.elements.length; i++)
  {
    if(valfunc) 
    {
      if (aok == true)
      {
        val = valfunc (fobj.elements[i].value,fobj.elements[i].name);
        
        if (val == false)
        {
          aok = false;
        }
      }
    }
    
    str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
  }
  
  //Then return the string values.
  return str;
}

//Function to process an XMLHttpRequest.
function process_ajax (serverPage, obj, getOrPost, str)
{
  //Get an XMLHttpRequest object for use.
  xmlhttp = getXMLHttpObject();
  
  if (getOrPost == "get")
  {
    xmlhttp.open("GET", serverPage);
    xmlhttp.onreadystatechange = function() 
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
        {
          obj.innerHTML = xmlhttp.responseText;
        }
    }

    xmlhttp.send(str);
  } 
  else 
  {
    xmlhttp.open("POST", serverPage, true);
    xmlhttp.setRequestHeader( "Content-Type",
                              "application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.onreadystatechange = function() 
    {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
      {
        obj.innerHTML = xmlhttp.responseText;
      }
    }
    
    xmlhttp.send(str);
  }
}

function process_xml_request (serverPage, xml, str)
{
  //Get an XMLHttpRequest object for use.
  xmlhttp = getXMLHttpObject();
  
  xmlhttp.open("POST", serverPage, true);
  xmlhttp.setRequestHeader( "Content-Type",
                            "application/x-www-form-urlencoded; charset=UTF-8");
  xmlhttp.onreadystatechange = function() 
  {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
    {
      xml = xmlhttp.responseXML;
    }
  }
  
  xmlhttp.send(str);
}

function submitform (theform, serverPage, objID, valfunc)
{
  var file = serverPage;
  var str = getformvalues(theform,valfunc);
  
  //If the validation is ok.
  if (aok == true)
  {
    obj = document.getElementById(objID);
    process_ajax (serverPage, obj, "post", str);
  }
}

// add to post list and submit
function add_and_show( value )
{
  var p_list = document.getElementById('post_list');
  if ( p_list )
  {
    if ( p_list.value != "")
      p_list.value += ",";
      
    p_list.value += value;
  }
  
  var post_list_frm = document.getElementById('post_list_form');
  if ( post_list_frm )
    post_list_frm.submit();
}
  
function findPosX(obj)
{
  var curleft = 0;
  
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
  {
    curleft += obj.x;
  }
  
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  } 
  else if (obj.y)
  {
    curtop += obj.y;
  }
  
  return curtop;
}

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;
}

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;
    }
  }
}


