var gnfolder;
gnfolder= 0 ;
//function to show list of values

function ShowLOV(tcUrl, toValue, toCheckBox)
{
	var arr = null;
	
	var lotext = event.srcElement.parentElement.parentElement.all(0);
	
	arr = showModalDialog(tcUrl, null, "dialogWidth:640px;dialogHeight:480px;resizable:yes;help:no;status:no;");
	if (arr != null) 
	{
		toValue.value = arr[0];
		lotext.innerText = arr[1];
		if (toCheckBox != null)
		{
			toCheckBox.checked = true;
		}
	}
}


function LOVReturnValue(tcKey, tcValue)
{
	var arr = new Array();
	arr[0] = tcKey;
	arr[1] = tcValue;
	window.returnValue = arr;
	window.close();
}

function QS_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.QS_pgW=innerWidth; document.QS_pgH=innerHeight; onresize=QS_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function QS_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=QS_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function QS_showHideLayers_old() { //v6.0
  var i,p,v,obj,args=QS_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=QS_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v;
  }
}

function 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))
		DIV_centre(tcLayer)
}

function QS_qschangeidtext(tcid, tctext) { 
	var node;
	lonode = document.getElementById(tcid);
	lonode.innerHTML = tctext;
}

// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.2 (European date format)
// Date: 10/14/2002 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: calendar?.js and calendar.html

// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = true;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

function calendar1(obj_target) {
	// assing methods
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup    = cal_popup1;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid tardet control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup1 (str_datetime) {
	this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	if (!this.dt_current) return;

	var obj_calwindow = window.open(
		'/calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
		'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
		',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp1 (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date1 (dt_datetime) {
	return (dt_datetime.getFullYear() + "." + 
		(dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "." +
		(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() 
	);
}
// time generating function
function cal_gen_time1 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp1 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date1 (str_date) {
	var arr_date = str_date.split('.');
	// format is yyyy.mm.dd
	// year arg 0 
	// month arg 1 
	// day  arg 2 

	if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.\nFormat accepted is yyyy-mm-dd.");
	if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid year value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[1]-1);
	 
	if (arr_date[0] < 100) arr_date[0] = Number(arr_date[0]) + (arr_date[0] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[0]);

	var dt_numdays = new Date(arr_date[0], arr_date[1], 0);
	dt_date.setDate(arr_date[2]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[2] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time1 (str_time, dt_date) {
	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0])) 
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}

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 ***
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// 	Call URL and update innerHTML of tag id with resulting HTML

function http_get_url(tcurl, tcform, tcid_destinationdiv, toCallingObject, tnFolder) 
{ 
	var loviewform, lcurl, loxmlhttp, loresponse, lodiv , lni, lcSaveCursor, lonode ; 

	if(toCallingObject)
		if(toCallingObject.style)
		{
			lcSaveCursor = toCallingObject.style.cursor;
			toCallingObject.style.cursor = 'wait';
			toCallingObject.style.color = '#ff0000';
		}

	UpdateDisplay();

	if (tcurl.substr(tcurl.length-1, 1) == '&')
	{
		lcurl = tcurl.substr(0, tcurl.length - 1);
	}
	else
	{
		lcurl = tcurl;
	}

	lcurl = lcurl + '&USERAW=YES'; 
	if (document.getElementById('qs_form_' + tnFolder))
		lcurl = lcurl + '&HOSTFORM=' + document.getElementById('qs_form_' + tnFolder).name ; 

	if ((lcurl.indexOf('http://')==-1 ) &&  (lcurl.indexOf('https://')==-1 ))
	{
		lcurl = document.location.protocol + '//' + document.domain + lcurl ;
	}
	http_execute(tcid_destinationdiv, lcurl, tnFolder);
	return false;
} 

// 	For https:// with a GET verb

function https_GET(tcurl) 
{ 
	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 = http_execute_url("GET", lcurl);
	return lcret;
} 

function UpdateDisplay()
{
	var lodiv, lcdiv;
	lcdiv = "qs_fetchdata"
	DIV_show(lcdiv);
	DIV_centre(lcdiv);
	return true;
}


// 	Order a view by a field 

function http_vieworder(tnfolder,tcfield, tcorder)
{
	var lcurl;
	DIV_centre('qs_fetchdata') ;
	DIV_show('qs_fetchdata') ;
	if (window.location.indexOf('/vd.asp')==-1)
		lcurl = '/lov.asp?FOLDERID=' + tnfolder + '&WCX=ListOfValues&USECONTEXT=YES&VIEWORDERBY=' + tcfield + '&VIEWORDERTYPE=' + tcorder + '&USERAW=YES';
	else
		lcurl = '/vd.asp?FOLDERID=' + tnfolder + '&WCX=ViewDisplay&USECONTEXT=YES&VIEWORDERBY=' + tcfield + '&VIEWORDERTYPE=' + tcorder + '&USERAW=YES';
	http_execute('qsfid' + tnfolder, lcurl, tnfolder) ;
//	http_get_url(lcurl, null, 'qsfid' + tnfolder, null, tnfolder) 
	return false;
}


function http_create_xmlhttp()
{
	var loobjxml;

	//if (window.XMLHttpRequest) 
	//{ 
		// alert('baseline')
		// loobjxml = new XMLHttpRequest(); 
	//} 
	
	if (window.ActiveXObject) 
	{ 
		try 
		{
			loobjxml = new ActiveXObject("msxml2.xmlhttp.6.0")
		}
		catch(e)
		{
			try
			{
				loobjxml = new ActiveXObject("msxml2.xmlhttp.4.0")
			}
			catch(e)
			{
				loobjxml = new ActiveXObject("msxml2.xmlhttp") 
			}			
		}
		try
		{
			loobjxml.settimeouts(5000, 60000, 30000, 90000);
		}
		catch(e)
		{
			null;
		}
	} 
	else if (window.XMLHttpRequest) 
	{ 
		loobjxml = new XMLHttpRequest(); 
	} 
	return loobjxml;
}

function http_googleanalytics(tcurl)
{
	try
	{
		qs_viewhandler.ogoogleids.sendtogoogle(tcurl)
	}
	catch(e)
	{
		null;
	}
}

function http_navigate(tcprotocol, tcurl)
{
	var lcurl;
	lcurl = tcurl.replace('&amp;', '&');

	if (location.protocol == tcprotocol)
	{
		lcurl = location.protocol + '://' + window.location.hostname + lcurl ;
	}
	else
	{
		
		lcurl = tcprotocol + '://' + window.location.hostname + lcurl;
	}

	try
	{
		
 		window.location.href = lcurl;	
	}
	catch(e)
	{
		null;
	}
	return false;
}

function http_execute_url(tcverb, tcurl)
{
	// forces wait
	return http_execute_url_implements(tcverb, tcurl, false)
}

function http_execute_url_async(tcverb, tcurl)
{  
	// Do not wait
   	return http_execute_url_implements(tcverb, tcurl, true)
}

function http_execute_url_sync(tcverb, tcurl)
{  
	// Do not wait
	// legacy please use http_execute_url_async
   	return http_execute_url_implements(tcverb, tcurl, true)
}

function http_execute_url_implements(tcverb, tcurl, tlasync)
{
	var loxmlhttp, lodiv, lcret; 
	lcret = "";

	try 
	{
		if ((tcurl.indexOf('http://')==-1 ) &&  (tcurl.indexOf('https://')==-1 ))
		{
			tcurl = document.location.protocol + '//' + document.domain + tcurl ;
		}

		tcurl = tcurl.replace(/&amp;/g, '&');
		loxmlhttp = http_create_xmlhttp();		
		loxmlhttp.open(tcverb, tcurl, tlasync); 
		loxmlhttp.send(null);
		lcret = loxmlhttp.responseText;
		http_googleanalytics(tcurl);
	}
	catch(e)
	{
		null;
	}
	return lcret;
}


function http_execute(tcdiv, tcurl, tnFolder)
{
	return http_execute_implements(tcdiv, tcurl, tnFolder, true)
}

function http_execute_sync(tcdiv, tcurl, tnFolder)
{
	return http_execute_implements(tcdiv, tcurl, tnFolder, false)

}

function http_execute_implements(tcdiv, tcurl, tnFolder, tlAsync)
{
	var lodiv, lcresult, lcsaveurl, lcsavedest, lloklogin , lotext, lloklogin, lolink, lnid; 

	DIV_centre('qs_fetchdata') ;
 	DIV_show('qs_fetchdata') ;

	// 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;


	loxmlhttp = http_create_xmlhttp();
	lnid = qs_viewhandler.nhttpXMLObj;
	qs_viewhandler.ahttpXMLObj[qs_viewhandler.nhttpXMLObj] = loxmlhttp;
	qs_viewhandler.nhttpXMLObj++ ;

	loxmlhttp.onreadystatechange=function() {http_xmlhttponcomplete(lnid, tcdiv, tcurl, tnFolder);}

	loxmlhttp.open('GET', tcurl, tlAsync); 	
	loxmlhttp.send(null);
	//adding delay 
	//var execdummy = setTimeout('http_execute(\''+tcdiv+'\',\'' +tcurl+'\',\''+ tnFolder+'\')',500)


	//qs_viewhandler.addurl(tcdiv, tcurl);
	http_googleanalytics(tcurl);
	return false;
}

function http_xmlhttponcomplete(tnID, tcdiv, tcurl, tnFolder) 
{
	var lcresult, lonode, lolink, lldestinationdivexists, loxmlhttp, lldone, lni;
	loxmlhttp = qs_viewhandler.ahttpXMLObj[tnID]

	if (loxmlhttp.readyState == 4)
	{
		// do not splice	qs_viewhandler.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 

		
		lldestinationdivexists = (tcdiv!=null) && (tcdiv!='') && (document.getElementById(tcdiv)!=null)

		lcresult =  loxmlhttp.responseText;
		if ((lcresult.indexOf('type="hidden" name="WCX" value="QsLogin"') != -1 ) && (lcresult.indexOf('<html>') != -1))
		{
			// user not loggedin
			DIV_write(tcdiv, "");
			http_showlogin(tcdiv, tcurl, "GET");
		}
		else
		{
			// User is logged in
			if (lldestinationdivexists==true)
			{
				DIV_write(tcdiv, lcresult);
				DIV_show(tcdiv);
			}
			else
			{
				//document.body.innerHTML = Extract_BODY(lcresult);
			}
			//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 <= qs_viewhandler.ahttpXMLObj.length; lni++)
			{
					if (typeof(qs_viewhandler.ahttpXMLObj[lni])=='object' && qs_viewhandler.ahttpXMLObj[lni].readyState != 4)
					{
						lni = qs_viewhandler.ahttpXMLObj.length;
						lldone = false;
					}
			}
			
			if (lldone == true)
			{
				qs_viewhandler.ahttpXMLObj.splice(0, qs_viewhandler.ahttpXMLObj.length)
				DIV_hide('qs_fetchdata') ;
			}
			else
			{
				DIV_hide('qs_fetchdata') ;
				DIV_show('qs_fetchdata') ;
				DIV_centre('qs_fetchdata') ;
			}
			qs_Add_CustomBoxes();
		}
		try
		{
			qs_viewhandler.displayallviews();
		}
		catch(e)
		{
			null;
		}
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 						*** 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;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 						*** LOGIN STUFF ***
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// 	Show the LOGIN form
function http_showlogin(tcdest, tcsaveurl, tcverb)
{
	document.qs_loginform.PWD.value ="";

	DIV_hide("qs_fetchdata")
	DIV_show("qs_loginform")
	DIV_centre("qs_loginform")

	// save URL and destination DIC for the result of the original URL request
	DIV_write('qs_loginurl', URLEncode(tcsaveurl));
	DIV_write('qs_logindestdiv', tcdest);
	DIV_write('qs_loginhttpverb', tcverb);

	return false;
}

// 	Execute the Login procedure
function http_closeqsobject()
{
	try 
	{		
		loxmlhttp = http_create_xmlhttp()
		loxmlhttp.open('GET', '/clearqsfromsession.asp', false) ;
		loxmlhttp.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()
{
	loxmlhttp = new ActiveXObject("msxml2.xmlhttp");
	loxmlhttp.open('POST', '/qs.asp', false) ;
	loxmlhttp.send(null);
	// every five minutes ping qstream to keep session alive
	setTimeout('http_keepalive()',300000);
}

function http_login()
{
	var loform, lcurl, lcresult , lloklogin , lcdest;
	loform  = document.getElementById("qs_loginform");
	{
		lcurl = "/qs.asp?USER=" + document.qs_loginform.USER.value;
		lcurl = lcurl + "&PWD=" + document.qs_loginform.PWD.value ;
		lcurl = lcurl + "&DOMAIN=" + document.qs_loginform.DOMAIN.value ;
		lcurl = lcurl + "&WCX=QsLogin" ;
		lcurl = lcurl + "&LOGINURL=" ;

		lcresult = https_GET(lcurl);

		if (!check_AccessDenied(lcresult))
		{
			// Login OK so http the previous URL
			lcresult = http_execute_url(DIV_get('qs_loginhttpverb'), URLDecode(DIV_get('qs_loginurl')));
			//
			lcdest = DIV_get('qs_logindestdiv');
			DIV_hide('qs_loginform');

			if ((lcdest) && (lcdest != ''))
			{
				DIV_write(lcdest, lcresult);
			}
			else
			{
				document.body.innerHTML = Extract_BODY(lcresult);
			}
		}
	else
	{
		// login NOT OK
		http_showlogin(DIV_get('qs_logindestdiv'), URLDecode(DIV_get('qs_loginurl')), DIV_get('qs_loginhttpverb'));
		lotext = document.getElementById('sys_invalidpassword');
		DIV_write('qs_loginmessage', lotext.innerHTML);}
	}
	return false ;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 						*** DIV STUFF ***
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// 	Write to a DIV 
function DIV_write(tcdiv, tcText )
{
	var lodiv ;
	lodiv = document.getElementById(tcdiv);
	if (lodiv)
	{
		lodiv.innerHTML = tcText;
		try
		{
			translatehttp();
		}
		catch(e)
		{
			null;
		}
	}
	return false;
}

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;	
}

// 	GET a value from a DIV
function DIV_get(tcdiv)
{
	var lodiv ;
	lodiv  = document.getElementById(tcdiv);
	return lodiv.innerHTML;
}

// 	HIDE a DIV
function DIV_hide(tcdiv)
{
	var lodiv;
	lodiv = document.getElementById(tcdiv);
	if (lodiv)
		lodiv.style.display="none";
	return false;
}

// 	SHOW a DIV
function DIV_copyto(tcfromdivid, tctodivid)
{
	var lodivfrom, todivto ;
	lodivfrom = document.getElementById(tcfromdivid);
	if (lodivfrom)
	{
		lodivto = document.getElementById(tctodivid);
		if (lodivto)
		{

			lodivto.innerHTML = lodivfrom.innerHTML;
		}
	}
}

function DIV_puthtml(tcdiv, tctext)
{
	var lodiv;
	lodiv = document.getElementById(tcdiv);
	if (lodiv)
	{
		lodiv.innerHTML = tctext;
	}
}

function DIV_show(tcdiv)
{
	var lodiv;
	lodiv = document.getElementById(tcdiv);
	if (lodiv)
		lodiv.style.display="block";
	return false;
}

// 	CENTER a DIV
function DIV_centre(tcdiv)
{
	var lonode, lnscreenleft;

	if (lnthisbrowser==2)
		lnscreenleft = window.screenX;		// mozilla
	else
		lnscreenleft = window.screenLeft

	lonode = document.getElementById(tcdiv);
	if (lonode)
	{
		if (lnscreenleft > screen.width)	
		{
			lonode.style.left =   parseInt((GetWindowWidth() - lonode.offsetWidth ) / 2 ) + 'px';
		}
		else
		{
			lonode.style.left =   parseInt((GetWindowWidth() - lonode.offsetWidth ) / 2) + 'px';
		}
        // RE 2008.04.14 - recenter object
		//lonode.style.top =  (GetWindowHeight() - lonode.offsetHeight) / 2;	
		if(typeof getScroll()!='undefined')
		{
	        lonode.style.top =   parseInt((getScroll() + (GetWindowHeight()/2)) ) + 'px';	
		}
		else
		{
		    lonode.style.top =   parseInt((GetWindowHeight() - lonode.offsetHeight) / 2) + 'px';			
		}
	}
}

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


}

//////////////////////////////////////////////////////////////////
// 	SET DIV at POSITION tcposid a DIV
//
function DIV_position(tcposid, tcdivid, tnoffsetx, tnoffsety)
{
var lodiv, lopos, lnx, lny, lncurrentx, lncurrenty;


	

	lodiv = document.getElementById(tcdivid);
	lopos = document.getElementById(tcposid);
	lncurrentx = getabsolutex(lodiv);
	lncurrenty = getabsolutey(lodiv);



	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';


	lodiv.style.left = lnx
	lodiv.style.top = lny 
	DIV_show(tcdivid);


}



//////////////////////////////////////////////////////////////////
// 	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.parentElement.tagName == 'A' || window.event.srcElement.parentElement.tagName == 'a' )
			loobj = window.event.srcElement.parentElement;
		else
			loobj = null;
	}
	catch(e)
	{
		// do nothing
	}
	if ((loobj!=null))
	{



		if ((!(loobj.onclick) || (loobj.onclick ==''))  )
		{

			lchref = loobj.href;
			lchref = lchref.toUpperCase();
		

			if (lchref.indexOf('&VIEWORDERBY=') != -1)
			{
				UpdateDisplay();

				loxmlhttp = http_create_xmlhttp();
				loxmlhttp.open("GET", loobj.href + '&USERAW=YES', false); 

				loxmlhttp.send(null);
				lnpos = lchref.toUpperCase().indexOf('FOLDERID');
				lchref = lchref.substring(lnpos + 9 );
				if (lchref.indexOf('&') > -1 )
				{
					lnfolderid = lchref.substring(0, lchref.indexOf('&'));
					DIV_write("qsfid" + lnfolderid , loxmlhttp.responseText );
					qs_Add_CustomBoxes();
					window.event.returnValue = false;
				}
				else
					window.event.returnValue = true;
				DIV_hide('qs_fetchdata') ; 
				


			}
			else
			{
				window.event.returnValue = true;
			}

			document.body.onclick = TrapBodyClick;
		}
		else
		{

			window.event.returnValue = true;
		}
	}
	else
		window.event.returnValue = true;
}
// alert('trapping');
}




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 http_post_a_form(tnformid, tcasppage ) 
{


	var loxmlhttp;

	var loviewform, lcurl,  loxmlhttp, loresponse, lodiv , lni, lcstr , llret;

	var loform, lni, lcurl, lcpage ;
	
	var lcfieldname, lcvaluetopost, lcfieldtype

	/*
	
	if (tcasppage =='')
	{	
		tcasppage = '/qs.asp?';
	}
	else
	{	
		tcasppage = tcasppage 
	}
	
	
	tcasppage = document.location.protocol + '//' + document.domain + tcasppage ;


	
	lcurl = "";
*/

	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

		//revaristo 2008.01.30 changed to suport other tag types

		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;
		
		}
		
	}
		
	if (lcurl.substr(lcurl.length-1, 1) == '&')
	{
		lcurl = lcurl.substr(0, lcurl.length - 1);
	}

	lcurl = lcurl + '&USERAW=YES'; 

	loxmlhttp = http_create_xmlhttp();
	loxmlhttp.open("POST", tcasppage , false); 
	loxmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	//alert(lcurl);

	
	//alert(lcurl)
	
	loxmlhttp.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(qs_viewhandler.oCurrentTabset))
		{
			qs_viewhandler.oCurrentTabset.resetLoaded();
		}
	}
	catch(e)
	{
		// nothing;
	}

//alert(loxmlhttp.responseText)
	

	return 	loxmlhttp.responseText;
	
	
}



function http_post_a_form_old(tnformid, tcasppage ) 
{

	tcasppage ='';


	var loviewform, lcurl,  loxmlhttp, loresponse, lodiv , lni, lcstr , llret;

	var loform, lni, lcurl, lcpage ;

	if (tcasppage =='')
	{	
		lcurl = '/qs.asp?';
	}
	else
	{	
		lcurl = tcasppage + '?';
	}
	

	loform = document.getElementById('saveform' + tnformid);

	if (loform)
	{
		for (lni=0; lni < loform.length; lni ++)
		{
			lcurl = lcurl + loform.elements[lni].name + '=' + URLEncode(loform.elements[lni].value) + '&' ;
		}
	}


	if (lcurl.substr(lcurl.length-1, 1) == '&')
	{
		lcurl = lcurl.substr(0, lcurl.length - 1);
	}

	lcurl = lcurl + '&USERAW=YES'; 

	lcurl = document.location.protocol + '//' + document.domain + lcurl ;


	lcpage = http_execute_url('POST', lcurl);
	
	return lcpage;
}


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, loxmlhttp, loresponse, lodiv , lni, lcstr , llret;

	loviewform = document.getElementById('qs_form_' + tnfolder); 
	loviewform.FOLDERID.value = tnfolder;

	
	if (tluseajax) 
	{

		if (loviewform.action.substring(1,3)=='qs')
			lcurl = '/vd.asp?' ;
		else
		{
			lcurl = loviewform.action;
			lcurl = lcurl.substring(0,lcurl.indexOf('.')) + '.asp?';		
		}
//		lcurl = '/vd.asp?' ;

		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';

		http_execute("qsfid" + tnfolder, lcurl, tnfolder);

//		llret = http_get_url(lcurl, null, "qsfid" + tnfolder, null, tnfolder);  
	}
	else
	{
		loviewform.submit();
	}
	qs_Add_CustomBoxes();
	lcbutton = "btnsearch";
	lctarget = "";
	loviewform.action	='/vd.asp';
	loviewform.WCX.value	='viewdisplay';

	
	return false;
}

function qs_translatepage(tnlang, tcapp, tcapptag, tcASP)
{
	var lnlength, lotags;
	var loxmlhttp, lcHtml;
	var lnlang;
	
	if (typeof(lcvarlist)!='string')
		lcvarlist=''

//			if (lcHtml.toUpperCase().indexOf('<TD') ==-1 && lcHtml.toUpperCase().indexOf('<SELECT') ==-1 && lcHtml.toUpperCase().indexOf('<SPAN') ==-1 && lcHtml.toUpperCase().indexOf('<DIV') ==-1 && lcHtml.toUpperCase().indexOf('<A') ==-1 && lcHtml.toUpperCase().indexOf('<IMG') ==-1)
	
	lotags = document.getElementsByTagName("OPTION");
	lnlength = lotags.length; 
	
	for (lni=1; lni < lnlength ; lni++)
	{
		lcid = lotags.item(lni).id ;

		if (lotags.item(lni).getAttribute('notranslate')!='1')
		if (lcid != ''  && lcid.substring(0,6).indexOf('qsapp_') == -1 && lcid.substring(0,5).indexOf('menu_') == -1 && lcvarlist.indexOf(lcid)==-1) 
		{
			lcHtml = lotags.item(lni).innerHTML ;
			if (lcHtml.toUpperCase().substring(0,1) !='<' && lcHtml.toUpperCase().substring(lcHtml.length-1,1) !='>')
			{
				http_execute_url_async('POST', tcASP + '?langid=' + lnlang  + '&langs=1,2&appname=' + tcapp + '&apptag=' + tcapptag + '&mtlcode=' + lcid + '&mtltext=' + lcHtml.replace('&', '&amp;'));
			}
			lcvarlist = lcvarlist +"*"+lcid
		}
	}

	lotags = document.getElementsByTagName("SPAN");
	lnlength = lotags.length; 

	for (lni=1; lni < lnlength ; lni++)
	{
		lcid = lotags.item(lni).id ;
		if (lotags.item(lni).getAttribute('notranslate')!='1')
		if (lcid != ''  && lcid.substring(0,6).indexOf('qsapp_') == -1 && lcid.substring(0,5).indexOf('menu_') == -1 && lcvarlist.indexOf(lcid)==-1) 
		{
			lcHtml = lotags.item(lni).innerHTML ;
			if (lcHtml.toUpperCase().substring(0,1) !='<' && lcHtml.toUpperCase().substring(lcHtml.length-1,1) !='>')
			{
				http_execute_url_async('POST', tcASP + '?langid=' + lnlang  + '&langs=1,2&appname=' + tcapp + '&apptag=' + tcapptag + '&mtlcode=' + lcid + '&mtltext=' + lcHtml.replace('&', '&amp;'));
			}
			lcvarlist = lcvarlist +"*"+lcid
		}
	}

	
	lotags = document.getElementsByTagName("TD");
	lnlength = lotags.length; 

	for (lni=1; lni < lnlength ; lni++)
	{
	
		lcid = lotags.item(lni).id ;
		if (lotags.item(lni).getAttribute('notranslate')!='1')
			if (lcid != ''  && lcid.substring(0,6).indexOf('qsapp_') == -1 && lcid.substring(0,5).indexOf('menu_') == -1 && lcvarlist.indexOf(lcid)==-1) 
			{
				lcHtml = lotags.item(lni).innerHTML ;
				if (lcHtml.toUpperCase().substring(0,1) !='<' && lcHtml.toUpperCase().substring(lcHtml.length-1,1) !='>')
				{
					http_execute_url_async('POST', tcASP + '?langid=' + lnlang  + '&langs=1,2&appname=' + tcapp + '&apptag=' + tcapptag + '&mtlcode=' + lcid + '&mtltext=' + lcHtml.replace('&', '&amp;'));
				}
				lcvarlist = lcvarlist +"*"+lcid
			}

	}
}

function qsPrintPage(tnfid)
{
	// hides blocks
	var lonodes, lcstyle;

	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(qs_viewhandler.oCurrentTabset))
		{
			var loTabset = document.getElementById('qstabset');
			var lcHtml = loTabset.innerHTML ;
			loTabset.innerHTML = document.getElementById('div_' + qs_viewhandler.oCurrentTabset.oTab.ntabId).innerHTML;
			window.print();
			//window.navigate(window.location);
			loTabset.innerHTML = lcHtml;

			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";
					}
				}
			} 
		}
	}
	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";
				}
			}
		}
	}
}
	
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 loheader, lchtml;
		
	lchtml = toObject.innerHTML;
	loheader = document.getElementById(tcstyle);
	// loheader.firstChild.cells().innerHTML = lchtml;
	toObject.style.padding="0px";
	toObject.innerHTML = loheader.innerHTML;
	
}

function qsstyle_insertfooterheader(toObject, tcstyle)
{
		
	var loheader, lchtml;
		
	lchtml = toObject.innerHTML;
	loheader = document.getElementById(tcstyle);
	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;

		qs_viewhandler.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_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)
{

	tcpage = tcpage.replace(/[\n\r]+/g, "<br>");
	document.getElementById("qs_messtitle").innerHTML 	= tctitle;
	document.getElementById("qs_messtext").innerHTML 	= tcpage ;
	document.getElementById("qs_mess_window").style.display	='block';
	DIV_centre("qs_mess_window");

	return true;
}

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).parentElement.innerHTML = loobjs.item(lni).parentElement.innerHTML ;
//				loobjs.item(lni).parentElement.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);

		lcpage = http_post_a_form(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)
			{
				qs_showmessage('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))
		{

			qs_showmessage('Unable to save form', lcpage);
			genxsl_SetFormReadonly(tnUIFID , false);

			llret = false;

		}
		if (llret == true)
		{
			if (tnreturnfid > 0 )
			{
				lcpage = http_execute_url("GET", "/vd.asp?wcx=viewdisplay&amp;folderid=" + tnreturnfid + "&amp;USERAW=YES&amp;ADDVIEWDIV=YES");

				pushJavaScript(lcpage , gnfolder);

				DIV_write('qsfid' + tnUIFID , 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 = 0;
			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 = lonodes.item(0).getAttribute('nresult');
		this.nerrors = lonodes.item(0).getAttribute('errors');
		this.nmessages = 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.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') 
		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)
	}

}

			


/*Drag routine

RE 2007.10.10 function to drag an object

*/		
			var goobjdrag
			var gldragmode
			var gnposojtop, gnposojleft

			function initdrag(lotodrag)
			{
			
			if(gldragmode)
			{
			    gldragmode = false;
			 }
			 else
			 {
			    gldragmode = true;
			 
			 }
			 
			gobjdrag = lotodrag;

			document.onmousemove = Drag;
			document.onclick = Drop
			document.onmouseup = Drop;
			document.body.style.cursor = 'move'; 
			
			}

			function Drop()
			{

			gnposojtop 	= null;
			gnposojleft	= null;
	
			gldragmode = false;
			document.onmouseup = null;
			document.onmousemove = null;
			
			document.body.style.cursor = ''; 

			}

			function Drag(e)
			{

			if(gldragmode){
	

			    // only drag when the mouse is down  
			    var evt = e || window.event;
    
			    if (!(gnposojtop))
			    {

			   	gnposojtop 	= gobjdrag.style.top.replace(/px/,'')*1  - evt.clientY
				gnposojleft	= gobjdrag.style.left.replace(/px/,'')*1 - evt.clientX
				   
			}
			    gobjdrag.style.top = (evt.clientY*1 + gnposojtop*1) + 'px';
			    gobjdrag.style.left = (evt.clientX*1 + gnposojleft *1) + 'px';
    
			   }
			}


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' ;

}


function seteleposevent(e, tctarget)
			{
			
			    // only drag when the mouse is down  
			    var loevt = e || window.event;
			    
			    var localler, lotargetobj;
			    
			    
			    //mozilla first
			    if(loevt.target)
			    {
			        localler = loevt.target;
			    }
			    else			    
			    {
			        localler = loevt.srcElement;			    
			    }
			    			    
			    if(document.getElementById(tctarget))		    
			    {
			        lotargetobj = document.getElementById(tctarget);
			        
			        lotargetobj.style.position ='absolute'
			        lotargetobj.style.top      = (loevt.clientY - window.screenTop) + 'px';
			        lotargetobj.style.left     = (loevt.clientX - lotargetobj.style.pixelWidth ) + '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, tcexeccode){ 
	var lncharacterCode 

	if(e && e.which){ 
		e = e
		lncharacterCode = e.which 
	}
	else{
		e = event
		lncharacterCode = e.keyCode 
	}

	if(lncharacterCode == 13){

		setTimeout ( tcexeccode,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;

}



//****************************************************************************************
//*
//*
//*		ABSOLUTE POSITION
//*
//*
//****************************************************************************************


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;
}



//****************************************************************************************
//*
//*
//*		ABSOLUTE POSITION
//*
//*
//****************************************************************************************


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;
}



//****************************************************************************************
//*
//*
//*		FLASH STUFF	FLASH STUFF	FLASH STUFF
//*
//*
//****************************************************************************************


isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;

var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;

var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;




function qs_AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }

  return str;
}

function qs_AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function qs_AC_GetArgs(args, ext, srcParamName, classid, mimeType)
{
  
var ret = new Object();
  
ret.embedAttrs = new Object();
  
ret.params = new Object();
  
ret.objAttrs = new Object();
  
for (var i=0; i < args.length; i=i+2)
{
    var currArg = args[i].toLowerCase();    

    
switch (currArg){	
      
case "classid":
        break;
      
case "pluginspage":
   ret.embedAttrs[args[i]] = args[i+1];
        break;
      
case "src":
      
case "movie":	
        args[i+1] = qs_AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      
case "onafterupdate":
      
case "onbeforeupdate":
      
case "onblur":
      
case "oncellchange":
      
case "onclick":
      
case "ondblClick":
      
case "ondrag":
      
case "ondragend":
      
case "ondragenter":
      
case "ondragleave":
      
case "ondragover":
      
case "ondrop":
      
case "onfinish":
      
case "onfocus":
      
case "onhelp":
      
case "onmousedown":
      
case "onmouseup":
      
case "onmouseover":
      
case "onmousemove":
      
case "onmouseout":
      
case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      
case "width":
      
case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      
default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    
}
  
}
  ret.objAttrs["classid"] = classid;
  
if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;

}


function qs_AC_FL_RunContent(){
  var ret = 
    qs_AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return qs_AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}




function fl_addtitle(tctitle, tnrotation, tcparent, tcpositionatid, tccolor, tctagid, tnoffsetx, tnoffsety) 
{
	try
	{
		qs_viewhandler.addflashtitle(tctagid, tctitle, tnrotation, tccolor, tcparent, tcpositionatid, tnoffsetx, tnoffsety);
	}
	catch(e)
	{
		// do nothing
	}

	return false;
}


function qsapp_properties()
{

	this.cappname 	= 'Update application name';
	this.ccopyright = 'Update copyright MIGG Copyright';
	this.cusername 	= 'Anonymous';
	this.cdate	= '';
	this.csite 	= ''

}

qsapp_properties.prototype.set= function(tcappname, tccopyrightnotice, tcsite, tcdate, tcusername)
{

	this.cappname 	= tcappname;
	this.ccopyright = tccopyrightnotice;
	this.cusername 	= tcusername;
	this.cdate 	= tcdate;
	this.csite 	= tcsite;

}

qsapp_properties.prototype.display = function()
{

	DIV_puthtml("qsapp_name"	, this.cappname);
	DIV_puthtml("qsapp_copyright"	, this.ccopyright);
	DIV_puthtml("qsapp_username"	, this.cusername);
	DIV_puthtml("qsapp_date"	, this.cdate);
	DIV_puthtml("qsapp_site"	, this.csite);


}


function fl_positiontitles()
{
	try
	{
		qs_viewhandler.showflashtitles();
	}
	catch(e)
	{
		// do nothing
	}
}

function viewhandler()
{
	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.atabsetTag= new Array();				// holds the tab id where the stuff was displayed
	this.atabkey= 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 qsapp_properties();
	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.nentities = 0 ;
	this.aentities = new Array() ;				// loaded data entities (entitybasclass) 
	this.ouser = null;
	this.ahttpXMLObj = new Array();
	this.nhttpXMLObj = 0 ;
	this.version = 1;
}


viewhandler.prototype.setUser = function(touser)
{
	// Hold the current user object for checking permissions and other issues
	this.ouser = touser;
}

viewhandler.prototype.TabSet_showheader = function(tcname)
{
	var lni;
	for (lni = 1; lni <= this.ntabsets; lni++)
	{
		if (this.atabsets[lni].cname == tcname)
		{
			this.oCurrentTabset = this.atabsets[lni];
			this.atabsets[lni].showheader();
		}
	}
}

viewhandler.prototype.TabSet_add = function(totabset)
{
	this.ntabsets = this.ntabsets + 1;
	this.atabsets[this.ntabsets] = totabset;
	this.oCurrentTabset = totabset;
}

viewhandler.prototype.TabSet_getTabId = function(tctabname, tctabset)
{
	var lotab, lntabset ;
	lntabset = 0 ;

	for (lni = 1; lni <= this.ntabsets; lni++)
	{
		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
}

viewhandler.prototype.TabSet_getTab = function(tctabname, tctabset)
{
	var lotab, lntabset ;
	lntabset = 0 ;

	for (lni = 1; lni <= this.ntabsets; lni++)
	{
		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
}

viewhandler.prototype.mover_get = function(tcTagName)
{
	var loMover;
	
	loMover = this.entity_get(tcTagName)
	
	if (isnull(loMover))
		loMover = new moverList;
	
	return loMover;
}

viewhandler.prototype.entity_add = function(loEntity)
{
	var lodummy;
	
	lodummy = null;
	
	if (typeof(loEntity.bc.cTagName) !='undefined')
		lodummy = this.entity_get(loEntity.bc.cTagName);

	if (typeof(loEntity.bc.ctagname) !='undefined')
		lodummy = this.entity_get(loEntity.bc.ctagname);
	
	if (typeof(loEntity.cTagName) !='undefined')
		lodummy = this.entity_get(loEntity.cTagName);
	
	
	if (isnull(lodummy))
	{
		this.nentities +=1;
		this.aentities[this.nentities] = loEntity;
	}
}

viewhandler.prototype.entity_get = function(tctag)
{
	var lni, loret;
	loret = null;

	for (lni=1; lni <= this.nentities; lni++)
	{	
		try 
		{
			if (this.aentities[lni].bc.ctagname == tctag)
			{
				loret = this.aentities[lni];
				lni = this.nentities;
			}
		}
		catch(e)
		{
			if (this.aentities[lni].cTagName == tctag)
			{
				loret = this.aentities[lni];
				lni = this.nentities;
			}
		}
	}
	
	return loret
}

viewhandler.prototype.refreshMovers = function()
{
	var lni, loret;
	loret = null;

	for (lni=1; lni <= this.nentities; lni++)
	{	
		try 
		{
			this.aentities[lni].refreshList()
		}
		catch(e)
		{
			// nothing
		}
	}
	return loret
}

viewhandler.prototype.viewAdd = function(tnfid)
{
	var loview = new qsView(tnfid)
	this.nfids +=1;
	this.afids[this.nfids] = loview;
}

viewhandler.prototype.viewGet = function(tnfid)
{
	var lni, loret, loview;
	loret = null;
	tnfid = parseInt(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)
		{
			null;
		}
	}
}

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('*', '%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;
}

viewhandler.prototype.displayWrappers = function()
{
	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;
}

viewhandler.prototype.displayDivPos= function()
{
	var lni;
	for (lni = 1 ; lni <= this.ndivpos; lni++)
	{
		DIV_position(this.adiv_pos[lni], this.adiv_item[lni],10,10)
		DIV_show(this.adiv_item[lni])
		document.getElementById(this.adiv_item[lni]).top = "100px";
		document.getElementById(this.adiv_item[lni]).style.display="inline";
	}
	return false;
}

viewhandler.prototype.moveToPage = function(tnFolderid, tnpage)
{
	http_execute('qsfid' + tnFolderid, '/vd.asp?folderid=' + tnFolderid + '&RHSPAGENO=' + tnpage + '&USERAW=YES&ADDVIEWDIV=NO', tnFolderid)
	return false;
}
viewhandler.prototype.movetopage = function(tnFolderid, tnpage)
{
	http_execute('qsfid' + tnFolderid, '/vd.asp?folderid=' + tnFolderid + '&RHSPAGENO=' + tnpage + '&USERAW=YES&ADDVIEWDIV=NO', tnFolderid)
	return false;
}

viewhandler.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;
	}
}

viewhandler.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;
	}
}

viewhandler.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;
	}
}

viewhandler.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;
}

viewhandler.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;
}

viewhandler.prototype.addUrlTab =  function(tcZone, tcUrl, tnTabId)
{
	this.addurl(tcZone, tcUrl);
	this.aurls[this.nurls].nTabId = tnTabId;
	this.aurls[this.nurls].cTabSetUrl = qs_viewhandler.oCurrentTabset.cUrl;
	this.aurls[this.nurls].nCallType = 2;
}
viewhandler.prototype.addurl =  function(tczone, tcurl)
{
	
	this.nurls += 1 ;
	this.aurls[this.nurls] = new urlCall(tczone, tcurl)
	
	try
	{
		if (!isnull(qs_viewhandler.oCurrentTabset))
		{
			// alert('set to ' + qs_viewhandler.oCurrentTabset.oTab.ntabId)
			this.aurls[this.nurls].nTabId = qs_viewhandler.oCurrentTabset.oTab.ntabId;
			this.aurls[this.nurls].cTabSetUrl = qs_viewhandler.oCurrentTabset.cUrl;
		}
	}
	catch(e)
	{
		null;
	}		
}

viewhandler.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(qs_viewhandler.oCurrentTabset) || (loCall.cTabSetUrl != qs_viewhandler.oCurrentTabset.cUrl)))
		{
				
			http_execute('qszone_appbody', loCall.cTabSetUrl + "&USERAW=YES&USEDEFHTML=OFF", 0);
			setTimeout('if (qs_viewhandler.oCurrentTabset.oTab.ntabid !='+ lnTabid + ') {qs_viewhandler.oCurrentTabset.callTab(' + lnTabid + '); qs_viewhandler.nurls -=1;}',800)
			setTimeout('http_execute("' + lczone + '", "' + lcurl + '&USERAW=YES&USEDEFHTML=OFF", 0)',1200)
			//this.nurls -=1;
		}
		else
		{
			if (loCall.nTabId != qs_viewhandler.oCurrentTabset.oTab.ntabid)
			{
				qs_viewhandler.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();
	}
}

viewhandler.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;	
}

viewhandler.prototype.showflashtitles = function()
{
	var lni;
	for (lni=0; lni < this.nflashtitles; lni++)
		this.aflashtitles[lni + 1].display();
}
viewhandler.prototype.addview =  function(tctag, tnviewid, tcdiv, tnpageno)
{
	this.nviews 	+=1;
	this.aviews[this.nviews] = new viewcontroller(tctag, tnviewid, tcdiv, tnpageno);				// Holds current records
}

viewhandler.prototype.display = function(tctag)
{
	var lnindex = this.getIndex(tctag)
	if (lnindex > 0 ) 
		this.aviews[lnindex].display();
}

viewhandler.prototype.displayallviews = function()
{
	var lni;

	this.oappproperties.display();
 	this.displayWrappers();
	this.displayDivPos();

	for (lni=1; lni <= this.nviews; lni++)
	{
		this.aviews[lni].display();
	}
	
	// Update all mover lists
	this.refreshMovers()

	// Update tab set menus
	try
	{	
		if ( !isnull(this.oCurrentTabset) && !isnull(this.oCurrentTabset.oTab.cObjectTagName) && !isnull(this.oCurrentTabset.oTab.cMenuTagName) )
		{
			var loapp = qs_viewhandler.entity_get(this.oCurrentTabset.oTab.cObjectTagName)
			if (loapp)
			{
				loapp.menu_setup(this.oCurrentTabset.oTab.cMenuTagName);
				loapp.bc.omenu.showmenu();
			}
			else
			{
				if (!isnull(this.oCurrentTabset.oTab.oMenu))
				{
					this.oCurrentTabset.oTab.oMenu.showmenu();
				}
			}
		}
	}

	catch(e)
	{
		null
	}
	//re 2009.01.26
	// oEditHandler may not exist
	if(qs_viewhandler.oEditHandler)
	{
		qs_viewhandler.oEditHandler.show();
	}

	setTimeout("try {qs_viewhandler.showflashtitles();}catch(e){null}", 20);
	
	try
	{
	    translatehttp();
	}
	catch(e)
	{
	    null;	
	}
}

viewhandler.prototype.getViewObject = function()
{
	return this.aviews[this.nviews];
}

viewhandler.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;
}

viewhandler.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;
}

viewhandler.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;
}

viewhandler.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;
}

viewhandler.prototype.moveleft = function(tctag)
{
	var lnindex = this.getIndex(tctag);
	if (lnindex > 0 ) 
		this.aviews[lnindex].moveleft();		
}

viewhandler.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 ((qs_viewhandler == 'undefined') || (qs_viewhandler==null))
{
	var qs_viewhandler = new viewhandler();
	var qsHandler = qs_viewhandler;				// since qs.dll has been updated to new version and uses qsHandler !!!
}

if ((qs_addhandler == 'undefined') || (qs_addhandler==null))
	var qs_addhandler = new addhandler();

qs_viewhandler.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 ;

		DIV_position(this.cpositionat, this.ctag,lnx,lny );
		//DIV_show(this.ctag);
	}
	else
	{
		lodiv = document.getElementById(this.ctag);
		if (lodiv != null)
			lodiv.style.display = "none";			// hide it!
	}
}

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;
	
	if (confirm(tctext))
	{
		lcurl = '/rdel.asp?wcx=recorddelete&folderid=' + tndelfolder + '&QSKEYID=' + tndelkey ;
		lcxml = http_execute_url('GET', lcurl);

		loresponse = new qstreamResponse(lcxml);
		if (loresponse.nresult == 1)
		{
			qs_showmessage('Unable to delete', loresponse.showErrors());
			lnret = 1;
		}
		else
		{
			lnret = 0;
		}

		if (tnretfid > 0 )
		{
			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())
	{
		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
			}
		}
	}
}

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;
}

qsView.prototype.bindToEntity = function(tctag)
{
	this.oboundEntity = qs_viewhandler.entity_get(tctag)
}

qsView.prototype.showThisRecord = function(tctag, tnkid)
{
	this.bindToEntity(tctag)		// bind entity with tag name to this view object
	if (this.oboundEntity)			// if there is an application tctag
	{
		try
		{	
			// view the record tab of the bound application using PKID selected
			try
			{
				// attempt top level otherwise base class level
				this.oboundEntity.showRecordTab(tnkid);
			}
			catch(e)
			{
				this.oboundEntity.bc.showRecordTab(tnkid);
			}
			// this.oboundEntity.bc.showRecordTab(this.otr.nkeyid);
		}
		catch(e)
		{}
	}
}

qsView.prototype.toggleHide = function()
{
	var lodiv = document.getElementById('cfilters_'+ this.nfid)

	if (lodiv)
	{
		if (lodiv.style.display=='none')
		{
			lodiv.style.display ="inline";
		}
		else
		{
			lodiv.style.display ="none";
		}
	}
	return true;
}

function qs_tr()
{
	this.cColor 	="";
	this.cBgColor	="";
	this.cSaveColor	="";
	this.cSaveBgColor="";
	this.olasttr = null;
	this.nkeyid  = 0;
}

qs_tr.prototype.hl= function(totr, tnkeyid)
{
	this.nkeyid = parseInt(tnkeyid);	

	if (this.olasttr)
	{
		this.olasttr.style.color = this.cSaveColor;
		if (this.olasttr.style.backgroundColor == "#ddeeff")
			this.olasttr.style.backgroundColor = this.cSaveBgColor;
		this.olasttr.lhighlight = false;
	}

	this.cSaveColor		= totr.style.color;
	this.cSaveBgColor	= totr.style.backgroundColor;
	totr.style.color 	= "#222222";
	totr.style.backgroundColor = "#ddeeff";
	this.olasttr = totr;
}

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()
{

	this.odom = http_create_xmlhttp();
	this.nagent = detectNavigator();
	this.oxmldoc = null;
}

xmlDOC.prototype.getdata = function(tcurl, tlAsync)
{
	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("GET", tcurl, false);
	this.odom.setRequestHeader("Content-Type", "text/xml");
	this.odom.send(null);
	this.oxmldoc = this.odom.responseXML;
	this.oxmldoc.async = false;
 	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.createNode = function(tcTagName, tcElementValue)
{
	return this.oxmldoc.createNode(1, tcTagName, tcElementValue)
}

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)
{
	try //Internet Explorer
	{
	  this.oxmldoc=new ActiveXObject("Microsoft.XMLDOM");
	}
	catch(e)
	{
		try //Firefox, Mozilla, Opera, etc.
		{
			this.oxmldoc = document.implementation.createDocument("","",null);
		}
		catch(e)
		{
			alert(e.message);
			return;
		}
	}
	this.oxmldoc.async=false;
	this.oxmldoc.loadXML(tcxml)
	return true;			
}

xmlDOC.prototype.selectNodes = function(tcselect)
{
	var lonodes, lnsResolver;

	if (this.nagent == 1)
	{
		lonodes = 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.ANY_TYPE, null );
	}
	return lonodes;
}

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.oxmldoc.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 g_hl(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 	= lotr.getAttribute("KID");
			lnfid 		= lotable.getAttribute("QSFID")
			loview 		= qs_viewhandler.viewGet(lnfid);
			if (loview)
				loview.otr.hl(lotr, lnkeyid);
		}
	}
	catch(e)
	{
		null;
	}
}

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')
		{
			lnfid 	= loNode.getAttribute("QSFID");
			if (lnfid > 0 )
				lnNode = loNode;
			else
				loNode = gen_getTable(loNode)
		}
		else
 			loNode = gen_getTable(loNode)
 	}
 	else
 		loNode = 0 ;
 	
 	return loNode;
}


function g_cl(toevent)
{
	var lotr, lotable, lnfid, loview, lcentitytag, lnkid, lnEditFID, lcVar;
	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)
		{
			lnfid 		= lotable.getAttribute("QSFID")
			lnEditFID	= lotable.getAttribute("QSEDITFID")
			lnkid		= lotr.getAttribute("KID")
			lcVar 		= lotable.getAttribute("QSKIDVAR")
			lcentitytag = lotable.getAttribute("boundToEntity")
			loview 		= qs_viewhandler.viewGet(lnfid);

			// If edit is defined use it ,  otehrwise show associated TAB SET
			if (lnEditFID > 0 )
				http_execute('qsfid' + lnfid , '/vd.asp?ADDVIEWDIV=YES&USERAW=YES&FOLDERID=' + lnEditFID + "&SETVAR_" + lcVar + "=" + lnkid, lnEditFID);		
			else
				loview.showThisRecord(lcentitytag, lnkid);				
		}
	}
	catch(e)
	{
		null;
	}
}

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;
}