/**
 * This javascript library serves as a helper module for displaying dyanmically
 * the dependent drill-downs for a selected catalog. The calls are made after placing 
 * AJAX request for fetching catalog meta-info and the screen wants to render 
 * the widgets accordingly.
 * 
 * @see catalog_navigation.jsp (admin)
 * @see catalog_navigation_cd.jsp (cd-website)
 * @since 1.50.0.1 (CAPP-Release)
 */

/**
 * Global variables used across for catalog navigation.
 */
insertIndex = 4;
siteType = 'admin';
textLink = '';
bullet = '&#8226;'+'&nbsp;';

function getBrowser()
{	var ua = navigator.userAgent.toLowerCase();
	if ( ua.indexOf( "opera" ) != -1 )
		return "opera";
	else if ( ua.indexOf( "msie" ) != -1 )
		return "msie";
	else if ( ua.indexOf( "safari" ) != -1 )
		return "safari";
	else if ( ua.indexOf( "mozilla" ) != -1 )
	{	if ( ua.indexOf( "firefox" ) != -1 )
			return "firefox";
		else
			return "mozilla";
	}
	return 'unknown';
}

function getClassAttribute()
{	var classTxt = 'class';
	var browserID = getBrowser();
	if(browserID.indexOf('msie')!=-1)
		classTxt = 'className';
    return classTxt;
}
/**
 * Call this function on window.onload to set index for insertion of catalog
 * drill-downs.
 * 
 * @since 1.50.0.1 (CAPP-Release)
 */
function setInsertIndex(indexToInsert)
{	insertIndex = indexToInsert;
}

function getInsertIndex()
{	return insertIndex;
}
/**
 * Call this function on window.onload to set what site this catalog navigation 
 * feature is being enabled for.
 * valid values - ['admin','cdreg','cdcreate','cdappt']
 * 
 * @since 1.50.0.1 (CAPP-Release)
 */
function setSiteType(typeOfSite)
{	siteType = typeOfSite;
}

/**
 * Call this function on window.onload to set/change text links for licenses displayed 
 * on the candidate site. Used only for candidate website
 * 
 * @since 1.50.0.1 (CAPP-Release)
 */
function setTextLink(linkForText)
{	textLink = linkForText;
}

/**
 * Removes and resets the previously selected and added rows.
 * 
 * @since 1.50.0.1 (CAPP-Release)
 */
function resetRows(selectedItem)
{	//Remove all the child hierarchical drop-downs for a previously selected value.
	var itemName = selectedItem.getAttribute("name");
	var remIndex = parseInt(itemName.substr(1,itemName.length))+1;
	if(insertIndex >= remIndex)
	{	removeRow('catalogNavigation',remIndex,insertIndex);
		if(siteType.indexOf('cdreg')!=-1)
			removeLicenseRows();
		if(siteType.indexOf('cdcreate')!=-1)
			hideIDTypeRows();
	}
	if(siteType.indexOf('cdappt')!=-1)
	{	if(insertIndex>=remIndex)
		{	removeLicenseRows();
			removePortionRows();
			displayCustMsgRow('',true);
		}
	}
}

/**
 * This method adds a row containing an immediate child catalog drop-down
 * defining the attributes of the drop-down. This function prepares the selection
 * id attribute. 
 *
 * @since 1.50.0.1 (CAPP-Release) 
 */
function updateContent(originalResponse)
{	var tree = originalResponse.responseXML.documentElement;
	var selectName = 'c';
	selectName=selectName.concat(insertIndex);
	addRow('catalogNavigation',selectName,tree,insertIndex);
}

/**
 * This method adds rows containing messages defined for the given catalog
 * 
 * @since 1.50.0.1 (CAPP-Release)
 */
function updateMessageContent(messageResponse)
{	var tree = messageResponse.responseXML.documentElement;
	addMessageRow('messageTable',tree);
}

/**
 * This method removes all the child catalog drop-down rows from the table
 * starting from selected drop-down next index to insertion index currently pointing.
 *
 * @since 1.50.0.1 (CAPP-Release) 
 */
function removeRow(tbl,removalIndex)
{	var table = document.getElementById( tbl ) ;
	for(var i=removalIndex; i < insertIndex; i++)
	{	table.deleteRow(removalIndex);
	}
	insertIndex = removalIndex;
}

/**
 * This method hides the candidate ID type fields for keying in SSN/Non SSN candidate record.
 * Used in Account_Create's Find Records flow.
 *
 * @since 1.50.0.1 (CAPP-Release) 
 */
function hideIDTypeRows()
{	idTypeRow = document.getElementById("SSNRow");
	idTypeRow.style.display = "none";
  	idTypeRow = document.getElementById("NonSSNRow");
  	idTypeRow.style.display = "none";
}

/**
 * This function adds a row containing an immediate child catalog drop-down
 * defining the attributes of the drop-dow. The input to this method is an XML stream
 * in the following format.
 *  <catalogs>
 *		<nodelist display_label='label_to_display'>
 *                  <node id='catalog_id' display='catalog_display_name' hasChildren='true|false'/>
 * 		</nodelist>
 *		<tests>
 *                  <test id='test_id' name='test_name'/>
 *		</tests>
 *	</catalogs> 			
 *
 * @since 1.50.0.1 (CAPP-Release) 
 */
function addRow(tbl, selectID,tree) 
{		if( !document.getElementById ) return ; // Only DOM browsers
		var testCenterID = -99;
		if(tree.attributes.length > 0) 
			testCenterID = tree.attributes[0].nodeValue;
		if(tree.childNodes[0].childNodes.length > 0)
		{	if(siteType.indexOf('admin')!=-1)
				addAdminCatalogDrilldown(tbl,selectID,tree.childNodes[0],testCenterID);
			else 
				addCDCatalogDrilldown(tbl,selectID,tree.childNodes[0],testCenterID);
		}
		if(siteType.indexOf('admin')!=-1)
			changeAvailableTests(tree.childNodes[1]);
		else if(siteType.indexOf('cdreg')!=-1)
		{	if(tree.childNodes[1].childNodes.length > 0)
			{   addLicenseRows(tree.childNodes[0],tree.childNodes[1]);
			}else
                        {   //no licenses are present for the selected catalog
                            changeLicenseLabel(tree.childNodes[0]);
                        }
		}else if(siteType.indexOf('cdappt')!=-1)
		{	if(tree.childNodes[1].childNodes.length > 0)
			{	addLicenseRows(tree.childNodes[0],tree.childNodes[1]);
			}else
                        {   //no licenses are present for the selected catalog
                            changeLicenseLabel(tree.childNodes[0]);
                            if(tree.childNodes[0].childNodes.length==0)
                             {   var selectedValue = document.getElementById("selectedName");
                                 selectedValue.innerHTML = 'Select the '+tree.childNodes[0].attributes[0].value;
                             }
                        }

		}else
		{	var idTypeRow;
		    var idType = tree.childNodes[0].attributes[1].nodeValue;
		    if(idType.indexOf('null')==-1)
		    {  if(idType.indexOf('SSN')!=-1)
				idTypeRow = document.getElementById("SSNRow");
			   else
			  	idTypeRow = document.getElementById("NonSSNRow");
			  idTypeRow.style.display = "";
			  var cols = idTypeRow.getElementsByTagName('td');
			  cols[0].setAttribute("nowrap","nowrap");
			  cols[0].innerHTML = 'Enter your '+idType;
			  //set the candidateIDType to SSN/NonSSN
			  var citype = document.getElementById('candidateIDType');
			  citype.value=idType;
		   }	
	   }
}

/**
 *	This function adds message and information rows for the message selected at
 *	catalog or sub catalog level
 *  <catalogs>
 *		<messages>
 *			<message linkId='link_id' description='Description' position='Position'/>
 *		</messages>
 *		<informationLinks>
 *			<informationlink id='information_link' description='Description' location='Location'/>
 *		</informationLinks>
 *	</catalogs>
 *	@since 1.50.0.1 (CAPP-Release)
 */
function addMessageRow(tbl,tree)
{	var messageNodes = tree.childNodes[0];
	var informationNodes = tree.childNodes[1];
	var table = document.getElementById(tbl) ;
	var count=tree.childNodes.length;
	if(count>0)
 	{	while (table.rows.length>0) //deletes all rows of a table
 			table.deleteRow(-1) //delete first row of contracting table until there
 	}
	if(messageNodes.childNodes.length > 0)
	{	var classTxt = getClassAttribute();
		var row = table.insertRow(-1);
		var messageCell = row.insertCell(0);
		var td1 = document.createElement('td');
		td1.setAttribute(classTxt, 'yellowheading wd190px');
		td1.innerHTML = 'Messages';
		messageCell.appendChild(td1);
	}
	
	for(var i=0;i<messageNodes.childNodes.length;i++)
	{	row = table.insertRow(-1);
		messageCell = row.insertCell(0);
		if( document.createElement )
		{	td1 = document.createElement('td');
			td1.setAttribute(classTxt,'text');
			td1.innerHTML = bullet+messageNodes.childNodes[i].attributes[1].nodeValue;
			messageCell.appendChild(td1);
		}
	}
	row = table.insertRow(-1);
	messageCell = row.insertCell(0);
	td1 = document.createElement('td');
	td1.innerHTML = '&nbsp;'
	messageCell.appendChild(td1);

	if(informationNodes.childNodes.length > 0)
	{	row = table.insertRow(-1);
		var classTxt = getClassAttribute();
		messageCell = row.insertCell(0);
		td1 = document.createElement('td');
		td1.setAttribute(classTxt, 'yellowheading wd190px');
		td1.innerHTML = 'Information Links';
		messageCell.appendChild(td1);
	}

	for(var j=0;j<informationNodes.childNodes.length;j++)
	{	row = table.insertRow(-1);
		var informationCell = row.insertCell(0);
		if( document.createElement)
		{	var td2 = document.createElement('td');
			var link = document.createElement('a');
			var linktext = document.createTextNode(informationNodes.childNodes[j].attributes[1].nodeValue);
			link.setAttribute(classTxt,"text");
			var informationLinkValue = informationNodes.childNodes[j].attributes[2].nodeValue;
			// startsWith function is used from prototype.js
			if (!informationLinkValue.startsWith("http://"))
				informationLinkValue = "http://" + informationLinkValue;
			link.setAttribute("href",informationLinkValue);
			link.setAttribute("target","_blank");
			link.appendChild(linktext);
			td2.appendChild(link);
			informationCell.appendChild(td2);
		}
	}
}


/**
 * Used by addRow function to change Available tests.
 * This function will be called on the admin site
 * 
 * @private
 */
function changeAvailableTests(childtree)
{	var testlist = document.getElementById("testlist");
	testlist.length=0;
	if(childtree.childNodes.length > 0)
	{	addTestRow(childtree);
	}else
	{	var option = document.createElement("option");
		option.value = '-1';
		option.text= '- Please select a catalogue -';
		testlist.add(option);
	}
}

/**
 * Add a catalog drop-down dynamically on the admin site
 *
 * @since 1.50.0.1 (CAPP-Release)
 */
function addAdminCatalogDrilldown(tbl,selectID,nodetree,testCenterID)
{	var table = document.getElementById( tbl ) ;
	var row = table.insertRow( insertIndex) ;	
	insertIndex= insertIndex+ 1;

	// Cells
	var cellLeft = row.insertCell(0) ;
	var cellMiddle1 = row.insertCell(1) ;
	var cellMiddle2 = row.insertCell(2) ;
	var cellRight = row.insertCell(3) ;

	var fieldLabel = nodetree.attributes[0].nodeValue;
	if(fieldLabel.indexOf("null")!=-1)
		fieldLabel = "Value";
	var classTxt = getClassAttribute();
	if( document.createElement ) //W3C Dom method. 
    {		var td1 = document.createElement('td');
    		td1.setAttribute(classTxt,"fieldlabel");
			td1.innerHTML = '&nbsp;';
			cellLeft.appendChild( td1 ) ;
			
			var td2 = document.createElement('td');
			td2.setAttribute(classTxt,"fieldlabel");
			td2.setAttribute("nowrap","nowrap");
			td2.innerHTML = fieldLabel;
			cellMiddle1.appendChild( td2 ) ;
			
    		var td3 = document.createElement('td');
    		td3.setAttribute("nowrap","nowrap");
			var select = document.createElement("select");
			select.setAttribute("name",selectID);
 			select.setAttribute(classTxt,"selectbox");
 			select.onchange=function(){fetchCatalogInfo(select)};
			var count=nodetree.childNodes.length;
			var optionsRef = select.options; 
			for(var i=0; i<count; i++)
 			{	optionsRef[i] = new Option();
 				optionsRef[i].value = nodetree.childNodes[i].attributes.getNamedItem('id').value+"^"+testCenterID;     				
				optionsRef[i].text= nodetree.childNodes[i].attributes[1].nodeValue;
 			}
 			optionsRef[0].selected=true;
			td3.appendChild(select);
			cellMiddle2.appendChild( td3 ) ;

			var td4 = document.createElement('td');
    		td4.setAttribute(classTxt,"fieldlabel");
			td4.innerHTML = '&nbsp;';
			cellRight.appendChild( td4 ) ;
    }    
}

/**
 * Add a catalog drop-down dynamically on CD website
 *
 * @since 1.50.0.1 (CAPP-Release)
 */
function addCDCatalogDrilldown(tbl,selectID,nodetree,testCenterID)
{	var table = document.getElementById( tbl ) ;
	var row = table.insertRow( insertIndex) ;	
	insertIndex= insertIndex+ 1;
	
	var fieldLabel = nodetree.attributes[0].nodeValue;
	if(fieldLabel.indexOf("null")!=-1)
		fieldLabel = "Value";
    var classTxt = getClassAttribute();
    if( document.createElement ) //W3C Dom method.
    {	var td2 = document.createElement('td');
		td2.setAttribute(classTxt,"boldtext");
		td2.innerHTML = "Select "+fieldLabel;
		td2.setAttribute("nowrap","nowrap");
		row.appendChild( td2 ) ;
			
   		var td3 = document.createElement('td');
   		td3.setAttribute(classTxt,"mediumbluetext");
   		td3.setAttribute("align","left");
   		td3.setAttribute("nowrap","nowrap");
		var select = document.createElement("select");
		select.setAttribute("id",selectID);
		select.setAttribute("name",selectID);
		select.setAttribute(classTxt,"inputborder");
		select.onchange=function(){fetchCatalogInfo(select)};
		var count=nodetree.childNodes.length;
		var optionsRef = select.options; 
		for(var i=0; i<count; i++)
		{	optionsRef[i] = new Option();
			optionsRef[i].value = nodetree.childNodes[i].attributes.getNamedItem('id').value+"^"+testCenterID+"^"+nodetree.childNodes[i].attributes.getNamedItem('disableTestDateDisplay').value+"^"+nodetree.childNodes[i].attributes.getNamedItem('custommessage').value;
			optionsRef[i].text= nodetree.childNodes[i].attributes[1].nodeValue;
		}
		optionsRef[0].selected=true;
		td3.appendChild(select);
		row.appendChild( td3 ) ;
   }
 }

/**
 * Add all available tests for the selected catalog dynamically.
 *
 * @since 1.50.0.1 (CAPP-Release)
 */
function addTestRow(testtree)
{	var testlist = document.getElementById("testlist") ;
	var count=testtree.childNodes.length;
	for(var i=0; i<count; i++)
	{	var option = document.createElement("option");
		option.value = testtree.childNodes[i].attributes.getNamedItem('id').value;
		option.text= testtree.childNodes[i].attributes.getNamedItem('name').value;
		testlist.add(option); 
	}
}
 
 /**
  * Add all available licenses for the selected catalog dynamically.
  *
  * @since 1.50.0.1 (CAPP-Release)
  */
 function addLicenseRows(nodetree,testtree)
{
    var lntable= document.getElementById("LicenseTable");
    var classTxt = getClassAttribute();
    var row,td1,td2,labeltxt,selectedValue;
    var count=testtree.childNodes.length;
    selectedValue = document.getElementById("selectedName");
    if(count>0)
    {
        while (lntable.rows.length>0) //deletes all rows of a table
            lntable.deleteRow(0);
    }
    if(siteType.indexOf('cdappt')!=-1 && nodetree.childNodes.length==0)
    {
        if(nodetree.attributes[0].value!="null")
            selectedValue.innerHTML = 'Select the '+nodetree.attributes[0].value;
        else
            selectedValue.innerHTML = 'Select the License';
    }
    row = lntable.insertRow(0);
    row.setAttribute(classTxt, "greyrow");
    td1 = document.createElement('td');
    td2 = document.createElement('td');
    td1.setAttribute(classTxt,"bottomborder");
    td1.innerHTML = '&nbsp;';
    td2.setAttribute(classTxt,"bottomborder");
    var nodeDisplay = nodetree.attributes[0];
    if(nodeDisplay.value!="null" && nodetree.childNodes.length==0)
        labeltxt = nodeDisplay.value;
    else
        labeltxt = 'License Name ';
    td2.innerHTML = labeltxt;
    row.appendChild(td1);
    row.appendChild(td2);

    for(var i=0; i<count; i++)
    {
        row = lntable.insertRow(1);
        td1 = document.createElement('td');
        td2 = document.createElement('td');
        var current = testtree.childNodes[i];
        var licname = current.attributes[1].value;
        var licid = current.attributes[0].value;

        if(siteType.indexOf('cdappt')!=-1)
        {	//create a radio button for the first td
            var radiokid = document.createElement('input');
            radiokid.type = 'radio';
            radiokid.id = 'radio'+i;
            radiokid.value = licid;
            radiokid.onmouseup=function(){
                resetRadios(this)
                };
            td1.appendChild(radiokid);
            row.appendChild(td1);
            td2.innerHTML = licname;
            row.appendChild(td2);
        }else
        {
            td1.innerHTML = '&nbsp;';
            row.appendChild(td1);
            //associate a link for the license name.
            var link = document.createElement('a');
            var linktext = document.createTextNode(licname);
            link.setAttribute(classTxt,"links");
            link.setAttribute("href",textLink+current.attributes.getNamedItem('id').value);
            link.appendChild(linktext);
            td2.appendChild(link);
            row.appendChild(td2);
        }
    }
	hideLicenseRows(false);
}

 /**
  * This changes License Name headding to the configured name if any.
  *
  * @since 1.50.0.1 (CAPP-Release)
  */
 function changeLicenseLabel(nodetree)
 {   var lntable= document.getElementById("LicenseTable") ;
     var classTxt = getClassAttribute();
     var row,td1,td2,labeltxt,labelDefaulttxt;
	while (lntable.rows.length>0) //deletes all rows of a table
 	{   lntable.deleteRow(0);
        }
        row = lntable.insertRow(0);
        row.setAttribute(classTxt, "greyrow");
        td1 = document.createElement('td');
        td2 = document.createElement('td');
        td1.setAttribute(classTxt,"bottomborder");
        td1.innerHTML = '&nbsp;';
        td2.setAttribute(classTxt,"bottomborder");
        var nodeDisplay = nodetree.attributes[0];
        if(nodeDisplay.value!="null" && nodetree.childNodes.length==0)
         {   labeltxt = nodeDisplay.value;
             labelDefaulttxt = labeltxt;
         }
        else
         {   labeltxt = 'License Name ';
             labelDefaulttxt = 'Licenses';
         }

        td2.innerHTML = labeltxt;
        row.appendChild(td1);
        row.appendChild(td2);

        row = lntable.insertRow(1) ;
 	td1 = document.createElement('td');
 	td1.innerHTML = '&nbsp;';
 	row.appendChild(td1);

 	td2 = document.createElement('td');
 	td2.innerHTML = 'No '+labelDefaulttxt+' found.';
 	row.appendChild(td2);
 }
 
 /**
  * Remove all added licenses for a previously selected catalog dynamically.
  *
  * @since 1.50.0.1 (CAPP-Release)
  */
 function removeLicenseRows()
 {	var lntable= document.getElementById("LicenseTable") ;
      var classTxt = getClassAttribute();
 	while (lntable.rows.length > 0) //deletes all rows of a table expect first
 		lntable.deleteRow(0); //delete first row of contracting table until there

        if(document.getElementById("selectedName"))
        {    selectedValue = document.getElementById("selectedName");
            selectedValue.innerHTML = 'Select the License';
        }
        
        var row = lntable.insertRow(0);
        row.setAttribute(classTxt, "greyrow");
 	var td1 = document.createElement('td');
        td1.setAttribute(classTxt,"bottomborder");
 	td1.innerHTML = '&nbsp;';
 	row.appendChild(td1);

 	var td2 = document.createElement('td');
        td2.setAttribute(classTxt,"bottomborder");
 	td2.innerHTML = 'License Name ';
 	row.appendChild(td2);

 	row = lntable.insertRow(1) ;
 	td1 = document.createElement('td');
 	td1.innerHTML = '&nbsp;';
 	row.appendChild(td1);

 	td2 = document.createElement('td');
 	td2.innerHTML = 'No Licenses found.';
 	row.appendChild(td2);
 	
 	hideLicenseRows(true);
 	hideButtons(true);
 }

 /**
  * Remove all added messages for a previously selected catalog dynamically.
  *
  * @since 1.50.0.1 (CAPP-Release)
  */
 function removeMessageRows()
 {	var lntable= document.getElementById("messageTable") ;
 	while (lntable.rows.length > 0) //deletes all rows of a table expect first
 		lntable.deleteRow(-1); //delete first row of contracting table until there
 }

  /**
  * Remove all added portions for a previously selected catalog dynamically.
  *
  * @since 1.50.0.1 (CAPP-Release)
  */
 function removePortionRows()
 {	var prtable= document.getElementById("PortionTable") ;
 	while (prtable.rows.length > 1) //deletes all rows of a table expect first
 		prtable.deleteRow(-1); //delete first row of contracting table until there

 	var row = prtable.insertRow(1) ;
 	var td1 = document.createElement('td');
 	td1.innerHTML = '&nbsp;';
 	row.appendChild(td1);

 	var td2 = document.createElement('td');
 	td2.innerHTML = 'No Portions found.';
	row.appendChild(td2);

	var td3 = document.createElement('td');
	td3.innerHTML = '&nbsp;';
 	row.appendChild(td3);
 	
 	hidePortionRows(true);
 	hideButtons(true);
 }

/**
  * Add all available test portions for the selected test.
  * @since 1.50.0.1 (CAPP-Release)
  */
 function displayTestPortions(originalResponse)
 {	var portionsTree = originalResponse.responseXML.documentElement;
	portionslist = portionsTree.childNodes;
	var selectedLicense = portionsTree.attributes[0].value;
	var testName = portionsTree.attributes[1].value;
	var catalogName = portionsTree.attributes[2].value;
 	var prtable = document.getElementById("PortionTable");
    var count=portionslist.length;
	 if(count>0)
 	 {	while (prtable.rows.length > 1) //deletes all rows of a table expect first
	 		prtable.deleteRow(-1); //delete first row of contracting table until there
 	 }

	var checkAttribute;
	var browser = getBrowser();
	if(browser.indexOf('msie')!=-1)
		checkAttribute = 'defaultChecked';
	else
		checkAttribute = 'checked';
	
	for(var i=0; i<count; i++)
 	{   var row = prtable.insertRow(1);
 		var td1 = document.createElement('td');
		var td2 = document.createElement('td');
		var td3 = document.createElement('td');
		
		var cp = document.createElement('input');
		cp.setAttribute('type','checkbox');
		cp.setAttribute('id','ck'+i);
		cp.value = selectedLicense+'^'+testName+'^'+catalogName+'^'+portionslist[i].attributes[0].value;
		
		if(portionslist[i].attributes[2].value.indexOf('Mandatory')!=-1)
		{	cp.setAttribute(checkAttribute, 'true');
			cp.setAttribute('disabled','true');
		}
		else
		{	cp.onclick=function(){checkUncheckPortion(this,checkAttribute);}
		}
		td1.appendChild(cp) ;
		td2.innerHTML = portionslist[i].attributes[1].value;
		td3.innerHTML = portionslist[i].attributes[2].value;
		row.appendChild(td1);
		row.appendChild(td2);
		row.appendChild(td3);
	}

	hidePortionRows(false);	
	hideButtons(false);
 }

/**
 * Set the 'checkAttrib' property appropriately on selecting radio buttons
 * @since 1.50.0.1 (CAPP-Release)
 **/
function checkUncheckPortion(selectedportion,checkAttrib)
{	var selected = selectedportion.getAttribute(checkAttrib);
	var browser = getBrowser();
	if(browser.indexOf('msie')!=-1)
	{
		if(selected)
			selectedportion.setAttribute(checkAttrib,'');
		else
			selectedportion.setAttribute(checkAttrib,'true');
	}
	else
	{	
		if(selected != null && selected.indexOf('true') != -1)
			selectedportion.setAttribute(checkAttrib,'false');
		else
			selectedportion.setAttribute(checkAttrib,'true');		
	}
}

/**
 * This function is to get the previously selected catalogID.
 * @since 1.50.0.1 (CAPP-Release)
 **/
function getPreviousSelectedCatalogID(selectedItem)
{	var itemID = selectedItem.getAttribute("id");
	var idIndex = parseInt(itemID.substr(1,itemID.length))-1;
	var previousCatalogID;
	if(idIndex != -1)
	{	var parentSelID = 'c';
		var parSelID = parentSelID.concat(idIndex);
		var prevSelection = document.getElementById(parSelID);
		var previousCatalogVars = prevSelection.options[prevSelection.selectedIndex].value;
		var previousCatalogVar = previousCatalogVars.split("^");
		previousCatalogID = previousCatalogVar[0];
	}
		return previousCatalogID;
}

/**
 * Reset all radio buttons
 * @since 1.50.0.1 (CAPP-Release)
 **/
function resetRadios(selectedTest)
{	var radios = document.getElementsByTagName('input');
	for(var k=0;k<radios.length;k++)
	{	if(radios[k].type.indexOf('radio')!=-1)
			radios[k].checked = false;
	}
	selectedTest.checked = true;
	removePortionRows();
	fetchTestPortionsInfo(selectedTest);
}

function hideLicenseRows(hide)
{	
	var LicenselabelRow = document.getElementById("licenselablerow");
	var LicenseRow = document.getElementById("licenserow");
        if (LicenselabelRow) {
		if(hide == true) {
			LicenselabelRow.style.display = "none";
		} else {
			LicenselabelRow.style.display = "";
		}
        }
        if(LicenseRow) {
		if(hide == true) {
                	LicenseRow.style.display = "none";
		} else {
			LicenseRow.style.display = "";
		}
        }
}

function hidePortionRows(hide)
{
	var PortionlabelRow = document.getElementById("portionlablerow");
	var portionRow = document.getElementById("Portionrow");
	if(PortionlabelRow && portionRow) {
		if(hide == true) {		
			PortionlabelRow.style.display = "none";	  	
			portionRow.style.display = "none";
		} else {
			PortionlabelRow.style.display = "";	  	
			portionRow.style.display = "";
		}
	}		
}

function hideButtons(hide)
{
	var Continue = document.getElementById("Continue");
	var Cancel = document.getElementById("Cancel");	
	if(Continue && Cancel) {
		if(hide == true) {		
			Continue.style.display = "none";	  	
			Cancel.style.display = "none";	  				
		 } else {
			Continue.style.display = "";	  	
			Cancel.style.display = "";	  				
		 }
	}
}

function displayCustMsgRow(message, hide)
{
	var msgRow = document.getElementById("MessageRow");
	var msgLabel = document.getElementById("custommessagevalue");
	var backBtnRow = document.getElementById("backBtnRow");
	if(msgRow && msgLabel) {
		if(hide == true) {		
			msgRow.style.display = "none";
			backBtnRow.style.display = "none";
		} else {
			msgRow.style.display = "";	  	
			msgLabel.innerHTML = message;
			backBtnRow.style.display = "";
		}
	}		
}