///////////////////////////////////////////////////////////////////////////////
// framecontrol.js
///////////////////////////////////////////////////////////////////////////////

function fr2_open() { fr2_size(170); }
function fr2_open_small() { fr2_size(30); }
function fr2_close() { fr2_size(0); if(parent.fr1) parent.fr1.focus(); }

function fr2_size(height) {
	var fs = parent.document.getElementById('ttframeset');

// The frameset context can change now that the frameset can 
// be generated through WindowOpenFrameset() or through 
// new_frameset().

	if (!fs)
	{
	   fs = document.getElementById('ttframeset');
	}

	if (fs) {
		var rowSpl=fs.rows.split(',');
		var t=rowSpl[0];
		var f3=rowSpl[3];
		fs.rows=t+',*,'+height+','+f3+',0,0';
	} else if (parent != window) {
		try {
			parent.fr2_size(height);
		} catch(e) {}
	}
}

function fr3_open() { fr3_size(170); }
function fr3_close() { fr3_size(0); if (parent.fr1) parent.fr1.focus(); }

function fr3_size(height) {
	var fs = parent.document.getElementById('ttframeset');

// The frameset context can change now that the frameset can 
// be generated through WindowOpenFrameset() or through 
// new_frameset().

	if (!fs)
	{
	   fs = document.getElementById('ttframeset');
	}

	if (fs) {
		var rowSpl=fs.rows.split(',');
		var t=rowSpl[0];
		var f2=rowSpl[2];
		fs.rows=t+',*,'+f2+','+height+',0,0';
	} else if (parent != window) {
		try {
			parent.fr3_size(height);
		} catch(e) {}
	}
}

function isitframed(writeto) {
	document.forms[0].elements[writeto].value='';

	if (parent.mainframe=="[object]")
		document.forms[0].elements[writeto].value='framed';
}

///////////////////////////////////////////////////////////////////////////////
// The new UI redefines the function new_frameset because this version is not compatible.
if(typeof new_frameset === 'undefined') {
	function new_frameset(bannerSz, bannerSrc, fr1Src, fr2src, bannerScroll, path) {
		var TThtml = GetFramesetHTML(bannerSz, bannerSrc, fr1Src, fr2src, bannerScroll, path);
		document.open();
		document.write('');
		document.write(TThtml);
		document.close();
	}
}

///////////////////////////////////////////////////////////////////////////////
// WindowOpenFrameset
// Similar to "new_frameset()" except this function also opens the new window.
// Using this function can save one or more server roundtrip calls because there
// is no longer a need to also call 'cgi/inline' in the url to create the frameset.
//////////////////////////////////////////////////////////////////////////////
function WindowOpenFrameset(bannerSz, bannerSrc, fr1Src, fr2src, bannerScroll, path, winspecs, title) {

	var TThtml = GetFramesetHTML(bannerSz, bannerSrc, fr1Src, fr2src, bannerScroll, path, title);
	if( winspecs == null ) {
		// Default winspecs.  Let the browser determine the window size. Disable most other features of the window.
		winspecs='directories=no, location=no, menubar=yes, resizable=yes, status=yes, titlebar=yes, toolbar=no';
	}
	var newWin=window.open("","",winspecs);
	if(newWin) {				
		newWin.document.open();
		newWin.document.write('');
		newWin.document.write(TThtml);
		newWin.document.close();
		newWin.document.title='Trade Tech Inc.';
		newWin.focus();		
	}
	else {
		alert("Could not open pop-up window!  Please check browser pop-up settings.");
	}
}

///////////////////////////////////////////////////////////////////////////////
function GetFramesetHTML(bannerSz, bannerSrc, fr1Src, fr2src, bannerScroll, path, title) {
	if ( bannerSrc == null ) bannerSrc = '';
	if ( fr1Src == null ) fr1Src = '';
	if ( fr2src == null ) fr2src = '';
	if (bannerScroll == null || bannerScroll == '') bannerScroll="no";
	if (path == null) path="";
	else if(path == "/cgi") path="/cgi/u"; // don't use "/cgi/ref.html" it just redirects to "cgi/u/ref.html" creating a useless server round-trip call.
	if (path) path +="/";
	if (title == null) title = 'Trade Tech Inc.';

	var TThtml = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/html4/frameset.dtd'>\n";
	TThtml += "<html><head><title>" +title+ "<\/title><\/head>\n";
	TThtml += "<frameset id='ttframeset' name='mainframe' rows="+bannerSz+",*,0,0,0,0 ttid1='' ttid2='' ttid3='' ttid4='' ttid5=''>\n";
	TThtml += "<frame id='banner' name='banner' src='"+bannerSrc+"' marginheight='0'  marginwidth='0' scrolling='"+bannerScroll+"' frameborder='0' noresize=''>\n";
	TThtml += "<frame id='fr1' name='fr1' src='"+fr1Src+"' marginheight='0' marginwidth='0' scrolling='auto' frameborder='0'>\n";
	TThtml += "<frame id='fr2' name='fr2' src='"+fr2src+"' marginheight='1' marginwidth='0' scrolling='auto' frameborder='0' >\n";
	TThtml += "<frame id='fr3' name='fr3' src='' marginheight='1' marginwidth='0' scrolling='auto' frameborder='0' >\n";
	TThtml += "<frame id='hb' name='hb' src='' marginheight='0' marginwidth='0' scrolling='no' frameborder='0' noresize='' >\n";
	TThtml += "<frame id='ref' name='ref' src='"+path+"ref.html' marginheight='0' marginwidth='0' scrolling='no' frameborder='0' noresize=''>\n";
	TThtml += "<\/frameset><\/html>\n";
	
	return TThtml;
}

///////////////////////////////////////////////////////////////////////////////

/*This function takes a string argument
  If this string is not unique for an id, random digits are appended until it is
  a unique ID is then returned as a string
  */
function find_unique_id(start_id) {
	while(document.getElementById(start_id) !== null) {
		start_id += Math.floor(Math.random()*10);
	}
	return start_id;
}

function chngq(pq) {
	if (pq == null) pq="";
	var allservers="";
	if (arguments.length >= 2) allservers=arguments[1];
	var cgi="/cgi/u/dreport?file=Fusers&rec=1&format=chngqual_new";
	if (pq != "") cgi += "&parent_qual="+pq;
	if (allservers != "") cgi += '&allservers='+allservers;
	var popupWin=window.open(cgi,"fr1","status,resizable,width=300,height=100,left=20,top=20");
}

function chngqFEAT(ft) {
	if (ft == null) ft="";
	var popupWin = window.open("/cgi/u/dreport?file=Fusers&sel=lowrec&format=chngqFEAT&feature="+ft,"fr1","status,resizable,width=300,height=100,left=20,top=20");
}

