<!--

/**********

 PUSHBOX JAVASCRIPT ROUTINES

 Copyright (c) 2000,2001 Push(22) Productions and Jaume Sola.
 All Rights Reserved.

**********/

//********************* INITIALIZATIONS

// Timeout to allow clicked button graphics to show

ONCLICK_TIMEOUT = 300;


aux = null;
ul = null;
path = null;
imgs = new Array();
loaded_imgs = "none";
uploading = false;

function setpath(p) { path = p; }

//********************* IMAGE PRE-LOADING FUNCTIONS

function load_admin_imgs() {

  load_user_imgs();

  if ( loaded_imgs != "admin" ) {
    load_buttons( "adminprop","copy","delete","editnotes",
      "move","newfolder","rename","userprop");
    loaded_imgs = "admin";
  }
}

function load_user_imgs() {

  if ( loaded_imgs == "none" ) {
    load_images( "logo","title","folder","upfolder","file","vbar","spacer");
    load_buttons( "download","logout","notify","upload");
    loaded_imgs = "user";
  }
}


function load_images() { 

  if(document.images) {
    args=load_images.arguments;
    var j=imgs.length;
    for(var i=0; i<args.length; i++) { 
      imgs[j] = new Image();
      imgs[j++].src = "images/" + args[i] + ".gif";
    }
  }

}

// Same as load_images() but three images per argument : -over & -click

function load_buttons() { 

  if(document.images) {
    args=load_buttons.arguments;
    var j=imgs.length;
    for(var i=0; i<args.length; i++) { 
      imgs[j] = new Image();
      imgs[j++].src = "images/" + args[i] + ".gif";
      imgs[j] = new Image();
      imgs[j++].src = "images/" + args[i] + "-over.gif";
      imgs[j] = new Image();
      imgs[j++].src = "images/" + args[i] + "-click.gif";
    }
  }

}


//********************* POP-UP WINDOWS


//*** Open auxiliary window to ask data to perform operations

function submit_to_aux(func) {  

  close_ul();

  // Size of the pop-up window

  ww=400; wh=300;

  if ( func == "newfolder" ) { ww=400; wh=350 }
  if ( func == "userprop" )  { ww=400; wh=350 }
  if ( func == "adminprop" ) { ww=400; wh=350 }
  if ( func == "upload" )    { ww=400; wh=300 }
  if ( func == "editnotes" ) { ww=400; wh=270 }
  if ( func == "rename" )    { ww=400; wh=220 }
  if ( func == "notify" )    { ww=400; wh=350 }

  aux=window.open('empty.html','aux','width='+ww+',height='+wh+',scrollbars=no,resizable=yes');

  main.document.form1.target = "aux";
  main.document.form1.submit();
}

//*** Initial error or warning message pop-up

function msg_popup(msg) {

// Show message in the aux pop-up, usually referred to the previous operation
// The message content (msg var) is assigned at dinamically in main.html

aux=window.open('','aux','width=400,height=200,scrollbars=no,resizable=yes');

aux.document.write('\
<html><head><title>Message</title></head>\n\
<body bgcolor="#FFFFFF">\n\
<table width="100%" valign="top">\n\
<tr bgcolor=#DADADA><td align="center"><b><font size=5>Message</font></b></td></tr>\n\
<tr><td align="center"><font size=4>\n'
+ msg +
'\n</font><form name=form1><input type=button name="close" value="Close" onClick="window.close();">\n\
</form></td></tr></table>\n</body>\n</html>\n');

/***
aux.document.write('\
<html><head><title>Message</title></head>\
<body> <font size=5>Message</font><font size=4>'
+ msg +
'</font><form name=form1><input type=button name="close" value="Close" onClick="window.close();">\
</form></body></html>');
***/

}

//*** Open "uploading" warning window

function begin_upload() {

  uploading = true;
  aux.document.form1.submit();
  ul=window.open('uploading.html','ul','width=300,height=300,scrollbars=no,resizable=yes');
}


//*** When uploading the upload window, cancel upload two seconds later
// Note that cancel_upload() will do nothing if the cause of the unload event
// is the finish of the upload.

function unload_upload() { setTimeout("cancel_upload();", 2000 ); }

//*** Actions when upload finishes (onload event in uploaded.html)

function finish_upload() {

 uploading = false;
 close_ul();
 setTimeout("aux.document.form1.submit();",1000);
}


//*** Cancel upload process (upload window button)
// Uses the uploading flag to avoid executing this function again
// when it isn't necessary

function cancel_upload() { if (uploading) close_popups(); }

//*** Close upload window

function close_ul() { if (ul) if (!ul.closed) ul.close(); }

//*** Close upload and/or auxiliary windows
// (closing aux window eventually cancels upload in progress)

function close_popups() {  

  close_ul();
  if (aux) if (!aux.closed) aux.close();

  if ( uploading ) {
    uploading = false;
    alert("WARNING: Upload in progress has been cancelled");
  }
}

//****************** ROLLOVER EFFECTS

function moover(func) {
  func = func.toLowerCase();
  main.document.images[func].src="images/" + func + "-over.gif";
}

function moout(func) {
  func = func.toLowerCase();
  main.document.images[func].src="images/" + func + ".gif";
}

function userpover(id) { 
  //main.document.form1.elements[id].src='images/userprop-over.gif';
  //sentence = "main.document.form1." + id + ".src='images/userprop-over.gif';";
  //eval(sentence);
  main.document.images[id].src="images/userprop-over.gif";
}

function userpout(id) { 
  //main.document.form1.elements[id].src='images/userprop.gif';
  //sentence = "main.document.form1." + id + ".src='images/userprop.gif';";
  //eval(sentence);
  main.document.images[id].src="images/userprop.gif";
}

//******************** ONCLICK ACTIONS AND EFFECTS

function moclick(func) { 

  cancel_upload();

  // Special cases of direct action 

  if ( func == "Logout" ) {
    main.document.form1.logout.src='images/logout-click.gif';
    main.document.form1.button.name = "Logout";
    main.document.form1.target = "main";
    setTimeout("main.document.form1.submit()",ONCLICK_TIMEOUT);
    return;
    }

 if ( func == "Download" ) {
    main.document.form1.download.src='images/download-click.gif';
    main.document.form1.button.name = "Download";
    main.document.form1.target = "main";
    setTimeout("main.document.form1.submit()",ONCLICK_TIMEOUT);
    return;
    }

  // General case new page in aux window

  main.document.form1.button.name = func + "Page";
  func = func.toLowerCase();
  //main.document.form1.elements[func].src='images/' + func + '-click.gif';
  //sentence = "main.document.form1." + func + ".src='images/" + func + "-click.gif';";
  //eval(sentence);
  main.document.images[func].src="images/" + func + "-click.gif";
  setTimeout("submit_to_aux('"+func+"')",ONCLICK_TIMEOUT);

}

function userpclick(id1,id2) { 

  cancel_upload();
  //main.document.form1.elements[id].src='images/userprop-click.gif';
  //sentence = "main.document.form1." + id1 + ".src='images/userprop-click.gif';";
  //eval(sentence);
  main.document.images[id1].src="images/userprop-click.gif";
  main.document.form1.button.name = "UserPropPage";
  main.document.form1.button.value = id2;
  setTimeout("submit_to_aux('userprop');",ONCLICK_TIMEOUT);
}

//-->
