jQuery.included = function(file) {
	return jQuery('script[@src="'+file+'"]').length > 0;
}

jQuery.include = function(files)
{
	var a = files.split('|');
	for (var i = 0;i < a.length;i++) {
		if (!jQuery.included(filename = a[i])) {
	    jQuery("head").append(jQuery(document.createElement("script")).attr({type:'text/javascript',src:filename}));
		}
	}
};

jQuery.miss = function(file) {
	alert('"'+file+'" must be included!');
}

/* -------------------------------------------------------------------------- */

jQuery.popup = function(url,name,w,h)
{
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2;

	window.open(url,name,'copyhistory=no,width='+w+',height='+h+',left='+l+',top='+t);
}

/* -------------------------------------------------------------------------- */

jQuery.doPost = function(url,data)
{
	var form = $(document.createElement('form')).attr({action:url,method:'post'});

	for (name in data) {
    form.append($(document.createElement('input')).attr({type:'hidden',name:name,value:data[name]}));
	}

	$("body").append(form);
	form.get(0).submit();
}

/* -------------------------------------------------------------------------- */

jQuery.fn.collect = function()
{
	var obj = new Object();
	
	jQuery(this).find("input,select,textarea").each(function()
	{
	  if (this.nodeName.toLowerCase() == 'input' && (this.type == 'checkbox' || this.type == 'radio')) {
	  	if (this.checked) obj[this.name] = this.value ? this.value : 'on';
		} else {
			obj[this.name] = this.value;
		}
	});

	return obj;
}

jQuery.fn.hmac = function(challenge)
{
	if (typeof hex_hmac_sha1 != 'function') jQuery.miss('res/hash/sha1.js');
	return (typeof this.val() == 'string') ? hex_hmac_sha1(hex_sha1(this.val()),challenge) : null;
}
