﻿//
//Dodos os direitos reservados
//Script desenvolvido por Syllas Hewerton Duarte de Souza
//
//e-mail para contato
//waldyhester@gmail.com
//waldyhester@hotmail.com


//
// Frame Window
//
function AddWindowFrame(PAGE)
{
    BrowserDetect.init();

    if (BrowserDetect.browser == "Safari")
    {
        NewWindow(PAGE, "WindowFrame", "300", "250")
    }
    else
    {
	    addElement("windowBackgroundFrame", "WindowBackgroundFrame")
    	
	    //addInternalElement("windowFrame", "<iframe src=\""+PAGE+"\" style=\"height:300;\"  heigth=\"600px\" width=\"300px\" scrolling=\"no\" frameborder=\"1\" name=\"wFrame\"></iframe>", "WindowFrame");
	    //style=\"height:300; background-color: #000000; width: 600px\"
	    addInternalElement(PAGE);
	}
}

//Janela Externa
function NewWindow(PAGE, NAME, WIDTH, HEIGHT)
{
    var posLeft = LeftPositionWindowFrame();
    var posTop = "150px";
    window.open(PAGE,NAME,"width="+WIDTH+",height="+HEIGHT+",left="+posLeft+",top="+posTop+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no")
}

//Adiciona o elemento
function addElement(id, classname)
{
    //Cria o elemento
    var newdiv = document.createElement('div');
    //Set ID
    newdiv.setAttribute("id", id);
    //CSS classname
    newdiv.className = classname;
    //Largura
    newdiv.style.height = HeightWindowFrame();
    //Escreve no div HTML
    document.getElementById('backgroundWindowFrame').appendChild(newdiv);
}

//Largura do FUNDO TRANASPARENTE
function HeightWindowFrame()
{
	var ie4_check = (document.all && !document.getElementById) ? true : false;
	var ie5_check = (document.all && document.getElementById) ? true : false;
	
    if (ie4_check || ie5_check) 
	{
        Height = document.body.clientHeight + "px";
        //window.innerHeight
    } 
    else 
	{
        Height = "100%";
    }	
    return(Height);
}



//Adiciona o elemento interno
/*function addInternalElement(id, text, classname)
{
    //Busca a janela com FUNDO
    var ni = document.getElementById('windowBackgroundFrame');
  
    //Cria um novo elemento
    var newdiv = document.createElement('div');
    
    //Seta o ID
    newdiv.setAttribute("id", id);
    
    //CSS class
    newdiv.className = classname;
    
    //Visibilidade
    //newdiv.visibility = "visible"
    
    //Conteudo interno
    newdiv.innerHTML = text;
    
    //POSIÇÃO DA ESQUERDA
    newdiv.style.left = LeftPositionWindowFrame();
  
    //Adicionar o elemento
    ni.appendChild(newdiv);
}*/

function addInternalElement(src)
{
    //Cria um novo elemento
    var newdiv = document.createElement('iframe');
    
    
    
    newdiv.setAttribute("src", src);
    
    //CSS class
    newdiv.className = "WindowFrame";
    
    
    newdiv.setAttribute("height", 250);
    newdiv.setAttribute("width", 300);
    newdiv.setAttribute("scrolling", "no");
    newdiv.setAttribute("frameborder", "0");
    newdiv.setAttribute("frameborder", 0);
    
    //ID DO FRAME
    newdiv.setAttribute("id", "windowFrame");
    
    
    //POSIÇÃO DA ESQUERDA
    newdiv.style.left = LeftPositionWindowFrame();
    newdiv.style.top = "20%";
  
  
  
    var ni = document.getElementById('windowBackgroundFrame');
    //Adicionar o elemento
    ni.appendChild(newdiv);
}


//Posição da esquerda
function LeftPositionWindowFrame()
{
	var ie4_check = (document.all && !document.getElementById) ? true : false;
	var ie5_check = (document.all && document.getElementById) ? true : false;
	
    if (ie4_check || ie5_check) 
	{
        width = document.body.clientWidth;
    } 
    else 
	{
        width = window.innerWidth;
    }
    
    width = (width/2) - 150;
	
	//Posição da esquerda
    return(width + "px");
}





//Deleta os elementos
function RemWindowFrame()
{
    BrowserDetect.init();
    if (BrowserDetect.browser == "Safari")
    {
        window.close();
    }
    else
    {
	    remElement("windowBackgroundFrame");
	}
}

//Deleta os elementos
function remElement(id) 
{
  var d = document.getElementById('backgroundWindowFrame');
  var olddiv = document.getElementById(id);
  d.removeChild(olddiv);
}



//Quando RESINZE
function Resinze()
{
    //Procula o windowFrame pelo seu ID
    var divwindowFrame = document.getElementById('windowFrame');
    //Verifica se o windowFrame esta presente
    if (divwindowFrame != null)
    {
        //windowFrame presente
        divwindowFrame.style.left = LeftPositionWindowFrame();
    }
}
/////////////////////////////////////////////////////////////////////////////////////









//
// Detecta o Navegador
//
var BrowserDetect = 
{
	init: function () 
	{
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
/////////////////////////////////////////////////////////////////////////////////////









//
//Verifica a data de nascimento
//
function DATANASCIMENTO(fld, evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    else
    {
        if (fld.value.length == 2)
        {
            if (!PassDia(fld))
                return false;
            else
                fld.value = fld.value + '/';
        }
        if (fld.value.length == 5)
        {
            if (!PassMes(fld))
                return false;
            else
                fld.value = fld.value + '/';
        }
        if (fld.value.length == 9) 
        {
            //APONTA O ULTIMO CARACTERE
            //fld.value = fld.value + String.fromCharCode(charCode);
            //alert(fld.value+String.fromCharCode(charCode));
            
            //CALCULA A IDADE
            bDay = fld.value+String.fromCharCode(charCode);
            now = new Date()
            bD = bDay.split('/');
            if(bD.length==3)
            {
                born = new Date(bD[2], bD[1]*1-1, bD[0]);
                years = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
                //alert(bDay.value+': '+years)
             }
             //-----------------------------------------------------------------

            if (years < 18)
            {
                alert("MENOR DE 18 ANOS. NÃO É POSSÍVEL REALIZAR O CADASTRO.");
                fld.value = "";
                return false;
            }
            else
            {
                //alert(years);
                //fld.value = fld.value;
            }
        }
        
        return true;
    }
}
/////////////////////////////////////////////////////////////////////////////////////



//
//Verifica e-mail
//
function VMail(this_) 
{
	var str = this_.value;
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	
	if (str.length > 0)
	{
	    if ((str.indexOf(at)==-1) | 
	    (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) |
	    (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) |
	    (str.indexOf(at,(lat+1))!=-1) |
	    (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) |
	    (str.indexOf(dot,(lat+2))==-1) |
	    (str.indexOf(" ")!=-1))
	    {
		    this_.focus();
		    this_.style.backgroundColor = '#FFD7D7';
	        return false
	    }
	    else
	    {
		    this_.style.backgroundColor = '#FFFFFF';
	    }
	}

	return true					
}
/////////////////////////////////////////////////////////////////////////////////////


//
//Verifica Nome Completo
//
function VNome(this_) 
{
	var str = this_.value;
	var dot = " ";
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (str.length > 0)
	{
	    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot) == lstr || str.indexOf(dot) < 3)
	    {
		    this_.focus();
		    this_.style.backgroundColor = '#FFD7D7';
	       return false
	    }
	    else
	    {
		    this_.style.backgroundColor = '#FFFFFF';
	    }
	}

	return true					
}
/////////////////////////////////////////////////////////////////////////////////////

//
//Verifica Nome Completo
//
function VNull(this_) 
{
	var str = this_.value;
	
	if (str.length > 0)
	{
	    if (str.length < 3)
	    {
		    this_.focus();
		    this_.style.backgroundColor = '#FFD7D7';
	       return false
	    }
	    else
	    {
		    this_.style.backgroundColor = '#FFFFFF';
	    }
	}

	return true					
}
/////////////////////////////////////////////////////////////////////////////////////


//
//Ativa o flash
//
function RunFlash(Arquivo, Largura, Altura)
{
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
	document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ');
	document.write(' ID="flashJogo" WIDTH="' + Largura + '" HEIGHT="' + Altura+ '" ALIGN="">');
	document.write(' <PARAM NAME=movie VALUE="' + Arquivo + '">');
	document.write(' <PARAM NAME=quality VALUE="Autohigh">');
	document.write(' <PARAM NAME=wmode VALUE="Transparent">');
	document.write(' <PARAM NAME=bgcolor VALUE="">');
	document.write(' <PARAM NAME=scale VALUE="showall">');
	document.write(' <PARAM NAME=PLAY VALUE=true>');
	document.write(' <PARAM NAME=LOOP VALUE=true>');
	document.write(' <PARAM NAME=EmbedMovie VALUE="false">');
	document.write(' <PARAM NAME=BASE VALUE="">');
	document.write(' <PARAM NAME=SALIGN VALUE="">');
	document.write(' <PARAM NAME=FlashVars VALUE="">');
	document.write(' <PARAM NAME=MENU VALUE="false">');
	document.write(' <PARAM NAME="allowScriptAccess" VALUE="sameDomain">');
	document.write(' <EMBED src="' + Arquivo + '" quality="Autohigh" wmode=Transparent bgcolor="" ');
	document.write(' swLiveConnect=false WIDTH="' + Largura + '" HEIGHT="' + Altura + '" NAME="flashJogo" ALIGN=""');
	document.write(' allowScriptAccess="sameDomain"');
	document.write(' scale="showall"');
	document.write(' flashvars=""');
	document.write(' menu="false"');
	document.write(' PLAY=true');
	document.write(' LOOP=true');
	document.write(' EmbedMovie=false');
	document.write(' BASE=""');
	document.write(' SALIGN=""');
	document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
	document.write(' <NOEMBED>');
	document.write('  <IMG SRC="" WIDTH="' + Largura + '" HEIGHT="' + Altura+ '" BORDER=0>');
	document.write(' </NOEMBED>');
	document.write(' </EMBED>');
	document.write('</OBJECT>');
}
/////////////////////////////////////////////////////////////////////////////////////



//
//Verifica se o mês está correto de 1 a 12
//
function PassMes(THIS)
{
    now = new Date()
    bD = THIS.value.split('/');
    if(bD.length==2)
    {
        if (bD[1] > 12)
        {
            alert("MÊS INCORRETO. VARIAÇÃO DE 1 ATÉ 12.");
            return false;
        }
        else
        {
            if (bD[1] <= 0)
            {
                THIS.value = "";
                alert("MÊS INCORRETO. VARIAÇÃO DE 1 ATÉ 12.");
                return false;
            }
            else
            {
                return true;
            }
        }
    }
    else
    {
        return true;
    }
}
/////////////////////////////////////////////////////////////////////////////////////



//
//Verifica se o dia está correto de 1 até 31
//
function PassDia(THIS)
{
    now = new Date()
    bD = THIS.value.split('/');
    if(bD.length==1)
    {
        if (bD[0] > 31)
        {
            THIS.value = "";
            alert("DIA INCORRETO. VARIAÇÃO DE 1 ATÉ 31.");
            return false;
        }
        else
        {
            if (bD[0] <= 0)
            {
                THIS.value = "";
                alert("DIA INCORRETO. VARIAÇÃO DE 1 ATÉ 31.");
                return false;
            }
            else
            {
                return true;
            }
        }
    }
    else
    {
        return true;
    }
}
/////////////////////////////////////////////////////////////////////////////////////



//
//Captura as strings do navegador
//
function goToURL(str) 
{ 
    window.location = str;
}
/////////////////////////////////////////////////////////////////////////////////////



//
//Captura as strings do navegador
//
   
function QueryString(variavel)
{
    qs=new Array()
    variaveis=location.search.replace(/\x3F/,"").replace(/\x2B/g," ").split("&")
    if(variaveis!="")
    {
        for(i=0;i<variaveis.length;i++)
        {
            nvar=variaveis[i].split("=")
            qs[nvar[0]]=unescape(nvar[1])
        }
    }

    return qs[variavel]
}
/////////////////////////////////////////////////////////////////////////////////////