/*
* Base class for all inheritance framework
* Inherits from -nothing-
* Requre -no- file
* d.rybakov
*/

function Klasse() { };

Klasse.prototype.construct = function() { };

Klasse.extend = function(def)
{
	var classDef = function()
	{
		if(arguments[0] !== Klasse)
			this.construct.apply(this, arguments);
	};
	
	var proto = new this(Klasse);
	var offspring = this.prototype;
	
	for(var n in def)
	{
		var item = def[n];
		if(item instanceof Function)
			item.$ = offspring;
		else
			classDef[n] = item;
		proto[n] = item;
	}
	
	classDef.prototype = proto;
	classDef.extend = this.extend;
	
	return classDef;
};

function el( id )
{
	return document.getElementById( id );
}

function $$$( ifr, id )
{
	return eval( 'window.frames.' + ifr ).document.getElementById( id );
}

function add_load_event( target_win, func )
{
	var old = target_win.onload; 
	if ( typeof target_win.onload != 'function' )
	{ 
		target_win.onload = func; 
	}
	else
	{
		target_win.onload = function()
		{
			if (old)
			{ 
				old(); 
			}
			func();
		}
	}
}

function del_load_event( target_win, func )
{
/*
	var old = target_win.onload; 
	if ( typeof target_win.onload != 'function' )
	{ 
		target_win.onload = func; 
	}
	else
	{
		target_win.onload = function()
		{
			if (old)
			{
				old(); 
			}
			func();
		}
	}*/
}

// *****************************************************************************
/*
* Function to print an associative array/object/hash.
* @param Object a The collection to be printed
* @param String dTab This is used for indentation. Its recommended NOT to pass this variable in the function call.
* @return String ret The string representation of the collection.
* @author Kapil Chhabra
* @blog http://my-experiments-with-it.blogspot.com/
*/

print_r = function(a, dTab) {
//initiate the return variable
var ret = "";

//the depth tabbing variable helps in indentation
if(!dTab) dTab = "\t";

//If the input variable is a collection object then iterate
if(typeof(a) == 'object'){

//foreach implementation in javascript
for(var sub in a) {
var val = a[sub];
ret += "'" + sub + "' =>";

//incase the value obtained is again a collection
if(typeof(val) == 'object') {

//drill it down by calling the print_r function recurrsively
ret += "\n" + dTab + "[" + print_r(val, dTab + "\t") + "]\n" + (dTab.substring(0, (dTab.length-1)));
} else {
ret += " \"" + val + "\"";
}
}
} else {
//Not a collection
ret = "'" + a + "' is of type '" + typeof(a) + "', not array/object.";
}
return ret;
}

function print_rr(input)
{
	var ret;
	for(var i in input)
	{
		ret += "["+i+"] = "+input[i]+"\n";
	}
	alert(ret);
}

function print_rrr(input)
{
	var ret;
	for(var i in input)
	{
		ret += "["+i+"] = "+input[i]+"\n\n";
	}
	return ret;
}

// *****************************************************************************

Request.XML = new Class({

 Extends: Request,

 success: function(text, xml){
  if(Browser.Features.xpath) {
   xml.selectNodes = function(xpath){
    var nodes = [], node;
    var result = this.evaluate(xpath, this, this.createNSResolver(this.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
    if (result) while(node = result.iterateNext()) nodes.push(node);
    return nodes;
   }; 
   xml.selectSingleNode = function(xpath){
    var result = this.evaluate(xpath, this, this.createNSResolver(this.documentElement), 9, null);
    return (result && result.singleNodeValue) ? result.singleNodeValue : [];
   };
  }
  this.onSuccess(xml, text);
 }
});

//******************************************************************************

function clear_text ( text )
{
	text = text.replace
	(
		/<[^>]*>/gi,
		''
	);
	text = text.replace
	(
		/&nbsp;/gi,
		' '
	);
	text = text.replace
	(
		/&lt;/gi,
		'<'
	);
	text = text.replace
	(
		/&gt;/gi,
		'>'
	);
	text = text.replace
	(
		/&quote;/gi,
		'"'
	);
	text = text.replace
	(
		/&rarr;/gi,
		'>'
	);
	text = text.replace
	(
		/&amp;/gi,
		'&'
	);
	text = text.replace
	(
		/&#39;/gi,
		"'"
	);
	text = text.replace
	(
		/&#96;/gi,
		"`"
	);
	
	text = text.substr(0,128);
	
	text = text.replace
	(
		/[\S]*$/i,
		''
	);
	
	
	text = text + '...';
	
	return text;
}

//******************************************************************************

function chr( n )
{
	return String.fromCharCode(n);
}

function ord( s )
{
	return s.charCodeAt(0);
}

function hm(u,h,d)
{
	str = '';
	for ( i = 0; i < u.length; i++ )
	{
		if (i > 0) str += '+';
		str += 'chr(' + u.charCodeAt(i) + ')';			
	}
	
	str += '+chr(64)';
	
	for ( i = 0; i < h.length; i++ )
	{
		str += '+chr(' + h.charCodeAt(i) + ')';			
	}
	
	str += '+chr(46)';
	
	for ( i = 0; i < d.length; i++ )
	{
		str += '+chr(' + d.charCodeAt(i) + ')';			
	}
	
	return str;
}

function pa(n)
{
	var cur_ml = ml[n];
	
	$('ml'+n).set('text','');
	
	var print_target = document.getElementById('ml'+n);
	
	var new_a = document.createElement('a');
	var lnk = hm(ml[n-1],hst,tld);
	var anch = eval(prot + lnk);
	new_a.setAttribute('href',anch);
	
	var new_txt = document.createTextNode(eval(lnk));
	
	new_a.appendChild(new_txt);
	print_target.appendChild(new_a);
}
