
/* ----- gerais.js ----- */
function fechar() {
    document.getElementById('LayerFlyerBox').style.display = 'none';
}

 function fechaDiv() {
     document.getElementById('LayerFlyerBox2').style.visibility = 'hidden';
 }

function abrirPopup(windowNome, windowUrl, windowWidth, windowHeight){
        windowTop    = screen.height/2 - windowHeight/2;
        windowLeft   = screen.width/2 - windowWidth/2;
        windowOpcoes = 'width=' + windowWidth + ', height=' + windowHeight + ', top=' + windowTop + ', left=' + windowLeft + ', scrollbars=none';
        windowPopup  = window.open(windowUrl, windowNome, windowOpcoes);
        windowPopup.focus();
}

function addFav(){
  var url = "http://www.apaesalvador.org.br"; 
  var title = "APAE Salvador";
  if (window.sidebar) window.sidebar.addPanel(title, url,"");
  else if(window.opera && window.print){
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
  }
  else if(document.all){window.external.AddFavorite(url, title);}
}

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_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 abreLayer(layerWidth, layerHeight, iframeUrl) {
    if (window.innerHeight && window.scrollMaxY) {	
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth){	
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    // container
    document.getElementById('layercontainer').style.top = '0px';
    document.getElementById('layercontainer').style.left = '0px';
    document.getElementById('layercontainer').style.width = pageWidth + 'px';
    document.getElementById('layercontainer').style.height = pageHeight + 'px';

    // content
    contentTop = 75;
    contentLeft = (pageWidth / 2) - (layerWidth / 2);

    document.getElementById('layercontent').style.top = contentTop + 'px';
    document.getElementById('layercontent').style.left = contentLeft + 'px';
    document.getElementById('layercontent').style.width = layerWidth + 'px';
    document.getElementById('layercontent').style.height = layerHeight + 'px';

    // close
    document.getElementById('layerclose').style.top = (contentTop + 5) + 'px';
    document.getElementById('layerclose').style.left = ((contentLeft + layerWidth) - 20) + 'px';
    document.getElementById('layerclose').style.width = '15px';
    document.getElementById('layerclose').style.height = '15px';

    // iframe layer
    document.getElementById('iframelayer').style.top = '0px';
    document.getElementById('iframelayer').style.left = '0px';
    document.getElementById('iframelayer').style.width = layerWidth + 'px';
    document.getElementById('iframelayer').style.height = layerHeight + 'px';

    // iframe content
    document.getElementById('iframecontent').style.width = layerWidth + 'px';
    document.getElementById('iframecontent').style.height = layerHeight + 'px';
    document.getElementById('iframecontent').src = iframeUrl;

    // visibilidade
    document.getElementById('layercontainer').style.visibility = 'visible';
    document.getElementById('layercontent').style.visibility = 'visible';
    document.getElementById('layerclose').style.visibility = 'visible';
}

function fechaLayer() {
    document.getElementById('layercontainer').style.visibility = 'hidden';
    document.getElementById('layercontent').style.visibility = 'hidden';
    document.getElementById('layerclose').style.visibility = 'hidden';
    document.getElementById('iframecontent').src = '';
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "* Você deve digitar um endereço de email válido.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "* Por favor, entre com um endereço de email válido.\n";
    }
    else {
       //testa email para evitar caracteres ilegais
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "* O endereço de email contém caracteres ilegais.\n";
       }
    }
return error;    
}


// numero de telefone - formata e delimita e checa se possui 10 digitos

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "* Você deve digitar um número de telefone válido.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "* O número de telefone contém caracteres ilegais.";
  
    }
    if (!(stripped.length == 10)) {
	     error = "* O número de telefone tem um tamanho incorreto. Tenha certeza que você incluiu um código de área.\n";
    } 
return error;
}


// password - entre 6-8 caracteres, uppercase, lowercase, e numeros

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "* Você deve digitar uma senha.\n";
}

    var illegalChars = /[\W_]/; // permite somente letras e números
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "* A senha tem um número incorreto de caracteres, deve ter entre 6 e 8 caracteres.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "* A senha contém caracteres ilegais.\n";
    } 
return error;    
}    


// nome de usuário - entre 4 e 10 caracteres, uc, lc, e  underscore somente.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "* Você deve digitar um nome de usuário válido.\n";
}


    var illegalChars = /\W/; // permite letras, numeros e underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "* Nome de usuário com tamanho incorreto, o nome de usuário deve ter entre 4 e 10 caracteres.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "* O nome de usuário contém caracteres ilegais.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "* Há campos obrigatórios em branco que devem ser preenchidos.\n"
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}
