/*	All pages that use linked lists or other AJAX functionality should check this flag before linking lists and calling any futher ajax functions
	as if its not undefined it will let you know whether to both trying to create objects or not. */
var bAllowAjax = undefined;
function enc(val){
	var c = encodeURIComponent||escape;
	return c(val);
}
function getXmlHttp(){
	ShowDebug("In getXmlHttp")
	var xmlHttp;	
	var ProgID, ieProgId = "";
	var init = false;
	// ProgIDs for MS XMLHTTP object. We will loop until we get one.
	var XML_ACTIVE_X_IDENTS = [
		  "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0",
		  "MSXML2.XMLHTTP", "MICROSOFT.XMLHTTP.1.0", "MICROSOFT.XMLHTTP.1",
		  "MICROSOFT.XMLHTTP" ];
	// IE versions should support this object and we'd rather use it as its inbuilt with no "request for ActiveX object use msg to user"
	if(typeof XMLHttpRequest != 'undefined'){
		try{
			xmlHttp = new XMLHttpRequest();
			init = true;
		}catch(e){}
	}
	// However if we can't use that object and we have access to activeX (IE) then try this
	// IE browsers could use many different objects so we loop the array of prog IDs until we find one that works
	if (!init && typeof ActiveXObject != 'undefined') {
		for (var i = 0; i < XML_ACTIVE_X_IDENTS.length; i++) {
			ProgID = XML_ACTIVE_X_IDENTS[i];
			try {
				new ActiveXObject(ProgID);
				ieProgId = ProgID; //if here we got one
				//alert("TRY AX = " + ProgID);
				break;
			} catch (e) {
			// do nothing; try next choice
			}
		}
		if(ieProgId!=""){ //could be the last in the array and still not work
			try{
				//alert("CREATE AX = " + ProgID);
				xmlHttp = new ActiveXObject(ieProgId);
				init = true;
			}catch(e){}
		}
	} 
	if (!init && window.createRequest) {
		try {
			xmlHttp = window.createRequest();
			init = true;
		} catch (e) {}
	}
	//set global flag so other JS functions know whether to even bother calling xmlHttpPost or other ajax functions
	if(init && typeof(xmlHttp) == "object"){
		ShowDebug("Found valid xmlHttp object set bAllowAjax=true")
		bAllowAjax = true; //set global flag to preven repeated calls to this function from xmlhttpost	
	}else{
		ShowDebug("No xmlHttp object set bAllowAjax=false")
		bAllowAjax = false;
	}
	return xmlHttp;	
}

function xmlhttpPost(strURL, strSubmit, strResultFunc, param1, param2) {
	ShowDebug("IN xmlhttp post URL = " + strURL + " submit = " + strSubmit + " func = " + strResultFunc + " param1 = " + param1 + " param2 = " + param2)
	var bounce=false;
	if(bAllowAjax==false){ 
		bounce=true; 
	}else{
		//try and get a new local xmlhttp object
		var xmlhttp = getXmlHttp();
		if(typeof(xmlhttp) != "object" || !bAllowAjax){
			ShowDebug("Could not get an xmlhttp object")
			bounce=true;
		}
	}
	if(bounce){
		//redirect user to the browser compatibility test page as the site will not work for them
		//unless we are already on that page
		cl = window.location.href;
		//alert(cl)
		if(cl.indexOf('/jobboard/cands/userTest.asp')==-1){
			//alert("redirect to usertest")
			window.location.href = "/jobboard/cands/userTest.asp?er=1"
		}
		return;
	}else{
		ShowDebug("Got valid xmlhttp object set up local functions")		
		xmlhttp.open("POST",strURL,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	    // Create a new anonymous function that calls the handler function with saved parameters. arguments.callee is how you can reference the anonymous function from within itsself.
		ShowDebug("Create onreadystatechange function")
		//var handler=new Function("handleXMLHttpResponse(arguments.callee.xmlhttp,arguments.callee.strResultFunc,arguments.callee.param1,arguments.callee.param2)");
		var handler= function(){ handleXMLHttpResponse(arguments.callee.xmlhttp,arguments.callee.strResultFunc,arguments.callee.param1,arguments.callee.param2,arguments.callee.url,arguments.callee.submit) };
		//var handler= function(){ handleXMLHttpResponse(arguments.callee.xmlhttp,arguments.callee.strResultFunc,arguments.callee.param1,arguments.callee.param2) };
		/*	Now save the new xmlhttp as a property of the anonymous function.
			This allows you not to have to have a global XmlHttp object lying around,
			you can create them as needed and not interfere.	*/
		ShowDebug("set parameters")		
		handler.xmlhttp=xmlhttp;
		handler.strResultFunc=strResultFunc;
		handler.param1=param1;
		handler.param2=param2;
		handler.url=strURL;
		handler.submit=strSubmit;
		xmlhttp.onreadystatechange=handler;				
		xmlhttp.send(strSubmit);			
		ShowDebug("set up of local xmlhttp complete")		
	}
}
function handleXMLHttpResponse(xmlhttp,strResultFunc,param1, param2, url, submit) {         
	ShowDebug("In handleXMLHttpResponse func = " + strResultFunc + " param1 = " + param1 + " param2 = " + param2 + " url = " + url + " submit = " + submit);
	if (xmlhttp.readyState == 4) {
		strResponse = xmlhttp.responseText;
		ShowDebug("xmlhttp.readyState = 4 param1 = " + param1 + ", param2 = " + param2);		
		var statusCode = -1;
		try{
			statusCode = xmlhttp.status;	
			ShowDebug("xmlhttpPost; xmlhttpPost.status  " + xmlhttp.status);
			switch (xmlhttp.status) {								
			// Page-not-found error
				case 404:
						alert('Error: Not Found. The requested URL ' + 
								strURL + ' could not be found.');
					break;
			// Display results in a full window for server-side errors
			case 500:
				handleErrFullPage(strResponse);
				break;
			default:
				//alert("full response = " + strResponse)
				// Call JS alert for custom error or debug messages
				if (strResponse.indexOf('Error:') > -1 || 
					strResponse.indexOf('Debug:') > -1) {
					alert(strResponse);
				}
				// Call the desired result function
				else {
					if(strResultFunc!=''){
						ShowDebug("xmlhttpPost; call function " + strResultFunc + " ( "+ strResponse + ", " + param1 + ", "+ param2 + ")");
						//ShowDebug("do trace");
						//console.trace();
						//ShowDebug("done trace");
						ShowDebug("call thisFunc = "+strResultFunc + "(strResponse,param1,param2);");
						eval(strResultFunc + '(strResponse,param1,param2)');
						ShowDebug("after function call")
					}
					break;
				}
			}
		}catch(e){return;}
	}
	return;
}

function handleErrFullPage(strIn) {
	//alert("handle full error = " + strIn)
	var errorWin;	
    // Create new window and display error
    try {
		errorWin = window.open('', 'errorWin');
		errorWin.document.write('<html><head><title>Error Message</title></head><body>' + strIn + '</body></html>')
		errorWin.document.close();	
    }
    // If pop-up gets blocked, inform user
    catch(e) {
            alert('An error occurred, but the error message cannot be' +
                  ' displayed because of your browser\'s pop-up blocker.\n' +
                  'Please allow pop-ups from this Web site.\n\n\The error message was\n\n' + strIn);
    }
}


//var bAllowAjax	= true; //will be set off if no object is found to allow us to handle XMLHttp requests
//var gobjText	= '';
var gstrList	= '';
var gbReq		= false;


function categoryListing(strEntry) {
	var strEntryArray = strEntry.split('|');
    
    this.CategoryID = strEntryArray[0];
    this.Category   = strEntryArray[1];
	    
}