var CurrentTableIndex = "";

function GoToItem(id)
{
GoTo("Item.aspx?ItemId=" + id);
}


function ViewPurchases()
{
GoTo("RPTTransaction.aspx");
}

function AdvancedSearch(url, show, width, height)
{
	MaximizeSearch();
}

function RemoveTR(td)
{
	if (td != null)
	{
		td.parentNode.style.display = "none";
	}
}
function AddToFavorite(profileTypeId)
{
	if (profileTypeId == null)
		profileTypeId = "1201";
	ShowDialog("../Dialogs/AddToFavorite.aspx?Link=" + escape(window.location) + "&ProfileTypeId=" + profileTypeId + "&Title=" + escape(document.title),0,1,0,0,0,300,102,"");
}
function CompleteJob(taskTypeId, itemId)
{
	ShowDialog("../Dialogs/CompleteTask.aspx?ItemId=" + itemId + "&TaskTypeId=" + taskTypeId ,0,1,0,0,0,300,132,"");
}
function DownloadFile(taskTypeId, itemId)
{
	window.location = "../Pages/DownloadFile.aspx?ItemId=" + itemId + "&TaskTypeId=" + taskTypeId;
}
function GetDDLText(ctrl, defaultVal, ignoreFirst)
{
	if ((!ignoreFirst || ctrl.selectedIndex > 0) && ctrl.selectedIndex != -1)
		return ctrl.options[ctrl.selectedIndex].text;
	return defaultVal;
}
function TabClick(td)
{
	var tabName = td.className.substr(0, 5);
	var ndList = td.parentNode.childNodes;
	for(var i = 0; i < ndList.length; i++)
	{
		newTd = ndList[i];
		if (newTd != td)
		{
			newTd.className = tabName + "MOU";
		}
		else
		{
			newTd.className = tabName + "SEL";
		}
	}
}
function TabMOU(td)
{
	if (td.className.substr(5,3) != "SEL")
	{
		td.className = td.className.substr(0, 5) + "MOU";
	}
}
function TabMOV(td)
{
	if (td.className.substr(5,3) != "SEL")
	{
		td.className = td.className.substr(0, 5) + "MOV";
	}
}

function PageLoad()
{
	InitPage();
}

function InitPage()
{
	if (window.frameElement != null)
	{
		//window.frameElement.height = document.body.scrollHeight;
		//window.frameElement.width = document.body.scrollWidth;
	}
}
function SetTableIndex(idx)
{
	CurrentTableIndex = idx;
	if (document.frm.TableIndex != null)
		document.frm.TableIndex.value = idx;
}
function LP(url)
{
	window.parent.location = url;
}

function OP(url)
{
	window.open(url);
}

function GetRadioOptValue(opt)
{
	if (opt == null)
		return null;
	for(var i = 0; i < opt.length; i++)
	{
		if (opt[i].checked)
			return opt[i].value;
	}
	return null;
}
function IsLoggedIn()
{
	if (AWGLoggedIn == true)
		return true;
	else
		return false;
}
function ShowDialog(url, cache, center, scroll, left, top, width, height, advancedFeatures)
{
	if (cache == 0)
	{
		var d = new Date();
		if (url.indexOf('?') == -1)
			url = url + "?pageversion=" + d.getTime();
		else
			url = url + "&pageversion=" + d.getTime();
	}
	if (center == 1)
	{
		left = (screen.availWidth - width)/2;
		top = (screen.availHeight - height)/2;
	}
	var features = "toolbar=0,scrollbars=" + scroll + ",left=" + left + ",top=" + top + ",height=" + height + ",width=" + width + "";
	if (advancedFeatures != "")
		features = features + "," + advancedFeatures;
	window.open(url, "", features);
}

function GoTo(url)
{
	window.location = url;
}

function RefreshPage()
{
	window.location = AWGRawLink;
}

function Printable()
{
	window.location = AWGPrintableLink;
}

function CancelAction()
{
	window.location = "CancelAction.aspx";
}

function InitSections()
{
	var cpage = getCookie('SelectedPage');
	var sect = getCookie('SelectedPageTab');
	if (sect == null || sect == 'null' || cpage != window.location.pathname + '?PageAction=' + AWGPageAction)
	{
		ShowAllSections();
	}
	else
	{
		ShowSection(sect);
	}
}
function ShowAllSections()
{
	if (document.getElementById("SEH_All") == null)
		return;
	document.getElementById("SEH_All").className = "TabSelected";
	var arr = AWGPageSections.split(",");
	for(var i=0; i < arr.length; i++)
	{
		var secname = "SEC_" + arr[i];
		var sehname = "SEH_" + arr[i];
		var setname = "SET_" + arr[i];
		if (document.getElementById(secname) != null)
			document.getElementById(secname).style.display = "inline";
		if (document.getElementById(sehname) != null)
			document.getElementById(sehname).className = "Tab";
		if (document.getElementById(setname) != null)
			document.getElementById(setname).style.display = "inline";
	}
	setCookie('SelectedPage');
	setCookie('SelectedPageTab', null);
}

function ShowSection(section)
{
	if (document.getElementById("SEH_All") == null)
		return;
	var arr = AWGPageSections.split(",");
	document.getElementById("SEH_All").className = "Tab";
	for(var i=0; i < arr.length; i++)
	{
		var secname = "SEC_" + arr[i];
		var sehname = "SEH_" + arr[i];
		var setname = "SET_" + arr[i];
		if (arr[i] == section)
		{
			if (document.getElementById(secname) != null)
				document.getElementById(secname).style.display = "inline";
			if (document.getElementById(sehname) != null)
				document.getElementById(sehname).className = "TabSelected";
			if (document.getElementById(setname) != null)
				document.getElementById(setname).style.display = "none";
		}
		else
		{
			if (document.getElementById(secname) != null)
				document.getElementById(secname).style.display = "none";
			if (document.getElementById(sehname) != null)
				document.getElementById(sehname).className = "Tab";
			if (document.getElementById(setname) != null)
				document.getElementById(setname).style.display = "inline";
		}
	}
	setCookie('SelectedPage', window.location.pathname + '?PageAction=' + AWGPageAction);
	setCookie('SelectedPageTab', section);
}

/*
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name, defaultVal)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return defaultVal;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    var val = unescape(dc.substring(begin + prefix.length, end));
    if (val == null || val == "")
		return defaultVal;
	else
		return val;
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function SelectOrDeselectAll(ctrl)
{
	if (ctrl == null)
		ctrl = document.frm.chkSelectAll;
	var chkName = 'SIDList' + CurrentTableIndex;
	for(i=0;i< document.frm.length;i++)
	{
		e=document.frm.elements[i];
		if (e.type=='checkbox' && e.name == chkName)
		{
			if (ctrl.checked)
				e.checked=true;	
			else
				e.checked=false;
		}
	}
}

function CheckCount()
{
	var count = 0;
	var chkName = 'SIDList' + CurrentTableIndex;
	for(i=0;i< document.frm.length;i++)
	{
		e=document.frm.elements[i];
		if (e.type=='checkbox' && e.name == chkName)
		{
			if (e.checked)
				count++;
		}
	}
	return count;
}

// QueryString
function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}

function QueryString_Set_Ctrl(key, ctrl)
{
	if (ctrl != null)
		QueryString_Set(key, ctrl.value);
}
function QueryString_Set(key, value)
{
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			QueryString.values[i] = value;
			return;
		}
	}
	QueryString.keys[QueryString.keys.length] = key;
	QueryString.values[QueryString.values.length] = value;		
}

QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}
}



function GetUrl()
{
	url = window.location.protocol + "//" + window.location.host + window.location.pathname;
	if (QueryString.keys.length > 0)
	{
		for (var i=0;i<QueryString.keys.length;i++)
		{
			if (i == 0)
			{
				url = url + "?" + QueryString.keys[i] + "=" + QueryString.values[i];
			}
			else
			{
				url = url + "&" + QueryString.keys[i] + "=" + QueryString.values[i];
			}
		}
	}
	return url;
}

function replace(s, t, u) {
	i = s.indexOf(t);
	r = "";
	if (i == -1) return s;
	r += s.substring(0,i) + u;
	if ( i + t.length < s.length)
		r += replace(s.substring(i + t.length, s.length), t, u);
	return r;
}

function HMenuMouseOver(menuId, itemId, bHover)
{
	var is = igmenu_getItemById(itemId);
	var ms = igmenu_getMenuById(menuId);
	//igmenu_showMenu(is.Id);
}

var ShowPopUpMenuEnabled = false;
// action popup menu
function ShowPopUpMenu(mnuName)
{
if (mnuName == null)
	mnuName = 'PopupMenu';
var parentTop = 0;
var parentLeft = 0;
if (window.frameElement != null)
{
	parentTop = document.body.getClientRects()[0].top;	
	parentLeft = document.body.getClientRects()[0].left;	
}
igmenu_hideMenu('PageHeaderHMenu', window.event);
var obj = null;
if (window.event == null)
{
	obj = document.getElementById("BtnMainAction");
}
else
{
	obj = event.srcElement;
}

if (obj != null)
{
x = obj.getClientRects()[0].right-1 + document.body.scrollLeft - parentLeft;
y = obj.getClientRects()[0].top-1 + document.body.scrollTop - parentTop;
ShowPopUpMenuEnabled = true;
var str = "ShowPopUpMenuNow('" + mnuName + "', " + x + ", " + y + ");";
window.setTimeout(str, 100);
event.returnValue = false;
event.cancelBubble=true;
}
}

function ShowPopUpMenuNow(mnuName, x, y)
{
	if (ShowPopUpMenuEnabled)
	{
		igmenu_showMenu(mnuName, null, x, y);
	}
}

function HidePopUpMenu()
{
	ShowPopUpMenuEnabled = false;
}
// sort an infragistics grid
function SortTable(v1, v2, v3)
{
	var col = igtbl_getColumnById(v2).Key;
	var sortIndicator = igtbl_getColumnById(v2).SortIndicator;
	if (col != "" && sortIndicator != 3)
	{
			val = QueryString("SortColumn");
			if (val != null && val.indexOf(col) == 0)
			{
				if (val.indexOf("ASC") > 0)
					val = replace(val, "ASC", "DESC");
				else if (val.indexOf("DESC") > 0)
					val = replace(val, "DESC", "ASC");
				else
					val = val + "+DESC";
				col = val;
			}
		QueryString_Set("SortColumn", col);
		window.location = GetUrl();
	}
}

function SortResults(col)
{
	if (col != "")
	{
			val = QueryString("SortColumn");
			if (val != null && val.indexOf(col) == 0)
			{
				if (val.indexOf("ASC") > 0)
					val = replace(val, "ASC", "DESC");
				else if (val.indexOf("DESC") > 0)
					val = replace(val, "DESC", "ASC");
				else
					val = val + "+DESC";
				col = val;
			}
		QueryString_Set("SortColumn", col);
		window.location = GetUrl();
	}
}

function ExportTable(action)
{
	var currentTime = new Date();
	var ver = currentTime.getTime();
	QueryString_Set("Ver", ver);
	document.frm.action = GetUrl();
	if (action == "ExportHTML")
		document.frm.target = "_blank";
	document.frm.AWGFormAction.value = action;
	document.frm.submit();
	document.frm.target = "_self";
}

function FormAction(action, minSelection, confirmMsg)
{
	var selected = CheckCount();
	if (minSelection == -1 && selected < 1)
	{
		alert("Please select one or more items by clicking on the checkboxes next to the items.");
		return;
	}
	if (minSelection == 1 && selected != 1)
	{
		alert("Please select only one item by clicking on the checkbox next to an item.");
		return;
	}
	
	if (confirmMsg)
	{
		if (!window.confirm(confirmMsg))
			return;
	}
	document.frm.AWGFormAction.value = action;
	document.frm.submit();
}

function FormReset()
{	
	if (window.confirm('Are you sure you want to reset the form?'))
		document.frm.reset();
}

function CustomizeTableView()
{
	ShowDialog('CustomizeView.aspx', 0, 1, 0, 0, 0, 560, 356, "");
}

function ValidateField(ctrl, ftype)
{
	if (ftype == 1)
	{	
		ExtractNumber(ctrl, 0, true);
	}
	if (ftype == 2)
	{	
		ExtractNumber(ctrl, 2, true);
	}
}

function ValidateKey(ctrl, ftype)
{
	if (ftype == 1)
	{	
		return BlockNonNumbers(ctrl, window.event, false, true);
	}
	if (ftype == 2)
	{	
		return BlockNonNumbers(ctrl, window.event, true, true);
	}
}

function ExtractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function BlockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function GridDblClick(grid, cell)
{
	clipboardData.setData("Text", document.getElementById(cell).innerText);
	alert("'" + document.getElementById(cell).innerText + "' copied to clipboard");
}

function ChangeRPP(val)
{
	QueryString_Set("CurrentPage", "1");
	QueryString_Set("Records", val);
	window.location = GetUrl();	
}

function ChangePage(val)
{
	QueryString_Set("CurrentPage", val);
	window.location = GetUrl();	
}

function ClearList(list) 
{
	var i = 0;
	var o = list.options;

	for (i = o.length; i >= 0; --i)
		o[i] = null;
}

function AddElement(list, text_in, value_in)
{
	var o = list.options;
	var nIdx;
	if (o.length < 0) //IE for Mac 4.5 sets length to -1 if list is empty
		nIdx = 0;
	else
		nIdx = o.length;
		
	o[nIdx] = new Option(text_in, value_in);
}


function AddElementAtPos(list, pos, text_in, value_in)
{
	var o = list.options;
	var nIdx = 0;

	if ((pos < 0) || (pos > o.length))
		return;

	AddElement(list, '', '');
	for (nIdx = o.length - 1; nIdx > pos; nIdx--)
	{
		o[nIdx].text = o[nIdx - 1].text;
		o[nIdx].value = o[nIdx - 1].value;
	}
	o[pos] = new Option(text_in, value_in);
}


function SetDefaultByText(list, text_in)
{
	with (list)
		{
		for (var i = 0; i < (options.length); i++)
				{
				if (options[i].text == text_in)
					{
					selectedIndex = i;
					return;
					}
				}
		}
}


function SetDefaultByValue(list, value_in)
{
	with (list)
	{
	for (var i = 0; i < (options.length); i++)
		{
		if (options[i].value == value_in)
			{
			selectedIndex = i;
			return;
			}
		}
	}
}
var DomDocumentPrefix = null;
// used to find the Automation server name
function GetDomDocumentPrefix() {
	if (DomDocumentPrefix != null)
		return DomDocumentPrefix;
	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
	var o;
	for (var i = 0; i < prefixes.length; i++) {
		try {
			// try to create the objects
			o = new ActiveXObject(prefixes[i] + ".DomDocument");
			DomDocumentPrefix = prefixes[i];
			return DomDocumentPrefix;
		}
		catch (ex) {};
	}
}

function GetXmlHttpPrefix() {
	if (getXmlHttpPrefix.prefix)
		return getXmlHttpPrefix.prefix;
	
	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
	var o;
	for (var i = 0; i < prefixes.length; i++) {
		try {
			// try to create the objects
			o = new ActiveXObject(prefixes[i] + ".XmlHttp");
			return getXmlHttpPrefix.prefix = prefixes[i];
		}
		catch (ex) {};
	}
	
	throw new Error("Could not find an installed XML parser");
}

function GetXmlHTTP()
{
	if(typeof XMLHttpRequest!="undefined"){
		return new XMLHttpRequest();
	}
	else if(typeof ActiveXObject != "undefined")
	{
		try{
			var xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			return xmlhttp;
		}
		catch(e)
		{
			return null;
		}
	}
	return null;
}

function GetXmlDoc()
{
	if (document.implementation && document.implementation.createDocument) {
		var doc = document.implementation.createDocument("", "", null);			
		return doc;
	}
	if (window.ActiveXObject)
		return new ActiveXObject(GetDomDocumentPrefix() + ".DomDocument");
	return null;
}

function GetVer()
{
	var d = new Date();
	return d.getTime()
}

var ajaxReq;
var ajaxCtrl;
var ajaxFirstItemName;
var ajaxFirstItemValue;
var ajaxVersion;
function PopulateModels(ctrl, make, firstItemName, firstItemValue)
{
	ajaxCtrl = ctrl;
	ajaxFirstItemName = firstItemName;
	ajaxFirstItemValue = firstItemValue;
	ClearList(ctrl);
	AddElement(ctrl, "Loading...", "");
	ajaxReq=GetXmlHTTP();
	ajaxReq.onreadystatechange = PopulateDDLResults
	ajaxVersion = GetVer();
	ajaxReq.open("GET","AJAX.aspx?Action=GetModels&Make=" + make + "&Version=" + ajaxVersion,true);
	ajaxreq.send(null);

}
function PopulateBodyStyles(ctrl, year, make, model, firstItemName, firstItemValue)
{
	ajaxCtrl = ctrl;
	ajaxFirstItemName = firstItemName;
	ajaxFirstItemValue = firstItemValue;
	ClearList(ctrl);
	AddElement(ctrl, "Loading...", "");
	ajaxReq=GetXmlHTTP();
	ajaxReq.onreadystatechange = PopulateDDLResults
	ajaxVersion = GetVer();
	ajaxReq.open("GET","AJAX.aspx?Action=GetBodyStyles&ItemYear=" + year + "&Make=" + make + "&Model=" + model + "&Version=" + ajaxVersion,true);
	ajaxreq.send(null);

}
function AddOrRemoveWatchList(itemId, add, owner, dontShowConfirmation)
{
	req=GetXmlHTTP();
	req.open("GET","AJAX.aspx?Action=AddOrRemoveWatchList&ItemId=" + itemId + "&Add=" + add + "&Version=" + GetVer(),false);
	req.send(null);
	listType = "custom pool list";
	if (owner)
		listType = "work list";
	if (dontShowConfirmation != true)
	{
		if (add)
			alert("Successfully added the item to your " + listType + ".");
		else
			alert("Successfully removed the item from your " + listType + ".");
	}
}
function AddOrRemoveJob(taskTypeId, itemId, add, dontShowConfirmation)
{
	req=GetXmlHTTP();
	req.open("GET","AJAX.aspx?Action=AddOrRemoveTask&TaskTypeId=" + taskTypeId + "&ItemId=" + itemId + "&Add=" + add + "&Version=" + GetVer(),false);
	req.send(null);
	if (!dontShowConfirmation)
		alert(req.responseText);
	RefreshPage();
}
function RemoveProfile(nd, id, dontShowConfirmation)
{
	req=GetXmlHTTP();
	req.open("GET","AJAX.aspx?Action=AddOrRemoveProfile&Add=False&ProfileId=" + id + "&Version=" + GetVer(),false);
	req.send(null);
	if (dontShowConfirmation != true)
	{
		alert("Successfully removed the item.");
	}
	if (nd != "")
	{
		document.getElementById(nd).parentElement.style.display = "none";
	}
}

function AddOrRemoveWishList(itemId, add, wishListType)
{
	req=GetXmlHTTP();
	req.open("GET","AJAX.aspx?Action=AddOrRemoveWishList&ItemId=" + itemId + "&Add=" + add + "&WishListType=" + wishListType + "&Version=" + GetVer(),false);
	req.send(null);
	if (add)
		alert("Successfully added the item to your wish list.");
	else
		alert("Successfully removed the item from your wish list.");
}
function PopulateDDLResults()
{
	if (ajaxReq.readyState == 4)
	{
		if (ajaxReq.status == 200)
		{
			var doc = GetXmlDoc();
			doc.loadXML(ajaxReq.responseText);
			var ndList = doc.firstChild.childNodes;
			if (ajaxFirstItemName != null)
			{
				ajaxCtrl.options[0].text = ajaxFirstItemName;
				ajaxCtrl.options[0].value = ajaxFirstItemValue;
			}
			else
			{
				ajaxCtrl.options[0] = null;
			}
			for (var i = 0; i < ndList.length; i++)
			{
				AddElement(ajaxCtrl, ndList[i].text, ndList[i].text);
			}
		}
	}	
}

function ChangeReportView(id)
{
	QueryString_Set("AWGReportViewId", id);
	window.location = GetUrl();				
}
function ChangeReportFormat(val)
{
	QueryString_Set("AWGReportFormat", val);
	window.location = GetUrl();				
}
function MinimizeSearch()
{
	if (document.getElementById("TRSearchHeader") != null)
		document.getElementById("TRSearchHeader").style.display = "inline";
	if (document.getElementById("TRSearchBox") != null)
		document.getElementById("TRSearchBox").style.display = "none";
}
function MaximizeSearch()
{
	if (document.getElementById("TRSearchHeader") != null)
		document.getElementById("TRSearchHeader").style.display = "inline";
	if (document.getElementById("TRSearchBox") != null)
		document.getElementById("TRSearchBox").style.display = "inline";
	document.getElementById("TRSearchBox").style.backgroundColor = "#ccffcc";
	window.setTimeout('document.getElementById("TRSearchBox").style.backgroundColor = "";', 500);
}
function CloseSearch()
{
	if (document.getElementById("TRSearchHeader") != null)
		document.getElementById("TRSearchHeader").style.display = "none";
	if (document.getElementById("TRSearchBox") != null)
		document.getElementById("TRSearchBox").style.display = "none";
}

function ChangeSelectedColumns(val)
{
	QueryString_Set("SelectedColumns", val);
	window.location = GetUrl();				
}

function ClientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id + 
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}


