// GLOBAL JAVASCRIPT
var last = "";
var intervalId;

// OPEN WINDOW FOR DOWNLOAD
function getFile(scr)
{
window.open(scr)
}
// TABLE LIST ROW EFECT
function trOvr(src,clrtrOvr) {if (!src.contains(event.fromElement))  {src.bgColor = clrtrOvr;src.style.cursor = 'hand';}}
function trOut(src,clrIn)   {if (!src.contains(event.toElement))    {src.style.cursor = 'default'; src.bgColor = clrIn;}}

// HELP SYSTEM

function setLyr(obj)
{

	var lyr = "ajuda";

	if ( document.getElementById('imaajuda').name  == "on" )
	{
		document.getElementById('imaajuda').src = "_img/content/ajuda.gif";
		document.getElementById('imaajuda').name = "off";
		document.getElementById('ajuda').style.visibility = "hidden";
	   	document.getElementById('ajudaseta').style.visibility = "hidden";
		document.getElementById('imaajuda').alt = "Clique aqui para visualizar a Ajuda";
		return;
	}
	else if ( document.getElementById('imaajuda').name  == "off" )
	{
		document.getElementById('ajuda').style.visibility = "visible";
		document.getElementById('ajudaseta').style.visibility = "visible";
		document.getElementById('imaajuda').name = "on";
		document.getElementById('imaajuda').src = "_img/content/ajudaon.gif";
		document.getElementById('imaajuda').alt = "Clique aqui para esconder a Ajuda";

		//var divHeight = 400;
		//var divWidth = 100;
		var newX = findPosX(obj);
		var newY = findPosY(obj);
		var x = new getObj(lyr);
		var xBro;
		if(navigator.appName == "Netscape")
		{
			xBro = 666
		}
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			xBro = 660
		}
		x.style.top = newY -70+ 'px';
		x.style.left = newX -xBro+ 'px';// FIREFOX -416
		document.getElementById('ajudaseta').style.top = newY + 'px';
		document.getElementById('ajudaseta').style.left = newX-11 + 'px';
	}

}
var PM = new Array() ;


function clear(obj)
{

	
	if(PM[0]== intervalId)
	{
	      document.getElementById(obj).src = "_img/content/info_doc.gif";
	      document.getElementById(obj).name = "detalhesoff";
	      document.getElementById('detalhesDiv').style.visibility = "hidden";
	      document.getElementById('detalhesSeta').style.visibility = "hidden";
	      window.clearInterval(intervalId);
	      
        }
	window.clearInterval(PM[0]);
        PM.shift();
	//intervalId = "";
	//last = "";
	
}

function setLyrDetalhes(obj)
{
	
	//window.clearInterval(intervalId);
	var lyr = "detalhesDiv";
	//alert (document.getElementById(obj.id).name);
	//alert(last);

	if ( last != "" )
	{
		if ( last == document.getElementById(obj.id).id )
		{
			if ( document.getElementById(obj.id).name == "detalheson" )
 			{
				document.getElementById(last).name = "detalheson";
			}
		}
		else
		{
			document.getElementById(last).name = "detalhesoff";
		}
		document.getElementById(last).src = "_img/content/info_doc.gif";
		
		//document.getElementById(last).id = obj.id;
	}

	if ( document.getElementById(obj.id).name  == "detalheson" )
	{
		
		document.getElementById(obj.id).src = "_img/content/info_doc.gif";
		document.getElementById(obj.id).name = "detalhesoff";
		document.getElementById('detalhesDiv').style.visibility = "hidden";
	   	document.getElementById('detalhesSeta').style.visibility = "hidden";
		//last = "";
		//document.getElementById('imaajuda').alt = "Clique aqui para visualizar a Ajuda";
		return;
	}
	else if ( document.getElementById(obj.id).name  == "detalhesoff" )
	{
		
		document.getElementById('detalhesDiv').style.visibility = "visible";
		document.getElementById('detalhesSeta').style.visibility = "visible";
		document.getElementById(obj.id).name = "detalheson";
		document.getElementById(obj.id).src = "_img/content/info_docsel.gif";
		//last = "";
		//alert ( obj.id );

		
		var divHeight = 400;
		var divWidth = 189;
		var newX = findPosX(obj);
		var newY = findPosY(obj);
		var x = new getObj(lyr);
	
		var xBro;
	
		if(navigator.appName == "Netscape")
		{
			xBro = 422;
		}
	
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			xBro = 416;
		}
		x.style.top = newY -70+ 'px';
		x.style.left = newX -xBro+ 'px';
		document.getElementById('detalhesSeta').style.top = newY - 5 + 'px';
		document.getElementById('detalhesSeta').style.left = newX-17 + 'px';
	
	}
	last = obj.id;
	intervalId = window.setInterval("clear(last)",20000);
	PM[PM.length] = intervalId;
	 
}



function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;

	return curtop;
}
function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}

function setRez()
{
	if ( document.getElementById('imaajuda') != undefined)
	{
		if ( document.getElementById('imaajuda').name  == "on" )
		{
			
			document.getElementById('imaajuda').src = "_img/content/ajuda.gif";
			document.getElementById('imaajuda').name = "off";
			document.getElementById('ajuda').style.visibility = "hidden";
			document.getElementById('ajudaseta').style.visibility = "hidden";
			document.getElementById('imaajuda').alt = "Clique aqui para visualizar a Ajuda";
		
   			return;
		}
	}
}
	window.onresize = setRez; 

/*----------------------------------------*/
   var xmlhttp=false;

    try {
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
          try {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) {
                       xmlhttp = false;
            }
    }

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
    {
       xmlhttp = new XMLHttpRequest();
    }
    
    //cache de caracteristicas
    var old_id=0;
    var old_content='';
    
    function makeRequest(id)
    {


		//if(id==old_id)
		//{
		//	ttip(old_content,'', 650);
		//}
		//else
		//{

			xmlhttp.open("GET", "../../home/ui/help.aspx?ID="+id,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
						old_content = xmlhttp.responseText;
						old_id=id;
						ttip(xmlhttp.responseText,'', 650);
					}
				}
			xmlhttp.send(null)
       //}
       
    }
    
function makeRequestDetalhes(id)
{

	if ( document.getElementById('detalhesDiv').style.visibility == "hidden")
	{
		return;
	}

	if(id==old_id)
	{
		ttip(old_content,'', 400);
	}
	else
	{

		xmlhttp.open("GET", "../../documentos/ui/detalhesdocumentoui.aspx?ID="+id,true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				old_content = xmlhttp.responseText;
				old_id=id;
				ttipDetalhes(xmlhttp.responseText,'', 400);
			}
		}
		xmlhttp.send(null)
       }
       
}
    


	function ttipDetalhes(thetext, thecolor, thewidth){

		var ie=document.all
		var ns6=document.getElementById && !document.all
		var enabletip1=false
		if (ie||ns6)
		var tipobj=document.all? document.all["detalhesDiv"] : document.getElementById? document.getElementById("detalhesDiv") : ''

		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
		tipobj.innerHTML = thetext;
		//tipobj.style.visibility = 'visible';
		enabletip1=true;
		return false;
	
}

    //TOOLTIP
	function ttip(thetext, thecolor, thewidth){

		var ie=document.all
		var ns6=document.getElementById && !document.all
		var enabletip=false
		if (ie||ns6)
		var tipobj=document.all? document.all["ajuda"] : document.getElementById? document.getElementById("ajuda") : ''

		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
		tipobj.innerHTML = thetext;
		//tipobj.style.visibility = 'visible';
		enabletip=true;
		return false;
	
	}


// JANELA DE PARTICIPANTES

function hasOptions(obj){if(obj!=null && obj.options!=null){return true;}return false;}
function selectUnselectMatchingOptions(obj,regex,which,only){if(window.RegExp){if(which == "select"){var selected1=true;var selected2=false;}else if(which == "unselect"){var selected1=false;var selected2=true;}else{return;}var re = new RegExp(regex);if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){if(re.test(obj.options[i].text)){obj.options[i].selected = selected1;}else{if(only == true){obj.options[i].selected = selected2;}}}}}
function selectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",false);}
function selectOnlyMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",true);}
function unSelectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"unselect",false);}
function sortSelect(obj){var o = new Array();if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;}if(o.length==0){return;}o = o.sort(
function(a,b){if((a.text+"") <(b.text+"")){return -1;}if((a.text+"") >(b.text+"")){return 1;}return 0;});for(var i=0;i<o.length;i++){obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);}}
function selectAllOptions(obj){if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){obj.options[i].selected = true;}}
function moveSelectedOptions(from,to){if(arguments.length>3){var regex = arguments[3];if(regex != ""){unSelectMatchingOptions(from,regex);}}if(!hasOptions(from)){return;}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){if(!hasOptions(to)){var index = 0;}else{var index=to.options.length;}to.options[index] = new Option( o.text, o.value, false, false);}}for(var i=(from.options.length-1);i>=0;i--){var o = from.options[i];if(o.selected){from.options[i] = null;}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(from);sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}
function copySelectedOptions(from,to){var options = new Object();if(hasOptions(to)){for(var i=0;i<to.options.length;i++){options[to.options[i].value] = to.options[i].text;}}if(!hasOptions(from)){return;}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){if(options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text){if(!hasOptions(to)){var index = 0;}else{var index=to.options.length;}to.options[index] = new Option( o.text, o.value, false, false);}}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}
function moveAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){moveSelectedOptions(from,to);}else if(arguments.length==3){moveSelectedOptions(from,to,arguments[2]);}else if(arguments.length==4){moveSelectedOptions(from,to,arguments[2],arguments[3]);}}
function copyAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){copySelectedOptions(from,to);}else if(arguments.length==3){copySelectedOptions(from,to,arguments[2]);}}
function swapOptions(obj,i,j){var o = obj.options;var i_selected = o[i].selected;var j_selected = o[j].selected;var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);o[i] = temp2;o[j] = temp;o[i].selected = j_selected;o[j].selected = i_selected;}
function moveOptionUp(obj){if(!hasOptions(obj)){return;}for(i=0;i<obj.options.length;i++){if(obj.options[i].selected){if(i != 0 && !obj.options[i-1].selected){swapOptions(obj,i,i-1);obj.options[i-1].selected = true;}}}}
function moveOptionDown(obj){if(!hasOptions(obj)){return;}for(i=obj.options.length-1;i>=0;i--){if(obj.options[i].selected){if(i !=(obj.options.length-1) && ! obj.options[i+1].selected){swapOptions(obj,i,i+1);obj.options[i+1].selected = true;}}}}
function removeSelectedOptions(from){if(!hasOptions(from)){return;}if(from.type=="select-one"){from.options[from.selectedIndex] = null;}else{for(var i=(from.options.length-1);i>=0;i--){var o=from.options[i];if(o.selected){from.options[i] = null;}}}from.selectedIndex = -1;}
function removeAllOptions(from){if(!hasOptions(from)){return;}for(var i=(from.options.length-1);i>=0;i--){from.options[i] = null;}from.selectedIndex = -1;}
function addOption(obj,text,value,selected){if(obj!=null && obj.options!=null){obj.options[obj.options.length] = new Option(text, value, false, selected);}}


