// JavaScript Document funcoes comuns de javascrip vão aqui
function vdata( strValue ) {
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

  if(!objRegExp.test(strValue))
    return false; 
  else{
    var strSeparator = strValue.substring(2,3) 
    var arrayDate = strValue.split(strSeparator); 

    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[0]);

    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; 
    }

    var intYear = parseInt(arrayDate[2]);
    var intMonth = parseInt(arrayDate[1]);
    if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
      return true; 
  }
  return false; 
}

function checkemail(str){
var testresults;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if (filter.test(str))
testresults=true;
else{
testresults=false;
}
return (testresults);
}

function naovazio( strValue ) {
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }
   return false;
}

function trimAll( strValue ) {
 var objRegExp = /^(\s*)$/;

    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

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_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_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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function isValid(parm,val) {
  if (parm == "") return false;
  for (i=0; i<parm.length; i++) {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
  }
  return true;
}

function  validateNumeric( strValue ) {
  var numb = '0123456789';
  return isValid(strValue,numb);
}

function sprintf(){var h=arguments,i=0,m=function(b,a,g,c){g||(g=" ");a=b.length>=a?"":Array(1+a-b.length>>>0).join(g);return c?b+a:a+b},l=function(b,a,g,c,d,e){var f=c-b.length;f>0&&(b=g||!d?m(b,c,e,g):b.slice(0,a.length)+m("",f,"0",!0)+b.slice(a.length));return b},d=function(b,a,g,c,d,e,f){b>>>=0;g=g&&b&&{2:"0b",8:"0",16:"0x"}[a]||"";b=g+m(b.toString(a),e||0,"0",!1);return l(b,g,c,d,f)};return h[i++].replace(/%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuidfegEG])/g,function(b, a,g,c,j,e,f){var n,o;if(b=="%%")return"%";var k=!1;o="";var p=j=!1;n=" ";for(var r=g.length,q=0;g&&q<r;q++)switch(g.charAt(q)){case " ":o=" ";break;case "+":o="+";break;case "-":k=!0;break;case "'":n=g.charAt(q+1);break;case "0":j=!0;break;case "#":p=!0}c=c?c=="*"?+h[i++]:c.charAt(0)=="*"?+h[c.slice(1,-1)]:+c:0;c<0&&(c=-c,k=!0);if(!isFinite(c))throw Error("sprintf: (minimum-)width must be finite");e=e?e=="*"?+h[i++]:e.charAt(0)=="*"?+h[e.slice(1,-1)]:+e:"fFeE".indexOf(f)>-1?6:f=="d"?0:void 0;a=a? h[a.slice(0,-1)]:h[i++];switch(f){case "s":return f=String(a),e!=null&&(f=f.slice(0,e)),l(f,"",k,c,j,n);case "c":return f=String.fromCharCode(+a),e!=null&&(f=f.slice(0,e)),l(f,"",k,c,j,void 0);case "b":return d(a,2,p,k,c,e,j);case "o":return d(a,8,p,k,c,e,j);case "x":return d(a,16,p,k,c,e,j);case "X":return d(a,16,p,k,c,e,j).toUpperCase();case "u":return d(a,10,p,k,c,e,j);case "i":case "d":return n=+a|0,b=n<0?"-":o,a=b+m(String(Math.abs(n)),e,"0",!1),l(a,b,k,c,j);case "e":case "E":case "f":case "F":case "g":case "G":return n= +a,b=n<0?"-":o,o=["toExponential","toFixed","toPrecision"]["efg".indexOf(f.toLowerCase())],f=["toString","toUpperCase"]["eEfFgG".indexOf(f)%2],a=b+Math.abs(n)[o](e),l(a,b,k,c,j)[f]();default:return b}})} function number_format(h,i,m,l){var h=(h+"").replace(/[^0-9+\-Ee.]/g,""),h=!isFinite(+h)?0:+h,i=!isFinite(+i)?0:Math.abs(i),l=typeof l==="undefined"?",":l,m=typeof m==="undefined"?".":m,d="",d=(i?function(b,a){var d=Math.pow(10,a);return""+Math.round(b*d)/d}(h,i):""+Math.round(h)).split(".");d[0].length>3&&(d[0]=d[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,l));if((d[1]||"").length<i)d[1]=d[1]||"",d[1]+=Array(i-d[1].length+1).join("0");return d.join(m)};
function setHomepage()
{
    if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage('http://www.alfa.pt');
    }
    else if (window.sidebar)
    {
        if(window.netscape)
        {
            try
            {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch(e)
            {
                alert("Esta acção foi impedida pelo seu navegador.\nSe deseja permiti-la, por favor escreva about:config na barra de endereço e modifique o valor de signed.applets.codebase_principal_support para true");
            }
         }
         var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
         prefs.setCharPref('browser.startup.homepage','http://www.unial.pt');
     }
}
