/*function switchtab(opt)
{
 	var container = opt.container ? opt.container : opt.obj.parentNode.parentNode.parentNode.parentNode;
	var className = opt.className ? opt.className : 'b300-tab-cont'; 
	var show = opt.show ? opt.show : "no-one";
	var ul_li = opt.ul_li ? opt.ul_li : "#tab-cont ul li";
	var classe = opt.classe ? opt.classe : "current";
	var tb = opt.obj.parentNode; 

	var tabcont = $(container).select('.'+className);
    tabcont.each(function(s, index) {
        if(s.id == show)
        {
            s.show();
        }
        else
        {
            s.hide();
        }
    });

	//var tabs = tb.parentNode.getElementsBySelector('li');   ---> BUG: non funziona con IE7
	var tabs = $A(tb.parentNode.getElementsByTagName('li'));
    tabs.each(function(s, index) {
        if(s == tb)
        {
            //s.addClassName(classe);  ---> BUG: non funziona con IE7
			s.className = classe;
        }
        else
        {
            //s.removeClassName(classe);  ---> BUG: non funziona con IE7
			s.className = "";
        }
    });

}*/

/** nuova funzione per i tab di link **/
function switch_tab(tab_object){
	var tab_object = tab_object;
	var content_object = document.getElementById(tab_object.id+"-cnt");
	var parent_object = document.getElementById(tab_object.parentNode.id);
    var tabs = parent_object.getElementsByTagName("li");
	for (var i = 0; i < tabs.length; i++) {
		var thisTab = tabs[i];
		if (thisTab.id) {
			var other_content_object = document.getElementById(thisTab.id+"-cnt");
			other_content_object.style.display = 'none';
			var other_tab_object = document.getElementById(thisTab.id);
    			other_tab_object.className = "";	
		}
	}	
	tab_object.className = "current";
	content_object.style.display = 'block';
}

function avatarUpload(id_form, target, waiting_image, id_container)
{
    rdm = new String (Math.random());
    rdm = rdm.substring(2,11);
    if (!$(target)) {
        new Insertion.After(id_form, '<iframe id="'+target+'" name="'+target+'" style="width:0;height:0;border:0"></iframe>');
    }
    $(id_container).update('<img src="'+waiting_image+'"> loading...');
    var form = $(id_form);
    var url_action = form.getAttribute("action");
    //url_action = url_action.match(/\?/g) ? url_action + '&id_container='+id_container+'&rxws='+rdm : url_action + '?id_container='+id_container+'&rxws='+rdm;
    if (url_action.match(/\?/g)) {
        if (!url_action.match(/id_container/g)) {
            url_action = url_action + '&id_container='+id_container;
        }
        if (url_action.match(/rxws/g)) {
            url_action = url_action + rdm;
        } else {
            url_action = url_action + '&rxws='+ rdm;            
        }
        
    } else {
        url_action = url_action + '?id_container='+id_container+'&rxws='+rdm;
    }
    form.setAttribute("action", url_action);
    form.submit();
}

function cleanText(obj, s) { if(obj.value == s) { obj.value = ''; } }

function formComplited(formName, init) {
	var s = $(formName);
	var compilato = false;
	var verified = false;
	var alertDiv = init.divmsg;
	var x = s.getElements();
	x.each(function(t) {
		if(init[t.name] != 'undefined' && t.value == init[t.name]) 
			verified = false;
		else {
			if(t.tagName.toLowerCase() == 'input') {
				switch(t.type.toLowerCase()) {
					case 'checkbox':	verified = t.checked; break;
					case 'hidden':	    break;
					default:			verified = t.present();
				}
			} else {
				verified = t.present();
			}
		}

		if(!verified) { t.observe('change', function(event) { $(alertDiv).hide(); } ); }
		compilato = compilato || verified;
	});

	if(!compilato) {
		$(alertDiv).show();
		return false;
	} else {  
		s.submit();
	}         
}

function submitKey(e, form)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13) {
          $(form).submit();
     } 
}

function checkAction(action,nick){
	var ret = false;
	var url = '/ajax_php/user/can'+action+'.php';
        var pars = 'n='+nick+'&rnd='+Math.random();
        var netAjax = new Ajax.Request(url,{method:'get', parameters: pars, asynchronous: false, onComplete: function(transp){eval(transp.responseText);} });
	return ret;
}

function blocca(nick,confirmed,postaction){
	if(confirmed===undefined)confirmed=false;
	if(postaction===undefined)postaction='window.location.reload();';
	if(confirmed||confirm('Questo utente non potrà più interagire con te.\n\nVuoi bloccare '+nick+'?')){
		var url = '/ajax_php/user/blocca.php';
		var pars = 'n='+nick+'&rnd='+Math.random();
		var netAjax = new Ajax.Request(url,{method:'get', parameters: pars, asynchronous: false, onComplete: function(t){eval(postaction);} });
	}
	return false;
}

function sblocca(nick,confirmed,postaction){
	if(confirmed===undefined)confirmed=false;
	if(postaction===undefined)postaction='window.location.reload();';
	if(confirmed||confirm('Questo utente potrà di nuovo interagire con te.\n\nVuoi sbloccare '+nick+'?')){
		var url = '/ajax_php/user/sblocca.php';
		var pars = 'n='+nick+'&rnd='+Math.random();
		var netAjax = new Ajax.Request(url,{method:'get', parameters: pars, asynchronous: false, onComplete: function(t){eval(postaction);} });
	}
	return false;
}


function isArray(obj) {
    try{
        return obj.constructor == Array;
}catch(e){ 
     return false;
  }
}
