function head_onload() {
		if (!parent.tree) 
			return;
		if (typeof(parent.tree.document) == "unknown")
			return;
		
		if (parent.tree.document.readyState == "complete")
			head_update_location(parent.tree.location);
}

function head_update_location(loc) {
	var p = "/", path , s, args, opts, URL, i = 0, l ;
	loc = loc + "";
	URL = explodeUrl(loc);
	base = loc.split("?");
	if (URL == false) {
		//Try degrade nicely..
		document.forms[0].action = base[0];
		return;
	} 
	document.forms[0].action = URL.pathname;
	if (!(l = window.document.getElementById('l')))
		return;

	if (locbar = window.document.getElementById('locbar'))
		locbar.value = URL.pathname;
	
	// alert( URL.toSource());
	args = get_http_get_vars();
	// preserve frame-dist-arch to improve caching
	opts = "?dist=" + get_select_values(document.forms[0],'dist');
	opts += ";arch=" + get_select_values(document.forms[0],'arch');
	if (opts == "?")
		opts = "";
	path =URL.pathname.split('/');
	s = "<a href='#' onclick='head_toggle_buttonmode(true);return false'>";
	// prefered URL: /usr/share/icons/gnome/24x24/actions/gtk-edit.png
	s += "<img src='/icons/16x16/stock/generic/stock_edit.png' alt='Edit URL' title='Edit URL' border='0'/></a>\n";
	s += "<span id='locbuttons'><a href='/"+opts+"' onclick='head_goto(this.href);return false'>ROOT:/</a> ";
	for (i = 0 ; i < path.length ; i++) {
		if (path[i] != '' ) {
			p = p + path[i] + "/";
			s = s +"<a href='"+ p + opts +"' onclick='head_goto(this.href);return false'>"+path[i]+"<span class='HideIfCSS'>/</span></a> ";
		}
	}
	s += '</span>';
	l.innerHTML = s;

	head_toggle_buttonmode(false);
}

function head_toggle_buttonmode(toggle) {
	var l, locbar;

	if (! (l = window.document.getElementById('locbuttons')))
		return;

	if (! (locbar = window.document.getElementById('locbar')))
		return;

	if ((locbar.type == 'hidden' && toggle)
		|| (locbar.type != 'hidden' && !toggle) ) {
		l.style.display = 'none';
		locbar.disabled = false;
		locbar.type =  'text';
		locbar.display =  'inline';
		locbar.focus();
	} else {
		l.style.display = 'inline';
		locbar.disabled =  true;
		locbar.type =  'hidden';
		locbar.display =  'none';
	}
	
}

function head_locbar_keyup(that) {
	if (that.keyCode == 27)
		head_toggle_buttonmode();

}

function get_select_values(form, sel) {
	var s = "";
	if (form.elements[sel])
		s +=  form.elements[sel].value;
	
	if (form.elements[sel+'[]'] &&  form.elements[sel+'[]'].options) 
		for (var i = 0 ; i < form.elements[sel+'[]'].options.length ; i++) 
			if (form.elements[sel+'[]'].options[i].selected) { 
				if (s) 
					s += "," ;
				s += form.elements[sel+'[]'].options[i].value;
			}
	return s;
}

function head_goto(url){
	if (!document.forms[0])
		return;
	document.forms[0].action = url;
	document.forms[0].submit();
}

function head_updatelocation_arch_dist(frame,form) {
	var search, locbar;
	if (locbar = window.document.getElementById('locbar')) {
		if (locbar.type != 'hidden')
			form.action = locbar.value;
	}

	search = frame.location.search;
	if (search) {
	
		if (form.arch)
			search = search.replace( /arch=\w+/ , 'arch=' + form.arch.value);
		if (form.dist)
			search = search.replace( /dist=\w+/ , 'dist=' + form.dist.value);
		if (frame.location.search != search)
			frame.location.search = search;
	}
}

function explodeUrl(url) {
	var re=/^(ftp|https?):\/\/([^:\/\s]+)((\w[\w\.]+)*)(\/[^#?]*)(\?([^[#]*)|)(#(.*)|)$/ ;
	var m = re.exec(url);
	if(m){
		return {
			proto:m[1],
			host:m[2],
			pathname:m[5],
			query:m[7],
			hash:m[9]
		};
	} else 
		return(false);
}
/* Regression test..
a=explodeUrl("ft"+"p://HOST/PATH/?QUERY#Bye");	alert(a.toSource());
a=explodeUrl("ht"+"tps://HOST/PATH/?QUERY#Bye");	alert(a.toSource());
a=explodeUrl("ht"+"tp://HOST/PATH/?QUERY#Bye");	alert(a.toSource());
a=explodeUrl("ht"+"tp://HOST/PATH/#Bye");	alert(a.toSource());
a=explodeUrl("ht"+"tp://HOST/PATH/?QUERY");	alert(a.toSource());
a=explodeUrl("ht"+"tp://HOST/PATH/");	alert(a.toSource());
a=explodeUrl("ht"+"tp://HOST/PATH");	alert(a.toSource());
*/
function explodePathFile(filename){
	var m = filename.match(/(.*)\/([^\/\\]+)\.?(\w*)$/);
	return {
		path: m[1],
		file: m[2],
		ext: m[3]
	}
}

function get_http_get_vars() {
	return parse_args(window.location.search);
}
function parse_args(q) {
		var args, o, key;
		o = new Object();
		if (q.charAt(0)=='?')
			q = q.slice(1);
		
		if (q.indexOf("&"))
			args = q.split("&");
		else
			args = q.split(";");

		for (var i = 0 ; i < args.length ; i++) {
			key = args[i].split('=');
			o[key[0]]= ((key.length > 1) ? key[1] :"");
		}
	return(o);
}


function build_frameset(folder, file) {
	var args, opts, and1, and2, main, view;

	// antisurgeprotect: Mozilla seems to have a feature to prevent the
	// frameset page, from loading itself in on of it's frames !
	var antisurgeprotect;

	if (window.parent.frames.length == 0) {
		args = get_http_get_vars();
		opts = ''
		// preserve frame-dist-arch to improve caching
		if (args.dist || (args.dist === ""))
			opts = "dist=" + args.dist;
		if (args.arch || (args.arch === "")) {
			if (opts!='')
				opts += ";";
			opts +=  "arch=" + args.arch;
		}
		if (opts) {
			and1 = '?';
			and2 = ';';
			antisurgeprotect = ';';
		} else {
			and1 = '';
			and2 = '';
			antisurgeprotect = '?';
		}
		if (file) {
			main = folder + file + and1 + opts + (file ? antisurgeprotect :'');
		} else {
			main = "/about:welcome";
		}
		view = "/about:blank";

		document.writeln('\
<frameset rows="85,*">\n\
	<frame src="' +folder + '?f=h' + and2 +opts+ '" name="head" id="head" frameborder="0" marginwidth="0" marginheight="0" noresize="noresize"/>\n\
	<frameset cols="20%,80%">\n\
		<frame src="' +folder + and1 +opts+ (file?'':antisurgeprotect) + '" name="tree" id="tree" frameborder="1" marginwidth="5" marginheight="5"/>\n\
		<frameset rows="35%,65%" >\n\
			<frame src="' + main + '" name="main" id="main" frameborder="1" marginwidth="5" marginheight="5"/>\n\
			<frame src="' + view +'" name="details" id="details" frameborder="1" marginwidth="5" marginheight="5"/>\n\
		</frameset>\n\
	</frameset>\n\
	<noframes>\n\
	        <body>\n\
			<p>Your configuration isn t supported : (your browser doesn t support frames)</p>\n\
			<p>SysInf0 support browser with both frames and javasript, or none. </p>\n\
			<p>Please, report the problem and your configuration to the admin.</p>\
			<p><!--<a href="/about:welcome">continue</a>--></p>\n\
			<p><!--<a href="?f=t;' + opts + '">continue</a>--></p>\n\
		</body>\n\
	</noframes>\n\
</frameset>\n\
<noscript>\n\
');
	}
}
function build_frameset_close() {
	if (window.parent.frames.length == 0) {
		document.writeln('\n</noscript>');
	}
}


	function main_onload() {
		if (window.parent) { 
			window.parent.document.title = window.document.title;
			if (window.parent.details) {
				/* No errors.. but doesn't work FF-1.5 ;(
				var base = window.document.getElementById('base').target = 'details';
				*/
				if (match_count=="multiple") {
//					window.parent.details.document.body.innerHTML = "Multiple matches. select one above.";
					w = window.parent.details.document.open();
					if (w) {
						w.writeln("<html><body>Multiple matches. select one above.</body></html>");
						w.close();
					}

				} else if (match_count==0) {
					w = window.parent.details.document.open();
					if (w) {
						w.writeln("<html><body>&nbsp;</body></html>");
						w.close();
					}
				} else {
				
					//Err on konq: window.parent.details.document.location = "?f=view;pkg_id=" + match_count;
					window.parent.details.location = "?f=view;" + match_count;
				}
			}
				

		}

	}

	function tree_onload() {
		if (window.parent) 
			window.parent.document.title = window.document.title;
		if (window.parent.head) 
			if (window.parent.head.head_update_location) 
				window.parent.head.head_update_location(window.location);

		var l = window.document.getElementById('long_title');
		if (l && l.style)
			l.style.display = 'none';

		// Gecko doesn t have readyState
		if (typeof(document.readyState) == "undefined")
			document.readyState = "complete";
	}
	
	// Update the "target" window of a <link> or <form>
	function setTarget(that, frame){
		if (window.parent)
			// Check if the frame exist (except "_new" "_self" ...) 
			if ((window.parent.frames[frame]) || (frame.charAt(0) == '_') )
				if (that.nodeName == 'INPUT' && that.type == 'submit')
					that.form.target = frame;
				else
					that.target = frame;
	}

//if (...  document.readyState == "complete" || "loading" || "loaded" 


// vim: set js=javascript
