// JavaScript Document
var loader;
var funcaoLoad = null;
var newImg = [];
var IE = (BrowserDetect.browser!="Explorer") ? false : true;

if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var mouseX = 0;
var mouseY = 0;

function getMouseXY(e) 
{	
  if (IE) 
  {  
	mouseX = event.clientX + document.body.scrollLeft;
    mouseY = 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' ) {
		  
		//Non-IE
		myWidth = window.innerWidth;
		   
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		   
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		  
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	   
	}
	  
	return myWidth;
  
}

function getWindowHeight() {
	
 	var myHeight = 0;
  
  	if( typeof( window.innerWidth ) == 'number' ) {
		  
		//Non-IE
		myHeight = window.innerHeight;
		
  	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
		
  	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		
		//IE 4 compatible
		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 = 'BUSCA';	
	}
}

function searchonFocus(obj)
{	
	if(obj.value=='BUSCA')
	{	
		obj.value = '';	
	}
}

function loadImg(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 = screen.width;
	h = screen.height;
	
	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+'');
	
}

function fieldFocus(obj){
	
	var oldValue = $(obj).attr("id");
	var vlr = $(obj).val();
	
	if(vlr=="" || vlr==oldValue)
	{	
		$(obj).val("");	
	}
}

function fieldBlur(obj)
{	
	var oldValue = $(obj).attr("id");
	var vlr = $(obj).val();	
	if(trim(vlr)=="")
	{	
		$(obj).val(oldValue);	
	}
}

function fieldFocusPassword(obj)
{
	$('#fakesenha').hide();
	$('#senha').show();
	$('#senha').focus();
}

function fieldBlurPassword(obj)
{
	var vlr = $("#senha").val();
	
	if(trim(vlr)=="")
	{	
		$('#senha').hide();
		$('#fakesenha').show();
	}
}

function trim(str)
{	
	return str.replace(/^\s+|\s+$/g,"");	
}

function disableSelection(target){

    if (typeof target.onselectstart!="undefined") //IE route
        target.onselectstart=function(){return false}

    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
        target.style.MozUserSelect="none";

    else //All other route (ie: Opera)
        target.onmousedown=function(){return false}

    target.style.cursor = "default";
	
}
