// Global JavaScript Functions,Object,etc.
//	Global JavaScript Include
////////////////////////////////
// Determine browser
var isMinNS4 = (document.layers) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;
var isNS6 = (document.getElementById && !document.all) ? 1 : 0;
var isMac = (navigator.userAgent.indexOf("Mac") > 0) ? 1 : 0;
var winHeight, winWidth;

//	Netscape 4.x bug fixes 
//	Relatively positioned layers fix - prevents crashing when resizing browser
if (document.layers)
{
	document.write('<LAYER NAME="NOTHING" VISIBILITY="HIDE" Z-INDEX="0" LEFT="0" TOP="0"></LAYER>');
}

// default page load method
function pageLoad()
{
	// window size variables for DHTML reloading
	winHeight = getWindowHeight();
	winWidth = getWindowWidth();
}

// Reload function to handle any DHTML required reloads of the page
function reloadIt()
{
	// only resize if the new window height is different from the old one
	if (winHeight != getWindowHeight() || winWidth != getWindowWidth())
		document.location.replace(document.location);
}

//	Opens a new window with specified properties
function openWin(url,name,w,h,scroll,resize,status,title,tool,menubar)
{
	var sFeatures;
	if (typeof(h) == "undefined") h = 300;
	if (typeof(w) == "undefined") w = 400;
	
	var screenW = screen.width;
	var screenH = screen.height;
	var posX = (screenW/2)-(w/2);
	var posY = (screenH/2)-(h/2);
	
	sFeatures = "screenY="+posY+",screenX="+posX+",top="+posY+",left="+posX+",height="+h+",width="+w;
	
	if (typeof(scroll) != "undefined"){ sFeatures += ",scrollbars=" + scroll; }
	if (typeof(resize) != "undefined"){ sFeatures += ",resizable=" + resize; }
	if (typeof(status) != "undefined"){ sFeatures += ",status=" + status; }
	if (typeof(title) != "undefined"){ sFeatures += ",titlebar=" + title; }
	if (typeof(tool) != "undefined"){ sFeatures += ",toolbar=" + tool; }
	if (typeof(menubar) != "undefined"){ sFeatures += ",menubar=" + menubar; }
	
	//alert(sFeatures);
	var win = window.open(url,name,sFeatures);
	win.focus();
}

//	Opens a new blank window with specified properties
function openBlankWin(url,name)
{

//	alert(sFeatures);
	var win = window.open(url,name);
	win.focus();
}


//	Preload function called from web page
//	arImgs is the array of image paths passed
function preload( imgs, pths )
{
	var i;

	if( document.images ){
		for(i = 0; i < pths.length; i++){
			imgs[i] = new Image();
			imgs[i].src = pths[i];
		//	alert(pths[i]);
		}
	}
	
/*	Use the following template to preload images on the individual web pages
	var imags = new Array();	//Image array to preload
	var paths = new Array();	//Image paths
	paths[0] = "";
	preload(imags,paths);
*/
}

//	Image swapping function
function swap_image(nme,imag)
{
	if(document.images)
	{
		var img_obj = findImage(nme, document);
		if (img_obj != null && typeof(imag) != 'undefined') img_obj.src = imag.src;
	}
}

//Where to Buy Right Chanell Select Box
function setDropDown(strComp){
	var strFilename, pos1, pos2;

	strFilename = "";

	pos1 = window.location.pathname.indexOf('wheretobuy_');
	if(pos1 >= 0){
		pos1 += 11;// len of "wheretobuy_"
		pos2 = window.location.pathname.lastIndexOf('.');
	}else{
		pos1 = window.location.pathname.indexOf('esp_');
		if(pos1 >= 0){
			pos1 += 4;// len of "esp_"
			pos2 = window.location.pathname.indexOf('_', pos1);
		}
	}

	if(pos1 >= 0){
		strFilename = window.location.pathname.substring(pos1, pos2);
	}

	if(strComp == strFilename){
		return true;
	}
	else{
		return false;
	}
}

// Positioning Methods (Used primarily for top nav positioning
/* Window and page properties */
function getWindowWidth()
{
	if (isMinNS4) { return window.innerWidth; }
	else if (isMinIE4 || isNS6 ) { return document.body.clientWidth; }
	return -1;
}

function getWindowHeight()
{
	if (isMinNS4) { return window.innerHeight; }
	else if (isMinIE4 || isNS6 ) { return document.body.clientHeight; }
	return -1;
}

/*  Image utilities */
function getImage(name)
{
	if (isMinNS4) { return findImage(name, document); }
	else if (isMinIE4) { return eval('document.all.' + name); }
	else if (isNS6) { return document.getElementById(name); }
	return null;
}

function findImage(name, doc)
{
	var i, img;
	for (i = 0; i < doc.images.length; i++) {
		if (doc.images[i].name == name) { return doc.images[i]; }
	}
	for (i = 0; i < doc.layers.length; i++) {
		if ((img = findImage(name, doc.layers[i].document)) != null)
		{
			img.container = doc.layers[i];
			return img;
		}
	}
	return null;
}

function getImagePageLeft(img)
{
	var x, obj;
	if (isMinNS4) {
		if (img.container != null) { return img.container.pageX + img.x; }
		else { return img.x; }
	} else if (isMinIE4 || isNS6 ) {
		x = 0;
		obj = img;
		if (obj != null) {
			do {
				x += obj.offsetLeft;
				obj = obj.offsetParent;
			} while (obj != null);
		}
		return x;
	}
	return -1;
}

function getImagePageTop(img)
{
	var y, obj;
	if (isMinNS4) {
		if (img.container != null) { return img.container.pageY + img.y; }
		else { return img.y; }
	} else if (isMinIE4 || isNS6 ) {
		y = 0;
		obj = img;
		if (obj != null) {
			do {
				y += obj.offsetTop;
				obj = obj.offsetParent;
			} while (obj != null);
		}
		return y;
	}
	return -1;
}

// Used by the DropDownList in Expert Solution Providers channel block
function providerSelect(obj)
{
	//	Change URL when the user selects a new country from drop down.
	var strWhereToNext, i;
	strWhereToNext='select';
	for(i=0;i<obj.length;i++)
	if(obj.options[i].selected==true)strWhereToNext=obj.options[i].value;
	if(strWhereToNext != 'select') window.location = strWhereToNext;
}