var fw_helpWin=false;

function activateMenu(root,url) {
	try {
	hnode = toolbox_nodes_getActiveLink(root,url);
	hnode.className = "active";
	} catch(e) { }
}

function activateLocation(root) {
	hnode = document.getElementById(root);
	activateMenu(hnode,window.location);
}


function activateImageMenu(root,url) {
	hnode = toolbox_nodes_getActiveLink(root,url);
	inode = toolbox_nodes_getFirstOf(hnote,'img');
	var nSrc = new String(inode.src);
	inode.src = nSrc.replace('_up','_over');
	inode.onmouseover=function(){}
}

function fw_showHelp() {
	fw_helpWin = fw_popWin('/help/home/','IndigoHelp',0,1,0,0,0,1,780,600);
	fw_helpWin.focus();
}

function fw_popWin(url,winName,toolbar,scrollbars,location,statusbar,menubar,resizable,width,height) {

	lft = ',left='+((screen.width-width)/2);
	tp = ',top='+((screen.height-height)/2);
	toolbar = 'toolbar='+toolbar;
	scrollbars=',scrollbars='+scrollbars;
	location=',location='+location;
	statusbar=',statusbar='+statusbar;
	menubar=',menubar='+menubar;
	resizable=',resizable='+resizable;
	width=',width='+width;
	height=',height='+height;
	params = ' '+toolbar+scrollbars+location+statusbar+menubar+resizable+width+height+lft+tp;
	//confirm(params);
	var popWin = window.open(url,winName,params);
	return popWin;

}

function fw_modalWin(url,winName,scrollbars,width,height,resizable) {
	if (window.showModalDialog) {
	var popWin = window.showModalDialog(url,winName,"dialogWidth:"+width+"px;dialogHeight:"+height+"px");
	} else {
	var popWin = window.open(url,winName,'height='+height+',width='+width+',toolbar=no,directories=no,status=no,menubar=no,scrollbars='+scrollbars+',resizable='+resizable+',modal=yes');
	}
	return popWin;
} 

function fw_changeActSubmitToBlank(formName,actValue,action,message) {

	doit = true;
	if (message) { doit = confirm(message); }

	if (doit) {

		myfm = document.forms[formName];
		myfm.oldAct = myfm.elements['_action'].value;
		myfm.elements['_action'].value = actValue;
		myfm.oldTarget = myfm.target;
		myfm.oldAction = myfm.action;
		myfm.target='_blank';
		myfm.action=action;
		
		try{myfm.onsubmit();}catch(err){}
		

		myfm.submit();

		myfm.elements['_action'].value=myfm.oldAct;
		myfm.action = myfm.oldAction;
		myfm.target = myfm.oldTarget;

	}
}

function fw_changeActSubmit(formName,actValue,message) {

	doit = true;
	if (message) { doit = confirm(message); }

	if (doit) {
		myfm = document.forms[formName];
		myfm.oldAct = myfm.elements['_action'].value;
		myfm.elements['_action'].value = actValue;
		try{
			myfm.onsubmit();
		} catch (err) {
		}
		myfm.submit();
		myfm.elements['_action'].value=myfm.oldAct;

	}
}



function fw_redirectOnConfirm(message,loc) {
	if (confirm(message)) {
		location = loc;
	}
}

function fw_showHide(caller,objID) {
	var obj = document.getElementById(objID);
	var result = toolbox_style_toggleDisplay(obj);
	if (result) {
		caller.className = 'toggleOpen';
	} else {
		caller.className = 'toggleClose';
	}
	//alert(caller.nodeName+' '+caller.className);
}


function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function killCookie(name) {
	setCookie(name,"",-1);
}



function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function killCookie(name) {
	setCookie(name,"",-1);
}




function nothing(obj) {
	return false;
}




//# AJAX

function ajaxReplace(url,replacementID) {
	new Ajax.Updater(replacementID, url, { method: 'get' });
}

function ajaxSubmit(formID,replacementID) {
	var fm = document.getElementById(formID);
	 new Ajax.Updater(replacementID, fm.action, { method: 'post',
    	parameters: $(formID).serialize() } );
}

function ajaxAlert(targetID,message) {
	document.getElementById(targetID).innerHTML = message;
}

function nothing() {
	return false;
}

function fwCopyField(ffrom,fto) {
	var cfrom = document.getElementById(ffrom);
	var cto = document.getElementById(fto);
	cto.value = cfrom.value;
}

function fwCopyDD(ffrom,fto) {
	var cfrom = document.getElementById(ffrom);
	var cto = document.getElementById(fto);
	for(i=0;i<cto.options.length;i++) {
		if (cto.options[i].value == cfrom.options[cfrom.selectedIndex].value) {
			cto.selectedIndex = i;
			return true;
		}
	}
	cto.selectedIndex=0;
}

function initRollover(obj) {
	var oldsrc = new String(obj.src);
	obj.upsrc = oldsrc;
	obj.oversrc = oldsrc.replace('_up','_over');
	obj.onmouseover = function() { this.src = this.oversrc; }
	obj.onmouseout = function() { this.src = this.upsrc; }
	obj.onload = function() { }
}

function fwSetTabs(tablabel,tabblock,id) {
	var tabPages = $(tabblock).select('[class="tabPage"]');
	tabPages.each(function(item) { item.style.display='none'; });
	var activeTab = $(id);
	activeTab.style.display='block';
	var tabLabels = $(tabblock).select('[class="tabLabelActive"]');
	tabLabels.each(function(item) { item.className='tabLabel'; });
	tablabel.className='tabLabelActive';
}


