﻿// JScript File

// To show the hand cursor when the mouse is over a label
function onMouseOver_Label( ctl )
{
	ctl.className = 'cursor_hand';
}

// To show the defaul cursor when the mouse is out of a label
function onMouseOut_Label( ctl )
{
	ctl.className = 'cursor_default';
}

// When the user clicks on the print roster button, a new table row will be displayed that contains three buttons
function ShowMainSubTR( showMain )
{
	try
	{
		var vtrMain, vtrSub;
		vtrMain = document.getElementById( 'trMain' );
		vtrSub = document.getElementById( 'trSub' );
		
		if( showMain )
		{
			vtrMain.style.display = "block";
			vtrSub.style.display = "none";
		}
		else
		{
			vtrMain.style.display = "none";
			vtrSub.style.display = "block";
		}
		
	}
	catch( ex )
	{
		alert( ex.message );
	}
}

// HabeebS 08.14.2007
function Login_LoginTextChanged( clientID )
{
	try
	{
		var vlblMessage, vlblHintStatus;
		vlblMessage = document.getElementById( clientID + '_lblMessage' );
		vlblHintStatus = document.getElementById( clientID + '_lblHintStatus' );
		
		if( vlblMessage != null )
			vlblMessage.innerHTML = '';
		
		if( vlblHintStatus != null )
			vlblHintStatus.innerHTML = '';
	}
	catch( ex )
	{
		alert( ex.message );
	}
}

// autoPrint: Flag for whether or not to automatically call the print function 
function printSpecial( autoPrint )
{
	try
	{
		if ( document.getElementById != null )
		{
			var html = '<html>\n<head>\n'; 
			if ( document.getElementsByTagName != null )
			{
				var headTags = document.getElementsByTagName( "head" ); 
				if ( headTags.length > 0 )
				{
					html += headTags[ 0 ].innerHTML;
				}
			}
			if ( autoPrint )
			{
				if ( navigator.appName == "Microsoft Internet Explorer" )
				{
					html += '\n</head>\n<body onLoad="PrintCommandObject.ExecWB( 6, -1 );">\n'; 
				}
				else
				{
					html += '\n</head>\n<body>\n'; 
				}
			}
			else
			{
				html += '\n</head>\n<body>\n'; 
			}

			var printReadyElem = document.getElementById( "printReady" ); 
			if ( printReadyElem != null )
			{
				html += printReadyElem.innerHTML; 
			}
			else
			{
				alert( "Could not find the printReady section in the HTML" ); 
				return; 
			}
			
			if ( autoPrint )
			{
				if ( navigator.appName == "Microsoft Internet Explorer" )
				{
					html += '<object ID="PrintCommandObject" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>\n</body>\n</html>';
				}
				else
				{
					html += '\n</body>\n</html>'; 
				}
			}
			else
			{
				html += '\n</body>\n</html>'; 
			}
			var printWin = window.open( "","printSpecial" ); 
			printWin.document.open(); 
			printWin.document.write( html ); 
			printWin.document.close();
			if ( autoPrint )
			{
				if ( navigator.appName != "Microsoft Internet Explorer" )
				{
					printWin.print(); 
				}
			}
		}
		else
		{
			alert( "Sorry, the print ready feature is only available in modern browsers." );
		}
	}
	catch( ex )
	{
		alert( ex.message );
	}
}

// To check if the user checked any of the item in the checkbox list
function AtLeastOneItemSelected( controlName, alertText )
{
	try
	{
		var vchklCheckBoxList, blnOneSelected;
		blnOneSelected = false;
		vchklCheckBoxList = document.getElementById( controlName );
		
		for( counter = 0 ; counter < vchklCheckBoxList.children( 0 ).children.length ; counter++ )
		{
			if( vchklCheckBoxList.children( 0 ).children( counter ).children( 0 ).children( 0 ).checked )
			{
				blnOneSelected = true;
				break;
			}
		}
		
		if( !blnOneSelected )
			alert( "Select one " + alertText + " at least!" );
		
		return blnOneSelected;
	}
	catch( ex )
	{
		alert( ex.message );
	}
}

//// HabeebS 08.29.2007
//function ccSelectAllCheckBox_CheckChanged( control, controlName )
//{
//	try
//	{
//		var vCtrl;
//		vCtrl = document.getElementById( controlName );
//		
//		var blnCheck;
//		blnCheck = control.checked;
//		
//		if( vCtrl == null )
//			return;
//		
//		for( counter = 0 ; counter < vCtrl.children( 0 ).children.length ; counter++ )
//			vCtrl.children( 0 ).children( counter ).children (0 ).children( 0 ).checked = blnCheck;
//	
//		if( blnCheck )
//			control.parentElement.children(1).innerHTML = 'Remove All';
//		else
//			control.parentElement.children(1).innerHTML = 'Select All';
//	}
//	catch( ex )
//	{
//		alert( ex.message );
//	}
//}


function SetSessionRequirementsToHiddenField( controlName, hiddenFieldName )
{
	// Author		: Habeeb Sweis
	// Date			: Sep 17, 2007
	// Purpose	: This function saves the session and the selected requirements as a comma separated ( per requirement ) and a 
	//		semi colon separated ( per session ) string in a hidden field so that it can be read from te CodeFile
	
	// Description: This function has two loops, one for the rows ( sessions ) and the inner one is for the cells ( requirements ).
	//		The outer loop, for each row it first reads the productID from the "ProductID" attribute that was added to each
	//		session (HtmlTableRow) and adds it to adds the sessionRequirements variables which is reset per session.
	//		Then it loops through the requirements (HtmlTableCells) and is the check box is checked, it adds the SubCode to the string

	try
	{
		// Get the HtmlTable controls that contains all the session rows
		var table = document.getElementById( controlName );
		
		// Declare the current HtmlTableRow that will hold the current row
		var tableRow;
		
		// This variable will be set to true if at least one of the requirements is selected for each session
		var atLeastOneIsSelected;
		
		
		// Get the hidden field control to save the product id along with the selected requirements
		// comma separated within the session and semi colon separated for each session
		var hidden = document.getElementById( hiddenFieldName );
		
		// Declare the variables that will hold the session requirements and the all the sessions requirements values
		var sessionRequirements = "", allSessionsRequirements = "";
		
		// Loop through all the row ( Sessions )
		for( counter = 1 ; counter < table.children( 0 ).children.length ; counter++ )
		{
			// Reset the sessionRequirements variable
			sessionRequirements = "";
			
			// Get the current row ( Session )
			tableRow = table.children( 0 ).children( counter );
			
			// Add the productID to the sessionRequirements variable
			sessionRequirements += tableRow.attributes( "ProductID" ).value;
			
			// Set the at least one is selected to false
			atLeastOneIsSelected = false;
			
			// Loop through all the Equipment Requirement CheckBoxes ( which start from the fourth tablecell )
			for( counter2 = 3 ; counter2 < tableRow.children.length ; counter2++ )
			{
				if( tableRow.children( counter2 ).children(0).children( 0 ).checked )
				{
					atLeastOneIsSelected = true;
					sessionRequirements += "," + tableRow.children( counter2 ).children( 0 ).attributes( "SubCode" ).value;
				}
			}
			
			if( !atLeastOneIsSelected )
			{
				alert( "If you don't want any requirements, please select the 'No AV Equipment Needed' ." );
				return false;
			}
			// Add the sessionRequirements to the allSessionsRequirements
			allSessionsRequirements += sessionRequirements + ";";
		}
		
		// Save the in the hidden field so that it can be read from the code behind file
		hidden.value = allSessionsRequirements.substr( 0 , allSessionsRequirements.length - 1 );
		
		return true;
	}
	catch( ex )
	{
		alert( ex.message );
	}
}

function ValidateCheckedValues( ctrl , isChecked )
{
	// Author		: Habeeb Sweis
	// Date			: Sep 18, 2007
	// Purpose	: This function is called when the user clicks on any checkbox in the equipment requirements table
	//		If the user clicks on the "No AV Equipment Requirement" checkbox it clears all the check boxes for that session, 
	//		but if the user checked any other requirement, it removes the check from the "No AV Equipment Requirement" checkbox
	
	try
	{
		if( ctrl.parentElement.attributes("SubCode").value == "NONE" )
		{
			if( isChecked )
			{
				for( counter = 3 ; counter < ctrl.parentElement.parentElement.parentElement.children.length ; counter++ )
				{
					ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).children( 0 ).checked = false;
				}
				ctrl.checked = true;
			}
		}
		else
		{
			if( isChecked )
			{
				for( counter = 3 ; counter < ctrl.parentElement.parentElement.parentElement.children.length ; counter++ )
				{
					if( ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).attributes("SubCode").value == "NONE" )
					{
						ctrl.parentElement.parentElement.parentElement.children( counter ).children( 0 ).children( 0 ).checked = false;
					}
				}
			}		
		}
	}
	catch( ex )
	{
		alert( ex.message );
	}
}

function HighlightSelection( ctrlName )
{
    try
    {
        var ctrl = document.getElementById( ctrlName );
        if( ctrl == null )
            return;
            
        for( counter = 0 ; counter < ctrl.children( 0 ).children.length ; counter++ )
        {
            if( !ctrl.children( 0 ).children( counter ).children( 0 ).children(0).checked )
                ctrl.children( 0 ).children( counter ).children( 0 ).children( 1 ).style.fontWeight = "";
            else
                ctrl.children( 0 ).children( counter ).children( 0 ).children( 1 ).style.fontWeight = "bold";
        }
        
    }
    catch( ex )
    {
    }
}
//added by May Wang 11/04/2008
function poponload(url)
{
testwindow= window.open(url, "mywindow","location=1,status=1,scrollbars=1,width=400,height=300");

testwindow.moveTo(0,0);
}
function SetVisibility(thePanel,otherPanel)
    {
   
        var panel = document.getElementById(thePanel);
        var nopanel=document.getElementById(otherPanel);
        if(panel.style.visibility == 'hidden')
        {
            panel.style.visibility = 'visible';
            nopanel.style.visibility= 'hidden';
        }
        else
        {
            panel.style.visibility = 'visible';
            nopanel.style.visibility= 'hidden';
        }
    }
function wopen(url,w,h)
    {
        var mywin = window.open(url,'newwin','height=' + h + ',width=' + w + ',location=no,status=no,toolbar=no,scrollbars=no,resizable=yes'); 
        mywin.focus();
    }
    
function hidestatus()
{

    var statusmsg=""
    window.status=statusmsg
    return true
}
//End added by May Wang 11/04/2008