// JavaScript Document
function addBookmark (title, url) {
if (document.all) window.external.AddFavorite(url, title);
else if (window.sidebar) window.sidebar.addPanel(title, url, "")
 }
 
function sendFriend () {
 url    = document.getElementById("recomendaramigo").getAttribute('href');
 target = 'recomendaramigo_popup';
 var nw = window.open(url, target, 'width=500,height=400,scrollbars=yes,resizable=yes,status=yes');
 if (nw) { return false; } 
}
//($('recomendaramigo') != null)? Event.observe('recomendaramigo', 'click', function(event){ openPopup('recomendaramigo','width=500,height=400'); return false; }) : false;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function submeterNewsletter (button) {
	
 // Processar dados : AJAX
 //   $('ajaxmsg').update('<img src="/images/waitstatus.gif" alt="Please wait..." width="16" height="16" style="vertical-align:middle" />');
	
	if($('ajaxmsg')!=null) { $('ajaxmsg').remove(); }
	new Insertion.After ($(button).id, '<div id="ajaxmsg" style="font-size:10px;"><img src="/images/waitstatus.gif" alt="Please wait..." width="16" height="16" style="vertical-align:middle" id="waitstatus" /></div>');
 
    //var idnews    = $F('idnews');
	var idnews    = 1;
	var idcountry = 0;
//    var nome      = $F('nome_news');
	var nome      = '';
	var email     = $F('email_news');
 
	var url  = '/includes/ajax_newsletter.inc.php';
	var pars = 'newsletter_action=subscribe&idnews='+idnews+'&nome='+nome+'&email='+email+'&idcountry='+idcountry;
	
	//urchinTracker('/novo_registo_newsletter');
	
	if (email == 'Insira o seu email') { $('ajaxmsg').update(''); return; };

	  var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				parameters: pars, 
				onSuccess: function (res) {
					//$('ajaxmsg').update( res.responseText );
					stripped = res.responseText.replace(/(<([^>]+)>)/ig,""); 
					alert(stripped);
					$('ajaxmsg').remove();
				 },
				onFailure: reportError
			});	

}

function submeterContacto () {
	
 // Processar dados : AJAX
 Element.hide('cb_form'); 
 Element.show('cb_ajaxwait');
 
 var params = Form.serialize('form_contact');
 var url  = '/includes/ajax_sendform.inc.php';
 var action = 'send';
 var pars = 'action='+action+'&'+params;
		
 var myAjax = new Ajax.Updater(
			{success: 'cb_ajaxwait'},  
			url, 
			{
				method: 'post', 
				parameters: pars,
				onFailure: reportError
 });
	
 return false;
}
function reportError () { alert('Sorry. There was an error.'); }


var newWindow = null;
function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
		
	type = type.toLowerCase();
	
	if (type == "fullscreen"){
		strWidth = screen.availWidth;
		strHeight = screen.availHeight;
	}
	var tools="";
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
function doPopUp(e)
{
//set defaults - if nothing in rel attrib, these will be used
var t = "standard";
var w = "600";
var h = "480";
//look for parameters
attribs = this.rel.split(" ");
if (attribs[1]!=null) {t = attribs[1];}
if (attribs[2]!=null) {w = attribs[2];}
if (attribs[3]!=null) {h = attribs[3];}
//call the popup script
popUpWin(this.href,t,w,h);
//cancel the default link action if pop-up activated
if (window.event) 
	{
	window.event.returnValue = false;
	window.event.cancelBubble = true;
	} 
else if (e) 
	{
	e.stopPropagation();
	e.preventDefault();
	}
}
function findPopUps() {
var popups = document.getElementsByTagName("a");
for (i=0;i<popups.length;i++)
 {
 if (popups[i].rel.indexOf("popup")!=-1) {
  // attach popup behaviour
  popups[i].onclick = doPopUp;
  // add popup indicator

/*
  if (popups[i].rel.indexOf("noicon")==-1)
  //more of the 'no icon' thing in a moment ...
   {
   popups[i].style.backgroundImage = "url(pop-up.gif)";
   popups[i].style.backgroundPosition = "0 center";
   popups[i].style.backgroundRepeat = "no-repeat";
   popups[i].style.paddingLeft = "15px";
   }
*/

// add info to title attribute to alert fact that it's a pop-up window
  popups[i].title = popups[i].title + " [Abre em nova janela]";
  
 } else if (popups[i].rel.indexOf("external")!=-1) { 
   popups[i].target = '_blank';
   popups[i].title = popups[i].title + " [Abre em nova janela]";
 }
 }
}

function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}
addEvent(window, 'load', findPopUps, false);

function openPopup (id, popoptions) {
 url    = document.getElementById(id).getAttribute('href');
 target = id+'_popup';
 var nw = window.open(url, target, popoptions+',scrollbars=yes,resizable=yes,status=yes');
 if (nw) { return false; }
 return false;
}


