﻿var setTimeout_variable;

var ExecMenuDropDown = function (){
 	
	if (document.getElementById("menu_dropdown")) {
		var navItems = document.getElementById("menu_dropdown").getElementsByTagName("li");
		for (var i = 0; i < navItems.length; i++) {
			if ((navItems[i].className == "submenu" || navItems[i].className == "selected") && navItems[i].getElementsByTagName('ul')[0] != null) {
				navItems[i].onmouseover = function(){
					this.getElementsByTagName('ul')[0].style.display = "block";
					this.style.backgroundColor = "#FFF";
					this.style.border = "1px solid #9DD07B";
				}
				
				navItems[i].onmouseout = function(){
					this.getElementsByTagName('ul')[0].style.display = "none";
					this.style.backgroundColor = "#FFF";
					this.style.border = "1px solid #FFF";
				}
			}
		}
	}
}
 
 
window.onload = function (){
	ExecMenuDropDown();
	//if(document.getElementById('ctl00_MainContent_btnAddGroup'))
	//    document.getElementById('ctl00_MainContent_btnAddGroup').onclick = function() { Log('NewGr', 'btAddGr', 'alfabetaNewGr'); };
	//if(document.getElementById('ctl00_MainContent_btnAddUser'))
	//    document.getElementById('ctl00_MainContent_btnAddUser').onclick = function() { Log('NewUsr', 'btAddUser', 'alfabetaNewUsr'); };
} 
 
var SizeScreenCapture = function() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function ShowSuccess(message)
{
    div = document.getElementById("SuccessOperation");
    span = document.getElementById("lblMessage");
    img = document.getElementById("imgSuccess");

    img.src = "../../Resources/modalpopup/success.jpg";
    
    span.innerHTML = message;
    
    Show("SuccessOperation");
    setTimeout("Hide('SuccessOperation');", 3000);
}

function ShowError(message) {
    div = document.getElementById("SuccessOperation");
    span = document.getElementById("lblMessage");
    img = document.getElementById("imgSuccess");

    img.src = "../../Resources/modalpopup/error.jpg";

    span.innerHTML = message;

    Show("SuccessOperation");
    setTimeout("Hide('SuccessOperation');", 5000);
}

function Show(obj)
{
    document.getElementById(obj).style.display = "inline";
}

function Hide(obj)
{
    document.getElementById(obj).style.display = "none";
    document.getElementById(obj).style.visibility= "hidden";
}

function ShowHide(image, obj, expandText, collapseText)
{
    div = document.getElementById(obj);
    img = document.getElementById(image);
    
    if(div.style.display == "none")
    {
        div.style.display = "inline";
        img.src = img.src.substring(0, img.src.lastIndexOf("/") + 1)  + "collapse.jpg";
        img.title = collapseText;
    }
    else
    {
        div.style.display = "none";
        img.src = img.src.substring(0, img.src.lastIndexOf("/") + 1)  + "expand.jpg";
        img.title = expandText;
    }
}

function ShowHideGeneric(targetId) {
    target = document.getElementById(targetId);

    if (target.style.display == "none")
        target.style.display = "inline";
    else 
        target.style.display = "none";
}

// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y+ 'px';
    top.style.left = (location.x + 20) + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

function DegubModeRegister(eventProcess, initProcessDateTime, endProcessDateTime, totalProcessTime)
{
    try 
    {
        divEvent =  parent.frames[0].document.getElementById("pnObjectType");
        divInit =  parent.frames[0].document.getElementById("pnStartReqProc");
        divEnd =  parent.frames[0].document.getElementById("pnEndReqProc");
        divTotal =  parent.frames[0].document.getElementById("pnTotalTime");
        
        if((initProcessDateTime != "1/1/0001 00:00:00") && (endProcessDateTime != "1/1/0001 00:00:00") && (totalProcessTime != "00:00:00"))
        {
            divEvent.innerHTML += eventProcess + "<br>";
            divInit.innerHTML += initProcessDateTime + "<br>";
            divEnd.innerHTML += endProcessDateTime + "<br>";
            divTotal.innerHTML += totalProcessTime + "<br>";
        }
    }
    catch(e) 
    { }
}

function EnableApplyByTxt(txtName, type) 
{
    clearTimeout(setTimeout_variable);
    setTimeout_variable = setTimeout("EnableApply('" + type + "');FocusById('" + txtName + "');", 2000);
}

function FocusById(id) 
{
    txt = document.getElementById(id);
    txt.focus();
}

function EnableApply(type) 
{
    btn = document.getElementById("ctl00_MainContent_btnApply");
    txt = document.getElementById("ctl00_MainContent_hiddenHasChanges");
    
    btn.disabled = "";
    btn.className = "ButtonClassOk";
    txt.value = type;
}

function HideLoading() 
{
    div = document.getElementById('divLoading');
    div.style.display = "none";
}

function ShowLoading() 
{
    div = document.getElementById('divLoading');
  
    div.style.display = "inline";
}

function cvPassword(source, args) {
    if (args.Value.length >= 6) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

function cvCity(source, args) {
    if (args.Value.length >= 3) {
        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}


function Log(tarefa, evento, atividade) 
{
    //alert("Registrou tarefa: " + tarefa + "  Evento: " + evento + "  Atividade: " + atividade );
    try 
    {
        //usemonitor_log('www.usemonitor.com', 'Interage', 'Trevio', tarefa, atividade, evento);
    }
    catch (e) 
    {
        //alert("USEMONITOR ERRO: "+ e);
    }
   
}
