/* Common Scripts for DIETADASEIVA.PT */

<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->

<!-- // Add to Favorite
function addFav(){t=document.title;l=location.href;m1="Press Ctrl + ";m2=" to Bookmark this page";if(window.opera != undefined ){var v="T";alert(m1+v+m2);}else if(window.sidebar){window.sidebar.addPanel(t, l,"")}else if(document.all!= -1){window.external.AddFavorite(l,t);}else {v="D";alert(m1+v+m2);}}
//-->

<!--
function sendPage() {
  var messageText = window.location;
  var subjectText = 'DietadaSeiva.pt';
  var email = prompt("Introduza o email do destinatário:", '');
{
    window.location = 'mailto:' + email +
      '?subject=' + encodeURIComponent(subjectText) +
      '&body=' + encodeURIComponent(messageText);
  }
}
//-->

<!--
function recomendar() {
  var messageText = 'Ola, encontrei este site e achei-o muito interessante: http://www.dietadaseiva.pt';
  var subjectText = 'O seu amigo(a) recomenda uma visita a este site';
  var email = prompt("Introduza o email do seu amigo(a):", '');
{
    window.location = 'mailto:' + email +
      '?subject=' + encodeURIComponent(subjectText) +
      '&body=' + encodeURIComponent(messageText);
  }
}
//-->

<!-- // Scroll to Anchors- by www.dreamlettes.net 
function ss_fixAllLinks() { 
 var allLinks = document.getElementsByTagName('a'); 
 for (var i=0;i<allLinks.length;i++) { 
   var lnk = allLinks[i]; 
   if ((lnk.href && lnk.href.indexOf('#') != -1) &&  
       ( (lnk.pathname == location.pathname) || 
   ('/'+lnk.pathname == location.pathname) ) &&  
       (lnk.search == location.search)) { 
     ss_addEvent(lnk,'click',smoothScroll); 
   } 
 }
} 
function smoothScroll(e) { 
 if (window.event) { 
   target = window.event.srcElement; 
 } else if (e) { 
   target = e.target; 
 } else return; 
 if (target.nodeType == 3) { 
   target = target.parentNode; 
 } 
 if (target.nodeName.toLowerCase() != 'a') return; 
 anchor = target.hash.substr(1); 
 var allLinks = document.getElementsByTagName('a'); 
 var destinationLink = null; 
 for (var i=0;i<allLinks.length;i++) { 
   var lnk = allLinks[i]; 
   if (lnk.name && (lnk.name == anchor)) { 
     destinationLink = lnk; 
     break; 
   } 
 } 
 if (!destinationLink) return true; 
 var destx = destinationLink.offsetLeft;  
 var desty = destinationLink.offsetTop; 
 var thisNode = destinationLink; 
 while (thisNode.offsetParent &&  
       (thisNode.offsetParent != document.body)) { 
   thisNode = thisNode.offsetParent;
   destx += thisNode.offsetLeft; 
   desty += thisNode.offsetTop; 
 } 
 clearInterval(ss_INTERVAL); 
 cypos = ss_getCurrentYPos(); 
 ss_stepsize = parseInt((desty-cypos)/ss_STEPS); 
 ss_INTERVAL = setInterval('ss_scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
 if (window.event) { 
   window.event.cancelBubble = true; 
   window.event.returnValue = false; 
 } 
 if (e && e.preventDefault && e.stopPropagation) { 
   e.preventDefault(); 
   e.stopPropagation(); 
 } 
} 
function ss_scrollWindow(scramount,dest,anchor) { 
 wascypos = ss_getCurrentYPos(); 
 isAbove = (wascypos < dest); 
 window.scrollTo(0,wascypos + scramount); 
 iscypos = ss_getCurrentYPos(); 
 isAboveNow = (iscypos < dest); 
 if ((isAbove != isAboveNow) || (wascypos == iscypos)) { 
   window.scrollTo(0,dest);
   clearInterval(ss_INTERVAL); 
   location.hash = anchor; 
 } 
} 
function ss_getCurrentYPos() { 
 if (document.body && document.body.scrollTop) 
   return document.body.scrollTop; 
 if (document.documentElement && document.documentElement.scrollTop) 
   return document.documentElement.scrollTop; 
 if (window.pageYOffset) 
   return window.pageYOffset; 
 return 0; 
}
function ss_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; 
 } 
}
var ss_INTERVAL; 
var ss_STEPS = 50; 
ss_addEvent(window,"load",ss_fixAllLinks);
//-->
