var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) {

	if(popUpWin) {
    	if(!popUpWin.closed) popUpWin.close();
  	}
  	popUpWin = window.open(URLStr, 'popUpWin', "width="+width+", height="+height+"toolbar=0, menubar=0, top="+top+", left="+left+", scrollbars=1");
}


function submitContacts()
{
  Element.show('contactFormLoader');
  var creds = 'r=1&a=sendContactsMail&' + Form.serialize('contactForm');

  var required = $$('#contactForm .required');
  var params = new Array();
  required.each(function(el){params.push(el.id);  });

  creds = creds + '&required='+params.join(',');

  var ajax = new Ajax.Request('index.php', {
    method: 'post',
    parameters: creds,
    onComplete: function( request )
    {
      var data = request.responseText;
      data = JSON.parse(data);
      if (data == false) { alert('errore json'); return false; }
      
      // pulisco tutti errori
        $$('#contactForm .errText').each( function(el) {
          el.up('tr').removeClassName('errore');
          el.remove();

        });
      
      if (data.result == 'ok')
      {
        Element.hide('contactForm');
        Element.hide('contactFormLoader');
        Element.show('contactFormSuccess');
      }
      else
      {
        
        
        var errors = data.errors;
        var keys = Object.keys(errors);
        keys.each( function(key) {
          var el = Builder.node('div',{className:'errText'},data.errors[key]);
          $(key).up('td').insert ({'top':el});
          $(key).up('tr').addClassName('errore');
        });

        Element.hide('contactFormLoader');
      }
    }
  });
}

function switchNode(id)
{
  //alert('aaaa'+id);
  Effect.toggle('node_'+id, 'blind', { duration:0.25,
    afterFinish:function()
    {
      if ($('swapimg_'+id))
      {
        $('swapimg_'+id).src = ($('swapimg_'+id).src.include('minus.gif')) ? 'images/plus.gif' : 'images/minus.gif';
      }
    }
  });
}
