function showIframe(url, extraClass)
{
   $('popupDiv').innerHTML = '<div id="expander"></div><a href="#" style="float:right;margin-top: -15px;" onclick="closeIframe()"><img src="/style/images/cancel.png" border="0"/></a>';
   
   if (extraClass != null)
     {
	if ($('popupDiv').extraClass != null)
	  {
	     Element.removeClassName($('popupDiv'), $('popupDiv').extraClass);
	  }
	Element.addClassName($('popupDiv'), extraClass);
	$('popupDiv').extraClass = extraClass;
     }
   
   
   $('popupDiv').url = url;
   new Ajax.Updater('popupDiv', url, {
      insertion: Insertion.Bottom,
	onComplete: function(t) {
	   Behaviour.apply();
      }
   });
   
   $('popupDiv').show();
   $('popupDiv').style.top = (window.scrollY?window.scrollY:document.body.scrollTop) + 20 + "px";
   $('wrapper').setStyle({opacity:  0.3});
}

function refreshIframe()
{
 showIframe( $('popupDiv').url );
}

function closeIframe()
{
   $('popupDiv').hide();
   $('wrapper').setStyle({opacity:  1});
}


// ----------

function saveVersionEnabled(versionId, enabled)
{
   new Ajax.Request("/actions/saveVersionEnabled.php", {
      method:  "post",
	parameters: {"versionId": versionId, "enabled": enabled?'y':'n' }
   });
}

function newVersion(product, version, callback)
{
 new Ajax.Request("/actions/newVersion.php", {
     method: "post",
     parameters: {"product":product, "version": version},
     onSuccess: callback
 });
}

function removeVersion(versionId)
{
   if ( confirm( "Do you really want to remove this version?") )
     {
	new Ajax.Request("/actions/removeVersion.php", {
	   method:"post",
	     parameters: {"versionId": versionId}
	});
     }
}



function addFile(versionId, url, title, comment, typ, callback)
{
   new Ajax.Request("/actions/addFile.php", {
      method: "post",
	parameters:
	{   
	   "versionId": versionId,
	     "downloadurl": url,
	     "title": title,
	     "comment": comment,
	     "typ": typ
	},
      onSuccess: callback
   } );
}

function editFile(fileId, url, title, comment, callback)
{
   new Ajax.Request("/actions/editFile.php", {
      method: "get",
	parameters:
	{
	   "fileId": fileId,
	     "downloadurl": url,
	     "title": title,
	     "comment": comment
	}
      ,onSuccess: callback
   });
}

function delFile(fileId)
{
   new Ajax.Request("/actions/removeFile.php", {
      method: "get", 
	parameters: { "fileId": fileId }
   });
}


function editFile_UI(id)
{
   Element.toggle("file_"+id);
   Element.toggle("editfile_"+id);
}


/// ----------------

function addFaq(product, question, title, email)
{
   
   new Ajax.Request("/actions/addFaq.php", {
      method: "get",
	parameters: 
	{
	   "product": product,
	     "title": title,
	     "email": email,
	     "question": question
	},
      onSuccess: function() 
	{
	   alert("Thank you, we will answer your question as soon as possible and post it here");
	   $('question').value = "";
	   $('title').value = "";
	   $('email').value = "";
	   Element.toggle('newFaqContent');
	}
   });
   
}

function publishFaq(faqId, publish)
{
   var status = publish ? "confirmed" : "pending";
   new Ajax.Request("/actions/publishFaq.php", {
      method: "get",
	parameters: 
	{
	   "faqId" : faqId,
	     "status" : status
	},
      onSuccess: function()
	{
	   
	}
   });
}

function removeFaq(faqId)
{
   new Ajax.Request("/actions/removeFaq.php", {
      method: "get",
	parameters: 
	{
	   "faqId": faqId
	},
      onSuccess: function()
	{
	   $('faq_'+faqId).remove();
	}
   });
}


// ------------

function createNewEvent(params)
{
   new Ajax.Request("/actions/createEvent.php", {
      method: "get",
	parameters: params,
	onSuccess: function(t)
	  {
	     window.location.reload();
	  }
      
   });
}

function removeEvent(eventId)
{
   new Ajax.Request("/actions/removeEvent.php", {
      method:"get",
	parameters: 
	{
	   "eventId": eventId
	},
      onSuccess: function(t) 
	{
	   $('event_'+eventId).remove();
	}
      
      
   });
}
