/**************************************************************************/
var GetObject = function(id,parent){
	if(parent == null) var parent = document;
	var o = parent.getElementsByName(id);
	if(o.length>1) return o; 
	else if(o.length==1) return o[0];
	else if(o.length==0) var o = parent.getElementById(id); if(o){ return o; }
	else alert('Error! Element \''+id+'\'does not exists!'); 
	return false;
}
var GetObjectParent = function(id){
	return GetObject(id).parentNode;
}
var GetObjectChildren = function(id){
	return GetObject(id).childNodes;
}

var $ = function(id,parent){
	if(parent == null) parent = document;
	var o = parent.getElementById(id);
	return o;
}

function getChildIndex(o,type,back){
	var tmp = o.parentNode;
	for(i=0;i<back;i++) tmp = tmp.parentNode;
	if(type!='') var childs = tmp.getElementsByTagName(type);
	else var childs = tmp.childNodes;
	for(i=0;i<childs.length;i++){ if(childs[i]==o) return i; }
}

var getParentTag = function(o,t){
	var p = o.parentNode;
	if(!p){
		return false;
	}else{
		if(p.tagName.toLowerCase()==t) return p;
		else return getParentTag(p,t);
	}
}
/*
var getElementsByClassName = function(str,type,child){
        var tmp = new Array();
        var o = child.getElementsByTagName(type);
        for(var i=0;i<o.length;i++){
                if(o[i].className.match(str)) tmp.push(o[i])
        }
        return tmp;
}
*/
function getElementsByClassName(str,type,child){
	if(!child) child = document;
	str = str.replace(/\-/g, "\\-");
	var regexp = new RegExp("(^|\\s)" + str + "(\\s|$)");
	var tmp = new Array();
	var o = child.getElementsByTagName(type);
	for(var i=0;i<o.length;i++){
		if(regexp.test( o[i].className )) tmp.push(o[i]);
	}
	return tmp;
}

function getElementsByName(str, type, child){
	if(!child) child = document;
	str = str.replace(/\-/g, "\\-");
	//var regexp = new RegExp("(^|\\s)" + str + "(\\s|$)");
	var regexp = new RegExp("" + str + "");
	var tmp = new Array();
	var o = child.getElementsByTagName(type);
	for(var i=0;i<o.length;i++){
		if(regexp.test( o[i].getAttribute('name') )) tmp.push(o[i]);
	}
	return tmp;
}

function getElementsByTagName(str, o){
	if(!o) o = document;
	list = o.getElementsByTagName(str);
	res = new Array();
	for(k=0;k<list.length;k++) res.push(list[k]);
	return res;
}


var nextSibling = function( str, prev ){
	var next = prev.nextSibling;
	if( next.tagName!=undefined && next.tagName.toUpperCase()==str.toUpperCase() ) return next;
	else return nextSibling(str, next );
	
}

var createTag = function(type,params){
	if(type){
		var o = document.createElement(type);
		for(var key in params){
			if(key=='id') o.setAttribute('id',params[key]);
			if(key=='name') o.setAttribute('name',params[key]);
			if(key=='type') o.setAttribute('type',params[key]);
			if(key=='value') o.setAttribute('value',params[key]);
			if(key=='className') o.setAttribute('class',params[key]);
			if(key=='src') o.src = params[key];
			if(key=='value') o.value = params[key];
			if(!(key=='id' | key=='name' | key=='value' | key=='className' | key=='src' )) o.style[key] = params[key];
		}
		return o;
	}
	return false;
}


var isArray = function(o){
	if(o.constructor.toString().indexOf("Array") == -1) return false;
	return true;
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isFunction(a) {
    return typeof a == 'function';
}
function stripHTML(t){
	return t.replace(/(<([^>]+)>)/ig,"");
}

function str_pad(str, len, pad, dir) {
	if (typeof(len) == "undefined") { var len = 0; }
	if (typeof(pad) == "undefined") { var pad = ' '; }
	if (typeof(dir) == "undefined") { var dir = 1; }
	str = str.toString();
	if (len + 1 >= str.length) {
		switch (dir){
			case 1:
				str = Array(len + 1 - str.length).join(pad) + str;
				break;
			case 2:
				var right = Math.ceil((padlen = len - str.length) / 2);
				var left = padlen - right;
				str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
				break;
			default:
				str = str + Array(len + 1 - str.length).join(pad);
				break;
		}
	}
	return str;
}

/**************************************************************************/
/*
document.layers  	The surfer is using NS 4
document.all 	The surfer is using IE 4+
window.opera 	The surfer is using Opera of some version
document.getElementById 	The surfer is using IE5+ OR NS6+/ Firefox
document.getElementById &&
!document.all

var isFF = function(){ if(document.getElementById && !document.all) return true; }
var isOP = function(){ if(window.opera) return true; }
var isIE = function(){ return false; }
*/

isFF = function(){
	if (navigator.appName.indexOf("Netscape")!=-1) return true;
}
isIE = function(){
	if (navigator.appName.indexOf("Microsoft")!=-1) return true;
}
isOP = function(){
	if (navigator.appName.indexOf("Opera")!=-1) return true;
}

if (!isIE()) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;
  var _x;
  var _y;

function getMousePosition(e) {
  if (!isIE()) {
    _x = e.pageX;
    _y = e.pageY;
  }
  if (isIE()) {
//    _x = event.clientX + document.body.scrollLeft;
//    _y = event.clientY + document.body.scrollTop;
	_x = event.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
	_y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  }
  return true;
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

var getMouseAbsolute = function(e){
	if(e.pageX) return [e.pageX,e.pageY];
	else if(e.clientX) return [e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft:document.body.scrollLeft), e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop:document.body.scrollTop)];
	else return null;
}

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

var GetOpacity = function(o){
	if(isFF()) return o.style.opacity*1;
	if(isIE()) return (o.filters.alpha.opacity)/100;
	if(isOP()) return o.style.opacity*1;
}

var SetOpacity = function(o,value){
	if(isFF()) o.style.opacity = value;
//	if(isIE()) o.filters.alpha.opacity = (value*100);
//	if(isIE()) o.filters = 'Alpha(Opacity='+(value*100)+')';
	if(isIE()) o.style.filter = 'alpha(opacity = '+(value*100)+')';
	if(isOP()) o.style.opacity = value;
}

var GetW = function(o){ return parseInt(o.style.width); }
var GetH = function(o){ return parseInt(o.style.height); }
var SetW = function(o,val){ o.style.width = val+'px'; }
var SetH = function(o,val){ o.style.height = val+'px'; }

var GetL = function(o){ return parseInt(o.style.left); }
var GetT = function(o){ return parseInt(o.style.top); }
var SetL = function(o,val){ o.style.left = val+'px'; }
var SetT = function(o,val){ o.style.top = val+'px'; }

var Stardust = function(){
	var parent = this;
	
	parent.width = function(o, value){
		if( isObject(o) ){
			if( value===undefined ) return parseInt(o.style.width);
			o.style.width = value + 'px';
			return true;
		}
	}
	parent.height = function(o, value){
		if( isObject(o) ){
			if( value===undefined ) return parseInt(o.style.height);
			o.style.height = value + 'px';
			return true;
		}
	}
	parent.left = function(o, value){
		if( isObject(o) ){
			if( value===undefined ) return parseInt(o.style.left);
			o.style.left = value + 'px';
			return true;
		}
	}
	parent.top = function(o, value){
		if( isObject(o) ){
			if( value===undefined ) return parseInt(o.style.top);
			o.style.top = value + 'px';
			return true;
		}
	}
	parent.right = function(o, value){
		if( isObject(o) ){
			if( value===undefined ) return parseInt(o.style.right);
			o.style.right = value + 'px';
			return true;
		}
	}
	parent.bottom = function(o, value){
		if( isObject(o) ){
			if( value===undefined ) return parseInt(o.style.bottom);
			o.style.bottom = value + 'px';
			return true;
		}
	}
	
	parent.opacity = function(o, value){
		if( isObject(o) ){
			if( value===undefined ) return isIE()? o.filters.alpha.opacity/100 : o.style.opacity*1;
			o.style.filter = isIE()? 'alpha(opacity = '+(value*100)+')' : o.style.opacity = value
			return true;
		}
	}
	
	parent.crop = function(o, p1, p2, p3, p4){
		if( o.clip ) {
			o.clip.left = p4; o.clip.top = p1; o.clip.right = p2; o.clip.bottom = p3;
		}else{
			o.style.clip = 'rect('+p1+'px,'+p2+'px,'+p3+'px,'+p4+'px)';
		}
	}
}
var stardust = new Stardust();


var crop = function(o, p1, p2, p3, p4){
	if( o.clip ) {
		o.clip.left = p4;
		o.clip.top = p1;
		o.clip.right = p2;
		o.clip.bottom = p3;
	}else{
		o.style.clip = 'rect('+p1+'px,'+p2+'px,'+p3+'px,'+p4+'px)';
	}
}
function stripHTML(val){
	var re= /<\S[^><]*>/g
	//for (i=0; i<arguments.length; i++)
	//arguments[i].value=arguments[i].value.replace(re, "")
	return val.replace(re, "")
}

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


function addEvent( obj, type, fn , follow)
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, follow );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

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

	function xmlhttpPost(url, synch){
	    var xmlHttpReq = false;
	    var self = this;
	    this.res;
	    if (window.XMLHttpRequest) self.xmlHttpReq = new XMLHttpRequest(); // Mozilla/Safari
	    else if (window.ActiveXObject) self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); // IE
	    
	    self.xmlHttpReq.open('GET', url, synch);
	    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    self.xmlHttpReq.onreadystatechange = function() {
        	if(self.xmlHttpReq.readyState == 4) {
				self.res = self.xmlHttpReq.responseText;
	        }
	    }
		self.xmlHttpReq.send(url);
		return this.res;
		    
	}

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

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