// JavaScript Document
// Added by MP Haagsma, 31 March 2005.
// useful javascript navigation functions

 function f_cancel(ls_url) {
	// alert(ls_url); // debug 
	// on a button, call like this: 
	// onClick="return f_cancel('/aglc_secure/Raffle_U10k/raffle/licence_new.jsp')"
	
	window.location =  ls_url  ;

}

//////////////////////////////////////////////////////////////////////////////
//
//	Method:  		f_setFocusToField(adw,  aColumnName, row)
//	
//	Arguments:		adw - the datawindow control (object)
//					aColumnName - the column (object)
//					row - the row
//
//	Returns:  		none
//						
//	Description:  	Set the focus to a specific field  
//					in a specific datawindow.  
//					Note: findControl() is in dwcomn.js     
//
//////////////////////////////////////////////////////////////////////////////		
function f_setFocusToField(adw,  aColumnName, row)  {
	// alert(aColumnName);  //debug
 	var oSelect = adw.findControl (aColumnName, row, true)
		if (oSelect != null){
			oSelect.focus();
		} 
}

//////////////////////////////////////////////////////////////////////////////
//
//	Method:  		f_resetDDLB( aDWControl, aColName, aJSRow )
//	
//	Arguments:		 DWName, ColName and RowNo 
//
//	Returns:  		none
//						
//	Description:  	Empties a DDLB dynamically. 
//
/* * * * * * * *
First line in the function maps the ColName and RowNo 
into a control referring to that specific item on the page.
courtesy of: MicK, Michael Kramer Rilau, Cynergy Systems, Europe
*****************************/	
// Note: findControl() is in dwcomn.js     
//
//////////////////////////////////////////////////////////////////////////////		

function f_resetDDLB( aDWControl, aColName, aJSRow ) {
  var oSelect = aDWControl.findControl (aColName, aJSRow, true)
    for(var i=0; i<oSelect.options.length; i++ ) {
      if (i == oSelect.selectedIndex) { /* SKIP to avoid losing current value */ } else {
        oSelect.options.remove(i);
        i--;
      }
    }
  };


//////////////////////////////////////////////////////////////////////////////
//
//	Method:  		f_getHelpContextId(as_HelpPageName, as_CallingPageName)
//	
//	Arguments:		as_HelpPageName 	- the help apps start page. 
//					as_CallingPageName 	- the webpage name
//
//	Returns:  		The Help Context id: if the page is found, the number, else, 0. 
//						
//	Description:  	Function is used to return the context id used by RoboHelp to present
//					a specific help page.  
//////////////////////////////////////////////////////////////////////////////		
function f_getHelpContextId(as_HelpPageName, as_CallingPageName){

	if (as_HelpPageName == "Raffle_Under_10K.htm"){
		
		 switch(as_CallingPageName)
			{
			case "licence_details.jsp":
			    return 100;
				break
			case "licence_new.jsp":
			    return 50;
				break
			case "tickets.jsp":
			    return 60;
				break
			case "draw_location.jsp":
			    return 70;
				break
			case "expenses.jsp":
			    return 90;
				break
			case "draw_prize.jsp":
			    return 80;
				break
			case "org_licences_list.jsp":
			    return 40;
				break	
			case "org_search_criteria.jsp":
			    return 20;
				break	
			case "org_search_list.jsp":
			    return 30;
				break	
			default:
			  	return 0;
			}
	}; 
	
	if (as_HelpPageName == "Stakeholder.htm"){
		 switch(as_CallingPageName)
			{
			case "auth_user_details.jsp":
			    return 60;
				break
			case "org_details.jsp":
			    return 40;
				break
			case "password_change.jsp":
			    return 50;
				break
			case "individual_find.jsp":
			    return 20;
				break
			case "individual_new.jsp":
			    return 30;
				break
			default:
			  	return 0;
			}
	}; 
	
	if (as_HelpPageName == "aglc_secure.htm"){
		 switch(as_CallingPageName)
			{
			case "login.jsp":
			    return 20;
				break
			case "loginfailed.jsp":
			    return 20;
				break
			case "passwordreminder.jsp":
			    return 40;
			case "passwordreminder.jsp?support":
			    return 70;				
				break
			default:
			  	return 0;
			}
	}; 
}
//////////////////////////////////////////////////////////////////////////////
//
//	Method:  		f_help(as_url, as_helpfile)
//	
//	Arguments:		as_url - the url of the calling page
//					as_helpLocation - the relative path and help file name.
//
//	Returns:  		none 
//						
//	Description:  	Open the supplied help file. 
//					Check for a context id for the calling page and if found
//					open the context page in a single paine window.
//////////////////////////////////////////////////////////////////////////////
 function f_help(as_url,as_helpLocation){
	
	// Remove the directory path from start of the URL
	var sPageAndParms = as_url.substring(as_url.lastIndexOf('/') + 1);
		
	// Remove any trailing page parameters
	var li_pos = sPageAndParms.indexOf(';')
	if (li_pos > 0){
		var sPage = sPageAndParms.substring(0, li_pos );
	}else{
		sPage = sPageAndParms;
	}
	
	// Get the help page name.
	var sHelpPage = as_helpLocation.substring(as_helpLocation.lastIndexOf('/') + 1);
	
	// Get the Help Context id.
	var li_index = f_getHelpContextId(sHelpPage,sPage);
	 
	var lv_helppage = "";
	
	// Call single paine help window for a context page or dual-paine for a general call.
	if ( li_index > 0){
		lv_helppage = "javascript:RH_ShowHelp(0,'" + as_helpLocation + ">AGLC_default_single', HH_HELP_CONTEXT," + li_index + "\);" ;
	}else{
		lv_helppage = "javascript:RH_ShowHelp(0,'" + as_helpLocation + ">AGLC_default', HH_HELP_CONTEXT," + 0 + "\);" ;
	}
	window.location = lv_helppage;
  
 }

 
//////////////////////////////////////////////////////////////////////////////
//
//	Method:  		f_PrintNavButtons
//	
//	Arguments:		web datawindow
//
//	Returns:  		none
//						
//	Description:  	Display the nav buttons for DW.
//
//////////////////////////////////////////////////////////////////////////////
function f_PrintNavButtons(adw){
	var _firstpage = "<input type='button' class='btn'"+
	                 " onmouseover=\"hov(this,'btn btnhov')\" "+
					 " onmouseout=\"hov(this,'btn')\" "+
					 " onclick='" + adw.name + ".ScrollFirstPage()' " +
					 " name='First' "+
					 " value=' First  '"
	var _priorpage = "<input type='button' class='btn'"+
	                 " onmouseover=\"hov(this,'btn btnhov')\" "+
					 " onmouseout=\"hov(this,'btn')\" "+
					 " onclick='" + adw.name + ".ScrollPriorPage()' " +
					 " name='Prior' "+
					 " value=' Prior  '" 
	var _nextpage  = "<input type='button' class='btn'"+
	                 " onmouseover=\"hov(this,'btn btnhov')\" "+
					 " onmouseout=\"hov(this,'btn')\" "+
					 " onclick='" + adw.name + ".ScrollNextPage()' " +
					 " name='Next' "+
					 " value=' Next  '"  
	var _lastpage  = "<input type='button' class='btn'"+
	                 " onmouseover=\"hov(this,'btn btnhov')\" "+
					 " onmouseout=\"hov(this,'btn')\" "+
					 " onclick='" + adw.name + ".ScrollLastPage()' " +
					 " name='Last' "+
					 " value=' Last  '" 
	var _firstpage_disable 
	var _priorpage_disable 
	var _nextpage_disable 
	var _lastpage_disable  
	
	_firstpage_disable = _firstpage + "disabled >";_firstpage += ">"
	_priorpage_disable = _priorpage + "disabled >";_priorpage += ">"
	_nextpage_disable = _nextpage + "disabled >";_nextpage += ">"
	_lastpage_disable = _lastpage + "disabled >";_lastpage += ">"
	
	if (adw.firstRow > 0) {
	  document.write(_firstpage);
	  document.write("&nbsp;&nbsp;&nbsp;");
	  document.write(_priorpage);
	  document.write("&nbsp;&nbsp;&nbsp;");
	}else{
	  document.write(_firstpage_disable);
	  document.write("&nbsp;&nbsp;&nbsp;");
	  document.write(_priorpage_disable);
	  document.write("&nbsp;&nbsp;&nbsp;");
	}
	<!-- Rowcount starts from 0.-->
	if (adw.lastRow != adw.rowCount - 1){
	  document.write(_nextpage);
	  document.write("&nbsp;&nbsp;&nbsp;");
	  document.write(_lastpage);
	}else{
	  document.write(_nextpage_disable);
	  document.write("&nbsp;&nbsp;&nbsp;");
	  document.write(_lastpage_disable);
	}
}

