var SERVER_URL = '';
var WFP_AGENT_PATH = '/kir0/plsql/';
// SUBMIT ------------------------------------------------------------------------------------------------
var submitted = false;
var msg = 'A művelet feldolgozása folyamatban van, kérjük legyen türelemmel.';

function submit_form (frm, url) {
	if (!submitted) {
		frm.action = url;
		frm.submit ();
		submitted = true;
	} else {
		alert (msg);
	}
}

function submit_form_parent (frm, url) {
	if (!submitted) {
		frm.action = url;
		frm.target = "_parent";
		frm.submit ();
		submitted = true;
	} else {
		alert (msg);
	}
}

function submit_form_self (frm, url) {
	if (!submitted) {
		frm.action = url;
		frm.target = "_self";
		frm.submit ();
		submitted = true;
	} else {
		alert (msg);
	}
}

function submit_form_target (frm, url, trg) {
	if (!submitted) {
		frm.action = url;
		frm.target = trg;
		frm.submit ();
		submitted = true;
	} else {
		alert (msg);
	}
}




function submit_form_nocheck (frm, url) {
	frm.action = url;
	frm.submit ();
}

function submit_form_parent_nocheck (frm, url) {
	frm.action = url;
	frm.target = "_parent";
frm.submit ();}
function submit_form_self_nocheck (frm, url) {
	frm.action = url;
	frm.target = "_self";
	frm.submit ();
}
function submit_form_target_nocheck (frm, url, trg) {
	frm.action = url;
	frm.target = trg;
	frm.submit ();
}
// LOV ----------------------------------------------------------------------------------------------------
function show_lov (p_lov_name, p_result_callback, p_width, p_height, p_execute, p_value1, p_value2, p_value3, p_value4) {
	url = SERVER_URL + WFP_AGENT_PATH + 'wfp_lov.show?p_lov_name='+ p_lov_name + '&p_result_callback='+ p_result_callback +	'&p_execute='+ p_execute;
	if (p_width != null)
		l_width = p_width;	
	else	l_width = 380;
	if (p_height != null)
		l_height = p_height;
	else	l_height = 500;
	if (p_value1 != null)
 		url += '&p_value1='+ p_value1;
	if (p_value2 != null)
		url += '&p_value2='+ p_value2;
	if (p_value3 != null) 
		url += '&p_value3='+ p_value3;
	if (p_value4 != null) 
		url += '&p_value3='+ p_value3;
	w = (800 - l_width < 100) ? (800 - l_width) : 100;
	if (w < 0) w = 5;
	h = (600 - l_height < 80) ? (600 - l_height) : 80;
	if (h < 0) h = 5;
	x = Math.round (w*Math.random ());
	y = Math.round (h*Math.random ());
	window.open (url, 'L'+p_lov_name, 'screenX='+ x +',screenY='+ y +',resizable,scrollbars,width='+ l_width +',height='+ l_height);
}
// EDIT -------------------------------------------------------------------------------------------------------
var iline;
function put_value () {
	return iline.value;
}
function get_value (new_value) {
	iline.value = new_value;
}
function edit (line) {
	iline = line;
	var w = window.open ('/wfp_home/edit.htm', 'editor', 'width=520,height=200');
	w.focus ();
}
// CALENDAR  -----------------------------------------------------------------------------------------------------
function show_calendar (p_variable, p_format_mask) {
	x = 50 + Math.round (100*Math.random ());
	y = 50 + Math.round (80*Math.random ());
	url = '/wfp_home/wfp_calendar.htm?p_variable=' + escape (p_variable);
	if (p_format_mask != null) 
		url += ('&p_format_mask=' + escape (p_format_mask));
		window.open (url, 'wcal', 'screenX='+ x +',screenY='+ y +',width=430,height=330,scrollbars,resizable');
}
// SHOW WINDOW ---------------------------------------------------------------------------------------------------
function show_window (p_url, p_name) {
	l_width = 785;
	l_height = 510;
	w = (screen.availWidth-20 - l_width < 0) ? 5 : (screen.availWidth-20 - l_width);
	h = (screen.availHeight-40 - l_height < 0) ? 5 : (screen.availHeight-40 - l_height);
	x = Math.round (w*Math.random ());
	y = Math.round (h*Math.random ());
	window.open (p_url, p_name, 'screenX='+ x +',screenY='+ y +',width='+ l_width +',height='+ l_height +',scrollbars,resizable');
}
// UNIQUE IN GROUP -----------------------------------------------------------------------------------------------
function unique_in_group (p_value, p_group) {
	for (i = 0; i < p_group.length; i++) {
		if (p_value == p_group[i].value) {
			return false;		
		}
	}	
	return true;
}
// PRELOADING IMAGES ---------------------------------------------------------------------------------------------
function image_utils () {
	this.images = new Array ();
	this.preload = preload;
	this.swap = swap;
}
function preload (p_image_src) {
	var ind = this.images.length;
	this.images[ind] = new Image;
	this.images[ind].src = p_image_src;
}
function swap (p_image_name, p_image_src) {
	document[p_image_name].src=p_image_src;
}
// COOKIES -------------------------------------------------------------------------------------------------------
// Cookie format :
// cookie_name=cookie_value; expires=expire_date; path=my_path; domain=my_domain; secure
function set_cookie(doc,cname,cvalue,cexpires,cpath,cdomain) {
	var ck;
	if (doc==null) doc=document;
	if (cname=='' || cvalue=='') return false;
	ck = cname+'='+escape(cvalue)+((cexpires=='')? '' : ' ;expires='+cexpires)+((cpath=='')? '' : ' ;path='+cpath)+((cdomain=='')? '' : ' ;domain='+cdomain) ;
	doc.cookie = ck;
	return true;
}
function old_get_cookie(doc,cname) {
	var i,j;
	var s=cname+'=';
	if (doc==null) doc=document;
	i = doc.cookie.indexOf(s);
	if (i>=0) j= doc.cookie.indexOf(';',i);
	else return null;
	if (j<0) j=doc.cookie.length;
	return doc.cookie.substring(i+s.length,j);
}
function get_cookie(doc,cname) {
	var i,j;
	var s=cname+'=';
	var q='EXPIRED';
	if (doc==null) doc=document;
	i = doc.cookie.indexOf(s);
	while (i>=0 && q=='EXPIRED') {		
		j= doc.cookie.indexOf(';',i);
		if (j<0) j=doc.cookie.length;
		q = doc.cookie.substring(i+s.length,j);
		i = doc.cookie.indexOf(s,j);
	}
	return (q=='EXPIRED')? null : q; 
}
function del_cookie(doc,cname,cpath) {
	if (doc==null) doc=document;
	var cvalue = get_cookie(doc,cname);
	if (cvalue != null) {
		var t = new Date();
		t.setTime(t.getTime() - 1);
		set_cookie(doc,cname,'EXPIRED',t,cpath,'');
	}
}
// WFP CHECKBOX - RADIO UTILS --------------------------------------------------------------------
function copy_checked (p_ind, p_clear_all) {
	with (document.forms[0]) {
		if (p_clear_all) {
			for (i = p_ind-1; i >= 0; i--)
				if (p_names[i].value != p_names[p_ind].value)
					break;
			l_first = i+1;
			for (i = p_ind+1; i < p_names.length; i++)
				if (p_names[i].value != p_names[p_ind].value)
					break;
					l_last = i-1;
			for (i = l_first; i <= l_last; i++)
				p_metamorfs[i].value = "0";
		}
		if (p_values[p_ind].checked)
			p_metamorfs[p_ind].value = "1";
		else	p_metamorfs[p_ind].value = "0";
	}
}
function sync_list_cbs (p_ind) {
	val = '';
	bounds = new Array (2);
	bounds = document.forms[0].p_metamorfs[p_ind].value.split(',');
	for (i = bounds[0]; i <= bounds[1]; i++)
		//alert (i + ':' + document.forms[0].p_discards[i].value);
		if ((document.forms[0].p_discards[i].checked) && (document.forms[0].p_discards[i].value != '')) {
			val += (val == '' ? document.forms[0].p_discards[i].value : ','+document.forms[0].p_discards[i].value)
		}
	document.forms[0].p_values[p_ind].value = val;
}
// NS atmeretezesi hiddenvesztes kezelese --------------------------------------------------------
// DEFINITION START: hidden_array
function hidden_array () {
	this.index = new Array ();
	this.value = new Array ();
	this.build = build;
	this.distribute = distribute;
}
function build (frm) {
	this.index.length = 0;
	this.value.length = 0;
	with (frm) {
		for (i = 0; i < elements.length; i++) {
			if (elements[i].type == "hidden") {
				ind = this.index.length;
				this.index[ind] = i;
				this.value[ind] = elements[i].value;
				//alert (elements[i].index + ': ' + elements[i].value);
			}
		}
	}
}
function distribute (frm) {
	with (frm) {
		for (i = 0; i < elements.length; i++) {
			if (elements[i].type == "hidden") {
				for (j = 0; j < this.index.length; j++) {
					if (this.index[j] == i) {
						elements[i].value = this.value[j];
						break;
					}
				}
			}
		}	
	}
}
// DEFINITION END: hidden_array
var ha = new hidden_array ();
function do_onresize (evnt) {
	if (document.forms.length != 0) ha.distribute (document.forms[0]);
	return routeEvent (evnt);
}
function do_onfocus (evnt) {
	if (document.forms.length != 0) ha.build (document.forms[0]);
	return routeEvent (evnt);
}
if (navigator.appName == "Netscape") {
	//document.captureEvents(Event.RESIZE | Event.FOCUS);
	window.captureEvents(Event.RESIZE | Event.FOCUS);
	window.onresize = do_onresize;
	window.onfocus = do_onfocus;
}

