var tools = function(){

  this.myLocation = this.getLocation();
	this.jupload_archive = this.myLocation+ "jupload/skinlf.jar, " + this.myLocation + "jupload/jupload.jar";
	this.jupload_align = "center";
	this.jupload_width = "600";
	this.jupload_height = "400";
	this.jupload_progressbar = "true"
	this.jupload_boxmessage = "Loading JUpload Applet ...";
	this.jupload_skinThemePackURL = "themepack.zip";
	this.jupload_lookAndFeelClass = "com.l2fprod.gui.plaf.skin.SkinLookAndFeel";
	this.jupload_actionURL = this.myLocation + "JUpload.php";
	this.jupload_imageURL = this.myLocation + "jupload/JUpload.gif"
	this.jupload_addWindowTitle = "Upload files" 
	this.jupload_showThumbnails = "false";
	this.jupload_backgroundColor = "#FFFFFF";
	this.jupload_addToolTip = "Press to open file chooser to add files to upload queue";
	this.jupload_removeToolTip = "Select files in queue and click this button to remove them from queue";
	this.jupload_uploadToolTip = "Press to start uploading the files in the queue to the configured webserver";
	this.jupload_completeURL = "";
	this.jupload_askAuthentification = "false";
	this.jupload_mainSplitpaneLocation = "300";
	this.jupload_leftSplitpaneLocation = "200";
	this.jupload_removeBorders = "false";
	this.jupload_maxNumberFiles = "-1";
	this.jupload_maxNumberFilesWarning = "Maximum number of files reached.";
	this.jupload_maxNumberFilesTitle = "Filelimit reached";
	this.jupload_maxTotalRequestSize = "1000000";
	this.jupload_maxTotalRequestSizeWarning = "File too large for upload";
	this.jupload_maxTotalRequestSizeTitle = "File too large";

}

tools.prototype.getLocation = function()
{
	this.l = window.location.href
	this.ls = this.l.split("/");
	this.l = this.l.split(this.ls[this.ls.length-1]);
	return this.l[0];
}

tools.prototype.jupload =function(obj)
{
  this.oJupload = elm.element("applet",obj,"code='JUpload.startup'","CODEBASE=''","archive='"+this.jupload_archive+"'","align='"+this.jupload_align+"'","width='"+this.jupload_width+"'","height='"+this.jupload_height+"'","mayscript='mayscript'","name='JUpload'","alt='JUpload by www.jupload.biz'");
  this.param = elm.element("param",this.oJupload, "name='progressbar'","value='"+this.jupload_progressbar+"'");
  this.param = elm.element("param",this.oJupload, "name='boxmessage'","value='"+this.jupload_boxmessage+"'");
  this.param = elm.element("param",this.oJupload, "name='skinThemePackURL'","value='"+this.jupload_skinThemePackURL+"'");
  this.param = elm.element("param",this.oJupload, "name='lookAndFeelClass'","value='"+this.jupload_lookAndFeelClass+"'");

  this.param = elm.element("param",this.oJupload, "name='actionURL'","value='"+this.jupload_actionURL+"'");
  this.param = elm.element("param",this.oJupload, "name='imageURL'","value='"+this.jupload_imageURL+"'");
  
  this.param = elm.element("param",this.oJupload, "name='addWindowTitle'","value='"+this.jupload_addWindowTitle+"'");
  this.param = elm.element("param",this.oJupload, "name='showThumbnails'","value='"+this.jupload_showThumbnails+"'");
  this.param = elm.element("param",this.oJupload, "name='backgroundColor'","value='"+this.jupload_backgroundColor+"'");

  this.param = elm.element("param",this.oJupload, "name='addToolTip'","value='"+this.jupload_addToolTip+"'");
  this.param = elm.element("param",this.oJupload, "name='removeToolTip'","value='"+this.jupload_removeToolTip+"'");
  this.param = elm.element("param",this.oJupload, "name='uploadToolTip'","value='"+this.jupload_uploadToolTip+"'");

  this.param = elm.element("param",this.oJupload, "name='completeURL'","value='"+this.jupload_completeURL+"'");
  this.param = elm.element("param",this.oJupload, "name='askAuthentification'","value='"+this.jupload_askAuthentification+"'");
  
  this.param = elm.element("param",this.oJupload, "name='mainSplitpaneLocation'","value='"+this.jupload_mainSplitpaneLocation+"'");
  this.param = elm.element("param",this.oJupload, "name='leftSplitpaneLocation'","value='"+this.jupload_leftSplitpaneLocation+"'");
  this.param = elm.element("param",this.oJupload, "name='removeBorders'","value='"+this.jupload_removeBorders+"'");

  this.param = elm.element("param",this.oJupload, "name='maxNumberFiles'","value='"+this.jupload_maxNumberFiles+"'");
  this.param = elm.element("param",this.oJupload, "name='maxNumberFilesWarning'","value='"+this.jupload_maxNumberFilesWarning+"'");
  this.param = elm.element("param",this.oJupload, "name='maxNumberFilesTitle'","value='"+this.jupload_maxNumberFilesTitle+"'");

  this.param = elm.element("param",this.oJupload, "name='maxTotalRequestSize'","value='"+this.jupload_maxTotalRequestSize+"'");
  this.param = elm.element("param",this.oJupload, "name='maxTotalRequestSizeWarning'","value='"+this.jupload_maxTotalRequestSizeWarning+"'");
  this.param = elm.element("param",this.oJupload, "name='maxTotalRequestSizeTitle'","value='"+this.jupload_maxTotalRequestSizeTitle+"'");
}

var bottomCreator = function(){
	this.frm = new Array();
	this.borderBottomColor = new Array();
	this.borderType ="solid";
	this.borderWidth = 1;
//	this.bottomLeft = 0;
	this.bottomBackgroundColor = "#FFF"
}

bottomCreator.prototype.createBorder = function(obj,vWidth,vHeight,vTop,vLeft,vBorder)
{
  newFrame = elm.element("div",obj,"style='position: absolute; font-size: " + (vHeight-4) + "px; width: "+parseInt(vWidth)+"px; height:"+parseInt(vHeight)+"px; top: "+parseInt(vTop) + "px; left: " + parseInt(vLeft) + "px; border: " + vBorder +"'");
  return newFrame;
}

bottomCreator.prototype.makeFrames = function(obj,vText,vWidth,vHeight,vTop,vLeft)
{
	if (this.borderBottomColor.length==0) 
	{
		this.frm[0] = this.createBorder(obj,vWidth,vHeight,vTop,vLeft,"none;");
		return this.frm[0]; 
	}
	else 
	{
	  for (n=0; n<this.borderBottomColor.length; n++)
	  {
			vBorder = parseInt(this.borderWidth) + "px " + this.borderType + " " + this.borderBottomColor[n] +";";
			wTil = vWidth+(this.borderBottomColor.length - n)*2*parseInt(this.borderWidth);
			hTil = vHeight+(this.borderBottomColor.length - n)*2*parseInt(this.borderWidth);
			if (n==0) {
			  frObj = obj;
			  vtopFr = vTop+n*parseInt(this.borderWidth);
			  vLeftFr = vLeft+n*parseInt(this.borderWidth);
			}
		 	else {
				frObj = this.frm[n-1];
			  vtopFr	 = 0;
			  vLeftFr = 0;
			}
			this.frm[n] = this.createBorder(frObj,wTil,hTil,vtopFr,vLeftFr,vBorder);
		}
//		this.frm[this.borderBottomColor.length-1].style.height = hTil -1 + "px";
		return this.frm[this.borderBottomColor.length-1];
  }

}

bottomCreator.prototype.createBottom = function(obj,vText,vWidth,vHeight,vTop,vLeft,callObject,vType)
{
  if (vType) this.borderType=vType; else this.borderType="solid"
  if (this.borderType == "inset") Style = "outset"; else Style = "inset";
  if (this.borderType == "groove") Style = "ridge";
  if (this.borderType == "ridge") Style = "groove";
	myBottom = this.makeFrames(obj,vText,vWidth,vHeight,vTop,vLeft);
	if (typeof vText == "string") elm.textNode(vText,myBottom);
	else myBottom.appendChild(vText);
	if (this.borderBottomColor.length>0) bgC = this.borderBottomColor[this.borderBottomColor.length-1]; else bgC = "#FFFFFF";
	if (this.borderBottomColor.length>1) bgCOver = this.borderBottomColor[this.borderBottomColor.length-2]; else bgCOver = "#666666";
	if (this.borderBottomColor.length>3) bgCDown = this.borderBottomColor[this.borderBottomColor.length-3]; else bgCDown = "#AAAAAA";
	if (this.borderBottomColor.length>1) bC = this.borderBottomColor[1]; else bgC = "#000000";
	vBC1 = parseInt(this.borderWidth) + "px " + this.borderType + " " + bgC +";";
	vBC2 = parseInt(this.borderWidth) + "px " + Style + " " + bgC +";";
	myBottom.style.backgroundColor = bgC;
	if (bgC>"#800000") myBottom.style.color = "#000"; else myBottom.style.color ="#FFF";
	myBottom.style.fontSize = vHeight-2 +"px";
	myBottom.style.textAlign = "center";
	myBottom.style.cursor = "pointer";
//	myBottom.className = "bottomStyle";
	
 	elm.addEvent(myBottom,"mouseover",changeColor,myBottom,bgCOver,vBC2);
 	elm.addEvent(myBottom,"mouseout",changeColor,myBottom,bgC,vBC1);
	elm.addEvent(myBottom,"mousedown",changeColor,myBottom,bgCDown,vBC2);
	elm.addEvent(myBottom,"mouseup",changeColor,myBottom,bgC,vBC1);
  elm.addEvent(myBottom,"click",callObject);
	
	return this.frm[0];
}

function changeColor(obj,Color,Style)
{
	obj.style.backgroundColor = Color;
	if (Color>"#800000") obj.style.color = "#000"; else obj.style.color ="#FFF";
	obj.style.border = Style;
}

function hide(obj)
{
  obj.style.display ="none"
}

function show(obj) {
  obj.style.display ="block"
}

function hideElm(on)
{
  if (on)	this.style.display ="none"
	else this.style.display ="block"
}

Object.prototype.hide = hideElm;

function udregnArrayToSelect(obj,n1,n2)
{
  returnArray = new Array();
  returnArray[0] = new Array();
  returnArray[1] = new Array();
  
  for (n=0; n<obj.length; n++)
  {
		returnArray[0].push(obj[n][n1]);	  
		returnArray[1].push(obj[n][n2]);	  
	}
	return returnArray;
}

function vInt(iString) {
    return (("" + parseInt(iString)) == iString);
}

function odd(val)
{
  return (parseInt(val/2)!=(val/2));
}

function not(val)
{
  if (val) return false; else return true;
}

shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};

function prePrint()
{
	if (window.print) window.print();
	else if (VBS) printIt();
	else alert('This script does not work in your browser');
}

function getObjectById(id)
{
  var obj;
  if (document.getElementById)
  {
    obj = document.getElementById(id);
  }
  else if (document.layers)
  {
    obj = document.layers[id];
  }
  else
  {
    obj = document.all.item(id);
  }
  return obj;
}

function setCookie(name, value, days, path, domain, secure)
{
	 if (days)
	 {
		  var date = new Date();
		  date.setTime(date.getTime()+(days*24*60*60*1000));
	 }
	 else var date = "";

   document.cookie= name + "=" + escape(value) +
        ((date) ? "; expires=" + date.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


