
/* Script called from the TestDirectory pages. */
var TD_Recid = null;
var TD_mnemonic = null;

/// Called via AJAX to display the Test Directory details of a single (test) selection. Caller
/// may provide a mnemonic, recid, or both. Known areas that do NOT yet provide a recid are those
/// hard-coded book icons (i.e. AP tests).
function ShowTestDetail( e, bShow, mnemonic, recid )
{	
    var agt = navigator.userAgent.toLowerCase();

    //Cancel the tr onclick event. 
    //(so submit buttons, such as ImageButton, will not postback twice)
    if( agt.indexOf("ie") > -1 ) { //IE			    
	    e.cancelBubble = true;
    }
    else { //Mozilla			    
	    e.stopPropagation();
    }

    var tdTestDetails = document.getElementById('tdTestDetails');
    
    var divTestDetailX = null;
    
    if( recid != null && recid != '' ) {
        TD_Recid = recid;
        divTestDetailX = document.getElementById('divTestDetail'+recid);
    }
    else if( mnemonic != null && mnemonic != '' ) {
        TD_mnemonic = mnemonic;
        divTestDetailX = document.getElementById('divTestDetail'+mnemonic);
    } 
        
    if( divTestDetailX != null ) { // already filled this list
    	
        if( bShow != null && bShow == true ) {
            tdTestDetails.innerHTML = divTestDetailX.innerHTML;
            OpenPopup('tblTestDetails', 'tdTestDetails');		                
        }
        else {			
            window.scroll(0,0);
            tdTestDetails.innerHTML = '';
        }

        return false;
    }
    else {	// make an AJAX call...
    
        var xmlHttp = GetXmlHttpObject();

        if (xmlHttp == null) {
            //alert ("Your browser does not support AJAX!");
            return false;
        } 

        showHideLoadingCover( true, 'Loading test detail...' );
    
        // call to the server.
        var url="secure.aspx?fn=AJAXTestDirectoryDetail";
        
        if( recid != null && recid != '' ) {
            url += "&recid="+recid;
        }
        else if( mnemonic != null && mnemonic != '' ) {
            url += "&testcode="+mnemonic;
        } 

        xmlHttp.open("POST", url, true); // use POST b/c IE caches calls to the server!!!
        xmlHttp.onreadystatechange = function() {
            if ( xmlHttp.readyState == 4 ) {	    
                var sHTML = ''; // <div ...><table .../>...</div>
                showHideLoadingCover(false);
    	    
                sHTML = xmlHttp.responseText; // from the svc call...

                xmlHttp = null;

                var div = document.createElement('div'); // temp placeholder
                div.innerHTML = sHTML; // add our HTML elements so we can parse below
                divTestDetailX = div.getElementsByTagName('div')[0];
    	        
                var divTestDetail = document.getElementById('divTestDetail');
                divTestDetail.appendChild(divTestDetailX);
                       	
                if( bShow != null && bShow == true ) {
	                tdTestDetails.innerHTML = divTestDetailX.innerHTML;
                    OpenPopup('tblTestDetails', 'tdTestDetails');		                
                }
                else {			
	                window.scroll(0,0);
	                tdTestDetails.innerHTML = '';
                }
           }
        };
        
        xmlHttp.setRequestHeader("Content-Type", "text/xml");
        xmlHttp.setRequestHeader("Cache-Control", "No-Cache");
        xmlHttp.send('');
   }
}

/// Called via AJAX to print the Test Directory details of a single (test) selection. Caller
/// may provide a mnemonic, recid, or both. Known areas that do NOT yet provide a recid are those
/// hard-coded book icons (i.e. AP tests).
function PrintTestDetail( recid )
{
    ClosePopup('tblTestDetails', 'tdTestDetails'); 
    showHideLoadingCover( true, 'Please Wait...' ); 
    setTimeout("showHideLoadingCover( false ); OpenPopup('tblTestDetails', 'tdTestDetails');", 3000); 
    
    var url="print/PrintNoImage.aspx";
    if( recid != null && recid != '' ) {
        url += "?recid="+recid;
    }
    else if( TD_mnemonic != null && TD_mnemonic != '' ) {
        url += "?testcode="+TD_mnemonic;
    }        
    
    var w = window.open(url);
    w.focus();
}
