﻿/**********************************************************************
	MAIN NAVIGATION
 *********************************************************************/

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}


/*******************************************************************************
	Popup Window openers
*******************************************************************************/

var winReference = null;

// Open a full-chrome (all GUI elements) window
// This is like using a target="_blank" in a normal link but allows focussing the window
function openFullChromeWindow(url, name, openerName) {
	return openWindow(url, name, 'directories,location,menubar,resizable,scrollbars,status,toolbar');
}


// Core utility function that actually creates the window and gives focus to it
function openWindow(url, name, properties, openerName) {

	// ie4.x pc can't give focus to windows containing documents from a different domain
	// in this case, initially load a local interstisial page to allow focussing before loading final url
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
		winReference = window.open('about:blank', name, properties);
		
		setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else {
		winReference = window.open(url, name, properties);
	}

	// ie doesn't like giving focus immediately (to new window in 4.5 on mac; to existing ones in 5 on pc)
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	
	if (openerName) self.name = openerName;
	return winReference;
}


/* Use for the view all sections of tabs */
function viewAll(isFirstCall) {
	if (titles) {
		$("#View_All").append(titles[0]);
		titles.splice(0, 1);
	}
	if (urls.length > 0) {
		if (urls[0] != null) {
			$.ajax({
				url: urls[0],
				cache: false,
				success: function(html) {
					if (isFirstCall) {
						$("#View_All").append(html);
					} else {
						$("#View_All").append("<div class='hideButtons'>" + html + "</div>");
					}
					urls.splice(0, 1);
					viewAll(false);
				}
			});
		} else {
			urls.splice(0, 1);
			viewAll(false);
		}
	}
}


/* export print images of charts */
var renderedCharts = new Array();

function testExport() {

}


function setLoading(placeHolder) {
    placeHolder.attr("src", "");
    placeHolder.attr("src", "_img/ajax-loader.gif");
    placeHolder.css("margin", "5px 7px 5px 6px");
}

function expanderStatus(placeHolder) {
	var imageFile = GetFilename(placeHolder.attr("src"))
	if (imageFile == "icon_close") {
		placeHolder.attr("src", "_img/icon_open.png");
		placeHolder.attr("alt", "Open");
    } else {
		placeHolder.attr("src", "_img/icon_close.png");
		placeHolder.attr("alt", "Close"); 
    }
}

function GetFilename(url) {
	if (url) {
		var m = url.toString().match(/.*\/(.+?)\./);
		if (m && m.length > 1) {
			return m[1];
		}
	}
	return "";
}

/* Use for the view all sections of tabs */
function BTALhwCall(params, elementId) {

	//set loading wheel

	var url = "handlers/brandtrendanalysis.aspx?params=" + params;

	if ($('#' + elementId).is(":visible")) {
		expanderStatus($('#toggle' + elementId))
		$('#' + elementId).toggle('slow');
		//$('#' + elementId).html("")
	}
	else if ($.trim($('#' + elementId).html()).length > 0) {
		expanderStatus($('#toggle' + elementId))
		$('#' + elementId).toggle('slow');
	}
	else {
		$('#toggle' + elementId).attr("src", "_img/loading.gif");
		$.ajax({
			url: url,
			cache: false,
			success: function(html) {
				$('#' + elementId).append(html);
				expanderStatus($('#toggle' + elementId))
				$('#' + elementId).toggle('slow');
			}
		});
	}

	

	return true;
}