//addEvent(window, 'load', setCurrentNav);
function setCurrentNav(){
    var topNavObj = _gel("AMAtopNav");
    var navArr = getElementsByClass("inactiveMenu", topNavObj, "a");
    var navLength = navArr.length;
    var navHref = "";
    
    var url = window.document.URL.toString();
    var surl = url.split("http://")[1];        
    var section = surl.split("/")[1];
    
    if (navLength > 0){
	    for(var i=0;i<navLength;i++){
		    navHref = navArr[i].getAttribute("href");
		     
            if(navHref.indexOf(section) > -1){
                navArr[i].setAttribute(classAttribute, "activeMenu");
            }
	    }		
    }
}

function switchid(id) {	
    if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == '') {
        showdiv(id);
    }
    else {
        hidediv(id);
    }
}

function hidediv(id) {
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        if(document.getElementById(id) != null)
            document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) { // Netscape 4
	        document.id.display = 'none';
        }
        else { // IE 4
	        document.all.id.style.display = 'none';
        }
    }
}

function isIE()
{
    return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}



function showdiv(id) {
    //safe function to show an element with a specified id
    if (document.getElementById)
    { // DOM3 = IE5, NS6
        if(document.getElementById(id) != null)
        {
            if (document.getElementById(id).tagName == 'TR')
            {
                if (isIE())
                {
                    document.getElementById(id).style.display = '';
                }
                else
                {
                    document.getElementById(id).style.display = 'table-row';
                }
            }
            else
            {
                document.getElementById(id).style.display = 'block';
            }
        }
    }
    else
    {
        if (document.layers) { // Netscape 4
	        document.id.display = 'block';
        }
        else { // IE 4
	        document.all.id.style.display = 'block';
        }
    }
}


function enableAddressInformationCheckboxPublishInAMAPublication(includeInAMADirectoryCheckBox, secondaryIsActive, doNotPublishPrimaryCheckBox, doNotPublishSecondaryCheckBox)
{   
    if(includeInAMADirectoryCheckBox.checked)
    {
        doNotPublishPrimaryCheckBox.disabled = false;
        doNotPublishPrimaryCheckBox.checked = false;
        if(secondaryIsActive)
        {
            doNotPublishSecondaryCheckBox.disabled = false;
            doNotPublishSecondaryCheckBox.checked = false;
        }
    }
    else
    {
        doNotPublishPrimaryCheckBox.disabled = true;
        doNotPublishSecondaryCheckBox.disabled = true;
    }    
}

function validateSelectCorrectState(countryCombo, stateComboId)
{
    stateCombo = document.getElementById(stateComboId);
    stateCombo.disabled = false;
    if(countryCombo.options[countryCombo.selectedIndex].value != 'USA' && countryCombo.options[countryCombo.selectedIndex].value != 'CAN' && countryCombo.options[countryCombo.selectedIndex].value != '-1')
    {
        for(var i = 0; i < stateCombo.length; i++)
        {
            if(stateCombo.options[i].value == 'NA')
            {
                stateCombo.selectedIndex = i;
                stateCombo.disabled = true;
            }
        }      
    }    
    else if(countryCombo.options[countryCombo.selectedIndex].value == 'USA' || countryCombo.options[countryCombo.selectedIndex].value == 'CAN')
    {
        if(stateCombo.options[stateCombo.selectedIndex].value == 'NA' || stateCombo.options[stateCombo.selectedIndex].value == '')        
        for(var i = 0; i < stateCombo.length; i++)
        {
            if(stateCombo.options[i].value == '-1')
            {
                stateCombo.selectedIndex = i;
            }
        }      
    }    
}

function enableOtherTextBox(combo, textBoxId)
{
    if (combo.options[combo.selectedIndex].value.toLowerCase() == "other")
    {
        if(document.getElementById(textBoxId) != null)
        {
            document.getElementById(textBoxId).disabled = false;
            
            classString = new String(document.getElementById(textBoxId).className);
            document.getElementById(textBoxId).className = classString.replace(/ disabled/g, "");
            
            return true;
        }
    }
    else
    {        
        document.getElementById(textBoxId).disabled = true;
        document.getElementById(textBoxId).className += " disabled";
        return true;
    }
}

function enableAddressInformationControl(isDisabled, containerDivId, includeInAMADirectory)
{	
    container = document.getElementById(containerDivId);
    textBoxes = container.getElementsByTagName("input");
    for(var i = 0; i < textBoxes.length; i++)
    {
        if(textBoxes[i].getAttribute("type") == 'text')
        {
            textBoxes[i].disabled = isDisabled;
            if(isDisabled)
            {				
                textBoxes[i].className += " disabled";
            }
            else
            {
                classString = new String(textBoxes[i].className);
                textBoxes[i].className = classString.replace(/ disabled/g, "");            			
            }
        }
        else if(textBoxes[i].getAttribute("type") == 'checkbox')
        {
            if(!includeInAMADirectory && !isDisabled)
            {
            // do nothing
            }
            else
            {
                textBoxes[i].disabled = isDisabled;
            }
        }
    }
    comboBoxes = container.getElementsByTagName("select");
    for(var i = 0; i < comboBoxes.length; i++)
    {		
        comboBoxes[i].disabled = isDisabled;
        if(isDisabled)
        {            		
            comboBoxes[i].className += " disabled";
        }
        else
        {
            classString = new String(textBoxes[i].className);
            comboBoxes[i].className = classString.replace(/ disabled/g, "");
        }	
    }
    return true;
}

function expandCollapse(id)
{
    //Expand or Collapse specific expandable control based on class
    if (document.getElementById('expandableHeader' + id).className == 'closed')
    {
        document.getElementById('expandableHeader' + id).className = "open";
        document.getElementById('expandableContent' + id).className = "open";
    }
    else
    {
        document.getElementById('expandableHeader' + id).className = "closed";
        document.getElementById('expandableContent' + id).className = "closed";
    }
}

function sortList(id) {
	var obj = document.getElementById(id);
	var values = new Array();
	for(var i = 0; i < obj.options.length; i++) {
		values.push(obj.options[i].innerHTML + "--xx--" + obj.options[i].value);
	}

	values = values.sort();

	for(var i = 0; i < values.length; i++) {
		valueArray = values[i].split('--xx--');
		obj.options[i].innerHTML = valueArray[0];
		obj.options[i].value = valueArray[1];
	}
}

function setComboBoxByElementId(prefix, id, comboId)
{
    if (document.getElementById) { // DOM3 = IE5, NS6
        if(document.getElementById(id) != null)
            setComboBoxTab(prefix, id, document.getElementById(comboId));
    }
    else {
        if (document.layers) { // Netscape 4
	        setComboBoxTab(prefix, id, document.comboId);
        }
        else { // IE 4
	        setComboBoxTab(prefix, id, document.all.comboId);
        }
    }    
}
function setComboBoxTab(prefix, id, combo)
{
    //reset all tabs to default inactive and hidden
    var i;
    for (i = 0; i<=combo.length - 1; i++)
    {
        if (combo.options[i].text == id)
            showdiv(prefix + 'Content' + id);
        else
            hidediv(prefix + 'Content' + combo.options[i].text);
    }   
}


function setSelectedSessionTutorial(checkBoxId, availableId, selectedId, isSelected)
{

    if(isSelected == 'true')
    {
        showdiv(selectedId);
        hidediv(availableId);
        document.getElementById(checkBoxId).checked = true;
    }
    else
    {
        showdiv(availableId);
        hidediv(selectedId); 
        document.getElementById(checkBoxId).checked = false;
    }
    SumSelectedEventSessions();
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function UpdateComplimentarySelectedCheckboxGridView(radioButtonIndex, gvId)
{	

	var d = document.getElementById(gvId);
	var r = d.rows;
	var i = r.length;

	while((i--) - 1)
	{ 	
		var checkboxes = r[i].cells[1].getElementsByTagName("input");	
		if(i == (radioButtonIndex + 1))
		{	
			checkboxes[0].disabled = true;	
			checkboxes[0].checked = false;		
		}
		else
		{
			checkboxes[0].disabled = false;	
		}
	}
	return true;
}

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function placeInHidden(delim, selStr, hidStr)
{

  var selObj = document.getElementById(selStr);
  var hideObj = document.getElementById(hidStr);
  hideObj.value = '';

  if(selObj.options.length > 0)
  {
  for (var i=0; i<selObj.options.length; i++) {
    hideObj.value = hideObj.value ==
      '' ? selObj.options[i].value : hideObj.value + delim + selObj.options[i].value;
  }
  }
}


function MoveListItemBetweenListBoxes(fromListBoxId, toListBoxId, selectedListBoxId, hiddenFieldId, sortAfterChange)
{

	var theSelFrom = document.getElementById(fromListBoxId);
	var theSelTo = document.getElementById(toListBoxId);
	var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  if(NS4) history.go(0);

  placeInHidden('|', selectedListBoxId, hiddenFieldId);


  if(sortAfterChange)
  {
    sortList(toListBoxId);
  }
}


function SumSelectedEventSessions() {
	var t = [], c,
	d = document.getElementById('SelectedTutorialsTable'),
	r = d.rows, 
	i = r.length - 1, 
	lastrow = r[i];
	t[0] = 0;
	t[1] = 0;

	while((i--) - 1)
	{ 				
		if(r[i].style.display != 'none')
		{
			c = r[i].cells;		
			t[0] += parseFloat(c[3].firstChild.nodeValue.replace("$", "").replace(",", ""));
			t[1] += parseFloat(c[4].firstChild.nodeValue.replace("$", "").replace(",", ""));	
		}	
	}


	lastrow.cells[1].firstChild.nodeValue = "$"+CommaFormatted(CurrencyFormatted(t[0])); 
	lastrow.cells[2].firstChild.nodeValue = "$"+CommaFormatted(CurrencyFormatted(t[1])); ; 
}


function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}

function settab(prefix, id){
    //reset all tabs to default inactive and hidden
    for(i = 1; i <= 12; i++)
    {
        if(document.getElementById(prefix + 'HasExpandedTabs').value == 'false')
            hidediv(prefix + 'Content' + i);

        if(document.getElementById(prefix + 'Content' + i) != null && document.getElementById(prefix + 'Content' + i).className == "tabHiddenContent")
        {
            hidediv(prefix + 'Content' + i);
        }
        else 
        {
            if(document.getElementById(prefix + 'Tab' + i) != null && i == id)
            {
                showdiv(prefix + 'Content' + i);
                document.getElementById(prefix + 'Tab' + i).className = "tabActive";
                document.getElementById(prefix + 'CurrentTabIndex').value = id;
            }
            else if(document.getElementById(prefix + 'Tab' + i) != null && i != id)
            {                        
                document.getElementById(prefix + 'Tab' + i).className = "tab";
            }
        }
    }   
}
function printPage() {
	window.print();
	return false;
}

function emailPage()
{
	window.location = "mailto:?subject=Interesting information on www.marketingpower.com&body=" + window.location + "";
	return false;
}

function ratingclear(star1id, star2id, star3id, star4id, star5id, offimage)
{
    document.getElementById(star1id).src = offimage;
    document.getElementById(star2id).src = offimage;
    document.getElementById(star3id).src = offimage;
    document.getElementById(star4id).src = offimage;
    document.getElementById(star5id).src = offimage;
}

function ratinghover(star1id, star2id, star3id, star4id, star5id, onimage, cur)
{
    if(cur >= 1)
        document.getElementById(star1id).setAttribute('src', onimage);
    if(cur >= 2)
        document.getElementById(star2id).setAttribute('src', onimage);
    if(cur >= 3)
        document.getElementById(star3id).setAttribute('src', onimage);
    if(cur >= 4)
        document.getElementById(star4id).setAttribute('src', onimage);
    if(cur >= 5)
        document.getElementById(star5id).setAttribute('src', onimage);
}

function popUp(divName, overlayName)
{
    showdiv(divName);
    showdiv(overlayName);
}

function onFocusEmail(emailField)
{
    if (emailField.value == 'E-Mail Address')
    {
        emailField.value = '';
    }
    return true;
}

function onBlurEmail(emailField)
{
    if (emailField.value == '')
    {
        emailField.value = 'E-Mail Address';
    }
    return true;
}

/* Extracted from Prototype JS Library, http://prototype.conio.net/
 Written by Sam Stephenson, http://conio.net/ */
function _gel() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = (document.getElementById) ? document.getElementById(element) : eval("document.all."+element) ;
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}

/* Function to grab all elements with a specific class name.
 Original written by Jonathan Snook, http://www.snook.ca/jonathan
 Add-ons by Robert Nyman, http://www.robertnyman.com 	
 Re-written by Zack Gilbert of Seen Creative, http://www.weareseencreative.com */
function getElementsByClass(className, elm, tag){
	if(elm == null) elm = document;
	if(tag == null) tag = '*';
	var elems = elm.getElementsByTagName(tag);
	var returnElems = new Array();
	className = className.replace(/\-/g, "\\-");
	var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
	for(var i=0; i<elems.length; i++){
		if(pattern.test(elems[i].className)) returnElems.push(elems[i]);
	}
	return returnElems
}

/* Function to return the class attribute. IE and all other standards compliant browsers have different names for the class attribute object. */
var classAttribute = classAttr();
function classAttr(){
	if (isIE()){
		class_att = 'className';
	}
	else {
		class_att = 'class';
	}
	
	return class_att;
	
}
/* Functions to add/remove event listeners to objects
	Written by John Resig, http://ejohn.org */
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

/* Functions to handle cross-browser events.
 Written by Zack Gilbert of Seen Creative, http://www.weareseencreative.com. */
/* get the target of an event object */
function getTarget(e) {
	return (e.target) ? e.target : e.srcElement;
}

function clean(elm) {
	while(_gel(elm).hasChildNodes()) {
		_gel(elm).removeChild(_gel(elm).childNodes[0]);
	}
	return true;
}
