/*******************************************************************
* Copyright (c) 2006-2007, Cloudsmith Inc.
******************************************************************/

 
/* CLOUDSMITH SITE FUNCTIONS */

/* IMAGE PRELOADING FOR ROLLOVERS */
var CSIMAGES = new Array();
CSIMAGES["unchecked"] = new Image(12, 12);
CSIMAGES["unchecked"].src = imgPath + "checkbox.unchecked.png";
CSIMAGES["checked"] = new Image(12, 12);
CSIMAGES["checked"].src = imgPath + "checkbox.checked.png";

CSIMAGES["info-on"] = new Image(34, 14);
CSIMAGES["info-on"].src = imgPath + "nav.info.1.png";
CSIMAGES["info"] = new Image(34, 14);
CSIMAGES["info"].src = imgPath + "nav.info.0.png";

CSIMAGES["signup-on"] = new Image(46, 14);
CSIMAGES["signup-on"].src = imgPath + "nav.signup.1.png";
CSIMAGES["signup"] = new Image(46, 14);
CSIMAGES["signup"].src = imgPath + "nav.signup.0.png";

CSIMAGES["signin-on"] = new Image(46, 14);
CSIMAGES["signin-on"].src = imgPath + "nav.signin.1.png";
CSIMAGES["signin"] = new Image(46, 14);
CSIMAGES["signin"].src = imgPath + "nav.signin.0.png";

CSIMAGES["signout-on"] = new Image(54, 14);
CSIMAGES["signout-on"].src = imgPath + "nav.signout.1.png";
CSIMAGES["signout"] = new Image(54, 14);
CSIMAGES["signout"].src = imgPath + "nav.signout.0.png";

CSIMAGES["myaccount-on"] = new Image(76, 14);
CSIMAGES["myaccount-on"].src = imgPath + "nav.myaccount.1.png";
CSIMAGES["myaccount"] = new Image(76, 14);
CSIMAGES["myaccount"].src = imgPath + "nav.myaccount.0.png";

CSIMAGES["myhome-on"] = new Image(61, 14);
CSIMAGES["myhome-on"].src = imgPath + "nav.myhome.1.png";
CSIMAGES["myhome"] = new Image(61, 14);
CSIMAGES["myhome"].src = imgPath + "nav.myhome.0.png";

CSIMAGES["cloud"] = new Image(14, 14);
CSIMAGES["cloud"].src = imgPath + "clouds.box.png";
CSIMAGES["cloud-on"] = new Image(14, 14);
CSIMAGES["cloud-on"].src = imgPath + "clouds.on.box.png";

CSIMAGES["arrowDownBarBox"] = new Image(14, 14);
CSIMAGES["arrowDownBarBox"].src = imgPath + "arrow.down.bar.box.png";
CSIMAGES["arrowDownBarBox-on"] = new Image(14, 14);
CSIMAGES["arrowDownBarBox-on"].src = imgPath + "arrow.down.bar.on.box.png";

CSIMAGES["caution"] = new Image(14, 13);
CSIMAGES["caution"].src = imgPath + "caution.grey.png";
CSIMAGES["caution-on"] = new Image(14, 13);
CSIMAGES["caution-on"].src = imgPath + "caution.orange.png";

CSIMAGES["nextarr"] = new Image(11, 10);
CSIMAGES["nextarr"].src = imgPath + "arrow.next.gray.png";
CSIMAGES["nextarr-on"] = new Image(11, 10);
CSIMAGES["nextarr-on"].src = imgPath + "arrow.next.png";

CSIMAGES["prevarr"] = new Image(11, 10);
CSIMAGES["prevarr"].src = imgPath + "arrow.prev.gray.png";
CSIMAGES["prevarr-on"] = new Image(11, 10);
CSIMAGES["prevarr-on"].src = imgPath + "arrow.prev.png";

CSIMAGES["delete-sign"] = new Image(13, 14);
CSIMAGES["delete-sign"].src = imgPath + "delete.sign.0.png";
CSIMAGES["delete-sign-on"] = new Image(13, 14);
CSIMAGES["delete-sign-on"].src = imgPath + "delete.sign.1.png";

/*
 * More images may be loaded and added to this array on individual pages.
 */

/*
CSIMAGES["watchlist-on"] = new Image(61, 14);
CSIMAGES["watchlist-on"].src = imgPath + "nav.watchlist.1.png";
CSIMAGES["watchlist"] = new Image(61, 14);
CSIMAGES["watchlist"].src = imgPath + "nav.watchlist.0.png";

CSIMAGES["publishing-on"] = new Image(61, 14);
CSIMAGES["publishing-on"].src = imgPath + "nav.publishing.1.png";
CSIMAGES["publishing"] = new Image(61, 14);
CSIMAGES["publishing"].src = imgPath + "nav.publishing.0.png";

CSIMAGES["mapping-on"] = new Image(59, 14);
CSIMAGES["mapping-on"].src = imgPath + "nav.mapping.1.png";
CSIMAGES["mapping"] = new Image(59, 14);
CSIMAGES["mapping"].src = imgPath + "nav.mapping.0.png";

CSIMAGES["help-on"] = new Image(34, 14);
CSIMAGES["help-on"].src = imgPath + "nav.help.1.png";
CSIMAGES["help"] = new Image(34, 14);
CSIMAGES["help"].src = imgPath + "nav.help.0.png";

CSIMAGES["settings-on"] = new Image(53, 14);
CSIMAGES["settings-on"].src = imgPath + "nav.settings.1.png";
CSIMAGES["settings"] = new Image(53, 14);
CSIMAGES["settings"].src = imgPath + "nav.settings.0.png";

CSIMAGES["bug"] = new Image(251, 32);
CSIMAGES["bug"].src = imgPath + "report.bug.ants.0.png";
CSIMAGES["bug-on"] = new Image(251, 32);
CSIMAGES["bug-on"].src = imgPath + "report.bug.ants.1.png";
 */




function csImage(anImage, imageName)
{
	if(anImage == null)
		return;
	anImage.src = CSIMAGES[imageName].src;
}
function csImageOn(anImage, imageName)
{
	if(anImage == null)
		return;
	anImage.src = CSIMAGES[imageName+'-on'].src;
}


function pageImage(anImage, imageName, imageArray)
{
	if(anImage == null)
		return;
	anImage.src = imageArray[imageName].src;
}
function pageImageOn(anImage, imageName, imageArray)
{
	if(anImage == null)
		return;
	anImage.src = imageArray[imageName+'-on'].src;
}


function toggleCheckboxTitles(inputId, imgId, falseTitle, trueTitle)
{
	input = document.getElementById(inputId);
	img = document.getElementById(imgId);
	
	if(input.value == "true")
	{
		input.value = "false";
		img.src = CSIMAGES["unchecked"].src;
		img.title = falseTitle;					
	}
	else
	{
		input.value = "true";
		img.src = CSIMAGES["checked"].src;
		img.title = trueTitle;
	}
}
function toggleCheckbox(inputId, theImg)
	{
	var input = document.getElementById(inputId);
	if(input.checked)
		{
		input.checked = false;
		theImg.src = CSIMAGES["unchecked"].src;
		}
	else{
		input.checked = true;
		theImg.src = CSIMAGES["checked"].src;
		}
	}
function toggleCheckboxId(inputId, imageId)
	{
	var theImg = document.getElementById(imageId);
	toggleCheckbox(inputId, theImg);
	}
function rowOver(row, className)
	{
	row.style.backgroundColor = "#ececec";
	var x = getElementsByClassName(row, "*", className);
	for(var i = 0; i < x.length; i++)
		{
		x[i]["csKeepColor"] = x[i].style.color;
		x[i].style.color="#2180c7"; 		
		}
	}
function rowOut(row, className)
	{
	row.style.backgroundColor = "#ffffff";
	var x = getElementsByClassName(row, "*", className);
	for(var i = 0; i < x.length; i++)
		{
		x[i].style.color = x[i]["csKeepColor"];
		}
	}

/* Note: use only when there is only a single child element of the
* particular class. 
*/
function clickOn(element, className)
{	
	var x = null;
	if(element.getElementsByClassName != null)
	{
		x = element.getElementsByClassName(className);
	}
	else
	{
		x = getElementsByClassName(element, "*", className);
	}
	var y = x[0];
	y.onclick(y);
}
function clickIfEnter(event, inputId)
{	
	if(event.keyCode == 13)
	{
		try
		{
			document.getElementById(inputId).click();
		}
		catch(e)
		{
			// ignore
		}
	}
}

function clickOnId(inputId)
{	
	var x = window.document.getElementById(inputId);
	x.onclick(x);
}
function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
// ---
// Array support for the push method in IE 5
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}
function cs_onunload() {
	if(at_previousMenu != null)
		at_clean();
}
function cs_onload() {
	/* does nothing */
	}
	
function show_alert(alertMessage)
{
	if(alertMessage != null && alertMessage.length > 0)
	{
		alert(alertMessage);
  	}	
}
function checkedModalPopup(modalPanel, condition)
{
	if(condition == null || condition == false)
		return;
	Richfaces.showModalPanel(modalPanel);
}

function disableWizardButton(buttonId)
{
	var button = document.getElementById(buttonId);
	if(button != null)
	{
		button.disabled = true;
		button.className = 'Dim';
	}
}
function disableWizardButtons(buttonIdPrefix)
{
	disableWizardButton(buttonIdPrefix + 'wizPrevious');
	disableWizardButton(buttonIdPrefix + 'wizNext');
	disableWizardButton(buttonIdPrefix + 'wizFinish');
	disableWizardButton(buttonIdPrefix + 'wizCancel');
	disableWizardButton(buttonIdPrefix + 'wizDone');
}

function toggleCsCheckbox(csWrapper, hideLabelWhenOff)
{
	elements = csWrapper.childNodes;
	checkboxValue = null;
	checkboxImage = null;

	for(i=0; i < elements.length; i++)
	{
		if(elements[i].tagName != null && elements[i].tagName.toLowerCase() == 'input')
		{
			checkboxValue = elements[i];
		}
		else if(elements[i].tagName != null && elements[i].tagName.toLowerCase() == 'img')
		{
			checkboxImage = elements[i];
		}
		if(checkboxValue != null && checkboxImage != null)
		{
			break;
		}
	}
	
	checkboxValue.value = checkboxValue.value == 'true' ? 'false' : 'true';
	csImage(checkboxImage, checkboxValue.value == 'true' ? 'checked' : 'unchecked'); 

	if(hideLabelWhenOff)
	{
		for(i=0; i < elements.length; i++)
		{
			if(elements[i].tagName != null && elements[i].tagName.toLowerCase() == 'span')
			{
				elements[i].style.display = checkboxValue.value == 'true' ? 'inline' : 'none';
			}
		}
	}
}

function findNeighborObject(myObject, neighborSubId)
{
	if(myObject == null)
	{
		return null;
	}
	
	return document.getElementById(myObject.name.substring(0, myObject.name.lastIndexOf(':')+1) + neighborSubId);
}

/*
 * toggle function used in the class below 
 */
function setState(state)
{
	this.imageElement.src = this.image[state].src;
	this.labelElement.style.color = this.labelColor[state];
}

/*
 * Class for toggling the state of an object consisting of an image and a text label 
 */  
function TwoStateToggle(imageElement, imageInactive, imageActive, labelElement, colorInactive, colorActive)
{
	this.imageElement = imageElement;

	this.image = new Array(2);;
	this.image[false] = new Image();
	this.image[false].src = imageInactive;
	this.image[true] = new Image();
	this.image[true].src = imageActive;

	this.labelElement = labelElement;

	this.labelColor = new Array(2);;
	this.labelColor[false] = colorInactive;
	this.labelColor[true] = colorActive;

	this.setState = setState;
}
