﻿// JScript File
    var DIVPopUp = "pop_up";			//CONTEM O NOME DA DIV QUE O POP-UP DEVERÁ SER ABERTO
	addLoadEvent(exibePopup);    	//INICIA A EXIBIÇÃO DO POP-UP
	
	function addLoadEvent(func) { //alert('teste');
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}
	
	function exibePopup()
	{
	    if(document.getElementById(DIVPopUp)!= null)
	    {
	        var pop_up = document.getElementById(DIVPopUp);
    	    //alert(pop_up);
	        //var Data = new Date();
		    demo.start(pop_up);
//	        makeRequestPopUp("inc_pop_up.aspx?dt="+Data.getSeconds());
	        
	    }
	}
	
	
	
	//FUNÇÃO QUE E CHAMADA PELO FLASH
/*	function AbrePopUp(janela,codigo){
		if (janela=="true" || janela=="True" || janela==true){
			window.open('inc_pop_up.aspx?pk='+codigo);
		}else{
			location = 'inc_pop_up.aspx?pk='+codigo;
		}
	}
*/	
	//FUNÇÂO QUE FAZ A REQUISIÇÃO NO SERVIDOR
/*	function makeRequestPopUp(pag){
        
        
        div = document.getElementById(DIVPopUp);
        
        var x = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			x = new XMLHttpRequest();
			if (x.overrideMimeType) {
				x.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				x = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					x = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}

	    if (x)
	    {   
		    x.onreadystatechange = function()
		    {
			    if (x.readyState == 4 && x.status == 200)
				{	
			        var xml = x.responseXML;
			        //alert(xml.childNodes.length);
			        if(xml.childNodes.length > 0)
			        {
			        if (document.all){
			            var nodes = xml.documentElement.childNodes;
			            if (nodes.item(3).text!="" && nodes.item(3).text!="0"){
							var newdiv = document.createElement('div');
							newdiv.style.width = nodes.item(1).text+"px";
							newdiv.style.height = nodes.item(2).text+"px";
							newdiv.innerHTML = nodes.item(3).text; 
							div.appendChild(newdiv);
				            if(nodes.item(0).text != 0)
				            {
				                setTimeout("fechaAutomaticamente()", parseInt(nodes.item(0).text)*1000);
				            }
			            }			
		            }else{
			            if (xml.childNodes[0].childNodes[7].data!="" && xml.childNodes[0].childNodes[7].data!="0"){
							var newdiv = document.createElement('div');
							newdiv.style.width = xml.getElementsByTagName('largura')[0].firstChild.data+"px";
							newdiv.style.height = xml.getElementsByTagName('altura')[0].firstChild.data+"px";
							newdiv.innerHTML = xml.childNodes[0].childNodes[7].data;
							div.appendChild(newdiv);
							
							if(parseInt(xml.getElementsByTagName('tempo')[0].firstChild.data) != 0)
				            {
				                setTimeout("fechaAutomaticamente()", parseInt(xml.getElementsByTagName('tempo')[0].firstChild.data)*1000);
				            }
			            }
		            }
		            }
	            	div.style.left = screen.width+"px";
                    //alert(pop_up.style.left);
                    demo.start(div);
				}
		    }
		    var Data = new Date();
		    
		    x.open("GET", pag+"?dt="+Data.getSeconds(), true);
		    x.send(null);
	    }
	}
*/
    
    //Função chamada caso o popup seja fechado automaticamente após um tempo.
/*    function fechaAutomaticamente()
    {
        document.getElementById(DIVPopUp).style.display='none';
    }
*/    

    //Função chamada ao se fechar o pop-up manualmente.
	function closeDiv()
    {
	    document.getElementById(DIVPopUp).style.display='none';
    }

	var demo =
	{
	    colorIndex:0,
	    interval:0,
	    element:null,
	    getRandom:function()
	    {
		    return Math.ceil(Math.random()*3) + 1;
		},
	    color:function()
	    {
		    var colors = ["#FFF"];
		    bytefx.color(
			    document.getElementById("text"),
			    "color",
			    colors[demo.colorIndex],
			    colors[++demo.colorIndex],
			    1,
			    demo.color
		    );
		    if(demo.colorIndex + 1 === colors.length)
			    demo.colorIndex = 0;
	    },
	    move1:function()
	    {
		    bytefx.move(demo.element, {x:500,y:100}, 3, null);
	    },
	    /*
	    move2:function()
	    {
		    bytefx.move(demo.element, {x:500,y:30}, demo.getRandom(), null);
	    },/*
	    move3:function()
	    {
		    bytefx.move(demo.element, {x:50,y:10}, demo.getRandom(), demo.move1);
	    },
	    move4:function(){
		    bytefx.move(demo.element, {x:10,y:10}, 9, demo.move1);
	    },*/
	    start:function(element)
	    {
		    this.element = element;
		    this.move1();
		    //this.color();
		    bytefx.drag(this.element,function()
		    {
				    bytefx.clear(demo.element)
				    // you could clear span clor too
				    // [i.e. bytefx.clear(document.getElementById("text"))]
			    },
			    function()
			    {
				    demo.move1()
			    }
		    );
	    }
    };
    



