function show_loading()
	{

	dws =  find_document_size();

	limg = gid('loading_img');

	styleleft = (dws[0] - limg.width)/2;
	styletop = (dws[1] - limg.height)/2;

	limg.style.left=styleleft;
	limg.style.top=styletop;
	limg.style.display = '';

	gid('big_bg_div').style.width=dws[0];
	gid('big_bg_div').style.height = dws[1];
	gid('big_bg_div').style.display = '';
	}

function hide_loading()
	{
	gid('loading_img').style.display = 'none';
	gid('big_bg_div').style.display = 'none';
	}

function show_message(mtext)
	{

	dws =  find_document_size();

	styleleft = (dws[0] - 450)/2;
	styletop = (dws[1] - 250)/2;

	gid('message_td').innerHTML = mtext;

	gid('message_div').style.left=styleleft+'px';
	gid('message_div').style.top=styletop+'px';
	gid('message_div').style.display = '';



	gid('big_bg_div').style.width=dws[0];
	gid('big_bg_div').style.height = dws[1];
	gid('big_bg_div').style.display = '';
	//FOCUS BUTTON
	gid('OK_BUTTON').focus();
	}

function hide_message()
	{
	gid('message_div').style.display = 'none';
	gid('big_bg_div').style.display = 'none';
	}

function find_document_size()
	{
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }

	retval = new Array();
	retval[0] = myWidth;
	retval[1] = myHeight;

	return retval;
	}


function in_array(val,ar)
	{
	for(key in ar)
		{
		if(ar[key]==val)
			{
			return key;
			break;
			}
		}
	return false;
	}


function utf2cp(text)
	{
	conv = new Array();
	conv[1040] = 192; //À
	conv[1072] = 224; //à
	conv[1041] = 193; //Á
	conv[1073] = 225; //á
	conv[1042] = 194; //Â
	conv[1074] = 226; //â
	conv[1043] = 195; //Ã
	conv[1075] = 227; //ã
	conv[1044] = 196; //Ä
	conv[1076] = 228; //ä
	conv[1045] = 197; //Å
	conv[1077] = 229; //å
	conv[1046] = 198; //Æ
	conv[1078] = 230; //æ
	conv[1047] = 199; //Ç
	conv[1079] = 231; //ç
	conv[1048] = 200; //È
	conv[1080] = 232; //è
	conv[1049] = 201; //É
	conv[1081] = 233; //é
	conv[1050] = 202; //Ê
	conv[1082] = 234; //ê
	conv[1051] = 203; //Ë
	conv[1083] = 235; //ë
	conv[1052] = 204; //Ì
	conv[1084] = 236; //ì
	conv[1053] = 205; //Í
	conv[1085] = 237; //í
	conv[1054] = 206; //Î
	conv[1086] = 238; //î
	conv[1055] = 207; //Ï
	conv[1087] = 239; //ï
	conv[1056] = 208; //Ð
	conv[1088] = 240; //ð
	conv[1057] = 209; //Ñ
	conv[1089] = 241; //ñ
	conv[1058] = 210; //Ò
	conv[1090] = 242; //ò
	conv[1059] = 211; //Ó
	conv[1091] = 243; //ó
	conv[1060] = 212; //Ô
	conv[1092] = 244; //ô
	conv[1061] = 213; //Õ
	conv[1093] = 245; //õ
	conv[1062] = 214; //Ö
	conv[1094] = 246; //ö
	conv[1063] = 215; //×
	conv[1095] = 247; //÷
	conv[1064] = 216; //Ø
	conv[1065] = 217; //Ù
	conv[1068] = 220; //Ü
	conv[1100] = 252; //ü
	conv[1066] = 218; //Ú
	conv[1098] = 250; //ú
	conv[1070] = 222; //Þ
	conv[1102] = 254; //þ
	conv[1071] = 223; //ß
	conv[1103] = 255; //ÿ
	
	out_text = '';
	for(i=0;i<text.length;i++)
		{
		utfcode = text.charCodeAt(i);
		if(conv[utfcode])
			{
			out_text += String.fromCharCode(conv[utfcode]);
			}
		else{
			out_text += text.charAt(i);
			}
		}
	
	return out_text;
	}
	
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

	
function show_hide(id)
	{
	try{
		if(gid(id).style.display == 'none')
			{
			gid(id).style.display = '';
			}
		else{
			gid(id).style.display = 'none';
			}
		}
	catch(e){
		alert(e.message);
		}
	}

function get_selection(selection_obj_id)
{
	sel_obj = gid(selection_obj_id);
	sel_obj.focus();

	var $sel;
	if(document.selection)
		{
		$sel = document.selection.createRange().text;
		}
	else
		{
		$sel = sel_obj.value.substring(sel_obj.selectionStart,sel_obj.selectionEnd);
		}
	return ($sel);
}


function show_hide_tag(tag,id)
	{
	try{

		ids = document.getElementsByTagName(tag);
		for(key in ids)
			{
			if(ids[key].id == id)
				{
				if(ids[key].style.display == 'none')
					{
					ids[key].style.display = '';
					}
				else{
					ids[key].style.display = 'none';
					}

				}
			}


		}
	catch(e){
		alert(e.message);
		}
	}

function toFixed(num, round)
{
	num = parseFloat(num);

	if(num<0)
		{
		num = num*(-1);
		reverse = -1;
		}
	else{
		reverse = 1;
		}

	tempd = num*Math.pow(10,round);

	tempd1 = Math.round(tempd.toFixed(5));

	number = tempd1/Math.pow(10,round);

	number = reverse*number;

	return number.toFixed(round);
}

function nz(digit)
	{
	return parseFloat(toFixed(digit,10))
	}


function fix(obj)
	{
	if(obj.value.length>0)
		{
		obj.value = (parseFloat(obj.value)).toFixed(2);
		}
	else{
		obj.value = '0.00';
		}
	calc();
	}


function dbl(e)
	{
	if (document.all)
				{
				var key = e.keyCode;
				var ch = String.fromCharCode(key);
				var obj = e.srcElement;
				}
	else
				{
				var key = e.which;
				var ch = String.fromCharCode(key);
				var obj = e.target;
				}


	if(ch == '.' && obj.value.indexOf('.') !=-1 ) return false;
	if(ch.match(/[^0-9\.]{1}/) && key!=8 && key!=0 ) return false;



	}


function intonly(e)
	{
	if (document.all)
				{
				var key = e.keyCode;
				var ch = String.fromCharCode(key);
				var obj = e.srcElement;
				}
	else
				{
				var key = e.which;
				var ch = String.fromCharCode(key);
				var obj = e.target;
				}

	if(ch.match(/[^0-9]{1}/) && key!=8 && key!=0 ) return false;
	}



function fake_post(address_target,params)
	{

	var adrt = address_target.split('|');
	var url = adrt[0];
	var target = adrt[1];
	var method = adrt[2];

	//napravi nova forma
	var form = document.createElement( "form" );
	
	if(method)
		{
		form.method  = method;
		}
	else{
		form.method = 'POST';
		}
	

	form.action = url;

	if(target)
		{
		form.target  = target;
		}

	//Zapochi da nabivash vytre inputcheta

	//Nameri razdelitelq
	if(params.charAt(0) == '&')
		{
		var splt = '&'
		params = params.substr(1);
		}
	else{
		var splt = ',';
		}


	var params_array = params.split(splt);




	for (i=0;i<params_array.length;i++)
		{
		if(params_array[i].indexOf('=')==-1) continue;

		pma = params_array[i].split('=');
		name = pma[0];
		value = pma[1];

		//JS TRIM :)
		name = name.replace(/^[\s]+/,'');
		value = value.replace(/^[\s]+/,'');

		name = name.replace(/[\s]+$/,'');
		value = value.replace(/[\s]+$/,'');

		input_el = document.createElement( "input" );
		input_el.type = 'hidden';
		input_el.name = name;
		input_el.value = value;

		form.appendChild(input_el);

		}

	//skrii shibanata forma ot shibani FF
	form.style['display'] = 'none';

	//NAII FORMATA U DOKUMENTO
	document.body.appendChild(form);

	//ARE ZAMINAVAY
	form.submit();
	}


function mark(id)
	{
	if(gid('selected').value>0 && gid('row_'+gid('selected').value) )
		{
		gid('row_'+gid('selected').value).style.backgroundColor = '';
		gid('row_'+gid('selected').value).style.color = '';
		}

	gid('selected').value = id;
	gid('row_'+id).style.backgroundColor= '#316AC5';
	gid('row_'+id).style.color= 'white';

	return false;

	}






function gid(id_name)
	{
	if(document.getElementById(id_name))
		return document.getElementById(id_name);
	else{
		ddname=document.getElementsByName(id_name);
		return  ddname[0];
		}
		
	}
	



function trigger_f(e,trf)
	{
	if(e.keyCode == 13) //ENTER IS PRESSED
		{
		//alert ('ENter');
		eval(trf);
		}

	}


function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft: what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
	totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft: totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
}

return totaloffset;
}


function resize_parent(iframename)
	{
	last = document.getElementById('last_image');
	hgh = getposOffset(last, 'top');
	window.parent.document.getElementById(iframename).height = hgh+50;
	}

