// JavaScript Document
var loader;
var funcaoLoad = null;
var newImg = [];
var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var mouseX = 0;
var mouseY = 0;

function getMouseXY(e) 
{
  if (IE) 
  {
    mouseX = window.event.clientX + document.body.scrollLeft;
    mouseY = window.event.clientY + document.body.scrollTop;
  } else 
  { 
   	mouseX = e.pageX;
    mouseY = e.pageY;
  }  
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}
  return true;
}

function procuraEnter(event)
{	
	if(window.event) 
	{
    	keynum = event.keyCode;		  
    } else if(event.which) 
	{	  
    	keynum = event.which 	 
   	}  
    if( keynum==13 ) 
	{	
		filtraBusca(); 
    }  
}

function xmlLoader(url)
{	
	if(window.XMLHttpRequest)
	{	
		loader = new XMLHttpRequest();
		loader.open("GET", url ,false);
        loader.send(null);	
		return loader.responseXML;
    }else if(window.ActiveXObject)
	{	
        loader = new ActiveXObject("Msxml2.DOMDocument.3.0");
        loader.async = false;
        loader.load(url);	
        return loader;
    }
}

function loadd()
{	
	if (window.DOMParser)
	{	
		parser = new DOMParser();
 		var xml = parser.parseFromString(loader.responseText,"text/xml");	
	}else
	{	
		var xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async="false";
		xml.loadXML(loader.responseText);	 
 	}
	if(funcaoLoad!=null)
	{
		funcaoLoad(xml);	
	}
}

function getWindowWidth() 
{
	var myWidth = 0; 
	if( typeof( window.innerWidth ) == 'number' ) 
	{
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		myWidth = document.documentElement.clientWidth;  
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}
function getWindowHeight() 
{	
 	var myHeight = 0; 
  	if( typeof( window.innerWidth ) == 'number' ) 
	{	  
		myHeight = window.innerHeight;	
  	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{	  
		myHeight = document.documentElement.clientHeight;	
  	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{	
		myHeight = document.body.clientHeight;	
  	}
  	return myHeight;
}

function getScroll()
{	
	var viewTop = $(window).scrollTop();
	var viewBottom = (viewTop + $(window).height());	
	return viewBottom;
}

function resumeTexto(text, size)
{	
	var textArray = text.split(" ");
	var textReturn = "";
	var textSize = (textArray.length < size) ? textArray.length : size;	
	for (var i = 0 ; i < textSize ; i++)
	{	
		textReturn += textArray[i] + " ";	
	}
	return textReturn;
}

function searchonBlur(obj)
{	
	if(obj.value=='')
	{		
		obj.value = 'digite o termo da busca';	
	}
}

function searchonFocus(obj)
{	
	if(obj.value=='digite o termo da busca')
	{	
		obj.value = '';	
	}
}

function getImgSize(imgSrc, id, imgLoaded)
{
	newImg[id] = new Image();
	newImg[id].name = id;
	newImg[id].src = imgSrc;	
	if(BrowserDetect.browser!="Explorer")
	{	
		newImg[id].onload = imgLoaded;	
	}else
	{
		imgLoaded(newImg[id]);	
	}
}

function openLink(url)
{	
	location.href=url;	
}

function openLinkWindow(url)
{
	window.open(url); 
	self.focus();	
}

function abreLinkPopUp(pagina, largura, altura)
{	
	w = getWindowWidth();
	h = getWindowHeight();	
	meio_w = w/2;
	meio_h = h/2;
	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+'');
}
