// JavaScript Document

function add_imagem(area){
	
	
	cria_sombra('/add_img.php?&salvar=ok&area='+area);
	
	
	
}

function troca_texto(){
	cria_sombra('/troca_texto.php?area=texto');
	
}
function troca_texto_exames(){
	
	cria_sombra('/troca_texto.php?area=texto_exames');
}


function troca_rodape(){
	cria_sombra('/troca_texto.php?area=rodape');
	
}
function send_img_document(nome,caminho,area){

document.form1['img_'+area].value = nome;

document.getElementById('add_img_'+area).innerHTML = '<img src="'+caminho+"\" style=\"cursor:pointer\" onclick=\"add_imagem('" + area+"');\">'";
fecha();
//document.form1.cro.focus();
}

function send_texto_document(texto){
	
	document.getElementById('texto').innerHTML  =  texto;
	
	document.form1.texto.value = texto;
	fecha();
	
}

function SomenteNumero(event,obj){
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
     
	 
	 var caract = new RegExp(/^[0-9 ]+$/i);
      var caract = caract.test(String.fromCharCode(keyCode));
      //------------------------
      if(keyCode == 13 || keyCode ==9 || keyCode ==8){
	  
	 return true;
	  }else{
		   if(!caract){
         // alert("Caracter inválido: " +String.fromCharCode(keyCode));
          keyCode=0;
          return false;
      }
		  
		  
		  
	  }
} 





function cria_sombra(url){

var pageSize = getPageSize();
        
        var divSombra = document.createElement('div');
        divSombra.id = 'sombra';
		//divSombra = document.getElementById('sombra');// aqui mudei
        divSombra.style.width = (pageSize.pageWidth + 'px');
        divSombra.style.height = (pageSize.pageHeight + 'px');
		divSombra.style.background = '#FFFFFF';
		
        document.body.appendChild(divSombra);
		
		
		var divConteudo = document.createElement('div');
        divConteudo.id = 'div_frame';
		divConteudo.align = "right";
      
        //divConteudo.className = 'fotoZoom';
        
        var frameContato = document.createElement('iframe');
        frameContato.id = 'frame';
        //frameContato.className = 'borda_contato_frame_';
        frameContato.src = url;
        frameContato.frameBorder = 0;
        frameContato.scrolling = "no";
		// divFechar.appendChild(aFechar);
        //divConteudo.appendChild(divFechar);
		
		var divFechar = document.createElement('div');
		divFechar.id = 'fechar';
        divFechar.className = 'fechar';
        divFechar.align = "center";
		divFechar.title = 'fechar';
		divFechar.onclick = function() {
            fecha(this);
            return false;
        }
        var aFechar = document.createElement('a');
        aFechar.title = 'fechar';
        aFechar.innerHTML = '<strong class="titu">X</strong>';
		aFechar.className = 'titu';
        aFechar.href = '#';
        aFechar.onclick = function() {
            fecha(this);
            return false;
        }
		
		
		
		 divFechar.appendChild(aFechar);
        divConteudo.appendChild(divFechar);
        divConteudo.appendChild(frameContato);
        document.body.appendChild(divConteudo);
		
		
		
		
}

    function fecha(obj) {
        document.body.removeChild(document.getElementById('sombra'));
        document.body.removeChild(document.getElementById('div_frame'));
    }





















function getPageSize() {
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY){
            xScroll = document.body.scrollWidth;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight){
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else {
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
        var windowWidth, windowHeight;
        if (self.innerHeight) {
            windowWidth = self.innerWidth;
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) {
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }
        if(yScroll < windowHeight) pageHeight = windowHeight;
        else pageHeight = yScroll;
        if(xScroll < windowWidth) pageWidth = windowWidth;
        else pageWidth = xScroll;
        arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
        return arrayPageSize;
    }

