function kustutame(){
	return confirm('Kas kustutame?');
}

function change_kuup_a(sisse){
	ar=sisse.split(';');
	for(var i = 0;i<ar.length - 1;i++){
		osa = ar[i].split(':');
		change_kuup_b(osa[0],osa[1]);
	}
}

function change_kuup_b(vali,type){
	var paev = document.getElementsByName(vali+'Day');paev = paev[0];
	var kuu = document.getElementsByName(vali+'Month');kuu = kuu[0];
	var aasta = document.getElementsByName(vali+'Year');aasta = aasta[0];
	var tunnid = document.getElementsByName(vali+'Hour');tunnid = tunnid[0];
	var minutid = document.getElementsByName(vali+'Minute');minutid = minutid[0];


	var d = new Date();
	var p_paev = 0;
	var p_kuu = 0;
	var p_aasta = d.getYear();   
	
	if(p_aasta<1900){p_aasta += 1900;}
		
	type = parseInt(type);

	if(type == 1){//Tühista
		p_paev = 0;p_kuu = 0;p_aasta = 0; 
	}else if(type == 2){//Täna
		p_paev = d.getDate();
		p_kuu = d.getMonth();
	}else if(type == 3){//Hetk
		p_paev = d.getDate();
		p_kuu = d.getMonth() ;
		//kell ka paika
		tunnid.selectedIndex =d.getHours() ;
		minutid.selectedIndex = d.getMinutes();
	}else if(type == 4){//Selle nädala esmaspäev
		p_paev = d.getDate()-d.getDay()+1;
		p_kuu = d.getMonth() ;
	}else if(type == 5){//Järgmine esmaspäev
		p_paev = d.getDate()-d.getDay()+8;
		p_kuu = d.getMonth() ;
	}else if(type == 6){	//6 - pühapäev <option value="6">Selle nädala pühapäev</option>
		p_paev = d.getDate()-d.getDay()+7;
		p_kuu = d.getMonth();
	}else if(type == 7){//7 - järgmine pühapäev <option value="7">Järgmine pühapäev</option>
		p_paev = d.getDate()-d.getDay()+14;
		p_kuu = d.getMonth();
	}else if(type == 8){//8 - selle kuu esimene kp <option value="8">Selle kuu esimene päev</option>
		p_paev = 1;
		p_kuu = d.getMonth();
	}else if(type == 9){//9 - järgmise kuu esimene kp<option value="9">Järgmise kuu esimene päev</option>
		p_paev = 1;
		p_kuu = d.getMonth() + 1;
	}else if(type == 10){//10 - kuu viimane päev<option value="10">Selle kuu viimane päev</option>
		p_paev = 0;
		p_kuu = d.getMonth() + 1;
	}else if(type == 11){//11 - järgmise kuu viimane päev <option value="11">Järgmise kuu viimane päev</option>
		p_paev = 0;
		p_kuu = d.getMonth() + 2;
	}else if(type == 12){//12 - eelmine kuu esimene päev<option value="12">Eelmise kuu esimene päev</option>
		p_paev = 1;
		p_kuu = d.getMonth()-1;
	}else if(type == 13){//13 - eelmise kuu viimane päev<option value="13">Eelmise kuu viimane päev</option>
		p_paev = 0;
		p_kuu = d.getMonth();
	}else if(type == 14){//14 - eelmine esmaspäev<option value="14">Eelmine esmaspäev</option>
		p_paev = d.getDate()-d.getDay()-6;
		p_kuu = d.getMonth() ;
	}else if(type == 15){//15 -eelmine pühapäev<option value="15">Eelmine pühapäev</option>
		p_paev = d.getDate()-d.getDay();
		p_kuu = d.getMonth() ;
	}else if(type == 16){//16 - nädala pärast<option value="16">Nädala pärast</option>
		p_paev = d.getDate()+7;
		p_kuu = d.getMonth();
	}else if(type == 17){//17 - kahe nädala pärast<option value="17">Kahe nädala pärast</option>
		p_paev = d.getDate()+14;
		p_kuu = d.getMonth();
	}else if(type == 18){//18 - kuu pärast<option value="18">Kuu pärast</option>
		p_paev = d.getDate();
		p_kuu = d.getMonth() + 1;
	}else if(type == 19){//19 - 3 kuu pärast<option value="19">Kolme kuu pärast</option>
		p_paev = d.getDate();
		p_kuu = d.getMonth() +3;
	}else if(type == 20){//20 - 6 kuu pärast<option value="20">Kuue kuu pärast</option>
		p_paev = d.getDate();
		p_kuu = d.getMonth() +6;
	}else if(type == 21){//21 - 9 kuu pärast<option value="21">Üheksa kuu pärast</option>
		p_paev = d.getDate();
		p_kuu = d.getMonth() +9;
	}else if(type == 22){//22 - aasta pärast<option value="22">Aasta pärast</option>
		p_paev = d.getDate();
		p_kuu = d.getMonth();
		p_aasta ++;
	}
	if(p_aasta > 0){
		date = new Date();
		date.setFullYear(p_aasta,p_kuu,p_paev);
		p_paev = date.getDate();
		p_kuu = date.getMonth() + 1;
		p_aasta = date.getYear();
		if(p_aasta<1900){p_aasta += 1900;}		
		for(var i = 0; i < paev.length; i++){
			if(parseInt(paev.options[i].value) == p_paev){
				paev.selectedIndex = i;
			}
		}
		for(var i = 0; i < kuu.length; i++){
			//alert('"'+kuu.options[i].value+'"=>'+parseInt(kuu.options[i].value) )
			if(parseInt('1'+kuu.options[i].value)-100 == p_kuu){
				kuu.selectedIndex = i;
			}
		}		
		for(var i = 0; i < aasta.length; i++){
			if(parseInt(aasta.options[i].value) == p_aasta){
				aasta.selectedIndex = i;
			}
		}
	}else{
		paev.selectedIndex = 0;
		kuu.selectedIndex = 0;
		aasta.selectedIndex = 0;
	}
}


function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();


curRow = 0;

function setOver(row, id){
	var cells = row.cells;
	if(cells){
		for(var i = 0; i < cells.length; i++){
			cells[i].className = "light";
//			cells[i].style.backgroundColor = "#D8D8D8";
		}
	}
}

function setOut(row, id){
	if(curRow == id){
		return;
	}
	var cells = row.cells;
	if(cells){
		for(var i = 0; i < cells.length; i++){
			cells[i].className = "";
//			cells[i].style.backgroundColor = "white";
		}
	}
}

function setRow(row, id){
	if(curRow == id){
		setOut(row, id);
		curRow = 0;
	}
	else{
		setOver(row, id);
		curRow = id;
	}
}

function rowBgColor(row, color){
	var cells = row.cells;
	if(cells){
		for(var i = 0; i < cells.length; i++){
			cells[i].style.backgroundColor = color;
		}
	}
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

function showDiv(btn, msg, top){
	var x, y;

	if(!top){
		top = 0;
	}

	document.getElementById("cell").innerHTML = msg

	var elem = document.getElementById("popup");

	x = getPageOffsetLeft(btn)  - elem.offsetWidth;
	y = getPageOffsetTop(btn) - elem.offsetHeight - top;

	if(browser.isIE){
		x += btn.offsetParent.clientLeft;
		y += btn.offsetParent.clientTop;
	}
	
	elem.style.left = x + "px";
	elem.style.top  = y + "px";
	elem.style.visibility = "visible";
}

function hideDiv(){
	document.getElementById("popup").style.visibility="hidden";
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length;
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1){
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		}
	}
}

function hasValue(val, arr){
	for(var i = 0; i < arr.length; i++){
		if(arr[i] == val){
			return true;
		}
	}
	return false;
}

function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value)
		+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}


if(typeof Array.prototype.copy=='undefined')
Array.prototype.copy=function(a){
var
i=0,
b=[];
for(i;i<this.length;i++)
b[i]=(typeof this[i].copy!='undefined')?
this[i].copy():
this[i];
return b
};

function explode(delimiter, item) {
  tempArray=new Array(1);
  var Count=0;
  var tempString=new String(item);

  while (tempString.indexOf(delimiter)>0) {
    tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
    tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
    Count=Count+1
  }

  tempArray[Count]=tempString;
  return tempArray;
}


function selectItem(item, str){
	for(k = 0; k < item.options.length; k++){
		if(item.options[k].value == str){
			item.selectedIndex = k;
			break;
		}
	}
}


function containsValue(ar, elem){
	for(var i = 0; i < ar.length; i++){
		if(ar[i] == elem){
			return true;
		}
	}
	return false;
	
}

function removeValue(ar, elem){
	var ar2 = new Array();
	for(var i = 0; i < ar.length; i++){
		if(ar[i] != elem){
			ar2[ar2.length] = ar[i];
		}
	}
	return ar2;
	
}

