/* returns information about object fields*/
function obj_info2( obj ) {

	var column = 0;
	obj_info = "";
	for ( fld in obj ) {
		//if ( obj[ fld ] != 0 ) 
			//continue;
		obj_info += "." + fld + "=" + ((typeof( obj[ fld ] )!='object')?obj[ fld ]:typeof( obj[ fld ] ));
		column ++;
		if ( column % 3 == 0 )
			obj_info += "\n";
		else
			obj_info += "    ";
				
		
	}
	return obj_info;
}
/* returns information about object fields*/
function obj_info ( obj ) {

	info = '';
	for ( fld in obj ) {
		info += "." + fld + "=" + obj [ fld ] + "\n";
	}
	return info;
}
/**/
function make_safe ( form ) {

	if ( form.elements [ 'login[safe]' ] . checked ) {
	
		form.elements [ 'login[passwd_hashed]' ] . value = hex_md5 ( hex_md5 ( form.elements [ 'login[passwd]' ] . value ) + form.elements [ 'login[key]' ] . value );
		form.elements [ 'login[passwd]' ] . value = '';
		return true;
	}
}
/*
	zamienia wartości w polach formularza @form	o identyfikatorach @field_id na wyniki funkcji hashującej MD5
*/
function hash_form ( form, salt, hash_it, hash_n_salt_it ) {

    var elts      = form.elements;
	
	if ( typeof ( elts ) == 'undefined' ) 
		return true;
		
    var elts_cnt  = ( typeof ( elts.length ) != 'undefined' )
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
		
			if ( elts[i].id == hash_it ) {
			
	            elts[i].value = hex_md5 ( elts[i].value );
			}
			if ( elts[i].id == hash_n_salt_it ) {
			
	            elts[i].value = hex_md5 ( hex_md5 ( elts[i].value ) + salt );
			}
			
        } // end for
    } else {
	
		if ( elts.id == hash_it ) {

            elts[i].value = hex_md5 ( elts[i].value );
		}
		if ( elts.id == hash_n_salt_it ) {

            elts[i].value = hex_md5 ( hex_md5 ( elts[i].value ) + salt );
		}
    } // end if... else
	return true;
}
/**
 * Zaznacza/odznacza wszystkie pola w danym formularzu o podanym id
 *
 * @param   string   nazwa formularza
 * @param   boolean  zaznaczyÄ‡ czy teĹĽ odznaczyÄ‡ elementy
 *
 * @return  boolean  false przy bĹ‚Ä™dzie inaczej true
 */
var check = true;
function setCheckboxes(the_form, field_id, do_check)
{
    check = do_check;
    var elts      = document.forms[the_form].elements;
	
	if ( typeof ( elts ) == 'undefined' ) 
		return false;
		
    var elts_cnt  = ( typeof ( elts.length ) != 'undefined' )
                  ? elts.length
                  : 0;

    if (elts_cnt) {
    	first = true;
        for (var i = 0; i < elts_cnt; i++) {
			if ( elts[i].id == field_id ) {
			   	if ( first && elts[i].checked )
    				check = false;
				first = false;
	            elts[i].checked = check;
			}
        } // end for
    } else {
		if ( elts.id == field_id ) {
		   	if ( elts.checked )
   				check = false;
	        elts.checked = check;
		}
    } // end if... else
	check = !check;
    return true;
}
var okno = null;
function open_window(url)
{
	od_lewej = ( screen.width  - 600  ) / 2;
	od_gory  = ( screen.height - 400  ) / 2;
	okno = window.open ( url, "", "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=400,left=" + od_lewej + ",top=" + od_gory ); 
	okno.focus();
	return false;
}

function open_window2( url, szerokosc, wysokosc ) {

	var okno = null;
	if ( typeof( szerokosc ) == 'undefined' ) {
		szerokosc = 640;
	}
	if ( typeof( wysokosc ) == 'undefined' ) {
		wysokosc = 400;
	}
	var od_lewej = ( screen.width  - szerokosc  ) / 2;
	var od_gory  = ( screen.height - wysokosc  ) / 2 - 20;
	okno = window.open ( url, "", "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width=" + szerokosc + ",height=" + wysokosc + ",left=" + od_lewej + ",top=" + od_gory ); 
	okno.focus();
	return okno;
}

function open_window3( url, szerokosc, wysokosc, args )
{
    function chkdef( val, defval )
    {
        if( typeof( val ) != 'undefined' )
        {
            return val;
        }
        return defval;
    }

	args = chkdef( args, {} )
    
	var okno = null;
	var offset = (navigator.userAgent.indexOf("Mac") != -1 || 
					navigator.userAgent.indexOf("Gecko") != -1 || 
					navigator.appName.indexOf("Netscape") != -1) ? 0 : 4;

	szerokosc = chkdef( szerokosc, 640 );
	wysokosc = chkdef( wysokosc, 400 );
    
	var od_lewej = ( screen.availWidth + offset - szerokosc  ) / 2;
	var od_gory  = ( screen.availHeight + offset - wysokosc  ) / 2;
	okno = window.open( url, "", "toolbar=" + chkdef( args.toolbar, "no" ) + 
                                    ",location=" + chkdef( args.location, "no" ) + 
                                    ",directories=" + chkdef( args.directories, "no" ) + 
                                    ",status=" + chkdef( args.status, "no" ) + 
                                    ",scrollbars="  + chkdef( args.scrollbars, "no" ) + 
                                    ",resizable=" + chkdef( args.resizable, "no" ) + 
                                    ",copyhistory=" + chkdef( args.resizable, "yes" ) + 
                                    ",width=" + szerokosc + 
                                    ",height=" + wysokosc + 
                                    ",left=" + od_lewej + 
                                    ",top=" + od_gory ); 
	okno.focus();
	return okno;
}	
function startList() 
{
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI"||node.nodeName=="li") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}

var g_html_editor_wnd = null;
function show_html_editor( ctrl_id, folder, rootPath ) {

	var ctrl = document.getElementById( ctrl_id );
	
	if( !g_html_editor_wnd || g_html_editor_wnd.closed )
	{
		g_html_editor_wnd = open_window3( /*'http://localhost/html_editor1/examples/core.html'*/'HTML_editor/editor.html'/*'DHTML/testButons.htm'*/,700, 400, { 'resizable' : 'yes'} );
		var params = {	'ctrl': ctrl,
						'fileFolders': folder,
						'pathToSiteRoot': rootPath,
						'html': document.getElementById(ctrl_id).value };
		g_html_editor_wnd.dialogArguments = params;
	}
	else
	{
		g_html_editor_wnd.focus();
	}
	/*var dlg = new Dialog( window.self );
	var params = {	'fileFolders': folder,
					'pathToSiteRoot': rootPath,
					'html': document.getElementById(ctrl_id).value }
	alert( ctrl_id + " " + folder + " " + rootPath );
	dlg.open( "HTML_editor/editor.html", 
				function( retVal ){ show_html_editor_ret( retVal, ctrl_id ) },
				params,
				{ 'dialogWidth': '641px', 'dialogHeight': '540px'  } )
	*/
	
}

function show_html_editor_ret( retVal, ctrl_id )
{
	/*if( retVal.ok )
	{
		document.all[ ctrl_id ].value = retVal.html;
	}*/
}