function OptSelect(id,title) {

	var HTMLSelect = window.opener.document.getElementById('partner_id');
	var Found = 0;
	var optionCounter;
	for (optionCounter = 0; optionCounter < HTMLSelect.length; optionCounter++) 
	{
	   if ( HTMLSelect.options[optionCounter].value == id ) {
//	   		alert('Found' + HTMLSelect.options[optionCounter].value);
		   	HTMLSelect.selectedIndex = optionCounter;
		   	Found = 1;
	   }
	}
	if ( Found == 0 ) {
		// Be kell szurnunk az optionboxba..
	    HTMLSelect.options[HTMLSelect.length] = new Option(title,id);
	    HTMLSelect.selectedIndex = HTMLSelect.length - 1;
	} 
	window.close();
	
}

function searchAndHide(input,target) {
	var text   = document.getElementById(input).value;
	var maxnum = document.getElementById('numrecords').innerHTML;
	var re 		= new RegExp(text.toLowerCase());
    debug = '';
    
	for ( i = 0 ; i < maxnum ; i ++ ) {
		
		id     = 'row_' + i + '_' + target;
		row_id = 'row_' + i;
		
		tdvalue    = document.getElementById(id).innerHTML;
		fieldvalue = tdvalue.toLowerCase();
		if ( fieldvalue.match(re) ) {
			   document.getElementById(row_id).style.display = '';
		 }else{
		   document.getElementById(row_id).style.display = 'none';
		 }
		debug = debug + ' ' + tdvalue;
	}
//	alert( debug );
}

function popUp(URL,Width,Height) {
        day = new Date();
        id = day.getTime();
        LeftPosition = (screen.width) ? (screen.width-Width)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-Height)/2 : 0;
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + Width + ",height=" + Height + ",left = "+ LeftPosition + ",top = "+ TopPosition +"');");
}


function calcNetto(f_brutto,f_netto) {
	var netto = document.getElementById( f_brutto ).value / 1.2;
    document.getElementById( f_netto ).value = roundNumber(netto);
} 

function roundNumber(number) {
	var newnumber = Math.round(number);
	return newnumber;
}

/*
 * String manipulation
 */

function Trim( p_string ) {
	if (typeof p_string != "string") { 
		return p_string; 
	}

	var t_string = p_string;
	var t_ch = '';

	// Trim beginning spaces

	t_ch = t_string.substring( 0, 1 );
	while ( t_ch == " " ) {
		t_string = t_string.substring( 1, t_string.length );
		t_ch = t_string.substring( 0, 1 );
	}

	// Trim trailing spaces

	t_ch = t_string.substring( t_string.length-1, t_string.length );
	while ( t_ch == " " ) {
		t_string = t_string.substring( 0, t_string.length-1 );
		t_ch = t_string.substring( t_string.length-1, t_string.length );
	}

	return t_string;
}


/*
 * Cookie functions
 */

function GetCookie( p_cookie ) {
	var t_cookie_name = "LOGSOL_" + p_cookie;
	var t_cookies = document.cookie;

	t_cookies = t_cookies.split( ";" );

	i = 0;
	while( i < t_cookies.length ) {
		var t_cookie = t_cookies[ i ];

		t_cookie = t_cookie.split( "=" );

		if ( Trim( t_cookie[ 0 ] ) == t_cookie_name ) {
			return( t_cookie[ 1 ] );
		}
		i++;
	}

	return -1;
}

function SetCookie( p_cookie, p_value ) {
	var t_cookie_name = "LOGSOL_" + p_cookie;
	var t_expires = new Date();

	t_expires.setTime( t_expires.getTime() + (365 * 24 * 60 * 60 * 1000));

   // document.cookie = t_cookie_name + "=" + p_value + "; expires=" + t_expires + ";";
    document.cookie = t_cookie_name + "=" + p_value +  ";";
}


/*
 * Collapsible element functions
 */

function SetDiv( p_div, p_cookie_bit ) {
	var t_view_settings = GetViewSettings();

	if( t_view_settings & p_cookie_bit ) {
		document.getElementById( p_div + "_open" ).style.display = "";
		document.getElementById( p_div + "_closed" ).style.display = "none";
	} else {
		document.getElementById( p_div + "_open" ).style.display = "none";
		document.getElementById( p_div + "_closed" ).style.display = "";
	}
}

function ToggleDiv( p_div, p_cookie_bit ) {
	var t_view_settings = GetViewSettings();

	t_view_settings ^= p_cookie_bit;
	SetCookie( "VIEW_SETTINGS", t_view_settings );

	SetDiv( p_div, p_cookie_bit );
}

function OwnToggle ( p_div ) {
	if (document.getElementById( p_div ).style.display == "none")
		{ OwnShow ( p_div ); } else { OwnHide ( p_div ); }
}

function OwnShow( p_div  ) {
	document.getElementById( p_div ).style.display="";
	SetCookie ( "viewstate_" + p_div, "show" );
}
function OwnHide( p_div  ) {
	document.getElementById( p_div ).style.display="none";
	SetCookie ( "viewstate_" + p_div, "hide" );
}

function OwnInitState( p_div ) {
	var t_cookie = GetCookie( "viewstate_" + p_div );

//	alert("hahoo");
	if ( t_cookie == 'show' ) {
		OwnShow( p_div );
	} else {
		OwnHide( p_div );
	}
	
}
function PenztarMaster ( MySel )
{
	if (MySel == 1) { OwnHide('szemely_panel'); OwnShow('partner_panel');  }
	if (MySel == 2) { OwnHide('szemely_panel'); OwnShow('partner_panel');  }
	if (MySel == 3) { OwnShow('szemely_panel'); OwnHide('partner_panel');  }
	if (MySel == 4) { OwnShow('szemely_panel'); OwnHide('partner_panel');  }
}


function BankMaster ( MySel )
{
	if (MySel == 0) { OwnHide('hozzarendeles'); OwnHide('kp_panel'); }
	if (MySel == 1) { OwnShow('hozzarendeles'); OwnHide('kp_panel'); }
	if (MySel == 2) { OwnShow('hozzarendeles'); OwnHide('kp_panel'); }
	if (MySel == 3) { OwnHide('hozzarendeles'); OwnShow('kp_panel'); OwnHide('bank_koltseg'); }
	if (MySel == 4) { OwnHide('hozzarendeles'); OwnShow('kp_panel'); OwnHide('bank_koltseg'); }
	if (MySel == 5) { OwnHide('hozzarendeles'); OwnShow('kp_panel'); OwnShow('bank_koltseg'); }
}
function ChooseBizonylat ( id ) {
	if (id == 1) { OwnShow('kp'); }
	if (id == 2) { OwnShow('atutalas'); }
}

function OwnToggleDiv( p_div ) {
	var t_view_settings = GetViewSettings();

	OwnSetDiv( p_div );
}

/* Check checkboxes */
function tooglecheck( p_name, p_state) {
	document.getElementById( p_name ).checked = p_state;
}


function checkall( p_formname, p_state) {
	var t_elements = (eval("document." + p_formname + ".elements"));
	
	for (var i = 0; i < t_elements.length; i++) { 
    	if(t_elements[i].type == 'checkbox') { 
      		t_elements[i].checked = p_state;
   		} 
  	}
}


