// Set the base_url.
url = document.location.href;    
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

// function: do_ja [str]
// -------------------------------------------------------
// arguments: <url>      the url of the page to be loaded.
// -------------------------------------------------------
// summary:
// Create a new script element in the current document, 
// and appends it, setting its source to the argument 
// sepcified in url.
// -------------------------------------------------------

function do_ja (url) 
{
  // if url is not a full url (ie: just a filename), 
  // append the full base_url to the beginning.
  if (url.substring(0, 4) != 'http') 
  {
    url = base_url + url;
  }

  var jsel = document.createElement('SCRIPT');
  jsel.type = 'text/javascript';
  jsel.src = url;

  document.body.appendChild (jsel);
}


// function: fake_submit [str, str, str]
// -------------------------------------------------------
// arguments: <htmlform>  the id of the form to be parsed.
//            <page>      the page to be called - form
//                        elements and values will be
//                        passed to it through cookies.
//            <container> The div/span or otherwise
//                        container where output will be
//                        displayed.
// -------------------------------------------------------
// summary:
// Takes the the html form, iterates through all its 
// elements, and puts all it all into a fake "querystring"
// which is then set into a cookie, along with the
// container id.
// -------------------------------------------------------

function fake_submit( htmlform, page, container )
{  
	var form = document.getElementById( htmlform )
    var	elements = form.elements
    var querystring = "?"

    for (i=0; i < elements.length; i++)
	{
      var el_name  = elements[i].name
      var el_value = elements[i].value                 
      
	  // Quick fix to prevent & and = from being passed	  
      el_value = el_value.replace( /\&/g,'#AND#')
      el_value = el_value.replace( /\=/g,'#EQ#')
      
	  querystring += el_name + "=" + escape( el_value ) + "&"		
	}
    
	createCookie( 'tmp_qs', querystring, 1 )	
    createCookie( 'tmp_cont', container, 1 )	
	do_ja( page )
}

// Creates a cookie.
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}