// Dependencies:
// jquery
// 
var GAEnabled=false;
var g_MqRef;
var BUILD_NUMBER = "7.7.0.319.020";

try{
	if (!g_MqRef)
	{
	  if (window==top){
		g_MqRef=window;
	  }else{
		if (parent.g_MqRef){
			g_MqRef=parent.g_MqRef;
		}else{
			g_MqRef=window;
		}
	  }
	 }
}catch(e){
	g_MqRef=window;	
}


function ConfirmBox()
{
	function show(title, message)
    {
		var defer = $.Deferred(); 
        $.confirm({
                    title: title,
                    content:message,
					columnClass: 'col-md-6 col-md-offset-3',
					boxWidth: '50%',
					useBootstrap: false,
					type: 'dark',
					typeAnimated: true,
                    buttons: {
						 confirm: {
							text: g_MqRef.RESX.Get("YES"),
							btnClass: 'btn-blue',
							keys: ['enter', 'shift'],
							action: function(){
								defer.resolve(true);
							}
						 },
						 cancel:{
							text: g_MqRef.RESX.Get("NO"),
							btnClass: 'btn-blue',
							keys: ['enter', 'shift'],
							action: function(){
								defer.resolve(false);
							}
						 }
                    }
                });

		return defer;
    }

	this.show = show;
}

function AlertBox()
{
	function show(title, message)
	{
		var defer = $.Deferred(); 
        
		$.alert({
			title:title,
			content: message,
			boxWidth: '50%',
			type: 'dark',			
			useBootstrap: false,
			buttons: {
				ok: {
					btnClass: 'btn-blue',
					action: function () {
						defer.resolve(true);
					}
				}
			}
		});

		return defer;
	}
	this.show = show;
}

function searchForChar(strSearch,strChar,blnRev)
{
	var intPosition;
	
  strSearch=String(strSearch);
  
	intPosition=-1;
			
	if (!blnRev){
    intPosition=strSearch.indexOf(strChar);
	}else{
    intPosition=strSearch.lastIndexOf(strChar);
	}
		
	return intPosition;
}

function getPath(strPath, strPathDelim)
{
  var strReturn;
  if (!strPathDelim){
    strPathDelim="/";
  }
  strReturn=strPath.substring(0,searchForChar(strPath,strPathDelim,true)+1);
  return strReturn;
}

function CMqArrayMgr()
{
	function IsValueInArray(varValue,varArray)
	{
		
		var blnResult=false;
		if (varArray){
			if (varArray.length){
				for(var lngIndex=0;lngIndex<varArray.length;lngIndex++){
					if (varArray[lngIndex]){
						if (varValue==varArray[lngIndex]){
							blnResult=true;
							break;				
						}
					}
				}
			}
		}
		return blnResult;
	}
	
	function GetIndex(varValue,varArray)
	{
		var lngIndexOut=-1;
		if (varArray){	
			var strValue=String(varValue);
			for(var lngIndex=0;lngIndex<varArray.length;lngIndex++){
				if (varArray[lngIndex]){
					if (strValue==String(varArray[lngIndex])){
						lngIndexOut=lngIndex;
						break;				
					}
				}
			}			
		}
		return lngIndexOut;
	}
	
	//supports one-dimensional arrays only
	function RemoveDuplicateElements(varArray){
		
		var arrUniques = new Array();
		var lngTotalCount=0;
		var x;
				
		for(x=0; x < varArray.length; x++) {
			if(!IsValueInArray(varArray[x], arrUniques)){
				arrUniques[lngTotalCount]=varArray[x];
				lngTotalCount++;
			}
		} 
				
		return arrUniques;
	}	
	this.GetIndex=GetIndex;
	this.IsValueInArray=IsValueInArray;
	this.RemoveDuplicateElements=RemoveDuplicateElements;
} 

function CMqEventUtils() {

	function CancelEventBubble(e, blnBrowserIndependent){
		
		WriteConsole("[CancelEventBubble] Browser independent? " + blnBrowserIndependent);
		
		if(g_MqRef.MqBrowser.ie){
			e.cancelBubble = true;
			e.returnValue = false;
		}else{
			if(blnBrowserIndependent){
				e.cancelBubble = true;
			}
		}
	}
	
	function GetKeyCode(event){
		var keynum;
		
		try{
			if(window.event){
				 keynum = event.keyCode;
			}else{
				if(event.which){ 
					// Netscape/Firefox/Opera
					keynum = event.which;
				}
			}
		}catch(err){
			keynum = 0;
		}
		return keynum;
	}
	
	this.CancelEventBubble=CancelEventBubble;
	this.GetKeyCode=GetKeyCode;
}

function CMqBrowserDetector() {
	var n = navigator;
	// string comparisons are much easier if we lowercase everything now.
	// to make indexOf() tests more compact/readable, we prepend a space 
	// to the userAgent string (to get around '-1' indexOf() comparison)
	var ua = ' ' + n.userAgent.toLowerCase();
	var pl = n.platform.toLowerCase(); // not supported in NS3.0
	var an = n.appName.toLowerCase();

	// browser version
  var appVer=n.appVersion.toLowerCase();
	this.version = appVer;
  
	this.nn = ua.indexOf('mozilla') > 0;

	// 'compatible' versions of mozilla aren't navigator
	if(ua.indexOf('compatible') > 0) {
	  this.nn = false;
	}

	this.opera = ua.indexOf('opera') > 0;
	this.webtv = ua.indexOf('webtv') > 0;
	this.ie = ua.indexOf('trident') > 0;
	if (!this.ie)
	{
		this.ie = ua.indexOf('msie') > 0;
	}
	this.aol = ua.indexOf('aol') > 0;
	this.omniweb = ua.indexOf('omniweb') > 0;
	this.galeon = ua.indexOf('galeon') > 0;  
	this.firefox = ua.indexOf('firefox') > 0; 
	this.chrome = ua.indexOf('chrome') > 0;
	
  // On ie, start of appVersion returns 3 or 4
  // which is the version of Netscape it is compatible with,
  // so look for the real version further on in the string
  if (this.ie) {
    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
	      this.minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
        this.major = parseInt(this.minor);
    }
  }else{
    // Netscape6 is mozilla/5 + Netscape6/6.0!!!
    // Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
    var nav6Pos = ua.indexOf('netscape6');
    if (nav6Pos !=-1) {
       this.minor = parseFloat(ua.substring(nav6Pos+10));
       this.major = parseInt(this.minor);
    }else{
        this.major = parseInt( appVer );
	      this.minor = parseFloat( appVer );
    }
  }
  
	function checkMobile() {
		var check = false;
		(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
		return check; 
	}
	
	// platform
	this.mac = ua.indexOf('mac') > 0;
	this.mac68k = (ua.indexOf('68k') > 0 || ua.indexOf('68000') > 0);
	this.macppc = (ua.indexOf('ppc') > 0 || ua.indexOf('powerpc') > 0);
	this.win = ua.indexOf('win') > 0;
	this.win16 = (ua.indexOf('16') > 0 && ua.indexOf('win') > 0);
	this.win31 = this.win16;
	this.win95 = (ua.indexOf('95') > 0 && ua.indexOf('win') > 0);
	this.win98 = (ua.indexOf('98') > 0 && ua.indexOf('win') > 0);
	this.winme = (ua.indexOf('win 9x 4.90') > 0 && ua.indexOf('win') > 0);
	this.winnt = (ua.indexOf('nt') > 0 && ua.indexOf('win') > 0);
	this.win2k = (ua.indexOf('nt 5') > 0 && ua.indexOf('win') > 0);
	this.os2 = ua.indexOf('os/2') > 0;
	this.sun = ua.indexOf('sunos') > 0;
	this.irix = ua.indexOf('irix') > 0;
	this.hpux = ua.indexOf('hpux') > 0;
	this.aix = ua.indexOf('aix') > 0;
	this.dec = (ua.indexOf('dec') > 0 || ua.indexOf('alpha') > 0 || ua.indexOf('osf1') > 0 || ua.indexOf('ultrix') > 0);
	this.sco = (ua.indexOf('sco') > 0 || ua.indexOf('unix_sv') > 0);
	this.vms = (ua.indexOf('vax') > 0 || ua.indexOf('openvms') > 0);
	this.linux = ua.indexOf('linux') > 0;
	this.sinix = ua.indexOf('sinix') > 0;
	this.reliant = ua.indexOf('reliantunix') > 0;
	this.freebsd = ua.indexOf('freebsd') > 0;
	this.openbsd = ua.indexOf('openbsd') > 0;
	this.netbsd = ua.indexOf('netbsd') > 0;
	this.bsd = ua.indexOf('bsd') > 0;
	this.unixware = ua.indexOf('unix_system_v') > 0;
	this.mpras = ua.indexOf('ncr') > 0;
	this.unix = ua.indexOf("x11") > 0;
	this.mobile = checkMobile();
	
	// workarounds
	// - IE5/Mac reports itself as version 4.0
	if(this.ie && this.mac) {
	  if(ua.indexOf("msie 5")) {
	    this.major = 5;
	    var actual_index = ua.indexOf("msie 5");
	    var actual_major = ua.substring(actual_index + 5, actual_index + 8);
	    this.minor = parseFloat(actual_major);
	  }
	}

	return this;
}


function MqString(){
	var DEFAULT_DELIMITER=",";
	var ARG_STRING="%";
	var cenNo_Encode = 0;
    var cenURL_Encode = 1;
    var cenCookie_Encode = 2;
    var cenURI_Encode = 3;
    var cenURIComponent_Encode = 4;
    
	function getChar(intNumber,strString){
		var blnRev;
		var intLength;
		var strReturn;
			
		if (intNumber<0) {
			blnRev=true;
		}else{
			blnRev=false;
		}		
		intNumber=Math.abs(intNumber);
		intLength=strString.length;
		if (intNumber>intLength){
			intNumber=intLength;
		}
		strReturn=(blnRev)?strString.substring(intLength-intNumber,intLength):strString.substring(0,intNumber);
		return strReturn;
	}
		
	function getNullTerminatedString(strString){
		var intCounter;
		var strTemp;
		strString=String(strString);
		for (intCounter=strString.length;intCounter>0;intCounter--){
			strTemp=strString.substr(strString.length-1,1);
			if (strTemp.toString().charCodeAt(0)==13 || strTemp.toString().charCodeAt(0)==10){
				strString=strString.substr(0,strString.length-1);
			}else{
				intCounter=0;
			}
			
		}
	
		return strString;
	}
	
	function TrimString(strToTrim){
			while (strToTrim.charAt(0) == " "){
				strToTrim = strToTrim.substr(1, strToTrim.length);
			}
			while (strToTrim.charAt(strToTrim.length - 1) == " "){
				strToTrim = strToTrim.substr(0, strToTrim.length - 1);
			}
			return (strToTrim);
	}
	function Right(strString,lngLength)
	{
		var intStringLength;
			
		intStringLength=strString.length;
			
		return (strString.substring(intStringLength-lngLength, intStringLength));
			
	}

	function Left(strString,lngLength)
	{
			
		return (strString.substring(0, lngLength));
		
	}
	
	function Mid(strString,lngStart,lngLength)
	{
		return (strString.substr(lngStart, lngLength));	
	}
	
	function GetPropertyValue(strPropertyName, strToSearchIn,blnUnescapeValue, strPropertyDelim,strPropertyValueDelim){
		var strPropertyValue = "";
		var PROPERTY_DELIM=";";
		var PROPERTY_VALUE_DELIM="=";
		var varProperties;
		if (!strPropertyDelim){
			strPropertyDelim=PROPERTY_DELIM;
		}
		
		if (!strPropertyValueDelim){
			strPropertyValueDelim=PROPERTY_VALUE_DELIM;
		}
		if (strToSearchIn && strPropertyName){
			varProperties=strToSearchIn.split(strPropertyDelim);
		}
		
		if (varProperties){
			
			strPropertyValue=GetPropertyValue_FromArray(varProperties,strPropertyName,strPropertyValueDelim);
		}
	
		if (blnUnescapeValue){
			strPropertyValue=MqDecodeURIComponent(strPropertyValue);
		}
		
		return strPropertyValue;
		
		
	}
	
	function ReplacePropertyValue(strCommandLine, strPropertyName, strNewPropertyValue, strDelim, strElementDelim)
	{	
		var NAME_ELEMENT=0;
		var VALUE_ELEMENT=1;
		
		var arrPropertyPair;
		var lngCount;
		var strResult;
		var blnFound=false;
		
		
		var arrProperties=strCommandLine.split(strDelim);
		
		for(lngCount=0; lngCount<arrProperties.length; lngCount++){
			
			arrPropertyPair=arrProperties[lngCount].split(strElementDelim);
			
			if(arrPropertyPair[NAME_ELEMENT]==strPropertyName){
				arrProperties[lngCount]=arrPropertyPair[NAME_ELEMENT] + strElementDelim + strNewPropertyValue;
				lngCount=arrProperties.length;
			}
		}
		
		strResult=arrProperties.join(strDelim);

		return strResult;
	}
	
	function PropertyExists(strCommandLine, strPropertyName, strDelim, strElementDelim)
	{
		var NAME_ELEMENT=0;
		
		var arrPropertyPair;
		var lngCount;
		var lngReturn=-1;
		
		var arrProperties=strCommandLine.split(strDelim);
		
		for(lngCount=0; lngCount<arrProperties.length; lngCount++){
			
			arrPropertyPair=arrProperties[lngCount].split(strElementDelim);
			
			if(arrPropertyPair[NAME_ELEMENT]==strPropertyName){
				lngReturn=lngCount;
				lngCount=arrProperties.length;
			}
		}
		return lngReturn;
	}
	
	function GetQueryStringValue(strCommandLine,strQSName,blnSkipUnescape)
	{
		var QUERY_STRING_DELIM="&";
		var QUESTION_MARK="?";

		if ( strCommandLine==null || typeof(strCommandLine)=="undefined")
		{
			strCommandLine=window.location.search;
		}
		
		if (Left(strCommandLine,QUESTION_MARK.length)==QUESTION_MARK){
			strCommandLine=Right(strCommandLine,(strCommandLine.length-QUESTION_MARK.length));
		}

		if(blnSkipUnescape){
			return GetPropertyValue(strQSName, strCommandLine, false, QUERY_STRING_DELIM);
		}else{
			return GetPropertyValue(strQSName, strCommandLine, true, QUERY_STRING_DELIM);
		}
		
	}		

	function AddToQueryString(sURL,sQSField,sQSValue)
	{
		var QS_DELIM="&";
		
		if (!sURL)
		{
			sURL="";
		}

		if(sQSField!=="")
		{
			if(typeof(sQSValue)!="undefined")
			{
				if(sURL!="")
				{
					sURL+=QS_DELIM;
				}
					
				sURL+= sQSField + "=" + MqEncodeURIComponent(sQSValue);
			}
		}

		return sURL;
	}		
	
	function FormatString(strString,strArgs,strDelim,blnUnescape)
	{
		if (!strDelim){
			strDelim=DEFAULT_DELIMITER;
		}
		if (strArgs){
			var arrArgs = strArgs.split(strDelim);
			var regExp;
			var strValue;
			for(var lngCount=0; lngCount<arrArgs.length; lngCount++){
				regExp=new RegExp(ARG_STRING+(lngCount+1),"g");
				strValue=arrArgs[lngCount];
				if (blnUnescape){
					 strValue=MqDecodeURIComponent(strValue);
				}
				if (!strString){
					strString="%1";
				}
				strString=strString.replace(regExp, strValue);
			}
		}
		return strString;
	}

	function StripLeading(strString, strRemoveString)
	{
		var strReturn =strString;
		if (strString && strRemoveString) {
			var lngRemoveStringLen=strRemoveString.length;
			var strLeft=strString.substring(0, lngRemoveStringLen);
			if (strLeft.toLowerCase()==strRemoveString.toLowerCase()){
				strReturn=strString.substring(lngRemoveStringLen, strString.length);
			}
		}
		return strReturn;
	}
	function StripTrailing(strString, strRemoveString)
	{
		var strReturn =strString;
		if (strString && strRemoveString) {
			var lngRemoveStringLen=strRemoveString.length;
			var strStringLen=strString.length;
			var strRight=strString.substring(strStringLen -lngRemoveStringLen, strStringLen);
			if (strRight.toLowerCase()==strRemoveString.toLowerCase()){
				strReturn=strString.substring(0, strStringLen -lngRemoveStringLen);
			}
		}
		return strReturn;
	}
	function Format(strString)
	{
		try{
			var regExp;
			if (strString){
				if (arguments){
					for(var i=1;i<arguments.length;i++){
						regExp=new RegExp(ARG_STRING+i,"g");
						strString=strString.replace(regExp,arguments[i]);
					}
				}
			}else{
				if (Format.caller !== null){
					console.log("Invalid string passed from " + Format.caller.toString());
				}
			}
		}catch(e)
		{
			console.log(e);
		}
		
		return strString;
	}

	function MqDecodeURI(strURI)
	{
		if(window.decodeURI){
			return window.decodeURI(strURI);
		}else{
			return unescape(strURI);
		}
	}
	
	function MqDecodeURIComponent(strURIComponent)
	{
		if(window.decodeURIComponent){
			return window.decodeURIComponent(strURIComponent);
		}else{
			return unescape(strURIComponent);
		}
	}
	
	function MqEncodeURI(strURI)
	{
		if(window.encodeURI){
			return window.encodeURI(strURI);
		}else{
			return GetEncodedString(strURI,cenURI_Encode);
		}
	}
	function MqEncodeURIComponent(strURIComponent)
	{
		if(window.encodeURIComponent){
			return window.encodeURIComponent(strURIComponent);
			
		}else{
			return GetEncodedString(strURIComponent,cenURIComponent_Encode);
		}
	}	
	
	function GetEncodedString(strURIComponent,lngEncodeType)
	{
		var lngCounter;
		var strChar;
		var strEncodeStr="";
	
		var lngStrLength=strURIComponent.length;

		if(lngStrLength > 0){
	        for(lngCounter=0; lngCounter<lngStrLength; lngCounter++){
				strChar = Mid(strURIComponent, lngCounter, 1);
				if(strChar.length > 0){
					if (lngEncodeType===cenURIComponent_Encode){
						strChar=URICompEscapeChar(strChar);
					}else{
						if (lngEncodeType===cenURI_Encode){
							strChar=URIEscapeChar(strChar);
						}
					}
					strEncodeStr+=strChar;
				}
			}
		}
	   return strEncodeStr;
	}
	
	function URICompEscapeChar(strChar)
    {
		var lngAsciiVal=strChar.charCodeAt();
		
		if(lngAsciiVal!=45 && lngAsciiVal!=95 && lngAsciiVal!=46 && 
				lngAsciiVal!=33 && lngAsciiVal!=126 && lngAsciiVal!=42 && 
					lngAsciiVal!=39 && lngAsciiVal!= 40 && lngAsciiVal!=41){
		
			// "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
			strChar = URLEncodeChar(strChar, lngAsciiVal);
		}

	    return strChar;
   }

	function URIEscapeChar(strChar)
    {
		var lngAsciiVal=strChar.charCodeAt();
		
		if(lngAsciiVal!=59 && lngAsciiVal!=47 && lngAsciiVal!=63 && 
				lngAsciiVal!=58 && lngAsciiVal!=64 && lngAsciiVal!=61 && 
					lngAsciiVal!=43 && lngAsciiVal!= 36 && lngAsciiVal!=44 && lngAsciiVal!=38 ){
		
			// ";" | "/" | "?" | ":" | "@" | "=" | "+" | "$" | ","| "&"
			strChar = URICompEscapeChar(strChar, lngAsciiVal);
		}

	    return strChar;
    }   
    
	function URLEncodeChar(strChar, lngAsciiVal)
	{    
		var strEncodeChar=strChar;
	        
	    if ((lngAsciiVal < 123) && (lngAsciiVal > 96)){
	        //do not encode
		}else{
			if ((lngAsciiVal < 91) && (lngAsciiVal > 64)){
		        //do not encode
			}else{
				if ((lngAsciiVal < 58) && (lngAsciiVal > 47)){
					//do not encode
				}else{
				     strChar = TrimString(Hex(lngAsciiVal));
				     if(lngAsciiVal < 16){
				         strChar = "%0" + strChar;
				     }else{
				         strChar = "%" + strChar;
				     }
				 }
			}
		}
		return strChar;
	}
	
	function Hex(lngNumber)
	{
		return lngNumber.toString(16);
	}
	
	function MqHtmlEncode(strString, blnReplaceSpace)
	{    
		var regExp;
		
		//replace all the & with &amp;
		regExp=new RegExp("&","g");
		strString=strString.replace(regExp,"&amp;");
    		
		//replace all the < with &lt;
		regExp=new RegExp("<","g");
		strString=strString.replace(regExp,"&lt;");
		
		//replace all the > with &gt;
		regExp=new RegExp(">","g");
		strString=strString.replace(regExp,"&gt;");
		
		//replace all the " with &quot;
		regExp=new RegExp('"',"g");
		strString=strString.replace(regExp,"&quot;");
		
		//replace all the ' with &apos;
		regExp=new RegExp("'","g");
		strString=strString.replace(regExp,"&#39;");
		
		if(blnReplaceSpace!=false){
			//replace all the " " with &#160;
			regExp=new RegExp(" ","g");
			strString=strString.replace(regExp,"&#160;");
		}

		return strString;
	}	
	
	function MqHtmlDecode(strString, blnReplaceSpace)
	{    
		var regExp;
		
		//replace all the &amp; with &
		regExp=new RegExp("&amp;","g");
		strString=strString.replace(regExp,"&");
    		
		//replace all the &lt; with <
		regExp=new RegExp("&lt;","g");
		strString=strString.replace(regExp,"<");
		
		//replace all the &gt; with >
		regExp=new RegExp("&gt;","g");
		strString=strString.replace(regExp,">");
		
		//replace all the &quot; with "
		regExp=new RegExp("&quot;","g");
		strString=strString.replace(regExp,'"');
		
		//replace all the &#39; with '
		regExp=new RegExp("&#39;","g");
		strString=strString.replace(regExp,"'");
		
		if(blnReplaceSpace!=false){
			//replace all the &#160; with " "
			regExp=new RegExp("&#160;","g");
			strString=strString.replace(regExp," ");
			
			// could also be encoded in the standard way
			regExp=new RegExp("&nbsp;", "g");
			strString=strString.replace(regExp," ");
		}

		return strString;
	}
	
	function MqUnformatXMLData(strString)
	{    
		var regExp;
		
		//replace all the encoded & (%26) with &
		regExp=new RegExp(escape("&"),"g");
		strString=strString.replace(regExp,"&");
    		
		//replace all the encoded < (%3C) with <
		regExp=new RegExp(escape("<"),"g");
		strString=strString.replace(regExp,"<");
		
		//replace all the encoded > (%3E) with >
		regExp=new RegExp(escape(">"),"g");
		strString=strString.replace(regExp,">");
		
		//replace all the encoded " (%22) with "
		regExp=new RegExp(escape('"'),"g");
		strString=strString.replace(regExp,'"');
		
		//replace all the encoded ' (%27) with '
		regExp=new RegExp(escape("'"),"g");
		strString=strString.replace(regExp,"'");

		return strString;
	}	
	
	function WriteResString(strResID)
	{
		document.write(RESX.Get(strResID));
	}

	function PropStringEncode(strString)
	{
		if(strString){
			strString=strString.toString();

			var arrCharsToReplace = new Array("&", ";", "=");
			var strChar;
			var regExp;
			
			for(var lngCount=0;  lngCount<arrCharsToReplace.length;lngCount++){
				//replace the char with a URIComponentEncoded one
				strChar = arrCharsToReplace[lngCount];
				regExp=new RegExp(strChar,"g");
				strString=strString.replace(regExp,MqEncodeURIComponent(strChar));
			}
		}
		return strString;
	}
	
	function PropStringDecode(strString)
	{
		if(strString){
			strString=strString.toString();

			var arrCharsToReplace = new Array("&", ";", "=");
			var strChar;
			var regExp;
			
			for(var lngCount=0;  lngCount<arrCharsToReplace.length;lngCount++){
				//replace the URIComponentEncoded char with a regular one
				strChar = arrCharsToReplace[lngCount];
				regExp=new RegExp(MqEncodeURIComponent(strChar),"g");
				strString=strString.replace(regExp,strChar);
			}
		}
		return strString;
	}
	
	
	
	function DecodeHTML(html) 
	{
	    var txt = document.createElement("textarea");
	    txt.innerHTML = html;
	    return txt.value;
	}
	
	function ExtractTextFromHTML(strHTML) 
	{
		if(strHTML){
			if(window.DOMParser){
				return (new DOMParser).parseFromString(strHTML, "text/html").documentElement.textContent;
			}else{
				return DecodeHTML(strHTML);
			}
		}else{
			return "";
		}
	}
	
	this.FormatString=FormatString;
	this.Right=Right;
	this.Left=Left;
	this.Mid=Mid;
	this.getNullTerminatedString=getNullTerminatedString;
	this.searchForChar=searchForChar;
	this.getChar=getChar;
	this.TrimString=TrimString;
	this.GetPropertyValue=GetPropertyValue;
	this.ReplacePropertyValue=ReplacePropertyValue;
	this.PropertyExists=PropertyExists;
	this.GetQueryStringValue=GetQueryStringValue;
	this.StripTrailing=StripTrailing;
	this.StripLeading=StripLeading;
	this.Format=Format;
	this.MqDecodeURIComponent=MqDecodeURIComponent;
	this.MqEncodeURIComponent=MqEncodeURIComponent;
	this.MqHtmlEncode=MqHtmlEncode;
	this.MqHtmlDecode=MqHtmlDecode;
	this.MqDecodeURI=MqDecodeURI;
	this.MqEncodeURI=MqEncodeURI;
	this.MqUnformatXMLData=MqUnformatXMLData;
	this.WriteResString=WriteResString;
	this.PropStringEncode=PropStringEncode;
	this.PropStringDecode=PropStringDecode;
	this.DecodeHTML=DecodeHTML;
	this.AddToQueryString=AddToQueryString;
	this.ExtractTextFromHTML=ExtractTextFromHTML;
	
	function GetPropertyValue_FromArray(varProperties,strPropertyName,strValueDelim)
	{
		var varProperty;	
		var strProperty;		
		var lngDelimPos;
		var strPropertValue="";
		var INDX_PROPERTY_NAME=0;
		var PROPERTY_VALUE_DELIM="=";
		if(!strValueDelim){
			strValueDelim=PROPERTY_VALUE_DELIM;
		}
		if (varProperties){
			for(var i=0;i<varProperties.length;i++){
				strProperty=varProperties[i];
				if(strProperty){
					varProperty=strProperty.split(strValueDelim);
					if (varProperty[INDX_PROPERTY_NAME]==strPropertyName){
						lngDelimPos=strProperty.indexOf(strValueDelim);
						strPropertValue=strProperty.substring(lngDelimPos+strValueDelim.length);
						break;
					}
				}
			}
		}
		return strPropertValue ;
	}
	
}	


function GetURL(lngLevel, objHTMLWindow)
{
	var strVD='';
	for(var c=0;c<=lngLevel;c++){
		strVD += (!objHTMLWindow ? window : objHTMLWindow).location.href.split('/')[c] + '/';	
	}	
	return strVD;
}



function MqFiles(){
	var mstrCurrentVD;
	
	function getFileName(strPath,strPathDelim, blnCompleteNAme){
		var strReturn;
		if (!strPathDelim){
			strPathDelim="/";
		}
		
		if (!blnCompleteNAme){
			strReturn=strPath.substring(searchForChar(strPath,strPathDelim,true)+1,searchForChar(strPath,".",true));
		}else{
			strReturn=strPath.substring(searchForChar(strPath,strPathDelim,true)+1);
		}
		
		return strReturn;
	}

	function removeSearchString(strPath){
		var intLastPosition;
		var strReturn;		

		strPath=String(strPath);		
		intLastPosition=searchForChar(strPath,"?",true);
		
		if (intLastPosition==-1){
			intLastPosition=searchForChar(strPath,"#",true);
		}
		
		if (intLastPosition==-1){
			intLastPosition=strPath.length;
		}
		strReturn=strPath.substring(0,intLastPosition);
		
		return strReturn;
	}

	function getFileExtension(strPath){
		var intFirstPosition;
		var strReturn;
		var strCharExt=".";
		strPath=String(strPath);

		strPath=removeSearchString(strPath);
		
		intFirstPosition=searchForChar(strPath,strCharExt,true);		
		
		var intLength=strPath.length;
		strReturn=strPath.substring(intFirstPosition+1,intLength);
	
		return strReturn;
	}
	function GetCurrentLocation(objHTMLWindow)
	{
		var strLocation="";
		
		if (objHTMLWindow){
			if (objHTMLWindow.location){
				
				var objHTMLLocation=objHTMLWindow.location;
				
				try{
					if (objHTMLLocation.href){
					
						strLocation=GetDomainURL(objHTMLLocation);
						
						if(strLocation){
							strLocation+=getPath(objHTMLLocation.pathname);
						}


					}					
				}catch(errorObject){
					strLocation="";
				}
			}
		}
	     
		return strLocation;
	}
	function getCurrentLocation(strDocumentName){
		var objDocument;	


		objDocument=eval(strDocumentName);


		
		var strLocation=GetCurrentLocation(objDocument);
		
		return strLocation;

	}
	
	function GetCurrentVDURL(objHTMLWindow)
	{
		var strURL="";
		
		if(objHTMLWindow){
			if(objHTMLWindow.location){
				strURL=GetDomainURL(objHTMLWindow.location);

				if(strURL){
					strURL+="/" + GetVDName(objHTMLWindow.location.pathname);
				}
			}

		}
		return strURL;
	}
	
	function ConcatenatePath(strFirstPath,strSecondPath, strPathDelim){
		var BACKSLASH="\\";
		if(!strPathDelim){
			strPathDelim=BACKSLASH;
		}
		var objStr=g_MqRef.MqStr;
		strFirstPath=objStr.StripTrailing(strFirstPath,strPathDelim);
		strSecondPath=objStr.StripLeading(strSecondPath,strPathDelim);
		return (strFirstPath +strPathDelim +strSecondPath);    
	}

	function GetCurrentVD()
	{
		if (!mstrCurrentVD){
			mstrCurrentVD=GetVDName();
		}
		return mstrCurrentVD;
	}
	
	function GetVDName(strPathName)
	{
		if (!strPathName){
			strPathName=window.location.pathname;
		}
		
		var strPathDelim="/";
		var strVDName="";
		var lngIndex;
		if(g_MqRef.MqStr.Left(strPathName, strPathDelim.length)==strPathDelim){
			strPathName=g_MqRef.MqStr.Right(strPathName, strPathName.length-strPathDelim.length);
		}
		lngIndex=strPathName.indexOf(strPathDelim);
		if(lngIndex>0){
			strVDName=g_MqRef.MqStr.Left(strPathName, lngIndex);
		}
		return strVDName;
		
	}
	
	function LoadScript(sFileURL,callback,HTMLDoc)
	{
		if (!HTMLDoc){
			HTMLDoc=document;
		}
		var script=HTMLDoc.createElement('script');
		var ret=false;
		script.setAttribute("type","text/javascript");
	
		// Support for callback
		if (script.readyState){  //IE
	        script.onreadystatechange = function(){
	            if (script.readyState == "loaded" ||
	                    script.readyState == "complete"){
	                script.onreadystatechange = null;
	                if (callback){
		                callback();
		            }
	            }
	        };
	    } else {  //Others
	        script.onload = function(){
	            if (callback){
	                callback();
	            }
	        };
	    }
		
		script.setAttribute("src", sFileURL);
		if (typeof script!="undefined")
		{
			HTMLDoc.getElementsByTagName("head")[0].appendChild(script);
			ret=true;
		}
		return ret; 		
	}
	
	function LoadScriptSync(sFileURL) 
	{		
		var objXMLHttpReqObj = new XMLHttpRequest();
		var READY_STATE_COMPLETE=4;
		
		if(objXMLHttpReqObj){
			objXMLHttpReqObj.open("GET", sFileURL, false); //synchronous
			objXMLHttpReqObj.onreadystatechange = function(){
				if(objXMLHttpReqObj.readyState==READY_STATE_COMPLETE)
				{
					try
					{
						eval(objXMLHttpReqObj.responseText);
					} catch(e)
					{
						console.log(e);
						console.log("Error loading file from: " + sFileURL + ", location:" + document.location.href);
					}
				}
			}
			objXMLHttpReqObj.send(null);			
		}
	}
	

	// Not JSONP. Not for cross-domain
	function LoadJSONSync(sFileURL) 
	{		
		var objXMLHttpReqObj = new XMLHttpRequest();
		var READY_STATE_COMPLETE=4;
		var sRet="";
		
		if(objXMLHttpReqObj){
			objXMLHttpReqObj.open("GET", sFileURL, false); //synchronous
			objXMLHttpReqObj.onreadystatechange = function(){
				if(objXMLHttpReqObj.readyState==READY_STATE_COMPLETE){
					sRet=objXMLHttpReqObj.responseText;
				}
			}
			objXMLHttpReqObj.send(null);	
			return sRet;		
		}
	}
	
	/** The ViewFolderURL is the folder of the view, which is usually named <project>_<view name>
	For example: http://server/connect02/example_view/
	**/

	function ViewFolderURL(oHTMLWindow)
	{
		var URL_VIEW = 4;
		return GetURL(URL_VIEW, oHTMLWindow);			
	}

	this.getFileName=getFileName;
	this.getFileExtension=getFileExtension;
	this.removeSearchString=removeSearchString;
	this.getPath=getPath;
	this.getCurrentLocation=getCurrentLocation;
	this.ConcatenatePath=ConcatenatePath;
	this.GetCurrentLocation=GetCurrentLocation;
	this.GetCurrentVDURL=GetCurrentVDURL;
	this.GetVDName=GetVDName;
	this.GetCurrentVD=GetCurrentVD;
	this.ViewFolderURL=ViewFolderURL;
	this.LoadScript=LoadScript;
	this.LoadScriptSync=LoadScriptSync;
	this.LoadJSONSync=LoadJSONSync;
	this.GetURL=GetURL;
	
	function GetDomainURL(objDocumentLocation)
	{
		var strURL="";
		
		if(objDocumentLocation){
			strURL=objDocumentLocation.protocol +"//" +objDocumentLocation.hostname;
				
			if (objDocumentLocation.port!="80" && objDocumentLocation.port!=="" ){
				 strURL+=":" + objDocumentLocation.port;
			}	
		}
		return strURL;
	}
	
}
function CMqURIUtils(){

	var PROTOCOL_FILE = "file";
	var PROTOCOL_FTP = "ftp";
	var PROTOCOL_GOPHER = "gopher";
	var PROTOCOL_HTTP = "http";
	var PROTOCOL_HTTPS = "https";
	var PROTOCOL_MAILTO = "mailto";
	var PROTOCOL_NEWS = "news";
	var PROTOCOL_NNTP = "nntp";
	var PROTOCOL_SOCKS = "socks";
	var PROTOCOL_JAVASCRIPT = "javascript";
	var PROTOCOL_VBSCRIPT = "vbscript";
	var DELIM_SEGMENT = "/";
	var QUESTION_MARK="?";
	
	function AddURIProtocol(strURL)
	{						
		var strDefaultProtocol=PROTOCOL_HTTP;
		
		var blnHasProtocol=HasProtocol(strURL);

		if(!blnHasProtocol){
			if(!IsRelativeURIPath(strURL)){
				strURL=strDefaultProtocol + GetSchemeDelimiter(strDefaultProtocol) + strURL;
			}
		}
			
		return strURL;
	}
	function ReplaceURIPath(strURI,strPath)
	{
		if (strURI && strPath){
			var varSegments=strURI.split(DELIM_SEGMENT);
			varSegments=varSegments.slice(0,3);
			var strAuthURI=varSegments.join(DELIM_SEGMENT);
			strURI=strAuthURI + DELIM_SEGMENT + strPath;
		}
		return strURI;
	}
	
	function AddToQueryString(strURL, strURIName, strURIValue)
	{
		var strFinalURL="";
		var QUERY_STRING_DELIM="&";
		var QUERY_STRING_ELEMENT_DELIM="=";
		
		var strURLQS=GetQueryStringFromURL(strURL);
		if(g_MqRef.MqStr.PropertyExists(strURLQS, strURIName, QUERY_STRING_DELIM, QUERY_STRING_ELEMENT_DELIM)>=0){
			strURLQS=g_MqRef.MqStr.ReplacePropertyValue(strURLQS, strURIName, strURIValue, QUERY_STRING_DELIM, QUERY_STRING_ELEMENT_DELIM); 
			var strURLPath=GetPathFromURL(strURL);
			strFinalURL=strURLPath + QUESTION_MARK + strURLQS;
		}else{
			if(strURL.indexOf(QUESTION_MARK) >=0){
				strFinalURL=strURL + QUERY_STRING_DELIM;
			}else{
				strFinalURL=strURL + QUESTION_MARK;
			}
			strFinalURL+=strURIName + QUERY_STRING_ELEMENT_DELIM + strURIValue;
		}
		return strFinalURL;
	}
	
	function RemoveFromQueryString(strURL, strURIName)
	{
		var strFinalURL="";
		var QUERY_STRING_DELIM="&";
		var QUERY_STRING_ELEMENT_DELIM="=";
		
		//add the & at the beginning so if we'reremoving the first item it will be found
		var strURLQS=QUERY_STRING_DELIM + GetQueryStringFromURL(strURL);
		if(strURLQS.indexOf(strURIName) >= 0){									
			var strURIValue=g_MqRef.MqStr.GetPropertyValue(strURIName, strURLQS,false, QUERY_STRING_DELIM,QUERY_STRING_ELEMENT_DELIM);
			
			strURLQS = strURLQS.replace(QUERY_STRING_DELIM + strURIName + QUERY_STRING_ELEMENT_DELIM + strURIValue, "");
			var strURLPath=GetPathFromURL(strURL);
			//remove the & that was added
			strURLQS = g_MqRef.MqStr.StripLeading(strURLQS, QUERY_STRING_DELIM)
			
			strFinalURL=strURLPath + QUESTION_MARK + strURLQS;
		}else{
			strFinalURL=strURL;
		}
		return strFinalURL;
	}
	
	function GetPathFromURL(strURL)
	{
		var strPath=strURL;
		var lngIndex=strURL.indexOf(QUESTION_MARK);
		
		if(lngIndex >= 0){
        strPath=strURL.substr(0,lngIndex);
		}
		return strPath;
	}
	
	function GetQueryStringFromURL(strURL)
	{
		var strQS="";
		var lngIndex=strURL.indexOf(QUESTION_MARK) + QUESTION_MARK.length;
		if(lngIndex >= 0){
			strQS=strURL.substr(lngIndex);
		}
		
		return strQS;
	}
	
	function GetURIFromUNC(strUNC)
	{

		//replace the initial \\ with file://
		var regExp=new RegExp("^\\\\\\\\","g");
		strUNC=strUNC.replace(regExp,"file://");
    		
		//replace all \ with /
		regExp=new RegExp("\\\\","g");
		strUNC=strUNC.replace(regExp,"/");

		return strUNC;
	
	}
	
	this.AddURIProtocol=AddURIProtocol;
	this.ReplaceURIPath=ReplaceURIPath;
	this.AddToQueryString=AddToQueryString;
	this.GetURIFromUNC=GetURIFromUNC;
	this.RemoveFromQueryString=RemoveFromQueryString;
	
	//private

	function HasProtocol(strURL)
	{
		var PROTOCOL_DELIM=":";
		var PROTOCOL_ELEMENT=0;
		var lngCount;
		var blnHasProtocol=false;
		var lngProtocolDelimIndex=strURL.indexOf(PROTOCOL_DELIM);
		if(lngProtocolDelimIndex>0){
		
			var arrProtocols=new Array(PROTOCOL_FILE,PROTOCOL_FTP,
										PROTOCOL_GOPHER,PROTOCOL_HTTP,
										PROTOCOL_HTTPS,PROTOCOL_MAILTO,
										PROTOCOL_NEWS,PROTOCOL_NNTP,
										PROTOCOL_SOCKS,PROTOCOL_JAVASCRIPT,
										PROTOCOL_VBSCRIPT);
			
			var strProtocol=strURL.substring(0,lngProtocolDelimIndex);
			
			strProtocol=strProtocol.toLowerCase();
		
			strProtocol=g_MqRef.MqStr.TrimString(strProtocol);
		
			for(lngCount=0; lngCount<arrProtocols.length; lngCount++){
				if(strProtocol==arrProtocols[lngCount]){
					blnHasProtocol=true;
					lngCount=arrProtocols.length;
				}
			}
		}		
		return blnHasProtocol;
	}
	
	function IsRelativeURIPath(strPath)
	{    
		var blnIsRelative=false;
		var lngCount;
		
		var FIRST_COMPONENT_ELEMENT=0;
			
		//a relative path could have the following formats:
	        // ./<PATH>
	        // /<PATH>
	        // ../<PATH>
	    //there are other formats, but these are the only ones we currently support
	    
	    var arrURIRelPathFirstComp = new Array(".", "..");
		    
	    var varSegments = strPath.split(DELIM_SEGMENT);
		    
	    var strFirstCompPath = varSegments[FIRST_COMPONENT_ELEMENT];
		    
	    if (strFirstCompPath.length===0){
			//ex: strPath= /HTML , which is a relative path
	        blnIsRelative = true;
		}else{
			//check if the first path component is a relative one
			for(lngCount=0;lngCount<arrURIRelPathFirstComp.length;lngCount++){
				if(arrURIRelPathFirstComp[lngCount]==strFirstCompPath){
					lngCount=arrURIRelPathFirstComp.length;
					blnIsRelative=true;
				}
			}
	    }

	    return blnIsRelative;
	}
		
	function GetSchemeDelimiter(strProtocol)
	{
		var strDelimiter="";
			
		if(strProtocol==PROTOCOL_MAILTO || strProtocol==PROTOCOL_NEWS){
			strDelimiter = ":";
		}else{
			strDelimiter =  "://";
		}
			
		return strDelimiter;
	}
}

//Images related functions ************************

function isImageDisabled(strImage,objImage){
	var blnReturn;
	var intPosition;
	blnReturn=false;

  if (!objImage){
	  objImage=document.images[strImage];
  }
	if (objImage){
    var strSRC=objImage.src;
    
		intPosition=searchForChar(strSRC,".",true);
		
		if (strSRC.substring(intPosition-3,intPosition)=="dis"){
			blnReturn=true;
		}else{
			blnReturn=false;
		}
	}
		
	return blnReturn;
}
	

function MqButton()
{
	var STATE_1="State1";
	var STATE_2="State2";
	var STATE_DIS="StateDis";
	var POSTFIX_SELECTED="Selected";
	var m_objHTMLDocument=document;
	var MQ_BUTTON_BASE_CLASS_PROP="MqBaseClass";
	
	function GetHTMLDocument()
	{
		return m_objHTMLDocument;
	}
	
	function SetHTMLDocument(objHTMLDocument)
	{
		m_objHTMLDocument=objHTMLDocument;
	}
	
	function Toggle(objHTMLElement, strBaseClass)
	{
		if (objHTMLElement){
            if (objHTMLElement.className.indexOf(STATE_1) >= 0) {
                if (objHTMLElement.classList.contains(strBaseClass + STATE_1)) {
                    objHTMLElement.classList.remove(strBaseClass + STATE_1);
                }
                objHTMLElement.classList.add(strBaseClass + STATE_2);
			}else{
                if (objHTMLElement.classList.contains(strBaseClass + STATE_2)) {
                    objHTMLElement.classList.remove(strBaseClass + STATE_2);
                }
                objHTMLElement.classList.add(strBaseClass + STATE_1);

			}
		}
	}

	function ChangeBaseClass(objHTMLElement, strNewBaseClass, strOldBaseClass)
	{
		SetCSSClass(objHTMLElement, strNewBaseClass, strOldBaseClass);
		objHTMLElement.setAttribute(MQ_BUTTON_BASE_CLASS_PROP, strNewBaseClass);
	}
		
	function Select(objHTMLElement, strState)
	{	
		if(!(strState)){
			strState=STATE_1;	
		}
		
		SetCSSClass(objHTMLElement, strState + POSTFIX_SELECTED, strState);
	}
	
	function UnSelect(objHTMLElement, strState)
	{		
		if(!(strState)){
			strState=STATE_1;	
		}
	
		SetCSSClass(objHTMLElement, strState, strState + POSTFIX_SELECTED);
	}

	function SetCSSClass(objHTMLElement, strNewState, strOldState)
	{
		var strCurrClass="";
	
        if (objHTMLElement) {
            if (objHTMLElement.classList.contains(strOldState)) {
                objHTMLElement.classList.remove(strOldState);
            }
            objHTMLElement.classList.add(strNewState);

		}

	}
	function Right(strString,lngLength)
	{
		var intStringLength;
			
		intStringLength=strString.length;
			
		return (strString.substring(intStringLength-lngLength, intStringLength));
			
	}
	
	function ToggleButton(strName, strBaseClass)
	{
		if(m_objHTMLDocument){
			var oButton=m_objHTMLDocument.getElementById(GetButtonHTMLName(strName));
					
			if(oButton){
				Toggle(oButton,strBaseClass);
			}			
		}
	}
	
	function DisableButton(strName)
	{
		if(m_objHTMLDocument){
			if(IsTextButton(GetButtonHTMLName(strName)))
			{
				DisableTextButton(strName);
			}
			else
			{
				var objLogonButton=m_objHTMLDocument.getElementById(GetButtonHTMLName(strName));
						
				if(objLogonButton){
					Disable(objLogonButton);
				}			
			}
		}
	}
	
	function EnableButton(strName)
	{
		if(m_objHTMLDocument){
			if(IsTextButton(GetButtonHTMLName(strName)))
			{
				EnableTextButton(strName);
			}
			else
			{
				var objLogonButton=m_objHTMLDocument.getElementById(GetButtonHTMLName(strName));
						
				if(objLogonButton){
					ShowHideButton(strName, true);
					Enable(objLogonButton);
				}	
			}
		}
	}
	
	function ShowHideButton(strName, blnVisible)
	{
		if(m_objHTMLDocument){
			var objLogonButton=m_objHTMLDocument.getElementById(GetButtonHTMLName(strName));
					
			if(objLogonButton){
				if(blnVisible){
					objLogonButton.style.display="";
				}else{
					objLogonButton.style.display="none";
				}
			}			
		}
	}
	
	function Enable(objHTMLElement)
	{		
		var blnReturn=false;
		if (objHTMLElement){
			if(IsTextButton(objHTMLElement.id, objHTMLElement)){
				HideTextButton(objHTMLElement.id, false, objHTMLElement);
			}else{
				if (objHTMLElement.className.indexOf(STATE_1)<0){
                    var strBaseClass = GetButtonBaseClass(objHTMLElement);

                    if (objHTMLElement.classList.contains(strBaseClass + STATE_DIS)) {
                        objHTMLElement.classList.remove(strBaseClass + STATE_DIS);
                    }
                    objHTMLElement.classList.add(strBaseClass + STATE_1);

				}
			}
			blnReturn=true;
		}		
		return blnReturn;
	}
	
	function Disable(objHTMLElement)
	{
		var blnReturn=false;
		
		if (objHTMLElement){
			if(IsTextButton(objHTMLElement.id, objHTMLElement)){
				HideTextButton(objHTMLElement.id, true, objHTMLElement);
			}else{
				if (!IsDisabled(objHTMLElement)){
                    var strBaseClass = GetButtonBaseClass(objHTMLElement);
                    if (objHTMLElement.classList.contains(strBaseClass + STATE_1)) {
                        objHTMLElement.classList.remove(strBaseClass + STATE_1);
                    }
                    objHTMLElement.classList.add(strBaseClass + STATE_DIS );
				}
			}
			blnReturn=true;
		}
		
		return blnReturn;
	}
	
	function GetButtonBaseClass(objHTMLElement)
	{
		return objHTMLElement.getAttribute(MQ_BUTTON_BASE_CLASS_PROP);
	}
	
	function GetButtonHTML(strName, strOnClick, strBaseClassName, fToggle,
							strInitialState, strTooltip, strAccessKey,strCaption)
	{
		
		if (strInitialState){
			strInitialState=strBaseClassName + strInitialState;
		}else{
			strInitialState=strBaseClassName + STATE_1;
		}
		
		var strReturnString="<a class=\"" + strInitialState ;
		strReturnString+="\" href=\"#\" id=\"" +GetButtonHTMLName(strName) + "\" ";
		strReturnString+=" onclick=\"if(!m_objMqButton.IsDisabled(this)){" + strOnClick + ";}";
		
		if (fToggle){
			strReturnString+="m_objMqButton.Toggle(this,'" + strBaseClassName + "');";
		}
		
		if(!strCaption)
		{
			strCaption="";
		}
		

		strReturnString+="return false;\" accesskey=\"" + strAccessKey +
							"\" title=\"" + strTooltip + "\" " + 
							MQ_BUTTON_BASE_CLASS_PROP + "=\"" + strBaseClassName + "\" ><span style=\"display:inline-block;\" >" + strCaption + "</span><\/a>";

		
		return strReturnString;
	}

	function WriteButtonHTML(strName, strOnClick, strBaseClassName, fToggle,
							fDisabled, strTooltip, strAccessKey, objDocumentRef, strCaption)
	{
		if(!objDocumentRef){
			objDocumentRef = document;
		}
		
		objDocumentRef.write(GetButtonHTML(strName, strOnClick, strBaseClassName, fToggle,
							fDisabled, strTooltip, strAccessKey, strCaption));
	}
		
	function IsDisabled(objHTMLElement)
	{
		var blnDisabled=false;
		if(objHTMLElement){
			if (objHTMLElement.className.indexOf(STATE_DIS)>=0){
				blnDisabled=true;
			}
				
		}
		return blnDisabled;
	}

	function GetButtonHTMLName(strName)
	{
		return "a_"+ strName;
	}
					
	function GetButtonState(objHTMLElement)
	{
		if(objHTMLElement){
			if(objHTMLElement.className.indexOf(STATE_1)>=0){
				return STATE_1;
			}else{
				if(objHTMLElement.className.indexOf(STATE_2)>=0){
					return STATE_2;
				}
			}
		}
	}	
	
	function SetState(strName,sNewState)
	{
		if(m_objHTMLDocument){
			var oButton=m_objHTMLDocument.getElementById(GetButtonHTMLName(strName));
					
            if (oButton) {
                var strBaseClass = GetButtonBaseClass(oButton);

                if (sNewState.indexOf(STATE_1) >= 0) {
                    
                    if (oButton.classList.contains(strBaseClass + STATE_2)) {
                        oButton.classList.remove(strBaseClass + STATE_2);
                    }
                    oButton.classList.add(strBaseClass + STATE_1);

				}else{
                    if (sNewState.indexOf(STATE_2) >= 0) {
                        if (oButton.classList.contains(strBaseClass + STATE_1)) {
                            oButton.classList.remove(strBaseClass + STATE_1);
                        }
                        oButton.classList.add(strBaseClass + STATE_2);
					}else{
						oButton.className=sNewState;
					}
				}
			}		
		}

	}
	
	function WriteTextButtonHTML(strName, strCaption, strOnClick, strImg, 
								intHeight, strExtraStyle, strTooltip, intWidth, strButtonCSS)
	{
		document.write(GetTextButtonHTML(strName, strCaption, strOnClick, strImg, 
										intHeight, strExtraStyle, strTooltip, intWidth, strButtonCSS));
	}
	
	//** Return the html of a simple button that opens a URL on click. 
	//** The url can contain wild card variables like these: 
	//**		<ValOfField>21</ValOfField> 	where 21 is the ID of the dts field
	//**		<Selected DtsRecords> 		resolves to a list of IDs of the selected dts records in the grid 
	// TODO: extend with window properties for the one to open ( VNWindowProperties)
	function GetURLButtonHTML( name, sCaption, sURLOnClick, iHeight, iWidth, sTooltip, winProps )
	{
		var ret="";
		try
		{
			// Generate button ID
			if (!name)
			{
				name = encodeURIComponent(sCaption);
			}
			var sWinProps= JSON.stringify(winProps);
			
			sWinProps= sWinProps.replace(/"/g,"&quot;");
			sWinProps= sWinProps.replace(/'/g,"&#39;");
		
		
			var onclick="g_VWS.URIOpener.Open('" + sURLOnClick + "',  '" + sWinProps + "' );";
			
			// Add the call to resolve and open the url
			ret= GetTextButtonHTML( name, sCaption, onclick, "", iHeight, 
							"", sTooltip, iWidth, "", "", "", "");
		}catch(e){}
		return ret;
	}
	
	function GetTextButtonHTML(strName, strCaption, strOnClick, strImg, intHeight, 
								strExtraStyle, strTooltip, intWidth, strButtonCSS, 
								strButtonTextCSS, strButtonImgCSS, strImgCustomPath)
	{
		
		var strHTML="";
		var strInitialState="";
		
		if(!strButtonTextCSS){
			strButtonTextCSS="TextButton";
		}
		
		if(!strButtonImgCSS) {
			strButtonImgCSS="";
		}
		if(!strImgCustomPath) {
			strImgCustomPath = "../../theme/images/buttons/";
		}
		
		if(!strTooltip){
			var div = document.createElement("div");
			div.innerHTML = strCaption;
			strTooltip=div.innerText;
		}
		
		if(!strExtraStyle){
			strExtraStyle="";
		}
		if(strImg!="")
		{
			if(!strButtonCSS){
				strButtonCSS="HTMLTextButton";
			}

			strInitialState=strButtonCSS + STATE_1;

			if (strImg.indexOf("<img")==-1)
			{
				// Backwards compatible, when only name of image passed
				strImg = "<img src='../../theme/images/buttons/" + strImg + "' />";
			}
			
			strHTML="<div style='height:" + intHeight + "px;" + strExtraStyle +"' class='" + strButtonCSS + " " + strInitialState + "' id='" + 
						GetButtonHTMLName(strName) + "' name='" + GetButtonHTMLName(strName) + "' " + MQ_BUTTON_BASE_CLASS_PROP 
						+ "='" + strButtonCSS + "' onmouseover='if(m_objMqButton.IsTextButtonEnabled(m_objMqButton.GetButtonHTMLName(\"" 
						+ strName + "\"))){this.className=\"" + strButtonCSS + " HTMLTextButtonState1 HTMLTextButtonHover\"}' " + 
						"onmouseout='if(m_objMqButton.IsTextButtonEnabled(m_objMqButton.GetButtonHTMLName(\"" + strName + "\"))){this.className=\"" 
						+ strButtonCSS + " HTMLTextButtonState1\"}' onclick='if(m_objMqButton.IsTextButtonEnabled(m_objMqButton.GetButtonHTMLName(\"" 
						+ strName + "\"))){" + strOnClick + "}' MqTextButton='1' title='" + strTooltip + "'>" +
						"<table width='100%'>" +
						"	<tr>" +
						"		<td width='100%' align='center' style='padding:0px !important;'><table><tr><td align='right' class='HTMLMblTextButtonImage'>" 
						+ strImg + "</td>" +
						"			<td align='left' class='" + strButtonCSS + " " + strInitialState + " HTMLMblTextButtonImage'><span id='lnkAction" 
						+ strName + "' style='padding-bottom:4px'>"+strCaption+"</span></td></tr></table>	" +							
						"		</td>" +
						"	</tr>" +
						"</table>" +
						"</div>";
		}else{	
			var strWidth="";
			var strHeight="";
			var strStyle="";
			strInitialState=strButtonTextCSS + STATE_1;
			if(!strButtonCSS){
				strButtonCSS=""; //avoid undefined
			}
		

			if(intWidth){
				if(isNaN(intWidth)){
					strWidth="width:" + intWidth + ";";
				}else{
					strWidth="width:" + intWidth+"px;";
				}
			}			
			if(intHeight){
				strHeight="height:" + intHeight+"px;'";
			}
			
			if(strWidth!=""||strHeight!=""){
				strStyle=" style='" + strWidth + strHeight + "'";
			}
			
			strHTML='<div style="padding-bottom:10px;' + strExtraStyle + '" id="' + 
							GetButtonHTMLName(strName) + '" name="' + GetButtonHTMLName(strName) + '" class="' + strInitialState  + " " + strButtonCSS
							+ '" MqTextButton="1" ' + MQ_BUTTON_BASE_CLASS_PROP +'="' + strButtonTextCSS + '"><div class="' 
							+ strButtonTextCSS + ' ' + strInitialState + '"' + strStyle + ' onclick="if(m_objMqButton.IsTextButtonEnabled(m_objMqButton.GetButtonHTMLName(\''
							+strName+'\'))){' + strOnClick + '};" id="btnAction' + strName + '"' +
						 '	onmouseover="if(m_objMqButton.IsTextButtonEnabled(m_objMqButton.GetButtonHTMLName(\''+strName
						 +'\'))){this.className=\'' + strButtonTextCSS + ' TextButtonState1 TextButtonOver\'; document.getElementById(\'lnkAction' 
						 + strName + '\').className=\'' + strButtonTextCSS + ' TextButtonState1 TextButtonOver\'}" ' +
						 '	onmouseout="if(m_objMqButton.IsTextButtonEnabled(m_objMqButton.GetButtonHTMLName(\''
						 +strName+'\'))){this.className=\'' + strButtonTextCSS + ' TextButtonState1\'; document.getElementById(\'lnkAction' 
						 + strName + '\').className=\'' + strButtonTextCSS + ' TextButtonState1\'}" title="' + strTooltip + '">' +
						 '	<table height="100%" width="100%"><tr>' +
						 '	<td valign="middle" class="' + strButtonTextCSS + ' ' + strInitialState + '" width="100%" id="lnkAction' + strName + '">' + strCaption + 
						 '  </td></tr></table>' +
						 '	</div></div>';
		}
		
		return strHTML;
	}
	
	function HideTextButton(strName, blnHidden, objButton)
	{
		var objTextButton;
		if(objButton){
			objTextButton=objButton;
		}else{
			if(m_objHTMLDocument){
				objTextButton=m_objHTMLDocument.getElementById(strName);
			}
		}
		if(objTextButton){
			if(blnHidden){
				objTextButton.style.display="none";
				objTextButton.style.visibility="hidden";
			}else{
				objTextButton.style.display="";
				objTextButton.style.visibility="visible";
			}
		}
	}
	
	function EnableTextButton(strName)
	{
		var blnReturn = false;
		if(m_objHTMLDocument)
		{
			var objTextButton=m_objHTMLDocument.getElementById(GetButtonHTMLName(strName));
			if(objTextButton)
			{
				if (objTextButton.className.indexOf(STATE_1)<0){
					var strBaseClass=GetButtonBaseClass(objTextButton);
					SwitchClass( objTextButton, strBaseClass + STATE_DIS, strBaseClass + STATE_1 );
					SwitchClass( m_objHTMLDocument.getElementById("btnAction" + strName), strBaseClass + STATE_DIS, strBaseClass + STATE_1 );
					SwitchClass( m_objHTMLDocument.getElementById("lnkAction" + strName), strBaseClass + STATE_DIS, strBaseClass + STATE_1 );
					
				}
				blnReturn = true;
			}
		}
		return blnReturn;
	}
	
	function SwitchClass( elem, remove, add )
	{
		if (elem)
		{
			elem.classList.remove( remove);
			elem.classList.add( add);
		}
	}
	
	function DisableTextButton(strName)
	{
		var blnReturn = false;
		if(m_objHTMLDocument)
		{
			var objTextButton=m_objHTMLDocument.getElementById(GetButtonHTMLName(strName));
			if(objTextButton)
			{
				if (!IsDisabled(objTextButton)){
					var strBaseClass=GetButtonBaseClass(objTextButton);
					SwitchClass( objTextButton, strBaseClass + STATE_1, strBaseClass + STATE_DIS );

					if(strBaseClass!="HTMLTextButton")
					{
						SwitchClass( m_objHTMLDocument.getElementById("btnAction" + strName), strBaseClass + STATE_1, strBaseClass + STATE_DIS );
					}
					SwitchClass( m_objHTMLDocument.getElementById("lnkAction" + strName), strBaseClass + STATE_1, strBaseClass + STATE_DIS );

				}
				blnReturn=true;
			}
		}
		return blnReturn;
	}
	
	function IsTextButton(strName, objButton)
	{
		var blnReturn=false;
		var objTextButton;
		if(objButton){
			objTextButton=objButton;
		}else{
			if(m_objHTMLDocument){
				objTextButton=m_objHTMLDocument.getElementById(strName);
			}
		}
		
		if(objTextButton){
			blnReturn=(objTextButton.getAttribute("MqTextButton")=="1");
		}
		return blnReturn;
	}
	
	function IsTextButtonEnabled(strName)
	{
		var blnEnabled=false;
		if(m_objHTMLDocument)
		{
			var objTextButton=m_objHTMLDocument.getElementById(strName);
			if(objTextButton)
			{
				if (objTextButton.className.indexOf(STATE_1)>=0){
					blnEnabled=true;
				}
			}
		}
		return blnEnabled;
	}
	
	function SetTextButtonCaption(strName, strCaption)
	{
		var objTextButtonCaption=m_objHTMLDocument.getElementById("lnkAction" + strName);
		if(objTextButtonCaption){
			objTextButtonCaption.innerHTML=strCaption;
		}
	}

	function SetTooltip(strName, strResID)
	{
		if(m_objHTMLDocument){
			var objElement=m_objHTMLDocument.getElementById(strName);
			if(objElement){
				objElement.title=g_MqRef.RESX.Get(strResID);
			}
		}
	}
		
	this.Toggle=Toggle;
	this.Enable=Enable;
	this.Disable=Disable;
	this.GetButtonHTML=GetButtonHTML;
	this.WriteButtonHTML=WriteButtonHTML;
	this.IsDisabled=IsDisabled;
	this.GetButtonHTMLName=GetButtonHTMLName;
	this.STATE_1=STATE_1;
	this.STATE_2=STATE_2;
	this.STATE_DIS=STATE_DIS;
	this.Select=Select;
	this.UnSelect=UnSelect;
	this.ToggleButton=ToggleButton;
	this.EnableButton=EnableButton;
	this.DisableButton=DisableButton;
	this.GetHTMLDocument=GetHTMLDocument;
	this.SetHTMLDocument=SetHTMLDocument;
	this.ChangeBaseClass=ChangeBaseClass;
	this.GetButtonBaseClass=GetButtonBaseClass;
	this.GetButtonState=GetButtonState;
	this.SetState=SetState;
	this.ShowHideButton=ShowHideButton;
	this.GetTextButtonHTML=GetTextButtonHTML;
	this.WriteTextButtonHTML=WriteTextButtonHTML;
	this.HideTextButton=HideTextButton;
	this.IsTextButton=IsTextButton;
	this.IsTextButtonEnabled=IsTextButtonEnabled;
	this.SetTextButtonCaption=SetTextButtonCaption;
	this.EnableTextButton=EnableTextButton;
	this.DisableTextButton=DisableTextButton;
	this.SetTooltip=SetTooltip;
	this.GetURLButtonHTML=GetURLButtonHTML;
	
}

function MqDebug()
{
	var mbEnableLog=false;
	
	// Start by checking if in debug mode
	ProcessMode(window);
	
	function GetEnableLog()
	{
		return mbEnableLog;
	}
	
	function SetEnableLog(bEnableLog)
	{
		mbEnableLog=bEnableLog;
	}

	function ProcessMode(oWindow)
	{
		if (oWindow){
			var oQS=new CMqQueryString(oWindow.location.search);
		    
		    if (oQS.QSVals["d"]==1){
				mbEnableLog=true;
			}else{
				mbEnableLog=false;
			}
		}
	}

	this.GetEnableLog=GetEnableLog;
	this.SetEnableLog=SetEnableLog;
	this.ProcessMode=ProcessMode;
}



function CMqQueryString(strQS)
{
	var m_varQSVals=new Array();
	var QUERY_STRING_DELIM="&";
	var QUERY_STRING_ELEMENT_DELIM="=";
	var m_objMqStr=g_MqRef.MqStr;
	

  if (strQS){
    BuildQSHashArray(strQS);
  }
  
	function Initialize(strQS)
	{
		BuildQSHashArray(strQS);
	}
	
	function GetQS(blnEncodeValues)
	{
		var strQS="";
		var oElement;
		var strValue;
		for(oElement in m_varQSVals){
		
			strValue=m_varQSVals[oElement];
			if(blnEncodeValues){
				strValue=m_objMqStr.MqEncodeURIComponent(strValue);
			}
			strQS+=oElement + QUERY_STRING_ELEMENT_DELIM + strValue + QUERY_STRING_DELIM;
		}

		if(m_objMqStr.Right(strQS,QUERY_STRING_DELIM.length)==QUERY_STRING_DELIM){
			strQS=m_objMqStr.Left(strQS,(strQS.length-QUERY_STRING_DELIM.length));
		}

		return strQS;
	}
	
	this.Initialize=Initialize;
	this.QSVals=m_varQSVals;
	this.GetQS=GetQS;
	
	function BuildQSHashArray(strQS)
	{
		var arrQSTemp;
		var lngCount;
		var arrQSElements;
		var QUESTION_MARK="?";
		var NAME_ELEMENT_INDEX=0;
		var VALUE_ELEMENT_INDEX=1;
		
		if(m_objMqStr.Left(strQS,QUESTION_MARK.length)==QUESTION_MARK){
			strQS=m_objMqStr.Right(strQS,(strQS.length-QUESTION_MARK.length));
		}
	
		if(m_objMqStr.Right(strQS,QUERY_STRING_DELIM.length)==QUERY_STRING_DELIM){
			strQS=m_objMqStr.Left(strQS,(strQS.length-QUERY_STRING_DELIM.length));
		}
		
		if(strQS.length > 0){
			arrQSTemp=strQS.split(QUERY_STRING_DELIM);
		
			for(lngCount=0; lngCount<arrQSTemp.length; lngCount++){
			
				arrQSElements=arrQSTemp[lngCount].split(QUERY_STRING_ELEMENT_DELIM);
								
				m_varQSVals[arrQSElements[NAME_ELEMENT_INDEX].toLowerCase()]=arrQSElements[VALUE_ELEMENT_INDEX];
			}	
		}
	}
}

function MqResMgr()
{
	var _me=this;
	
	function ProcessAll(oRootElem)
	{
		if (!oRootElem){
			oRootElem=document;
		}
		
		$("[translate='yes']",oRootElem).each(SetDataRes);
		
	}
	
	function SetDataRes()
	{
		var sText="";
		if (this) 
		{
			var sRESID=$(this).attr('data-res');
			sText=g_MqRef.RESX.Get(sRESID); 
			
			if (this.nodeName=="SPAN" || this.nodeName=="DIV" || this.nodeName=="BUTTON")
			{
				//don't duplicate if called twice
				if(g_MqRef.MqStr.TrimString($(this).context.innerText) != sText){
					$(this).html(sText + $(this).html() );		
				}
			}
			else
			{
				if (this.nodeName=="IMG")
				{
					$(this).attr('title', sText);	
				}
				else
				{
					$(this).text(sText);					
				}
			}
		
		}
	}
	
	function ResGet( resID )
	{
		var ret="";
		
		if (resID)
		{
			ret=g_MqRef.RESX[resID]; 

			if ( typeof(ret)=="undefined")
			{
				// Return the same key
				ret = resID;
				//console.log("Did not find a localized resource for:" + resID + ". Using without translation.");

			}
			
		}
		return ret;
	}
	
	function LoadJSON( jsonRes) 
	{
		try
		{
			if (!g_MqRef.RESX)
			{
				//console.log("creating resx");

				g_MqRef.RESX=new Object();
				g_MqRef.RESX.Get=ResGet;
			}
			
			if (Object.assign)
			{
				Object.assign(g_MqRef.RESX, jsonRes);
			}else{
				for (var attrname in jsonRes) 
				{ 
					g_MqRef.RESX[attrname] = jsonRes[attrname]; 
				}
			}
			//console.log("json loaded");

		}catch(e)
		{
			console.log( e);
		}
	}
	
	function LoadGlobalRes() 
	{
		try
		{
			// Get the culture/language code of the html doc
			var culture=document.documentElement.lang;
			
			if (!culture)
			{
				console.log("no culture found, using default");
				culture="en-US";
			}
			LoadJSONRes("/connect/Localization/" + culture + "/Resources." + culture + ".js");
			LoadJSONRes("/connect/Localization/" + culture + "/ResourcesCust." + culture + ".js");
		} catch(e)
		{
			console.log(e);
			console.log("Error loading LoadGlobalRes ");
		}
	}

	function LoadViewRes( sViewPath)
	{
		LoadJSONRes( "/connect/vzui/" + sViewPath + "/GetResources/");
		 
	}

	function LoadJSONRes( sJSONURL) 
	{
		var sJSONRes = g_MqRef.MqFS.LoadJSONSync( sJSONURL );
		try
		{
			_me.LoadJSON(JSON.parse( sJSONRes));
		} catch(e)
		{
			console.log(e);
			console.log("Error loading JSON from: " + sJSONRes );
		}
	
	}
	
	this.ProcessAll=ProcessAll;
	this.LoadJSON=LoadJSON;
	this.LoadGlobalRes=LoadGlobalRes;
	this.LoadViewRes=LoadViewRes;
}

function MqLogonFrm(sUserFld, sPwdFld, sLogonButtonName, oMqButton, bIsMobile, win, sessURL)
{
	var _gClientID;
	var _win=win;
	var _sUserFld=sUserFld;
	var _sPwdFld=sPwdFld;
	var _sLogonButtonName=sLogonButtonName;
	var _oMqButton=oMqButton;
	 
	if (!win)
	{
		_win=window;
	}else{
		_win=win;
	}
	// Get logon info
	CallInit( _win.location, sessURL);

	function GetUsrFld()
	{
		return _win.document.getElementById(_sUserFld);
	}

	function GetPwdFld()
	{
		return _win.document.getElementById(_sPwdFld);
	}	

	function SetFocus(){
		try{
			if(GetUsrFld().value.length == 0){
				GetUsrFld().focus();
			}else{
				GetPwdFld().focus();
			}
		}
		
		catch(e){
			// element cannot accept focus	
		}
	}

	function CallInit(urlLocation, sessURL)
	{
		//if(!m_blnIsMobile)
		//{
			g_MqRef.RESTClient.Initialize(urlLocation.protocol + "//" + urlLocation.hostname + "/" + 
					sessURL.BaseVDName() );
			g_MqRef.RESTClient.Get("App/LogonPageInfo").then( Init);
			
		//}
	}
	
	function ProcessLogonMsg()
	{
		const LOGON_MSG_ELEMENT = "LogonWarningPaneText";
		const LOGON_MSG_PANE ="LogonWarningPane";
		
		var msg=g_MqRef.MqStr.GetQueryStringValue( null , "m" );
		
		if (msg)
		{
			var elem=_win.document.getElementById( LOGON_MSG_ELEMENT );
		
			if (elem)
			{
				elem.innerHTML=msg;

				elem=_win.document.getElementById( LOGON_MSG_PANE );
				if (elem)
				{
					elem.style.visibility="visible";
					elem.style.display="";

				}
			}
		}
	}
	
	function Init (response) 
	{
		if (response)
		{ 	
			if (response.MSAzureAuthEnabled=="1")
			{
				var sButtonHTML=m_objMqButton.GetTextButtonHTML("azureAcct",g_MqRef.RESX.Get("LOGON.LOGON_WITH_MS_ACCOUNT"), 
					"document.location.replace(\"/connect/MsAuth/GetIdentity?" + GetLogonQS() + "\")",
					'<img src="Theme/images/images/microsoft-logo-icon.png" width="25" height="25" >', 
					32, "margin-bottom:5px;width:92%", "", 414);
				document.getElementById("tdLogonAzure").innerHTML += sButtonHTML;
			}
			
			if (response.GoogleClientID)
			{
				_gClientID= response.GoogleClientID;
				document.getElementById( "g_id_onload" ).setAttribute( "data-client_id", _gClientID );
				// load the google auth library now so the client id exists
				jQuery.ajax({
						type: "GET",
						url: "https://accounts.google.com/gsi/client",
						dataType: "script",
						cache: true
				});

			}
			else
			{
				if (_win.document.getElementById("tdLogonGoogle"))
				{
					_win.document.getElementById("tdLogonGoogle").style.display="none";
				}
			}
		}
	}
	
	function AdjustUI()
	{
		try{
			if(GetUsrFld()){
				var PwdLbl=GetAssociatedLabel(GetPwdFld().id);
			
				if(GetUsrFld().value.length >=2 || bIsMobile){
					GetPwdFld().style.visibility="visible";
					if (PwdLbl){
						PwdLbl.style.visibility="visible";
					}
					_oMqButton.SetState(_sLogonButtonName,_oMqButton.STATE_1);
		
				}else{
					GetPwdFld().style.visibility="hidden";
				
					if (PwdLbl){
						PwdLbl.style.visibility="hidden";
					}
				
					_oMqButton.SetState(_sLogonButtonName,_oMqButton.STATE_2);
				}
			}
		}catch(e){
		}
	}
	
	function ValidateIfButtonsExist(){

		let networkAccButton = _win.document.getElementById("btnActionnetworkAcct");//Network Account Button
		let googleButton = _win.document.getElementById("tdLogonGoogle"); //Google Button
		let AzureButton = _win.document.getElementById("tdLogonAzure");//Azure Button
		


	if(networkAccButton==null && googleButton==null && AzureButton==null){
		ShowHideLogonFields();
		_win.document.getElementById("ckshowLogonControls").checked=true;
	}

	}
	
	function ShowHideLogonFields(){
		
		_win.document.getElementById("loginDivInnerTable").style.display="block";
	}
	
	function OnLoad()
	{
			var vnSetTitle = new HTMLDocumentUITools(); //Set the page title
			vnSetTitle.SetDocumentTitle( _win.document);
			
			g_MqRef.ResMgr.ProcessAll();
			ProcessLogonMsg();
			AdjustUI();
			SetFocus();
			ValidateIfButtonsExist();

	}
	
	function GetLogonQS()
	{
		//remove any qs params we don't want to pass along
		var strQSFinal = location.search;
		
		strQSFinal = g_MqRef.MqURI.RemoveFromQueryString(strQSFinal, "Exit");
		strQSFinal = g_MqRef.MqURI.RemoveFromQueryString(strQSFinal, "UserName");
		strQSFinal = g_MqRef.MqURI.RemoveFromQueryString(strQSFinal, "AuthVD");
		strQSFinal = g_MqRef.MqURI.RemoveFromQueryString(strQSFinal, "LogonType");
		//remove the ? from the beginning
		strQSFinal=g_MqRef.MqStr.StripLeading(strQSFinal, "?");
		
		return strQSFinal;		
	}
	
	this.SetFocus=SetFocus;
	this.AdjustUI=AdjustUI;
	this.CallInit=CallInit;
	this.OnLoad=OnLoad;
	this.ValidateIfButtonsExist=ValidateIfButtonsExist;
	this.GetLogonQS=GetLogonQS;
	
	function GetAssociatedLabel(sElementID)
	{
		try{
		 	var labels = _win.document.getElementsByTagName("label");
	            
	        for (var i = 0; i < labels.length; i++) {
	            if (sElementID==labels[i].htmlFor){
	            	return labels[i];
	            }
	        }
        }catch(e){ 
        }
	}			
	
}

function MqURIOpener()
{
	var m_oMacros;
	var m_oLoadDataMgr;

	function InitForMacros(oMacros, oLoadDataMgr)
	{
		m_oMacros=oMacros;
		m_oLoadDataMgr=oLoadDataMgr;
	
	}
	
	function OpenUNC(strUNC)
	{               
		
		if (strUNC){
	
			if(m_oMacros && m_oLoadDataMgr){
				strUNC=m_oMacros.ResolveFieldMacros(strUNC,m_oLoadDataMgr,false,false);
				
			}
			        
			strUNC=g_MqRef.MqURI.GetURIFromUNC(strUNC);
			
			WriteConsole("Opening UNC as URL: " + strUNC); 
			window.open(strUNC,"_blank","toolbar=no,directories=no,resizable=yes,scrollbars=yes");
		}
		
    }
    
	function Open( url, winProps)
	{               
		
		if (url){
	
			if(m_oMacros && m_oLoadDataMgr){
				url=m_oMacros.ResolveFieldMacros(url,m_oLoadDataMgr,false,false);
				url=m_oMacros.ResolveSLMacros(url);
				
			}
			        
			WriteConsole("Opening URL: " + url); 
			
			if ( typeof(winProps)=='undefined')
			{
				var winProps=new VNWindowProperties();
				winProps.Width=1000;
				winProps.Height=700;
				winProps.Modal=true;
			}
			else
			{
				if (typeof(winProps)=='string')
				{
					winProps=JSON.parse(winProps);
				}
			}
			
			var vnWin = new VNWindow( winProps.Modal);
			vnWin.Open( url, "", winProps.Width, winProps.Height, "","", winProps.SizeMode);
			
		}
		
    }
	
    this.InitForMacros=InitForMacros;
    this.OpenUNC=OpenUNC;
	this.Open=Open;

}

function MqMsgHelper()
{
	function DisplayMessage(strMsg)
	{
		var strMsgToDisplay=FormatMessage(strMsg);
		if(strMsgToDisplay!="")
		{
			return g_MqRef.AlertBox.show("VIZOR", strMsgToDisplay);
		}
	}
	
	function FormatMessage(strMsg)
	{
		var MSG_PART_DELIM="&";
		var IDX_MSG_VAL=0;
		var IDX_MSG_ARGS=1;
		const DEF_ARG_DELIMITER="||";
		var strMsgToDisplay=strMsg;
		
		if(strMsg!=""){
			var arrMsgParts=strMsg.split(MSG_PART_DELIM);
			if(arrMsgParts.length>IDX_MSG_VAL){
				strResString=GetResStr(g_MqRef.MqStr.PropStringDecode(arrMsgParts[IDX_MSG_VAL]));
				if(strResString!=""){
					strMsgToDisplay=g_MqRef.MqStr.FormatString(strResString, 
																								g_MqRef.MqStr.PropStringDecode(arrMsgParts[IDX_MSG_ARGS]),
																								DEF_ARG_DELIMITER);
				}
			}
		}
		return strMsgToDisplay;
	}
	
	function FormatXMLMessage(strXML)
	{
		var MSG_RESULT_XML_TAG="MsgResult";
		var MSG_XML_TAG="Msg";
		var strFormattedMessage="";
		var xmlDoc = $.parseXML(strXML);
		$(xmlDoc).find(MSG_RESULT_XML_TAG).each(function () {
			var strMsg = $(this).find(MSG_XML_TAG).text();
			strMsg=FormatMessage(strMsg);
			//put each item on a new line
			strFormattedMessage+="<br />"+strMsg;
		});	
		return strFormattedMessage;
	}	
	
	function GetResStr(strString)
	{
		var strResString="";
		
		try{
			if(g_MqRef.RESX[strString]){
				strResString=g_MqRef.RESX[strString];
			}
		}catch(e){
			strResString="";
		}
		
		return strResString;
	}
	
	this.DisplayMessage=DisplayMessage;
	this.FormatXMLMessage=FormatXMLMessage;
	this.FormatMessage=FormatMessage;
}

//***** start initialize objects

if (!g_MqRef.MqBrowser){
  g_MqRef.MqBrowser=new CMqBrowserDetector();
}
if (!g_MqRef.MqStr){
  g_MqRef.MqStr=new MqString();
}
if (!g_MqRef.MqFS){
  g_MqRef.MqFS=new MqFiles();
}

if (!g_MqRef.MqURI){
   g_MqRef.MqURI=new CMqURIUtils();
}
if (!g_MqRef.MqArr){
   g_MqRef.MqArr=new CMqArrayMgr();
}
if (!g_MqRef.Deb){
	g_MqRef.Deb=new MqDebug();
}
if (!g_MqRef.ResMgr){
	g_MqRef.ResMgr=new MqResMgr();  
}

if (!g_MqRef.RESX){
	// Load localized resources
	g_MqRef.ResMgr.LoadGlobalRes();
	
}
if(!g_MqRef.MsgHlpr){
	g_MqRef.MsgHlpr=new MqMsgHelper();
}

// Since ConfirmBox is the same name as the constructor, use show
if(!g_MqRef.ConfirmBox.show){
	g_MqRef.ConfirmBox=new ConfirmBox();


}

// Since AlertBox is the same name as the constructor, use show
if(!g_MqRef.AlertBox.show){
	g_MqRef.AlertBox=new AlertBox();
}

if(!g_MqRef.RESTClient.Get)
{
	g_MqRef.RESTClient = new RESTClient();
}

if(!g_MqRef.MqCurr){
	g_MqRef.MqCurr=new CMqCurrency();
}

if(!g_MqRef.MqDate){
	g_MqRef.MqDate=new CMqDate();
}

g_MqRef.BuildNumber=BUILD_NUMBER;



//***** end initialize objects

// Global functions

function WriteConsole(strContent) {
	var wnMain=top;
	var CONTENT_DIV="jsconsole";
	var blnCreateNewWin=false;
	var objDiv;
	
	if (g_MqRef.Deb.GetEnableLog()){
    try{
	// Use the browser console
	console.log(strContent + " t[" + new Date().getTime() + "]" );

	return;

        var wnConsole=wnMain.consoleRef;
        
        if (wnConsole){
            var docTmp=wnMain.consoleRef.document;
            objDiv=docTmp.getElementById(CONTENT_DIV);
        }
    }catch(e){
        blnCreateNewWin=true;
    }
    
		strContent=Date() + " : " + g_MqRef.MqStr.MqHtmlEncode(strContent);
		
		if (!wnConsole || blnCreateNewWin ){
			
			wnMain.consoleRef=window.open('/' + g_MqRef.MqFS.GetCurrentVD() + '/diagnostics/diag.htm','mqjsconsole',
				'width=1000,height=750'
				+',menubar=0'
				+',toolbar=1'
				+',status=0'
				+',scrollbars=1'
				+',resizable=1');
		 
			wnConsole=wnMain.consoleRef;
			
			var divContent=wnConsole.document.getElementById(CONTENT_DIV);
			if (divContent){
				divContent.innerHTML+=strContent;
			}
		}else{
			if (objDiv){
				objDiv.innerHTML=objDiv.innerHTML + "<br>" + strContent + "</br>";
            if (objDiv.scrollIntoView){
                objDiv.scrollIntoView(false);
            }
			}
		}
	}
}

function IncludeScriptFile(strFile){
	var js = document.createElement("script"); 
	 
	js.type = "text/javascript"; 
	js.src = strFile; 
	
	document.body.appendChild(js);
}

// Images Related Event Handlers **********************
function onOver(strName){
	var strPath;

  var objImage=document.images["img" + strName];
  if (objImage){
	  strPath=getPath(objImage.src);

	  if (!isImageDisabled("",objImage)){
		    objImage.src=strPath+strName+"on.gif";
	  }
  }
}

function onOut(strName){
	var strPath;

  var objImage=document.images["img" + strName];
  if (objImage){
	  strPath=getPath(objImage.src);

	  if (!isImageDisabled("",objImage)){
		    objImage.src=strPath+strName+"off.gif";
	  }
  }
}


function writeImageAlt(strName,strSrc,strLink,intWidth,intHeight,blnDisabled,strAlt){
    var strJS;
    var strReturnString;
    var strLinkTemp;
    strReturnString="";
    if (strLink.length>0){
        if (strLink.substring(0,3)=="js:"){
            strJS=strLink.substring(3,strLink.length);
            strLinkTemp="#";
        }else{
            strLinkTemp=strLink;
        }
    }else{
        strLinkTemp="#";
    }
    
    strReturnString+="<a href=\"" + strLinkTemp + "\" id='a_" + strName + "' name='a_" + strName + "'";
  
    if (strJS){
      strReturnString+=(" onClick=\"if (!isImageDisabled('img"+strName+"')){" + strJS + ";return false;}\" ");
    }
    strReturnString+=" onMouseOver=\"onOver('" +strName+ "');\" ";
    strReturnString+=" onMouseOut=\"onOut('" +strName+ "');\" ";
    strReturnString+="><img name='img"+strName+"' ";
    strReturnString+="id='img"+strName+"' ";

    if (blnDisabled){
        strReturnString+="src='"+strSrc+strName.toLowerCase()+"dis.gif' ";
    }else{
        strReturnString+="src='"+strSrc+strName+"off.gif' ";
    }
    strReturnString+="width='"+intWidth+"' ";
    strReturnString+="height='"+intHeight+"' ";
    
    if (strAlt){
        if (strAlt.length>0){
            strReturnString+="alt='"+strAlt+"' title='"+strAlt+"' ";
        }else{
            strReturnString+="alt='"+strName+"' title='"+strName+"' ";
        }
    }else{
        strReturnString+="alt='"+strName+"' title='"+strName+"' ";
    }
    strReturnString+="border='0'></a>";
    
    return strReturnString;
}
	
function disableImage(strImage){
	var objImage;
	var blnReturn;

	blnReturn=true;

  objImage=document.images["img" + strImage];
	
	if (objImage){
		var strPath;
			
		strPath=getPath(objImage.src);
		objImage.src=strPath+strImage+"dis.gif";
    objImage.style.cursor = "default";
    
	}else{
		blnReturn=false;
	}
		
	return blnReturn;
}
	
function enableImage(strImage){
	var objImage;
	var blnReturn;
		
	blnReturn=true;

  objImage=document.images["img" + strImage];
	if (objImage){
		var strPath;

		strPath=getPath(objImage.src);
		objImage.src=strPath+strImage+"off.gif";
    objImage.style.cursor = "";
	}else{
		blnReturn=false;
	}
		
	return blnReturn;
}
	
function disableSCC(){

	parent.objControlsUi.disableControlSCC();
}

function MqStyles()
{
	function LoadJS(strFilename)		//Add JS file to the HEAD
	{
		var fileref=document.createElement('script')
		fileref.setAttribute("type","text/javascript")
		fileref.setAttribute("src", strFilename)
		if (typeof fileref!="undefined")
		{
			document.getElementsByTagName("head")[0].appendChild(fileref)
		}
	}
	
	function LoadCSS(strFilename)		//Add CSS file to the HEAD
	{
		var fileref=document.createElement("link")
		fileref.setAttribute("rel", "stylesheet")
		fileref.setAttribute("type", "text/css")
		fileref.setAttribute("href", strFilename)
		if (typeof fileref!="undefined")
		{
			document.getElementsByTagName("head")[0].appendChild(fileref)
		}
	}
	
	this.LoadJS = LoadJS;
	this.LoadCSS = LoadCSS;
}

function HTMLDocumentUITools () {
    var _self = this;
    var m_mbl = g_MqRef.MqBrowser.mobile;
    
    function SetDocumentTitle(docRef) {
        //Set document title regardless of what platform
        docRef.title = g_MqRef.RESX.Get("LOGON.TITLE");
        //If mobile platform
        if(m_mbl) {
            var mblMeta = docRef.createElement('meta');
            var mblContentMeta = docRef.createElement('meta');
            //Set iOS specific entries for document
            mblMeta.httpEquip = "apple-mobile-web-app-title";
            mblMeta.content = g_MqRef.RESX.Get("LOGON.TITLE");
            mblContentMeta.httpEquip = "apple-mobile-web-app-capable";
            mblContentMeta.content = "yes";
            //Append the Meta to the head as a child
            docRef.getElementsByTagName('head')[0].appendChild(mblMeta);
            docRef.getElementsByTagName('head')[0].appendChild(mblContentMeta);
        }
    }
    _self.SetDocumentTitle = SetDocumentTitle;
}

function CMqAlert(strObjName, strURL, arrFieldIDs, lngWidth, lngHeight, objViewFields, blnOnFieldChangeOnly)
{
	var m_strObjName=strObjName;
	var m_strURL=strURL;
	var m_arrFieldIDs=arrFieldIDs;
	var m_lngWidth=lngWidth;
	var m_lngHeight=lngHeight;
	var m_objViewFields=objViewFields;
	var m_blnOnFieldChangeOnly=blnOnFieldChangeOnly;
	
	function HandleAlert(strVals, strFieldsHTMLContainer, blnOnFieldChange)
	{
		var blnShowAlert=true;
		if(strVals!=""){
			if(blnOnFieldChangeOnly){
				if(!blnOnFieldChange){
					blnShowAlert=false;
				}
			}
			if(blnShowAlert){
				var arrVals=unescape(strVals).split("=");
						
				var strVal=unescape(arrVals[1]);
				
				if(strVal!=""){		
					window.setTimeout(m_strObjName + ".ShowAlert('" + strFieldsHTMLContainer + "')", 1000);
				}
			}
		}
	}
	
	function ShowAlert(strFieldsHTMLContainer)
	{
		var strArgs="";
		var strURL=m_strURL;
		if(arrFieldIDs){
			for(var x=0; x<arrFieldIDs.length;x++){
				var objField=m_objViewFields.Field(arrFieldIDs[x]);
				if (objField){
					var objFormElement=new CMqFormElement();
					var lngCtrlType=objField.GetControlType();
					objFormElement.Initialize(objField.GetBoundControl(),lngCtrlType,strFieldsHTMLContainer);
					strArgs+=objFormElement.GetValue()+",";
				}else{
					strArgs+=",";
				}
			}
			strArgs=g_MqRef.MqStr.StripTrailing(strArgs, ",")
			strURL=g_MqRef.MqStr.FormatString(strURL,strArgs);
		}
		OpenModalWindow(strURL, m_lngWidth, m_lngHeight);
	}
	this.HandleAlert=HandleAlert;
	this.ShowAlert=ShowAlert;
}

function RESTClient()
{
    var _strbaseURL;
    
    function Initialize(strbaseURL)
    {
        _strbaseURL = strbaseURL;
    }

    function Post(strURL_Service_Resource, dataToSend) {
        var defer = $.Deferred();
        $.ajax({
            type: "POST",
            data:dataToSend,
            url: _strbaseURL + "/" + strURL_Service_Resource,
            dataType: "json",
            contentType: " application/json",
        }).success(function (data) {
            m_serviceResponse = data;
            defer.resolve(m_serviceResponse);
        
        })
        .error(function (err) {
            console.log(err.statusText);
            defer.resolve(err);
        });

        return defer;
    }

    function Get(strURL_Service_Resource)
     {
        var defer = $.Deferred();
        $.ajax({
            type: "GET",
            url: _strbaseURL + "/" + strURL_Service_Resource,
            dataType: "json",
            contentType: " application/json",
        }).success(function (data) {
            m_serviceResponse = data;
            defer.resolve(m_serviceResponse);
        
        })
        .error(function (err) {
            console.log(err.statusText);
            defer.resolve(err);
        });

        return defer;
    }
    this.Initialize = Initialize;
    this.Get = Get;
    this.Post = Post;
}


function CMqCurrency()
{
	var m_RegExDelimiter = new RegExp("\\"+g_MqRef.RESX.Get('CURRENCY.THOUSANDS'), "g");
	var m_RegExDecimal = new RegExp("\\"+g_MqRef.RESX.Get('CURRENCY.DECIMAL'), "g");
	
	var m_arrCalcFieldSrcs=new Array();
	var m_arrCalcFieldTgts=new Array();

	var CURR_VAL_NONE=""; //"0.00";
	
	function Format(strValue, blnSkipSymbol)
	{
		var strFormattedValue="";
		if(!IsValidCurrency(strValue))
		{
			strValue = CURR_VAL_NONE;
		}
		
		strValue=strValue.replace(m_RegExDelimiter, "");
		strValue=strValue.replace(m_RegExDecimal, ".");
		
		if (strValue)
		{
			strFormattedValue=parseFloat(strValue)
											.toFixed(2)
											.toString()
											.replace(/\./g, g_MqRef.RESX.Get('CURRENCY.DECIMAL')) 
											.replace(/\B(?=(\d{3})+(?!\d))/g, g_MqRef.RESX.Get('CURRENCY.THOUSANDS'));
		}
		else
		{
			strFormattedValue= strValue;
		}
			
		if(typeof(blnSkipSymbol)=="undefined"){
			blnSkipSymbol=false;
		}
		
		if(!blnSkipSymbol){
			strFormattedValue = g_MqRef.RESX.Get('CURRENCY.SYMBOL') + " " + strFormattedValue;
		}
		
		return strFormattedValue;
	}
	
	
	function FormatDefault(strValue)
	{		
		if(IsValidCurrency(strValue))
		{
			//Convert Edit value to use NA format (#####.##)
			strValue = parseFloat(strValue.replace(m_RegExDelimiter, "").replace(m_RegExDecimal, ".")).toFixed(2);
		}
		else
		{
			//Default value for currency field
			strValue = CURR_VAL_NONE;
		}
		
		return strValue;
	}
	
	
	this.Format=Format;
	this.FormatDefault=FormatDefault;
	
	function IsValidCurrency(strValue)
	{
		var blnValid=false;
		
		if(strValue != "")
		{
			strValue=strValue.replace(m_RegExDelimiter, "");
		
			strValue=strValue.replace(m_RegExDecimal, ".");
			
			blnValid=!isNaN(strValue);
		}

		return blnValid;
	}
}

function CMqDate()
{
	function Format(strValue)
	{
		var strFormattedValue=strValue;
		if(strValue.indexOf(" ")>0){
			var formattedVal=strValue.split(" ");
			strFormattedValue=formattedVal[0];
		}
		return strFormattedValue;
	}
	
	function DateDiff(date1, date2)
	{
		var date1_ms = date1.getTime();
		var date2_ms = date2.getTime();
		
		return date2_ms - date1_ms;
	}
	this.Format=Format;
	this.DateDiff=DateDiff;
}


function CMqXML(strXML)
{
	var RESULT_DELIMITER = ";";
	var m_strXML=strXML;
	
	function Search(strSearchPath)
	{
		var strSearchResult = "";
		if (window.DOMParser) { 
			var parser = new DOMParser();
			var xmlDoc = parser.parseFromString (m_strXML, "text/xml");
			if (xmlDoc.evaluate) {
				var iterator = xmlDoc.evaluate(strSearchPath, xmlDoc, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
				try {
					var node = iterator.iterateNext();
					while (node) {
						strSearchResult+=node.textContent + RESULT_DELIMITER;
						node = iterator.iterateNext();
					} 
				}
				catch (e) {
					WriteConsole( 'Error: CMqXML.Search failed getting node values ' + e );
				}
			}else{
				//IE
				var doc = new ActiveXObject('Microsoft.XMLDOM'); 
				doc.loadXML(m_strXML); 
				try {
					var nodes = doc.selectNodes(strSearchPath);
					for (var y=0; y<nodes.length; y++) {
						if(nodes[y]){
							if(nodes[y].childNodes){
								if(nodes[y].childNodes[0]){
									strSearchResult+=nodes[y].childNodes[0].nodeValue + RESULT_DELIMITER;
								}
							}
						}
					}
				}
				catch (e) {
					WriteConsole( 'Error: CMqXML.Search failed getting child node values ' + e );
				}
			}
		}
		
		strSearchResult=g_MqRef.MqStr.StripTrailing(strSearchResult, RESULT_DELIMITER);
		return strSearchResult;
	}
	
	this.Search=Search;
}

function InitGA()
{
	if (GAEnabled)
	{
		var sGAID="UA-881582-4";
	
		// Global site tag (gtag.js) - Google Analytics 

		var sURL="https://www.googletagmanager.com/gtag/js?id=" + sGAID;
		g_MqRef.MqFS.LoadScript(sURL,null,document);
		window.dataLayer = window.dataLayer || [];
		function gtag(){dataLayer.push(arguments);}
		gtag('js', new Date());
		gtag('config', sGAID);

		(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

		ga('create', sGAID, 'auto');
		ga('send', 'pageview');
		
		(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
		new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
		j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
		'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
		})(window,document,'script','dataLayer','GTM-WGJVJCG');

	}else
	{
		window.ga=function(){};
	}
}
InitGA();

function InitIncludes()
{
	
	if(g_MqRef.MqBrowser.mobile){
		
		var objStyles=new MqStyles();
		var varSegments = top.document.location.pathname.split("/");
		var view = varSegments[2];
		
		if (view.toLowerCase().includes("checkincheckout") || view.toLowerCase().includes("manageloc"))
		{
			objStyles.LoadCSS(g_MqRef.MqFS.GetCurrentVDURL(window)+"/theme/css/vn.core.mobile.css");
		}
		else
		{
			objStyles.LoadCSS(g_MqRef.MqFS.GetCurrentVDURL(window)+"/theme/css/censusmainmobile.css");
		}
		
		//this will overwrite materialize.custom.css with the file below when in mobile
		objStyles.LoadCSS(g_MqRef.MqFS.GetCurrentVDURL(window)+"/materialize/css/materialize.custom.mobile.css");
	}
}

InitIncludes();

function MqCookies(blnWriteAltPaths)
{
	var arrCookies;
	var m_strMainVD="";
	var m_blnWriteAltPaths=true;
    
    var MAIN_COOKIE_NAME="MqMain";
	var REG_COOKIE_POSTFIX="1";
	var LCASE_COOKIE_POSTFIX="2";
	
    var m_strMainCookieValue="";
    var m_strMainCookieName="";
    
    var COOKIE_PROP_VAL_DELIM="=";
    var COOKIE_PROPERTY_DELIM="; ";
    
    var objMqStr=g_MqRef.MqStr;
		
	if (typeof(blnWriteAltPaths)!="undefined"){
		m_blnWriteAltPaths=blnWriteAltPaths;
	}
  
	arrCookies=new Array();

	function getCookie(strCookieName)
	{
		var strReturn=isCached(strCookieName);
		
		if (!strReturn){
			strReturn=objMqStr.MqDecodeURIComponent(getCookieValue(objMqStr.MqEncodeURIComponent(strCookieName)));	
			writeToCache(strCookieName,strReturn);
		}
		
		return strReturn;
	}
	
	function setCookie(strCookieName,strValue,intExpireSecs)
	{
		var blnReturn;
		var expire = new Date();
		
		var strCookieExpireDate=GetCookieExpiryDate(intExpireSecs, expire);
		
		var strVirtualDir=GetVirtualDirName(this);

				
		var strEncodedCookieName=objMqStr.MqEncodeURIComponent(strCookieName);
		var strEncodedCookieValue=objMqStr.MqEncodeURIComponent(strValue);

		SetDocumentCookie(strEncodedCookieName, strEncodedCookieValue, strCookieExpireDate, expire, strVirtualDir);

		if (m_blnWriteAltPaths){
			if(strVirtualDir!=strVirtualDir.toLowerCase()){
				SetDocumentCookie(strEncodedCookieName, strEncodedCookieValue, strCookieExpireDate, expire, strVirtualDir.toLowerCase());
			}
		}
    
		if (isCached(strCookieName)){
			blnReturn=updateCache(strCookieName,strValue);
		}else{
			blnReturn=writeToCache(strCookieName,strValue);
		}
		
		return blnReturn;
	}

	function GetCookieProp(strMainCookieName, strPropName)
	{
		var strReturn;
		
		strReturn=GetCookieValueFromString(strPropName, COOKIE_PROP_VAL_DELIM, objMqStr.MqDecodeURIComponent(GetMainCookieValue(strMainCookieName)), COOKIE_PROPERTY_DELIM)
		
		//strReturn=objMqStr.MqDecodeURIComponent(strReturn);	
		
		if(strReturn!=""){
			strReturn=objMqStr.MqDecodeURIComponent(strReturn);
		}
		return strReturn;
	}
	
	function SetCookieProp(strMainCookieName, strPropName, strPropValue, intExpireSecs)
	{
		var expire = new Date();
		
		var strCookieExpireDate=GetCookieExpiryDate(intExpireSecs, expire);
		
		var strVirtualDir=GetVirtualDirName(this);
		
		var strEncodedPropName=objMqStr.MqEncodeURIComponent(strPropName);
		var strEncodedPropValue=objMqStr.MqEncodeURIComponent(strPropValue);
		
		var strMainCookieValue=AddPropertyToMainCookieString(strMainCookieName, strEncodedPropName, strEncodedPropValue);
				
		m_strMainCookieValue=strMainCookieValue;

		SetDocumentCookie(GetMainCookieName() + REG_COOKIE_POSTFIX, strMainCookieValue, strCookieExpireDate, expire, strVirtualDir);

		if (m_blnWriteAltPaths){
			if(strVirtualDir!=strVirtualDir.toLowerCase()){
				SetDocumentCookie(GetMainCookieName() + LCASE_COOKIE_POSTFIX, strMainCookieValue, strCookieExpireDate, expire, strVirtualDir.toLowerCase());
			}
		}
	}
	
	//*************From Cookies.Inc File*********************
	
	//this function will register the cookies
	function registerCookie(name,value)
	{
	   this.setCookie(name, value);
	} 
	
	function CookiesEnabled()
	{
		if (navigator.appName == "Netscape" ){
			return true;
		}else{
			return window.navigator.cookieEnabled;
		}
	}
	
	function getFieldValue(fieldName, strToSearchIn)
	{
	    var varParsString = "";
	    var pos = strToSearchIn.indexOf(fieldName);
	    var pos2;

	    if (pos != -1){
			pos2 = strToSearchIn.indexOf("&", pos + fieldName.length + 1);
			if (pos2 != -1) {
				varParsString= strToSearchIn.substr(pos + fieldName.length + 1, pos2 - (pos + fieldName.length + 1));
				return (unescape(varParsString));
			}
		}else{
			return ("");
		}
	}
	
	function GetMainCookieName()
	{
		var strReturn;
		
		if(m_strMainCookieName=="" || typeof(m_strMainCookieName)=="undefined"){
			m_strMainCookieName=MAIN_COOKIE_NAME;
		}

		return m_strMainCookieName;
	}

	function SetMainCookieName(strName)
	{
		m_strMainCookieName=strName;
	}
	
	function SetMainCookieValue(strValue)
	{
		m_strMainCookieValue=strValue;
	}
	
	this.MainVD=m_strMainVD;
	this.getCookie=getCookie;
	this.setCookie=setCookie;
	this.registerCookie=registerCookie;
	this.CookiesEnabled=CookiesEnabled;
	this.getFieldValue=getFieldValue;
	this.GetMainCookieName=GetMainCookieName;
	this.SetMainCookieName=SetMainCookieName;
	this.GetCookieProp=GetCookieProp;
	this.SetCookieProp=SetCookieProp;
	this.SetMainCookieValue=SetMainCookieValue;
	
	//private
	function isCached(strName)
	{
		var strReturn;
		var intCount;
		
		strReturn=false;
		for(intCount=0;intCount<arrCookies.length;intCount++){
			if (arrCookies[intCount][0]==strName){
				strReturn=arrCookies[intCount][1];
			}
		}
		return strReturn;
	}
	
	function updateCache(strName,strValue)
	{
		var intCount;
		var blnReturn;
		
		blnReturn=false;
		for(intCount=0;intCount<arrCookies.length;intCount++){
			if (arrCookies[intCount][0]==strName){
				arrCookies[intCount][1]=strValue;
				blnReturn=true;
			}
		}
		return blnReturn;
	}

	function writeToCache(strName,strValue)
	{
		arrCookies[arrCookies.length]=[strName,strValue];	
		return true;
	}
	
	function getCookieValue(strName)
	{	
		var strReturn="";
		if(strName==objMqStr.MqEncodeURIComponent(GetMainCookieName())){
			strReturn=GetMainCookieValue(strName);
		}else{
			var strCookieString=document.cookie;
			strReturn=GetCookieValueFromString(strName, COOKIE_PROP_VAL_DELIM, strCookieString, COOKIE_PROPERTY_DELIM)
		}
		return strReturn;
	}

	function GetCookieValueFromString(strName, strPropValDelim, strCookieString, strPropertyDelim)
	{
		var lngFirstChar, lngLastChar;
		var strReturn="";
		
		strName+=strPropValDelim;
		
		lngFirstChar = strCookieString.indexOf(strName);

		if(lngFirstChar != -1){
			lngFirstChar += strName.length;
			lngLastChar = strCookieString.indexOf(strPropertyDelim, lngFirstChar);
	    	
	    	if(lngLastChar == -1){
	    		lngLastChar = strCookieString.length;
	    	}	
	    	strReturn=strCookieString.substring(lngFirstChar, lngLastChar);
		}

		return strReturn;
	}
	
	function GetMainCookieValue(strMainCookieName)
	{
		var strReturn="";

		if(m_strMainCookieValue==""){
			
			if(strMainCookieName=="" || typeof(strMainCookieName)=="undefined"){
				strMainCookieName=GetMainCookieName();
			}
		
			strReturn = getCookieValue(strMainCookieName + REG_COOKIE_POSTFIX);
		
			if (strReturn.length==0){
				strReturn = getCookieValue(strMainCookieName + LCASE_COOKIE_POSTFIX);
			}
						
			m_strMainCookieValue=strReturn;
		}else{
			strReturn=m_strMainCookieValue;
		}
		
		return strReturn;
	}
	
	function GetCookieExpiryDate(intExpireSecs, expire)
	{
		var today = new Date();
    
		if (isNaN(intExpireSecs)){
		    expire.setTime(today.getTime() + 1000*60*60*24*365);
		}else{
		    expire.setTime(today.getTime() + 1000*intExpireSecs);
		}
		return expire.toGMTString();
	}

	function GetVirtualDirName(objThis)
	{
		var strVirtualDir="";
		var strSlash="/";

		if (objThis.MainVD!=="") {
			strVirtualDir= objThis.MainVD;
		} else {
			strVirtualDir = window.location.pathname;
			if (strVirtualDir.indexOf(strSlash) === 0){ 
		        strVirtualDir = strVirtualDir.substring(strSlash.length, strVirtualDir.length);
		    }
		 	if (strVirtualDir.indexOf(strSlash) > 0){
		        strVirtualDir = strVirtualDir.substring(0, strVirtualDir.indexOf(strSlash));
		    }
		}	
		return strVirtualDir;	
	}
	
	function SetDocumentCookie(strCookieName, strCookieValue, strCookieExpireDate, expire, strPath)
	{
		document.cookie=strCookieName + COOKIE_PROP_VAL_DELIM + strCookieValue + ((expire == null) ? "" : ("; expires=" + strCookieExpireDate))+ ";Path=/" + strPath + "/";
	}
	
	function AddPropertyToMainCookieString(strMainCookieName, strEncodedPropertyName, strEncodedPropertyValue)
	{
		var strMainDocCookie=objMqStr.MqDecodeURIComponent(GetMainCookieValue(strMainCookieName));
			
		if(objMqStr.PropertyExists(strMainDocCookie, strEncodedPropertyName, COOKIE_PROPERTY_DELIM, COOKIE_PROP_VAL_DELIM)>=0){									
			strMainDocCookie=objMqStr.ReplacePropertyValue(strMainDocCookie, strEncodedPropertyName, strEncodedPropertyValue, COOKIE_PROPERTY_DELIM, COOKIE_PROP_VAL_DELIM); 
		}else{
			if(strMainDocCookie!=""){
				strMainDocCookie+=COOKIE_PROPERTY_DELIM;
			}
			strMainDocCookie+=strEncodedPropertyName + COOKIE_PROP_VAL_DELIM + strEncodedPropertyValue;
		}
		strMainDocCookie=objMqStr.MqEncodeURIComponent(strMainDocCookie);
		
		return strMainDocCookie;
	}
}

// TODO: Move it inside CMqHttpResponse or CMqMessage
var MSG_TRUE="1";

function CMqHTTPRequest_js() {
	var CANCEL_PROCESS="-99999999";
	var REQUEST_REMOTE_CALL="REMOTE_CALL";
	var REMOTE_CALL_TRUE="-1";
	var appRequest;
	var objSysMsg=new CMqSysMsg;
	var m_oMqString=new MqString;
	var m_strParam;
	var m_blnUseCache=false;
	var m_varCachedResponse;
	var INVALID_INDEX=-1;
	var ARR_URL=0;
	var ARR_OUTPUT=1;
	var INDEX_ENCODED_SYSMSG=0;
	var INDEX_ENCODED_MSGTEXT=1;
	var INDEX_ENCODED_FORCEEXIT=2;
	var PROPERTY_DELIMITER="&";
	var self=this;
	var mlngAppMsgTries=0;
	var MAX_TRIES_BEFORE_MSG=20;
	var DEF_CHSET="ISO-8859-1";
	var UTF8_CHSET="UTF8";
	var m_objXMLHttpReqObj;
	var USE_APPLET=false;
	
	function Get(strUrlPath, bUTF8)
	{
		var strResult="";
		var blnHTTPGet =true;
		try{
			
		    if (m_blnUseCache){
			    var lngCacheIndex=IsCached(strUrlPath, m_varCachedResponse);
			    if (lngCacheIndex!=INVALID_INDEX){
				    strResult=GetCachedResponse(lngCacheIndex,m_varCachedResponse);
				    blnHTTPGet=false;
			    }
			
		    }
		    if (blnHTTPGet){
				var strHTTPUrlPath=strUrlPath;
				if(strUrlPath.indexOf("?")>0){
				    strHTTPUrlPath+="&";
				}else{
					strHTTPUrlPath+="?";
				}
				strHTTPUrlPath+=REQUEST_REMOTE_CALL + "=" + REMOTE_CALL_TRUE;
				
				strHTTPUrlPath+="&rd=" + Math.floor(Math.random()*1000001)
				
			    if (m_strParam){
				    strHTTPUrlPath=strHTTPUrlPath+"&"+ m_strParam;
			    }
				
				if(USE_APPLET){
					if (IsAppletLoaded(appRequest)){
						if (bUTF8){
							appRequest.SetCharset(UTF8_CHSET);
						}
						var co=appRequest.Get(strHTTPUrlPath);

						strResult=ProcessResponse(co,m_blnUseCache,strUrlPath);
						if (bUTF8){
							appRequest.SetCharset(DEF_CHSET);
						}
					}else{
						strResult=CANCEL_PROCESS;
					}
				}else{
					var objReq = GetXMLHttpReqObj();
					if(objReq){
						objReq.open("GET", strHTTPUrlPath, false);
						objReq.send(null);
						if(objReq.status==200){
							var co=objReq.responseText;
							strResult=ProcessResponse(co,m_blnUseCache,strUrlPath);
						}else{
							//alert(objReq.status);
							strResult=CANCEL_PROCESS;
						}
					}else{
						strResult=CANCEL_PROCESS;
					}
				}
		    }
		}catch(err){
			alert(err.description);
		}
		return strResult;
	}
	
	function Post(strUrlPath,strPostData,bUTF8)
	{
		var strResult="";
		try{
			if(strUrlPath.indexOf("?")>0){
				strUrlPath+="&";
		    }else{
				strUrlPath+="?";
		    }
		    strUrlPath+=REQUEST_REMOTE_CALL + "=" + REMOTE_CALL_TRUE;
		     
		    if (m_strParam){
			    strUrlPath=strUrlPath+"&"+ m_strParam;
		    }
			
			if(USE_APPLET){
				if (IsAppletLoaded(appRequest)){
					if (bUTF8){
						appRequest.SetCharset(UTF8_CHSET);
					}
					var co=appRequest.Post(strUrlPath,strPostData);

				    strResult=ProcessResponse(co,false,"");
					if (bUTF8){
						appRequest.SetCharset(DEF_CHSET);
					}
				}else{
					strResult=CANCEL_PROCESS;
				}		
			}else{
				var objReq = GetXMLHttpReqObj();
				if(objReq){
					objReq.open("POST", strUrlPath, false);
					objReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					if(!(g_MqRef.MqBrowser.ie==true && g_MqRef.MqBrowser.major <=6)){
						//objReq.setRequestHeader("Content-length", strPostData.length);
						//objReq.setRequestHeader("Connection", "close");
					}
					objReq.send(strPostData);
					if(objReq.status==200){
						var co=objReq.responseText;
						strResult=ProcessResponse(co,false,"");
					}else{
						//alert(objReq.status);
						strResult=CANCEL_PROCESS;
					}
				}else{
					strResult=CANCEL_PROCESS;
				}
			}		    	
		}catch(err){
			alert(err.description);
		}
		return strResult;
	}
	
	function GetXMLHttpReqObj()
	{
		if(m_objXMLHttpReqObj){
			return m_objXMLHttpReqObj;
		}else{
			// Provide the XMLHttpRequest class for IE 5.x-6.x:
			if( typeof XMLHttpRequest == "undefined" ){
				try { 
				  m_objXMLHttpReqObj = new ActiveXObject("Msxml2.XMLHTTP.6.0") 
				  } catch(e) {}
				
				if(!m_objXMLHttpReqObj){
					try { 
					  m_objXMLHttpReqObj = new ActiveXObject("Msxml2.XMLHTTP.3.0") 
					  } catch(e) {}
					  
					if(!m_objXMLHttpReqObj){
						try { 
						  m_objXMLHttpReqObj = new ActiveXObject("Msxml2.XMLHTTP") 
						  } catch(e) {}
						
						if(!m_objXMLHttpReqObj){
							try { 
							  m_objXMLHttpReqObj = new ActiveXObject("Microsoft.XMLHTTP") 
							  } catch(e) {}
						}
					}
				}
			}else{
				m_objXMLHttpReqObj = new XMLHttpRequest();
			}
			return m_objXMLHttpReqObj;
		}
	}
	function ProcessResponse(strSvrResponse, blnCache, strUrlPath)
	{
		var strResult="";
		
		if (strSvrResponse){
			strSvrResponse=String(strSvrResponse);
			strSvrResponse= m_oMqString.getNullTerminatedString(strSvrResponse);
		
			if (objSysMsg.isSysMsg(strSvrResponse)){
				var arrSysMsg=ParseSysMsg(strSvrResponse);
				if (arrSysMsg){
					objSysMsg.doSysMsg(arrSysMsg[INDEX_ENCODED_SYSMSG], arrSysMsg[INDEX_ENCODED_MSGTEXT],
										arrSysMsg[INDEX_ENCODED_FORCEEXIT]);
				}else{
					objSysMsg.doSysMsg(strSvrResponse);
				}
				strResult= CANCEL_PROCESS;
			}else{
				strResult= strSvrResponse;
				if (blnCache && strUrlPath){
					SetCachedResponse(strUrlPath,strResult);
				}
			}
		}
		return strResult;
	}
	
	function ParseSysMsg(strEncodedMessage)
	{
		var arrSysMsg;
		
		if (strEncodedMessage){
			arrSysMsg=strEncodedMessage.split(PROPERTY_DELIMITER);
		}
		return arrSysMsg;
	}
	
	
	function setParam(strParam)
	{
		m_strParam=strParam;
	}
	
	function IsAppletLoaded(objApplet)
	{
		if(USE_APPLET){
			var fAppletLoaded=false;
			if(IsJavaEnabled(objApplet)){
				if (objApplet.isActive()){
					fAppletLoaded=true;
				}
			}else{
				self.OpenJavaVMHelpWindow();
			}
								
			return fAppletLoaded;
		}else{
			return true;
		}
	}
	
	function IsJavaEnabled(objApplet)
	{
		var blnJavaEnabled=true;
		if (navigator.javaEnabled()){
			try{
				if (objApplet){	
				
					if (objApplet.isActive()){
					}
				}
				
			}catch (errorObject) {
				blnJavaEnabled=false;
			}
		}else{
			blnJavaEnabled=false;
		}
					
		return blnJavaEnabled;
	}
	
	function OpenJavaVMHelpWindow()
	{
		if(mlngAppMsgTries==0){
			OpenChildWindow(g_MqRef.MqFS.GetCurrentVDURL(window) + "/HTML/TmplJavaVMHelp.htm", "JavaVMHelp","toolbar=no,resizable=no,directories=no,width=600,height=300", true, 600, 300);
		}

		if(mlngAppMsgTries==MAX_TRIES_BEFORE_MSG){
			mlngAppMsgTries=0;
		}else{
			mlngAppMsgTries++;
		}
	}
	
	function GetRspObj(strResponse){
		var objResponse =new CMqHttpResponse(strResponse);
		return objResponse;
	}
	
	function SetUseCache(blnCache)
	{
		m_blnUseCache=blnCache;
	}
	
	function GetUseCache()
	{
		return m_blnUseCache;
	}
	
	function ClearCache()
	{
		m_varCachedResponse=null;
	}
	function GetAppRequest()
	{
		return appRequest;		
	}
	function SetAppRequest(objAppRequest)
	{
		appRequest=objAppRequest;
	}
	function WriteAppletHTML(strCodeBase,objDocument)
	{
		if(USE_APPLET){
			if(!objDocument){
				objDocument=document;
			}
			if(objDocument){
				objDocument.write(GetAppletHTML(strCodeBase,objDocument));
			}
		}
	}
	
  function GetRsp(strURL)
  {
    return GetRspObj(Get(strURL));
  }

	this.setParam=setParam;
	this.Get=Get;
	this.Post=Post;
	this.GetAppRequest=GetAppRequest;
	this.SetAppRequest=SetAppRequest;
	this.Response=GetRspObj;
	this.SetUseCache=SetUseCache;
	this.GetUseCache=GetUseCache;
	this.ClearCache=ClearCache;
	this.CANCEL_PROCESS=CANCEL_PROCESS;
	this.WriteAppletHTML=WriteAppletHTML;
	this.IsAppletLoaded=IsAppletLoaded;
	this.OpenJavaVMHelpWindow=OpenJavaVMHelpWindow;
	this.GetRsp=GetRsp;
	this.IsJavaEnabled=IsJavaEnabled;
	
	//private methods
	function GetAppletHTML(strCodeBase,objDocument)
	{
		var strHtml="";
		if (objDocument){							

			strHtml="<applet codebase='" + strCodeBase +"' ";
			strHtml+=" code='MqHttpRequest.class' archive='MqHttpRequest.class' width=1 height=1 id='MqHttpRequest' name='MqHttpRequest' MAYSCRIPT>";
			strHtml+="<param name=\"browserCookie\" value=\"" + objDocument.cookie + "\">";
			strHtml+="<param name=\"charset\" value=\"" + DEF_CHSET + "\"><param name=\"debug\" value=\"false\"></applet>";
			
		}				
		return strHtml;
	}
	function IsCached(strUrl,varCachedResponse){
		var lngCount;
		var lngIndex=INVALID_INDEX;
		if (varCachedResponse){
			for (lngCount=0;lngCount<varCachedResponse.length;lngCount++){
				if (varCachedResponse[lngCount][ARR_URL]==strUrl){
					lngIndex=lngCount;
					break;
				}
			}
		}
		return lngIndex;
	}
	function GetCachedResponse(lngIndex,varCachedResponse){
		var lngCount;
		var strFound;		
		strFound="";
		if(varCachedResponse){
			strFound=varCachedResponse[lngIndex][ARR_OUTPUT];
		}
		return strFound;
	}
		
	function SetCachedResponse(strUrl,strReponse){
		if (!m_varCachedResponse){
			m_varCachedResponse=new Array();	
		}
		if (strReponse!= CANCEL_PROCESS){			
			m_varCachedResponse[m_varCachedResponse.length]=new Array(strUrl,strReponse);		
		}		
	}	
}

function CMqHttpResponse(strResponse){
	//constructor *****
	var m_strResponse=unescape(strResponse);
	var m_strRefLocation;
	if (g_MqRef.RefLocation){
	  m_strRefLocation=g_MqRef.RefLocation;
	}else{
	  m_strRefLocation="./";
	}
  
	var ERROR_ITEM="Err";
	var CONTENT_ITEM="Content";
	var m_objString=new MqString();	
	var m_strErrors;
	var self=this;
  
  try{
    this.IsOK=GetContent().GetText()==MSG_TRUE;
  }catch(e){
    this.IsCancel=true;
  }
  
	function HasErrors()
	{
		var blnHasErrors=false;		
		m_strErrors= m_objString.GetPropertyValue(ERROR_ITEM,m_strResponse,true);
		if(m_strErrors){
			blnHasErrors=true;
		}
		return blnHasErrors;
	}
	function GetErrors(blnUnescape){
		var objErrors;
		
		if (blnUnescape==null){
			blnUnescape=true;
		}
		
		if (m_strResponse){
			if(!m_strErrors){
				m_strErrors= m_objString.GetPropertyValue(ERROR_ITEM,m_strResponse,true);
			}
			if (m_strErrors){
				objErrors= new CMqMessageCol(m_strErrors,blnUnescape);
				if (objErrors.Count==0){
					objErrors=null;
				}
			}
		}
		return objErrors;
	}
	function GetContent(blnUnescape)
	{
		var objMessage;
		if (blnUnescape==null){
			blnUnescape=true;
		}
		
		if (m_strResponse){
			var strContent=m_objString.GetPropertyValue(CONTENT_ITEM,m_strResponse,true);
			if (strContent){
				objMessage= new CMqMessage();
				objMessage.Load(strContent,blnUnescape);
			}			
		}
		return objMessage;
	}

	function GetData()
	{
		var objData;
		if (m_strResponse){
			var objContent=JSON.parse(m_strResponse);
			if (objContent){
				if(objContent.Data){
					objData=JSON.parse(objContent.Data);
				}
			}			
		}
		return objData;
	}
	
    function ProcessErrors(strMsgMask,blnShowFirstOnly,objWindow)
    {
        var objErrors=GetErrors();
        var strErrStr=m_strErrors;
        if (objErrors && strErrStr){
            var blnCancel=false;
            var arrErrors=objErrors.Items();
                    
            if (arrErrors){
                for (i=0;(i<arrErrors.length) && (!blnCancel);i++){
                    blnCancel=self.ProcessSingleError(arrErrors[i],objErrors);
                }

                if (!blnCancel){
                    if ((arrErrors.length==1) || blnShowFirstOnly){
                        var objError=arrErrors[0];
                        var strErr;
                        if (strMsgMask){
                            strErr=m_objString.Format(strMsgMask,objError.GetText(),objError.GetAdditionalInfo() );
                        }else{
                            strErr=objError.GetText();
                            strErr+="\n" + objError.GetAdditionalInfo();
                        }
                        if (strErr){
							if(objWindow){
								objWindow.alert(strErr);
							}else{
								alert(strErr);
							}
                        }
                    }else{
                        if (strErrStr){
                            strErrStr=escape(strErrStr);
                            if (window.BrowserDetector){
                                if (window.BrowserDetector.minor=="5.01"){
                                    // Bug in ie 5.01: decodes urls
                                    strErrStr=escape(strErrStr);
                                }
                            }
                            OpenModalDialog(m_strRefLocation + "HTML/MsgViewer.htm?Msgs=" + strErrStr,
                                "MsgViewer","",false,600,480);
                        }
                    }
                }
            }
        }
    }
    
    function SetRefLocation(strRefLocation)
    {
        m_strRefLocation=strRefLocation;
    }
    
	this.GetErrors=GetErrors;
	this.GetContent=GetContent;
	this.HasErrors=HasErrors;
	this.ProcessSingleError=function(){return false;};
	this.ProcessErrors=ProcessErrors;
	this.SetRefLocation=SetRefLocation;
	this.GetData=GetData;
}


function CMqMessage()
{
	var m_strType;
	var m_strText="";
	var m_lngAction=0;
	var m_strSource="";
	var m_strAdditionalInfo="";
	var m_objHelp;
	var m_strActionSource="";
	var m_strExcludeInstances="";
	var m_lngNumber=0;

	
	function SetNumber(lngNumber)
	{
		m_lngNumber=lngNumber;
	}
	
	function GetNumber()
	{
		return m_lngNumber;
	}
	function GetText()
	{
		return m_strText;
	}
	
	function SetText(strText)
	{
		m_strText=strText;
	}
	
	function GetType()
	{
		return m_strType;
	}
	
	function SetType(strMessageType)
	{
		m_strType=strMessageType;
	}
	function GetAction()
	{
		return m_lngAction;
	}
	
	function SetAction(lngAction)
	{
		m_lngAction=lngAction;
	}
	
	function GetSource()
	{
		return m_strSource;
	}
	
	function SetSource(strSource)
	{
		m_strSource=strSource;
	}
	
	function GetHelp()
	{
		return m_objHelp;
	}
	
	function SetHelp(objHelp)
	{
		m_objHelp=objHelp;
	}
	
	function GetAdditionalInfo()
	{
		return m_strAdditionalInfo;
	}
	
	function SetAdditionalInfo(strAdditionalInfo)
	{
		m_strAdditionalInfo=strAdditionalInfo;
	}
	
	function GetActionSource()
	{
		return m_strActionSource;
	}
	
	function SetActionSource(strActionSource)
	{
		m_strActionSource=strActionSource;
	}
	
	function SetExcludeInstances(strExcludeInstances)
	{
		m_strExcludeInstances=strExcludeInstances;
	}
	function GetExcludeInstances()
	{
		return m_strExcludeInstances;
	}
	
	
	function Load(strMessage,blnUnescape,strChildrenDelim)
	{
		var MSG_TYPE_INDX=0;
		var MSG_TEXT_INDX=1;
		var MSG_SOURCE_INDX=2;
		var MSG_ADD_INFO_INDX=3;
		var MSG_ACTION_INDX=4;
		var MSG_NUMBER_INDX=5;
		var CHILDREN_DELIM=";";
		if (blnUnescape==null){
			blnUnescape=true;
		}
		if (!strChildrenDelim){
			strChildrenDelim=CHILDREN_DELIM;
		}
		if(strMessage){
			var varMessageInfo=strMessage.split(strChildrenDelim);
			m_strText=unescape(varMessageInfo[MSG_TEXT_INDX]);
			m_strType=unescape(varMessageInfo[MSG_TYPE_INDX]);
			m_lngAction=unescape(varMessageInfo[MSG_ACTION_INDX]);
			m_strSource=unescape(varMessageInfo[MSG_SOURCE_INDX]);
			m_strAdditionalInfo=unescape(varMessageInfo[MSG_ADD_INFO_INDX]);
			m_lngNumber=unescape(varMessageInfo[MSG_NUMBER_INDX]);
		}
	}
	
	this.GetText=GetText;
	this.SetText=SetText;
	this.GetType=GetType;
	this.SetType=SetType;
	this.GetSource=GetSource;
	this.SetSource=SetSource;
	this.GetHelp=GetHelp;
	this.SetHelp=SetHelp;
	this.GetAdditionalInfo=GetAdditionalInfo;
	this.SetAdditionalInfo=SetAdditionalInfo;
	this.GetActionSource=GetActionSource;
	this.SetActionSource=SetActionSource;
	this.SetExcludeInstances=SetExcludeInstances;
	this.GetExcludeInstances=GetExcludeInstances;
	this.SetNumber=SetNumber;
	this.GetNumber=GetNumber;
	this.GetAction=GetAction;
	this.SetAction=SetAction;
	this.Load=Load;
  
  this.MSG_TRUE=MSG_TRUE;
		
}

function CMqMessageCol(strMessages,blnUnescape,strDelim)
{
	var m_lngCount=0;
	var DELIM="&";
	var m_varMessages= new Array();
	//start constructor 
	Load(m_varMessages,strMessages,blnUnescape,strDelim);
	//end constructor 	
	
	function Item(lngIndex)
	{
		return m_varMessages[lngIndex];
	}
	
	function Exists(lngIndex)
	{
		var blnExists=false;
		if (Item(lngIndex)!=null){
			blnExists=true;
		}
		return blnExists;
	}
	function Items()
	{
		return m_varMessages;
	}
	function Count()
	{		
		return m_lngCount;
	}
	
	
	this.Item=Item;
	this.Exists=Exists;
	this.Items=Items;
	this.Count=Count;
	
	//private methods
	function Load(varMessages,strMessages,blnUnescape, strDelim, strChildrenDelim)
	{
		if (!strDelim){
			strDelim=DELIM;
		}
		if (blnUnescape==null){
			blnUnescape=true;
		}
		if (strMessages){
			var varMessageIDs =strMessages.split(strDelim);
			if (varMessageIDs){
				var strMessage;
				var objMessage;
				var strMessageType;
				for(var i=0;i<varMessageIDs.length;i++){
					strMessage =varMessageIDs[i];
					if(strMessage){
						objMessage=new CMqMessage();
						objMessage.Load(strMessage,blnUnescape,strChildrenDelim);
						strMessageType=String(objMessage.GetType());
						if (strMessageType){
							varMessages[m_lngCount]=objMessage;
							m_lngCount++;
						}
					}
				}
			}
		}
	}
}

function CMqSysMsg(objMessage, strReceivers, blnIncludeReceivers)
{
	
	// The responses that are system messages (from system), should all begin with
	var SYS_MSG_PREFIX  = "SYS_MSG_";
	var SYS_MSG_TIMEOUT = SYS_MSG_PREFIX + "TIMEOUT";
	var SYS_MSG_ADMIN_REQUEST = SYS_MSG_PREFIX + "ADMIN_REQUEST";
	var SYS_MSG_TEMPLATE_CHANGE = SYS_MSG_PREFIX + "TEMPLATE_CHANGE";
	var SYS_MSG_UNDEFINED = SYS_MSG_PREFIX + "UNDEFINED";
	var SYS_MSG_PSW_CHANGE=SYS_MSG_PREFIX + "PSW_CHANGE";

	var LENGTH_SYS_MSG_PREFIX=SYS_MSG_PREFIX.length;
	
	// Messages
	var SYS_MSG_TIMEOUT_MESSAGE=g_MqRef.RESX["SYS_MSG_TIMEOUT_MESSAGE"];
	var SYS_MSG_TIMEOUT_MESSAGE_ASK=g_MqRef.RESX["SYS_MSG_TIMEOUT_MESSAGE_ASK"];
	var SYS_MSG_ADMIN_REQUEST_MESSAGE = g_MqRef.RESX["SYS_MSG_ADMIN_REQUEST_MESSAGE"];
	var SYS_MSG_TEMPLATE_CHANGE_MESSAGE =g_MqRef.RESX["SYS_MSG_TEMPLATE_CHANGE_MESSAGE"];
	var SYS_MSG_PSW_CHANGE_MESSAGE=g_MqRef.RESX["SYS_MSG_PSW_CHANGE_MESSAGE"];
	var SYS_MSG_UNDEFINED_MESSAGE = SYS_MSG_ADMIN_REQUEST_MESSAGE;
	var MSG_ASK_EXIT =g_MqRef.RESX["MSG_ASK_EXIT"];
	//Constructor
	var mobjMessage=objMessage;
	var mstrReceivers=strReceivers;
	var m_blnIncludeReceivers=blnIncludeReceivers;
	// End Constructor
	//private properties
	var mblnDoingSysMsg;
	
	function GetMessage()
	{
	 return mobjMessage; 
	}
	function SetMessage(objMessage)
	{
		mobjMessage=objMessage 
	}
	function GetReceivers()
	{
		return mstrReceivers;
	}
	
	function SetReceivers(strReceivers)
	{
		mstrReceivers=strReceivers;
	}
	
	function SetInclude(blnInclude)
	{
		m_blnIncludeReceivers=blnInclude;
	}
	
	function GetInclude()
	{
		return m_blnIncludeReceivers;
	}
		
	function isSysMsg(strMessage){
		
		strMessage=String(strMessage);
		
		if (strMessage.substr(0,LENGTH_SYS_MSG_PREFIX)==SYS_MSG_PREFIX){
			return true;
		}else{
			return false;
		}
	}
	
	function doSysMsg(strMessage,strSysMsg,bForceExit){
	
			if (mblnDoingSysMsg){
				return true;
			}
		
			mblnDoingSysMsg=true;
			
			//notify the parent
			if (window.parent){
		
				if (window.parent!=window.self){
					if (window.parent.objSysMsg){
						window.parent.objSysMsg.doSysMsg(strMessage,strSysMsg,bForceExit);
						return true;
					}
				}
			
			}
			
			
			//notify the opener		
			if (window.opener) {
	
				if (window.opener!=window.self){
					if (window.opener.objSysMsg){
						window.opener.objSysMsg.doSysMsg(strMessage,strSysMsg,bForceExit);
						window.close();
						return true;
					}
				}
			}

			if ((!strSysMsg)||(strSysMsg.length=0)){
				strSysMsg=GetSysMsgText(strMessage);
			}

			bForceExit=parseInt(bForceExit);

			mblnDoingSysMsg=false;
			
			window.location.assign("/connect/logon.asp?m=" + encodeURIComponent(strSysMsg));
	
	}
	
	this.isSysMsg=isSysMsg;
	this.doSysMsg=doSysMsg;
	this.GetMessage=GetMessage;
	this.SetMessage=SetMessage;
	this.GetReceivers=GetReceivers;
	this.SetReceivers=SetReceivers;
	this.GetInclude=GetInclude;
	this.SetInclude=SetInclude;
	
	
	// Private functions
	
	function ConfirmExit(strMsg){
			if (window.confirm(unescape(strMsg))){							
				//if the function exists then call it
				if (window.exit) {
					window.exit(true);											
				}							
		   }
	}
	

	function GetSysMsgText(strSysMsgType){
		
		//var strMessageTypeID;
		
		strSysMsgType=String(strSysMsgType);

		if (strSysMsgType.substr(0,SYS_MSG_TIMEOUT.length)==SYS_MSG_TIMEOUT)
		{		
				
					return SYS_MSG_TIMEOUT_MESSAGE_ASK;
				
					//return SYS_MSG_TIMEOUT_MESSAGE;

		}

		
		if (strSysMsgType.substr(0,SYS_MSG_ADMIN_REQUEST.length)==SYS_MSG_ADMIN_REQUEST){
			return SYS_MSG_ADMIN_REQUEST_MESSAGE;
		}
				
		if (strSysMsgType.substr(0,SYS_MSG_TEMPLATE_CHANGE.length)==SYS_MSG_TEMPLATE_CHANGE){
			return SYS_MSG_TEMPLATE_CHANGE_MESSAGE;
		}
				
		if (strSysMsgType.substr(0,SYS_MSG_UNDEFINED.length)==SYS_MSG_UNDEFINED){
			return SYS_MSG_UNDEFINED_MESSAGE;
		}
		
		if (strSysMsgType.substr(0,SYS_MSG_PSW_CHANGE.length)==SYS_MSG_PSW_CHANGE){
			return SYS_MSG_PSW_CHANGE_MESSAGE;
		}
		
		if (strSysMsgType.substr(0, SYS_MSG_PREFIX.length)==SYS_MSG_PREFIX){
			
			//strMessageTypeID=g_MqRef.MqStr.Mid(strSysMsgType, SYS_MSG_PREFIX.length, 
			//									strSysMsgType.length-SYS_MSG_PREFIX.length);
			//use the message type to get the message
				
			//so far there are none that need it here, just display undefined message if there is something
			return SYS_MSG_UNDEFINED_MESSAGE;
		}
						
	}

	
}


