function insSqlAjax(FormName,aTableName,aModul){
	var FieldString = '';
	var ValueString = '';
   	for(var i=0;i<document.forms[FormName].elements.length;i++)
   	{
    	if (document.forms[FormName].elements[i].name.charAt(0)=='i' && document.forms[FormName].elements[i].name.charAt(1)=='_')
    		{
        	FieldString = FieldString + document.forms[FormName].elements[i].name.substring(2) + ',';
        	ValueString = ValueString + "'" + escape(document.forms[FormName].elements[i].value) + "',";
        	}
   	}
	xajax_insFormElements(FieldString,ValueString,aTableName,aModul);
}

function ClearOnClick(input) // set visible or hidden
{
	if (input.alt == 'get')
		{
		input.value = '';
		input.alt = 'set';
		}
	return true;
}


function VisHid(DivID) // set visible or hidden
{
	if ( document.getElementById(DivID).style.visibility=='visible' )
	{	document.getElementById(DivID).style.visibility='hidden';
		document.getElementById(DivID).style.position='absolute';}
	else
	{ document.getElementById(DivID).style.visibility='visible';
		document.getElementById(DivID).style.position='relative';}
	return true;
}

function csikicsuki(DivID)	// A bezarando div id-je
{	
	var Dstyle;
	var objs;
	if (document.all)
	{ objs = document.all.tags("DIV");}
	else if (document.getElementsByTagName)
	{ objs = document.getElementsByTagName("DIV");}
	else if (document.layers)
	{ objs = document.layers["DIV"];}
	else
	{ alert('Sorry, Your browser does not support this'); }
	
	for (var i=0; i<objs.length; i++) 
	{
	if (objs[i].id.substring(0,4) == 'tab_')
	objs[i].style.display = "none";
	}

	var _element = document.getElementById(DivID);
	if(!_element) { return true; }

	if (document.all)
		Dstyle=document.all[DivID].style;
			else
		Dstyle=document.getElementById(DivID).style; 

	if (Dstyle)	if(Dstyle.display == 'block')
		Dstyle.display='none';
			else
		{
		Dstyle.display='block';
		}
}

function DivHider(DivID)	// A bezarando div id-je
{
	document.getElementById(DivID).style.display='none';
	return true;
}

function DivShower(DivID)	// A bezarando div id-je
{
	document.getElementById(DivID).style.display='block';
	return true;
}

function hide_div(DivID)	// A bezarando div id-je
{	var Dstyle;
	var objs;
	if (document.all)
	{ objs = document.all.tags("DIV");}
	else if (document.getElementsByTagName)
	{ objs = document.getElementsByTagName("DIV");}
	else if (document.layers)
	{ objs = document.layers["DIV"];}
	else
	{ alert('Sorry, Your browser does not support this'); }
	
	if (document.all)
		Dstyle=document.all[DivID].style.display='none';
			else
		Dstyle=document.getElementById(DivID).style.display='none';
}

/* -------- */
function posttoparent(tmp_fn, tmp_in, tmp_value)
{
	window.opener.document.forms[tmp_fn].elements[tmp_in].value=tmp_value;
	window.close();
}

function allDelete(tblname,modul,aUrl)
{
	var ec = document.getElementsByName("chk_id").length;
	for (var i=0; i<ec;i++)
		{
			if ( document.getElementsByName("chk_id")[i].checked)
				{
						xajax_delCheckedItem(document.getElementsByName("chk_id")[i].id,tblname,modul);
				}
		}
	setTimeout('location.href=\''+aUrl+'\'',1500);
}

function SelectAllToDelete(mode)
{
	var ec = document.getElementsByName("chk_id").length;
	for (var i=0; i<ec;i++)
		{
		  	if (mode == 'select')
				document.getElementsByName("chk_id")[i].checked = true;
		  	if (mode == 'none')
				document.getElementsByName("chk_id")[i].checked = false;				
		}
}


/* menu - start */
navHover = function() {
	if (!document.getElementById("navmenu")) return false;
	var lis = document.getElementById("navmenu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++){
		lis[i].onmouseover=function(){this.className+=" iehover";}
		lis[i].onmouseout=function(){this.className=this.className.replace(new RegExp(" iehover\\b"),"");}}}
if (window.attachEvent) window.attachEvent("onload", navHover);
/* menu - end */

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var b64str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789+/=";
var b64str_m = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+"abcdefghijklmnopqrstuvwxyz"+"0123456789-_=";
// -lett a + helyett és _ a / helyett

function base64enc(inp,m)
{

 if (inp=="") return("");

 var b64ch=(m==1)?b64str:b64str_m;

 for (i=0;i<inp.length;i++)
 {
   //if (inp.charCodeAt(i)>255) alert("i:"+i+" code:"+inp.charCodeAt(i)+" ch:"+inp.charAt(i));
   if (inp.charCodeAt(i)>255) alert("i:"+i+" code:"+inp.charCodeAt(i)+" code:"+inp.charCodeAt(i+1));
   //alert(inp.charCodeAt(i)+inp.charAt(i));
 }

 if (typeof(btoa)=="function")
  {
    alap=btoa(inp);
    if (m!=1)
    {
     alap=alap.replace(/\x2B/g,"-");
     alap=alap.replace(/\x2F/g,"_");
    }
    return alap;
  }

    var out = ""; //This is the output
    var chr1, chr2, chr3 = ""; //These are the 3 bytes to be encoded
    var enc1, enc2, enc3, enc4 = ""; //These are the 4 encoded bytes
    var i = 0; //Position counter

    do
    { //Set up the loop here
        chr1 = inp.charCodeAt(i++); //Grab the first byte
        chr2 = inp.charCodeAt(i++); //Grab the second byte
        chr3 = inp.charCodeAt(i++); //Grab the third byte

        //Here is the actual base64 encode part.
        //There really is only one way to do it.
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;

        if (isNaN(chr2))
        {
          enc3 = enc4 = 64;
        }
         else if (isNaN(chr3))
         {
            enc4 = 64;
         }

        //Lets spit out the 4 encoded bytes
        out = out + b64ch.charAt(enc1) + b64ch.charAt(enc2) + b64ch.charAt(enc3) + b64ch.charAt(enc4);

        // OK, now clean out the variables used.
        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";

    } while (i < inp.length); //And finish off the loop

    //Now return the encoded values.
    return out;
}

function multicheckbox(element, pos, value)
{
var cbx_value = parseInt(document.getElementById(element).value);
if (value == true)
	cbx_value += Math.pow(2,pos);
	else
	cbx_value -= Math.pow(2,pos);
document.getElementById(element).value = cbx_value;
//alert(cbx_value);
}

function integer_separator(element)
{
var num = element.value.toString();
num = num.replace(/,/g,"");
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
document.getElementById(element.id).value = num;
num = num.replace(/,/g,"");
document.getElementById(element.id.replace(/_show+$/,"")).value = num;
}

function date_separator(element)
{
var num = element.value;
num = num.replace(/-/g,"");
if (num.length >= 6)
	{
	var year = num.substr(0,4);
	var month = num.substr(4,2);
	var day = num.substr(6,2);
	num = year + "-" + month + "-" + day;
	document.getElementById(element.id).value = num;
	return;
	}
if (num.length >= 4)
	{
	var year = num.substr(0,4);
	var month = num.substr(4,2);
	num = year + "-" + month;
	document.getElementById(element.id).value = num;
	return;
	}
}
