function nullFunction() {};

if (typeof XWK == "undefined")
	XWK = {};


XWK.os = "";
XWK.browser = "";

XWK.initList = new Array();

XWK.addOnInit = function(callback) {
	XWK.initList.push([callback,XWK.arraySlice(arguments,1)]);
}

XWK.exists = function(str) {
	var arr = str.split('.')
	if (eval('typeof '+arr[0]) != 'object')
		return false;

	var ref = eval(arr[0]);
	for (var i=1; i< arr.length; i++) {
		var t = typeof ref[arr[i]];
		if (t == 'object' || t == 'function') {
			ref = ref[arr[i]];
			continue;
		}
		return false;
	}
	return true;
}

XWK.init = function() {
	XWK.guessOS();
	XWK.guessBrowser();
	for (var i=0; i<XWK.initList.length; i++) {
		XWK.sendCallback(XWK.initList[i][0],XWK.initList[i][1]);
	}
}

XWK.guessOS = function() {
	var str = 	navigator.appVersion.toUpperCase();
	if (str.indexOf("WIN") != -1) {
		XWK.os = "WIN";
		return;
	}
	if (str.indexOf("MAC") != -1) {
		XWK.os = "MAC";
		return;
	}
}

XWK.guessBrowser = function() {
	var str = 	navigator.userAgent.toUpperCase();
	if (str.indexOf("SAFARI") != -1) {
		XWK.browser = "SAFARI";
		return;
	}
	if (str.indexOf("MSIE") != -1) {
		XWK.browser = "IE";
		return;
	}
	if (str.indexOf("NETSCAPE") != -1) {
		XWK.browser = "NS";
		return;
	}
	if (str.indexOf("FIREFOX") != -1) {
		XWK.browser = "FF";
		return;
	}
	if (str.indexOf("OPERA") != -1) {
		XWK.browser = "OPERA";
		return;
	}
}

XWK.isMac = function() {
	return (navigator.appVersion.toUpperCase().indexOf("MAC") != -1);
}


XWK.getElementsByClass = function(styleClass,tag,node) {
	if (tag == null)
		tag = 'div'
	if (node == null)
		node = document;
	var divs = node.getElementsByTagName(tag);
	var res = new Array();
	for(var i=0; i<divs.length; i++) {
		if (divs[i].className && divs[i].className == styleClass) {
			res.push(divs[i]);
		}
//		var c = divs[i].getAttribute('class');
//		XWK.alertObj(divs[i]);
//		if (c && c.nodeValue &&  c.nodeValue == styleClass)
//			res.push(divs[i]);
	}
	return res;
}

XWK.sendCallback = function(func,args) {
	var obj=null;
	var objFunc = null;
	var callFunc = func;
	if (typeof func == "string") {
		var res= func.lastIndexOf(".");
		if (res > -1) {
			obj = eval(func.substr(0,res));
			objFunc = func.substr(res+1);
		}
		callFunc=eval(func);
	}
	//&& func.__prototype__ instanceof Array
	if (typeof func == "object") {
		try {
			obj = func[0];
			objFunc = func[1];
			callFunc = obj[func[1]];
		} catch(e) {
			return;
		}
	}

	if (args == null)
		args = new Array();

	if (callFunc.apply) {
		return callFunc.apply(obj,args);
	}


	var temp = new Array();
	for (var i=0; i<args.length; i++) {
		temp.push("args["+i+"]");
	}
	if (obj==null) {
		return eval("callFunc("+temp.join(",")+")");
	} else {
		return eval("obj."+objFunc+"("+temp.join(",")+")");
	}
}

XWK.alert = function(aa,b) {
	alert(aa+b);
	return "RET";
}
XWK.alertObj = function(obj,notHtml) {
	str = new Array();
	for (i in obj) {
		str.push(i+": "+obj[i])
	}

	if (notHtml) {
		alert(str.join("\n"));
		return;
 	}

    var temp = document.getElementsByTagName("body");
	var body = temp[0];
    var x = document.createElement("textarea");
       	        x.style.height = "500px";
	        x.style.width = "90%";
			body.appendChild(x);

       x.value = str.join("\n");

}

XWK.traceobj = null;
XWK.trace = function(str) {
    if (!XWK.traceobj) {
	    var temp = document.getElementsByTagName("body");
		var body = temp[0];
   		var x = document.createElement("textarea");
       	x.style.height = "500px";
	    x.style.width = "90%";
		body.appendChild(x);
      	XWK.traceobj = x;
      }
  	 XWK.traceobj.value += str+"\n";
}

XWK.arraySlice = function (arr,a,length) {
	var res = new Array();
	if (!length)
		length = arr.length;
	if (length > arr.length-a)
		length = arr.length-a;

	for(var i=a; i<arr.length; i++) {
		res.push(arr[i]);
	}
	return res;
}
/*
if (!XWK.exists("Array.prototype.splice")) {
	Array.prototype.push = function(obj) {
		this[this.length] = obj;
	}
}
if (!XWK.exists("Array.prototype.splice")) {
	Array.prototype.splice = function(i,d,replace) {
		var a = new Array();
		for (var k=0; k<this.length; k++) {
			if (k>=i && k<=i+d) {
				continue;
			}
			a.push(this[k]);
		}
		this.length = 0;
		for (var k=0; k<a.length; k++) {
			this[k] = a[k];
		}
	}
}
*/

XWK.extractInt = function(string) {
	return parseInt(string.match(/\d+/));
}


window.onload = XWK.init;



