var TimeOutID = 0;
var PollingTimeOutID = 0;

function SetMenuTimeout() {
   ResetTimeout();
   TimeOutID = setTimeout('ClearDownMenu();',2000);
}

function ClearDownMenu() {
   MM_showHideLayers('MenuCompanies','','hide','MenuContacts','','hide','MenuVacancies','','hide','MenuBookings','','hide','MenuCandidates','','hide','MenuNotifications','','hide','MenuBookmarks','','hide','MenuReports','','hide','MenuAdministration','','hide','MenuBookmarksCo','','hide','MenuBookmarksCt','','hide','MenuBookmarksVc','','hide','MenuBookmarksCa','','hide','MenuAgencies','','hide');
   document.frmUserNavigation.recordjumpurl.style.visibility='visible';
}

function ResetTimeout() {
   clearTimeout(TimeOutID);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function CheckEmail(formname,fieldname) {
	
	// If the email entry box has something in it carry out the email
	// address validation, otherwise just return true
	if (formname.value.length > 0) {
		
		// split the entered string at the @ sign, if 
		// there aren't at least 2 array elements created
		// no @ sign was entered so therefore it is an
		// invalid email address so return false.
		string = formname.value;
		check_for_at = string.split("@");
		
		if ( ! check_for_at[0] || ! check_for_at[1] ) {
			alert(fieldname + ' must be a valid email address');
			return false;
		} else {
			
			// If there is a valid @ sign, split the second 
			// half of the string by the first dot.  If 
			// there aren't at least 2 array elements created
			// no . was entered so therefore it is an
			// invalid email address so return false.
			check_for_dot = check_for_at[1].split(".");
			if ( ! check_for_dot[0] || ! check_for_dot[1] ) {
				alert(fieldname + ' must be a valid email address');
				return false;
			}
		}
	}
	return true;
}

function CheckBlank(formname,fieldname) {
	// If nothing has been entered return false
	var CurrentValue;
	CurrentValue = formname.value;
	
	CurrentValue = trim(CurrentValue);
	formname.value = CurrentValue;
	
	if (CurrentValue.length < 1) {
		alert('Please complete the "' + fieldname + '" field.');
		return false;
	} else {
		return true;
	}
}

function CheckSelect(formname,fieldname,bMulti,Maxnoitems,bNoItems) {
	
	// If this is NOT a multi select
	if ( ! bMulti ) {
		
		// If the user is NOT allowed to select nothing (sounds a bit
		// strange but bear with me...)
		if ( ! bNoItems ) {
			
			// Check they haven't just selected the default option
			// or even just not selected anything at all.  If this is
			// the case return false.
			mySelectedIndex = formname.selectedIndex;
			if ( formname.options[mySelectedIndex].value<1 || formname.options[mySelectedIndex].value=="" ) {
				alert('Please select ' + fieldname);
				return false;
			} 
		} 
		return true;
	
	// If this IS a multi select list
	} else {
		
		// If the user is NOT allowed to select nothing (sounds a bit
		// strange but bear with me...)
		if ( ! bNoItems ) {
			
			// If selectedIndex is a negative value nothing
			// has been selected so print error and return false
			mySelectedIndex = formname.selectedIndex;
			if ( mySelectedIndex < 0 ) {
				alert('Please select ' + fieldname);
				return false;
			}
			
			// If a maximum number of items has been set check
			// that the user hasn't selected more.  If they have
			// print the error and return false.
			if ( Maxnoitems > 0 ) {
				numSelected = 0;
				for ( i=0; i<formname.options.length ; i++ ) {
					if ( formname.options[i].selected ) {
						numSelected++;
					}
				}
				if ( numSelected > Maxnoitems ) {
					alert('Only ' + Maxnoitems + ' options can be selected from the ' + fieldname + ' list');
					return false;
				}
			}
			return true;
		} else {
			// If the user IS allowed to select nothing, just check that 
			// they haven't selected more than the maximum allowed (if
			// it is set)
			if ( Maxnoitems > 0 ) {
				numSelected = 0;
				for ( i=0; i<formname.options.length ; i++ ) {
					if ( formname.options[i].selected ) {
						numSelected++;
					}
				}
				if ( numSelected > Maxnoitems ) {
					alert('Only ' + Maxnoitems + ' options can be selected from the ' + fieldname + ' list');
					return false;
				}
			}
			return true;
		}
		
	}

}

function contains(smstring,lrgstring) {
        //returns true if lrgstring contains smstring.
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        istrue = false
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        istrue = true
                        break
                }
        }
        return istrue
}

function lcase(str) {
        //returns str in all lowercase letters.
        return str.toLowerCase()
}


function left(str,n) {
        //returns the left n characters from str.
        return str.substring(0,n)
}

function leftOf(smstring,lrgstring) {
        //returns leftmost characters of lrgstring up to smstring.
        //If user passes an empty string, change that to a space.
        if (smstring == ""){smstring = " "}
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return lrgstring.substring(0,(foundat-1))
}

function mid(str,start,n) {
        //returns a substring of str starting at 'start' that's n characters long.
        strlen = str.length
        var jj = str.substring(start-1,strlen)
        jj = jj.substring(0,n)
        return jj
}

function pcase(str) {
        //returns str in proper-noun case (first letter uppercase)
        strlen = str.length
        jj = str.substring(0,1).toUpperCase()
        jj = jj + str.substring(1,strlen).toLowerCase()
        for (i = 2; i <= strlen; i++) {
                if (jj.charAt(i)==" ") {
                        lefthalf = jj.substring(0,i+1)
                        righthalf = jj.substring(i+1,strlen)
                        righthalf = righthalf.substring(0,1).toUpperCase()+righthalf.substring(1,strlen)
                        jj=lefthalf+righthalf
                }
        }
        return jj
}

function right(str,n) {
        //returns the right n characters of str
        strlen = str.length
        return str.substring(strlen-n,strlen)
}

function rightOf(smstring,lrgstring) {
        //returns the rightmost characters of lrgstring back to smstring.
        //If user passes an empty string, change that to a space.
        if (smstring == ""){smstring = " "}
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=strlen2;i>=0;i--) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return lrgstring.substring(foundat,255)
}

function spot(smstring,lrgstring) {
        //returns a number indicating the spot where smstring appears in lrgstring.
        strlen1 = smstring.length
        strlen2 = lrgstring.length
        foundat = 0
        for (i=0;i<=strlen2;i++) {
                comp=lrgstring.substring(i-1,strlen2)
                comp = comp.substring(0,strlen1)
                if (comp == smstring) {
                        foundat = i
                        break
                }
        }
        return foundat
}



function ucase(str) {
        //returns str in all uppercase letters.
        return str.toUpperCase()
}



// Submit a form (rather than using a submit image) and set the command value
function submitForm(formname,strCommand) {

   var thisObj = eval("document." + formname);
   thisObj.command.value = strCommand;
   thisObj.submit();

}

function setCookie(name, value, expires, path, domain, secure) {
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments

  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds

  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function check_date(field,fieldname){
   var checkstr = "0123456789";
   var DateField = field;
   var Datevalue = "";
   var DateTemp = "";
   var seperator = "/";
   var day;
   var month;
   var year;
   var leap = 0;
   var err = 0;
   var i;
   err = 0;
   DateValue = DateField.value;

   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
   	year = DateValue.substr(4,2);
   	if (year <= 50) {
      		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2);
      	}
      	else {
      		DateValue = DateValue.substr(0,4) + '19' + DateValue.substr(4,2);
      	}
   }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
     alert("Please enter a valid date (dd/mm/yyyy) in the " + fieldname + "field");
     DateField.select();
     DateField.focus();
   }
}

function CheckLength (formname,fieldname,minlength,maxlength) {
	if (minlength != 0) {
		if (formname.value.length < minlength) {
			alert(fieldname + ' must be greater than ' + minlength + ' characters.');
			return false;
		}
	}
	if (maxlength != 0) {
		if (formname.value.length > maxlength) {
			alert(fieldname + ' must be less than ' + maxlength + ' characters.');
			return false;
		}
	}

	return true;
}


function cleanNumber(inputNum, bIsFloat)
     {
     var i;
     var ch;
      var outputNum = "";
     // walk through the string character by character to build a new string with numbers only
     i = 0;
     while (i < inputNum.length)
     {
        // get the current character
        ch = inputNum.substring(i, i+1);

        if ((ch >= "0") && (ch <= "9"))
        {
           // if the current character is a digit then add it to the numbers-only string we're building
           outputNum += ch;
        }
        else
        {
           if ((bIsFloat) && (ch == ".")){
             outputNum += ch;
           }
        }

        i++;
     }
     // we got here if we didn't fail, so return what we built
      return outputNum;
}

function DisplayHelp (url) {
   var strFile

   strFile = '/' + url

   strFile = leftOf('.asp',strFile);
   strFile = rightOf('/',strFile);

   strFile = '/help.asp?topic=' + strFile

   window.open(strFile,'help','left=1,top=1,height=500,width=620,scrollbars=yes');
}

function CheckTime (formfield,fieldname,blankallowed) {
	var timevalid = true;
	var hours;
	var mins;
	
	if (formfield.value == '' && !blankallowed) {
		alert('Please complete the ' + fieldname + ' field.');
		return false;
	}
	
	if (formfield.value != '') {
		if (formfield.value.length == 5) {
			hours = formfield.value.substring(0,2);
			if (hours.substring(0,1) == '0') {
				hours = hours.substring(1,2);
			}
//			alert('hours = ' + hours);
			mins = formfield.value.substring(3,5);
			if (mins.substring(0,1) == '0') {
				mins = mins.substring(1,2);
			}
//			alert('mins = ' + mins);

			if (!IsNumeric(hours,false)) {
				timevalid = false;
			}
			if (timevalid && (hours < 0 || hours > 23)) {
//				alert('hours not valid');
				timevalid = false;
			}
			if (timevalid && !IsNumeric(mins,false)) {
				timevalid = false;
			}
			if (timevalid && (mins < 0 || mins > 59)) {
//				alert('mins not valid');
				timevalid = false;
			}
		}
		else {
			timevalid = false;
		}
		
		if (!timevalid) {
			alert(formfield.value + ' is not a valid time. Please enter in HH:MM format.');
			return false;
		}
	}
	
	return true;
}

function CheckNumeric (formfield,fieldname,blankallowed,isfloat) {
	if (formfield.value == '' && !blankallowed) {
		alert('Please complete the ' + fieldname + ' field.');
		return false;
	}
	else {
		if (formfield.value != '') {
			if (!IsNumeric(formfield.value,isfloat)) {
				alert('Please enter numbers only in the ' + fieldname + ' field.');
				return false;
			}
		}
	}
	
	return true;
}

function IsNumeric (number,isfloat) {
	var numvar;
	
	if (isfloat) {
		numvar = parseFloat(number);
	}
	else {
		numvar = parseInt(number);
	}
	
//	alert('numvar = ' + numvar);
//	alert('number = ' + number);
//	alert(numvar == number);
	
	if (numvar == 'NaN' || numvar != number) {
		return false;
	}
	
	return true;
}

function OpenNRPopup (url, winname, width, height, options) {
	var w = 480, h = 340;
	
	if (document.all || document.layers) {
	  w = screen.availWidth;
	  h = screen.availHeight;
	}

	var leftPos = (w-width)/2, topPos = (h-height)/2;

	window.open(url,winname,'width=' + width + ',height=' + height + ',top=' + topPos + ',left=' + leftPos + ',' + options);
}

function updateDepartments (deptlistname,officeid,nonetext) {
	var list = eval(deptlistname);
	
	// Delete all entries from the Department list
	// except the first and select the first entry
	list.length = 1;
	list.selectedIndex = 0;
	
	if (officeid > 0) {
		list[0].text = ' ';
		
		var arrDeptNames = eval('arrDeptNames' + officeid);
		var arrDeptIds = eval('arrDeptIds' + officeid);
		
		list.length = 1 + arrDeptNames.length;
		
		var i;
		for (i=0; i < arrDeptNames.length; i++) {
			list[i + 1].text = arrDeptNames[i];
			list[i + 1].value = arrDeptIds[i];
		}
	
		if (arrDeptNames.length==0) { list[0].text = nonetext; }
	}
	else {
		list[0].text = nonetext;
	}
}

function GenerateCorrespondence(strType, strUssnid, strA, strB, strC, strD, strE, strF, strG, strH){

   var strLinkURL

   if (strType == '0' || strType == '') {
      alert('You must firstly select a correspondence type.');
      return false;
   }

	strLinkURL = '/scnCorrespondenceGenerate.asp?ussnid=' + strUssnid + '&type=' + strType + '&a=' + strA + '&b=' + strB + '&c=' + strC + '&d=' + strD + '&e=' + strE + '&f=' + strF + '&g=' + strG + '&h=' + strH;
	strJavascript = OpenNRPopup(strLinkURL,'Correspondence',780,500,'scrollbars=yes');

}

function ActionEvent(strUssnid, intPlannerID, strReturnURL) {
	strLinkURL = '/frmEventAction.asp?ussnid=' + strUssnid + '&returnurl=' + escape(strReturnURL) + '&pln_id=' + intPlannerID;
	strJavascript = OpenNRPopup(strLinkURL,'ActionEvent',500,410,'scrollbars=yes');
}

function ScheduleEvent(strUssnid, intSystemEntity, intCompany, intContact, intVacancy, intCandidate, intPlacement, intBooking, strReturnURL) {
   strLinkURL = '/frmPlannerSchedule.asp?ussnid=' + strUssnid + '&syse=' + intSystemEntity + '&co_id=' + intCompany + '&ct_id=' + intContact + '&vc_id=' + intVacancy + '&ca_id=' + intCandidate + '&pl_id=' + intPlacement + '&bk_id=' + intBooking + '&returnurl=' + escape(strReturnURL)
	strJavascript = OpenNRPopup(strLinkURL,'LogEvent',500,270,'scrollbars=yes');
}

function setCheckAll(OnOffFlip)
{
	// 0=off, 1=on, other=flip
	var cb=document.getElementsByTagName('input');
	for (var i=0;i<cb.length;i++)
	{
		if (OnOffFlip!=0&&OnOffFlip!=1)
		{cb[i].checked=!cb[i].checked}else{cb[i].checked=OnOffFlip;}
	}
}

function getTop(ll) {
	if (ll.offsetParent)
		return (ll.offsetTop + getTop(ll.offsetParent));
	else
		return (ll.offsetTop);
}

function getLeft(ll) {
	if (ll.offsetParent)
		return (ll.offsetLeft + getLeft(ll.offsetParent));
	else 
		return (ll.offsetLeft);
}

function getWidth(ll) {
	return (ll.offsetWidth);
}

function DisplayMenu(menu) {
   var posLeft;
   var posTop;
   
   ResetTimeout();
   ClearDownMenu();
   
   // Move the sub menu to the correct point
   posLeft = getLeft(document.getElementById(menu + 'Position'));
   posTop = getTop(document.getElementById(menu + 'Position'));
   
   document.getElementById(menu).style.left = posLeft + 'px';
   document.getElementById(menu).style.top = posTop + 19 + 'px';
   
   if ((getLeft(document.getElementById('recordjumpurl'))) < (getLeft(document.getElementById(menu)) + getWidth(document.getElementById(menu)))){
      document.frmUserNavigation.recordjumpurl.style.visibility='hidden';
   }
   
   MM_showHideLayers(menu,'','show');
   SetMenuTimeout();
}

function DisplaySubMenu(menu) {
   var posLeft;
   var posTop;
   
   ResetTimeout();
   
   // Move the sub menu to the correct point
   posLeft = getLeft(document.getElementById(menu + 'Position'));
   posTop = getTop(document.getElementById(menu + 'Position'));
   
   document.getElementById(menu).style.left = posLeft + 98 + 'px';
   document.getElementById(menu).style.top = posTop - 1 + 'px';
   
   document.frmUserNavigation.recordjumpurl.style.visibility='visible';
   
   if ((getLeft(document.getElementById('recordjumpurl'))) < (getLeft(document.getElementById(menu)) + getWidth(document.getElementById(menu))) && (getTop(document.getElementById(menu)) < 30)){
      document.frmUserNavigation.recordjumpurl.style.visibility='hidden';
   }
   
   MM_showHideLayers('MenuCompanies','','hide','MenuContacts','','hide','MenuVacancies','','hide','MenuCandidates','','hide','MenuNotifications','','hide','MenuBookmarks','','show','MenuReports','','hide','MenuAdministration','','hide','MenuBookmarksCo','','hide','MenuBookmarksCt','','hide','MenuBookmarksVc','','hide','MenuBookmarksCa','','hide','MenuBoookings','','hide','MenuAgencies','','hide');
   MM_showHideLayers(menu,'','show');
   SetMenuTimeout();
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function MessagePollingInitiate(lngCurrentUserId, strSessionID)
{
	// Poll now
	MessagePollingPoll(lngCurrentUserId, strSessionID);
	
	// Then poll every 15 seconds
	PollingTimeOutID = setTimeout('MessagePollingPoll(' + lngCurrentUserId + ',\'' + strSessionID + '\');',15000);
}

function MessagePollingPoll(lngCurrentUserId, strSessionID)
{
//	return true;

	// Performs the message polling from xml_NotificationsPoll.asp
	var MessageSpan = document.getElementById('ConsultantMessage');
	var CompareSpan = document.getElementById('ConsultantMessageCompare');
	var ResponseText = "";
	
	// Create the XML object
	var xml = false;
	xml = new ActiveXObject("Microsoft.XMLHTTP");
	
	// Perform the postback
	if (xml) {
		xml.open("post", "xml_NotificationsPoll.asp", true);
		xml.onreadystatechange = function() {
			if (xml.readyState == 4) {
				if (xml.responseText) {
					if (xml.status != '200'){
						//alert('Please contact HotLizard quoting error: \n\n  ' + xml.status + " : " + xml.statusText + '\n\nduring poll action.');
					}
					//alert(xml.responseText); // Debug only
					if (!contains('<!--***DONE***-->',xml.responseText)){
						// Invalid response
						//alert('Please contact HotLizard quoting error: \n\n   Unrecognised polling response.');
					}
					else {
						if (left(xml.responseText,15) == '!!!TERMINATE!!!'){
							// Force expiry
							
							location.replace('/frmUserLogin.asp?mode=terminated&ussnid=' + strSessionID + '&returnurl=%2FlstPlanner%2Easp');
						}
						else {
							// Message to be displayed
							ResponseText = xml.responseText;
							
							// Put text in invisible comparespan, so that when innerHTML is referenced
							// it is the same as that we are trying to compare (comments stripped etc.)
							CompareSpan.innerHTML = ResponseText;
							
							if (CompareSpan.innerHTML != MessageSpan.innerHTML){
								// Only update span, if it hasn't changed
								// This is to prevent scrolling oddities
								MessageSpan.innerHTML = ResponseText;
							}
							
							CompareSpan.innerHTML = "";
							
							// Make a noise if it's got the ALERT tag
							if (contains('<!--ALERT-->',xml.responseText)){
						   	document.sndNotification.play();
						   }
						}
					}
				}
			}
		}
	   xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xml.send("rand=" + Math.random() + "&us_id=" + lngCurrentUserId + "&ussnid=" + strSessionID + "&command=POLL");
	}
	
	PollingTimeOutID = setTimeout('MessagePollingPoll(' + lngCurrentUserId + ',\'' + strSessionID + '\');',15000);
}

function MessageClear(lngCurrentUserId, strSessionID, lngMessageStackId)
{
	clearTimeout(PollingTimeOutID);

	// Performs the message clearing from xml_NotificationsPoll.asp
	var ResponseText = "";
	
	// Create the XML object
	var xml = false;
	xml = new ActiveXObject("Microsoft.XMLHTTP");
	
	// Perform the postback
	if (xml) {
		xml.open("post", "xml_NotificationsPoll.asp", true);
		xml.onreadystatechange = function() {
			if (xml.readyState == 4) {
				if (xml.responseText) {
					if (xml.status != '200'){
						//alert('Please contact HotLizard quoting error: \n\n  ' + xml.status + " : " + xml.statusText + '\n\nduring message clear.');
					}
					//alert(xml.responseText); // Debug only
					if (!contains('<!--***DONE***-->',xml.responseText)){
						// Invalid response
						//alert('Please contact HotLizard quoting error: \n\n   Unrecognised message clear response.');
					}
				}
			}
		}
	   xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xml.send("rand=" + Math.random() + "&us_id=" + lngCurrentUserId + "&ussnid=" + strSessionID + "&msgst_id=" + lngMessageStackId + "&command=CLEAR");
	}
	
	MessagePollingPoll(lngCurrentUserId, strSessionID);
	PollingTimeOutID = setTimeout('MessagePollingPoll(' + lngCurrentUserId + ',\'' + strSessionID + '\');',15000);
}

function ChangePassword(ussnid){
	var strURL;
	strURL = '/frmPasswordChange.asp?ussnid=' + ussnid;
	
	OpenNRPopup(strURL,'ChangePassword',500,380,'scrollbars=yes');
}

function ExportCSV(strUssnid, intSystemEntity, strSource, intLinkId) {
	strLinkURL = '/frmCSVExport.asp?ussnid=' + strUssnid + '&syse=' + intSystemEntity + '&src=' + strSource + '&linkid=' + intLinkId;
	strJavascript = OpenNRPopup(strLinkURL,'ExportCSV',500,340,'scrollbars=yes');
}


