﻿// JScript File

function openImprensa(){
    if(document.getElementById('imprensa').style.display=='none')
        document.getElementById('imprensa').style.display='';
    else
        document.getElementById('imprensa').style.display='none';
}

function submit(){
    document.forms['frmBusca'].submit();
}

function openQuestion(s){
    //alert(document.getElementById(resposta)==null);
    if(document.getElementById(s).style.display=='none')
        document.getElementById(s).style.display='';
    else
        document.getElementById(s).style.display='none';
}

function openImage(mypage, myname, w, h, scroll)
{
	pos_left = (screen.width - w) / 2
	pos_height = (screen.height - h) / 2
	winprops = 'height='+h+',width='+w+',scrollbars='+scroll+',left='+ pos_left +',top='+ pos_height +''
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function imprimirDiv(id, pg) {
    var oPrint, oJan;
    
    oPrint     = window.document.getElementById(id).innerHTML;
    oJan     = window.open(pg);
    oJan.document.write(oPrint);
    oJan.history.go();
    oJan.window.print();
}



//tipo - img, swf, css
//atributo - src, param, rel.
function alterarSRC(tipo, atributo){
	if(document.getElementsByTagName(tipo) != null)
	{
		for(i=0; (a = document.getElementsByTagName(tipo)[i]); i++) 
		{
		    if(tipo=='param') 
		    {
		        if (a.name=='movie'){
		            eval("a."+atributo + "='" + obterAtributo(tipo, a.getAttribute(atributo)) + "'");
		       }
		    }
		    else
		    {
		        eval("a."+atributo + "='" + obterAtributo(tipo, a.getAttribute(atributo))+ "'");
		    }
		}
	}	
}




function obterAtributo(tipo, atributo){
	var atributoAux;
	var relative='';
	var pasta='';
	
	atributo = atributo.replace('http://localhost/Fertility/','');
	if(atributo.indexOf('.')==0){
		relative = '../';
		atributoAux= atributo.substr(atributo.indexOf("/",3)+1);
	}
	else
		if(atributo.indexOf('/')==0){
			relative = '/';
			atributoAux= atributo.substr(atributo.indexOf("/",1)+1);
		}
		else
			atributoAux= atributo.substr(atributo.indexOf("/")+1);
	
	if(window.screen.width > 800)
	    pasta = '1024x768/';

    var ret;
    switch(tipo){
        case 'embed':
            ret =relative + 'swf' + pasta + atributoAux;
            break;
        case 'param':
            ret =relative + 'swf' + pasta + atributoAux;
            break;        
        case 'img':
            ret =relative + 'images' + pasta + atributoAux;    
            break;
        case 'link':
            ret=relative + 'css' + pasta + atributoAux;
            break;
        default:
            ret='';
    }
    
    //alert(ret);
    return ret;
	    
	    	    
}

var oAjax;

window.onload = function (){
	

    //alterarSRC('embed', 'src');
    //alterarSRC('param', 'value');
    //alterarSRC('img', 'src');
    //alterarSRC('link', 'href');
    
        
            
    AjaxRequest();
    oAjax.open('GET', 'Sessao/atualizar.aspx?value='+window.screen.width+'&cache='+new Date().getTime(),false);
    oAjax.send(null);
    retorno=oAjax.responseText;
    //alert('window.screen.width = ' + window.screen.width)
    //alert('retorno 1: ' + retorno);
    
    if(isNaN(retorno))
    {
        oAjax.open('GET', '../Sessao/atualizar.aspx?value='+window.screen.width+'&cache='+new Date().getTime(),false);
        oAjax.send(null);
        retorno=oAjax.responseText;
        //alert('retorno 2: ' + retorno);
    }
    
    if(retorno=='0')
        window.location.reload();
}


function AjaxRequest()
{
		try 
		{
			oAjax = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		    catch (e) 
		    {
			    try 
			    {
				   oAjax = new ActiveXObject("Microsoft.XMLHTTP");
			    } 
			        catch (e) 
			        {
				        oAjax = false;
		            }
		    }
		
		if (!this.ajaxInstance && typeof XMLHttpRequest != 'undefined') 
		{
			oAjax = new XMLHttpRequest();
		}
}


function Abrir(pagina,altura,largura)
		{
			var wndHeight = altura;
			var wndWidth = largura;
			var X = 0;
			var Y = 0;
			if (screen.availWidth)
			{
				X = (screen.availWidth / 2) - (wndWidth / 2);
				Y = (screen.availHeight / 2) - (wndHeight / 2);
			} 
			window.parent.open(pagina,"","left=" + X + "screenX=" + X + "screenY=" + Y + ",top=" + Y + ",toolbar=0,scrollbars=1,resizable=0,height="+ altura +",width="+ largura);
		}
		
		
function novajanela(url,nomejanela,largura)
{
window.open(url,nomejanela,largura);
}
