function SwitchPage(cur,obj){
  if(obj.length > 0){
    var el = document.getElementById(obj);
    if(el.style.display != "block"){
      el.style.display = "block";
    }else{
      el.style.display = "none";
    }
  }

  var ar = document.getElementById("masterdiv").getElementsByTagName("span");
  for (var i=0; i<ar.length; i++){
    if (ar[i].id != obj)
      ar[i].style.display = "none";
  }
}

function writeCookie(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=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

var thisurl = (location.href.split('?').length > 1?
      location.href.split('?')[0] : location.href);

function loaddataset(){
  writeCookie('workfile',document.forms["inputscript"].dname.value,0);
  writeCookie('isdata','true',0);
  window.open(thisurl,'_self');
}

function cleardataset(){
  writeCookie('workfile','',-1);
  writeCookie('isdata','false',0);
  window.open(thisurl,'_self');
}

function BarAtWork(appletname, appletparam){
  var workfile = readCookie('workfile');
  document.write('<APPLET code=rclientJava/dataTable.class');
  document.write(' name=' + appletname + ' ' + appletparam + '>');
  if(workfile && readCookie('isdata') == 'true'){
    document.write('<PARAM NAME=FILE VALUE='+workfile+'>');
  }
  document.write('</APPLET>');
}

function BarAtData(filename, appletparam){
  var thispath = (thisurl.indexOf("index") > 0?
        thisurl.substring(0,thisurl.indexOf("index"))
        : thisurl.substring(0,thisurl.indexOf("page")));
  var workfile = thispath + filename;
  writeCookie('workfile', workfile, 0);
  if(! readCookie('isdata')){
    writeCookie('isdata','true',0);
  }
  document.write('<APPLET code=rclientJava/dataTable.class');
  document.write(' name=' + filename + ' ' + appletparam + '>');
  if(readCookie('isdata') == 'true'){
    document.write('<PARAM NAME=FILE VALUE='+workfile+'>');
  }
  document.write('</APPLET>');
}

function BarAtTop(){
  document.write('<FORM ID=inputscript>');
  document.write('<input type=text value="" name=dname size=16>');
  if(readCookie('isdata') == 'true'){
    document.write('&nbsp<input type=button value=" Clear " onclick=cleardataset()>');
  }else{
    document.write('&nbsp<input type=button value=" Load " onclick=loaddataset()>');
  }
  var workfile = readCookie('workfile');
  if(workfile){
    document.forms["inputscript"].dname.value = workfile;
  }
  document.write('</FORM>');
}
