/* moved here from show_section.js to reduce requests
	April 1 2008 Kelly Knight */
	
function showSection(sectionDiv,showSpan,hideSpan) { 
	var d = document;
	if (d.getElementById(sectionDiv).className == "hidden") {
		d.getElementById(sectionDiv).className = "sectionBox lightBg visible";
	} else
	if (d.getElementById(sectionDiv).className == "sectionBox lightBg visible") {
		d.getElementById(sectionDiv).className = "hidden";
	}
	
	if (d.getElementById(showSpan).className == "inline") {
		d.getElementById(showSpan).className = "hidden";
	} else 
	if (d.getElementById(showSpan).className == "hidden") {
		d.getElementById(showSpan).className = "inline";
	}

	if (d.getElementById(hideSpan).className == "inline") {
		d.getElementById(hideSpan).className = "hidden";
	} else 
	if (d.getElementById(hideSpan).className == "hidden") {
		d.getElementById(hideSpan).className = "inline";
	}
}

/* moved here from enable_fields.js to reduce requests
	April 1 2008 Kelly Knight */
function enableFields(formName,triggerField,radioNum,fieldTitles,fieldNames) { 
	var d = document;
	var doc = document.forms[formName];	
	var titleArray = fieldTitles.split(",");
	var fieldArray = fieldNames.split(",");

	if (doc.elements[triggerField] && doc.elements[triggerField][radioNum].checked == true) { // field value = "disabled"
		for ( var ii = 0; ii < fieldArray.length; ii++ ) {
			doc.elements[fieldArray[ii]].disabled = true;
			doc.elements[fieldArray[ii]].className = "field disabled";
		}
		for ( var j = 0; j < titleArray.length; j++ ) { 
			d.getElementById(titleArray[j]).style.color = "#A9A9A9"; /* Dark Gray */
		} 
	} else { // field value = "enabled"
		for ( var ii = 0; ii < fieldArray.length; ii++ ) {
			doc.elements[fieldArray[ii]].disabled = false;
			doc.elements[fieldArray[ii]].className = "field enabled"; /* white */
		}
		for ( var j = 0; j < titleArray.length; j++ ) { 
			d.getElementById(titleArray[j]).style.color = "#000"; /* black */
		}
	}
	return true;
}

// disables fields (makes them readonly). Not dependent on any other event.
// formName = $formName, fieldTitles = id of Field Title (in a <td> usually), fieldNames = id of field element
function disableFields(formName,fieldTitles,fieldNames) {
	var d = document;
	var doc = document.forms[formName];
	var titleArray = fieldTitles.split(",");
	var fieldArray = fieldNames.split(",");
	
	for ( var a = 0; a < fieldArray.length; a++ ) {
		doc.elements[fieldArray[a]].disabled = true;
		doc.elements[fieldArray[a]].className = "field disabled";
	}
	for ( var b = 0; b < titleArray.length; b++ ) {
		d.getElementById(titleArray[b]).style.color = "#A9A9A9"; /* Dark Gray */
	}
}

// enables and disables radio array in bid_strategy.mc
function enableRadios(formName,triggerField,radioNum,radioLabels,radioNames) { 
	var d = document;
	var doc = document.forms[formName];	
	var labelArray = radioLabels.split(",");
	var nameArray = radioNames.split(",");

	if (doc.elements[triggerField][radioNum].checked == true) { // field value = "disabled"
		for ( var ii = 0; ii < nameArray.length; ii++ ) {
			doc.elements[nameArray[ii]].disabled = true;
		}
		for ( var j = 0; j < labelArray.length; j++ ) { 
			d.getElementById(labelArray[j]).style.color = "#A9A9A9"; /* Dark Gray */
		} 
	} else { // field value = "enabled"
		for ( var ii = 0; ii < nameArray.length; ii++ ) {
			doc.elements[nameArray[ii]].disabled = false;
		}
		for ( var j = 0; j < labelArray.length; j++ ) { 
			d.getElementById(labelArray[j]).style.color = "#000"; /* black */
		}
	}
	return true;
}

// disables fields (makes them readonly). Not dependent on any other event.
// formName = $formName, fieldTitles = id of Field Title (in a <td> usually), fieldNames = id of field element
function disableRadios(formName,fieldTitles,fieldNames) {
	var d = document;
	var doc = document.forms[formName];
	var titleArray = fieldTitles.split(",");
	var fieldArray = fieldNames.split(",");
	
	for ( var a = 0; a < fieldArray.length; a++ ) {
		doc.elements[fieldArray[a]].disabled = true;
	}
	for ( var b = 0; b < titleArray.length; b++ ) {
		d.getElementById(titleArray[b]).style.color = "#A9A9A9"; /* Dark Gray */
	}
}

// restore original field values to the field when "Use [entity] default [X]" radio == "yes"
function restoreValues(formName,fieldNames,origFieldNames) { 
	var d = document;
	var doc = document.forms[formName];	
	var fArray = fieldNames.split(",");
	var oArray = origFieldNames.split(",");
	
	for ( var ii = 0; ii < fArray.length; ii++ ) {
		doc.elements[fArray[ii]].value = doc.elements[oArray[ii]].value;
	}
}

////////////////// DON'T THINK THIS IS USED -KK //////////////////////////////////
// enable field and make field name 'active' based on which radio is selected
function activateFields(formName,triggerField,radioNum,triggerFieldEnabled,otherFields,otherFieldsID) {
	var d = document;
	var doc = formName;	
	var otherFieldsArray = otherFields.split(",");
	var otherFieldsIDArray = otherFieldsID.split(",");
	// enable field for selected radio
	if (doc.elements[triggerField][radioNum].checked == true) {
		doc.elements[triggerField].className = "field enabled"; /* white */
		d.getElementById(triggerFieldEnabled).style.color = "#000"; /* black */
		// disable all other fields
		for ( var ii = 0; ii < otherFieldsArray.length; ii++ ) {
			doc.elements[otherFieldsArray[ii]].disabled = true;
			doc.elements[otherFieldsArray[ii]].className = "field disabled";
		}
		for ( var j = 0; j < otherFieldsIDArray.length; j++ ) { 
			d.getElementById(otherFieldsIDArray[j]).style.color = "#A9A9A9"; /* Dark Gray */
		} 
	}
}

////////////////// DON'T THINK THIS IS USED -KK //////////////////////////////////
// this function is only used for the Additional Creative & URLs section subcomponents when Partner == Google
function checkAddtlFields(formName,triggerField,addtlFieldsID,fieldTitles,fieldNames) { 
	var d = document;
	var doc = document.forms[formName];	
	var titleArray = fieldTitles.split(",");
	var fieldArray = fieldNames.split(",");

	if ((doc.elements[triggerField][0].checked == true) && (d.getElementById(addtlFieldsID).className == "sectionBox lightBg visible")) {
		for ( var ii = 0; ii < fieldArray.length; ii++ ) {
			doc.elements[fieldArray[ii]].disabled = false;
			doc.elements[fieldArray[ii]].className = "field enabled"; /* white */
		}
		for ( var j = 0; j < titleArray.length; j++ ) { 
			d.getElementById(titleArray[j]).style.color = "#000"; /* black */
		} 
	} else {
		for ( var ii = 0; ii < fieldArray.length; ii++ ) {
			doc.elements[fieldArray[ii]].disabled = true;
			doc.elements[fieldArray[ii]].className = "field disabled";
		}
		for ( var j = 0; j < titleArray.length; j++ ) { 
			d.getElementById(titleArray[j]).style.color = "#A9A9A9"; /* Dark Gray */
		}
	}
	return true;
}

/* moved here from show_hide.js to reduce requests
	April 1 2008 Kelly Knight */

// expands and collapses divs and spans (need to pass the ID)
function show(item) { 
	if(document.getElementById(item)){
 		document.getElementById(item).className = "visible";
	}
}
 
function hide(item) { 
	if(document.getElementById(item)){
		document.getElementById(item).className = "hidden";
	}
}

function showInline(item) {
	if(document.getElementById(item)){
		document.getElementById(item).className = "inline";
	}
}
//search/web/interface/docs/default/top/admin/client_list_iframe.html
//search/web/interface/docs/default/sub/kw_org/creative_urls_google.mc
//search/web/interface/docs/default/sub/kw_org/creative_urls_msn.mc
function showHide(item) {
   if  (document.getElementById(item).className == "hidden") {
	   document.getElementById(item).className = "visible";
	} else
	if  (document.getElementById(item).className == "visible") {
	   document.getElementById(item).className = "hidden";
	}
}

//search/web/interface/docs/default/top/admin/client_list_iframe.html
function showHideInline(item) {
   if  (document.getElementById(item).className == "hidden") {
	   document.getElementById(item).className = "inline";
	} else
	if  (document.getElementById(item).className == "inline") {
	   document.getElementById(item).className = "hidden";
	}
}
	

/* original methods in global_3.67RC1.js below April 1 2008 */

/* ***************************************************************************************
the following are javascript functions that are frequently used throughout the interface.
**************************************************************************************** */

/* **************************************************************************
at times you may want to the use of the enter key to behave differently.
for instance if a user is on a page that allows for the searching of a company,
but doing so should not refresh the entire page, this script will disable the enter 
key from submitting the entire form, and click the element (eg. a button)
that will run another function.
******* e = the event
******* elem = the id of the button that will be clicked on using the '.click()' property
******* usage =  onkeypress="return enterKeyAct(event, 'id-of-element-to-receive-click');"
************** see example @ affiliate - /top/links/link_feeds.html
***************************************************************************** */
function enterKeyAct(e, elem) {
	var key = window.event ? e.keyCode : e.which;	
	var action = document.getElementById(elem);
	if(key == 13) {
		action.click();
		return false;
	}
}

/* **************************************************************************
this function can be used to alternate the row colors of a specified table (tableid)
******* tableid = the id of the table that you wish to have alternating row colors
******* evenclass = the name of the class for all rows that are even (divisble by 2)
******* oddclass = the name of the class for all rows that are odd (not divisible by 2)
******* hiliteclass = the name of the class to change the row to when the user mouses over it
**************** see example @ affiliate - /top/links/link_feeds.html
***************************************************************************** */
function setRowClasses(tableid,evenclass,oddclass,hiliteclass) {
	if(document.getElementById(tableid))
	{
		var tableid = document.getElementById(tableid);
		var rows = tableid.tBodies[0].rows;
		for(var ii = 0; ii < rows.length; ii++) {
			var row = rows[ii];
			row.onmouseover = function () {this.className=hiliteclass;};
			if(ii % 2) {
				row.className = evenclass;
				row.onmouseout = function () {this.className=evenclass;};
			} else {
				row.className = oddclass;
				row.onmouseout = function () {this.className=oddclass;};
			}
		}
	}
}

/* **************************************************************************
this function can be used to change the class name of a row in a table (generally used for color changes)
******* rowid = the id of the row (tr) that you wish to be hilited
******* classname = the name of the class to change the row to
**************** see example @ affiliate - /top/links/link_feeds.html
***************************************************************************** */
function hiliteRow(rowid, classname) {
	document.getElementById(rowid).className = classname;
}

function showBox(boxid, nohide, percentsize, overlay){
	if(typeof percentsize == 'undefined'){
		var percentsize = 0.75;
	}
	this.bodyOverflow = document.body.style.overflow;
	// this will define the size of the body of content, which will then determine the size of the overlay (IE).
	document.body.style.height   = Math.max(document.body.scrollHeight, document.body.clientHeight) + 'px';
	// this will disable the scrollbar (in FF) so that the user is forced to take action on the floatbox before continuing.
	document.body.style.overflow = 'hidden';
	
	setDisplayForElement('',overlay);
	resize_overlay(overlay);
	resize_floatbox(boxid, percentsize);
	
	var selectElems = document.getElementsByTagName('select');
	for(var i = 0; i < selectElems.length; ++i) {
		if(nohide == '' || selectElems[i].id != nohide) {
			selectElems[i].style.visibility = 'hidden';
		}
	}
	center(boxid);
    return false;
}

//lightbox with set dimensions.  nohide is for select form elements that should not be hidden when the box is visible
function showStaticSizeBox(boxid, boxwidth, boxheight, overlay, pxfromtop, nohide){

        if(!pxfromtop){pxfromtop=20};
		
		this.bodyOverflow = document.body.style.overflow;
        // this will define the size of the body of content, which will then determine the size of the overlay (IE).
        document.body.style.height   = Math.max(document.body.scrollHeight, document.body.clientHeight) + 'px';

        setDisplayForElement('',overlay);
        resize_overlay(overlay);
        var arrayPageSize = getPageSize();
        setElementDimensions(boxid, {w: boxwidth,h: boxheight});

        var selectElems = document.getElementsByTagName('select');
        //if there are form elements that should not be hidden when the lightbox is visible
		for(var i = 0; i < selectElems.length; ++i) {
              if(nohide == '' || selectElems[i].id != nohide) {
                      selectElems[i].style.visibility = 'hidden';
              }
      }
	  centerHorizontal(boxid,pxfromtop);
    return false;
}

function resize_floatbox(id, percentsize) {
	if(typeof percentsize == 'undefined'){
		var percentsize = 0.75;
	}
	var arrayPageSize = getPageSize();
	setElementDimensions(id, {w: (arrayPageSize[2] * percentsize),h: (arrayPageSize[3] * percentsize)});
}

function resize_overlay(id) {
	var arrayPageSize = getPageSize();
	setElementDimensions(id, {h: arrayPageSize[1]});
}

function center(id) {
    try{
        id = $(id);
    }catch(e){
        return;
    }
	
	var arrayPageSize = getPageSize();
	
    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = getElementDimensions(id);
	
	// arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

    var setX = ( arrayPageSize[2]  - elementDimensions.w  ) / 2;
    var setY = ( arrayPageSize[3] - elementDimensions.h ) / 2;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;
    id.style.left = setX + "px";
    id.style.top  = setY + "px";
	
    id.style.display  = 'block';
	
}

//centers element horizontally only
function centerHorizontal(id,pxfromtop) {
    try{
        id = $(id);
    }catch(e){
        return;
    }

    var arrayPageSize = getPageSize();
    var elementDimensions = getElementDimensions(id);
    var setX = ( arrayPageSize[2]  - elementDimensions.w  ) / 2;

    setX = ( setX < 0 ) ? 0 : setX;
    id.style.left = setX + "px";
    id.style.top  = pxfromtop + 'px';
    id.style.display  = 'block';

}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function hideBox(boxid, overlay){
	// this will re-enable the scrollbar.
	document.body.style.overflow = this.bodyOverflow;
	// this will enable the scrollbar (in FF) so that the user is forced to take action on the floatbox before continuing.
	document.body.style.overflow = 'auto';
	setDisplayForElement('none',boxid);
	setDisplayForElement('none',overlay);
	var selectElems = document.getElementsByTagName('select');
	for(var i = 0; i < selectElems.length; ++i) {
		selectElems[i].style.visibility = 'visible';
	}
    return false;
}

function accordion(id, id2) {
	if ($(id).style.display == 'none') {
		blindDown($(id), {duration: .25, queue: 'end'});
		if ($(id2).style.display != 'none') {
			blindUp($(id2), {duration: .25, queue: 'front'});
		}
	}
}

/* **************************************************************************
this function expands and collapses the optional information form sections
***************************************************************************** */
function expandCollapse(contentid, expandimg, collapseimg) {
	if($(contentid).style.display == 'none') {
		blindDown(contentid, {duration: .25});
		setDisplayForElement('none',expandimg);
		setDisplayForElement('',collapseimg);		 
	} else {
		blindUp(contentid, {duration: .25});
		setDisplayForElement('none',collapseimg);
		setDisplayForElement('',expandimg);	
	}
}

/* **************************************************************************
this function changed the "basic" and "advanced" tabs based on parameters given to it
***************************************************************************** */
function toggleFind(showtoggle, showcriteria, hidetoggle, hidecriteria) {
	$(showtoggle).className = 'active';
	$(hidetoggle).className = '';
	accordion(showcriteria, hidecriteria);
}

/* **************************************************************************
this function removes the 1px border around checkboxes and radio buttons
***************************************************************************** */
function addEvent(elm, evType, fn, useCapture) {
	if(elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}
// removes the square border that IE
// insists on adding to checkboxes and radio
function removeCheckBoxBorders() {
	var el = document.getElementsByTagName("input");
	for (i=0;i<el.length;i++) {
		var type = el[i].getAttribute("type");
		if((type=="checkbox")||(type=="radio")) {
			el[i].style.border = "none";
			el[i].style.backgroundColor = "transparent";
		}
	}
}
addEvent(window, 'load', removeCheckBoxBorders, false);

/* moved here from scope_adv_pub.js to reduce requests
	April 1 2008 Kelly Knight */

// changing the advertiser implicitly changes the publisher as well.
function changeAdv(formName,iframeFormName,URL,choose_selected) {
	var doc = document.forms[formName];
	doc.iframeForm.value = iframeFormName;
	doc.choose_selected.value = choose_selected;
	doc.change_selected.value = 1;
	doc.selected_merchant.value = '';
	doc.selected_affiliate.value = '';
	doc.action = URL;
    doc.target = "_top";
	doc.submit();
}

function changePub(formName,iframeFormName,URL) {
	var doc = document.forms[formName];
	doc.iframeForm.value = iframeFormName;
	doc.choose_selected.value = 1;
	doc.change_selected.value = 1;
	doc.selected_merchant.value = '<% $cc_session ? $cc_session->selected_merchant() : "" %>';
	doc.selected_affiliate.value = '';
	doc.action = URL;
    doc.target = "_top";
	doc.submit();
}

// this is simply a wrapper for changeAdv ATM.
// It may need to have differrent functionality later, 
// so I am leaving it in - JSG, 2005-07-12
function clearAdvPub(formName,iframeFormName,URL) {
    changeAdv(formName,iframeFormName,URL,0);
}

/* moved here from base_jscripts.mc to reduce requests
	April 1 2008 Kelly Knight */

// Determine browser
var isMinIE5 = (navigator.appVersion.indexOf("5.")) >= 0 ? 1 : 0;
var isDOM = (document.getElementById) ? 1 : 0;
// Alter color of text elements
function changeColor(objId,color) {
	var tabOff = "#999999";
	var tabOver = "#333333";
	if (!color.match('#')) {
		var color = eval(color);
	}

	if (isMinIE5||isDOM) {
		document.getElementById(objId).style.color=color;
	} else {
		return;
	}
}

// Alter background color of elements
function changeBgcolor(objId,name) {
	var tabBgOff = "tabOff"; // #fffff0 
	var tabBgOver = "tabOver"; // #dedecb
	var sortOffLight = "light";
	var sortOffDark = "dark"; // #f0f0e8
	var sortOnLight = "light"; // #dedecb
	var sortOnDark = "dark"; // #ccccb3
	var rolloverLight = "lightershadebg"; // #ccccb3
	var rolloverDark = "lightershadebg"; // #aaaa80
	var archivedOffDark = "dark red"; // #f0f0e8
	var archivedOffLight = "light red"; // #dedecb
	var overarchivedLight = "lightershadebg red"; // #ccccb3
	
	var name = eval(name);
	if(document.getElementById(objId)){
		document.getElementById(objId).className = name;
	}
}

////////////////// DON'T THINK THIS IS USED -KK //////////////////////////////////
// change color and bgcolor of tab links
function changeTabColor(tabId,name) {
	var tabOff = "tabOff";
	var tabOver = "tabOver";
	var name = eval(name);

	if (isMinIE5||isDOM) {
		if (document.getElementById(tabId).className == "tabOn") {
		// do nothing
		} else {
			document.getElementById(tabId).className = name;
		}
	} else {
		return;
	}
}

// script for row highlighting onmouseover-onmouseout
function changeClass(cellId,name) {
	document.getElementById(cellId).className = name;
}

// script for row highlighting onmouseover-onmouseout better
function changeClassName(cell,name) {
	cell.className = name;
}

// expands and collapses divs and spans (need to pass the ID)
function showTip(item) { 
 document.getElementById(item).className = "note visible";
}
 
function hideTip(item) { 
 document.getElementById(item).className = "hidden";
}

// defines empty fields
function isEmpty (inputStr) {
	if (inputStr == "" || inputStr == null) {
		return true;
	}
	return false;
}

/*
Submit Once form validation- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/
var submitcount = 0;
function submitOnce() {
	if (submitcount == 0) {
		submitcount++;
		return true;
	} else {
		alert("This form has already been submitted.  Thanks!");
		return false;
	}
}

function set_loading(state)
{
    var loading = document.getElementById('loading_message');
    if(state){
        log("Loading...");
        removeElementClass(loading, 'not_visible');
        var x = getScrollXY()[0];
        var y = getScrollXY()[1];
        var width = getWindowXY()[0];
        var height = getWindowXY()[1];
        var middle = height / 2;
        var vtop = (y + middle) - 200;
        loading.style.top = vtop + 'px';

    }
    else {
        log("Loaded...");
        addElementClass(loading, 'not_visible');
    }
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getWindowXY() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}

function showConfirmation(timeframe) {
	var container_id = 'g-confirmation-msg';
	var message_id = 'g-confirmation';
	
	positionScrollTop(container_id,message_id);
	
	window.scrollmessage = connect(window, 'onscroll', function() { positionScrollTop(container_id,message_id); });
	
	MochiKit.Visual.appear(container_id);
  if (typeof timeframe == 'undefined') {
		var timeframe = 4000;
	}
  setTimeout("MochiKit.Visual.fade('" + container_id + "');disconnect(window.scrollmessage);", timeframe);
}

function showError() {
	var container_id = 'g-error-msg';
	var message_id = 'g-error';

	positionScrollTop(container_id,message_id);

	window.scrollmessage = connect(window, 'onscroll', function() { positionScrollTop(container_id,message_id); });

	MochiKit.Visual.appear(container_id);
}

function positionScrollTop(container_id, message_id) {
	if($(container_id).style.display == 'none') {
		$(container_id).style.visibility = 'hidden';
		setDisplayForElement('', container_id);
		//get the size of the element container
		var elementDimensions = getElementDimensions(message_id);
		setDisplayForElement('none', container_id);
		$(container_id).style.visibility = '';
	} else {
		var elementDimensions = getElementDimensions(message_id);
	}

	var elw = elementDimensions.w + 1;
	setElementDimensions(container_id, {w:elw});

	var viewportDimensions = getViewportDimensions();
	var elx = (viewportDimensions.w - elementDimensions.w)/2;	

	elx = (elx < 0 ) ? 0 : elx;
	setElementPosition(container_id, {x:elx} );
	
	// figure out where the user is scrolled within the page to put the element at the top
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0) {
	    if (window.pageYOffset)
	        ScrollTop = window.pageYOffset - 3;
	    else
	        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	var msgTop = (ScrollTop == 0) ? 40 : ScrollTop;
	setElementPosition(container_id, {y:msgTop});
}

function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("Handler could not be attached");
	}
}

function gMenuShow(id, eventObj, mult) {
	var mid = 'options_' + id; // id of menu appearing
	if($(mid).style.display == 'none') {
		if(eventObj) {
			// hide any currently-visible popups
			gMenuHide();
			// stop event from bubbling up any farther
			eventObj.cancelBubble = true;
			positionMenu('options_' + id, 'bright_' + id);
			setDisplayForElement('', 'options_' + id);
			window.currentlyVisibleMenu = id;
			document.getElementById('bright_' + id).className = "gmenu_button_righton";
			document.getElementById('bleft_' + id).className = "gmenu_button_lefton";
			window.verifyclick = connect(document, 'onclick', function(e) {
				var elclk = e.target();	//element clicked on
				//check to see if the element clicked is a child of the menu that appears to the user
				var ischild = (isChildNode(elclk,mid));
				//if the element is not a child, the hide the menu.  otherwise do nothing (i.e. keep showing the menu).
				if(mult) {
					if(ischild == false) { 
						gMenuHide(); 
					}
				} else {
					gMenuHide();
				}
			});
		}
	} else {
		gMenuHide();
	}
}

function gMenuHide() {
	if(window.verifyclick) {
	 disconnect(window.verifyclick);
	}
	if(window.currentlyVisibleMenu) {
		setDisplayForElement('none', 'options_' + window.currentlyVisibleMenu);
		document.getElementById('bright_' + window.currentlyVisibleMenu).className = "gmenu_button_right";
		document.getElementById('bleft_' + window.currentlyVisibleMenu).className = "gmenu_button_left";
		window.currentlyVisibleMenu = false
	}
}

function positionMenu(mid, bid) {
	var bttnDim = getElementDimensions(bid);
	var bttnPos = getElementPosition(bid);
	var mnuDim = getElementDimensions(mid);
	var docDim = getElementDimensions(document.body);
	var vpDim = getViewportDimensions();
	
	var bttnright = (bttnPos.x - 2) + bttnDim.w;
	var bttntop = bttnPos.y;

	var mh = mnuDim.h - 10; /* 10 = 4px top and bottom padding and 1px top and bottom border */
	var mw = mnuDim.w - 2; /* 2 = 1px left and right border */
	
	var mnuw = (mw > 200) ? mw : '200';
	
	var sph = (docDim.h > vpDim.h) ? docDim.h : vpDim.h; /* of document.body is smaller than the height of the Viewport, then the allowable space is the Viewport height, else it's the document.body height */	 
	var sph = sph - bttntop - bttnDim.h - 10;

	if(bttnright < mnuw) {
		var mnux = bttnPos.x - 7;
	} else {
		var mnux = bttnright - mnuw;
	}	
	
	var mnuy = bttntop + bttnDim.h - 4;
	
	var mnuh = (mh > sph) ? sph : mh; /* if the original height of the menu is larger than the allowable space of the document body, then set mnuh to the allowable space */
	mnuh = (mnuh > 500) ? 500 : mnuh;  /* if the orignial height of the menu is larger than 500px, then set mnuh to 500 pixels. */

	setElementPosition(mid, {x:mnux, y:mnuy});
	setElementDimensions(mid, {w:mnuw, h:mnuh});
}

function menuShow(id, eventObj) {
    if(eventObj) {
		// hide any currently-visible popups
		menuHide();
		// stop event from bubbling up any farther
		eventObj.cancelBubble = true;
		setDisplayForElement('', id);
		window.currentlyVisibleMenu = id;
		connect(document, 'onclick', function() { menuHide(); });
	}
}

function menuHide() {
    if(window.currentlyVisibleMenu) {
		setDisplayForElement('none', window.currentlyVisibleMenu);
		window.currentlyVisibleMenu = false;
    }
}

function toggleTip(id, e) {
	if($(id).style.display == 'none') {
		var mouse = e.mouse();
		var mx = mouse.page.x + 5;
		var my = mouse.page.y + 5;
		setElementPosition(id, {x:mx, y:my});
	}
	toggle(id, 'appear', {duration: .25});
	return false;
}

function toggleSteps(stepno, numsteps) {
  for(ii=1; ii<=numsteps; ii++) {
    setDisplayForElement('none', 'step' + ii + '_content');
    $('step' + ii + '_header').className = 'inactive';
  }
  var activeh = 'step' + stepno + '_header';
  if(stepno > 1){
    var prevh = 'step' + (stepno -1) + '_header';
    $(prevh).className = 'previous';
  }
  var activec = 'step' + stepno + '_content';
  $(activeh).className = 'active';
  setDisplayForElement('', activec);
}

function openNW(url, cwidth, cheight) {
        var viewportDimensions = getViewportDimensions();

        var wx = ((viewportDimensions.w + 30)- cwidth)/2;
        var wy = ((viewportDimensions.h + 70) - cheight)/2;

        wx = (wx < 0) ? 0 : wx;
        wy = (wy < 0) ? 10 : wy;

        var childW = null;
        if(childW != null) childW.window.close();
        var wvars = 'width=' + cwidth + ',height=' + cheight + ',left=' + wx + ',top=' + wy + ',menubar=no,status=no,toolbar=no,scrollbars=yes,directories=no,location=no';
        childW = window.open(url,'childW',wvars);
        return false;
}
