// JavaScript for ChoiceTech

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} 
		while (obj = obj.offsetParent);
	}

	return [curleft,curtop];
}

function showDropDown() {
	var productMenu = document.getElementById('productmenu');
	var productTab = document.getElementById('producttab');
	var posLeft = findPos(productTab);
	//alert(posLeft[0]);
	productMenu.style.left = posLeft[0] - 42;
	productMenu.style.top = posLeft[1] + 27;
	productMenu.style.display = 'block';
}




// Sets the "visibility" css property of an object to "hidden" or "visible"
function toggleCSSDisplay(objID, displayOverride) {
	
	if (displayOverride)
		document.getElementById(objID).style.display = displayOverride;
	
	else {
		d = document.getElementById(objID).style.display;
		if (d == "block" || d == "")
			document.getElementById(objID).style.display = "none";
		else
			document.getElementById(objID).style.display = "block";
	}
}

// Returns left-of-center values
function placeObjFromCenter_coords(LeftValueWhenEvenBrowserWidth) {

	BrowserWidth = document.body.clientWidth;

	if (String(BrowserWidth/2).match(/\.[0-9]{1,}/))
		return Math.floor(BrowserWidth/2) + LeftValueWhenEvenBrowserWidth;
	else
		return BrowserWidth/2 + (LeftValueWhenEvenBrowserWidth);
}

// Places an image off-center
function placeObjFromCenter(ImgID, l, t) {
	use_position = "absolute";
	use_left     = placeObjFromCenter_coords(l);
	use_top      = (document.all)?t:(t-3);

	document.getElementById(ImgID).style.visibility = "visible";
	document.getElementById(ImgID).style.position = use_position;
	document.getElementById(ImgID).style.left = use_left; // 84
	document.getElementById(ImgID).style.top  = use_top; // 18;
}

// Renames the SRC and size of an image
function renameSRCandSizeOfImg(ImgID, NewSrc, NewX, NewY) {
	document.getElementById(ImgID).src    = NewSrc;
	document.getElementById(ImgID).width  = NewX;
	document.getElementById(ImgID).height = NewY;
}

// Generates email address "safe" from harvesters
function generateAntiSpiderEmail(Username, DomainName, TLD) {
	EmailAddress = Username + "&#64;" + DomainName + "." + TLD;
	document.write("<a href=\"ma" + "il" + "to:" + EmailAddress + "\">" + EmailAddress + "</a>");
}

// OPENS A DYNAMIC WINDOW
function openDynamicWindow(output, WinName, WinParams) {
	DynWin = window.open("", WinName, WinParams);
	
	with (DynWin.document) {
		open();
		write(output);
		close();
	}
}

// ROTATES OUTPUT, MARQUEE-STYLE
function rotateOutput(OutputArray, PlaceInObj) {
	
	if (typeof ArrayCounter == 'undefined')
		ArrayCounter = 0;
	
	if (typeof OutputArray[ArrayCounter] == 'undefined')
		ArrayCounter = 0;
	
	if (navigator.appVersion.indexOf('MSIE') != -1) {
		PlaceInObj.style.filter = "revealTrans(Duration=1,Transition=4)";
		PlaceInObj.filters[0].Apply();
		PlaceInObj.filters[0].Play();
	}
	
	PlaceInObj.innerHTML = OutputArray[ArrayCounter];
	ArrayCounter++;
}