// Versao 1.5 - 17/Nov/2010

function findPosX(obj)
{
        var curleft= 0;
        if (obj.offsetParent) {
                curleft = obj.offsetLeft
                while (obj = obj.offsetParent) {
                        curleft += obj.offsetLeft
                }
        }
//alert('X='+curleft);
        return curleft;
}
function findPosY(obj)
{
        var curtop = 0;
        if (obj.offsetParent) {
                curtop = obj.offsetTop
                while (obj = obj.offsetParent) {
                        curtop += obj.offsetTop
                }
        }
//alert('Y='+curtop);
        return curtop;
}
function getScreenSizeX()
{
  //return window.innerWidth; nao funciona no IE
  return $(window).width();
}
function getScreenSizeY()
{
  //return window.innerHeight;  nao funciona no IE
  return $(window).height();
}
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 ajaxLoad(url,area,whileWaitMsg)
{
   if(area==null || url==null)
   {
      return;
   }
   area.innerHTML=whileWaitMsg;
   if (window.XMLHttpRequest)
   {// Usado para Mozilla, Safari
     http_request = new XMLHttpRequest();
   }
   else if (window.ActiveXObject)
   { // Usado pro IE
     try
     {
         http_request = new ActiveXObject('Msxml2.XMLHTTP');
     }
     catch (e)
     {
        try
        {
         http_request = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (e)
        {}
     }
   }
   http_request.onreadystatechange  = function()
   {
       if(http_request.readyState  == 4)
       {
         if(http_request.status  == 200)
            area.innerHTML=http_request.responseText;
         else
            area.innerHTML='Error code='+ http_request.status;
       }
       else
       {
         //area.innerHTML='ReadyState='+http_request.readyState;
       }
   };
   http_request.open('GET',url,true);
   http_request.send(null);
}
function isNumeric(valor)
{
 var filter = /^([0-9])+$/;
 if(valor==null)
  return false;
 else
  return filter.test(valor);
}
function isEmailAddress(email)
{
 var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
 if(email==null)
  return false;
 else
  return filter.test(email);
}
function carregarGoogleMap(ddiv,htmlLabel,latitude,longitude,showCtrlNav,showCtrlType,mType)
{
   var odiv=document.getElementById(ddiv);

   if (odiv!=null && GBrowserIsCompatible())
   {
     var map = new GMap2(odiv);
     var point = new GLatLng(latitude,longitude);
     map.addOverlay(new GMarker(point));

     //Controlos de localizacao
     if(showCtrlNav)
     {
       //map.addControl(new GSmallMapControl());
       map.setUIToDefault();
     }

     // Controlo de tipo de visualizacao
     if(showCtrlType)
     {
        map.addControl(new GMapTypeControl());
     }
     map.setCenter(new GLatLng(latitude,longitude), 17);

     //Define o tipo de mapa
     map.setMapType(mType);

     if(htmlLabel!=null)
     {
       //map.openInfoWindow(map.getCenter(),document.createTextNode(htmlLabel));
       map.openInfoWindowHtml(map.getCenter(),htmlLabel);
     }
   }
}
 function WebizAlert(msg)
 {
   alert(msg);
 }
 function WebizGetAreaResultado()
 {
   return $('#area_resultado');
 }
 function WebizLimparRequestResultado()
 {
   WebizGetAreaResultado().html('');
   WebizGetAreaResultado().hide('slow');
 }
 function WebizIniciarRequestResultado()
 {
   WebizGetAreaResultado().html('');
   WebizGetAreaResultado().hide('fast');
 }
 function WebizPopupRequestResultado(html,tm,err)
 {
   if(html!=null && html.length>0 && tm>=0)
   {
      if(err)
      {
         WebizGetAreaResultado().css({'background-color':'rgb(255, 111, 0)','border-left':'1px solid black','border-bottom':'1px solid black','border-right':'1px solid black'});   
      }
      else
      {
         WebizGetAreaResultado().css({'background-color':'rgb(255,255,255)','border-left':'1px solid black','border-bottom':'1px solid black','border-right':'1px solid black'});
      }
      if(tm>0)
      {
        WebizGetAreaResultado().html(html).show('slow').fadeOut(tm);
      }
      else
      {
        WebizGetAreaResultado().html(html).show('slow');
      }
   }
   else
   {
     WebizLimparRequestResultado();
   }
 }
 function WebizSetRequestResultado(html)
 {
      WebizPopupRequestResultado(html,0,false);
 }
 function WebizSetRequestError(html)      
 {
      WebizPopupRequestResultado(html,0,true);
 }
 function ddmmaaaaToDate(ddmmaaaa)
 {
      if(ddmmaaaa==null)
      {
          return null;
      }
      var aaaa=parseInt(ddmmaaaa.substring(6,10),10);
      var mm=parseInt(ddmmaaaa.substring(3,5),10)-1;
      var dd=parseInt(ddmmaaaa.substring(0,2),10);
      dt=new Date(aaaa,mm,dd);
      //alert(dt.toString());
      return dt;     
 }

