	$(function() {
		$("#tabelaGeral").hide();
		$("#size").resizable({
		maxWidth:1000,
		minWidth:100,
		resizable: true,
			ghost: true
		});
	});
	
	var idCache = new Array();
	
	function onOverIcon(idImg) {
	$(function() {
				$(idImg).animate({width: 150, height: 150}, 100);
	});

	}
	function onOutIcon(idImg) {
		$(function() {
				$(idImg).animate({width: 100, height: 100}, 100);
		});

	}

function preloader(url, div) {
	$(div).css('display', 'none');
	$(function () {
		var img = new Image();
		$(img).load(function () {            
			$(this).hide();            
			$(div).append(this);            
			$(div).css('display', 'block');
			$(this).fadeIn();        
			}).error(function () {            
			// notify the user that the image could not be loaded        
		}).attr('src', url);
	});
}

function antiCacheRand(aurl){                
	var dt = new Date();                
	if(aurl.indexOf("?")>=0){
		return aurl + "&" + encodeURI(Math.random() + "_" + dt.getTime());
	}else{ 
		return aurl + "?" + encodeURI(Math.random() + "_" + dt.getTime());
	}
}

			
function update(ident, div, div2) {
if(ident != false) {


        
           $("#"+div).ajaxStart(function() {
			   	alert();
               $("#"+div2).html("carregando").show();
           });
         
           var options = {
               target: "#"+div2, 
               url: "modules/cmd.php",
               type: "post", 
               success: function(contain) {
				   
               $("#"+div2).html(contain).show();
               }
           }
           
           $("#"+div).ajaxForm(options);
		   
	   ident = false;
   }
}

function formMethod(ident, form, div2, url, MEHTOD) {
	if(!METHOD) { METHOD = 'post'; }
if(ident != false) {
       $(form).submit(function() {
        
           $(form).ajaxStart(function() {
		   	
               $(div2).html("").show();
           });
         
           var options = {
               target: div2, 
               url: url,
               type: METHOD, 
               success: function(contain) {
               $(div2).html(contain).show();
               }
           }
           
           $(form).ajaxForm(options);
		   
       });
	   ident = false;
   }
}

	$(function() {
		$("#dialogConteudo").tabs();
	});
	
	function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}




addLoadEvent(function() {
  $("#loading").dialog('close');
  $("#tabelaGeral").fadeIn();
});


var DIV_ANTIGO;
function ativar(aurl, LINK, user, EXTRA, controler, code, key, cmd, orderBy, parameter, minimum, id, history) {
	if((aurl != DIV_ANTIGO) || (LINK == 2)) {
	if(parameter == 1) { frame = null; } else if(parameter == 2) { frame = 'fast'; } else { frame = 'slow'; }
	$(controler).hide();
	if(orderBy == null) {
	$(controler).html("<center><div style='width:100%;' align='center'><div style='width:60px;' style=''><span class='draw1'></span><span class='draw2'></span><span class='draw3'></span><span class='draw4'></span><div class='backgroundWhite' style='width:60px; height:40px; align:center; vertical-align:middle;' align='center'><img src='load.gif' align='center' style='vertical-align:middle; margin-top:12px;'></div><span class='draw5'></span><span class='draw6'></span><span class='draw7'></span><span class='draw8'></span></div></div></center>");	
	$(controler).fadeIn("slow");
} else {
	if(cmd == "search") {
$(controler).html("<center><div style='width:100%;' align='center'><div style='width:500px;' style='margin-bottom:170px;'><span class='draw1'></span><span class='draw2'></span><span class='draw3'></span><span class='draw4'></span><div class='backgroundWhite' style='width:500px; height:40px; align:center; vertical-align:middle;' align='center'><img src='images/loading11.gif' align='center' style='vertical-align:middle; margin-top:12px;'></div><span class='draw5'></span><span class='draw6'></span><span class='draw7'></span><span class='draw8'></span></div></div></center>");	
	$(controler).fadeIn("slow");
		} else {
			$(controler).show();
	}
	
}

	URL = antiCacheRand(aurl);
	$.get(URL,{ user: user, module: EXTRA, palavrasChave: key, cmd: cmd, order: orderBy, minimum: minimum, id: id },function(data){ $(controler).html(data); });
DIV_ANTIGO = URL;

	}

}




function ativarNoLoad(aurl, LINK, user, EXTRA, controler, code, key, cmd, orderBy, parameter, minimum, id, history) {
	URL = antiCacheRand(aurl);
	$.get(URL,{ user: user, add: LINK, module: EXTRA, key: key, cmd: cmd, order: orderBy, minimum: minimum, id: id },function(data){ $(controler).html(data); });
DIV_ANTIGO = URL;
}

function ativarNoLoadAppendTo(aurl, LINK, user, EXTRA, controler, code, key, cmd, orderBy, parameter, minimum, id, history) {
	URL = antiCacheRand(aurl);
	$.get(URL,{ user: user, module: EXTRA, palavrasChave: key, cmd: cmd, order: orderBy, minimum: minimum, id: id },function(data){ $(controler).append(data); });
DIV_ANTIGO = URL;
}



function detail(aurl, detail, user, id, type, controler) {
	if(detail != "remove") {
	URL = antiCacheRand(aurl);
	$.get(URL,{ user: user, id: id, type: type, detail: detail },function(data){ $(controler).html(data); });
	$(controler).fadeIn("slow");
	} else {
	$(controler).hide();
	}
}


	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: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			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.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


function createDialog(id, divID, width, titule, color, height) {
	$(function() {
		if(!$(divID).dialog('isOpen')) {
			$(divID).dialog({
				bigframe: true,
				width: width,
				height: height,
				maxWidth: width,
				minWidth: width,
				id: id,
				position: [50,50],
				modal: false,
                autoOpen: false,
				resizable: false,
				backgroundColor: color,
				title: titule
							
			});
		}
	});
    

}

function disableselect(e){
return false
}
function reEnable(){
return true
}
//document.onselectstart=new Function ("return false")
if (window.sidebar){
//document.onmousedown=disableselect
//document.onclick=reEnable
}

document.oncontextmenu = function(){return false}

$(function() {
		$("#loading").dialog({
			bgiframe: true,
			width: 500,
			maxWidth: 500,
			minWidth: 500,
			modal: true,
			autoOpen: true,
			resizable: false,
			buttons: {
			}
		});
});


$(function() {
		$("#errorBrowser").dialog({
			bgiframe: true,
			width: 500,
			maxWidth: 500,
			minWidth: 500,
			closeOnEscape: false,
			closeShow: false,
			modal: true,
			autoOpen: false,
			resizable: false,
			buttons: {
			
			}
		});
});


if((BrowserDetect.browser != 'Explorer')&&(BrowserDetect.version < 7)) {
	$(function() { 
		//$("#errorBrowser").dialog('open');
	});

}


// scroll
function pageScroll() {
window.scrollBy(x,y);
scrolldelay = setTimeout('pageScroll()', 10); // scrolls every 100 milliseconds
}
function setUp() { 
if( typeof( window.innerWidth ) == 'number' ) {
	/* Non-IE */
winW = window.innerWidth;
winH = window.innerHeight;
} else if( document.documentElement &&
( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
/* IE 6+ in 'standards compliant mode' */
winW = document.documentElement.clientWidth;
winH = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
/*IE 4 compatible*/
winW = document.body.clientWidth;
winH = document.body.clientHeight;
}
setL = winW/3;// zone left first 1/3 from client width
setR = winW*2/3;// zone right third 1/3 from client width
setU = winH/3-100;// zone up first 1/3 from client height
setD = winH*2/3+100;// zone down third 1/3 from client width
pix=25// scroll speed control pixels/mousemove
}
function checkS(e){
// capture the mouse position
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageY)
{
posy = e.pageY;
}
else if (e.clientY)
{ 
posy = e.clientY; 
}
// initialize the scrollBy parameters
x=0;
y=0;
// set the new scrollBy parameters

	if(posy<setU){
		y=-pix;
		pageScroll(x,y);	
	} else if(posy>setD){
		y=pix;
		pageScroll(x,y);
	} else {
		clearTimeout(scrolldelay);
	}
		this.window.onblur = function () {
		clearTimeout(scrolldelay);
	} 

} 


function selectRota(i) {
$('#rotaDefinida' + i).attr('value', $('#selectRota' + i).attr('value'));
$('#rotaShow' + i).attr('value', $('#rotaDefinidaNome' + i).attr('value'));
$('#dialogRotaChoice' + i).dialog('close');	
$('#dialogRotaChoiceEsquemaInForm' + i).html($('#dialogRotaChoiceEsquema' + i).html());
$('#dialogRotaChoiceEsquemaInForm' + i).css('display', 'block');
$('#rotaShow' + i).css('color', '#333333');
}


function ativarDialog(id, divID, aurl, user, temp, width, title, height, color) {
	if(idCache[id] == null) {
   $(divID).html("");
   imageMarginTop = height / 2-50;
			$(divID).html("<center><div style='height:" + height + " '><div style='width:100%; padding-top:" + imageMarginTop + "px;' align='center'><div style='width:60px;'><span class='draw1'></span><span class='draw2'></span><span class='draw3'></span><span class='draw4'></span><div class='backgroundWhite' style='height:40px; align:center; vertical-align:middle;' align='center'><img src='images/load.gif' align='center' style='vertical-align:middle;  margin-top:12px;'></div><span class='draw5'></span><span class='draw6'></span><span class='draw7'></span><span class='draw8'></span></div></div></div></center>");
			URL = antiCacheRand(aurl);
			if(color == null) { var color = '#eeeeee'; }
			$.get(URL,{ id: id, user: user, temp: temp, url: URL, divID: divID },function(data){ $(divID).html(data); });
			createDialog(id, divID, width, title, color);
			idCache[id] = true;
			$(divID).dialog('open');
			}

}

			function ac(a,b,c) {
					  refreshParecer = setTimeout('ac(\"'+a+'\",\"'+b+'\",\"'+c+'\")', 2000);
			          ativarNoLoad('modules/real/parecer.php', '', a, '', b, b, c);
			} 
