//=========================================================================
//
//CertINFO Page Functions -- Order by characher
//=======================
//=========================================================================
//
//Personal List Functions
//=======================

//	This following javascript functions are for managing a
//	user's personal list of occupational profiles.

//	The personal list is stored as a delimited list of
//	occupational profile ids.  The list is stored in a
//	client side cookie that exists until the user's session
//	expires, and is accessed through javascript.
//
//	The basic cookie handling routines are used courtesy of
//	Bill Dortch:
//		Cookie Functions -- "Night of the Living Cookie"
//				Version (25-Jul-96)
//				Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//				Available from: http://www.hidaho.com/cookies/cookie.txt
// Constants
var COOKIENAME = "PersonalList";
var SEPERATOR = ",";



// Add the specified Item to the Personal List
// if it is not already in the list
function addToList(Item) {

	var val = GetCookie(COOKIENAME);

	if (val) {
		if (val.indexOf(Item + SEPERATOR) < 0)
			val = val + Item + SEPERATOR;
	}
	else {
		val = Item + SEPERATOR;
	}
	SetCookie(COOKIENAME, val);
}



// Browser detect for Noc Search tree view
function BrowserCheck()
{
	var browser;
	if (navigator.appName=="Netscape" && parseInt(navigator.appVersion.charAt(0)) >= 5)
		document.location.href = "appletFrame_NC6.html"
	else {
		if (navigator.appName.indexOf("Netscape") >= 0)       browser = "NC4";
		else if (navigator.appName.indexOf("Microsoft") >= 0) browser = "IE4";
		else                                                  browser = "???";
	}	
}


function CERTRequirementSearchKeyword() {
	var str = new String(trim(document.frmRequirementSearch.Keyword.value));
	
	//Check if the search string if long enough (at least 3 char)
	if (str.length < 3) {
		alert("You must enter at least 3 characters in the Keyword field.");
		return false;
	}
	else {
		//Check for invalid characters
		if (	str.indexOf("%") >= 0 ||
			str.indexOf("_") >= 0 ||
			str.indexOf("[") >= 0 ||
			str.indexOf("]") >= 0 ) {
				alert("You keyword search may not contain %, _, [, or ] characters.");
				return false;
		}
	}
	return true;
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}



//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}


//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function getCERTPages(sPage,sMenu,SSnipCodeList,Spliter) 
{
   var loc = "RequestAction.asp?";
   loc = loc + "format=html" + String.fromCharCode("38") + "aspAction=" + sPage + String.fromCharCode("38") + "Page=" + sMenu ; 
   switch (sPage)
   { case "GetCertReportsPage":
        loc = loc +  String.fromCharCode("38") + "SNT_ID=12";
         break;
     case "GetCERTReqSearch":
        loc = loc +  String.fromCharCode("38") + "SNT_CODE_LIST="+SSnipCodeList;
        loc = loc +  String.fromCharCode("38")+"SPLITTER="+Spliter; 
        break;
    }    
  top.document.location.href = loc;
}


function getRequirementSearch() 
{   //getPages('GetCERTRequirementsSearch', 'CERTRequirementsSearch');
   top.document.location.href = "NOCSearch.asp";
}			

function getPages(sPage, sMenu,value) 
{
			var loc = "RequestAction.asp?";
			loc = loc + "format=html" + String.fromCharCode("38") + "aspAction=" + sPage + String.fromCharCode("38") + "Page=" + sMenu ; 
			if (sPage =='GetCertReportsPage')
			{
				loc = loc +  String.fromCharCode("38") + "SNT_ID=" + value;
			}
			top.document.location.href = loc;
}


function getTitles(FirstLetter) 
{
	var loc = "RequestAction.asp?aspAction=GetCERTTitlesSearchFirstLetter" + String.fromCharCode("38");
	loc = loc + "format=html" + String.fromCharCode("38");
	loc = loc + "Page=CERTRequirementsSearchResult" + String.fromCharCode("38");
	loc = loc + "Results=TRUE" + String.fromCharCode("38");
	loc = loc + "FirstLetter=" + FirstLetter;
	document.location.href = loc;
}


function getRangeTitles(FirstLetter,LastLetter)
 {
		       	var loc = "RequestAction.asp?aspAction=GetCERTTitlesSearchRangeLetter" + String.fromCharCode("38");
				loc = loc + "format=html" + String.fromCharCode("38");
				loc = loc + "Page=CERTRequirementsSearchResult" + String.fromCharCode("38");
				loc = loc + "Results=TRUE" + String.fromCharCode("38");
				loc = loc + "FirstLetter=" + FirstLetter+ String.fromCharCode("38");
				loc = loc + "LastLetter=" +LastLetter;				
				document.location.href = loc;
}
		
			
function getOther()
 {
				var loc = "RequestAction.asp?aspAction=GetCERTTitlesSearchOtherLetter" + String.fromCharCode("38");
				loc = loc + "Page=CERTRequirementsSearchResult" + String.fromCharCode("38");
				loc = loc + "Results=TRUE"  + String.fromCharCode("38");
				loc = loc + "format=html";
				document.location.href = loc;
}
			

function getAll()
{
				var loc = "RequestAction.asp?aspAction=GetCERTTitlesSearchAll" + String.fromCharCode("38");
				loc = loc + "Page=CERTRequirementsSearchResult" + String.fromCharCode("38");
				loc = loc + "Results=TRUE"  + String.fromCharCode("38");
				loc = loc + "format=html";
				document.location.href = loc;
}

 
function getCookieVal (offset)
 {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}



//If the browser detected is IE 4.0, then insert a Web Browser
//ActiveX object to provide print functionality

function insertWBforIE4() {
	if (da && !pr && !mac) {
	  document.writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
	  document.writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
	  document.writeln('Sub window_onunload');
	  document.writeln('  On Error Resume Next');
	  document.writeln('  Set WB = nothing');
	  document.writeln('End Sub');
	  document.writeln('Sub vbPrintPage');
	  document.writeln('  OLECMDID_PRINT = 6');
	  document.writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
	  document.writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
	  document.writeln('  On Error Resume Next');
	  document.writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER');
	  document.writeln('End Sub');
	  document.writeln('<' + '/SCRIPT>');
	}
}



//	If the required number of characters are entered
//	then submit the Keyword Search, otherwise show an alert.
function KeywordSearch() {
	var str = new String(trim(document.frmKeywordSearch.Keyword.value));
	
	//Check if the search string if long enough (at least 3 char)
	if (str.length < 3) {
		alert("You must enter at least 3 characters in the Keyword field.");
		return false;
	}
	else {
		//Check for invalid characters
		if (	str.indexOf("%") >= 0 ||
			str.indexOf("_") >= 0 ||
			str.indexOf("[") >= 0 ||
			str.indexOf("]") >= 0 ) {
				alert("You keyword search may not contain %, _, [, or ] characters.");
				return false;
		}
	}
	return true;
}
	
function ltrim(aString) {
	var str;
	str = new String(aString);
	
	while (str.indexOf(" ") == 0 && str.length > 0)
		str = str.substring(1, str.length);
	return str;
}


//function to return back the search page 
function newSearch()
{
	      var loc = "RequestAction.asp?";
			loc = loc + "format=html" + String.fromCharCode("38") + "aspAction=GetCERTRequirementsSearch"  + String.fromCharCode("38") + "Page=CERTRequirementsSearch"  ; 
			top.document.location.href = loc;
}

function openKeyFact(KeyCode) 
{
		var width = 640;
			var height = 480;
				//var width = window.screen.availWidth/2;
				//var height = window.screen.availHeight/2;
				var left =window.screen.availWidth/8;
				
				var top = window.screen.availHeight/4;
				var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
				open("RequestAction.asp?aspAction=GetKeyFact" + String.fromCharCode("38") + "format=html" + String.fromCharCode("38") + "Page=KeyFact" + String.fromCharCode("38") + "KEY_FACT_CODE=" +KeyCode, "", options);
}

//purpose: display the content of group 
function OpenGroupListsFolder(GroupID)
{

		    divColl = document.all.tags("table");
			var mode;
			for (i=0; i<divColl.length; i++) 
			{
			  if (divColl(i).id == GroupID)
			   {
					divColl(i).style.display = (divColl(i).style.display == "none" ) ? "" : "none";
				    mode = divColl(i).style.display;
					 
			   }
			 }
			 
			divColl = document.all.tags("img");
			for ( i=0;i<divColl.length;i++)
			{
			  if (divColl(i).id == GroupID)
			   {
			      if (mode.indexOf("none")== -1 ) 
			      {  divColl(i).src = "../images/minus.gif"  }
			      else
			      {divColl(i).src = "../images/plus.gif" }
			      return;
			    }
			}
}	


	function openCERTReport(strReport)
	{
			var width = 640;
			var height = 480;
			var left = window.screen.availWidth/10;
			var top = window.screen.availHeight/4;
		var loc;
    	var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
    	if (confirm("You need install Adobe Reader to open the report.Click OK to open report now.CLick cancel to install Adobe."))
    	 {
    	 	loc = strReport;  
    	 }
    	else
    	{
    	  loc ="http://www.adobe.co.uk/products/acrobat/readstep2.html";
    	} 	    
	  window.open(loc, "", options);
	
	}






  

//	Open the profile with the given id in a
//	new browser window.
function openProfileWindow(occPro_ID) {
	var loc = "RequestAction.asp?aspAction=GetHTMLProfile" + String.fromCharCode("38");
	loc = loc + "format=html" + String.fromCharCode("38");
	loc = loc + "occPro_ID=" + occPro_ID;

		var width = 640;
		var height = 480;
	var left = (window.screen.availWidth - width)/2;
	var top = (window.screen.availHeight - height)/2;


	var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
	//var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height;
	window.open(loc, "", options);
}

//	new browser window.
function openCERTProfileWindow(CERT_ID) {
	var loc = "RequestAction.asp?aspAction=GetCERTHTMLProfile" + String.fromCharCode("38");
	loc = loc + "format=html" + String.fromCharCode("38");
	loc = loc + "CERT_ID=" + CERT_ID;

	var width = 640;
	var height = 480;
	
	//var left = (window.screen.availWidth - width)/2;
	var left =window.screen.availWidth/8;
	var top = (window.screen.availHeight - height)/2;
  
	var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
	//var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height;
	window.open(loc, "", options);
}

//	new browser window.
function openCERTTradeSection(SNT_CODE) {
	var loc = "RequestAction.asp?aspAction=GetCERTTradeContent" + String.fromCharCode("38");
	loc = loc + "format=html" + String.fromCharCode("38");
	loc = loc + "SNT_CODE=" + SNT_CODE;

	var width = 640;
	var height = 480;
	var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height;
	window.open(loc, "", options);
}



//	Open the given Help File in a
//	new browser window.


function openHelpWindow(File) {
	var width = 500;
	var height = 400;
	var left = (window.screen.availWidth - width)/2;
	var top = (window.screen.availHeight - height)/2;
	var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
	window.open(File, "Help", options);
}

//	Open the given reports in a new browser window.
function openReportWindow(Report) {
	var File = "../Content/RequestReport.asp?Format=HTML&aspAction=" + Report 
	window.open(File, "Report"); 
}


//	Open the given reports in a new browser window.
function openCERTReportWindow(Report) {
	var width = 500;
	var height = 400;
	var left = (window.screen.availWidth - width)/2;
	var top = (window.screen.availHeight - height)/2;
	var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
	window.open(Report, "Report", options);
	
}


//	Open the given statement snippet in a
//	new browser window.
function openStatementWindow(Statement, width, height) {

	var left = (window.screen.availWidth - width)/2;
	var top = (window.screen.availHeight - height)/2;
	var File = "../Content/RequestAction.asp?Format=HTML&aspAction=GetSnippet&SNT_CODE=" + Statement

	var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
	window.open(File, "", options);
}


function openCERTStatementWindow(Statement, width, height) {

	var left = (window.screen.availWidth - width)/2;
	var top = (window.screen.availHeight - height)/2;
	var File = "../Content/RequestAction.asp?Format=HTML&aspAction=GetCERTSnippet&SNT_ID=" + Statement

	var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
	window.open(File, "", options);
	
}

//=========================================================================
//
//IE 4.0 Print Compatibility Functions
//====================================

//	This following javascript functions provide javascript
//	print compatibility for IE 4.0

// The flow of the printing process is: 
//		PrintThis() -> vbPrintPage()

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printThis() {
if (pr) { // NS4, IE5
	window.print();
  } else if (da && !mac) { // IE4 (Windows)
    vbPrintPage();
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}



function printCERTPage(sAction,sPage,value,optionValue)
{
    var loc = "RequestAction.asp?";
    loc = loc + "format=html" + String.fromCharCode("38") + "Page=" + sPage ; 
    var strValue;
  
    switch (sPage)
	{	case  "CERTReportPrintF": 
	          loc = loc + String.fromCharCode("38") + "aspAction=" + sAction;   
		      loc= loc + String.fromCharCode("38") + "SNT_ID=" + value;
			  break;
	    case "ReqSePrintF":
	          loc = loc + String.fromCharCode("38") + "aspAction=" + sAction;   
	       	  loc = loc +  String.fromCharCode("38") + "SNT_CODE_LIST="+value;
              loc = loc +  String.fromCharCode("38")+"SPLITTER="+optionValue; 
              strValue = new String(trim(document.frmRequirementSearch.Keyword.value));
			  loc = loc +  String.fromCharCode("38")+"value="+strValue; 	    
			  break;
	   case "CERTReqSearchResultPrintF":
	            var aspAction =document.frmSearchResults.Type.value;
	            switch (aspAction)
				{ case "GetCERTTitlesSearchRangeLetter":
				       var FirstLetter =document.frmSearchResults.FirstLetter.value; 
				       var LastLetter = document.frmSearchResults.LastLetter.value;
				       loc = loc + String.fromCharCode("38")+ "FirstLetter=" + FirstLetter;
					   loc = loc + String.fromCharCode("38") + "LastLetter=" +LastLetter;	
					   loc = loc + String.fromCharCode("38") + "aspAction=GetCERTTitlesSearchRangeLetterPrintF";
					   break; 
				    case  "GetCERTTitlesSearchKeyword":
				        var Keyword= document.frmSearchResults.Keyword.value; 
				        loc = loc + String.fromCharCode("38")+ "Keyword=" + Keyword;
				        loc = loc + String.fromCharCode("38") + "aspAction=GetCERTTitlesSearchKeywordPrintF";	
				        break;
				    case "GetCERTTitlesSearchFirstLetter":
				         var FirstLetter =document.frmSearchResults.FirstLetter.value; 
				         loc = loc + String.fromCharCode("38")+"FirstLetter=" + FirstLetter;
				         loc = loc + String.fromCharCode("38") + "aspAction=GetCERTTitlesSearchFirstLetterPrintF";
				          break;
				    case "GetCERTTitlesSearchAll":
				        loc = loc + String.fromCharCode("38") + "aspAction=GetCERTTitlesSearchAllPrintF";
				         break;
				     
				 }
				 break; 
		case "TradeContent":
			loc = loc + String.fromCharCode("38") + "aspAction=GetCERTTradeContentPrintF";
			loc= loc + String.fromCharCode("38") + "SNT_ID=" + value;
			loc= loc + String.fromCharCode("38") + "GroupName=" + optionValue;
			break; 	 
		default : 
	         loc = loc + String.fromCharCode("38") + "aspAction=" + sAction;   
		 		   
	 }
	var width = window.screen.availWidth/2;
	var height = window.screen.availHeight/2;
     var left = (window.screen.availWidth - width)/2;
	var top = (window.screen.availHeight - height)/2;
	var options = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top+",menubar=yes";
	var options = options + ",resizable=yes";
	//window.open(loc, "", options);
 window.open(loc);	
	
}



//	Opens the selected profiles in a new browser window.
function printSelected(frm) {
	var loc = "RequestAction.asp?aspAction=GetHTMLProfile" + String.fromCharCode("38");
	loc = loc + "format=html";
	
	var items = frm.elements;
	var match = false;
	for (var i = 0; i < items.length; i++)
		if (items[i].type == "checkbox" && items[i].checked == true){
			loc = loc + "&OCCPRO_ID=" + items[i].value;
			match = true;
		}

	if (match){
		var width = 600;
		var height = 400;
		var left = (window.screen.availWidth - width)/2;
		var top = (window.screen.availHeight - height)/2;

		var options = "resizable=yes,scrollbars=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
		window.open(loc, "", options);
	}
	else
		alert ('Please select at least one profile.');
}


function printPage(sAction, sPage,value)
{

    var loc = "RequestAction.asp?";
   loc = loc + "format=html" + String.fromCharCode("38") + "aspAction=" + sAction + String.fromCharCode("38") + "Page=" + sPage ; 
     											
	var width = window.screen.availWidth/2;
	var height = window.screen.availHeight/2;
	var left = window.screen.availWidth/4;
	var top = window.screen.availHeight/4;
	var options = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top;
	//window.open(loc, "", options);
	window.open(loc);			
}
	
	
	
			
			
function rtrim(aString) {
	var str;
	str = new String(aString);
	
	while (str.lastIndexOf(" ") == str.length-1 && str.length > 0)
		str = str.substring(0, str.length-1);
	return str;
}

//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}



function trim(aString) {
	return rtrim(ltrim(aString));
}








