function IsNumeric(sText){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1){
			IsNumber = false;
		}
	}
	return IsNumber;
}

function getMultiple(ob){
 	selected = new Array();
  	for (var i = 0; i < ob.options.length; i++){
    	if (ob.options[i].selected){
     		selected.push(ob.options[i].value);
     	}
	}
	return selected;
}

function openTooltip(url, id){
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
			Ajax_Tooltip(transport.responseText,id);
		}
	});
}

function buildData(form,spec){
	var gg = document.getElementById('datagg_'+spec).value*1;
	var mm = (document.getElementById('datamm_'+spec).value*1)-1;
	var aa = document.getElementById('dataaaaa_'+spec).value;
	var orario = (document.getElementById('orario_'+spec).value).split(":");
	var ggmysql = gg;
	var mmmysql = mm;
	var aamysql = aa;
	
	var time = new Date();
	if ((gg>0) && (mm>=0) && (aa>0)){
		time.setFullYear(aa);
		time.setMonth(mm);
		time.setDate(gg);
		time.setHours(orario[0], orario[1], 0);
		var timestamp = (time.getTime() / 1000);
		
		var mmstring = ((mmmysql+1)<10) ? '0'+(mmmysql+1) : (mmmysql+1);
		var ggstring = (ggmysql<10) ? '0'+ggmysql : ggmysql;
		document.getElementById('dataora_'+spec).value = Math.round(timestamp);
		document.getElementById('dataora_mysql_'+spec).value = aamysql+'-'+mmstring+'-'+ggstring;
		
		if (gup("module")=='Contabilita'){
			if (aa>1000){	
				checkquery('dataora_'+spec);
			}
		}
	}else{
		document.getElementById('dataora_'+spec).value = "NULL";
		document.getElementById('dataora_mysql_'+spec).value = "NULL";
	}
	return false;
}
function gup(name){
  name = name.replace(/#pag\d+/,"");
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function getQueryString(){
	var querystring = new Array;
	// parse current url into an array with the keys/values
	var q = String (document.location).split ('?')[1];
	if (!q) return false;
	q = q. split ('&');
	for (var i = 0 ; i < q.length; i++){
		// for each key/value, split them at the '='
		// and add them to the qerystring array
		var o = q[i].split('=');
		if (unescape(o[0]).search(/function/)<0)
			querystring[o[0]] = o[1];
	}
	// return the querystring
	return querystring;
}
function getQueryString4editor(){
	var get = getQueryString();
	var out = '';
	for (var i in get){
		if ((i!='module') &&
			(i!='file') &&
			(i!='act') &&
			(i!='row') &&
			(i!='in_array') &&
			(i!='clone') && 
			(i!='rand') &&
			(i!='filtri') &&
			(unescape(get[i]).search(/function/)<0)
			){
			out+='&'+i+'='+unescape(get[i]);
		}
	}
	return out;
}
function register_cli(){
	window.location.replace('index.php?module=register');
}
function setStatus(check,id){
	if (check.checked==true){
		document.getElementById(id).value=1
	}else{
		document.getElementById(id).value=0
	}
}
function open_list(type, img){
	lista = document.getElementById(type+'_lista')
	if (lista.style.display=='block'){
		lista.style.display='none'
		img.src='img/closed.png'
	}else{
		lista.style.display='block'
		img.src='img/open.png'
	}
}
function paginate(url){
	filtra();
	if ($('int_content')!=undefined){
		Effect.ScrollTo('int_content');
	}
	
	new Ajax.Updater('int_content', url+'&request=ajax',{
		onSuccess: function(transport) {
			window.setTimeout(setEqual, 1000);
		}
	});
	
}
function filtra(){
	var collection = document.filter_hash.elements;
	var filter = new Array;
	var stosend;
	var ftosend;
	var i = 0;
	var k = 0;
	for (var i  in collection){
		if ((collection[i] != undefined) && (collection[i].name != undefined) && (collection[i].name.replace("_sel","")!="") && (collection[i].value!=0) && (collection[i].value!='') && (collection[i].value!=undefined) && (collection[i].value!="NULL") && (collection[i].value!="0000-00-00"))  {
			if ((collection[i].id.substring(0,7) == 'dataora') || (collection[i].id.substring(0,6) == 'orario')){
				if (collection[i].name.substring(0,9)=="mysql_da_"){
					name = collection[i].name.replace("_sel","").replace("mysql_da_","")
					filter[k] = "(FROM_UNIXTIME("+name+",'%Y-%m-%d')>='"+collection[i].value+"')";
					k++;
				}else if (collection[i].name.substring(0,8)=="mysql_a_"){
					name = collection[i].name.replace("_sel","").replace("mysql_a_","")
					filter[k] = "(FROM_UNIXTIME("+name+",'%Y-%m-%d')<='"+collection[i].value+"')"
					k++;
				}
			}else if ((collection[i].type == 'select-one')){
				filter[k] = '(' + collection[i].name.replace("_sel","").replace("sel_","") +' = "' + escape(collection[i].value) + '")';
				k++;
			}else{
				filter[k] = '(' + collection[i].name.replace("_sel","").replace("sel_","") +' LIKE "%25' + escape(collection[i].value) + '%25" OR ' +collection[i].name.replace("_sel","") +' LIKE "%' + escape(collection[i].value) + '" OR ' +collection[i].name.replace("_sel","") +' LIKE "' + escape(collection[i].value) + '%" OR ' +collection[i].name.replace("_sel","") +' = "' + escape(collection[i].value) + '")';
				k++;
			}
		}
	}
	ftosend = filter.join(' and ');
	var extget = getQueryString4editor();
	url = 'index.php?module='+gup('module')+'&act='+gup('act')+'&request=ajax&filtri='+ftosend+extget;
	new Ajax.Updater('int_content', url,{
		onSuccess: function(transport) {
			window.setTimeout(setEqual, 1000);
		}
	});
}