var browsername = navigator.appName;
var browserversion = navigator.appVersion;
var browsermajor = Number(browserversion.substring(0,browserversion.indexOf('.')+1));

// returns an array that contains the name/value pairs of the url parameters
// array[even_number] = name
// array[odd_number] = value
function parseURL()
{

	var urlThere = ((document.URL.indexOf('?') != -1) ? true : false);
	var urlarr = new Array();
	if (urlThere) {
		var urlstr = document.URL.substring(document.URL.indexOf('?')+1,document.URL.length);
		var urlidx = 0;
		var urlid1 = '=';
		var urlid2 = '&';
		var aindx = -1;
		var tcntr = 1;  // a test control so while loop does not go to excursion

		// this is the loop 
		while (urlstr.length > 0)
		{
			var urllen = urlstr.length;
			var morethanone = urlstr.indexOf(urlid2);

			var tsub = urlstr.substring(urlidx,urlstr.indexOf(urlid1));
			var tval = urlstr.substring(urlstr.indexOf(urlid1)+1, (morethanone == -1 ? urllen : urlstr.indexOf(urlid2)) );

			if (morethanone > 0)
				urlidx = urlstr.indexOf(urlid2)+1;
			else
				urlidx = urllen;

			//urlarr["eval(tsub)"] = tval;
			//alert(urlarr["eval(tsub)"]);
			urlarr[++aindx] = tsub;
			urlarr[++aindx] = tval

			urlstr = urlstr.substring(urlidx,urllen);
		
			++tcntr;
			urlidx = 0;
		}
	}
	return urlarr;
}

// This function test if a text input has data in it
// returns true if data, false otherwise.
// Accept input types of text, file and textarea
function isInputText(input_text)
{
	var rtnflag = false;
	var input_type = input_text.type.toLowerCase();
	var s = allTrim(input_text.value);
	if (( input_type == 'text' || input_type == 'file' || input_type == 'textarea' || input_type == 'password' || input_type == 'hidden') && s.length > 0)
		rtnflag = true;
	return rtnflag;
}

// This function test if all text input is a number
// returns true if all digits, false otherwise.
function isInputInteger(input_text)
{
	var rtnflag = true;
	if (input_text.type.toLowerCase() == 'text' && input_text.value.length > 0)
	{
		var s = allTrim(input_text.value);
		//input_text.value = s;
		var slen = s.length
		for (var i=0; i<slen; i++)
		{
			if (!(s.charAt(i) >= '0' && s.charAt(i) <= '9'))
			{
				rtnflag = false;
				break;
			}
		}
	}
	return rtnflag;
}


// This function removes leading blanks.
function removeLeftBlanks(s)
{
	var nEnd = s.length;
	for (var i=0; i<s.length; i++) 
		if (s.charAt(i) != " " && s.charAt(i) != "\n" && s.charAt(i) != "\r")
			break
	return s.substring(i,nEnd)
}

// Remove leading and trailing blanks.
function allTrim(s)
{
	var rtnstr = removeLeftBlanks(s);
	var lastblank = rtnstr.lastIndexOf(' ');
	if (lastblank > -1)
		rtnstr = rtnstr.substring(0,lastblank);
	return rtnstr;
}

/* This function checks of the text input conforms to email address
true, if the string contains a valid e-mail address which is a string
plus an '@' character followed by another string containing at least 
one '.' and ending in an alpha (non-punctuation) character
false, otherwise.
*/
function isEmail(email_fld)
{
	var rtnflag = false;
	if (email_fld.value == "")
	{
		rtnflag = true;
	}
	else
	{
		// is there a @ and not first, is the .  there and not the first character, 
		// is the combo @. present, last character alphabet
		// dot dot pair in domain || (email_fld.value.indexOf('..') > -1 && email_fld.value.indexOf('..') > email_fld.value.indexOf('@')
		// the underscore in domain || (email_fld.value.indexOf('_') > -1 && email_fld.value.indexOf('_') > email_fld.value.indexOf('@')
		// domain rules (a-z,A-Z,0-9,.,-) at least 3 alphanumeric, cannot start with - or end in -, no spaces
		var email_fld_len = email_fld.value.length;
		var last_char = email_fld.value.substring(email_fld_len -1,email_fld_len).toUpperCase();
		var last_not_AZ = ((last_char >= 'A' && last_char <= 'Z') ? false : true);
		if ( (email_fld.value.indexOf('@') < 1) || (email_fld.value.indexOf('.') < 1) || (email_fld.value.indexOf('@.') != -1) || last_not_AZ)
		{
			// not a valid email format
			email_fld.focus();
		}
		else
		{
			rtnflag = true;
		}
	}
	return rtnflag;
}

// This function counts the number of items (options) selected
// in a select type input (can handle single or multiple)
// returns the number selected.
function cntSelectOption(selectoption)
{
	var rtnint = 0;
	if (selectoption.type.toLowerCase().indexOf('select') > -1)
	{
		if (selectoption.type.toLowerCase().indexOf('select-m') > -1)
		{
			// multi select
			var len = selectoption.length;
			var cnt = 0;
			for (var i=0; i<len; i++)
			{
				if (selectoption.options[i].selected)
					++cnt;
			}
			rtnint = cnt;
		}
		else
		{
			// single select
			rtnint = (selectoption.selectedIndex > -1 ? 1 : 0);
		}
	}
	return rtnint;
}

// This function deselects all options in a single select box.
// returns nothing
function unSelectAll(selectoption)
{
	if (selectoption.type.toLowerCase().indexOf('select') > -1)
	{
			var len = selectoption.length;
			var cnt = 0;
			for (var i=0; i<len; i++)
			{
				selectoption.options[i].selected = false;
			}	
	}
	return null;
}

// This function turns on the select options
function selectAll(selectoption)
{
	if (selectoption.type.toLowerCase().indexOf('select') > -1)
	{
			var len = selectoption.length;
			var cnt = 0;
			for (var i=0; i<len; i++)
			{
				selectoption.options[i].selected = true;
			}	
	}
	return null;
}

// This function puts a text input into a select box and resorts the select option object.
// required input:
// input_data - the text of the new option (or text object)
// selectoption - the select option object
// ------------------------------------------------------
// optional input:
// init_value - the value for the new option value attribute
// select_value - the value (true/false) of the new option selected attribute
function addSelectOption(input_data,selectoption,init_value,select_value)
{
	var input_data_type = typeof(input_data);
	var input_data_len = (input_data_type == "object" ? input_data.value.length : input_data.length);
	if (selectoption.type.toLowerCase().indexOf('select') > -1 &&  input_data_len > 0)
	{
		var optval = (init_value == null ? 0 : init_value);
		var optsel = (select_value == null ? true : select_value);
		var aTmpval = new Array();
		var aTmptxt = new Array();
		var aTmpsel = new Array();
		var aTmpdsl = new Array();
		var aTmpsrt = new Array();
		var iTmpidx = -1;
		for (var i=0; i<selectoption.length; i++)
		{
			aTmpval[++iTmpidx] = selectoption.options[i].value;
			aTmptxt[iTmpidx] = selectoption.options[i].text;
			aTmpsel[iTmpidx] = selectoption.options[i].selected;
			aTmpdsl[iTmpidx] = selectoption.options[i].defaultSelected;
			aTmpsrt[iTmpidx] = selectoption.options[i].text + '\t' + i;
		}
		aTmpval[++iTmpidx] = optval;
		aTmptxt[iTmpidx] = (input_data_type == "object" ? input_data.value : input_data);
		aTmpsel[iTmpidx] = optsel;
		aTmpsrt[iTmpidx] = (input_data_type == "object" ? input_data.value : input_data) + '\t' + selectoption.length;
		++selectoption.length;
		aTmpsrt.sort();
		for (var i=0; i<selectoption.length; i++)
		{
			var idxptr = aTmpsrt[i].lastIndexOf('\t');
			var idx = Number(aTmpsrt[i].substring(idxptr+1));
			selectoption.options[i].value = aTmpval[idx];
			selectoption.options[i].text = aTmptxt[idx];
			selectoption.options[i].selected = aTmpsel[idx];
			selectoption.options[i].defaultSelected = aTmpdsl[idx];
		}
		// this will resize the select box
		//history.go(0);
	}
	return null;
}

// This function will remove all selected items from a select box or
// move selected items of the source select option object to the target
// select option object.
// required input:
// the source select option object
// -----------------------------
// optional input:
// the target select option object (used for a move)
function moveSelectOptions(selectoption_source,selectoption_target)
{
	if (selectoption_source.type.toLowerCase().indexOf('select') > -1)
	{
		var tArrval = new Array();
		var tArrtxt = new Array();
		var tArrsel = new Array();
		var tindx = -1;
		var trgtthere = (selectoption_target == null ? false : true);
		for (var i=0; i<selectoption_source.length; i++)
		{
			var tval = selectoption_source.options[i].value;
			var ttxt = selectoption_source.options[i].text;
			var tsel = selectoption_source.options[i].selected;
			// keep this item in the source select option object
			if (!selectoption_source.options[i].selected)
			{
				tArrval[++tindx] = tval;
				tArrtxt[tindx] = ttxt;
				tArrsel[tindx] = tsel;
			}
			else
				// move the selected into the target select option object
				if (trgtthere)
				{
					addSelectOption(ttxt,selectoption_target,tval,tsel);
				}
		}
		selectoption_source.length = 0;
		for (var i=0; i<tArrval.length; i++)
		{
			var optitem = new Option(tArrtxt[i],tArrval[i]);
			selectoption_source.options[i] = optitem;
		}
		selectoption_source.length = tArrval.length;
	}
	return null;
}


// test if java enabled in browser
function isJavaOn()
{
	var flag = false;
	if (navigator.javaEnabled())
		flag = true;
	return flag;
}

// This is the generic popup window 
function newwin(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 700;
	var w = 750;
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=yes,menu=no,location=no,resizable"';
	//var owindow = window.open("../administration/index.cfm","adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

// This is the popup window used specifically for MyPage Edit
function editmpwin(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 300;
	var w = 730;
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=yes,location=no,resizable,menu=yes"';
	//var owindow = window.open("../administration/index.cfm","adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

// This is the popup window for contact directory (others?)
function newwin3(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 600;
	var w = 650;
	if (majorver >= 4)
	{
		h =  screen.height - Math.round(screen.height / 3);
		w =  screen.width - Math.round(screen.width / 3);
	}
	w = 700;
	h = 450;
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=yes,location=no,resizable,menu=yes,location=yes"';
	//var owindow = window.open("../administration/index.cfm","adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

// This is the popup window used specifically for WorkSpace
function newwin_wkspc(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 750;
	var w = 420;
	if (majorver >= 4)
	{
		h =  Math.round(screen.height / 1.33);
		w =  Math.round(screen.width / 1.33);
	}
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=yes,location=no,resizable,location=no"';
	//var owindow = window.open("../administration/index.cfm","adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

function printwin(file_to_open,winname,ph,pw)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var sh = 25;
	var sw = 25;
	var dh = 500;
	var dw = 750;
	var nh = (ph != null ? ph : dh);
	var nw = (pw != null ? pw : dw);
	if (majorver >= 4)
	{
		sh =  Math.round((screen.height - nh) / 4);
		sw =  Math.round((screen.width - nw) / 2);
	}
	var lwinname = (winname == null ? 'Print_Window' : winname);
	var toolbarstring = '"toolbar=yes,height='+nh+',width='+nw+',top='+sh+',left='+sw+',scrollbars=yes,status=yes,location=no,resizable"';
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));

}


function newwin_vivakos(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 670;
	var w = 400;
	if (majorver >= 4)
	{
		h =  screen.height - Math.round(screen.height / 3);
		w =  screen.width - Math.round(screen.width / 3);
	}
	w = 670;
	h = 400;
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=no,location=no,resizable=no,location=no"';
	//var owindow = window.open("../administration/index.cfm,"adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

function newwin_full(file_to_open,winname) 
{
	var owindow = window.open(file_to_open);
}

function openLink(url,window_title){
	window_title = (window_title == null ? 'External_Link' : window_title);
	window.open(url,window_title);
}

function ViewContentItem(content_item_id,folder_ka_id){
	var token = '<cfoutput>#URLTOKEN#</cfoutput>';
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));		
	var h = 450;
	var w = 620;
	if (majorver >= 4)
	{
		h =  Math.round(screen.height / 1.2);
		w =  Math.round(screen.width / 1.2);
	}	
	where = "/ka/view_content.cfm?content_item_id=" + content_item_id + "&folder_id=" + folder_ka_id + "&in_workspace=True";
	window.open(where,"View_Content_Item","resizable,scrollbars,width="+w+",height="+h+",left=20,top=20")
}

function EditContentItem(content_item_id,folder_ka_id){
	where = "/kad/confirm_and_close.cfm?content_item_id=" + content_item_id + "&folder_ka_id=" + folder_ka_id + "&in_workspace=True";
	window.open(where,"Edit_Content_Item","resizable,scrollbars,width=700,height=616,left=200")
}

function CreateContentItem(folder_ka_id){
	where = "/kad/ka-d1.cfm?content_item_id=0&folder_ka_id=" + folder_ka_id;
	window.open(where,"New_Content_item","resizable,scrollbars,width=700,height=616,left=200")
}
function EditContentAreaHeader(folder_ka_id){
	where = "/administration/ka/admin_ka_modify_step1.cfm?nodeid=" + folder_ka_id + "&area=KA";
	window.open(where,"Edit_Content_Area","resizable,scrollbars,width=940,height=616,left=200")
}
var browsername = navigator.appName;
var browserversion = navigator.appVersion;
var browsermajor = Number(browserversion.substring(0,browserversion.indexOf('.')+1));

// returns an array that contains the name/value pairs of the url parameters
// array[even_number] = name
// array[odd_number] = value
function parseURL()
{

	var urlThere = ((document.URL.indexOf('?') != -1) ? true : false);
	var urlarr = new Array();
	if (urlThere) {
		var urlstr = document.URL.substring(document.URL.indexOf('?')+1,document.URL.length);
		var urlidx = 0;
		var urlid1 = '=';
		var urlid2 = '&';
		var aindx = -1;
		var tcntr = 1;  // a test control so while loop does not go to excursion

		// this is the loop 
		while (urlstr.length > 0)
		{
			var urllen = urlstr.length;
			var morethanone = urlstr.indexOf(urlid2);

			var tsub = urlstr.substring(urlidx,urlstr.indexOf(urlid1));
			var tval = urlstr.substring(urlstr.indexOf(urlid1)+1, (morethanone == -1 ? urllen : urlstr.indexOf(urlid2)) );

			if (morethanone > 0)
				urlidx = urlstr.indexOf(urlid2)+1;
			else
				urlidx = urllen;

			//urlarr["eval(tsub)"] = tval;
			//alert(urlarr["eval(tsub)"]);
			urlarr[++aindx] = tsub;
			urlarr[++aindx] = tval

			urlstr = urlstr.substring(urlidx,urllen);
		
			++tcntr;
			urlidx = 0;
		}
	}
	return urlarr;
}

// This function test if a text input has data in it
// returns true if data, false otherwise.
// Accept input types of text, file and textarea
function isInputText(input_text)
{
	var rtnflag = false;
	var input_type = input_text.type.toLowerCase();
	var s = allTrim(input_text.value);
	if (( input_type == 'text' || input_type == 'file' || input_type == 'textarea' || input_type == 'password' || input_type == 'hidden') && s.length > 0)
		rtnflag = true;
	return rtnflag;
}

// This function test if all text input is a number
// returns true if all digits, false otherwise.
function isInputInteger(input_text)
{
	var rtnflag = true;
	if (input_text.type.toLowerCase() == 'text' && input_text.value.length > 0)
	{
		var s = allTrim(input_text.value);
		//input_text.value = s;
		var slen = s.length
		for (var i=0; i<slen; i++)
		{
			if (!(s.charAt(i) >= '0' && s.charAt(i) <= '9'))
			{
				rtnflag = false;
				break;
			}
		}
	}
	return rtnflag;
}


// This function removes leading blanks.
function removeLeftBlanks(s)
{
	var nEnd = s.length;
	for (var i=0; i<s.length; i++) 
		if (s.charAt(i) != " " && s.charAt(i) != "\n" && s.charAt(i) != "\r")
			break
	return s.substring(i,nEnd)
}

// Remove leading and trailing blanks.
function allTrim(s)
{
	var rtnstr = removeLeftBlanks(s);
	var lastblank = rtnstr.lastIndexOf(' ');
	if (lastblank > -1)
		rtnstr = rtnstr.substring(0,lastblank);
	return rtnstr;
}

/* This function checks of the text input conforms to email address
true, if the string contains a valid e-mail address which is a string
plus an '@' character followed by another string containing at least 
one '.' and ending in an alpha (non-punctuation) character
false, otherwise.
*/
function isEmail(email_fld)
{
	var rtnflag = false;
	if (email_fld.value == "")
	{
		rtnflag = true;
	}
	else
	{
		// is there a @ and not first, is the .  there and not the first character, 
		// is the combo @. present, last character alphabet
		// dot dot pair in domain || (email_fld.value.indexOf('..') > -1 && email_fld.value.indexOf('..') > email_fld.value.indexOf('@')
		// the underscore in domain || (email_fld.value.indexOf('_') > -1 && email_fld.value.indexOf('_') > email_fld.value.indexOf('@')
		// domain rules (a-z,A-Z,0-9,.,-) at least 3 alphanumeric, cannot start with - or end in -, no spaces
		var email_fld_len = email_fld.value.length;
		var last_char = email_fld.value.substring(email_fld_len -1,email_fld_len).toUpperCase();
		var last_not_AZ = ((last_char >= 'A' && last_char <= 'Z') ? false : true);
		if ( (email_fld.value.indexOf('@') < 1) || (email_fld.value.indexOf('.') < 1) || (email_fld.value.indexOf('@.') != -1) || last_not_AZ)
		{
			// not a valid email format
			email_fld.focus();
		}
		else
		{
			rtnflag = true;
		}
	}
	return rtnflag;
}

// This function counts the number of items (options) selected
// in a select type input (can handle single or multiple)
// returns the number selected.
function cntSelectOption(selectoption)
{
	var rtnint = 0;
	if (selectoption.type.toLowerCase().indexOf('select') > -1)
	{
		if (selectoption.type.toLowerCase().indexOf('select-m') > -1)
		{
			// multi select
			var len = selectoption.length;
			var cnt = 0;
			for (var i=0; i<len; i++)
			{
				if (selectoption.options[i].selected)
					++cnt;
			}
			rtnint = cnt;
		}
		else
		{
			// single select
			rtnint = (selectoption.selectedIndex > -1 ? 1 : 0);
		}
	}
	return rtnint;
}

// This function deselects all options in a single select box.
// returns nothing
function unSelectAll(selectoption)
{
	if (selectoption.type.toLowerCase().indexOf('select') > -1)
	{
			var len = selectoption.length;
			var cnt = 0;
			for (var i=0; i<len; i++)
			{
				selectoption.options[i].selected = false;
			}	
	}
	return null;
}

// This function turns on the select options
function selectAll(selectoption)
{
	if (selectoption.type.toLowerCase().indexOf('select') > -1)
	{
			var len = selectoption.length;
			var cnt = 0;
			for (var i=0; i<len; i++)
			{
				selectoption.options[i].selected = true;
			}	
	}
	return null;
}

// This function puts a text input into a select box and resorts the select option object.
// required input:
// input_data - the text of the new option (or text object)
// selectoption - the select option object
// ------------------------------------------------------
// optional input:
// init_value - the value for the new option value attribute
// select_value - the value (true/false) of the new option selected attribute
function addSelectOption(input_data,selectoption,init_value,select_value)
{
	var input_data_type = typeof(input_data);
	var input_data_len = (input_data_type == "object" ? input_data.value.length : input_data.length);
	if (selectoption.type.toLowerCase().indexOf('select') > -1 &&  input_data_len > 0)
	{
		var optval = (init_value == null ? 0 : init_value);
		var optsel = (select_value == null ? true : select_value);
		var aTmpval = new Array();
		var aTmptxt = new Array();
		var aTmpsel = new Array();
		var aTmpdsl = new Array();
		var aTmpsrt = new Array();
		var iTmpidx = -1;
		for (var i=0; i<selectoption.length; i++)
		{
			aTmpval[++iTmpidx] = selectoption.options[i].value;
			aTmptxt[iTmpidx] = selectoption.options[i].text;
			aTmpsel[iTmpidx] = selectoption.options[i].selected;
			aTmpdsl[iTmpidx] = selectoption.options[i].defaultSelected;
			aTmpsrt[iTmpidx] = selectoption.options[i].text + '\t' + i;
		}
		aTmpval[++iTmpidx] = optval;
		aTmptxt[iTmpidx] = (input_data_type == "object" ? input_data.value : input_data);
		aTmpsel[iTmpidx] = optsel;
		aTmpsrt[iTmpidx] = (input_data_type == "object" ? input_data.value : input_data) + '\t' + selectoption.length;
		++selectoption.length;
		aTmpsrt.sort();
		for (var i=0; i<selectoption.length; i++)
		{
			var idxptr = aTmpsrt[i].lastIndexOf('\t');
			var idx = Number(aTmpsrt[i].substring(idxptr+1));
			selectoption.options[i].value = aTmpval[idx];
			selectoption.options[i].text = aTmptxt[idx];
			selectoption.options[i].selected = aTmpsel[idx];
			selectoption.options[i].defaultSelected = aTmpdsl[idx];
		}
		// this will resize the select box
		//history.go(0);
	}
	return null;
}

// This function will remove all selected items from a select box or
// move selected items of the source select option object to the target
// select option object.
// required input:
// the source select option object
// -----------------------------
// optional input:
// the target select option object (used for a move)
function moveSelectOptions(selectoption_source,selectoption_target)
{
	if (selectoption_source.type.toLowerCase().indexOf('select') > -1)
	{
		var tArrval = new Array();
		var tArrtxt = new Array();
		var tArrsel = new Array();
		var tindx = -1;
		var trgtthere = (selectoption_target == null ? false : true);
		for (var i=0; i<selectoption_source.length; i++)
		{
			var tval = selectoption_source.options[i].value;
			var ttxt = selectoption_source.options[i].text;
			var tsel = selectoption_source.options[i].selected;
			// keep this item in the source select option object
			if (!selectoption_source.options[i].selected)
			{
				tArrval[++tindx] = tval;
				tArrtxt[tindx] = ttxt;
				tArrsel[tindx] = tsel;
			}
			else
				// move the selected into the target select option object
				if (trgtthere)
				{
					addSelectOption(ttxt,selectoption_target,tval,tsel);
				}
		}
		selectoption_source.length = 0;
		for (var i=0; i<tArrval.length; i++)
		{
			var optitem = new Option(tArrtxt[i],tArrval[i]);
			selectoption_source.options[i] = optitem;
		}
		selectoption_source.length = tArrval.length;
	}
	return null;
}


// test if java enabled in browser
function isJavaOn()
{
	var flag = false;
	if (navigator.javaEnabled())
		flag = true;
	return flag;
}

// This is the generic popup window 
function newwin(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 700;
	var w = 750;
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=yes,menu=no,location=no,resizable"';
	//var owindow = window.open("../administration/index.cfm","adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

// This is the popup window used specifically for MyPage Edit
function editmpwin(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 300;
	var w = 730;
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=yes,location=no,resizable,menu=yes"';
	//var owindow = window.open("../administration/index.cfm","adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

// This is the popup window for contact directory (others?)
function newwin3(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 600;
	var w = 650;
	if (majorver >= 4)
	{
		h =  screen.height - Math.round(screen.height / 3);
		w =  screen.width - Math.round(screen.width / 3);
	}
	w = 700;
	h = 450;
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=yes,location=no,resizable,menu=yes,location=yes"';
	//var owindow = window.open("../administration/index.cfm","adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

// This is the popup window used specifically for WorkSpace
function newwin_wkspc(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 750;
	var w = 420;
	if (majorver >= 4)
	{
		h =  Math.round(screen.height / 1.33);
		w =  Math.round(screen.width / 1.33);
	}
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=yes,location=no,resizable,location=no"';
	//var owindow = window.open("../administration/index.cfm","adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

function printwin(file_to_open,winname,ph,pw)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var sh = 25;
	var sw = 25;
	var dh = 500;
	var dw = 750;
	var nh = (ph != null ? ph : dh);
	var nw = (pw != null ? pw : dw);
	if (majorver >= 4)
	{
		sh =  Math.round((screen.height - nh) / 4);
		sw =  Math.round((screen.width - nw) / 2);
	}
	var lwinname = (winname == null ? 'Print_Window' : winname);
	var toolbarstring = '"toolbar=yes,height='+nh+',width='+nw+',top='+sh+',left='+sw+',scrollbars=yes,status=yes,location=no,resizable"';
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));

}


function newwin_vivakos(file_to_open,winname)
{
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));
	var h = 670;
	var w = 400;
	if (majorver >= 4)
	{
		h =  screen.height - Math.round(screen.height / 3);
		w =  screen.width - Math.round(screen.width / 3);
	}
	w = 670;
	h = 400;
	var lwinname = (winname == null ? 'newwindow' : winname);
	var toolbarstring = '"toolbar=no,height='+h+',width='+w+',scrollbars=yes,status=no,location=no,resizable=no,location=no"';
	//var owindow = window.open("../administration/index.cfm,"adminwin",eval(toolbarstring));
	var owindow = window.open(file_to_open,lwinname,eval(toolbarstring));
	//owindow.onblur = owindow.close;
}

function newwin_full(file_to_open,winname) 
{
	var owindow = window.open(file_to_open);
}

function openLink(url,window_title){
	window_title = (window_title == null ? 'External_Link' : window_title);
	window.open(url,window_title);
}

function ViewContentItem(content_item_id,folder_ka_id){
	var token = '<cfoutput>#URLTOKEN#</cfoutput>';
	var appver = navigator.appVersion;
	var majorver = appver.substring(0,appver.indexOf('.'));		
	var h = 450;
	var w = 620;
	if (majorver >= 4)
	{
		h =  Math.round(screen.height / 1.2);
		w =  Math.round(screen.width / 1.2);
	}	
	where = "/ka/view_content.cfm?content_item_id=" + content_item_id + "&folder_id=" + folder_ka_id + "&in_workspace=True";
	window.open(where,"View_Content_Item","resizable,scrollbars,width="+w+",height="+h+",left=20,top=20")
}

function EditContentItem(content_item_id,folder_ka_id){
	where = "/kad/confirm_and_close.cfm?content_item_id=" + content_item_id + "&folder_ka_id=" + folder_ka_id + "&in_workspace=True";
	window.open(where,"Edit_Content_Item","resizable,scrollbars,width=700,height=616,left=200")
}

function CreateContentItem(folder_ka_id){
	where = "/kad/ka-d1.cfm?content_item_id=0&folder_ka_id=" + folder_ka_id;
	window.open(where,"New_Content_item","resizable,scrollbars,width=700,height=616,left=200")
}
function EditContentAreaHeader(folder_ka_id){
	where = "/administration/ka/admin_ka_modify_step1.cfm?nodeid=" + folder_ka_id + "&area=KA";
	window.open(where,"Edit_Content_Area","resizable,scrollbars,width=940,height=616,left=200")
}


// The functions BELOW this line come from the join_form.cfm before re-skin on 1/13/2010
	function isEmailAddr(email)
	{
	  var result = false;
	  var theStr = new String(email);
	  var index = theStr.indexOf("@");
	  if (index > 0)
	  {
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	  }
	  return result;
	}
	
	function validRequired(formField,fieldLabel)
	{
		var result = true;
		
		if (formField.value == "")
		{
			alert('Please enter a value for the "' + fieldLabel +'" field.');
			formField.focus();
			result = false;
		}		
		return result;
	}
	
	function allDigits(str)
	{
		return inValidCharSet(str,"-0123456789");
	}
	
	function inValidCharSet(str,charset)
	{
		var result = true;
	
		// Note: doesn't use regular expressions to avoid early Mac browser bugs	
		for (var i=0;i<str.length;i++)
			if (charset.indexOf(str.substr(i,1))<0)
			{
				result = false;
				break;
			}		
		return result;
	}
	
	function validEmail(formField,fieldLabel,required)
	{
		var result = true;
		
		if (required && !validRequired(formField,fieldLabel))
			result = false;
	
		if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
		{
			alert("Please enter a complete email address in the form: yourname@yourdomain.com");
			formField.focus();
			result = false;
		}	   
	  return result;	
	}
	
	function validNum(formField,fieldLabel,required)
	{
		var result = true;
	
		if (required && !validRequired(formField,fieldLabel))
			result = false;
	  
		if (result)
		{
			if (!allDigits(formField.value))
			{
				alert('Please enter a number for the "' + fieldLabel +'" field.');
				formField.focus();		
				result = false;
			}
		} 		
		return result;
	}
	
	
	function validInt(formField,fieldLabel,required)
	{
		var result = true;
	
		if (required && !validRequired(formField,fieldLabel))
			result = false;	  
		if (result)
		{
			var num = parseInt(formField.value,10);
			if (isNaN(num))
			{
				alert('Please enter a number for the "' + fieldLabel +'" field.');
				formField.focus();		
				result = false;
			}
		} 		
		return result;
	}
	
	
	function validDate(formField,fieldLabel,required)
	{
		var result = true;
	
		if (required && !validRequired(formField,fieldLabel))
			result = false;
	  
		if (result)
		{
			var elems = formField.value.split("/");			
			result = (elems.length == 3); // should be three components			
			if (result)
			{
				var month = parseInt(elems[0],10);
				var day = parseInt(elems[1],10);
				var year = parseInt(elems[2],10);
				result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
						 allDigits(elems[1]) && (day > 0) && (day < 32) &&
						 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
			}			
			if (!result)
			{
				alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
				formField.focus();		
			}
		} 		
		return result;
	}
	
	function validateForm(theForm)
	{
		// Customize these calls for your form	
		// Start					
		if (!validRequired(theForm.name,"Contact Name"))
			return false;
		
		if (!validNum(theForm.phone,"Contact Phone Number",true))
			return false;
		
		if (!validEmail(theForm.email,"Contact Email",true))
			return false;
			
		if (!validRequired(theForm.DealerName,"Dealership Name"))
			return false;
		
		if (!validRequired(theForm.DealerVehAvg,"Dealership New Vehicle average sales per month (units)"))
			return false;
		if (!validRequired(theForm.category,"NADA or ATD"))
		return false;		
		//  End		
		return true;
	}
	
	
	var arrayData = new Array(); 
	 
	arrayData[0]	= 'NADA|Acura|' 
	arrayData[1]	= 'NADA|Audi|' 
	arrayData[2]	= 'NADA|BMW|' 
	arrayData[3]	= 'NADA|Buick|' 
	arrayData[4]	= 'NADA|Cadillac|' 
	arrayData[5]	= 'NADA|Chevrolet|' 
	arrayData[6]	= 'NADA|Chrysler|' 
	arrayData[7]	= 'NADA|Daewoo|' 
	arrayData[8]	= 'NADA|Dodge|' 
	arrayData[9]	= 'NADA|Ford|' 
	arrayData[10]	= 'NADA|GMC Light Truck|' 
	arrayData[11]	= 'NADA|Honda|' 
	arrayData[12]	= 'NADA|Hummer|' 
	arrayData[13]	= 'NADA|Hyundai|' 
	arrayData[14]	= 'NADA|Infiniti|' 
	arrayData[15]	= 'NADA|Isuzu|' 
	arrayData[16]	= 'NADA|Jaguar|' 
	arrayData[17]	= 'NADA|Jeep|' 
	arrayData[18]	= 'NADA|Kia|' 
	arrayData[19]	= 'NADA|Land Rover|' 
	arrayData[20]	= 'NADA|Lexus|' 
	arrayData[21]	= 'NADA|Lincoln Mercury|' 
	arrayData[22]	= 'NADA|Mazda|' 
	arrayData[23]	= 'NADA|Mercedes-Benz|' 
	arrayData[24]	= 'NADA|Mercury|' 
	arrayData[25]	= 'NADA|Mini|' 
	arrayData[26]	= 'NADA|Mitsubishi|' 
	arrayData[27]	= 'NADA|Nissan|'
	arrayData[28]	= 'NADA|Oldsmobile|'
	arrayData[29]	= 'NADA|Other Car Franchise|'
	arrayData[30]	= 'NADA|Pontiac|'
	arrayData[31]	= 'NADA|Porsche|'
	arrayData[32]	= 'NADA|Saab|'
	arrayData[33]	= 'NADA|Saturn|'
	arrayData[34]	= 'NADA|Scion|'
	arrayData[35]	= 'NADA|Subaru|'
	arrayData[36]	= 'NADA|Suzuki|'
	arrayData[37]	= 'NADA|Toyota|'
	arrayData[38]	= 'NADA|Volkswagen|'
	arrayData[39]	= 'NADA|Volvo|'
	arrayData[40]	= 'ATD|Autocar|'
	arrayData[41]	= 'ATD|Bering|'
	arrayData[42]	= 'ATD|Chevy Medium Truck|'
	arrayData[43]	= 'ATD|Crane Carrier|'
	arrayData[44]	= 'ATD|Diamond Reo Truck|'
	arrayData[45]	= 'ATD|Ford Heavy Truck|'
	arrayData[46]	= 'ATD|Ford Medium Truck|'
	arrayData[47]	= 'ATD|Freightliner Heavy Truck|'
	arrayData[48]	= 'ATD|Freightliner Medium Truck|'
	arrayData[49]	= 'ATD|GMD Medium Truck|'
	arrayData[50]	= 'ATD|Hino Truck|'
	arrayData[51]	= 'ATD|HME Truck|'
	arrayData[52]	= 'ATD|Hyundai Truck|'
	arrayData[53]	= 'ATD|International Heavy Truck|'
	arrayData[54]	= 'ATD|International Medium Truck|'
	arrayData[55]	= 'ATD|Kenworth Heavy Truck|'
	arrayData[56]	= 'ATD|Kenworth Medium Truck|'
	arrayData[57]	= 'ATD|Mack Truck|'
	arrayData[58]	= 'ATD|Marmon Truck|'
	arrayData[59]	= 'ATD|Mitsubishi Truck|'
	arrayData[60]	= 'ATD|Oshkosh Truck|'
	arrayData[61]	= 'ATD|Other Truck Franchise|'
	arrayData[62]	= 'ATD|Peterbuilt Heavy Truck|'
	arrayData[63]	= 'ATD|Peterbuilt Medium Truck|'
	arrayData[64]	= 'ATD|Sterling Truck|'
	arrayData[65]	= 'ATD|UD Truck|'
	arrayData[66]	= 'ATD|Volvo Truck|'
	arrayData[67]	= 'ATD|Western Star Truck|'
	arrayData[68]	= 'ATD|Winnebago Truck|'
	 
	function populateData( name ) { 
	 
		select	= window.document.form.SubCategory; 
		string	= ""; 
	 
			// 0 - will display the new options only 
			// 1 - will display the first existing option plus the new options 
	 
		count	= 0; 
	 
			// Clear the old list (above element 0) 
	 
		select.options.length = count; 
	 
			// Place all matching categories into Options. 
	 
		for( i = 0; i < arrayData.length; i++ ) { 
			string = arrayData[i].split( "|" ); 
			if( string[0] == name ) { 
				select.options[count++] = new Option( string[1] ); 
			} 
		} 
	 
			// Set which option from subcategory is to be selected 	 
	//	select.options.selectedIndex = 2; 	 
			// Give subcategory focus and select it	 
	//	select.focus();	 
	}