/**********************************************
* A cookiek kliens oldali kezelésének rutinjai
**********************************************/
var tabcookie = 1;
//Megnyit egy popup ablakot
function wopen(lnk,target,w,h){
		pars = "status=0,scrollbars=1,resizable=0,menubar=0,width=" + w + ",height=" + h;
		w = window.open(lnk,target,pars);
	    w.moveTo(10,10);
	    w.focus();
}    

//Alt+szám karakterrel módosul a TAB menu.
var alt   = false;

function KeyEventHandler(){
	if(document.all) {//ie
		document.onkeydown=KeyDown;
	}else{
		window.onkeydown=KeyDown;
	}
}

function KeyDown(e){
	if(document.all){	//ie
		e    = window.event;
		key  = e.keyCode;
	}else{
		key  = e.which;
	}
	alt  = (e.altKey) ? true : false;   
	if (alt) {
		if(key > 48 && key <59){
   			target = "atab" + (key-48);
			window.location.hash = target;
	    }else if(key >96 && key <107){
   			target = "atab" + (key-96);
			window.location.hash = target;
	 	}else{
	 		target = key;
	 	}
	}
	alt = false;
	return true;
}

/*
//Egy targetet ujratölt
function ujratolt(target){
	target.reload();
}
*/

//TAB set cookie
function settabcookie(tab){
	var today   = new Date();
	var oneyear = today.getTime() + 1000*60*60*24*365; 
	var expire = new Date(oneyear);
	setCookie("tab",tab,expire);
	return true;
}
//Visszakapja a TAB cookie-t
function gettabcookie(){
	var tab=getCookie("tab");
	if (window.location.hash != tab) window.location.hash = tab;
	return false;
}
function gettabcookiejava(){
	return getCookie("tab");
}

//A JAVA ezen keresztül állítja be a col_view cookie-kat.
/*
function setviewcookie(ertek){
	var today   = new Date();
	var oneyear = today.getTime() + 1000*60*60*24*365; 
	var expire  = new Date(oneyear);
	setCookie("cv" , ertek, expire);
}*/
//A JAVA így menti le az utoljára beállított ID-t.
function setidcookie(ID){
	var today   = new Date();
	var oneyear = today.getTime() + 1000*60*60*24*365; 
	var expire = new Date(oneyear);
	setCookie("ID",ID,expire);	
}

//Itt állítom be a treeview opciót
function settreeviewcookie(tree){
	var today   = new Date();
	var oneyear = today.getTime() + 1000*60*60*24*365; 
	var expire = new Date(oneyear);
	setCookie("treeview",tree,expire);
}

function setsortedcookie(sorted){
	var today   = new Date();
	var oneyear = today.getTime() + 1000*60*60*24*365; 
	var expire = new Date(oneyear);
	setCookie("ORDERBY",sorted,expire);
}
function gettreeviewcookie(){ 
	return getCookie("treeview");
}
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
//<a href="#" onclick='setCookie("name", "Jason Davies")'>Set Cookie!</a>

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
//getCookie("name")

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 SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
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";
    }
}
/**
* Módosítja egy elem stílusparamétereit paramétereit
* 
*
*/
function ChangeStyleOnFocus( o ){
	if(o!=undefined){
		o.style.backgroundColor = "#DFD9B3";
		o.style.borderColor     = "#e4e4e4"
	}
}

function ChangeStyleOnBlur( o ){
	if(o!=undefined){
		o.style.backgroundColor = "#FFFFFF";
		o.style.borderColor     = "#e6e6e6"
	}
}

function ChangeCalendarPickerStyleOnFocus( datum ){
	var o = document.getElementById( "inp_" + datum);
	ChangeStyleOnFocus( o )
	var cal = document.getElementById("img_" + datum);
	cal.style.borderColor   = "#DFD9B3";
	cal.style.borderWidth   = "1px";
	cal.style.width         = "14px";
	cal.style.height        = "14px";
	cal.style.borderStyle   = "ridge";
}

function ChangeCalendarPickerStyleOnBlur( datum ){
	var o = document.getElementById( "inp_" + datum);
	ChangeStyleOnBlur( o )
	var cal = document.getElementById( "img_" + datum);
	cal.style.borderColor     = "#e6e6e6";
	cal.style.borderWidth     = "0px";
	cal.style.width         = "16px";
	cal.style.height        = "16px";
	cal.style.borderStyle   = "none";
}

//-------- Parentlistkezelés függvényei -----------------
var evtype = "";
var evkeyCode = 0;
var index =0;

//Onchange eseményre lefutó függvények
function ParentListChange(e){
	var fromsel = $("ParentList");
	var tosel   = $("ChildList");
	var etype  = e.type;
	var button = e.button;
	var masol = modifychildlist();
	if ( masol) {
		PListChange(e,fromsel,tosel);
	}else{
		//jump = jumptorekord();		
		//if(jump){
		//	index = fromsel.selectedIndex;
		//	parent.ListGrid.GotoRowID(fromsel.options[index].value);
		//}
	}
	n = tosel.options.length;
//	tosel.size   = ( n < 14 ? n : 14);
	m = fromsel.options.length;
	//fromsel.size = ( m < 14 ? m : 14);
	$("Parentdb").innerHTML = " " + n ;
}

function ChildListChange(e){
	var fromsel = $("ChildList");
	var tosel   = $("ParentList");
	var etype  = e.type;
	var button = e.button;
	var masol = modifychildlist();
	if ( masol) {
		PListChange(e,fromsel,tosel);
	}else{
		//jump = jumptorekord();		
		//if(jump){
		//	index = fromsel.options.selected;
		//	parent.ListGrid.GotoRowID(fromsel.options[index].value);
		//}
	}
	n = tosel.options.length;
	//tosel.size   = ( n < 14 ? n : 14);
	m = fromsel.options.length;
	//fromsel.size = ( m < 14 ? m : 14);
	$("Parentdb").innerHTML = " " + m ;
}

function PListChange(e, fromsel,tosel){	//Ha kattintottam a tételre
	var frommax = fromsel.options.length; 
	var tomax   = tosel.options.length; 
    var t = new Array();
   
	index = (fromsel.selectedIndex>=0) ? fromsel.selectedIndex : 0;
	if (index>=0){
		var len = tosel.options.length;
		var val = fromsel.options[index].value;
		var text= fromsel.options[index].text;
		tosel.options[len] = new Option(text, val);
		fromsel.options[index] = null;
		for(i = 0; i< len;i++){
			t.push(new Array (tosel.options[i].text, tosel.options[i].value))		
		}
		t.sort(MYIDSort)
		for(i = 0; i< len;i++){
			tosel.options[i].text  = t[i][0];
			tosel.options[i].value = t[i][1];
		}
	}
	evtype = "";
}

function MYIDSort(a,b){
	if( a[0]< b[0]) return -1;
	else 
		if (a[0] > b[0]) return 1;
		else return 0;
}

function PListOnSubmit(){
	var sel = $("ChildList");
	var max = sel.options.length; 
	for(var i=0; i<max ;i++){
		sel.options[i].selected = true;
	}
	return true;
}

//Paraméterezhető filter függvénye
function SetFilter(flt,day){
	month = day*30;
	//Megjelenítem a popup ablakot overlibbel
	var url = 'dbserver.php';
	var pars = 'cmd=FUNC:SetFilter:' + flt+"|" + month;
	var myAjax = new Ajax.Updater( 'FilterDiv', url, { method: 'get', parameters: pars, evalScripts: true });
}
//ProgressBar
var pbmin;
var pbmax;
var pb1,pb2,pb3,ifr;

function Progress(text, mi, ma){
	pbmin = mi;
	pbmax = ma
	pb1 = $("Progress");
	pb2 = $("Progress2");
	pb3 = $("ProgressEmpty");
	pb4 = $("ProgressText");
	ifr = $("OverApplet");
	
	pb1.innerHTML="0%";
	pb2.style.width="0px";
	pb3.style.display    = "block";
	pb4.innerHTML=text;
	
    ifr.style.width   = pb3.offsetWidth;
    ifr.style.height  = pb3.offsetHeight;
    ifr.style.top     = pb3.style.top;
    ifr.style.left    = pb3.style.left;
    ifr.style.display = "block";    
}
function ProgressValue(i){
	percent = parseInt(i*100/pbmax);
	value = 2*percent;
	pb1.innerHTML=percent+"%";
	pb2.style.width=value+"px";
}
function ProgressHide(){
    pb1.innerHTML     ="";
    pb2.style.width   ="0px";
    ifr.style.display = "none";
    pb3.style.display = "none";
    pb4.innerHTML     ="";
}

//------------------- Calibrálási intervallum szabad beírásának rutinja ---------
//Betölti a selectboxba a kiválasztott dátumot
function CalIntMonth(monthname){
	var CalibMonth = $F("id_edit_form_CalIntMonth");
	var month = parseInt(CalibMonth);
	var days   = month * 30;
	var sel = $("id_edit_form_CalInt");
	var n = sel.length;
	sel.options[n-1].text  = CalibMonth + " " + monthname;
	sel.options[n-1].value = days;
	sel.options[n-1].selected	= true;
}

//---------------- Visible eff /Novisible - Edit.php oldalon használjuk --------------------
function visibleie(t){
	for(i = 1;i < 7 ;i++){
		var x= $("datab" + i);
		x.style.visibility='hidden';
		x.style.zIndex=0;
	}	
	location.href = "edit.php#" + t;
	var y = $("d" + t);
	y.style.visibility = 'visible';
	y.style.zIndex=7;
	settabcookie(t);
}

function visibleff(t){
	for(i = 1;i < 7 ;i++){
		var x= $("datab" + i);
		x.style.visibility='hidden';
		x.style.zIndex=0;
	}
	location.href = "edit.php#" + t;
	var y = $("d" + t);
	y.style.visibility = 'visible';
	y.style.zIndex=7;
	settabcookie(t);
}

function tabbkpon(x){
	x.style.background ="#D4D0C8";
}

function tabbkpoff(x){
	x.style.background ="#CFE5ED";
}//-------------- IF Frissítés bug --------------
function update_content(){
	var v=document.getElementsByClassName("fuckapplet");  
	for(i=0;i<v.length;i++){
		var el=v[i];
		var nel=document.createElement("span");	// create new span element to hold content
		nel.innerHTML=el.innerHTML;				// fill the newly inserted span with the active content
		el.parentNode.replaceChild(nel,el); 	// and replace the <noscript> element with the <span> element
	}
}
