var gnfolder;
gnfolder= 0 ;

// This is version 2 of qstream.js
// qstream.js is now included in the application (qsi) so that we do not need to build qs to push a new version of qstream.js out


function getEventKey()
{
	var lnc;
	if(event) 
	{ 
		if (event.keyCode)
			lnc = event.keyCode;
		else
			lnc = event.which 
	}
	else
	{
		var e = event
		lnc = e.keyCode 
	}
	return lnc

}
function callFormOnEnter(e, toInput)
{ 

	var lnc 
	if(e) 
	{ 
		if (e.keyCode)
			lnc = e.keyCode;
		else
			lnc = e.which 
	}
	else
	{
		e = event
		lnc = e.keyCode 
	}
	
	if(lnc == 13)
	{
		var lcContinue = toInput.getAttribute('followon');
		window.setTimeout (lcContinue ,1)
		return false 
	}
	return true;
}

function URLEncode( tcvalue )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = tcvalue;
	var encoded = "";
	if (plaintext ) 
	{
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			   // alert( "Unicode Character '" 
               //         + ch 
                //        + "' cannot be encoded using standard URL encoding.\n" +
				//          "(URL encoding only supports 8-bit characters.)\n" +
				//		  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	}

	return encoded ;
}

function URLDecode(tcvalue)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = tcvalue ;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

   return plaintext;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 						*** XMLHTTP STUFF ***
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function UpdateDisplay()
{
	var lodiv, lcdiv;

	lcdiv = "qs_fetchdata"
	var loEl = new elUi(lcdiv)
	loEl.show();
	loEl.centre();
}

function http_execute(tcdiv, tcUrl, tnFolder)
{
	// legacy and called by settimeout
	var loHttp;
	loHttp = new xmlHttpDom()
	loHttp.exec(tcdiv, tcUrl, tnFolder)
}

function xmlHttpDom()
{
	this.lFailed = null;
	this.oResponse = null;
	if (window.ActiveXObject) 
	{ 
		try 
		{
			this.oXmlHttp = new ActiveXObject("msxml2.xmlhttp.6.0")
		}
		catch(e)
		{
			try
			{
				this.oXmlHttp = new ActiveXObject("msxml2.xmlhttp.4.0")
			}
			catch(e)
			{
				this.oXmlHttp = new ActiveXObject("msxml2.xmlhttp") 
			}
			
		}
		try
		{
			this.oXmlHttp.settimeouts(5000, 60000, 30000, 90000);
		}
		catch(e)
		{
			null
		}
	} 
	else if (window.XMLHttpRequest) 
	{ 
		
		this.oXmlHttp = new XMLHttpRequest(); 
	} 
}

xmlHttpDom.prototype.fixUrl = function(tcUrl)
{
var lcP;
if (tcUrl.indexOf('?')==-1 )
	lcP ="?";
else
	lcP = "&";
return tcUrl + lcP +'sys_nc=' + new Date().getTime();
}
 

xmlHttpDom.prototype.callFailed = function()
{
	if (isnull(this.lFailed))
	{
		var lcPage = this.oXmlHttp.responseText;
		this.lFailed = ((lcPage.indexOf('**QSTREAM*EXECPTION*TRAP**') > -1) || (lcPage.indexOf('VBScript Compilation') > -1) || (lcPage.indexOf('VBScript compilation') > -1)     || (lcPage.indexOf('VBScript runtime') > -1)    || (lcPage.indexOf('HTTP/1.1 500 Server Error') > -1) || (lcPage.indexOf("error '800a03ea") > -1) );
		this.oResponse = new qstreamResponse(lcPage);
	}

	return this.lFailed
}

xmlHttpDom.prototype.setRequestHeader = function(tcType, tcEncode)
{
	this.oXmlHttp.setRequestHeader(tcType, tcEncode)
}

xmlHttpDom.prototype.open = function(tcVerb, tcUrl, tlAsync)
{
	this.oXmlHttp.open(tcVerb, this.fixUrl(tcUrl), tlAsync) ;
}

xmlHttpDom.prototype.send = function(tcUrl)
{
	this.oXmlHttp.send(tcUrl);
}

xmlHttpDom.prototype.responseText = function()
{	
	return this.oXmlHttp.responseText;
}

xmlHttpDom.prototype.callUrl = function(tcVerb, tcUrl, tcVars)
{
	// function http_execute_url()  sync  forces wait
	return this.callUrlImplements(tcVerb, tcUrl, false, tcVars)
}

xmlHttpDom.prototype.callUrlAsync = function(tcVerb, tcUrl, tcVars)
{  
	//function http_execute_url_async(tcVerb, tcUrl)
	// Do not wait
	return this.callUrlImplements(tcVerb, tcUrl, true, tcVars)
}

xmlHttpDom.prototype.callUrlHttps = function(tcVerb, tcUrl, tcVars)
{ 
	// function https_GET() 
	
	var loviewform, lcUrl, lcRet ; 

	if (tcUrl.substr(tcUrl.length-1, 1) == '&')
		lcUrl = tcUrl.substr(0, tcUrl.length - 1);
	else
		lcUrl = tcUrl ;

	lcUrl = lcUrl + '&USERAW=YES'; 
	lcUrl = 'https://' + document.domain + lcUrl ;

	lcRet = this.callUrl("GET", lcUrl, tcVars);

	return lcRet;
} 

xmlHttpDom.prototype.callUrlImplements = function(tcVerb, tcUrl, tlAsync, tcVars)
{
	//function http_execute_url_implements(tcVerb, tcUrl, tlAsync)
	var loXHttp, lodiv, lcRet; 	
	lcRet = "";

	if (typeof(tcVars)!='string')
		tcVars = null;
	
	try 
	{
		if ((tcUrl.indexOf('http://')==-1 ) &&  (tcUrl.indexOf('https://')==-1 ))
		{
			tcUrl = document.location.protocol + '//' + document.domain + tcUrl ;
		}
		tcUrl = tcUrl.replace(/&amp;/g, '&');
		
		this.oXmlHttp.open(tcVerb, this.fixUrl(tcUrl), tlAsync); 
		if(tcVerb=='POST')
			this.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
		this.oXmlHttp.send(tcVars);
		lcRet = this.oXmlHttp.responseText;
		http_googleanalytics(tcUrl);
	}
	catch(e)
	{
		alert('Failed in ' + tcUrl )
		null;
	}
	return lcRet;
}

xmlHttpDom.prototype.exec = function(tcdiv, tcUrl, tnFolder)
{
	//http_execute
	this.execImplements(tcdiv, tcUrl, tnFolder, true)
}


xmlHttpDom.prototype.execSync = function(tcdiv, tcUrl, tnFolder)
{
	//http_execute
	this.execImplements(tcdiv, tcUrl, tnFolder, false)
}

xmlHttpDom.prototype.execImplements = function(tcdiv, tcUrl, tnFolder, tlAsync)
{
	// function http_execute_implements(tcdiv, tcUrl, tnFolder, tlAsync)
	var lodiv, lcresult, lcsaveurl, lcsavedest, lloklogin , lotext, lloklogin, lolink, lnid; 

	var loEl = new elUi('qs_fetchdata')
	loEl.show();
	loEl.centre() ;


	// Save the URL and the destination ID (div) that receives the resulting HTML
	// these global vars are then used in the event handler (only way of passing down)

	if ((tcUrl.indexOf('http://')==-1 ) &&  (tcUrl.indexOf('https://')==-1 ))
	{
		tcUrl = document.location.protocol + '//' + document.domain + tcUrl ;
	}

	tcUrl = tcUrl.replace(/&amp;/g, '&');


	if (tcUrl.toUpperCase().indexOf('WCX=') == -1 )
		tcUrl = tcUrl + '&WCX=VIEWDISPLAY';
		
	lodiv = document.getElementById(tcdiv);
	if ((typeof(lodiv)=='undefined') || (lodiv==null))
	{
		tcUrl = tcUrl.replace('USERAW=YES','USERAW=NO');
	}

	gnfolder = tnFolder;

	lnid = qsHandler.nHttpXmlObj;
	qsHandler.aHttpXmlObj[qsHandler.nHttpXmlObj] = this.oXmlHttp;
	qsHandler.nHttpXmlObj++ ;

	qsHandler.nAsyncCalls = qsHandler.nAsyncCalls + 1;
	this.oXmlHttp.onreadystatechange=function() {http_xmlhttponcomplete(lnid, tcdiv, tcUrl, tnFolder);}

	this.oXmlHttp.open('GET', this.fixUrl(tcUrl), tlAsync); 	
	this.oXmlHttp.send(null);

	// / qsHandler.addUrl(tcdiv, tcUrl);
	http_googleanalytics(tcUrl);

	return false;
}

xmlHttpDom.prototype.postForm = function(tnformid, tcasppage) 
{
	// function http_post_a_form(tnformid, tcasppage ) 
	
	var loXHttp;
	var loviewform, lcUrl,  loXHttp, loresponse, lodiv , lni, lcstr , llret;
	var loform, lni, lcUrl, lcpage ;
	var lcfieldname, lcvaluetopost, lcfieldtype

	loform = document.getElementById('saveform' + tnformid);

	if ( tnformid > 0 ) 
	{
		loform = document.getElementById('saveform' + tnformid) ;
	}
	else
	{
		loform = document.getElementById(tnformid);
	}
	
    
    //first define a form then if tcasppage = 0 use the form action attribute
    if (tcasppage =='')
	{	
		tcasppage = '/qs.asp?';
	}
	else if(tcasppage =='0' && loform)
	{
	    tcasppage = loform.action;	
	}	
	else
	{	
		tcasppage = tcasppage ;
	}
		
	//RE 2008.04.14 FIX: Mozilla adds the name server to relative paths
	if(tcasppage.indexOf('http:')<0 && tcasppage.indexOf('https:')<0)
	{	
	    tcasppage = document.location.protocol + '//' + document.domain + tcasppage ;    
	}
	
	lcUrl = "";


	if (loform)
	{
		var loinputlements, loformelements
		var loformlength
		var loTextElements
		var loSelectElements

		//revaristo 2008.01.30 changed to suport other tag types
		//revaristo 2009.04.03 added select

		loformlength = loform.length?loform.length:loform.getElementsByTagName('input').length
		loformelements = loform.elements?loform.elements:loform.getElementsByTagName('input')
	

		for (lni=0; lni < loformelements.length; lni ++)
		{
            lcfieldtype = loformelements[lni].getAttribute('type');
            lcfieldname = loformelements[lni].name
              
			if ((lcfieldtype != 'checkbox') || (loformelements[lni].checked))
			    			    
			    if(lcfieldtype != 'radio')
			    {
			        lcvaluetopost = loformelements[lni].value
			        
					lcUrl = lcUrl + lcfieldname + '=' + URLEncode(lcvaluetopost) + '&' ;			    	
			    }	
		}
		
		 loinputlements = loform.getElementsByTagName('input')


	    
	     for (var n=0; n<loinputlements.length; n++)
	     {  	     
	         if (loinputlements[n].getAttribute('type') == 'radio' && loinputlements[n].checked == true)
	         {
	            lcfieldname = loinputlements[n].name
    	        lcvaluetopost = loinputlements[n].value;
				
				//alert("radio:" + lcfieldname)
				
                lcUrl = lcUrl + lcfieldname + '=' + URLEncode(lcvaluetopost) + '&' ;
              }
	     }
		
		//RE 2008.12.09 Adding text area support
			
		
		loTextElements = loform.elements?null:loform.getElementsByTagName('textarea')		
		
		lctxtexists =''
		
		
		if(loTextElements)
		{
			
			for (var n=0; n<loTextElements.length; n++)
			{  	     
	         
				lcfieldname = loTextElements[n].name
				lcvaluetopost = loTextElements[n].value;
											
				if(lcUrl.indexOf(lcfieldname) > 0)
				{
					lctxtexists = lctxtexists + ',' + lcfieldname;
					alert('Error: text field already in post:' + lcfieldname);
				}
				else
				{
					lcUrl = lcUrl + lcfieldname + '=' + URLEncode(lcvaluetopost) + '&' ;             
				}
		    }
		}
		else
		{
			null;
		}
		
		
		loSelectElements = loform.elements?null:loform.getElementsByTagName('select')		
		
		lctxtexists =''		
		
		
		if(loSelectElements)
		{
			
			for (var n=0; n<loSelectElements.length; n++)
			{  	     
	         
				lcfieldname 	= loSelectElements[n].name
				lcvaluetopost	= loSelectElements[n].value;
				
				if(lcUrl.indexOf(lcfieldname) > 0)
				{
					lctxtexists = lctxtexists + ',' + lcfieldname;
					//alert('Error: text field already in post:' + lcfieldname);
				}
				else
				{
					lcUrl = lcUrl + lcfieldname + '=' + URLEncode(lcvaluetopost) + '&' ;             
				}
		    }
		}
		else
		{
			null;
		}
	}
		
	if (lcUrl.substr(lcUrl.length-1, 1) == '&')
	{
		lcUrl = lcUrl.substr(0, lcUrl.length - 1);
	}

	lcUrl = lcUrl + '&USERAW=YES'; 
	
	this.open("POST", tcasppage , false); 
	this.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	this.send(lcUrl);

	try
	{
		// if i have a current tab set then restethe loaded tabs to force a reload - POST may change data so we must reload
		if (!isnull(qsHandler.oCurrentTabset))
		{
			qsHandler.oCurrentTabset.resetLoaded();
		}
	}
	catch(e)
	{
		// nothing;
	}

	return 	this.responseText();
	
}

function http_googleanalytics(tcUrl)
{
	try
	{
		qsHandler.oGoogleIds.sendToGoogle(tcUrl)
	}
	catch(e)
	{
		null
	}
}


function http_xmlhttponcomplete(tnID, tcdiv, tcUrl, tnFolder) 
{
// stays the same since PUSHED function // cannot be part of the Object

var lcresult, lonode, lolink, lldestinationdivexists, loXHttp, lldone, lni;

loXHttp = qsHandler.aHttpXmlObj[tnID]

if (loXHttp.readyState == 4)
{
	// do not splice	qsHandler.aHttpXmlObj.splice(tnID, 1)
	// Accept any DIV even if it does not exist.
	// if if does not exist then stick it in BODY
	// Also the llogin prompt only if it is not a top level 

		
	var loEl = new elUi(tcdiv);
	
	lcresult =  loXHttp.responseText;
	if ((lcresult.indexOf('type="hidden" name="WCX" value="QsLogin"') != -1 ) && (lcresult.indexOf('<html>') != -1))
	{

		// user not loggedin
		loEl.write("");
		var loEl = new elUi('qs_fetchdata');
		loEl.hide()
		//var loUser = qsHandler.entityGet("qstreamUser");
		//if (loUser)
		//	loUser.showLogin("", tcUrl);

	}
	else
	{
		// User is logged in
		try
		{
			// hide tool tips
			for (lnj=0; lnj < qsHandler.oTip.length; lnj++)		qsHandler.oTip.item(lnj).tip.style.visibility='hidden';
		}
		catch(e)
		{
		}
		loEl.write(lcresult);
		loEl.show();
		if (tcdiv =='cmp_qswindow')
			loEl.centre();
		

		//After insert html pushjavascript to execute

		// MV 2008.08.27 before was always EVAL mode, 
		// added this code so that noeval for IE explorer
		//  Had to revert back becuase now the default value
		// on combos was NOT being populated
		//
		// Ok finally go it,  NO eval CAN be used, however
		// snippets of javascript must be located INSDE a writable item
		// such as a TD ,  if they are in the body they will not be executed.
		//
		if(detectNavigator()!=2)
		{
			pushJavaScriptNoEval(lcresult, tnFolder);
		}
		else
			pushJavaScript(lcresult, tnFolder);


		if (tcdiv.indexOf('qsfid') > -1)
		{

			lonode = document.getElementById(tcdiv)
			tcdiv = 'qsfid' + tnFolder;

			if (lonode != null)
				lonode.id = tcdiv ;	

		}
		lldone = true;
		
		for (lni = 0; lni <= qsHandler.aHttpXmlObj.length; lni++)
		{
				if (typeof(qsHandler.aHttpXmlObj[lni])=='object' && qsHandler.aHttpXmlObj[lni].readyState != 4)
				{
					lni = qsHandler.aHttpXmlObj.length;
					lldone = false;
				}
		}
		
		var loEl = new elUi('qs_fetchdata');
		if (lldone == true)
		{
			qsHandler.aHttpXmlObj.splice(0, qsHandler.aHttpXmlObj.length)
			loEl.hide() ;
		}
		else
		{
			
			loEl.hide('qs_fetchdata') ;
			loEl.show('qs_fetchdata') ;
			loEl.centre('qs_fetchdata') ;
		}
	}
	
	displayWhenReady();
	qsHandler.nAsyncCalls = qsHandler.nAsyncCalls - 1 
	
	if (qsHandler.nAsyncCalls ==0)		// only call the displayllviews if this is the last async call
	{
		//qs_Add_CustomBoxes();
		// qsHandler.displayAllViews();
	}
//	else	
//		alert("nb of async calls" + qsHandler.nAsyncCalls )
}
}

function displayWhenReady()
{
	var lni, loObj, llNoPaint ;
	
	
	llNoPaint = false;
	for (lni = 0; lni <= qsHandler.aHttpXmlObj.length -1 ; lni++)
	{
		loObj = qsHandler.aHttpXmlObj[lni];
		if (!isnull(loObj))
			if (loObj.readyState != 4)
			{
				llNoPaint = true;
				lni = qsHandler.aHttpXmlObj.length
			}
	}
	if (!llNoPaint)
	{	
		qs_Add_CustomBoxes();
		qsHandler.displayAllViews();
	}
	
	//alert('paint ' + !llNoPaint)
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 						*** BROWSER STUFF ***
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function GetWindowWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }

return myWidth;
}

function GetWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }

  return myHeight;
}

function http_closeqsobject()
{
	try 
	{
		loXHttp = new xmlHttpDom()
		loXHttp.open('GET', '/clearqsfromsession.asp', false) ;
		loXHttp.send(null);	
		setTimeout('http_closeqsobject()', 30000);			
		// every 30 seconds shut down qstream object if it is available on II session variable
	}	
	catch(e)
	{
		null
	}
}
function http_keepalive()
{
	loXHttp = new xmlHttpDom()
	loXHttp.open('GET', '/qs.asp', false) ;
	loXHttp.send(null);
	// every five minutes ping qstream to keep session alive
	setTimeout('http_keepalive()',300000);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 						*** DIV STUFF ***
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function getGoodDIV(toObject, tcdiv)
{
var lonode, lcRet;
lonode=document.getElementById(tcdiv)
if ((typeof(lonode)=='undefined') || (lonode==null))
	lcRet = getFirstDIV(toObject);
else
	lcRet = tcdiv;

return lcRet;
}

function getFirstDIV(toObject )
{
	var lcRet;
	if(toObject.tagName=='DIV' && toObject.id.substring(0,6) == 'pszone')
	{
		lcRet = toObject.id;
	}
	else
	{
		if (toObject.parentNode!=null)
			lcRet = getFirstDIV(toObject.parentNode)				
	}
	return lcRet;	
}

function elUi(tcId)
{
	this.cId = tcId;
	this.oEl = document.getElementById(tcId);
	this.lok = !isnull(this.oEl)
}
elUi.prototype.get = function()
{
	if(this.lok)
	{
		return this.oEl.innerHTML;
	}
	
}

elUi.prototype.hide = function()
{
	if(this.lok)
		this.oEl.style.display="none";
}

elUi.prototype.copyTo = function(tcToId)
{
	var loDivTo ;
	loDivTo = document.getElementById(tcToId);
	if (loDivTo && this.lok)
		loDivTo.innerHTML = this.oEl.innerHTML;	
}

elUi.prototype.putHtml = function(tcText)
{
	if(this.lok)
		this.oEl.innerHTML = tcText;
}

elUi.prototype.show = function()
{
	if(this.lok)
	{
		this.oEl.style.display="block";
	}
}

elUi.prototype.write = function(tcText)
{
	
	if(this.lok)
	{
		this.oEl.innerHTML = tcText;
		if (typeof(translatehttp)!='undefined')
			translatehttp();
	}	
}

elUi.prototype.centre = function()
{
	if(this.lok)
	{
		var lnscreenleft;

		if (detectNavigator()==2)
			lnscreenleft = window.screenX;		// mozilla
		else
			lnscreenleft = window.screenLeft

		if (lnscreenleft > screen.width)	
			this.oEl.style.left =   parseInt((GetWindowWidth() - this.oEl.offsetWidth ) / 2 ) + 'px';
		else
			this.oEl.style.left =   parseInt((GetWindowWidth() - this.oEl.offsetWidth ) / 2) + 'px';

		if(typeof(getScroll())=='object')
		{
			this.oEl.style.top =   parseInt((getScroll().y +  parseInt((GetWindowHeight() - this.oEl.offsetHeight) / 2) ) ) + 'px';	
		}
		else
			if(typeof(getScroll())!='undefined')
				this.oEl.style.top =   parseInt((getScroll() + (parseInt((GetWindowHeight() - this.oEl.offsetHeight) / 2) )) ) + 'px';	
			else
				this.oEl.style.top =   parseInt((GetWindowHeight() - this.oEl.offsetHeight) / 2) + 'px';
	}			
}

elUi.prototype.position = function(tcPosAtDivId, tnOffsetX, tnOffsetY)
{
	
	if(this.lok)
	{
		var loPos, lnx, lny, lncurrentx, lncurrenty;

		lodiv = document.getElementById(tcdivid);
		loPos = document.getElementById(tcPosAtDivId);
		lncurrentx = getabsolutex(this.oEl);
		lncurrenty = getabsolutey(this.oEl);

		lnx = getabsolutex(loPos.offsetParent) + parseInt(tnOffsetX) ;
		lnx = lnx - lncurrentx;
		lnx = lnx.toString() + 'px';

		lny = getabsolutey(loPos.offsetParent) +  parseInt(tnOffsetY);
		lny = lny - lncurrenty;
		lny = lny.toString() + 'px';

		this.oEl.style.left = lnx
		this.oEl.style.top = lny 
		this.show()
	}
}

function getScroll()
{
    var lnscroll

    if( typeof( window.scrollTop ) == 'number' ) {
    
    lnscroll = window.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    
    lnscroll = document.documentElement.scrollTop;
    
    document.body.scrollTop
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    
    lnscroll = document.body.scrollTop;
  }
  

	return lnscroll
}

//////////////////////////////////////////////////////////////////
// 	CHECK ACCESS DEFINED
//////////////////////////////////////////////////////////////////
function check_AccessDenied(tcHTML)
{
return ((tcHTML.indexOf('type="hidden" name="WCX" value="QsLogin"') != -1 ) && (tcHTML.indexOf('"qs_loginform"') == -1))
}

//////////////////////////////////////////////////////////////////
// 	SHOW a DIV
//////////////////////////////////////////////////////////////////
function TrapBodyClick()
{
	var lcresult, loobj, lcresultcopy, lchref, lnpos, lnfolderid;

	if (window.event)
	{
		loobj = null;
		try 
		{
			if (window.event.srcElement.tagName == 'A' || window.event.srcElement.tagName == 'a' )
				loobj = window.event.srcElement
			else
				if (window.event.srcElement.parentNode.tagName == 'A' || window.event.srcElement.parentNode.tagName == 'a' )
					loobj = window.event.srcElement.parentNode;
				else
					loobj = null;
		}
		catch(e)
		{
			null;
		}
		if ((loobj!=null))
		{
			if ((!(loobj.onclick) || (loobj.onclick ==''))  )
			{
				lchref = loobj.href;
				lchref = lchref.toUpperCase();
				if (lchref.indexOf('&VIEWORDERBY=') != -1)
				{
					// UpdateDisplay();

					loXHttp = new xmlHttpDom();
					loXHttp.open("GET", loobj.href + '&USERAW=YES', false); 
					loXHttp.send(null);
					
					lnpos = lchref.toUpperCase().indexOf('FOLDERID');
					lchref = lchref.substring(lnpos + 9 );
					if (lchref.indexOf('&') > -1 )
					{
						lnfolderid = lchref.substring(0, lchref.indexOf('&'));
						var loEl = new elUi("qsfid" + lnfolderid)
						loEl.write(loXHttp.responseText());
						
						qs_Add_CustomBoxes();
						window.event.returnValue = false;
					}
					else
						window.event.returnValue = true;
				
					var loEl = new elUi('qs_fetchdata')
					loEl.hide(); 
				}
				else
				{
					window.event.returnValue = true;
				}
				document.body.onclick = TrapBodyClick;
			}
			else
			{
				window.event.returnValue = true;
			}
		}
		else
			window.event.returnValue = true;
	}
}

function Extract_BODY(tcHtml)
{
	var lcresultcopy, lnend, lnstart;

	lcresultcopy = tcHtml.toUpperCase();
		
	lnstart = lcresultcopy.indexOf("<BODY");
	if (lnstart != -1)
	{
		lcresultcopy= lcresultcopy.substr(lnstart, lcresultcopy.length - lnstart);
		tcHtml		= tcHtml.substr(lnstart, tcHtml.length - lnstart);
	}
	lnstart = lcresultcopy.indexOf(">");
	if (lnstart != -1)
	{
		lcresultcopy 	= lcresultcopy.substr(lnstart +1 , lcresultcopy.length - (lnstart+1))
		tcHtml		= tcHtml.substr(lnstart +1 , tcHtml.length - (lnstart+1))
	}
	lnend	= lcresultcopy.indexOf("</BODY>");

	if (lnend ==-1)
		lnend = lcresultcopy.length ;
	return tcHtml.substr(0, lnend);
}

function getMessageFromId(tcid)
{
	var lonode;
	lonode = document.getElementById(tcid);
	if (lonode != null)
		lcRet = lonode.innerHTML;
	else
		lcRet = '---';
	return lcRet;
}

function http_call_failed(tcpage)
{
	return ( (tcpage.indexOf('**QSTREAM*EXECPTION*TRAP**') > -1) || (tcpage.indexOf('VBScript Compilation') > -1) || (tcpage.indexOf('VBScript compilation') > -1)     || (tcpage.indexOf('VBScript runtime') > -1)    || (tcpage.indexOf('HTTP/1.1 500 Server Error') > -1) || (tcpage.indexOf("error '800a03ea") > -1) );
}

function form_buildUrlofFields(tcform)
{
	var lcUrl, loviewform, lni;
	lcUrl = '';
	loviewform = document.getElementById(tcform); 

	for (lni=0; lni < loviewform.length ; lni++)
	{ 	
		lcUrl = lcUrl + loviewform.elements[lni].name + '=' + URLEncode(loviewform.elements[lni].value) + '&' ;
	} 
	return lcUrl;
}

function qs_showorder(tcid)
{
	var lonode;
	lonode = document.getElementById('ord_a_' + tcid);
	if (lonode != null)
		lonode.style.display='inline';

	lonode = document.getElementById('ord_d_' + tcid);
	if (lonode != null)
		lonode.style.display='inline';
}

function qs_hideorder(tcid)
{
	var lonode;
	lonode = document.getElementById('ord_a_' + tcid);
	if (lonode != null)
		lonode.style.display='none';

	lonode = document.getElementById('ord_d_' + tcid);
	if (lonode != null)
		lonode.style.display='none';

}


function viewsearch(tnFolder, tlUseAjax) 
{

	var loViewForm, lcUrl, loResponse, loDiv , lni, lcStr , llRet;
	
	if (tlUseAjax) 
		qsHandler.viewGet(tnFolder).search();
	else
		loViewForm.submit();

		qs_Add_CustomBoxes();
	//lcbutton = "btnsearch";
	//lctarget = "";
	//loViewForm.action	='/vd.asp';
	//loViewForm.WCX.value	='viewdisplay';

	return false;
}

// remove function qsTranslatePage(tnLang, tcApp, tcAppTag, tcASP)  ,  use new tanslate class (KID=45)


function qsPrintPage(tnFid)
{
	// hides blocks
	var loNodes, lcstyle;
	var loTable, loTd, loTr, loTbody
	
	loNodes = document.getElementsByTagName("td");

	for (lni = 0 ; lni < loNodes.length ; lni++)
	{
		if (loNodes.item(lni).style.cssText)		
		{
			lcstyle = loNodes.item(lni).style.cssText;
			lcstyle = lcstyle.toLowerCase();
			lcstyle = lcstyle.replace(/ /, "");

			if ((lcstyle.indexOf('qshideonprint:1') > -1 ) || (lcstyle.indexOf('qshideonprint: 1') > -1 ))
			{
				loNodes.item(lni).style.display="none";
			}
		}
	}	
	try 
	{
		if (!isnull(qsHandler.oCurrentTabset))
		{
			//document.getElementById('qstabset').innerHTML = document.getElementById('div_' + qsHandler.oCurrentTabset.oTab.nTabId).innerHTML;

			loTable    = new Element('table', '')
			loTbody = document.createElement('TBODY');
			loTable.appendChild(loTbody);
			
			//include header on print area
			loTr  = document.createElement('TR');
			loTbody.appendChild(loTr);
			loTd  = document.createElement('TD');
			loTr.appendChild(loTd);			
			loTd.innerHTML = document.getElementById('tab_header' + qsHandler.oCurrentTabset.nId).innerHTML;

			//include body on print area
			loTr  = document.createElement('TR');
			loTbody.appendChild(loTr);			
			loTd  = document.createElement('TD');
			loTr.appendChild(loTd);			
			loTd.innerHTML = document.getElementById('div_' + qsHandler.oCurrentTabset.oTab.nTabId).innerHTML;

			document.getElementById('tabset').innerHTML = loTable.innerHTML;
			
			window.print();
			window.navigate(window.location);
		}
	}
	catch(e)
	{
		window.print();	

		// if I have a tab set then et innhtl of the active tab of the tab set and put it in the tabset work area			
		for (lni = 0 ; lni < loNodes.length ; lni++)
		{
			if (loNodes.item(lni).style.cssText)		
			{
				lcstyle = loNodes.item(lni).style.cssText;
				lcstyle = lcstyle.toLowerCase();
				lcstyle = lcstyle.replace(/ /, "");

				if ((lcstyle.indexOf('qshideonprint:1') > -1 ) || (lcstyle.indexOf('qshideonprint: 1') > -1 ))
				{
					loNodes.item(lni).style.display="inline";
				}
			}
		}
	}
	//window.navigate('/vd.asp?WCX=ViewDisplay&amp;FOLDERID=' + tnFid + '&amp;USECONTEXT=YES');
}
	
function isnull (toobject)
{
	return ((typeof(toobject)=='undefined') || (toobject==null)) ;
}

// Open header

function qsstyle_top_header(toObject, tcstyle)
{
	var loheader, lcHtml;
		
	lcHtml = toObject.innerHTML;
	loheader = document.getElementById(tcstyle);
	loheader.firstChild.cells(4).innerHTML = lcHtml;
	toObject.style.padding="0px";
	toObject.innerHTML = loheader.innerHTML;
	toObject.width = loheader.firstChild.width;
}

// Close footer

function qsstyle_closefooter(toObject, tcstyle)
{
		
	var lcHtml;

	toObject.style.padding="0px";
	toObject.innerHTML = document.getElementById(tcstyle).innerHTML;
}

function qsstyle_insertfooterheader(toObject, tcstyle)
{
	var loheader;
		
	loheader = document.getElementById(tcstyle);
	if(!isnull(loheader))
	{	 
		toObject.style.padding="0px";
		toObject.innerHTML = loheader.innerHTML;
	}
}

//
// Add customer boxes with rounded edges
//	
function qs_Add_CustomBoxes()
{
	var loNodes, lcclass;

	loNodes = document.getElementsByTagName("td");

	for (lni = 0 ; lni < loNodes.length ; lni++)
	{

		if (loNodes.item(lni).className)
		{
			lcclass = loNodes.item(lni).className
			lcclass= lcclass.toLowerCase();
			if (lcclass.indexOf('qsstyle_') > -1) 
			{
				qsstyle_insertfooterheader(loNodes.item(lni), loNodes.item(lni).className);
			}		
		}
	}
}


//****************************************************************************************
//*
//*
//*		GENXSL FUNCTIONS
//*
//*
//****************************************************************************************

function genxsl_setcombovalue(tcselect, tcoption)
{

	// function required to populate the default values in combos for the actual values of a edit form and
	// the default values of combos of the select single relation / multiple relation view 
	var looption;
	var loselect;

	loselect = document.getElementById(tcselect);
	looption = document.getElementById(tcoption);
	
	if (!isnull(loselect))
	{ 			
		if (!isnull(looption))
		{
			loselect.selectedIndex = looption.index ;
		}
	}
}


function genxsl_addflashtitle(tctitle, tccolor, tcpositiondiv, tnoffsetx, tnoffsety)
{
	var lcmyid, lonode, lnx ;
//	lcmyid = 'vt_arttitle';
 	lcmyid = 'vt_' + tcpositiondiv ;
	lonode = document.getElementById(tcpositiondiv);


	if ((lonode !=null) && (tctitle !=''))
	{

	  lnx = tctitle.length * 12; 
	  lonode.innerHTML = '<img src="/images/blankspacer.gif" width="' + lnx + 'px" height="1" alt=""/>';
// 	  fl_addtitle(tctitle, 0, tcpositiondiv, tcpositiondiv, tccolor, lcmyid, 0, -15);
	
	if ((typeof(tnoffsetx)=='undefined') || (tnoffsetx==null))
		tnoffsetx = 0;

	if ((typeof(tnoffsety)=='undefined') || (tnoffsety==null))
		tnoffsety = -15;

		qsHandler.addFlashTitle(lcmyid, escape(tctitle), 0, tccolor, tcpositiondiv, tcpositiondiv, tnoffsetx, tnoffsety);
	}
	return false;

}


function genxsl_setradiovalue(tcoption)
{
	// function required to populate the default values of radio buttons of the select single relation / multiple relation view 
	var looption;
	
	looption = document.getElementById(tcoption);

	if ((typeof(looption) != 'undefined') && (looption!=null))
	{
		looption.checked = true ;
	}
}		


function genxsl_LovReturnValue(tcKey, tcValue)
{
	var arr = new Array();
	arr[0] = tcKey;
	arr[1] = tcValue;
	window.returnValue = arr;
	window.close();
}


function genxsl_ShowLOV(tcUrl, totext, tovalue)
{
	var arr = null;				
	// window.location.protocol + '//' + window.location.hostname 

	
	arr = showModalDialog(tcUrl , null, "dialogWidth:740px;dialogHeight:450px;resizable:yes;center:yes;help:no;status:no;");
	if (arr != null) 
	{
		tovalue.value = arr[0];
		totext.innerText = arr[1];
	}
}		

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Remove selected item from LOV field
//////////////////////////////////////////////////////////////////////////////////////////////////////
function genxsl_RemoveLOV(totext, tovalue)
{
	tovalue.value = "";
	totext.innerText = "";
}	

function genxsl_checksignature(tnfolderid, toForm) 
{
	var lcvalue, lonode, lcUrl, loobjs ;
	lcvalue=''; 
	lonode = document.getElementById("QSDGSCRC");

	if (isnull(toForm))
		loobjs = document.getElementsByTagName("input");
	else
		loobjs = toForm.getElementsByTagName("input");
	

	lonode = null;
	for (lni=0;lni < loobjs.length ; lni++)
	{
		loitem = loobjs.item(lni);
		if (! isnull(loitem) && (loitem.name  =='QSDGSCRC'))
		{
			lonode = loitem;
			lni = loobjs.length;
		}						
	}

		
	lcUrl='/qs.asp?WCX=DigitalSignatureGetForm&FOLDERID='+tnfolderid+'&PRMID=6';
	if ((typeof(lonode) !='undefined') && (lonode!=null))
	{
		lonode.value = window.showModalDialog(lcUrl,'','dialogWidth:270px;dialogHeight:140px;dialogTop:'+event.screenY+'px;dialogLeft:'+event.screenX+'px;status:no;scroll:no'); 
		if (lonode.value!='CANCEL') 
			return true;
		else 
			return false ; 
	}
	else
			return false;
}


function genxsl_cancel(tnformid)
{

	//
	// Get current for object
	//
	loform = document.getElementById("saveform" + tnformid);
	loform.reset();

	genxsl_SetFormReadonly(tnformid, true);
	setTimeout("loadFormDefaults" + tnformid + "();",10);

}

function genxsl_deleterecord(tnfolderid, tnrecorid, tclabel, tctext, tnreturnFid)
{
	if (confirm(tclabel + ' ' + tctext))
	{
		// code to delete record 
		// if not ok message
		// else view display tnreturnFid)
	}
}


function qs_showmessage(tctitle, tcpage)
{
	qsShowMessage(tctitle, tcpage)
}

function qsShowMessage(tctitle, tcpage)
{
//	tcpage = tcpage.replace(/[\n\r]+/g, "<br/>");
	tcpage = tcpage.replace(/\n/g, "<br/>");
	document.getElementById("qs_messtitle").innerHTML 	= tctitle;
	document.getElementById("qs_messtext").innerHTML 	= tcpage ;
	document.getElementById("qs_mess_window").style.display	='block';
	var loEl = new elUi("qs_mess_window")
	loEl.centre();

}


function genxsl_save(tnchkds, tnUIFID, tndatafid, tnajax, tnreturnFid, tcasp) 
{

var llret, loform;
llret = true;

var lnqskeyid

//
// This is the generic submit and save functions for all form. The differentiator of all the forms 
// is the ID of the form definition itself.
//
// Changes:
// 1) submitandsave push button becomes: "savebutton" + tnUIFID
// 2) Make the button language independent (to do !)
// 3) save button becomes type="button" (not submit)

	if (tcasp) 
	{
		null;
	}
	else
	{
		tcasp = '/rs.asp';


	}

	var loitem, lobutton, loobjs, lni;


	lobutton = document.getElementById("savebutton" + tnUIFID );

	
	
	loform = document.getElementById('saveform' + tnUIFID)
	if (tnchkds==1)
	{
		// tndatafid is @xldformid
		genxsl_checksignature(tndatafid, loform);
	}
	
//	lobutton.value		= "saving";
//	lobutton.disabled	= true;
	
	// Do not remove the submit code, need to disable the save button 
	// lobutton.onsbumit="";
					
			

	if (isnull(loform))
		loobjs = document.getElementsByTagName("object");
	else
		loobjs = loform.getElementsByTagName("object");
	

	for (lni=0;lni < loobjs.length ; lni++)
	{
		loitem = loobjs.item(lni);
		if (! isnull(loitem) && (loitem.classid =='CLSID:FE52304F-FBB3-4DC9-A976-5EDE74A40062'))
		{
			if (!loitem.UploadFile())
			{
				event.returnValue=true; 
				return true;
			}
			else
			{

// 				loobjs.item(lni).parentNode.innerHTML = loobjs.item(lni).parentNode.innerHTML ;
//				loobjs.item(lni).parentNode.style.display='none';
			}
		}						
	}

	
	//				
	// we are currently not using the edit HTML control so we do not need to breakit up 
	// If we do start to use them later then we need to active this code
	//
	

	// RE 2007.07.23 - Select boxes are no sent when readonly, so read only routine goes a few lines below
	//genxsl_SetFormReadonly(tnUIFID , true);

	if (tnajax !=1) 
	{
		document.getElementById('saveform' + tnUIFID ).submit();
	}
	else
	{


		genxsl_SetFormReadonly(tnUIFID , true);

		var loXmlHttp = new xmlHttpDom();		
		
		
		lcpage = loXmlHttp.postForm(tnUIFID, tcasp);

		llret = true;
		loresponse = new qstreamResponse(lcpage);
		if (lcpage.substring(1,13)=='?xml version')
		{
			var loxml, lnResult, lni, lnMessages, lcstr, loresponse;


			if (loresponse.nResult == 1)
			{
				qsShowMessage('Unable to save', loresponse.showErrors());
				genxsl_SetFormReadonly(tnUIFID , false);
				llret = false;
			}
			// if we have xml then we always pass the response object and bubble up
			llret = loresponse;

		}
		else if (http_call_failed(lcpage))
		{

			qsShowMessage('Unable to save form', lcpage);
			genxsl_SetFormReadonly(tnUIFID , false);

			llret = false;

		}
		if (llret == true)
		{
			if (tnreturnFid > 0 )
			{
			
				var loXmlHttp = new xmlHttpDom();
				
				lcpage = loXmlHttp.callUrl("GET", "/vd.asp?wcx=viewdisplay&amp;folderid=" + tnreturnFid + "&amp;USERAW=YES&amp;ADDVIEWDIV=YES");
				pushJavaScript(lcpage , gnfolder);

				var loEl = new elUi('qsfid' + tnUIFID)
				loEl.write(lcpage );

				lonode 		= document.getElementById('qsfid' + tnUIFID );
				gnfolder 	= tnreturnFid ;
				lonode.id 	= 'qsfid' + tnreturnFid ;

				qs_Add_CustomBoxes();

			}
			else
			{
				lnqskeyid = lcpage

				loqskeyid = document.getElementById('QSKEYID')
				
				if (typeof loqskeyid == 'undefined' || !(loqskeyid))
				{
				   loqskeyid =  getElementByTypeAndName('QSKEYID','INPUT')
				  				
				}
				
				if((typeof loqskeyid != 'undefined' && (loqskeyid)) &&( loqskeyid.value == '' || loqskeyid.value == 0))
				{
				    loqskeyid.value = lnqskeyid
				}

			}
		}
	}
	return loresponse;
}


function qstreamResponse(tcXml)
{
	var lonode;

	this.lIsXml 	= tcXml.substring(1,13)=='?xml version'
	this.oXml		= null;
	this.nResult 	= 0;
	this.nErrors	= 0 ;
	this.nMessages  = 0 ;
	this.lResponse 	= false;
	this.cHtml	= null;
	this.nRecordId 	= null;
	this.oXmlElements = null;
	
	if (this.lIsXml)
	{
		this.cXml 	= tcXml;
		this.load();
		if (this.nErrors == 0)
		{
			lonode = this.getAttribute('recordId');
			if (isnull(lonode))
			{
				this.nRecordId = this.getKeyId();
			}
			else
				this.nRecordId = parseInt(lonode);
		}
		else
			this.nRecordId = 0 ;
	}
	else
	{
		this.cHtml = tcXml
		llerror = http_call_failed(tcXml)
		if (llerror)
		{
			this.nResult = 1;
			this.nErrors = 1;
			this.nRecordId = 0 ;
		}
		else
		{
			this.nRecordId = parseInt(tcXml);
			this.nResult = 0;
			this.nErrors = 0;
		}
	}
}

qstreamResponse.prototype.load = function()
{
	var loNodes;

	this.oXml = new xmlDOC();
	this.lResponse = this.oXml.loadXML(this.cXml);

	if (this.lResponse)
	{
		loNodes = this.oXml.selectNodes("/qstreamresponse/qserrorobject")
		this.nResult = parseFloat(loNodes.item(0).getAttribute('nresult'));
		this.nErrors = parseFloat(loNodes.item(0).getAttribute('errors'));
		this.nMessages = parseFloat(loNodes.item(0).getAttribute('messages'));


		this.nRecordId = loNodes.item(0).getAttribute('recordId');

		this.oXmlElements = this.oXml.selectNodes("/qstreamresponse/qsel")
	}
}

qstreamResponse.prototype.getDataElements = function()
{
	return this.oXmlElements;
}

qstreamResponse.prototype.getAttribute = function(tcName)
{
	var loNodes, lcRet;

	// These attributes are set in the ASP errorHandler withint the qsresponsedata element using the setAttribute method
	// so that the error object can passfurther items back to the caller.

	loNodes = this.oXml.selectNodes("/qstreamresponse/qsdata"); 
	if (loNodes.length > 0) 
		lcRet = loNodes.item(0).getAttribute(tcName);
	else
		lcRet = null;
	

	return lcRet;
}
qstreamResponse.prototype.getKey = function(tcFilter)
{
	// get record of first element // uses xml save
	var loNodes, lcRet;

	// These attributes are set in the ASP errorHandler withint the qsresponsedata element using the setAttribute method
	// so that the error object can passfurther items back to the caller.
	lcRet = 0;
	if (this.lResponse)
	{
		loNodes = this.oXml.selectNodes("/qstreamresponse/qsel[" + tcFilter + "]"); 
		if (loNodes.length > 0) 
			lcRet = loNodes.item(0).getAttribute('qskeyid');
	}
	return lcRet;
}

qstreamResponse.prototype.getKeyId = function()
{
	// get record of first element // uses xml save
	var loNodes, lcRet;

	// These attributes are set in the ASP errorHandler withint the qsresponsedata element using the setAttribute method
	// so that the error object can passfurther items back to the caller.

	loNodes = this.oXml.selectNodes("/qstreamresponse/qsel"); 
	if (loNodes.length > 0) 
		lcRet = loNodes.item(0).getAttribute('qskeyid');
	else
		lcRet = 0;
	return lcRet;
}


qstreamResponse.prototype.addError = function(tnNumber, tcError)
{
	var loNode, loError, loErrorHolder;
	
	if (!this.oXml)
		this.initXml();
		
	this.nErrors += 1;
	loErrorHolder = this.oXml.selectNodes("/qstreamresponse/qserrorobject")

	loError = this.oXml.createNode("qsmsg", "")
	
	loError.setAttribute("messid", tnNumber)
	loError.setAttribute("messtxt", tcError)
	loErrorHolder.item(0).appendChild(loError)
}

qstreamResponse.prototype.initXml = function()
{
	this.cXml = '<?xml version = "1.0" encoding="windows-1252" standalone="yes"?><qstreamresponse><qserrorobject nresult="0" errors="0" messages=""></qserrorobject></qstreamresponse>'

	this.load();
}

qstreamResponse.prototype.showMessages = function()
{
	var loNodes,  lni, lcstr;
	
	lcstr = ""
	loNodes = this.oXml.selectNodes("/qstreamresponse/qserrorobject/qsmsg")

	for (lni = 1; lni <= this.nMessages; lni++)
	{
		lcstr = lcstr + loNodes.item(lni -1 ).getAttribute('messtxt') + '<br/>';
	} 	

	return lcstr;	
}

qstreamResponse.prototype.showErrors = function()
{

	var loNodes, lnMessages, lni, lcstr;

	loNodes = this.oXml.selectNodes("/qstreamresponse/qserrorobject")
	lnResult = loNodes.item(0).getAttribute('nresult');

	// nresult = 0 OK, nresult = 1 error and show messages

	lnMessages = loNodes.item(0).getAttribute('errors');
	lcstr = ""
	loNodes = this.oXml.selectNodes("/qstreamresponse/qserrorobject/qserrormsg")

	// if (this.nresult == 1)
	if (this.nErrors  > 0)
	{
		for (lni = 1; lni <= lnMessages; lni++)
		{
			lcstr = lcstr + loNodes.item(lni -1 ).getAttribute('errmess') + '<br/>';
		} 	
	}
	return lcstr;	
}

function genxsl_SetFormReadonly(tnformid, tlSetAsReadOnly)
{

	var loform, loNodes, lni, lobutton, lcbackcolor;
	//
	// if set as read only then set backgound color as light grey
	//
	if (tlSetAsReadOnly)
	{
		lcbackcolor="f0f0f0";
	}
	else
	{
		lcbackcolor="";
	}
	

	//
	// Get current for object
	//
	loform = document.getElementById("saveform" + tnformid);


	//
	// for each element of form: Text box, combo, text area , check box 
	// Set as readonly / read write 
	//


	for (lni=0; lni < loform.length ; lni++)
	{	
		loform.elements[lni].readOnly			= tlSetAsReadOnly ;
		loform.elements[lni].style.backgroundColor	= lcbackcolor;
		if (tlSetAsReadOnly==false)
			loform.elements[lni].style.className 	= "udf_textbox";
		if (loform.elements[lni].tagName=='SELECT')

			loform.elements[lni].disabled 		= tlSetAsReadOnly ;
	}


	if (tlSetAsReadOnly == true)
	{


		// IF RO 
		// Set save and cancel as disabled and edit enmabled
		lobutton = document.getElementById("editbutton" + tnformid);
		if (lobutton!=null)
			lobutton.disabled = false ;
		lobutton = document.getElementById("savebutton" + tnformid);
		if (lobutton!=null)
			lobutton.disabled = true ;

		lobutton = document.getElementById("cancelbutton" + tnformid);
		if (lobutton!=null)
			lobutton.disabled = true ;

	}
	else
	{

		// IF RO 
		// NOT (Set save and cancel as disabled and edit enmabled)
		lobutton = document.getElementById("editbutton" + tnformid);
		if (lobutton!=null)
			lobutton.disabled = true ;

		lobutton = document.getElementById("savebutton" + tnformid);
		if (lobutton!=null)
			lobutton.disabled = false ;

		lobutton = document.getElementById("cancelbutton" + tnformid);
		if (lobutton!=null)
			lobutton.disabled = false ;
	}

}


function genxsl_BreakItUp(tcFieldName, tncpid)
{
	var FormLimit = 102399;
	var TempVar = new String;
	var lonode;
	
	if (document.all("eHtmlO" + tcFieldName)  != null)
	{
		lonode = document.getElementById("eHtmlO" + tcFieldName);
		TempVar =lonode.DocumentHTML;

		lonode = document.getElementById(tncpid);
			
		if (TempVar.length > FormLimit)
		{
			
			lonode.value  = TempVar.substr(0, FormLimit);
			TempVar = TempVar.substr(FormLimit);
			while (TempVar.length > 0)
			{
				var objTEXTAREA = window.document.createElement("INPUT");
				objTEXTAREA.name = tncpid; 
				objTEXTAREA.type = "HIDDEN";
				objTEXTAREA.value = TempVar.substr(0, FormLimit);
				window.document.saveform.appendChild(objTEXTAREA);
				TempVar = TempVar.substr(FormLimit);
			}
		}
		else
		{
			lonode.value = TempVar;
		}
	}
		
	// No need to upload HTML files (when using the qs uploader since we have a a generic funciton
	// that will upload any of object present (based on clsid )
	
}


//****************************************************************************************
//*
//*
//*		PUSHJAVASCRIPT
//*
//* Push Javascript contained in an httprequest.text to dom where the called 
//* paged is being inserted
//*
//****************************************************************************************





function pushJavaScript(tcText, tnFid)
        {		

            return pushJavaScriptImplements(tcText, tnFid, true)
				
        }
        
        
function pushJavaScriptNoEval(tcText, tnFid)
        {		

            return pushJavaScriptImplements(tcText, tnFid, false)
				
        }


function pushJavaScriptImplements(tcText, tnFid, tlEvalMode)
       {		

            
			var llFidLoaded;
	       		var loscript;
			var loscriptnodes;
			var lodummydiv;
	        	var lodest          = document.getElementsByTagName('head');
		        var lcAction
			var lcdummydivname;
			var lnerror;
			var lcnewscript;
			var losupport;


			lcnewscript = '';
			
			
			// This does not aplly once we are loading all scripts so gcFidLoadedScript is always = 0
						
			try
			{
				gcFidLoadedScript = '0';
				
				eval(gcFidLoadedScript);
				//Variable must always be defined eval does not work well in Firefox
				
			}
			catch(err)
			{
				
				//	Intantiation of gcFidLoadedScript in case there is no defined variable
				gcFidLoadedScript = '0';
			}			

			if(gcFidLoadedScript.indexOf(';' + tnFid + ';') > -1)
			{
				llFidLoaded = true;
			}   
    		    loscript        = document.createElement('script');
			    loscript.id     ='AJAXScript'
    		

//			    A HIDDEN DIV with ID ps_pushscript must exist in the TOP LEVEL template BETWEEN end body and end HTML tag. (2007.10.16)
		   	    lcdummydivname = 'ps_pushscript';
//		   	    lcdummydivname = 'lodummydiv';
			   
			    lodummydiv      = document.createElement('div') ;
			    lodummydiv.style.display = 'none' ;
			    lodummydiv.id   = lcdummydivname ;
			    
	    		lodummydiv.innerHTML = tcText;
	                
			// losupport = document.getElementById('qs_scriptscratch')
	               // losupport.appendChild(lodummydiv)

	    		loscriptnodes   = lodummydiv.getElementsByTagName('script');

	    		for (var lnpush_i = 0; lnpush_i < loscriptnodes.length; lnpush_i++)
	    		{

				lcAction = loscriptnodes[lnpush_i].getAttribute("qs_ajaxscript");
				
				// DO NOT PUSH javascript for google analyticts setup code (http: // https

				if (loscriptnodes[lnpush_i].text.indexOf('var gaJsHost') == -1)
				{

				    try
		            	    {
					//if there is an error goes to next

	 		            	        
	 		            	        if(tlEvalMode)
	 		            	        {
	 		            	            eval(loscriptnodes[lnpush_i].text);
	 		            	        }

					                        try
					                        {
                                                
					                            lcnewscript = lcnewscript +  "\r\n"   + loscriptnodes[lnpush_i].text;	 
                        					
                                            }
					                        catch(err)
					                        {
						                        null;
					                        }


	    		            }
	    		            catch(err)
	    		            {
					
	    		            }

				}
				else if(lcAction == 'execute')
				{	

					try
		            	    	{
								//if there is an error goes to next
		            	        		eval(loscriptnodes[lnpush_i].innerHTML);
		            	        		loscript.text = loscript.text + String.fromCharCode(13,10) + loscriptnodes[lnpush_i].text;	            	        
	            	        
	    		            	}
	    		            	catch(err)
	    		            	{
	    		                	
	    		            	}					
				}
				else
				{
					null;					
				}	

				
			}

			
			// Need to use lcnewscript and add in one go otherwise it gets 
			// executed each time I add the item

			loscript.text = lcnewscript;

			lodest[0].appendChild(loscript);

           		loscript.parentNode.removeChild(loscript);

			// lodummydiv.parentNode.removeChild(lodummydiv);
			gcFidLoadedScript = gcFidLoadedScript + ';' + tnFid + ';';
		

			return true;	
        }


function selectAllCheckBoxes(tcFrom, tcType, tcNameCollection, tlAction, toCaller)
{

	var loCkCollection, lcFrom;
	var lnPos;

	lcFrom 			 = 	document.getElementById(tcFrom);

	loCkCollection	 = 	lcFrom.getElementsByTagName('input');

		for (lnPos=0;lnPos<loCkCollection.length;lnPos++)
		{
			loCkCollection[lnPos].checked = tlAction;
		}

	toCaller.setAttribute("selectall",!(tlAction));
	toCaller.value= tlAction ? "Unselect all" : "Select all"
}



function isAnyCheckBoxChecked(tcForm)
	{
		var i
		var loallinputs, lodeleteboxes, lochangealbumboxes, lcinputtype
		var loform
		var llaboxischecked

		loform 		= document.getElementById(tcForm);
		loallinputs 	= loform.getElementsByTagName("input");
			
		llaboxischecked = false;
		
		//puting inputs in the rigth variable



		for(i=0;i<loform.elements.length;i++){
			
			
			
			if(loform.elements[i].getAttribute("type"))
				{
						lcinputtype = loform.elements[i].getAttribute("type")

						switch(lcinputtype){
			
							case "checkbox": 
							 if (loform.elements[i].checked)
							 {
								llaboxischecked = true;								
							 }
								break;

							default: null ;
						}
				}
			
		}
		
return llaboxischecked;
}


function printAds(toDiv){
			
		var lodivprocesspub, lopubprops, lcadname, lcHtmlgrab, lcpubdefinition
		var lodestination, lnnumberofitens, lcAdToGet, loAdToGet
		var lonode


		if (!(document.getElementById("psprocesspub")))
		{
		
			if (document.readyState == 'complete')
			{
						
				lodivprocesspub 	= document.createElement('div')
				lodivprocesspub.id 	= 'psprocesspub'
				document.appendChild(lodivprocesspub)
			}
			else
			{	
				return false
			
			}
			
		}

		if(toDiv.getAttribute('pubdefinition') && (toDiv.getAttribute("divisup") != 'yes') )
		{

		lcpubdefinition 	= toDiv.getAttribute('pubdefinition') 
		
		var loXmlHttp = new xmlHttpDom();
		lcHtmlgrab 		= loXmlHttp.callUrl('GET','/pstreampub/banners/'+ lcpubdefinition +'.asp' );
		// lcHtmlgrab 		= http_execute_url('GET','/pstreampub/banners/'+ lcpubdefinition +'.asp' );
		
		lodivprocesspub 	= document.getElementById("psprocesspub");
		
		lonode 			= document.createElement('div')
		lonode.innerHTML = lcHtmlgrab

		lodivprocesspub.appendChild(lonode)

		toDiv.setAttribute('divisup', 'yes') ;

		if(document.getElementById("properties"))
		{

			loproperties 		= document.getElementById("properties");
			lnnumberofitens 	= loproperties.getAttribute("numberofitens")
			if (typeof(lnnumberofitens)=='undefined')
				lnnumberofitens = 0 
			else
			{
				if (lnnumberofitens  > 0 )
				{


					lnrandom = randomnumber(1, lnnumberofitens) 
					lcAdToGet 			= 'html_' + lcpubdefinition + '_' + lnrandom
					loAdToGet 			= document.getElementById(lcAdToGet);
		
					if (loAdToGet){
						toDiv.innerHTML 	= loAdToGet.innerHTML;	
					}
				}

			}	
			qs_addhandler.addad(toDiv.innerHTML, toDiv.id)
		}
		
		lonode.parentNode.removeChild(lonode);
		if(detectNavigator()!=2)
		{

			// pushJavaScriptNoEval(lcHtmlgrab,0);
		}
	}	
}						
	
	
function randomnumber(tnMin, tnMax)
{

var lnrandomnumber

lnrandomnumber = Math.floor(Math.random()*(tnMax+1))
if (lnrandomnumber >= tnMin && lnrandomnumber <=tnMax)
	{

	//alert(lnrandomnumber)

		return lnrandomnumber 
	}
	else
	{

		return randomnumber(tnMin, tnMax)
	}

}

			


function setpostoleft(tcchild, tchost)
{
	var lochild, lohost;


	lohost 	= document.getElementById(tchost);
	lochild	= document.getElementById(tcchild);
	lochild.style.position ='absolute';

	lochild.style.top 	= lohost.style.top;
	lochild.style.left 	= lohost.style.pixelLeft - lochild.style.pixelWidth;

}
function setposcascade(tcchild, tchost)
{
	var lochild, lohost;


	lohost 	= document.getElementById(tchost);
	lochild	= document.getElementById(tcchild);
	lochild.style.position ='absolute';

	lochild.style.top 	= lohost.style.pixelTop + 20 + 'px';
	lochild.style.left 	= lohost.style.pixelLeft + 20 + 'px' ;

}



/* MV 2007.10.19  */
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}



function maxsizeh(tnmaxh)
{
	var loimgphoto
	


	if (!(document)){
		setTimeout('maxsizeh(tnmaxh)',500);
	}
	else
	{
		if(document.getElementById("showsinglephoto"))
		{
			lodivphoto = document.getElementById("showsinglephoto");
		
			if (lodivphoto.height > tnmaxh)

			{
				lodivphoto.height = tnmaxh;
			}
		}
	}


}

function maxsizewidth(tnmaxw)
{

var loimgphoto, lnscale;


	if (!(document)){
		setTimeout('maxsizewidth(tnmaxw)',500);
	}
	else
	{
		if(document.getElementById("showsinglephoto"))
		{
			lodivphoto = document.getElementById("showsinglephoto");
		
			if ((lodivphoto.width > tnmaxw) || (lodivphoto.width < tnmaxw ))

			{
				lnscale = lodivphoto.width / lodivphoto.height;
				lodivphoto.width = tnmaxw;
				if (lnscale != 0) 
					lodivphoto.height = tnmaxw / lnscale ;

			}
		}
	}


}


function execOnEnterKey(e, tcCode){ 
	var lnc 
	if(e && e.which)
	{ 
		e = e
		lnc = e.which 
	}
	else
	{
		e = event
		lnc = e.keyCode 
	}

	if(lnc == 13)
	{
		setTimeout ( tcCode,1)
		return false 
	}
	else
		return true 
}



function displayitems(tcnames,tcstyle)
{
	var laitem, loitem, lnitem, lcitem;

	laitem = tcnames.split(',')
	for (lnitem=0;lnitem < laitem.length ; lnitem++)
		{
			lcitem = laitem[lnitem]
			loitem = document.getElementById(lcitem);
			if(loitem)
			{
				loitem.style.display= tcstyle;
			}
		}
}

function getinnerHTML(tcname)
{
	return document.getElementById(tcname).innerHTML;

}

function setinnerHTML(tcname, tcHtml)
{
	return document.getElementById(tcname).innerHTML=tcHtml;

}


function getabsolutex(toobj)
{
	var lnx=0;


	if (toobj.offsetParent) {
//		do {
//			;
//			lnx += toobj.offsetLeft;
//		} while (toobj = toobj.offsetParent);

		do {
			toobj = toobj.offsetParent
			lnx += toobj.offsetLeft;
		} while (toobj.offsetParent);
	}

	return lnx;
}
function getabsolutey(toobj)
{
	var lny=0;

	if (toobj.offsetParent) {
		
		do 
		{
			toobj = toobj.offsetParent;
			lny += toobj.offsetTop;
		} while (toobj.offsetParent)
	}

return lny;
}


function cAppProperties()
{

	this.cAppName 	= 'Update application name';
	this.cCopyright = 'Update copyright MIGG Copyright';
	this.cUsername 	= 'Anonymous';
	this.cDate	= '';
	this.cSite 	= ''

}

cAppProperties.prototype.set= function(tcappname, tccopyrightnotice, tcsite, tcdate, tcusername)
{

	this.cAppName 	= tcappname;
	this.cCopyright = tccopyrightnotice;
	this.cUsername 	= tcusername;
	this.cDate 	= tcdate;
	this.cSite 	= tcsite;

}

cAppProperties.prototype.display = function()
{
var loEl = new elUi("qsapp_name")

loEl.putHtml(this.cAppName)

var loEl = new  elUi("qsapp_copyright")
loEl.putHtml(this.cCopyright)

var loEl = new  elUi("qsapp_username")
loEl.putHtml(this.cUsername)

var loEl = new  elUi("qsapp_date")
loEl.putHtml(this.cDate)

var loEl = new  elUi("qsapp_site")
loEl.putHtml(this.cSite)

}


function fl_positiontitles()
{
	try
	{
		qsHandler.showFlashTitles();
	}
	catch(e)
	{
		// do nothing
	}
}


cPopText = function(tcText, tcId, tlIsString, tcTag)
{
	this.cText = tcText;		// 
	this.lIsString = tlIsString; // true -> cText is an ID otherwise is the TEXT
	this.cId = tcId;				// recipient element
	this.cTag = tcTag;

}

function cQsHandler()
{

	this.nAsyncCalls = 0 ;				// keep track of async calls
	this.nviews 	= 0					// number of qstream views in window
	this.aviews 	= new Array();				// Hold collection of view objects
	this.nflashtitles= 0 ;					// Number of flash titles to handle
	this.aflashtitles = new Array();

	this.nUrls= 0 ;
	this.aUrls= new Array();				// holds array of url executes - to handle BACK
	this.azones= new Array();				// holds the div where the url was executed
	this.atabids= new Array();				// holds the tab id where the stuff was displayed
	this.aUrls[0]='';

	// Handle HTML wrappers for views
	this.awrappers = new Array();
	this.awrapper_data = new Array();
	this.awrapper_pos = new Array();
	this.awrapper_col = new Array();
	this.nwrappers = 0;
	this.adiv_item = new Array();
	this.adiv_pos = new Array();
	this.ndivpos = 0;
	this.oGoogleIds = new googleTrackerId();
	this.oAppProperties = new cAppProperties();
	this.oCurrentTabset	= null;

	this.atabsets = new Array();
	this.ntabsets = 0 ;
	this.omsg = new message_handler();

	// hold a reference for all loaded views (viewdisplay),  this is need to click search
	// and all future searching;
	this.nFids = 0;
	this.aFids = new Array();
	
	this.nPopText = 0;
	this.aPopText = new Array();
		
	this.nentities = 0 ;
	this.aentities = new Array() ;				// loaded data entities (entitybasclass) 
	this.oUser = null;
	this.aHttpXmlObj = new Array();
	this.nHttpXmlObj = 0 ;
	this.oFids = new fidsContainer();
	this.version = 2;
	this.oMap = null;
	this.oTip = new objCollection();
	
	// Handlers
	this.oGoogleMaps  = null;
	this.oJsHandler = null;
	this.oUiHandler = null;		// by default no Ui handler
	this.cTxExtraTags = "";		// include additional html element tags to be included in tx
	this.cTxCodeFamily = "";		// byt defaulkt any id /txId is included,  if this has a value then only ids txid starting with the value
	
	
}


cQsHandler.prototype.initJsHandler = function()
{
	qsHandler.oJsHandler = new cJsHandler();
}
	
cQsHandler.prototype.getVarValue = function(tcVar)
{
	return getVarValue(tcVar)
}

cQsHandler.prototype.setVarValue = function(tcVar, tcValue)
{
	if (!isnull(tcVar))
	{
		var loXmlSetVar = new xmlDOC;
		loXmlSetVar.getdata("/sv.asp?" + encodeURIComponent(tcVar)  + "=" + encodeURIComponent(tcValue)  );
	}
}

cQsHandler.prototype.translatePage = function()
{
	var loTx;
	if (typeof(translateHandler)=='function')
		loTx = new translateHandler();

	if (loTx)
	{
		loTx.translateThePage();
		loTx.txLabels();
	}
}
	
cQsHandler.prototype.editTranslation = function(tnFid)
{
	var loTx;
	if (typeof(translateHandler)=='function')
		loTx = new translateHandler();
	
	if (loTx)
		loTx.editTranslation(tnFid);
	
}	
	
	
cQsHandler.prototype.addPopText = function(toText, tcId, tcTag)
{
	// toText can either be text or an element containing text.
	// tcTag is the tagname of the recipient element 
	// the origin element always provides text via innerHTML;
	
	this.nPopText += 1; 
	if (typeof(toText)=='string')
		this.aPopText[this.nPopText] = new cPopText(toText, tcId, true, tcTag);
	else
		this.aPopText[this.nPopText] = new cPopText(toText.id, tcId, false, tcTag);
}


cQsHandler.prototype.showPopText = function()
{
	var lni, loDiv, lcText;
	lcText = "";
	for (lni=1; lni<=this.nPopText; lni++)
	{
		loDiv = document.getElementById(this.aPopText[lni].cId);
		if (loDiv)
		{
			if (this.aPopText[lni].lIsString)
				lcText = this.aPopText[lni].cText
			else
			{
				loEl = $(this.aPopText[lni].cText)
				if (loEl)
					lcText = loEl.innerHTML
			}	
			if (this.aPopText[lni].cTag == 'INPUT')
				loDiv.value = lcText;
			else
				loDiv.innerHTML = lcText;
			
		}
	}
}


cQsHandler.prototype.setUser = function(touser)
{
	// Hold the current user object for checking permissions and other issues
	this.oUser = touser;
}

cQsHandler.prototype.TabsetShowHeader = function(tcname)
{
	var lni;
	for (lni = 1; lni <= this.ntabsets; lni++)
	{
		if (!(typeof(this.atabsets[lni].cname)=='undefined'))
		{			
			// v0
			if (this.atabsets[lni].cname == tcname)
			{
				this.oCurrentTabset = this.atabsets[lni];
				this.atabsets[lni].showheader();
			}
		}
		else
		{			
			// v1
			if (this.atabsets[lni].cName == tcname)
			{
				this.oCurrentTabset = this.atabsets[lni];
				this.atabsets[lni].showHeader();
			}
		}
	}

}

cQsHandler.prototype.TabsetAdd = function(totabset)
{
	this.ntabsets = this.ntabsets + 1;
	this.atabsets[this.ntabsets] = totabset;
	this.oCurrentTabset = totabset;

}

cQsHandler.prototype.TabsetGetTabId = function(tctabname, tctabset)
{
	var lotab, lntabset ;
	lntabset = 0 ;

	for (lni = 1; lni <= this.ntabsets; lni++)
	{
		if (!typeof(this.atabsets[lni].cname)=='undefined')
		{			
			// v0
			if (this.atabsets[lni].cname == tctabset)
			{
				this.oCurrentTabset = this.atabsets[lni];
				lntabset = lni ;
			}
		}
		else
		{
			// v1
			if (this.atabsets[lni].cName == tctabset)
			{
				this.oCurrentTabset = this.atabsets[lni];
				lntabset = lni ;
			}
		}
	}
	if (lntabset > 0 )
		return this.atabsets[lntabset].getTabId(tctabname);		
	else
		return null
//	else
		alert('Tabset ' + tctabset + ' not found');

}

cQsHandler.prototype.TabsetGetTab = function(tctabname, tctabset)
{
	var lotab, lntabset ;
	lntabset = 0 ;

	for (lni = 1; lni <= this.ntabsets; lni++)
	{
		// v1
		if (this.atabsets[lni].cName == tctabset)
		{
			this.oCurrentTabset = this.atabsets[lni];
			lntabset = lni ;
		}
	}
	if (lntabset > 0 )
		return this.atabsets[lntabset].getTab(tctabname);		
	else
		return null
}

cQsHandler.prototype.moverGet = function(tcTagName)
{
	var loMover;
	
	loMover = this.entityGet(tcTagName)
	
	if (isnull(loMover))
		loMover = new moverList;
	
	return loMover;
}

cQsHandler.prototype.entityRemove = function(tcTag)
{
	var lni, loret;
	loret = null;

	for (lni=1; lni <= this.nentities; lni++)
	{	
		if (typeof(this.aentities[lni].cTagName)=='string')
		{
			if (this.aentities[lni].cTagName == tcTag)
			{
				this.aentities.splice(lni,1);
				this.nentities -=1;
			}
		}
		else
		{
			if (this.aentities[lni].bc.cTagName == tcTag)
			{
				this.aentities.splice(lni,1)
				this.nentities -=1;
			}
		}
	}	
	
}
cQsHandler.prototype.entityAdd = function(loEntity)
{
	var lodummy = null;
	
	if (typeof(loEntity.bc) !='undefined')
		lodummy = this.entityGet(loEntity.bc.cTagName,true);

	if (typeof(loEntity.cTagName) !='undefined')
		lodummy = this.entityGet(loEntity.cTagName, true);
	
	
	if (isnull(lodummy))
	{
		this.nentities +=1;
		this.aentities[this.nentities] = loEntity;
	}
}

cQsHandler.prototype.entityGet = function(tcTag, tlNoLoadJs)
{
	var lni, loRet;
	loRet = null;

	for (lni=1; lni <= this.nentities; lni++)
	{	
		if (typeof(this.aentities[lni].cTagName)=='string')
		{
			if (this.aentities[lni].cTagName == tcTag)
			{
				loRet = this.aentities[lni];
				lni = this.nentities;
			}
		}
		else
		{
			if (this.aentities[lni].bc.cTagName == tcTag)
			{
				loRet = this.aentities[lni];
				lni = this.nentities;
			}
		}
	}
	
	if (typeof(tcTag)!='undefined' && isnull(loRet) && tlNoLoadJs!=true && this.oJsHandler)
	{
		this.oJsHandler.loadJs(tcTag);
	}

	return loRet
}


cQsHandler.prototype.refreshMovers = function()
{

	var lni, loret;


	loret = null;

	for (lni=1; lni <= this.nentities; lni++)
	{	
		if (typeof(this.aentities[lni].refreshList)=='function')
			this.aentities[lni].refreshList();
	}
	return loret
}


cQsHandler.prototype.viewAdd = function(tnFid)
{

	var loView;
	loView = this.viewGet(tnFid);
	if (isnull(loView))
	{
		loView = new qsView(tnFid)
		this.nFids +=1;
		this.aFids[this.nFids] = loView;
	}
	return loView;
}

cQsHandler.prototype.toggleViewSize = function(toElement)
{

	var lnFid = parseInt(toElement.getAttribute('qsfid'));
	if (lnFid > 0 )
	{
		var loView = this.viewGet(lnFid);
		loView.toggleSize();
	}
}
cQsHandler.prototype.viewGet = function(tnFid)
{
	var lni, loRet;
	loRet = null;
	tnFid = parseFloat(tnFid);
	for (lni=1; lni <= this.nFids; lni ++)
	{
		if (this.aFids[lni].nFid == tnFid)
		{
			loRet = this.aFids[lni];
			lni = this.nFids;
		}			
	}

	return loRet;
}


function googleTrackerId()
{

	this.nIds = 0;
	this.aGoogleIds = new Array();
	this.aUdn	= new Array();

}

googleTrackerId.prototype.addid = function(tcid, tcudn)
{

var lcgoggleids

lcgoggleids = ','+this.aGoogleIds.toString()+','

if (lcgoggleids.indexOf(tcid)>0)
{
    null;
}
else
{
    this.aGoogleIds.push(tcid) ;
    this.aUdn.push(tcudn) ;					// domain name , must pass additional '.'
}

}

googleTrackerId.prototype.sendToGoogle = function (tcUrl)
{
    var lnigoogle, lctrackid, lcudn;

	for(lnigoogle=0 ;lnigoogle < this.aGoogleIds.length; lnigoogle ++)
        {
           

	try
	{
             lctrackid = this.aGoogleIds[lnigoogle] 

        if (typeof( lctrackid )=='string')
	{
          
            if ((_gat != null) )
		{
			lcudn = this.aUdn[lnigoogle] ;
			var pageTracker = _gat._getTracker(lctrackid);
			pageTracker._initData();
			if (typeof( lcudn )=='string' && lcudn.length > 0)
			{
				pageTracker._setDomainName(lcudn);
			}
			pageTracker._trackPageview(tcUrl);
		}

        }
	}
	catch(e)
	{
		// do thing
	}
	}
	

}





function showmeHTML(tctag, tctextarea)
{
	var lotag, lotextarea, lcstr;


	lotag = document.getElementById(tctag);
	if (lotag != null)
	{

		lotextarea = document.getElementById(tctextarea);
		if (lotextarea != null)
		{
			lcstr = lotag.innerHTML;
			lotextarea.innerHTML = urlencode(lcstr);
		}
	}
	return false;	

}


function txtencode(str) {

str = str.replace('<', '&lt;');
str = str.replace('>', '&gt;');
str = str.replace('&', '&amp;');
return str;
}

function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
//str = str.replace('%20', '+');

str = str.replace('%', '%25');

str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');

str = str.replace(/%3C/g, '&lt;');
str = str.replace(/%3E/g, '&gt;');
str = str.replace(/%20/g, ' ');
str = str.replace(/%22/g, '&quot;');
str = str.replace(/%2C/g, '.');
str = str.replace(/%3A/g, ':');
str = str.replace(/%3B/g, ';');

str = str.replace(/%3D/g, '=');


return str;
}

cQsHandler.prototype.displayWrappers = function()
{

//	alert('wrapper stuff');
	var lotemplate, lodata, loposition, lni,lcwrapper,lodiv, lcstr,loparent, lccolor;
	for (lni = 1 ; lni <= this.nwrappers; lni++)
	{

		lopos  	= document.getElementById(this.awrapper_pos[lni]);

		if (lopos)
		{

			lcwrapper = lopos.getAttribute("wrapper");


			if (lcwrapper != 'yes')
			{


				lotemplate 	= document.getElementById(this.awrappers[lni]);
				lodata		= document.getElementById(this.awrapper_data[lni]);

				lodiv 			= document.createElement("div");
				// lodiv.style.display	="inline";			// needed to locate location of genxsl titles  // BUT now does not display the EMBED TOOLBAR !!
				// lodiv.style.position	="relative";
				//lodiv.style.left 	= "0px";
				//lodiv.style.top		= "0px";

				loparent = lodata.parentNode;
				loparent.appendChild(lodiv);

				lodiv.innerHTML 	= lotemplate.innerHTML;

				

				lccolor = this.awrapper_col[lni];
				lobin 			= lodiv.getElementsByTagName('TABLE');
				if ((lobin.length > 0 ) && (lccolor !=null))
				{
 					lobin[0].style.backgroundColor=lccolor;
				}


				lobin 			= lodiv.getElementsByTagName('span');


				lodata.parentNode.removeChild(lodata);
				
				lobin[0].innerHTML = '';
// alert('put ' + this.awrapper_data[lni] + " inside " + this.awrappers[lni] + " and position at " + this.awrapper_pos[lni] );
				lobin[0].appendChild(lodata);


				lopos.setAttribute("wrapper", "yes");


			}
			else
			{
//				alert('wrapper is here');
			}
		}
	}

	return false;
}

cQsHandler.prototype.displayDivPos= function()
{

	var lni, loEl;
	for (lni = 1 ; lni <= this.ndivpos; lni++)
	{
		loEl = new elUi(this.adiv_item[lni]);
		loEl.position(this.adiv_pos[lni],10,10);
		loEl.show();
		document.getElementById(this.adiv_item[lni]).top = "100px";
		document.getElementById(this.adiv_item[lni]).style.display="inline";
	}
}

cQsHandler.prototype.moveToPage = function(tnFolderid, tnpage)
{
	var loXmlHttp = new xmlHttpDom();
	loXmlHttp.exec('qsfid' + tnFolderid, '/vd.asp?folderid=' + tnFolderid + '&RHSPAGENO=' + tnpage + '&USERAW=YES&ADDVIEWDIV=NO', tnFolderid)
	// http_execute('qsfid' + tnFolderid, '/vd.asp?folderid=' + tnFolderid + '&RHSPAGENO=' + tnpage + '&USERAW=YES&ADDVIEWDIV=NO', tnFolderid)
	return false;
}


cQsHandler.prototype.addDivPos = function(tcdiv, tcpos)
{
	var lni;

	lni = this.getDivPosIndex(tcdiv);
	if (lni == 0 )
	{
		this.ndivpos += 1 ;
		this.adiv_item[this.ndivpos] = tcdiv;
		this.adiv_pos[this.ndivpos] = tcpos;
	}
	else
	{
		this.adiv_item[lni] = tcdiv;
		this.adiv_pos[lni] = tcpos;
	}

}

cQsHandler.prototype.addwrapper =  function(tcwrapperid, tcdataid, tcposid, tccolor)
{
	this.addWrapper(tcwrapperid, tcdataid, tcposid, tccolor)
}

cQsHandler.prototype.addWrapper =  function(tcwrapperid, tcdataid, tcposid, tccolor)
{
	var lni;

	lni = this.getWrapperIndex(tcdataid);
	if (lni == 0 )
	{
		this.nwrappers += 1 ;
		// alert('adding wrapper for ' + tcwrapperid + ' at pos ' + tcposid + ' pos nb is ' + this.nwrappers );
		this.awrappers[this.nwrappers] = tcwrapperid;
		this.awrapper_data[this.nwrappers] = tcdataid;
		this.awrapper_pos[this.nwrappers] = tcposid;
		this.awrapper_col[this.nwrappers] = tccolor;
	}
	else
	{
		this.awrapper_data[lni] = tcdataid;
		this.awrapper_pos[lni] = tcposid;
		this.awrapper_col[lni] = tccolor;
	}
}

cQsHandler.prototype.addUrlTabset = function(tcUrl)
{
	this.addUrl('qszone_appbody', tcUrl);
	this.aUrls[this.nUrls].nTabId = null;
	this.aUrls[this.nUrls].cTabSetUrl = tcUrl;
	this.aUrls[this.nUrls].nCallType = 3;
}

cQsHandler.prototype.urlGetLastTabSet = function()
{

	var lcret = null;
	var lni;
	for (lni = this.nUrls ; lni > 0; lni--)
	{
		if (!isnull(this.aUrls[lni].cTabSetUrl))
		{
			lcret = this.aUrls[lni].cTabSetUrl;
			lni = 0;
		}
	}
	if (isnull(lcret))
	{
		lcret = window.location.href;
	}

	return lcret;
}

function urlCall(tcZone, tcUrl)
{
	this.cUrl = tcUrl;
	this.cZone = tcZone;
	this.cTabSetUrl = null;
	this.nTabId = null;
	this.nCallType = 1;
}

cQsHandler.prototype.addUrlTab =  function(tcZone, tcUrl, tnTabId)
{
	this.addUrl(tcZone, tcUrl);
	this.aUrls[this.nUrls].nTabId = tnTabId;
	this.aUrls[this.nUrls].cTabSetUrl = qsHandler.oCurrentTabset.cUrl;
	this.aUrls[this.nUrls].nCallType = 2;
}

cQsHandler.prototype.addUrl =  function(tcZone, tcUrl)
{
	
	this.nUrls += 1 ;
	this.aUrls[this.nUrls] = new urlCall(tcZone, tcUrl)
	
	try
	{
		if (!isnull(qsHandler.oCurrentTabset))
		{
			// alert('set to ' + qsHandler.oCurrentTabset.oTab.ntabId)
			this.aUrls[this.nUrls].nTabId = qsHandler.oCurrentTabset.oTab.ntabId;
			this.aUrls[this.nUrls].cTabSetUrl = qsHandler.oCurrentTabset.cUrl;
		}
	}
	catch(e)
	{
		null;
	}		
}

cQsHandler.prototype.backUrl =  function(tcUrl)
{
	var lcurl, lczone, lnTabId, lcTagName, lnKeyid, lnFid, lnLastTabIndex;
	var loCall;
	
	
	if (this.nUrls > 0)
	{
		this.nUrls -= 1 ;
		loCall = this.aUrls[this.nUrls]
		lcurl = loCall.cUrl;
	 	lczone = loCall.cZone
		lnTabId = loCall.nTabId;
		if (loCall.nCallType==3)
		{
			this.nUrls -= 1 ;
			loCall = this.aUrls[this.nUrls]
			lcurl = loCall.cUrl;
			lczone = loCall.cZone
			lnTabId = loCall.nTabId;
		}
		if (!isnull(loCall.cTabSetUrl) && (isnull(qsHandler.oCurrentTabset) || (loCall.cTabSetUrl != qsHandler.oCurrentTabset.cUrl)))
		{
				
			http_execute('qszone_appbody', loCall.cTabSetUrl + "&USERAW=YES&USEDEFHTML=OFF", 0);
			setTimeout('if (qsHandler.oCurrentTabset.oTab.nTabId !='+ lnTabId + ') {qsHandler.oCurrentTabset.callTab(' + lnTabId + '); qsHandler.nUrls -=1;}',800)
			setTimeout('http_execute("' + lczone + '", "' + lcurl + '&USERAW=YES&USEDEFHTML=OFF", 0)',1200)
			//this.nUrls -=1;
		}
		else
		{
			if (loCall.nTabId != qsHandler.oCurrentTabset.oTab.nTabId)
			{
				qsHandler.oCurrentTabset.callTab(loCall.nTabId)
				this.nUrls -=1;
			}
			if (loCall.nCallType==1)
				if (!isnull(document.getElementById(lczone)))
					http_execute(lczone, lcurl + "&USERAW=YES", 0);
				else
					history.back();
		}
	}
	else
	{
		this.nurl = 0 ;
		history.back();
	}
}


cQsHandler.prototype.addFlashTitle =  function(tctagid, tctitle, tnrotation, tccolor, tccontainer, tcpositionat, tnx, tny)
{
	var lnindex;
	try 
	{
		if ((tccolor=='undefined') || (tccolor==null))
		tccolor = 'FF3322';
	}
	catch(e)
	{
		tccolor = 'FF3322';
	}
	try 
	{
		if ((typeof(tnoffsetx)=='undefined' )  || (tnoffsetx==null))
			tnoffsetx = 0;

	}
	catch(e)
	{
		tnoffsetx = 0;
	}
	try 
	{
		if ((typeof(tnoffsety)=='undefined' )  || (tnoffsety==null))
			tnoffsety = 0;

	}
	catch(e)
	{
		tnoffsety = 0;
	}

	lnindex = this.getFlashIndex(tctagid, tccontainer);

	if (lnindex == 0)
	{
		this.nflashtitles 	+=1;
		this.aflashtitles[this.nflashtitles] = new flashtitle(tctagid, tctitle, tnrotation, tccolor, tccontainer, tcpositionat, tnx, tny);				// Holds current records
	}
	else
	{
		this.aflashtitles[lnindex].ctitle = tctitle;
		this.aflashtitles[lnindex].nrotation = tnrotation;
		this.aflashtitles[lnindex].cpositionat = tcpositionat;
		this.aflashtitles[lnindex].ccontainer = tccontainer;
		this.aflashtitles[lnindex].ccolor = tccolor;
		this.aflashtitles[lnindex].noffsetx = tnx;
		this.aflashtitles[lnindex].noffsety = tny;
	}
	return false;	
}

cQsHandler.prototype.showFlashTitles = function()
{
	var lni;
	for (lni=0; lni < this.nflashtitles; lni++)
		this.aflashtitles[lni + 1].display();
}
cQsHandler.prototype.addView =  function(tctag, tnviewid, tcdiv, tnpageno)
{
	this.nviews 	+=1;
	this.aviews[this.nviews] = new viewcontroller(tctag, tnviewid, tcdiv, tnpageno);				// Holds current records
}


cQsHandler.prototype.display = function(tctag)
{
	var lnindex = this.getIndex(tctag)
	if (lnindex > 0 ) 
		this.aviews[lnindex].display();
}

cQsHandler.prototype.displayAllViews = function()
{
	var lni, loDiv, lnj, loTds, lcTipId , llF, loTip , lcText;
	
	this.oAppProperties.display();
 	this.displayWrappers();
	this.displayDivPos();
	
	for (lni=1; lni <= this.nviews; lni++)
		this.aviews[lni].display();
	
	// Update all mover lists
	this.refreshMovers()

	if ( !isnull(this.oCurrentTabset) && !isnull(this.oCurrentTabset.oTab.cObjectTagName) && !isnull(this.oCurrentTabset.oTab.cMenuTagName) )
	{
		var loapp = qsHandler.entityGet(this.oCurrentTabset.oTab.cObjectTagName)
		
		if (loapp && this.oCurrentTabset.oTab.cMenuTagName > '')
		{
			loapp.menuSetup(this.oCurrentTabset.oTab.cMenuTagName);
			loapp.bc.oMenu.showMenu();
		}
		else
		{
			if(!isnull(this.oCurrentTabset.oTab.oMenu))
				this.oCurrentTabset.oTab.oMenu.showMenu();
		
		}
	}
	// this.showPopText();							// moved after editahandler.show and now moved AFTER Translation
	//this.translatePage();

	if (qsHandler.oEditHandler)
		qsHandler.oEditHandler.show();

	for (lni=1; lni <= this.nFids; lni++)
	{
		// go through each qsview 
		this.aFids[lni].bindFilters();		// bind udf filters to combos
		this.aFids[lni].hlSearch();		// highlight search icon if full
	}
	
	//this.showPopText();								// Needs to be AFTER qsHandler.oEditHandler.show() since some IDs may not be present yet !;
	
	if (typeof(qsHandler.showFlashTitles))
		setTimeout("try {qsHandler.showFlashTitles();}catch(e){null}", 20);	

	this.updateTxFormats();

	if (this.oUiHandler)
		this.oUiHandler.process();

	
	//this.translatePage();
	//window.setTimeout("qsHandler.translatePage();", 10);
	window.addEvent('domready', function() {qsHandler.translatePage(); qsHandler.showPopText();})
	
	
	loTds = document.getElements('td[qsTip="1"]')

	llF = false;
	if (loTds.length > 0 )
	{
		for (lni=0; lni <loTds.length ; lni++)
		{
			if (loTds[lni].id =='udfflthelp')
			{
				
				var loHelp = $('filterhelp');
				if (loHelp)
				{
					loTds[lni].style.display="block"
					lcText = loHelp.innerHTML;
					lcWidth = "500px"
				}
				else
					lcText =""
			}
			else
			{
				lcText = loTds[lni].getAttribute('qsTipTitle').replace(/\\n/g, "<br />");  // weird bug !!
				lcWidth = "200px"
			}
				
			
			if (!isnull(lcText) && lcText!='')
			{
				if (loTds[lni].getAttribute('txBtip')!='1')
				{
					lcTipId = 'tip' + loTds[lni].getAttribute('qsTipId');
					lcDelay =loTds[lni].getAttribute('qsTipShowDelay')
					if (lcDelay)
						lcDelay = '700';
					
					for (lnj=0; lnj < qsHandler.oTip.length; lnj++)
						if (qsHandler.oTip.item(lnj).tip.getAttribute('tipid')==lcTipId)
						{
							loTip = qsHandler.oTip.item(lnj);
							loTip.attach(loTds[lni]);
							llF	= true;
							break;
						}
						
					if (!llF)
					{
						loTip = new Tips(loTds[lni], {	showDelay: lcDelay, className: 'qsTip'});
						loTip.tip.style.width = lcWidth 
						qsHandler.oTip.add(loTip);
						loTip.tip.setAttribute('tipid', lcTipId);
					}
					$(loTds[lni]).store('tip:text', lcText.replace(/\n/g, "<br />") );
				}
				loTds[lni].setAttribute('txBtip', '1');
			}
			loTip = null
		}
	}
 }

 					

 
cQsHandler.prototype.getViewObject = function()
{
	return this.aviews[this.nviews];
}

cQsHandler.prototype.getIndex = function(tctag)
{
	var lni, lnret;
	lnret = 0;
	for (lni=1 ; lni <= this.nviews; lni++)
	{
		if (this.aviews[lni].ctag == tctag)
		{
			lnret = lni;
		}
	}
	return lnret;
}

cQsHandler.prototype.getFlashIndex = function(tctag, tccontainer)
{
	var lni, lnret;
	lnret = 0;
	for (lni=1 ; lni <= this.nflashtitles; lni++)
	{
		if ((this.aflashtitles[lni].ctag == tctag) && (this.aflashtitles[lni].ccontainer == tccontainer) )
		{
			lnret = lni;
		}
	}
	return lnret;
}

cQsHandler.prototype.getDivPosIndex = function(tctag)
{
	var lni, lnret;
	lnret = 0;

	for (lni=1 ; lni <= this.ndivpos ; lni++)
	{
		if (this.adiv_item[lni] == tctag)
		{
			lnret = lni;
		}
	}
	return lnret;
}

cQsHandler.prototype.getWrapperIndex = function(tcdatatag)
{
	var lni, lnret;
	lnret = 0;

	for (lni=1 ; lni <= this.nwrappers ; lni++)
	{
		if (this.awrapper_data[lni] == tcdatatag)
		{
			lnret = lni;
		}
	}
	return lnret;
}

cQsHandler.prototype.moveLeft = function(tctag)
{
	var lnindex = this.getIndex(tctag);
	if (lnindex > 0 ) 
		this.aviews[lnindex].moveleft();
}

cQsHandler.prototype.moveRight = function(tctag)
{
	var lnindex = this.getIndex(tctag);
	if (lnindex > 0 ) 
		this.aviews[lnindex].moveright();
}


// Create a global view handler for this page

if ((qsHandler == 'undefined') || (qsHandler==null))
	var qsHandler = new cQsHandler();
if ((qs_addhandler == 'undefined') || (qs_addhandler==null))
	var qs_addhandler = new addhandler();

qsHandler.aUrls[0] = window.location.href;



function flashtitle(tctagid, tctitle, tnrotation, tccolor, tccontainer, tcpositionat, tnx, tny)
{
	this.ctag = tctagid;
	this.ctitle = tctitle;
	this.ccontainer = tccontainer;
	this.ccolor = tccolor;
	this.nrotation = tnrotation;
	this.cpositionat = tcpositionat;
	this.noffsetx = tnx;
	this.noffsety = tny;
}

flashtitle.prototype.display = function()
{
	var lcdiv, locontainer, llnew, lnx, lny, lodivtitles;
	lcdiv = this.ctag;

	// Creates a DIV to hold the flash title and positions the DIV 
	// at de position of this.ccontainer. 
	// the DIV is also appended to the this.cContainer so that when the position DIV
	// is remove so is the flash title.

	locontainer = document.getElementById(this.ccontainer);
	lodivtitles= document.getElementById(this.ccontainer);

	if (locontainer != null)
	{
		lodiv = document.getElementById(this.ctag);
		if (lodiv ==null)
		{
			//alert('creating ' + this.ctag + " append to " + this.ccontainer + " and position at " + this.cpositionat);
			llnew 			= true;
			lodiv 			= document.createElement("DIV");
			lodiv.style.display	="inline";
			lodiv.style.position	="absolute";
			lodiv.style.left 	= "0px";
			lodiv.style.top		= "0px";
			lodiv.id 		= this.ctag;
		 	lodivtitles.appendChild(lodiv);
			lodiv.innerHTML = this.addflash(this.ctitle, this.nrotation, '0x' + this.ccolor);
		}
		else
		{
			// lodiv.innerHTML = this.addflash(this.ctitle, this.nrotation, '0x' + this.ccolor);
			//alert('reusing  ' + this.ctag + " in container " + this.ccontainer);
	
			lodiv.style.display	="inline";
			lodiv.style.position	="absolute";
			lodiv.style.left 	= "0px";
			lodiv.style.top		= "0px";
			llnew = false;
		}
		lnx = this.noffsetx;
		lny = this.noffsety;

		if (isnull(lnx))
			lnx = 0 ;
		if (isnull(lny))
			lny = 0 ;

		var loEl = new elUi(this.ctag);
		loEl.position(this.cpositionat, lnx, lny);	
	}
	else
	{
		var loEl = new elUi(this.ctag);
		loEl.hide();
	}
}

flashtitle.prototype.addflash = function(tctext, tnrotation, tccolor)
{
	return qs_AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '550',
		'height', '40',
		'src', '/qsscripts/qs_viewtitle',
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'flashvars', 'text=' + tctext + '&textcolor=' + tccolor + '&rotation=' + tnrotation, 
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'transparent',
		'devicefont', 'false',
		'id', 'giggletitle',
		'bgcolor', '#ffffff',
		'name', 'viewtitle',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', '/qsscripts/qs_viewtitle',
		'salign', ''
		); //end AC code
}

function addhandler()
{
	this.nads = 0;
	this.aadscript = new Array();
	this.aadpos= new Array();
}

addhandler.prototype.addad = function(tcscript, tcpos)
{
	var llfound;
	llfound = false;
	for (lni=1; lni <= this.nads; lni++)
	{
		if (this.aadpos[lni]==tcpos)
			llfound = true;
	}
	if (llfound == false)
	{
		this.nads +=1;
		this.aadscript[this.nads] = tcscript;
		this.aadpos[this.nads] = tcpos; 
	}
}

addhandler.prototype.showads = function()
{
	var lni, lcscript;
	if(detectNavigator()!=2)
	{
		for (lni=1; lni <= this.nads; lni++)
		{
			document.write('<div style="display:none" id="scratchad_' + lni + '">');
			lcscript = this.aadscript[lni];
			pushJavaScriptNoEval(lcscript , 0)
			document.write('</div>');
		}
		for (lni=1; lni <= this.nads; lni++)
		{
			lopos = document.getElementById(this.aadpos[lni]);
			lodata = document.getElementById('scratchad_' + lni );
			if (this.aadscript[lni].toLowerCase().indexOf('<script') > 0 )
				lopos.innerHTML = lodata.innerHTML;
		}
	}
}

function viewcontroller(tctag, tnviewid, tcdiv, tnpageno)
{
	this.ctag	= tctag					// Unique identifier
	this.nviewid 	= tnviewid;				// FID of view
	this.cdiv  	= tcdiv;				// DIV where it lives on screen
	this.npageno	= tnpageno ;					// Current qstream page number
	this.arecs 	= new Array();				// Holds current records
	this.nrecords	= 0;					// Number of records
	this.ncurrentpos= 1;					// Start displaying at
	this.adisplaypos = new Array();
	this.ndisplaypos= 0;
}

viewcontroller.prototype.addrec = function(tnrecid, tcdivid_container)
{
	this.nrecords += 1;		// increase number of documents
	this.arecs[this.nrecords] = new viewrecords(tnrecid, tcdivid_container);
}

viewcontroller.prototype.adddisplaypos = function(tcid)
{
	this.ndisplaypos += 1;		// increase number of documents
	this.adisplaypos[this.ndisplaypos] = new displaypos(tcid);
}

viewcontroller.prototype.moveright = function()
{
	if (this.ncurrentpos == this.nrecords)
		this.ncurrentpos = 1;
	else
		this.ncurrentpos = this.ncurrentpos + 1;
	this.display();
}

viewcontroller.prototype.moveleft = function()
{
	if (this.ncurrentpos == 1)
		this.ncurrentpos = this.nrecords;
	else
		this.ncurrentpos = this.ncurrentpos - 1;
	this.display();
}

viewcontroller.prototype.display = function()
{
	var lni, lcid, lcdiv, lonode, lodiv, lcHtml;

	for (lni = 0 ; lni < this.ndisplaypos; lni++)
	{
		lcid = this.adisplaypos[lni + 1].cid ;
		lonode = document.getElementById(lcid);
		if (lni + this.ncurrentpos <= this.nrecords)
		{			
			lodiv = document.getElementById(this.arecs[lni + this.ncurrentpos].cdivid);
			if (lodiv != null)
				lcHtml = lodiv.innerHTML;
			else
				lcHtml = '';
		}
		else
		{	
			lcHtml = '';
		}
		if (lonode !=null)
			lonode.innerHTML = lcHtml	
	}
}

function viewrecords(tnrecid, tcid)
{
	this.nrecid = tnrecid;
	this.cdivid = tcid;
}

function message_handler()
{
	this.nMessages = 0;
}

function displaypos(tcid)
{
	this.cid = tcid;
}

message_handler.prototype.add = function(tcmessage, tcid)
{
	var lodiv, lospan;

	lodiv = document.getElementById("qs_messagecontainer")
	if (lodiv)
	{
		lospan = document.createElement('span');
		lospan.id = tcid;
		lospan.innerHTML = tcmessage;
		lodiv.appendChild(lospan);
	}
}

message_handler.prototype.get = function(tcid)
{
	var lodiv, lcRet;

	lodiv = document.getElementById(tcid)
	if  (! isnull(lodiv))
	{
		lcRet = lodiv.innerHTML;
	}
	else
	{
		lcRet = "Message is not defined"
	}
	return lcRet
}

function insertTemplate(tctemplateid, tcdataid, tcpositionid)
{
 	var lotemplate, lodata, loposition;

	lotemplate 	= document.getElementById(tctemplateid);
	lodata		= document.getElementById(tcdataid);
 	lopos  		= document.getElementById('pszone_mainarea');
 	lopos  		= document.getElementById(tcpositionid);
	lobin 		= lotemplate.getElementsByTagName('DIV');
	lobin(0).innerHTML = lodata.innerHTML;
  	lopos.innerHTML  = lotemplate.innerHTML;
}

function alertbyid(tcid)
{
	var lomessage
	lomessage = document.getElementById(tcid)

	if(lomessage.innerHTML)
	{
		alert(lomessage.innerHTML)
	}
}

function getElementByTypeAndName(tcName, tcType)
{
    var loElements, lniElements, lcElementName
    var loToReturn
    
    loToReturn = null
    
    loElements = document.getElementsByTagName(tcType)
    
    for(lniElements=0; lniElements < loElements.length; lniElements++)
    {
        lcElementName = loElements[lniElements].getAttribute('name')
        
        if(lcElementName == tcName)
        {
            loToReturn = loElements[lniElements]        
        }
    
    }
    return loToReturn
}

function qs_fn_response()
{
	this.nResult = null;
	this.cerror = "";
}

function qs_delete_record(tctext, tndelfolder, tndelkey, tnretfid, tcdiv, tcfilters)
{
	var lcUrl, loerror, lnret, loresponse, lcxml,  loXmlHttp;
		
	if (confirm(tctext))
	{
		lcUrl = '/rdel.asp?wcx=recorddelete&folderid=' + tndelfolder + '&QSKEYID=' + tndelkey ;
		loXmlHttp = new xmlHttpDom();
		lcxml = loXmlHttp.callUrl('GET', lcUrl);

		//		lcxml = http_execute_url('GET', lcUrl);
		loresponse = new qstreamResponse(lcxml);
		if (loresponse.nResult == 1)
		{
			qsShowMessage('Unable to delete', loresponse.showErrors());
			lnret = 1;
		}
		else
		{
			lnret = 0;
		}
		if (tnretfid > 0 )
		{
			loXmlHttp = new xmlHttpDom();
			loXmlHttp.exec(tcdiv, '/vd.asp?folderid=' + tnretfid + '&USERAW=YES&ADDVIEWDIV=YES',  tnretfid);
			// http_execute(tcdiv, '/vd.asp?folderid=' + tnretfid + '&USERAW=YES&ADDVIEWDIV=YES',  tnretfid);
		}
	}
	else
	{
		lnret = 2;
	}
	return lnret;
}

function detectNavigator()
{
	var lnnavigator
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
	{
		lnnavigator = 1
	}
	else if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{
		lnnavigator = 2
	}
	else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
	{
		lnnavigator = 3
	}
	else
		lnnavigator = 0 
	return lnnavigator
}

var lnthisbrowser = detectNavigator();

function http_execute_protocol(tcprotocol, tcid_destinationdiv, tcUrl, tnFolder)
{
	var lcprotocol
	lcprotocol = window.location.protocol

	if(lcprotocol.indexOf(':')>0)
	{
		tcprotocol += ':'
	}
	if(tcprotocol.toLowerCase() == lcprotocol.toLowerCase())
	{
		var loXmlHttp = new xmlHttpDom();
		loXmlHttp.exec(tcid_destinationdiv, tcUrl, tnFolder);
		// http_execute(tcid_destinationdiv, tcUrl, tnFolder);
	}
	else
	{
		tcUrl =	tcUrl.replace('&amp;', '&');
		tcUrl =	tcUrl.replace('USERAW=YES', 'USERAW=NO');
		tcUrl = tcUrl.replace(lcprotocol, tcprotocol);
		if(!(tcUrl.indexOf('http')>=0))
		{
			tcUrl = tcprotocol + '//' + window.location.hostname + tcUrl
		}
		window.location = tcUrl;
	}
}

function qs_setcombovalue(tcselect, tcvalue)
{
	var looption, loChildOptions;
	var loselect;
	var lniOptions;
	
	loselect = document.getElementById(tcselect);
	
	if (!isnull(loselect))
	{ 
		loChildOptions = loselect.options
		for (lniOptions=0; lniOptions<loChildOptions.length; lniOptions++)
		{
			if(loChildOptions[lniOptions].value == tcvalue)
			{
				looption = loChildOptions[lniOptions];
				loselect.selectedIndex = looption.index
			}
		}
	}
}


qsFilter.prototype.buildFilterLookup = function()
{
	// show autocomplete // comboBox
	
	var lcCode, loDiv;
	// var loInput = $(this.cFullCpName)
	// var loInput = $('vp_' + this.cFullCp)
	var loInput = $(this.cFullCp)
	
	if (loInput)			// input item
	{
		loInput.setAttribute('fltBound', '1');
		
		$(loInput).addEvent('blur', function() 	
		{
			// needed when blur on mouse click (not needed for onkeydown)
			var llRet, loInput, loMView, loTable;
			
			llRet = false;
			
			if (typeof(loAutoCall) !='undefined')
				window.clearTimeout(loAutoCall)
			
			loInput = window.event.srcElement;
			loMView = qsHandler.viewGet(loInput.getAttribute('FID'));
			
			loFilter = loMView.aFilters[loInput.getAttribute('filterIndex')]
			
			// if the selection table is available then get id and text 
			loInput.setAttribute('KID', loFilter.oView.nSelKid);
			loTable = $('table_' + loFilter.oView.nFid);
			
			if (loTable)
				if (!loFilter.oView.nSelKid > 0 )
					loInput.value = '';
				else
					loInput.value =	loTable.getElements('tr[KID='+ loFilter.oView.nSelKid+ ']')[0].firstChild.innerText;
		
		});
		
		$(loInput).addEvent('dblclick', function() 	
		{
			var loInput = window.event.srcElement;
			loInput.value = '';
			qsHandler.viewGet(loInput.getAttribute('FID')).aFilters[loInput.getAttribute('filterIndex')].showList()
		}
		);
			
		$(loInput).addEvent('keydown', function() 	
		{
			var loDiv, lnc, loE, loFilter, loInput, llRet, loTr, loTable, loMView, loCView, llExit;
			
			llExit = false;
			llRet = false;
			loE = window.event;
			
			if(loE && loE.which)
				lnc = loE.which 
			else
				lnc = loE.keyCode 

			loInput = loE.srcElement;
			loMView = qsHandler.viewGet(loInput.getAttribute('FID'));
			
			loFilter = loMView.aFilters[loInput.getAttribute('filterIndex')]
			loCView = qsHandler.viewGet(loFilter.nFid);
			
			loDiv = $(loInput.getAttribute('divWrap'))
			
			if (loDiv && loDiv.style.display!='block')
				loDiv.style.display='block'
				
			switch (lnc)
			{
				case 9:
					// tab out if input field then if not selected then blank
					loTable = $('table_' + loCView.nFid);
					if (loTable)
					{
						if (!loCView.nSelKid > 0 )
							if (loFilter.cType == 'fieldauto')
								loInput.value = '';
						//else
						//	loInput.value =	loTable.getElements('tr[KID='+ loCView.nSelKid+ ']')[0].firstChild.innerText;
					}
						
					llExit = true
					llRet = true;
					
				case 40:
					if (loDiv)
						loFilter.oView.down();
					else
						loFilter.showList();
					
					break;
				
				case 38:
					if (loDiv)
						loFilter.oView.up();

						break;

				case 13:
					if (typeof(loAutoCall) !='undefined')
						window.clearTimeout(loAutoCall)
					
					if (loCView.nSelKid > 0 )
					{
						loTable	= $('table_' + loFilter.nFid)				
						if ($chk(loTable))
							{
							loTr =  loTable.getElement("tr[KID="+loCView.nSelKid+"]")
							loInput.value = loTr.firstChild.innerText;
							if (loFilter.cType == 'fieldauto')
								loInput.setAttribute('KID', loCView.nSelKid);	// add the Key Id as KID attribute on input
							else
							{
								if (!isnull(loCView.cBoundToEntity) && loCView.cBoundToEntity!='')
									qsHandler.entityGet(loCView.cBoundToEntity).showRecordTab(loCView.nSelKid);
								else
									loMView.search();
							}
						}
						else	
							llret = true;
					}
					else
					{
						if (loFilter.cType != 'fieldauto')
							qsHandler.viewGet(loInput.getAttribute('FID')).search();
					}
					if (loDiv)
					{
						loDiv.style.display ="none";
						loDiv.firstChild.innerHTML = ''
					}
					llExit = true;
					llRet = false
					break;
					
				default:
					
					if (lnc > 31)			// if printable chars
					{
						loInput.setAttribute('KID', 0)
						loFilter.showList();
					}
					llRet = true
			}
			
			if (loDiv  && llExit)
			{
				loDiv.style.display ="none";
				loDiv.firstChild.innerHTML = ''
			}

			return llRet;		// llRet means process key press
		});
	}
}

qsFilter.prototype.showList = function()
{
	this.oView.nSelectedTr = -1;
	this.oView.nSelKid = 0 ;
	if (typeof(loAutoCall) !='undefined')
		window.clearTimeout(loAutoCall)


	var lcCode = "var loInput = $('" + this.oInput.id + "'); var loView = qsHandler.viewGet(loInput.getAttribute('FID')); loView.aFilters[loInput.getAttribute('filterIndex')].showAutoComplete(); loView.otr.lClear = false;";	
	loAutoCall = window.setTimeout (lcCode, 250)
}


function qsFilter(toInput, tcFullCpName, tcCrName, tnFid, tcSearchField, tcType)
{
	this.cFullCp = tcFullCpName;
	this.cCrName = tcCrName;
	this.nFid	= tnFid; 		// lookup view UI
	this.cAutoSearchField = tcSearchField;
	if (tcType=='A' || tcType =='a')
		this.cType = 'autocomp';
	else
	if (tcType=='I' || tcType =='i')
			this.cType = 'fieldauto';
	else
		this.cType = 'combo';
	
	this.oInput = toInput;
	
	if (this.nFid > 0 )
		this.oView = qsHandler.viewAdd(this.nFid)
	else
		this.oView = null;
	
}

qsFilter.prototype.showAutoComplete = function()
{
	var lnFid, lcFilter, lcPage, lcId, loDivWrap,  loDiv, lni, toInput, loTrs, lnFound;
	
	toInput = this.oInput
	lnFound = 0;
	
	lcId  = "flt" + this.cFullCp;
	loDivWrap = $(lcId);
	
	if (!$chk(loDivWrap))
	{
		loDivWrap = new Element('div', {    'styles': {   'display':'none', 'position':'relative', 'top':'0px', 'left':'0px' } });
		loDiv   = new Element('div', {    'styles': {   'position':'absolute',  'top':'-2px', 'left': '-7px' } });
		loDivWrap.id = lcId
		loDivWrap.setAttribute("inputId", this.oInput.id)
		this.oInput.setAttribute('divWrap', lcId)
		loDivWrap.appendChild(loDiv);	
		
		this.oInput.parentNode.appendChild(document.createElement("br"));
		this.oInput.parentNode.appendChild(loDivWrap);

		loDiv.addEvent('mouseout', function() 	{ this.parentNode.style.display = 'none'; return false;});
		loDiv.addEvent('mouseover', function() 	{  			
			this.parentNode.style.display = 'block'; 
			return false;});
		//window.addEvent('domready', function() { 	qs_Add_CustomBoxes();		});
	}
	else
		loDiv = loDivWrap.firstChild;
	
	lcFilter = URLEncode(this.oInput.value.replace('=',''));
	if (lcFilter.substr(0,3)!='%25' && lcFilter!='')
		lcFilter = '%25'+lcFilter
	

	this.oView.loadPage(loDiv, 'vp_' + this.cAutoSearchField + '=' + lcFilter);
	this.oView.oTrs = null;
	this.oView.otr.lClear = false;
	var loPage = $('qsfid' + this.nFid);

	if ($chk(loDiv))
	{

		loTrs = $(loDiv).getElements('tr');
		loDiv.getElements('td').addEvent('mouseover', function() 	{  gHl(window.event.srcElement, false) });
		
		loDiv.getElements('tr').addEvent('click', function() 	
		{  
			
			var loDiv = $(lcId);			// get divwrap
			var loInput = $(loDiv.getAttribute('inputId'))
			var loMView = qsHandler.viewGet(loInput.getAttribute('FID'));
			var loFilter = loMView.aFilters[loInput.getAttribute('filterIndex')]
			if (loFilter.cType != 'fieldauto')
				if (!isnull(loFilter.oView.cBoundToEntity) && loFilter.oView.cBoundToEntity!='')
					qsHandler.entityGet(loFilter.oView.cBoundToEntity).showRecordTab(window.event.srcElement.parentNode.getAttribute('KID'));
				else
					loMView.search();
			if (loDiv )
			{
				loDiv.style.display ="none";
				loDiv.firstChild.innerHTML = ''
			}
		
		});
					
		
		for (lni=0; lni< loTrs.length; lni++)
		{
			if (loTrs[lni].getAttribute('KID') > 0 )
			{
				loTrs[lni].setAttribute('divflt', lcId)
				loTrs[lni].style.cursor = 'hand';
				lnFound = lni;
				// loTrs[lni].firstChild.innerHTML = loTrs[lni].firstChild.innerHTML.replace(new RegExp(this.oInput.value, "gi"), '<b>' + this.oInput.value.toUpperCase() + '</b>');
			}
			
		}
		if (lnFound > 0 )
			loTrs[lnFound].parentNode.setAttribute('divflt', lcId)	
		
		
		if (loDivWrap.style.display!='block')
		{
			loDivWrap.style.display='block';
			var myFx = new Fx.Slide('table_' + this.nFid, {duration: 500,   transition: Fx.Transitions.Bounce.easeOut})
			myFx.hide();
			myFx.slideIn('vertical')
		}
		
		qsHandler.translatePage(); 
	}
}

qsFilter.prototype.showCombo = function(toInput)
{
	var loTd, loCombo, loXmlHttp, lcHtml, loInput, lni, lnValue;
	
	if (toInput)
	{
		loTd = toInput.parentNode;
		loXmlHttp = new xmlHttpDom()
		lcHtml = loXmlHttp.callUrl("GET", "/vd.asp?folderid=" + this.nFid + "&USERAW=YES") ;
		lcCombo = '<select class="udf_combobox" name="' + this.cFullCp + '">' + lcHtml + "</select>";
		loTd.innerHTML = lcCombo;
		
		loInput = loTd.firstChild;
		lnValue = toInput.value.replace('=', '');
		for (lni = 1 ; lni <= loInput.length; lni++)
		{
			if (loInput.item(lni-1).value == lnValue)
			{
				loInput.selectedIndex = loInput.item(lni-1).index;
				lni = loInput.length+1;
			}
		}
	}
}



function qsView(tnFid, tcId)
{
	this.nFid = parseInt(tnFid);
	this.lsub = false;
 	this.lhide = true;
 	this.cdiviv = tcId;
	this.otr   = new qs_tr();
	this.oboundEntity = null;
	this.noUdf = 0;
	this.aUdf = new Array();
	this.aUdfFid = new Array();
	this.aUdfId = new Array();
	this.aFilters = new Array();
	this.nFilters = 0 ;
	this.lFilterBound = false;
	this.nSelKid = null;
	this.nSelectedTr = -1;
	this.oTrs = null;
	this.cWidth	= '';
	this.oUi = null;			// holds the UI settings
	
	if (qsHandler.oUiHandler)
		this.oUi = new cUiView(tnFid)

}


function copyElToClip(toElement)
{
	var loTopDiv = document.body;
	var loDiv = new Element('div');
	var loSource;
	
	if (detectNavigator()==1)
	{
		loTopDiv.appendChild(loDiv);
		loDiv.contentEditable = 'true';
		loSource = toElement
		if ($chk(loSource))
		{
			loDiv.innerHTML = loSource.outerHTML;

			var loControlRange;
			if (document.body.createControlRange) {
				loControlRange = document.body.createControlRange();
				loControlRange.addElement(loDiv);
				loControlRange.execCommand('Copy');
			}
			loTopDiv.removeChild(loDiv)
			alert('Copied to clipboard!')
		}
	}
	else
		alert('Copy to clipbaord not supported on this browser')
}

qsView.prototype.copyToClip = function()
{
	var loTopDiv = document.getElementById('qsfid' + this.nFid);
	var loDiv = new Element('div');
	var loSource;
	

	if (detectNavigator()==1)
	{
		loTopDiv.appendChild(loDiv);
		loDiv.contentEditable = 'true';
		loSource = $('table_' + this.nFid)
		if ($chk(loSource))
		{
			loDiv.innerHTML = loSource.outerHTML;
			loCaptions = loDiv.getElements('SPAN[txId^=cap]');
			
			for (lni = loCaptions.length-1 ; lni >=0; lni--)
			{
					loCaptions[lni].parentNode.parentNode.parentNode.parentNode.parentNode.innerHTML = loCaptions[lni].innerHTML;
			}

		
			var loControlRange;
			if (document.body.createControlRange) {
				loControlRange = document.body.createControlRange();
				loControlRange.addElement(loDiv);
				loControlRange.execCommand('Copy');
			}
			loTopDiv.removeChild(loDiv)
			alert('View was copied to clipboard!')
		}
	}
	else
		alert('Copy to clipbaord not supported on this browser')
}

qsView.prototype.down = function()
{
	var loTable;
	if (isnull(this.oTrs))
	{
		loTable = $('table_' + this.nFid)
		if (loTable)
			this.oTrs = loTable.getElements("tr");
	}
	
	if (!isnull(this.oTrs))
	{
		if (this.nSelectedTr < this.oTrs.length-1)
			this.nSelectedTr += 1; 
			
		//alert(this.nSelectedTr )
		if (this.nSelectedTr > -1)
			this.hl(this.oTrs[this.nSelectedTr]);		
	}
}

qsView.prototype.up = function()
{
	if (isnull(this.oTrs))
		this.oTrs = $('table_' + this.nFid).getElements("tr");

	if (this.nSelectedTr > 0)
		this.nSelectedTr -=1; 
	
	if (this.nSelectedTr > -1)
		this.hl(this.oTrs[this.nSelectedTr]);		
			
}


qsView.prototype.hl = function(toTr)
{

	if (toTr)
	{

		this.nSelKid = toTr.getAttribute('KID');
		this.otr.hl(toTr, this.nSelKid);
	}
}

qsView.prototype.bindFilters  = function()
{
	// After display all views we need to bind the filters
	// Only need to do once
	// alert('bind')
	var lni, loInput;

		for (lni=1; lni <= this.nFilters; lni++)
		{
			loInput = this.aFilters[lni].oInput
			
			if (loInput)
			{
				
				if (this.aFilters[lni].cType == 'combo')
				{
					loInput.onmouseover = function anonymous() 
					{
					
						var lnFid, lnValue, loView, lcSearch, lcCode, loDiv;
						loView = qsHandler.viewGet(this.getAttribute("FID"));
						if (loView)
							loView.aFilters[this.getAttribute("filterIndex")].showCombo(this);
					};
				}
				else
				if (loInput && loInput.getAttribute('fltBound') != '1')
					this.aFilters[lni].buildFilterLookup();

				loInput.setAttribute("FID", this.nFid);
				loInput.setAttribute("filterIndex", lni);

			}
	}
}


qsView.prototype.getFilter  = function(tcFullCpName)
{
	var lni, loRet;
	
	for (lni = 1 ; lni <= this.nFilters ; lni++)
	{
		if (this.aFilters[lni].cFullCp == tcFullCpName)
		{
			loRet = this.aFilters[lni];
			lni = this.nFilters;
		}
	}
	return loRet;
}

qsView.prototype.addFilter  = function(tcFullCpName, tcCrName, tnFid, tcFilterField, tcType)
{
	var loInput, loDiv, loFilter;
	
	tcFullCpName=tcFullCpName.substring(0,tcFullCpName.length)
	
	loDiv = $("qsfid" + this.nFid);
	if (loDiv)
	{
		loDiv = $("qsfid" + this.nFid).getElements('input[id=' + tcFullCpName + ']');
	
		if (loDiv)
		{
			if (loDiv.length > 0)
			loInput = loDiv[0]
		else
			loInput = null;

			loFilter = this.getFilter(tcFullCpName);
			if (!$chk(loFilter))
			{
				this.nFilters += 1;
				this.aFilters[this.nFilters] = new qsFilter(loInput, tcFullCpName, tcCrName, tnFid, tcFilterField, tcType);
			}
			else
			{
				loFilter.oInput = loInput;
			}
		}
	}
}

qsView.prototype.getSearchUrl  = function()
{
	var loViewForm, lni, lcUrl;
	loViewForm = document.getElementById('qs_form_' + this.nFid); 
	
	if (loViewForm.action.substring(1,3)=='qs')
		lcUrl = '/vd.asp?' ;
	else
	{
		lcUrl = loViewForm.action;
		lcUrl = lcUrl.substring(0,lcUrl.indexOf('.')) + '.asp?';		
	}
	lcbutton = "btnsearch";
	lctarget = "";

	return lcUrl + this.getSearchItems()
}


qsView.prototype.getSearchItems  = function()
{
	var loViewForm, lni, lcUrl;
	loViewForm = document.getElementById('qs_form_' + this.nFid); 
	
	lcUrl = '';
	
	for (lni=0; lni < loViewForm.length ; lni++)
	{ 	
		if (loViewForm.elements[lni].name == 'WCX')
		{
			if (lcUrl.toUpperCase().substring(1,4) =='LOV')
				lcUrl = lcUrl + loViewForm.elements[lni].name + '=listofvalues&' ;
			else
				lcUrl = lcUrl + loViewForm.elements[lni].name + '=viewdisplay&' ;
		}
		else
			lcUrl = lcUrl + loViewForm.elements[lni].name + '=' + URLEncode(loViewForm.elements[lni].value) + '&' ;
	} 
	lcUrl = lcUrl + 'USERAW=YES';
	
	//loViewForm.action	='/vd.asp';
	//loViewForm.WCX.value	='viewdisplay';
	
	return lcUrl;
}
qsView.prototype.loadPage = function(toDiv, tcFilter)
{
	var loXmlHttp = new xmlHttpDom();
	
	if (!$chk(tcFilter))
		tcFilter = '';
	else
		tcFilter = '&' + tcFilter;
	var lcPage = loXmlHttp.callUrl('GET' , '/vd.asp?wcx=viewdisplay&folderid=' + this.nFid + '&USERAW=YES' + tcFilter )
	
	if ($chk(toDiv))
		toDiv.innerHTML = lcPage;
	
	if (toDiv)
		this.cBoundToEntity = toDiv.firstChild.getAttribute('boundToEntity')
	qs_Add_CustomBoxes();	
}

qsView.prototype.getUdf  = function(tnIndex)
{
	if (tnIndex > 0 )
	{
		lcUrl = this.aUdf[tnIndex] + "&USERAW=YES&ADDVIEWDIV=YES&SETVAR_qsi_udfid=" + this.aUdfId[tnIndex];
		var loXmlHttp = new xmlHttpDom();
		loXmlHttp.exec('qsfid' + this.aUdfFid[tnIndex], lcUrl, this.aUdfFid[tnIndex])
	}
	else
		if (tnIndex == -1)
			this.save();
		else
			if (tnIndex == -2)
				this.showUdfProps();
}

qsView.prototype.save  = function()
{
	var loDiv, loElUi, loXmlHttp, lnFid, lnKey;
	var loUdf = new userDefinedView(this)
	
	lnFid = qsHandler.oFids.getFid('udfSaveProps');
	
	lnKey = loUdf.save()	

	loElUi = new elUi('cmp_qswindow');
	loDiv = document.getElementById('cmp_qswindow');

	if (!isnull(loDiv))
	{
		loDiv.onresize  = function anonymous() {loElUi.centre()};
		loDiv.style.display = "block";
		loXmlHttp = new xmlHttpDom();
		loXmlHttp.exec('cmp_window_content', '/vd.asp?wcx=viewdisplay&folderid=' + lnFid + '&USERAW=YES&ADDVIEWDIV=YES&SETVAR_qsi_udfid=' + lnKey, lnFid)
		loElUi.show();
	}
}

qsView.prototype.showUdfProps = function()
{
	var lnFid = qsHandler.oFids.getFid('udfAllProps');
	loElUi = new elUi('cmp_qswindow');
	loDiv = document.getElementById('cmp_qswindow');

	if (!isnull(loDiv))
	{
	
		loDiv.onresize  = function anonymous() {loElUi.centre()};
		loDiv.style.display = "block";
		
		loXmlHttp = new xmlHttpDom();
		loXmlHttp.exec('cmp_window_content', '/vd.asp?wcx=viewdisplay&folderid=' + lnFid + '&USERAW=YES&ADDVIEWDIV=YES&SETVAR_qsi_fnseq=' + this.nFid, lnFid)
		loElUi.show();
	}
}



qsView.prototype.showViewCombo  = function()
{
	var loUdf = new userDefinedView(this)
	loUdf.showViewCombo()	
}

qsView.prototype.search  = function()
{
	var loXmlHttp = new xmlHttpDom();
	loXmlHttp.exec("qsfid" + this.nFid, this.getSearchUrl(), this.nFid);
	qs_Add_CustomBoxes();
}




qsView.prototype.toggleSize  = function(tcMode)
{
	//var lcContentDiv = 'qscnt' + this.nFid
	var loDiv = $('qsbound' + this.nFid)
	if (loDiv)
	{
		event.cancelBubble =true;
		if (loDiv.width=='')
			loDiv.width='100%';
		else
			loDiv.width='';
	}
}
qsView.prototype.sort = function(tcField, tcOrder)
{
	var loXmlHttp  = new xmlHttpDom()
	var lcOrder;
	if (tcOrder =='A')
		lcOrder = "ASCENDING";
	else
		lcOrder = "DESCENDING";
	
	loXmlHttp.exec('qsfid' + this.nFid , "/vd.asp?FOLDERID=" + this.nFid + "&VIEWORDERBY=" + tcField + "&VIEWORDERTYPE=" + lcOrder + "&USERAW=YES&ADDVIEWDIV=YES", this.nFid)
}


qsView.prototype.bindToEntity = function(tctag)
{
	this.oboundEntity = qsHandler.entityGet(tctag)
}


qsView.prototype.showThisRecord = function(tctag, tnkid, tcViewTag)
{


	// tcViewTag is the optional tag name save / view defined in genxsl 
	
	this.bindToEntity(tctag)		// bind entity with tag name to this view object
	if (this.oboundEntity)			// if there is an application tctag
	{
		// view the record tab of the bound application using PKID selected
		if (typeof(this.oboundEntity.showRecordTab)=='function')
			this.oboundEntity.showRecordTab(tnkid, null, tcViewTag);
		else
			if (typeof(this.oboundEntity.bc.showRecordTab)=='function')
				this.oboundEntity.bc.showRecordTab(tnkid);
	}
}

qsView.prototype.clearFilters = function()
{
	var loForm, lni, loInputs;
	
	loForm= document.getElementById("qs_form_" + this.nFid);
	if (loForm)
	{
		loInputs = document.getElementsByTagName("input");
		for (lni = 0 ; lni < loInputs.length ; lni++)
			if (loInputs.item(lni).id.substring(0,3) == 'vp_')
				 loInputs.item(lni).value = ''
		loInputs = document.getElementsByTagName("select");
		for (lni = 0 ; lni < loInputs.length ; lni++)
			if (loInputs.item(lni).name.substring(0,3) == 'vp_')
				 loInputs.item(lni).value = ''
	}
}

qsView.prototype.hlSearch = function()
{
	var llRet = false;
	var loForm, lni, loInputs, loImg, lnValue;
	
	loForm = document.getElementById("qs_form_" + this.nFid);
	
	if (loForm)
	{
		
		loInputs = loForm.getElementsByTagName("input");
		for (lni = 0 ; lni < loInputs.length ; lni++)
			if (loInputs.item(lni).id.substring(0,3) == 'vp_' &&  trim(loInputs.item(lni).value.replace(/=/g,'')) != '')
			{
				llRet = true;
				lni = loInputs.length  + 1;
			}
		if (!llRet)
		{
			loInputs = loForm.getElementsByTagName("select");
			for (lni = 0 ; lni < loInputs.length ; lni++)
			{
				lnValue = parseFloat(trim(loInputs.item(lni).value.replace(/=/g,'')));
				if (loInputs.item(lni).name.substring(0,3) == 'vp_' && lnValue > 0)
				{
					llRet = true;
					lni = loInputs.length  + 1;
				}
			}
		}
		loImg = document.getElementById("sgif" + this.nFid);
		if (loImg)
			if (llRet)
				loImg.src = "/bmp/toolbar/searchgreen.gif"
			else
				loImg.src = "/bmp/toolbar/search.gif"
	}
}



qsView.prototype.toggleHide = function()
{
	var lodiv = document.getElementById('udfsave_'+ this.nFid)
	lodiv.style.display="inline";
	var lodiv = document.getElementById('udflist_'+ this.nFid)
	lodiv.style.display="inline";
	var lodiv = document.getElementById('udfclear_'+ this.nFid)
	lodiv.style.display="inline";
	
	var lodiv = document.getElementById('cfilters_'+ this.nFid)
	if (lodiv)
	{
		if (lodiv.style.display=='none')
		{
			lodiv.style.display ="inline";
			this.showViewCombo();
			var lodiv = document.getElementById('udf_'+ this.nFid)
			lodiv.style.display="inline";
		}
		else
		{
			lodiv.style.display ="none";
		}
	}
	return true;
}

userDefinedView = function(toView)
{
	this.oView = toView;
}

userDefinedView.prototype.save = function()
{
	var loXmlHttp = new xmlHttpDom();
	var lcAsp = qsHandler.oFids.getFid('UdfSaveAsp');
	lcAsp = lcAsp + '?' + this.oView.getSearchItems();
	
	loXmlHttp.callUrl("GET", lcAsp);
	if (!loXmlHttp.callFailed())
		lnKey = loXmlHttp.oResponse.getAttribute('qskeyid');
	else
		lnKey = 0 
	return lnKey;
}

userDefinedView.prototype.showViewCombo = function()
{
	var loTd, loButton;
	loTd = $('udf_' + this.oView.nFid);
	if (loTd)
	{
		loTd.innerHTML = '<button class="udf_button">UDF</button>'
		loTd.setAttribute('fid', this.oView.nFid);
		loButton = $(loTd.firstChild);
		loButton.addEvent('click', function () {var loView = qsHandler.viewGet(this.parentNode.getAttribute('fid')); var loUdf = new userDefinedView(loView); loUdf.buildViewCombo()	})
	}
}


userDefinedView.prototype.buildViewCombo = function()
{
	// get combo and add it to a tag.
	var loXmlHttp = new xmlHttpDom();
	var lnView  = qsHandler.oFids.getFid('udfViewCombo');
	loXmlHttp.exec('udf_' + this.oView.nFid, "/vd.asp?wcx=viewdisplay&folderid=" + lnView + "&ADDVIEWDIV=YES&USERAW=YES&SETVAR_qsi_fnseq=" + this.oView.nFid, lnView);
	return true;
}


function qs_tr()
{
	this.cColor 	="";
	this.cBgColor	="";
	this.cSaveColor	="";
	this.cSaveBgColor="";
	this.olasttr = null;
	this.nkeyid  = 0;
	this.cSetColor = null;
	this.lClear = true;
}

qs_tr.prototype.clearLast = function()
{	
	if (this.olasttr)
	{
		this.olasttr.style.color = this.cSaveColor;
		
		if (this.olasttr.style.backgroundColor == this.cSetColor )
		{
			
			this.olasttr.style.backgroundColor = this.cSaveBgColor;
		}
		this.olasttr.lhighlight = false;
	}
}

qs_tr.prototype.hl= function(totr, tnkeyid)
{	
	this.nkeyid = parseInt(tnkeyid);	
	
	this.clearLast()

	this.cSaveColor		= totr.style.color;
	this.cSaveBgColor	= totr.style.backgroundColor;
	totr.style.color 	= "#222222";
	totr.style.backgroundColor = "#ddeeff";
	this.cSetColor = totr.style.backgroundColor ;
	goLastTr = this;
	this.olasttr = totr;
	
	if (this.lClear)
	{
		if (typeof(loLastTimeout) !='undefined')
				window.clearTimeout(loLastTimeout)
		loLastTimeout = window.setTimeout(function  () {clearTrHl()}, 500)
	}
}
function clearTrHl()
{
	goLastTr.clearLast();
}
function setformaction(tnfolder, tcaction, tctarget) 
{ 
	var loviewform, lobutton ; 
	// submit excel and other buttons
	loviewform = document.getElementById('qs_form_' + tnfolder); 
	if (loviewform)
	{
		lobutton = document.getElementById('btnview_' + tnfolder);

		if (isnull(lobutton))
		{
			lobutton = document.createElement("input");
			lobutton.type="hidden";
			lobutton.value = tcaction;
			loviewform .appendChild(lobutton);
		}
		if (lobutton)
		{
			if (tctarget)
				loviewform.target = tctarget;

			lobutton.name = tcaction;
			loviewform.action="/qs.asp";
			loviewform.WCX.value="recordsrvrcvdata";
			loviewform.FOLDERID.value= tnfolder;
		}	
	}
	return loviewform;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// XMLDOC generic qstream xml DOM
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function xmlDOC()
{
	var loDom = new xmlHttpDom();
	this.oDom = loDom;
	this.nAgent = detectNavigator();
	this.oXmlDoc = null;
}

xmlDOC.prototype.load = function(tnFid, tcVars, tlAsync)
{
	// changed from GET to POST
	// mv 2009.11.22 fixed long label translate
	
	if (typeof(tlAsync)=='undefined')
		tlAsync = false;

	var lcUrl = "/sx.asp";
	
	if (typeof(tcVars)=='string')
		tcVars = "folderid=" + tnFid + "&" + tcVars;
	else
		tcVars = "folderid=" + tnFid + "&" + tcVars;
		
	return this.getdata(lcUrl, tlAsync, tcVars, 'POST')
		
	//return this.loadByPost(tnFid, tcFilter, tlAsync)
	//	var lcUrl = "/sx.asp?folderid=" + tnFid ;
	//	if (typeof(tcFilter)=='string')
	//		lcUrl = lcUrl + '&' + tcFilter
	//	return this.getdata(lcUrl)
}

xmlDOC.prototype.getViewXml = function(tnFid, tlAsync)
{
	var lcUrl = "/sx.asp?folderid=" + tnFid ;

	if (typeof(tlAsync)=='undefined')
		tlAsync = false;
		
	this.getdata(lcUrl, tlAsync)
}

xmlDOC.prototype.getMaxValue = function(toNodes, tcField)
{
	return this.getMinMaxValue(toNodes, tcField, 1)
}

xmlDOC.prototype.getMinValue = function(toNodes, tcField)
{
	return this.getMinMaxValue(toNodes, tcField, 2)
}

xmlDOC.prototype.getMinMaxValue = function(toNodes, tcField, tnType)
{
	var lni, lcAux;
	
	lcAux = this.getAttribute(toNodes.item(0), tcField);
	
	for (lni=0; lni < toNodes.length; lni++)
	{		
		if ((this.getAttribute(toNodes.item(lni), tcField) > lcAux && tnType == 1) || (this.getAttribute(toNodes.item(lni), tcField) < lcAux && tnType == 2)) 
			lcAux = this.getAttribute(toNodes.item(lni), tcField);
	}
	return lcAux;
}	


xmlDOC.prototype.getdata = function(tcUrl, tlAsync, tcVars, tcVerb)
{

	if (typeof(tcVerb)!='string')
		tcVerb = 'GET';
		
	if (typeof(tcVars)!='string')
		tcVars = null;
		
	if (typeof(tlAsync)=='undefined')
		tlAsync = false;
	if ((tcUrl.indexOf('http://')==-1 ) &&  (tcUrl.indexOf('https://')==-1 ))
	{
		tcUrl = document.location.protocol + '//' + document.domain + tcUrl ;
	}

	this.oDom.open(tcVerb, tcUrl, tlAsync);
	if (tcVerb =='POST')
		this.oDom.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	else
		this.oDom.setRequestHeader("Content-Type", "text/xml");
	
	this.oDom.send(tcVars);
	this.oXmlDoc = this.oDom.oXmlHttp.responseXML; 	// this needs to be looked into // will it work with FF ???
	this.oXmlDoc.async = false;
	
	if (this.nAgent==1)
		this.oXmlDoc.setProperty("SelectionNamespaces", "xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882' xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema' ")
	
	return true;
}

xmlDOC.prototype.getLength = function (tcSelect)
{
	var loNodes;
	loNodes = this.oXmlDoc.selectNodes(tcSelect);
	
	return loNodes.length;
}

xmlDOC.prototype.createDocument = function(tcRootElement, tcNS)
{

	var loDocument, loRoot, lcDocumentType;

	tcNS = tcNS || '';
	lcDocumentType = null;
	if (this.nAgent==1)
	{
		loDocument = new ActiveXObject('Microsoft.XMLDOM');
		loRoot = loDocument.createNode(1, tcRootElement, tcNS);
		loDocument.appendChild(loRoot);
	}
	else
	{
		loDocument = document.implementation.createDocument(tcNS,  tcRootElement, lcDocumentType)
	}
	this.oXmlDoc = loDocument;
	this.oXmlDoc.async = false;
}

xmlDOC.prototype.getXml = function()
{
	var lcXml;
	if (this.nAgent==1)
		lcXml = this.oXmlDoc.xml;
	else
		lcXml = new XMLSerializer().serializeToString(this.oXmlDoc);
	return lcXml;
}

xmlDOC.prototype.createNode = function(tcTagName, tcNS)
{
	
	// if (typeof ownerDocument.createElementNS != 'undefined') {

	var loNode;
	if (this.nAgent==1)
		loNode = this.oXmlDoc.createNode(1, tcTagName, tcNS);
	else
	{
		loNode = this.oXmlDoc.createElementNS(tcNS, tcTagName);
	}
	return loNode
}

xmlDOC.prototype.getAttribute = function(toNode, tcAttribute)
{
	toNode.getAttribute(tcAttribute)
}

xmlDOC.prototype.setAttribute = function(toNode, tcAttribute, tcValue)
{
	toNode.setAttribute(tcAttribute, tcValue)
}

xmlDOC.prototype.appendChildToRoot = function(loNodePackage)
{
	this.oXmlDoc.appendChild(loNodePackage)
}

xmlDOC.prototype.appendChild = function(loNodePackage, toParent)
{
	toParent.appendChild(loNodePackage)
}


xmlDOC.prototype.loadXML = function (tcXml)
{

	if (this.nAgent==1)
	{
		this.oXmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		this.oXmlDoc.async=false;
		this.oXmlDoc.loadXML(tcXml)
	}
	else
	{
	  try //Firefox, Mozilla, Opera, etc.
	  {
		var oParser = new DOMParser();
		this.oXmlDoc = oParser.parseFromString(tcXml,"text/xml");
	    //this.oXmlDoc = document.implementation.createDocument("","",null);
		//this.oXmlDoc.loadXML(tcXml)
	  }
	  catch(e)
	  {
	   	alert(e.message);
		return;
	   }
	}
	
	return true;
}

function objCollection()
{
	this.length = 0 ;
	this.aNodes = new Array();
}
objCollection.prototype.add = function(toValue)
{
	this.aNodes[this.length] = toValue;
	this.length = this.length + 1
}

objCollection.prototype.item = function(tnIndex)
{
	return this.aNodes[tnIndex];
}

function mozNode(toNode)
{
	this.oNode = toNode;
}
mozNode.prototype.getAttribute = function(tcAttribute)
{
	var lcRet, loItem;
	loItem = this.oNode.attributes.getNamedItem(tcAttribute);
	if (loItem)
		lcRet = this.oNode.attributes.getNamedItem(tcAttribute).value
	else
		lcRet = null;
	
	return lcRet
}

xmlDOC.prototype.selectNodes = function(tcselect)
{
	var loNodes, lnsResolver, lni, loMozNode;

	if (this.nAgent == 1)
	{
		var loResult
		loResult = this.oXmlDoc.selectNodes(tcselect);
	}
	else	
	{
		lnsResolver = this.oXmlDoc.createNSResolver( this.oXmlDoc.ownerDocument == null ? this.oXmlDoc.documentElement : this.oXmlDoc.ownerDocument.documentElement);
		loNodes = this.oXmlDoc.evaluate(tcselect, this.oXmlDoc, lnsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
	// loNodes[0].attributes.getNamedItem('errors').value
		var loResult = new objCollection();
		for( var lni = 0; lni < loNodes.snapshotLength; lni++)     
		{    
			loMozNode = new mozNode(loNodes.snapshotItem(lni))
			loResult.add(loMozNode);     
		}	     
    
	}
	return loResult;
}

xmlDOC.prototype.getAttribute = function(toitem, tcfield)
{
	var luret;

	try
	{
		luret = toitem.getAttribute(this.getFieldFromName(tcfield));
	}
	catch(e)
	{
		luret = null;
	}
	return luret;
}

xmlDOC.prototype.getFieldFromName = function(tcfield)
{
	var loNodes, lcRet;
	loNodes = this.selectNodes("//xml/s:Schema/s:ElementType/s:AttributeType[@rs:name= '" + tcfield + "']")
	if (loNodes.length > 0 )
	{
		lcRet = loNodes.item(0).getAttribute('name');
	}
	else
	{
		lcRet = tcfield;
	}
	return lcRet;
}

function gen_getFID(toNode)
{
	var lnFid;
	var loNode = gen_getTable(toNode)
	if (loNode)
		lnFid = loNode.getAttribute("QSFID")
	else	
		lnFid = null
	return lnFid;
}

function gen_getTable(toNode)
{
	var lnFid;
	var loNode = toNode.parentNode;
	if (loNode)
 	{
 		if (loNode.tagName == 'TABLE')
		{
			if (loNode.getAttribute("qsclass") == 'qsBoundTable')
				lnNode = loNode;
			else
				loNode = gen_getTable(loNode)
		}
		else
 			loNode = gen_getTable(loNode)
 	}
 	else
 		loNode = 0 ;
 	
 	return loNode;
}


function gHl(toevent)
{
	var lotr, lotable, lnFid, loview, lnkeyid;
	try 
	{
		if (toevent.tagName =='TR')
			lotr = toevent;
		else
			lotr = toevent.parentNode;
			if (lotr.tagName !='TR')
				lotr = lotr.parentNode;
			if (lotr.tagName !='TR')
				lotr = lotr.parentNode;
		lotable = gen_getTable(lotr);
		if (lotable)
		{
			//lnkeyid 	= parseFloat(lotr.getAttribute("KID"));
			lnFid 		= lotable.getAttribute("QSFID")
			loview 		= qsHandler.viewGet(lnFid);
			
			if (loview)
			{
				loview.hl(lotr);
			}
		}
	}
	catch(e)
	{
		null;
	}
}

function gCl(toevent)
{

	var lotr, lotable, lnFid, loview, lcentitytag, lnkid, lnEditFID, lcVar, lcViewTag;
	var llOk;

	if (toevent.tagName =='TR')
		lotr = toevent;
	else
		lotr = toevent.parentNode;
		if (lotr.tagName !='TR')
			lotr = lotr.parentNode;
		if (lotr.tagName !='TR')
			lotr = lotr.parentNode;
	lotable = gen_getTable(lotr);
	
	llOk = true;
	if (typeof(event)!='undefined')
		if (event.shiftKey)
			llOk = false;
			
			
	if (lotable && llOk)
	{		
		lnFid 		= lotable.getAttribute("QSFID")
		lnEditFID	= lotable.getAttribute("QSEDITFID")
		lnkid		= lotr.getAttribute("KID")
		lcVar 		= lotable.getAttribute("QSKIDVAR")
		lcentitytag = lotable.getAttribute("boundToEntity")
		lcViewTag 	= lotable.getAttribute("viewtag")
		loview 		= qsHandler.viewGet(lnFid);
		loview.nSelectedTr = -1;
		// If edit is defined use it ,  otehrwise show associated TAB SET

		
		if (lnEditFID > 0 )
		{
			if (lcentitytag!='')
			{
				// if button is selected AND there is a bound to data object then button has precedence but a loaddata is done
				var loEntity = qsHandler.entityGet(lcentitytag)
				if (loEntity && typeof(loEntity.loadData)=='function')
				{
					loEntity.loadData(lnkid);
					loEntity.bc.nBackToListFid = lnFid;		// set return fid
					if (qsHandler.oCurrentTabset && qsHandler.oCurrentTabset.oTab.oMenu) 
						qsHandler.oCurrentTabset.oTab.oMenu.refresh();
				}
					
			}

			var loXmlHttp = new xmlHttpDom();
			loXmlHttp.exec('qsfid' + lnFid , '/vd.asp?ADDVIEWDIV=YES&USERAW=YES&FOLDERID=' + lnEditFID + "&SETVAR_" + lcVar + "=" + lnkid, lnEditFID);		
		}
		else
		{
			if (typeof(loview.showThisRecord)=='function')
				loview.showThisRecord(lcentitytag, lnkid, lcViewTag);		
		}
			
	}
}

function getUrlVars()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

function QS_showHideLayer(tcLayer,tcDummy,tcAction, tlcenter) { 
	var loLayer, lcDisplay
	try
	{
		loLayer = document.getElementById(tcLayer)
		if (tcAction=='show')
		{
			lcDisplay ='inline';
		}
		else
		{
			lcDisplay ='none';
		}	
		//loLayer.style.visibility = (lcAction=='show')?'visible':'hide';
	}
	catch(e)
	{
		null;
	}
	if (loLayer != null)
	  loLayer.style.display = lcDisplay;	
	if (!isnull(tlcenter))
	{
		var loEl = new elUi(tcLayer)
		loEl.centre();
		//DIV_centre(tcLayer)
	}
}


function viewOrder(toElement, tcOrder)
{
	// used by genxsl
	var lnFid, lcField, loView;
	lnFid = toElement.getAttribute('FID');
	lcField  = toElement.getAttribute('fieldname');
	
	lcField = lcField.substring(1,lcField.length);		// remove the '@' field this was needed because of import export PID translation
	loView = new qsView(lnFid)
	loView.sort(lcField, tcOrder)
	event.cancelBubble = true;
}

function viewBarButtonClick(toElement, tcMode)
{
	// used by genxsl
	
	var lnFid, loXmlHttp, lcUrl, lcVar, lcDiv, loEntity ;
	lnFid = toElement.getAttribute('FID');
	lcDiv = toElement.getAttribute('divpos');
	loXmlHttp = new xmlHttpDom()
	lcUrl = "/vd.asp?FOLDERID=" + lnFid + "&WCX=viewdisplay&ADDVIEWDIV=YES&USERAW=YES" 
	loEntity = qsHandler.entityGet(toElement.getAttribute('dataentity'));
	
	if (tcMode =='new')
	{
		lcVar = toElement.getAttribute('varname');
		lcUrl = "/vd.asp?FOLDERID=" + lnFid + "&WCX=viewdisplay&ADDVIEWDIV=YES&USERAW=YES&SETVAR_" + lcVar  + "=0";
	}
	if (tcMode =='back')
	{
		if (loEntity)
		{
			// if I have a data object bound then I invoke the backToList method zzz, this is set in gCl.  if not defined then called lnFid
			loEntity.bc.backToList(lnFid, lcDiv)
			lcUrl = null;
		}
		if ($chk(lcDiv))
			$('cmp_qswindow').style.display="none";
	}
	
	if (lcUrl)
		loXmlHttp.exec(lcDiv , lcUrl, lnFid)
}


function flushCache(tnFid, tnType, tnTag)
{
var lcUrl;

lcUrl = null;

if (tnFid > 0 )
	var lcurl = "/qs.asp?WCX=FLUSHCACHE&FOLDERID=" + tnFid ;

if (tnType > 0 )
	var lcurl = lcUrl + "&TYPE=" + tnType;

if (tnTag> 0 )
	var lcurl = lcUrl + "&TAG=" + tnTag

if (!isnull(lcUrl))
{
	var loHttp = new xmlHttpDom();
	loHttp.callUrlAsync(GET, lcUrl);
}
}

function fidsContainer()
{
	this.nOption = 0 ;
	this.aFidTag = new Array();
	this.aFidId = new Array();
}

fidsContainer.prototype.setFid  = function(tcTag, tnFid)
{
	var lni;
	var lnFind = this.getFid(tcTag)
	if (lnFind == 0)
	{
		this.nOption = this.nOption + 1 ;
		this.aFidTag[this.nOption] = tcTag ;
		this.aFidId[this.nOption] = tnFid ;
	}
	else
	{
		for (lni = 1 ; lni <= this.nOption; lni++)
		{
			if (this.aFidTag[lni] == tcTag)
				this.aFidId[lni] = tnFid;
		}
	}
}

fidsContainer.prototype.getModeFromFid = function(tnFid)
{
	var lni = 0 ;
	var lcRet = 'xxx' ;
	for (lni = 1 ; lni <= this.nOption; lni++)
	{
		if (this.aFidId[lni] == tnFid)
			lcRet   = this.aFidTag[lni];
	}
	return lcRet  ;
}

fidsContainer.prototype.getFid = function(tcTag)
{
	var lni = 0 ;
	var lnRet = 0 ;
	for (lni = 1 ; lni <= this.nOption; lni++)
	{
		if (this.aFidTag[lni] == tcTag)
			lnRet  = this.aFidId[lni];
	}
	return lnRet ;
}


function qsNumber(tnNumber)
{
	this.nNumber = tnNumber;
}

qsNumber.prototype.value = function()
{
	return this.nNumber;
}
qsNumber.prototype.formatNumber = function()
{
	var x, rgx, x1, x2;
	
	if (this.nNumber > 0 )
	{
		var lnNumber = this.nNumber.toFixed(2)
		lnNumber  += '';
		x = lnNumber.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		
		rgx = /(\d+)(\d{3})/;

		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return (x1 + x2);
	}
	else
		return ('0.00')
}
function http_navigate(tcprotocol, tcUrl)
{
	var lcUrl;
	lcUrl = tcUrl.replace(/&amp;/g, '&');

	if (location.protocol == tcprotocol && 1==2)
		lcUrl = location.protocol + '://' + window.location.hostname + lcUrl ;
	else
		lcUrl = tcprotocol + '://' + window.location.hostname + lcUrl;

	try
	{
 		window.location.href = lcUrl;	
	}
	catch(e)
	{
		null
	}
}

function swapHttpSecure(tlSecure)
{
var lcUrl;
if (isnull(tlSecure))
	tlSecure = true;
	
lcUrl = window.location.pathname + window.location.search 
if (tlSecure)
	http_navigate('https:', tcUrl)
else
	http_navigate('http:', lcUrl)

}


function getVarValue(tcVarName)
{
var lcRet
lcRet = null;
if (!isnull(tcVarName))
{
// the get it from getvarvalue
var loHttp, loResponse, lcXml;
loHttp = new xmlHttpDom();
lcXml = loHttp.callUrl('GET', "/getvar.asp?varname=" + tcVarName)
loResponse = new qstreamResponse(lcXml);
lcRet = loResponse.getAttribute(tcVarName)
}
return lcRet;
}



function newPopWindow()
{
	this.oDiv = $('cmp_qswindow');
	this.oDiv.addEvent('resize', function anonymous() { new elUi(this.id); loElUi.centre()});
	this.oDiv.style.display = "block";
	this.cContentDiv = 'cmp_window_content';
	$(this.oDiv.firstChild.firstChild.firstChild.firstChild).addEvent('mousedown', function () { 
		if (typeof(loWindowDrag)=='undefined') {	
			loWindowDrag = $('cmp_qswindow').makeDraggable(); 
		}
		else 		
			loWindowDrag.attach();
	});	
	$(this.oDiv.firstChild.firstChild.firstChild.firstChild).addEvent('mouseup', function () { 	if (typeof(loWindowDrag)!='undefined') loWindowDrag.detach();	});

	if (this.oDiv.getAttribute('txB')!='1')
	{
		loFooter = $('cmp_window_footer');
		loWindowResize = $('cmp_window_resize').makeResizable({handle:loFooter, onComplete:function(){		var loWindow = $('cmp_window_resize');  
			if (loWindow.style.width!='')
			{
				var lnWidth = parseFloat(loWindow.style.width) - 2
				$('cmp_window_content').style.width = parseFloat(loWindow.style.width) - 2;
				$('cmp_window_content').style.height = parseFloat(loWindow.style.height) - 24;
			}
		}}); 
		this.oDiv.setAttribute('txB', '1')
	}
}
newPopWindow.prototype.show = function()
{
	var loEl = new elUi(this.oDiv.id);
	loEl.show()
	loEl.centre();
	
}

function qsDateFormat(tcValue, tnType)
{
	this.value = tcValue.replace(/\x2E/g , '-'); // remove .
	this.value = this.value.replace(/\x3A/g , ''); // remove :
	this.dDate = new Date();
	this.nType = tnType; // 1 date time 2 date
}

qsDateFormat.prototype.getItem = function(tnItem, tcValue)
{
	var lcStr, lni, lcValue, lnPos ;
	lcStr = tcValue;
		
	if (tcValue.count('-') >= tnItem)
	{
		for (lni = 0; lni < tnItem; lni++)
		{
			lnPos = lcStr.indexOf('-');
			lcValue = lcStr.substring(0, lnPos);
			if (lcValue != '')
				lcValue = lcValue.padL('0',2);
			lcStr = lcStr.substring(lnPos+1, lcStr.length  );
		}
	}
	else	
		lcValue = ''
	
	
	if (lcValue == '')
	{
		switch (tnItem)
		{
			case 1: 
				lcValue = (this.dDate.getYear() + '') // year
				break;
			
			case 2: 
				lcValue = (this.dDate.getMonth() + 1 + '').padL('0', 2) // month
				break;
				
			
			case 3: 
				lcValue = (this.dDate.getDay() + 1 + '').padL('0', 2) // day
				break;
			
			case 4: 
				lcValue = (this.dDate.getHours() + '').padL('0', 2) // month// hours
				break;
			
			case 5: 
				lcValue = (this.dDate.getMinutes() + '').padL('0', 2) // mns
				break;
			
			case 6: 
				lcValue = '00';
				break;
		}
	}
	return lcValue;
}

qsDateFormat.prototype.formatDate = function()
{
	var lcDate, lnPos, lcTime, lcHours, lcMns, lcSecs, lcRet;
	
	lnPos = this.value.indexOf(' ');
	if (lnPos  > -1 )
	{
		lcTime = this.value.substring(lnPos + 1, this.value.length).replace(/ /g, '');
		lcDate = this.value.substring(0, lnPos) 
	}
	else
	{
		lcTime = '';
		lcDate = this.value
	}
	
	if (lcDate.count('-')==0)
		lcDate = '--' + lcDate + '-'
	else
		if (lcDate.count('-')==1)
			lcDate = '-' + lcDate + '-'
		else
			lcDate = lcDate + '-'

	lcHours = lcTime.substring(0,2).padL('0',2)
	lcMns = lcTime.substring(2,4).padL('0',2)
	lcSecs =  lcTime.substring(4,6).padL('0',2)
	if (lcHours < '00' || lcHours > '23')
		lcHours = '00';
		
	if (lcMns < '00' || lcMns > '59')
		lcMns = '00';
		
	if (lcSecs < '00' || lcSecs > '59')
		lcSecs = '00';
	if (this.nType == 2)
		lcRet = this.getItem(1, lcDate) + '.' + this.getItem(2, lcDate) + '.' + this.getItem(3, lcDate);
	else
		lcRet = this.getItem(1, lcDate) + '.' + this.getItem(2, lcDate) + '.' + this.getItem(3, lcDate) + ' ' + lcHours + ':'+ lcMns + ':'+ lcSecs;	
		
	return lcRet;
	
}


cQsHandler.prototype.updateTxFormats = function()
{
	var loDates, lcYear, lcMonth, lcDay, lcHour, lcMinute, lcSec, lni, lcFormat;
	
	loDates = document.getElements('TD[qsFormat^=date]');
	
	for (lni=0; lni < loDates.length; lni++)
	{
	
		lcFormat = loDates[lni].getAttribute('qsFormat').replace('date', '');
		if (!isnull(lcFormat) && lcFormat !='')
		{
	
			lcDate = loDates[lni].innerText;
			loDates[lni].setAttribute('txRaw', lcDate);
			
			lcYear 	= lcDate.substr(0,4);
			lcMonth = lcDate.substr(5,2);
			lcDay 	= lcDate.substr(8,2);
			lcHour	= lcDate.substr(1,2);
			lcMinute= lcDate.substr(14,2);
			lcSec 	= lcDate.substr(17,2);
			
			if (lcFormat.indexOf('yyyy') > -1)
				lcFormat = lcFormat.replace('yyyy', lcYear);
			else
				if (lcFormat.indexOf('yy') > -1)
					lcFormat = lcFormat.replace('yy', lcYear.substring(2,4));
			
			if (lcFormat.indexOf('MMM') > -1)
			{
				switch(lcMonth)
				{
					case  '01':
						lcMonth = 'JAN';
						break;
					case  '02':
						lcMonth = 'FEB';
						break;
					case  '03':
						lcMonth = 'MAR';
						break;
					case  '04':
						lcMonth = 'APR';
						break;
					case  '05':
						lcMonth = 'MAY';
						break;
					case  '06':
						lcMonth = 'JUN';
						break;
					case  '07':
						lcMonth = 'JUL';
						break;
					case  '08':
						lcMonth = 'AUG';
						break;
					case  '09':
						lcMonth = 'SEP';
						break;
					case  '10':
						lcMonth = 'OCT';
						break;
					case  '11':
						lcMonth = 'NOV';
						break;
					case  '12':
						lcMonth = 'DEC';
						break;
					}
					lcFormat = lcFormat.replace('MMM', lcMonth );
				}
				else if (lcFormat.indexOf('MM') > -1)
					lcFormat = lcFormat.replace('MM', lcMonth);
				
					
								

			if (lcFormat.indexOf('dd') > -1)
				lcFormat = lcFormat.replace('dd', lcDay);
					
			if (lcFormat.indexOf('hh') > -1)
				lcFormat = lcFormat.replace('hh', lcHour);
				
			if (lcFormat.indexOf('mn') > -1)
				lcFormat = lcFormat.replace('mm', lcMinute);
				
			if (lcFormat.indexOf('ss') > -1)
				lcFormat = lcFormat.replace('ss', lcSec);
				
			loDates[lni].innerHTML = lcFormat;
			loDates[lni].setAttribute('txFormat', '');		// reset it so i do not do it again
		}		
	}
}


String.prototype.count = function(match) {

	var res = this.match(new RegExp(match,"g"));
	if (res==null) { return 0; }
	return res.length;
}

String.prototype.padR = function(tcPad, tnNumber) 
{

	var lni, lnLength, lcRet;
	
	lcRet = this;
	lnLength = tnNumber - this.length
	for (lni=0; lni < lnLength; lni++)
		lcRet = lcRet + tcPad;
		
	return lcRet;
}


String.prototype.padL = function(tcPad, tnNumber) 
{

	var lni, lnLength, lcRet;
	lcRet = this;
	lnLength = tnNumber - this.length
	for (lni=0; lni < lnLength; lni++)
		lcRet = tcPad + lcRet;
		
	return lcRet;
}

cQsHandler.prototype.showMap = function(tcTitle, tcAddress, tcDiv)
{
	if (isnull(qsHandler.oGoogleMaps))
		qsHandler.oGoogleMaps = new cGoogleMaps()
		
	window.addEvent('domready', function () { qsHandler.oGoogleMaps.genMap(tcTitle, tcAddress, tcDiv)});
}

cQsHandler.prototype.initUiHandler = function()
{
	this.oUiHandler = new cUiHandler();
}
