function setCheck(state, form)
{
    var checkBoxes = $(form).getElementsByClassName('checkbox');
    checkBoxes.each(function(i){
        i.checked = state;
    });
}

function __delete(jumpTo)
{
    if ( '' != jumpTo && confirm ( 'Are you shure you want to delete selected items ?' ) )
        document.location.href=jumpTo;
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
function canSave(elClass) {
	var items = $A(document.getElementsByClassName(elClass));
	for(i =0; i<items.length; i++) {
		if (!items[i].value.length) {
			return 0;
		}
	}
	return 1;
}

var gui={
    updateNode:function(item){
    	$(item).visualEffect('Highlight');
    }
}

var common={
	// default ajax loader image
	img: 'loader.gif',
	// request method
	request:function(method)
	{
		new Ajax.Request(
			method,
			{	
				method: 'get',
				evalScripts:true,
				asynchronous:true,
				onSuccess: function(transport) {
					// make something
				}
			}
		);
	},
	// load method
	load:function(method, id, img)
	{
		img = (img) ? img : common.img;

		new Ajax.Updater(
			id,
			method, 
			{
				method: 'get',
				evalScripts: true,
				asynchronous:true,
				onCreate: function() {
				     $(id).update('<div class="loading"><img src="/img/' + img + '"></div>');
				}
			}
		);
	},
	// update method
	update:function(method, id, params, img, complete)
	{
		img = (img) ? img : common.img;

		new Ajax.Updater(
			id,
			method, 
			{
				asynchronous:true,
				evalScripts:true,
				method: 'post',
				  onCreate: function() {
				     $(id).update('<div class="loading"><img src="/img/' + img + '"></div>');
				  },
				  onComplete: function() {
				  	complete;
				  },
				parameters:params
			}
		)
	},
	
	// empty element method
	close:function(id)
	{
		$(id).update('');
	},
	
	// set ajax loader image
	setImg:function(img)
	{
		this.img=img;
	},
	toInt:function(item)
	{
		return ( isNaN(parseInt(item))) ? 0 : parseInt(item);
	},
	toFloat:function(item)
	{
		return ( isNaN(parseFloat(item))) ? 0 : parseFloat(item);
	}
}

