var state = Array ('on.gif','off.gif');
var on = /on.gif/i;
var off = /off.gif/i;

g = { /* global */
	o:function(e){ /* object */
		return document.getElementById(e);
	}
}

slideshow = {
	setItem:function(item){
		g.o("slideshow-slot").innerHTML = item;
	},
	getItem:function(){
		currentItem = g.o('spl').src;
		return currentItem;
	},
	findCurrentItem:function(myItems){
		var i,result,item;
		i = 0;
		result = 0;
		while (i < this.findItemTotal(myItems)){
			item = myItems[i];
			item = item.toLowerCase();
			currentItem = this.getItem().toLowerCase();
			if(item.match(currentItem)){
				result = i;
				break;
			}
			i++;
		}
		return result;
	},
	
	findItemTotal:function(myItems){
		var result;
		result = 0;
		result = myItems.length;
		return result;
	},

	nextPosition:function(position,total){
		var nextposition;
		nextposition = parseInt(position+1);
		total = parseInt(total-1);
		nextposition >= total  ? nextposition = total:0; 
		return nextposition;
	},
	previousPosition:function(position){
		var previousposition;
		previousposition = parseInt(position-1);
		previousposition < 0 ? previousposition = 0:0; 
		return previousposition;
	},
	
	next:function(myItems){
		this.setItem(myItems[this.nextPosition(this.findCurrentItem(myItems),this.findItemTotal(myItems))]);
	},
	
	previous:function(myItems){
		this.setItem(myItems[this.previousPosition(this.findCurrentItem(myItems))]);
	}
}

w = { /* window */
	o:function(u,n){
		var win = window.open(u,n,'width=300,height=400,scrollbars=yes',true);
		win.focus();
	},
	oc:function(u,n,p){ /* open custom -> size */
		var win = window.open(u,n,p+',scrollbars=yes',true);
		win.focus();
	},
	s:function(u,n,p){
		var win = window.open(u,n,p,true);
		win.focus();
	},
	t:function(e){
		return top.opener.g.o(e);
	},
	tv:function(e,v){
		this.t(e).value = v;
	},
	c:function(){
		self.close();// = window.parent.opener;
	},
	resize:function(u,n,x,y){
		var win = window.open(u,n,'width='+x+',height='+y+',scrollbars=yes,status=yes',true);
		win.focus();
	},
	f:function(){
		window.moveTo(0,0);
		window.resizeTo(window.screen.availWidth,window.screen.availHeight);
	}
}

s = { /* swap */
	sh:function(e){ /* show-hide */
		(e.style.display == "none") ? e.style.display = "inline" : e.style.display = "none";
	},
	sb:function(e){/* show-hide block element */
		(e.style.display == "none") ? e.style.display = "inline-block" : e.style.display = "none";
	},
	h:function (e) { /* hide */
		(e.style.display == "inline") ? e.style.display = "none" : 0;
	},
	s:function (e) { /* show */
		(e.style.display == "none") ? e.style.display = "inline" : 0;
	}
}

action = { /* commands to server scripts */
	copy:function(url){
		var concatLocation = location.pathname+url;
		newProjectId = prompt("Copy to Project #:","");
		if(newProjectId > 0){
			newLocation = concatLocation+','+newProjectId
			window.location = newLocation;
		}
	},
	discard:function(nom,url){
		var msg = confirm("Please press OK to delete page:\n"+nom);
		var concatLocation = location.pathname+url;
		if (msg){
			window.location = concatLocation;
		}
	},
	confirm:function(url){
		var msg = confirm("Please press OK to create invoice from selected budget.\nDates will be generated as Today");
		var concatLocation = location.pathname+url;
		if (msg){
			window.location = concatLocation;
		}
	},
	/*
		&confirm.
		change: @msg
	*/
	newinvoice:function(url){
		var msg = confirm("Please press OK to create new invoice from selected budget.\nDates will be generated as Today");
		var concatLocation = location.pathname+url;
		if (msg){
			window.location = concatLocation;
		}
	},
	/*
		&confirm.
		change: @msg
	*/
	lock:function(url){
		var msg = confirm("Please press OK to LOCK BUDGET COSTS.\nMissing dates will be generated as Today");
		var concatLocation = location.pathname+url;
		if (msg){
			window.location = concatLocation;
		}
	},
	/*
		&confirm.
		change: @msg
	*/
	unlock:function(url){
		var msg = confirm("Budget costs will be UNLOCKED but Previous LOCKING date remains untouched.");
		var concatLocation = location.pathname+url;
		if (msg){
			window.location = concatLocation;
		}
	}		
}

make = {
	copy:function(){
		projekt_id = prompt("Copy to Project #:","");
		if(projekt_id > 0) {
			window.open("?budget:copy,"+projekt_id+","+g.o('budget_id').value,"_self");
		}
	}
}
htmlinput = {
	/* Convert to Object */
	o:function(el){
		return document.getElementById(el);
	},
	e:function(el){
		return document[el];
	},
	setv:function(el){
		el = this.e(el);
		el.value = this.swap(el);
		return;
	},
	swap:function(el){
		tmp = this.e(el).src;
		tmp.match(on) != null ? this.e(el).src = tmp.replace(on,state[1]) : this.e(el).src = tmp.replace(off,state[0]);
	},
	/* html checkbox emulator */
	checkbox:function(el){
		this.swap(el);
	}
}

function m(s,t){
	var tmp = new Array();
	var x = 0;
	for (var i = 0; i < s.length; i++) {
		if (s.options[i].selected) {
			var intTargetLen = t.length++;
			t.options[intTargetLen].text = s.options[i].text;
			t.options[intTargetLen].value = s.options[i].value;
		}else {
			var objTempValues = new Object();
			objTempValues.text = s.options[i].text;
			objTempValues.value = s.options[i].value;
			tmp[x] = objTempValues;
			x++;
		}
	}
	s.length = tmp.length;
	for (var i = 0; i < tmp.length; i++) {
		s.options[i].text = tmp[i].text;
		s.options[i].value = tmp[i].value;
		s.options[i].selected = false;
	}
}

var Color= new Array();
Color[1] = "ff";
Color[2] = "ee";
Color[3] = "dd";
Color[4] = "cc";
Color[5] = "bb";
Color[6] = "aa";
Color[7] = "99";

function waittofade() {
  if (document.getElementById('fade')) {
    setTimeout("fadeIn(7)", 1000);
   }
}

function fadeIn(where) {
  if (where >= 1) {
      document.getElementById('fade').style.backgroundColor = "#ffff" + Color[where];
    if (where > 1) {
      where -= 1;
      setTimeout("fadeIn("+where+")", 200);
    } else {
      where -= 1;
      setTimeout("fadeIn("+where+")", 200);
      document.getElementById('fade').style.backgroundColor = "transparent";
      document.getElementById('fade').id = '';
    }
  }
}
