function hideIt(s)
{
    var obj = document.getElementById( s );
    obj.style.display = 'none'; 
}
function showIt(s)
{
    var obj = document.getElementById( s );
    obj.style.display = 'block'; 
}
function toggleViewIt(s)
{
    var obj = document.getElementById( s );
    if( obj.style && obj.style.display )
    {
        if( obj.style.display == 'block' ) obj.style.display = 'none';
        else obj.style.display = 'block';
    }
}
function fotoOpen(idTag,idImg,bOpen)
{
    var obj = document.getElementById( idTag );
    var objImg = document.getElementById( idImg );
    
    if( obj )
    {
        if( obj.style )
        {
            if( obj.style.display && obj.style.display == 'block' && !bOpen )
            {
                obj.style.display = 'none';
                objImg.src = imgClose.src;
            }
            else
            {
                obj.style.display = 'block';
                objImg.src = imgOpen.src;
            }
        }
    }
        
    return true;
}
function printEmail()
{
	document.write('sandro'+String.fromCharCode(64)+'aronanumismatica'+String.fromCharCode(46)+'com');
}
function LogOnSubmit()
{
	var sUser = document.formLogin.user.value;
	var sPwd = document.formLogin.pwd.value;

	if( !sUser || !sPwd )
	{
		alert('ATTENZIONE! Utente e password sono obbligatori per accedere ai servizi di amministrazione');
		document.formLogin.user.focus();
		document.formLogin.user.select();
		return false;
	}
	return true;
}
function ShowPopUp(sName,sUrl,w,h,c)
{
   var s, hwin;

   s = 'width=' + w + ',height=' + h
   if( c.length > 0 )
       s = s + ',' + c;
   if( c.length == 0 )
       sName = 'popUp';

   hwin = window.open(sUrl,sName,s);
   hwin.focus();
}
function setInnerText(o,t)
{
    if(o.text) {o.text=t;}
    else if(o.innerText) {o.innerText = t;}
    else {o.innerHTML = t;}
}
function getInnerText(o)
{
    if(o.text) {return o.text;}
    else if(o.innerText) {return o.innerText;}
    else if(o.innerHTML) {return o.innerHTML ;}
    return '';
}
function setBorder(o,w,s,c) {
  if( !o ) return;
  if( !o.style ) return;
  o.style.borderWidth = w;
  o.style.borderStyle = s;
  o.style.borderColor = c;
}
function setMargin(o,t,r,b,l) {
  if( !o ) return;
  if( !o.style ) return;
  o.style.marginTop = t;
  o.style.marginRight = r;
  o.style.marginBottom = b;
  o.style.marginLeft = l;
}
function setPadding(o,t,r,b,l) {
  if( !o ) return;
  if( !o.style ) return;
  o.style.paddingTop = t;
  o.style.paddingRight = r;
  o.style.paddingBottom = b;
  o.style.paddingLeft = l;
}
function refresh() {
   window.location.reload(true);
}
function okpNumeric(e) {
    if( !e ) e = window.event;
    if( e.keyCode < 0x30 || e.keyCode > 0x39 ) return false;
    return true;
}
function setBorder(o,b) {
    if( !o ) return;
    if( !o.style ) return;
    o.style.borderTop=b;
    o.style.borderRight=b;
    o.style.borderBottom=b;
    o.style.borderLeft=b;
}
function toolsTipOn(obj,idCss,tm) {
    var ott = document.getElementById(idCss);

    if( ott ) {
        obj.style.border = '1px solid red';
        obj.style.margin = '0';
        if( obj.alt ) ott.innerHTML = obj.alt;
        if( obj.title ) ott.innerHTML = obj.title;
        ott.style.top = (tm.y+5)+'px';
        ott.style.left = (tm.x+5)+'px';
        ott.style.display='block';
    }
}
function toolsTipOff(obj,idCss) {
    var ott = document.getElementById(idCss);

    if( ott ) ott.style.display='none';
    obj.style.border = '0';
    obj.style.margin = '1px';
}
function setSessionField(obj,sid) {
    if( obj ) {
        var v = obj.value;
        if( !v ) v = obj.innerHTML;
        if( !v ) v = obj.innerText;
        if( v ) postAjaxValuePair2Session('',null,sid,v);
    }
}
function getY( oElement ) {
    var iReturnValue = 0;
    while( oElement != null )     {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
function getX( oElement ) {
    var iReturnValue = 0;
    while( oElement != null )     {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
function getH( oElement ) {
    if( oElement.offsetHeight ) return oElement.offsetHeight;
    if( oElement.height ) return oElement.height;
    if( oElement.style.height ) return oElement.style.height;
    return 20;
}
function getW( oElement ) {
    if( oElement.offsetWidth ) return oElement.offsetWidth;
    if( oElement.width ) return oElement.width;
    if( oElement.style.width ) return oElement.style.width;
    return 20;
}

/* nl function */
function nl_subscription(id) {
    var o = document.getElementById(id); if( !o ) return;
    var ao = o.getElementsByTagName('input'); if( !ao ) return;

    var e='',n='';
    for(var i=0; i < ao.length; i++) {
        switch( ao[i].name ) {
        case 'alias':
            n = ao[i].value;
            break;
        case 'email':
            e = ao[i].value;
            break;
        }
    }
    
    if( e.length == 0 ) alert('email obbligatoria!');
    else postAjaxForm('nlsub.php',oksubscription,'c','1','e',e,'n',n);
}
function oksubscription() {
    if( !ajaxText['null'] ) return;
    var o = document.getElementById('idpopup'); if( !o ) return;
    var s = "<div><a href=\"javascript:hideIt('idpopup')\"><img align=\"right\" src=\"img/chiudi.png\" alt=\"\" /></a></div>";
    for(var i=0;i < ajaxText['null'].length;i++) s += ajaxText['null'][i]+'&nbsp;';
    setInnerText(o,s);
    o.style.display='block';
}
/* generic shop function */
function shop_gira_img(c,im,sz) {
    var o = document.getElementById( 'shopimg'+c ); if( !o ) return;
    var s = new Image();
    if( o.oldsrc ) s.src = o.oldsrc;
    else s.src = 'incphp/lib/img/crop.php?i='+im+'&p=shop&w='+sz+'&h='+sz;
    o.oldsrc = o.src;
    o.src = s.src;
}
function shop_acquista(c) {
    postAjaxForm('acquista.php',okacquisto,'c',c);
}
function okacquisto() {
    if( !ajaxText['null'] ) return;
    var o = document.getElementById('idpopup'); if( !o ) return;
    var s = '<div id="idpopupclose" onclick="javascript:hideIt(\'idpopup\');refresh();" ></div>'; //"<div><a href=\"javascript:hideIt('idpopup')\"><img align=\"right\" src=\"img/chiudi.png\" alt=\"\" /></a></div>";
    for(var i=0;i < ajaxText['null'].length;i++) s += ajaxText['null'][i]+'&nbsp;';
    setInnerText(o,s);
    o.style.display='block';
}

