function setCurrent(id) {
        document.getElementById(id).className = 'select';
}

function openWin(strLink){
         window.open(strLink,'action','toolbar=no,width=400,height=218,scrollbars=no,status=no')
}

function closeWin() {
        window.open('','_parent','');
        window.close();
}

function appendOption(id,string,val) {

        var elOptNew = document.createElement('option');
        elOptNew.text = string;
        elOptNew.value = val;
        var elSel = document.getElementById(id);

        try {
                elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
        }
        catch(ex) {
                elSel.add(elOptNew); // IE only
        }

}

function removeOptions(id) {

        var elSel = document.getElementById(id);
        while (elSel.length > 0) {
                elSel.remove(elSel.length - 1);
        }

}

function comboItem(ID, ParentID, Value, Sel) {

        this.ID = ID
        this.Value = Value
        this.ParentID = ParentID
        this.Sel = Sel
}

function fillCombo(cmbArray, cmbObj, cmbKey, ind) {

        if (ind) { document.getElementById(ind).style.display = ''; }
        cmbObj.options.length = 0;
        q = 1;
        for (var i = 0; i < cmbArray.length; i++) {
                if (cmbArray[i].ParentID == cmbKey) {
                        cmbObj.options[q] = new Option(cmbArray[i].Value, cmbArray[i].ID, cmbArray[i].Sel);
                        q++;
                }
        }
        if (ind) { document.getElementById(ind).style.display = 'none'; }
}

function comboProv(strarray,prov_obj) {

        removeOptions(prov_obj);
        var num = 0;
        var prov = strarray.split(",");
        while (num < prov.length) {
                var elem = prov[num].split("=");
                appendOption(prov_obj,elem[0],elem[1]);
                num += 1;
        }

}

function changeProv(region,prov_obj,ind) {

        document.getElementById(ind).style.display = '';
        var url = '/bin/prov.php';
        var pars = 'id_region='+region;

        var callback = {
        success: function (o) {
             //alert(o.responseText);
                comboProv(o.responseText,prov_obj);
                document.getElementById(ind).style.display = 'none';
        },
        failure: function(o) {
            alert('Sorry. There was an error.');
        }
	}
	YAHOO.util.Connect.asyncRequest('POST', url, callback, pars);

}

function comboCity(strarray,city_obj) {

        removeOptions(city_obj);
        var num = 0;
        var cities = strarray.split(",");
        while (num < cities.length) {
                var elem = cities[num].split("=");
                appendOption(city_obj,elem[0],elem[1]);
                num += 1;
        }

}

function changeCity(prov,city_obj,ind) {

        document.getElementById(ind).style.display = '';
        var url = '/bin/city.php';
        var pars = 'id_prov='+prov;

        var callback = {
        success: function (o) {
             //alert(o.responseText);
                comboCity(o.responseText,city_obj);
                document.getElementById(ind).style.display = 'none';
        },
        failure: function(o) {
            alert('Sorry. There was an error.');
        }
	}
	YAHOO.util.Connect.asyncRequest('POST', url, callback, pars);

}

function verifyEmail(s) {
        var chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-@';
        var sLen = s.length; var i=0, c=0, cCnt=0, step=0;
        if (sLen < 6) return false;
        if (s.indexOf('@.')>=0) return false;
        if (s.indexOf('.@')>=0) return false;
        while (i < sLen){
                c=s.charAt(i);
                if (!(chrs.indexOf(c)>=0 || (c=='_' && step<1))) return false;
                if (c=='.') { if (cCnt<1) return false; cCnt=0; }
                if (c=='@') { if (step>0) return false; if (cCnt<1) return false; step++; cCnt=0; }
                cCnt=cCnt+1; i++;
        }
        if (cCnt < 3 || cCnt > 5 || step==0 || (s.indexOf(".")<0) ) return false;
        return true;
}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

var Dom = YAHOO.util.Dom;
var Event = YAHOO.util.Event;
var Anim = YAHOO.util.Anim;

function fadeObj(objid) {

	var anim = new YAHOO.util.ColorAnim(objid, {opacity: { to: 1.0}});

	anim.duration = 0.2;

	anim.onComplete.subscribe(function() {
		var timer = setTimeout(function() {

				var anim = new YAHOO.util.ColorAnim(objid, {opacity: { to: 0.0}});

				anim.duration = 0.2;

				anim.onComplete.subscribe(function() {

					// posso fare qualcosa alla fine dell'animazione

				});

				anim.animate();
			}, 3000);

		});

	anim.animate();
	return false;

}

