var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var menuToClose = null;

function InitializeTimer(subMenu)
{
    // Set the length of the timer, in seconds
    secs = 2;
    StopTheClock();
    StartTheTimer();
    menuToClose = subMenu;
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        menuToClose.className = "hidemenu";
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

function GetSection(SectionId)
{
	hdSection = document.getElementById("hdSection");
	
	hdSection.value = SectionId;
	
	__doPostBack('lnkSetSection','');
	//window.location.replace("");
}

function CallWindowDialog(url,width,height)
{
	//window.showModalDialog(url,"","dialogWidth:" + width + "px;dialogHeight:" + height + "px;scroll:no; status:no")
	var features = "width="+width+"px;height="+height+"px;center=yes;help=no;status=no;resizable=no;";
	var popupArgs = true;
	window.open(url,popupArgs,features)
	
	return popupArgs;	
}

function CallModalDialog(url,width,height)
{
	//window.showModalDialog(url,"","dialogWidth:" + width + "px;dialogHeight:" + height + "px;scroll:no; status:no")
	var features = "dialogWidth="+width+"px;dialogHeight="+height+"px;center=yes;help=no;status=no;resizable=no;";
	var popupArgs = true;
	window.showModalDialog(url,popupArgs,features);
	
	return popupArgs;	
}

function menuRollOver(img, subMenu)
{
	var strReplace;
	var oSubMenu = document.getElementById(subMenu);
	
	if(img.src.indexOf("out") > -1)
	{
		strReplace = img.src.replace("out","over");
		
		if(oSubMenu != null)
		{
			oSubMenu.className = "showmenu";
		}
		
		if(menuToClose != null && oSubMenu != menuToClose)
			menuToClose.className = "hidemenu";
	}
	else
	{
		strReplace = img.src.replace("over","out");
		
		if(oSubMenu != null)
			InitializeTimer(oSubMenu);
	}
		
	img.src = strReplace;
}

function SetSelectedClient(clientId, hdFieldName)
{
	var inField = document.getElementById(hdFieldName);
	inField.value = clientId;
	
	__doPostBack('_ctl0$_ctl0$Portfolio1$lnkSetClient','');
}

function SetSelectedItem(itemId, hdFieldName)
{
	var inField = document.getElementById(hdFieldName);
	inField.value = itemId;
	
	__doPostBack('_ctl0$_ctl0$Portfolio1$lnkSetSection','')
}

function ChangeTesti(TdTestiID, TdPagerID, oBtnTriggered, TestiID)
{
	oTesti = document.getElementById(TestiID);
	oTdTesti = document.getElementById(TdTestiID);
	oTdPager = document.getElementById(TdPagerID);
	
	var selectedIndex;
	
	for(i = 0; i < oTdTesti.childNodes.length; i++)
	{
		oTdTesti.childNodes[i].style.display = "none";
		
		if(i < 9)
			oBtnTriggered.parentNode.parentNode.cells[i].firstChild.className = "pager";
		else
			oBtnTriggered.parentNode.parentNode.cells[i].firstChild.className = "pagerPlus";
		
		if(oBtnTriggered.parentNode.parentNode.cells[i].firstChild == oBtnTriggered)
			selectedIndex = i;
	}

	
	if(selectedIndex < 9)
		oBtnTriggered.className = "pagerselected";
	else
	{
		oBtnTriggered.className = "pagerselectedPlus";
	}
		
	oTesti.style.display = "block";
}