/**
 * General functions
 * @version 0.1
 * @author Jaap Broeders
 * @copyright 2006 - 2009 Beatboost
 */
function in_array(needle, haystack) {
	var hay = haystack.toString();
  if(hay == '') return false;
  var pattern = new RegExp(needle, 'g');
  var matched = pattern.test(haystack);
	return matched;
}
function makeArray(o) {
	// make an array from any object
	if (o == null) return [];
	if (!o.length) return [o];
	var result = [];
	for (var i=0; i<o.length; i++) result[i] = o[i];
	return result;
}
function copyObject(obj) {
	for (i in obj) {
	 	if (typeof obj[i] == 'object') this[i] = new copyObject(obj[i]);
  	else this[i] = obj[i];
	}
}
function ucFirst(str) {
   return str.substr(0,1).toUpperCase() + str.substr(1,str.length);
}
function str_repeat(s,l){
	return new Array(l+1).join(s);
}
function trim(val) {
  val = val.replace(/^\s+/,'');
  val = val.replace(/\s+$/,'');
  return val;
}
function getElementsByClassName(oElm, strTagName, needle){
	var s, i, r = [], l = 0, el;
  var re = new RegExp('(^|\\s)' + needle + '(\\s|$)');
  if (navigator.userAgent.indexOf('Opera') > -1) {
		s = oElm, i = 0;// [document.documentElement || document.body], i = 0;
		do { el = s[i];
			while (el) { if (el.nodeType == 1) { if (el.className && re.test(el.className)) { r[l++] = el; } s[i++] = el.firstChild; } el = el.nextSibling;	}
		} while (i--);
	} else {
		s = oElm.getElementsByTagName(strTagName), i = s.length; //document.getElementsByTagName('*'), i = s.length;
		while (i--) { el = s[i]; if (el.className && re.test(el.className)) { r[l++] = el; }}
	}
	return r;
}
function findMousePos(e) {
	// pos contains the mouse positions relative to the document
	var pos = new Array();
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		pos['x'] = e.pageX;	pos['y'] = e.pageY;
	} else if (e.clientX || e.clientY) 	{
		pos['x'] = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		pos['y'] = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	return pos;
}
function findPos(obj) {
	var curleft = curtop = 0;
	try {
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				if (obj.offsetParent.scrollLeft) { curleft -= obj.offsetParent.scrollLeft; }
				curtop += obj.offsetTop;
				if (obj.offsetParent.scrollTop) { curtop -= obj.offsetParent.scrollTop; }
			} while (obj = obj.offsetParent);
		} else if(obj.x && obj.y) {
	    	curleft += obj.x;
	    	curtop += obj.y;
		}
	} catch (e) { }
 	curleft += document.body.scrollLeft - document.body.clientLeft;
  	curtop += document.body.scrollTop - document.body.clientTop;
	return [curleft,curtop];
}

function showHideDiv(div) {
	if(document.getElementById(div)) {
		document.getElementById(div).style.display = ((document.getElementById(div).style.display=="block")?"none":"block");
	}
}
function showDiv(div) {
	
}
function hideDiv(div) {
	
}
function getFormValues(el) {
	var at = new Array();
	var fElem = el.elements;
	for(var i = 0; i < fElem.length; i++) {
		if(fElem[i].name.indexOf(el.name)!= -1) {
			if(fElem[i].value !="" && fElem[i].value != undefined) at[fElem[i].name] = fElem[i].value;
		}
	}
	return at;
}
function submitForm(vpid, vpfile, el) {
	var ac = new Array();
	var at = getFormValues(el);
	if(vpid > 0) {
		var a = viewports[vpid]['viewport'].getLink().split("&");
		for(var i = 0; i < a.length; i++) {
			var al = a[i].split("=");
			var v = al[0].indexOf("?");
			if(v>-1) al[0] = al[0].substr(1);
			ac[al[0]] = al[1];
		}
	}
	for(var inp in at) ac[inp] = at[inp];
	var str = "?1=1";
	for(var inp in ac) str += "&"+inp+"="+ac[inp];
	var vpid = vpid;
	FUI.debug("sf: "+vpfile+" - "+str);
	FUI.httpRequest(FUI.fui_root+"json.php?fFile="+vpfile, ac, function(respons) {
		if(!respons.error) {
			if(vpid > 0) {
				var a = viewports[vpid]['viewport'].getLink();
				if(a.indexOf("?")<0) a+="?1=1";
				Path.link(vpid, a+"&form=send");
			}
		}
		if(respons.script != undefined) eval(respons.script);
	}, "post");
	return false;
}
function serialize(a) {
	var s = [];
	if ( a.constructor == Array) { // If an array was passed in, assume that it is an array of form elements
		for( var i in a ) s.push(encodeURIComponent(i)+"="+encodeURIComponent(a[i])); // Serialize the form elements
	} else { // Otherwise, assume that it's an object of key/value pairs
		for ( var j in a ) { // Serialize the key/values
			if ( a[j] && a[j].constructor == Array ) { // If the value is an array then the key names need to be repeated
				for( var i in a[j] ) s.push(encodeURIComponent(i)+"="+encodeURIComponent(a[j][i]));
			} else { s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) ); }
		}
	} return s.join("&"); // Return the resulting serialization
}
function uploadAvatarDone(_1,_2) {
	document.getElementById(_2).value = _1;
	_d('updAvatarBtn').style.display = "block";
}	
function uploadAvatarStart(_1,_2) {
}
function Delegator() {}
Delegator.create = function (o, f) {
	var a = new Array() ;
	var l = arguments.length ;
	for(var i = 2 ; i < l ; i++) a[i - 2] = arguments[i] ;
	return function() {
		var aP = [].concat(arguments, a) ;
		f.apply(o, aP);
	}
}