/*
document.onmousedown=click;*/
document.oncontextmenu = new Function("return false;");	

//limpa espacos em branco 
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}


//função redimensiona

function getPageScroll()
{

	var yScroll;
	
	if (self.pageYOffset) 
	{
		yScroll = self.pageYOffset;
	} 
	else if(document.documentElement && document.documentElement.scrollTop)
	{ // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} 
	else if (document.body) 
	{// all other Explorers
		yScroll = document.body.scrollTop;
	}
	
	arrayPageScroll = new Array('',yScroll)
	
	return arrayPageScroll;
}
	
function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) 
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else 
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) 
	{ // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight) 
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) 
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else 
	{
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{
		pageWidth = windowWidth - 18;
	} 
	else 
	{
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}



var Resize = {
	
	//essa primeira parte serve para funções na arvore
	'_open': function(){
		parent.$('#frameContainer2').removeAttr('cols');
		parent.$('#frameContainer2').attr('cols','100%,*');
		parent.$('#frameContainer').focus();
	},
	
	//essa primeira parte serve para funções na arvore
	'_open2': function(){
		parent.$('#frameContainer').removeAttr('rows');
		parent.$('#frameContainer').attr('rows','0,*');		
		parent.$('#frameContainer2').removeAttr('cols');
		parent.$('#frameContainer2').attr('cols','100%,*');
		parent.$('#frameContainer').focus();
	},
	
	//essa segunda parte serve para funções na no conteudo
	'_open3': function(){
		parent.$('#frameContainer').removeAttr('rows');
		parent.$('#frameContainer').attr('rows','0,*');		
		parent.$('#frameContainer2').removeAttr('cols');
		parent.$('#frameContainer2').attr('cols','100%,*');
		parent.$('#frameContainer').focus();
	},
	
	'_close': function(){
		parent.$('#frameContainer').removeAttr('rows');
		parent.$('#frameContainer').attr('rows','85,*');		
		parent.$('#frameContainer2').removeAttr('cols');
		parent.$('#frameContainer2').attr('cols','25%,*');
		$('#arvore').focus();
	}
	
	
	/*var pageSize = getPageSize();
	
	var resize = pageSize[3] - 95;
	//alert(resize);
	$('#container').css({height:''+(pageSize[3] - 2)+'px'});
	$('#Content').css({height:''+resize+'px'});
	$('#menuLeft').css({height:''+(resize - 10)+'px'});
	$('#conteudoFrame').css({height:''+(resize - 5)+'px'});*/
}




var Window =
{
	
	'_open': function(div,W,H) 
	{
	
	
	$('#'+div).width(W)
	$('#'+div).height(H);
	$('#'+div).show('normal');
	
	var pageSize = getPageSize();
	
	var objScroll = getPageScroll();
	
	
	var winW = pageSize[0];
	var winY = pageSize[1];
	
	//menos a largura da div
	var w = (winW - W) / 2;
	 //menos a altura da div
	var y = (winY - H) / 2;
	
	//alert(w);
	//alert(y);
	
	
	document.getElementById(div).style.left = w + 'px';
	document.getElementById(div).style.top = y + 'px';
	//y = 10 + objScroll[1];
	
	/*if (W > 600)
		do*cument.getElementById(div).style.top = 30 + 'px';
	else
		document.getElementById(div).style.top = y + 'px';*/
	
	},
	
	'_close': function(div)
	{
		$('#'+div).hide('normal');
		$('#'+div).empty();
		$.unblockUI();
	}
}




/*********** EFEITO TABELA *************************/


var Common = {
	'color': function(obj,tipo)
	{			
		switch(tipo)
		{
			case 'over':$(obj).css({background:'#eeeeee'});	
			break;
			case 'out':$(obj).css({background:'#ffffff'});	
			break;

		}			
	},
	
	// ID = id do que se quer escluir
	// URL = pagina que sera feita a exclusao
	//MSG = se quiser definir mensagem especial para exclusao
	'Deleta': function(URL,MSG)
	{
		if (MSG == "" || MSG == null)
			MSG = "Tem certeza que deseja excluir ?";
			
	   if(confirm(MSG))
	   document.location = URL;
	}
}


var Valida = {
	
	'fNovoFolder': function()
	{
		if ($('#fNovoFolder #nome').val() == "")
		{
			alert('Você tem que digitar um nome!');
			$('#fNovoFolder #nome').focus();
			return false;		
		}		
	},
	
	'fNovoArquivo': function()
	{
		if($("#id_arquivo").val() == "")
		{		
			if ($('#fNovoArquivo #file').val() == "")
			{
				alert('Você deve escolher um arquivo em sua maquina para fazer upload!');
				$('#fNovoArquivo #file').focus();
				return false;		
			}
		}
		
		if ($("#novo_Nome:checked").length > 0)
		{			
			if ($('#fNovoArquivo #nome').val() == "")
			{
				alert('Você tem que digitar um nome!');
				$('#fNovoArquivo #nome').focus();
				return false;		
			}			
		}
	},
	
	'fNovoLink': function()
	{
		if ($('#fNovoLink #nome').val() == "")
		{
			alert('Você tem que digitar um nome!');
			$('#fNovoLink #nome').focus();
			return false;		
		}
		
		if ($('#fNovoLink #url').val() == "" || $('#fNovoLink #url').val() == "http://")
		{
			alert('Você tem que digitar uma url!');
			$('#fNovoLink #nome').focus();
			return false;		
		}
	}

}


function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}


/*************** FORMULARIO **************************/
var Usuario = {
	
	'validaMeuCadastro': function() {
		
		if ($('#nome').val() == "")
		{
			alert("Digite seu nome! ");	
			$('#nome').focus();
			return false;
		}
		
		if ($('#login').val() == "")
		{
			alert("Digite um login para acesso! ");	
			$('#login').focus();
			return false;
		}
		
		if ($('#password').val() != "" && $('#password').val().length < 4)
		{
			alert("Digite uma senha com no mínimo 4 caracteres! ");
			$('#password').focus();
			return false;
		}
		
		if ($('#password').val() != $('#confirmaSenha').val())
		{
			alert("A senha de confirmação precisa ser igual a digitada no campo senha! ");	
			$('#confirmaSenha').focus();
			return false;
		}
		
	},
	
	'Valida': function(){
		
		//Valida formulario de cadastro modo admin
		var intra = document.getElementById('intranet').checked;
		var gerproj = document.getElementById('gerproj').checked;
		
		if (intra == false && gerproj == false)
		{
			alert("Escolha pelo menos um diretório! ");	
			document.getElementById('intranet').focus;
			return false;
		}
		
		if ($('#nome').val() == "")
		{
			alert("Digite um nome! ");	
			$('#nome').focus();
			return false;
		}
		
		if ($('#id_perfil').val() == 0)
		{
			alert("Escolha um perfil! ");	
			$('#id_perfil').focus();
			return false;
		}
		
		if ($('#login').val() == "")
		{
			alert("Digite um login para acesso! ");	
			$('#login').focus();
			return false;
		}
		
		if ($('#id_usuario').val() == "" && $('#password').val() == "")
		{
			alert("Digite uma senha com no mínimo 4 caracteres! ");	
			$('#password').focus();
			return false;
		}
		
		if ($('#password').val().length > 0 && $('#password').val().length < 4)
		{
			alert("Digite uma senha com no mínimo 4 caracteres! ");	
			$('#password').focus();
			return false;
		}
		
		if ($('#password').val() != $('#confirmaSenha').val())
		{
			alert("A senha de confirmação deve ser a mesma da senha! ");	
			$('#confirmaSenha').focus();
			return false;
		}
		
	},
	
	//Valida formulario de cadastro modo convite
	'Valida2': function(){
		
		if ($('#nome').val() == "")
		{
			alert("Digite um nome! ");	
			$('#nome').focus();
			return false;
		}
		
		if ($('#login').val() == "")
		{
			alert("Digite um login para acesso! ");	
			$('#login').focus();
			return false;
		}
		
		if($('#email').val() == "" || document.getElementById('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
		{
			alert('Você precisa digitar um endereço de e-mail válido! ')
			$('#email').focus();
			return false;
		}
		
		if ($('#password').val() == "")
		{
			alert("Digite uma senha com no mínimo 4 caracteres! ");	
			$('#password').focus();
			return false;
		}
		
		if ($('#password').val().length > 0 && $('#password').val().length < 4)
		{
			alert("Digite uma senha com no mínimo 4 caracteres! ");	
			$('#password').focus();
			return false;
		}
		
		if ($('#password').val() != $('#confirmaSenha').val())
		{
			alert("A senha de confirmação deve ser a mesma da senha! ");	
			$('#confirmaSenha').focus();
			return false;
		}
	},
	
	//Valida formulario de cadastro modo convite
	'Valida3': function(){
		
		if ($('#nome').val() == "")
		{
			alert("Digite um nome! ");	
			$('#nome').focus();
			return false;
		}
		
		if($('#email').val() == "" || document.getElementById('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
		{
			alert('Você precisa digitar um endereço de e-mail válido! ')
			$('#email').focus();
			return false;
		}
	}
}
