






//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;
    }    
}

//Ravi 10/11/2011 - Modified to support showing a text box for the user to type in international state
//Ravi 11/15/2011 - To select the phone country code when user selects a country
function validateSelectCorrectState(countryCombo, stateComboId, intltdStateTxtId, intlStateValidatorId, txtDummyId, phoneCountryComboId)
{
    stateCombo = document.getElementById(stateComboId);
    stateCombo.disabled = false;
    var tdInternationalState, stateValidator;
    
    if(intltdStateTxtId && intltdStateTxtId != ''){
        tdInternationalState = document.getElementById(intltdStateTxtId);
    }
    if(intlStateValidatorId && intlStateValidatorId != ''){
        stateValidator = document.getElementById(intlStateValidatorId);
    }
    
    //Set the phone country code.
    if(phoneCountryComboId && phoneCountryComboId != '' && countryCombo){
        var phoneCountryCombo = document.getElementById(phoneCountryComboId);
        if(phoneCountryCombo && phoneCountryCombo != null){
            try{
                phoneCountryCombo.value = countryCombo.value;
                phoneCountryCombo.className = phoneCountryCombo.className.replace('water','');
            }
            catch(eXe){//Log client error.  
            }
        }
    }
    
    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;
                stateCombo.style.display = 'none';
            }
        }
        if(tdInternationalState){
                tdInternationalState.style.display = 'block';
                if(stateValidator && stateValidator.controltovalidate){
                    stateValidator.controltovalidate = intltdStateTxtId;
                    stateValidator.enabled = true;
                }
        }      
    }    
    
    else if(countryCombo.options[countryCombo.selectedIndex].value == 'USA' || countryCombo.options[countryCombo.selectedIndex].value == 'CAN')
    {
        for(var i = 0; i < stateCombo.length; i++)
        {
            if(stateCombo.options[i].value == '-1')
            {
                stateCombo.selectedIndex = i;
                stateCombo.style.display = 'block';
            }
        }
        if(tdInternationalState){
                tdInternationalState.style.display = 'none';
                if(stateValidator && stateValidator.controltovalidate){
                    stateValidator.controltovalidate = txtDummyId;
                    stateValidator.enabled = false;
                }
        }
    }    
}

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");	
		var checkboxPrint = null;
		if (r[i].cells[5] != null)
		{
		    checkboxPrint = r[i].cells[5].getElementsByTagName("input")[0];
		}
		
		if(i == (radioButtonIndex + 1))
		{	
			checkboxes[0].disabled = true;	
			checkboxes[0].checked = false;		
			
			if (checkboxPrint != null)
            {
                checkboxPrint.disabled = false;
            }
		}
		else
		{
			checkboxes[0].disabled = false;
			
			if (checkboxPrint != null)
            {
                
			    if (checkboxes[0].checked == true)
			    {
			        checkboxPrint.disabled = false;
			    }
			    else
			    {
			        checkboxPrint.disabled = true;	
			        checkboxPrint.checked = false;		
			    }
		    }
		}
		
		
		
	}
	return true;
}

function UpdatePrintFullfillmentCheckbox(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");	
		var checkboxPrint = r[i].cells[5].getElementsByTagName("input");
		
		if (checkboxPrint[0] != null)
		{
		    if (checkboxes[0].checked == true || checkboxes[0].disabled == true)
		    {
		        checkboxPrint[0].disabled = false;
		    }
		    else
		    {
		        checkboxPrint[0].disabled = true;	
		        checkboxPrint[0].checked = 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 settabWithPostBack(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";
            }
        }
    }
    __doPostBack('','');
}

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;
}
    /* Function to open new window with AMA IOM Membership pricing details */
    function showIOMPricing(){
        window.open('www.google.com','win','height:100,width:400');
    }
    /* Functions to show an Ajax-based rolldown tooltip */
    function showToolTip(el){

    var title = 'American Marketing Association';
    var type = 'membership';
    if(el && el.id){
        switch(el.id){
            case 'spProfessional_Membership_Tip': 
                    title += ' - Professional Membership'; 
                    break;
            case 'spYoung_Professional_Membership_Tip': 
                    title += ' - Young Professional Membership';
                    break;   
        }
        type = el.id;
    }
    showToolTipBase(el,type, title);
    }
    function showToolTipBase(el, type, title) {
        
        //Show tooltip here.
        
    } 
    //Summary
    //Function to manage complimentary vs priced publications / SIG's & ENewsletters after user selects a subscription
    //gvId      -->      Client ID of the Grid
    //indx      -->      Row number
    //dPrice    -->      Price for the publication / SIG
    //dCompOverride -->  To just show complimentary when checked like in ENewsletters.
    //dPrintColIndx  -->  For publications - whether to show Print option in the last column   
    //dCompHiddenFld --> To read which subscription is complimentary when uploading info to the server.
    //dPriceOverride --> To skip complimentary and show the price. (students)
    //dPrintOrOnlinePrice --> To differentiate between online and print pricing.
    function updatePublicationsInfo(gvId, indx, colIndexes, dPrice,dCompOverride,dPrintColIndx, dCompHiddenFld, dPriceOverride, dPrintOrOnlinePrice)
    {
        var d = document.getElementById(gvId);
        var isCompSelected = false, forcePrice = false, isChecked = false , forceComplimentary = false, compHdnField = null;
        var r,checkboxes;
        var nxtIndxComp = -1, PRINT_COL_INDX = -1, CHECKBOX_COLUMN = 3, PRICE_DETAIL_COLUMN = 2, COMPLIMENTARY = "complimentary", PRICE = "$50";
        var printPrice, onlinePrice, selectedPubOption = 'P';

        
        //Reset variables based on type of grid
        if(colIndexes && colIndexes != ''){
            var tempIndxs = colIndexes.split(",");
            if(tempIndxs && tempIndxs.length > 0){
                PRICE_DETAIL_COLUMN = tempIndxs[0];
                CHECKBOX_COLUMN = tempIndxs[1];
            }
        }
        if(dPrintOrOnlinePrice && dPrintOrOnlinePrice != ''){
           var dPrintDocsEl = document.getElementById(dPrintOrOnlinePrice);
           if(dPrintDocsEl){
               var dPrintRadioBtns = dPrintDocsEl.getElementsByTagName('input');
               if(dPrintRadioBtns && dPrintRadioBtns.length > 0){
                    for(var l=0;l<dPrintRadioBtns.length;l++){
                        if(dPrintRadioBtns[l].checked == true){
                            if(dPrintRadioBtns[l].value == 'PRINT'){
                                selectedPubOption = 'P';
                            }
                            else{
                                selectedPubOption = 'O';
                            }
                        }
                    }
               } 
           }
        }
        if(dPrice && dPrice != ''){
            PRICE = dPrice;
            if(dPrice.indexOf(',') != -1){
                //Add span and add attributes to it, to access them later 
                var allPrices = dPrice.split(',');
                if(allPrices && allPrices.length > 0){
                    printPrice = allPrices[0];
                    onlinePrice = allPrices[1];
                    if(selectedPubOption == 'P'){
                        PRICE = "<span name='dPrintOnlinePrice' printprice='" + printPrice + "' onlineprice='" + onlinePrice + "' />" + printPrice + "</span>";
                    }
                    else{
                        PRICE = "<span name='dPrintOnlinePrice' printprice='" + printPrice + "' onlineprice='" + onlinePrice + "' />" + onlinePrice + "</span>";
                    }
                }
            }
        }
        if(dCompOverride && dCompOverride == 'true'){
            forceComplimentary = true;
        }
        if(dPrintColIndx && dPrintColIndx!= null){
            PRINT_COL_INDX = dPrintColIndx;
        }
        if(dCompHiddenFld && dCompHiddenFld != ''){
            compHdnField = document.getElementById(dCompHiddenFld);                                	                        
        }
        if(dPriceOverride && dPriceOverride == 'true'){
            forcePrice = true;
        }
        try{
            r = d.rows;
            if(r && r != 0 && indx){
                for(var t=0;t<r.length;t++){
                    if(r[t].cells[PRICE_DETAIL_COLUMN].innerHTML.replace(/\n/g,'').trim() == COMPLIMENTARY && !isCompSelected){
                        isCompSelected = true;
                        break;
                    }
                }
                checkboxes = r[indx].cells[CHECKBOX_COLUMN].getElementsByTagName("input");
                if(checkboxes && checkboxes[0].checked == true){
                    isChecked = true;
                }
                if(isChecked == true){
                     if((isCompSelected == false || forceComplimentary === true) && forcePrice == false ){
                        r[indx].cells[PRICE_DETAIL_COLUMN].innerHTML = COMPLIMENTARY;
                        if(compHdnField != null){
                            compHdnField.value = indx;
                        }
                     }
                     else{
                        r[indx].cells[PRICE_DETAIL_COLUMN].innerHTML = PRICE; 
                     }
                }
                else{
                    if(forceComplimentary === false && forcePrice == false){
                        if(r[indx].cells[PRICE_DETAIL_COLUMN].innerHTML.replace(/\n/g,'').trim() == COMPLIMENTARY){
                            for(var t=0;t<r.length;t++){
                                var bCheckbox = r[t].cells[CHECKBOX_COLUMN].getElementsByTagName("input")[0];
                                if(isCompSelected && bCheckbox.checked == true && bCheckbox.disabled != true ){
                                    nxtIndxComp = t;
                                    break;
                                }
                            }
                            if(nxtIndxComp != -1){
                                r[nxtIndxComp].cells[PRICE_DETAIL_COLUMN].innerHTML = COMPLIMENTARY;
                               if(compHdnField != null){
                                    compHdnField.value = nxtIndxComp;
                                }
                            }
                        }
                    }
                    r[indx].cells[PRICE_DETAIL_COLUMN].innerHTML = "";
                    //Print option
                     if(PRINT_COL_INDX > -1){
                        r[indx].cells[PRINT_COL_INDX].display = 'block';
                     }
                }
                //Print option
                if(PRINT_COL_INDX > -1){
                    var cbPrint = r[indx].cells[PRINT_COL_INDX].getElementsByTagName("input");
                    var printCol = r[indx].cells[PRINT_COL_INDX].getElementsByTagName("span");
                    if(cbPrint && printCol && printCol.length > 0 && printCol.length > 0){
                        if(isChecked == true){
                            printCol[0].style.display = 'block';
                        }
                        else{
                            cbPrint[0].checked = false;
                            printCol[0].style.display = 'none';
                        }
                    }
                }
            }
        }
        catch(err){
            //Todo: Log exception to application error manager.	        
        }
    	
        return true;
    }
    ///Ravi 10/05/2011 - In step1 of membership registration, to check switch between login and create login
    // If the user enters an email in the login step we turn the create login's validations off and turn on the login field's validations
    function skipCreateLoginValidations(txtEmailAddrId,passFldId, loginCtrl){
        //disable all validators in login control
        var loginCtrlsCount = 0;
        var loginCtrlFields = document.getElementById(loginCtrl).getElementsByTagName('input');
        var loginCtrlDropDown = document.getElementById(loginCtrl).getElementsByTagName('select');
        var txtEmailAddrFld = document.getElementById(txtEmailAddrId);
        var passFld = document.getElementById(passFldId);
        var createLoginValidation = false, loginValidation = true;
        if(txtEmailAddrFld != null && passFld != null   ){
            if((txtEmailAddrFld.value == txtEmailAddrFld.title || txtEmailAddrFld.value == '' )){ //Check for watermark
                createLoginValidation = true; loginValidation = false;
            }
            loginCtrlsCount = loginCtrlFields.length;
            if(loginCtrlFields && loginCtrlFields.length > 0){
                if(loginCtrlDropDown && loginCtrlDropDown.length == 1){
                    loginCtrlFields[loginCtrlFields.length] = loginCtrlDropDown[0];
                    loginCtrlsCount += 1; //Could have used push, but for some reason this object is not treated as Array
                }
       	        for(var k=0;k<loginCtrlsCount;k++){
                    if(loginCtrlFields[k].Validators){
                        for(var i=0;i<loginCtrlFields[k].Validators.length;i++){
                            loginCtrlFields[k].Validators[i].enabled = createLoginValidation;
                        }
                    }		
                }
                if(txtEmailAddrFld.Validators && passFld.Validators){
                    txtEmailAddrFld.Validators[0].enabled = loginValidation;
                    txtEmailAddrFld.Validators[1].enabled = loginValidation;
                    passFld.Validators[0].enabled = loginValidation;
                }
            }
        }    
    }
    //Ravi 10/14/2011 Function to populate mailing address in payment screen.
    //intlOptions - Optional, used for international addresses.
    function fillMailingAddress(chckFld, addressFields, fieldIds, isIntl,intlOptions){
        try{
            var isChecked = true;
            if(chckFld && chckFld != null && !chckFld.checked){
                isChecked = false;
            }
            if((addressFields != null && addressFields != '') && (fieldIds != null && fieldIds != '')){
                var dAddressFields = addressFields.split('@#');
                var dFieldIds = fieldIds.split(',');                        
                if(dAddressFields.length > 0 && dFieldIds.length > 0){
                    for(var k=0; k< dAddressFields.length; k++){
                        var tmpFld = document.getElementById(dFieldIds[k]);
                        if(tmpFld && tmpFld != null){
                            if(isChecked){
                                tmpFld.value = dAddressFields[k];
                            }
                            else{
                                if(tmpFld.type != null){
                                    if(tmpFld.type.indexOf('text') != -1){
                                        tmpFld.value = '';
                                    }
                                    else{
                                        tmpFld.selectedIndex = 0;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if(isIntl && isIntl == 'true' && intlOptions != ''){
                var iOptions = intlOptions.split(','), comboBoxObj, stateBoxId,intlStateTxtId, intlStateValidatorId, txtDummyId;
                if(iOptions && iOptions.length > 1){
                    comboBoxObj = document.getElementById(iOptions[0]);
                    stateBoxId = iOptions[1];
                    intlStateTxtId = iOptions[2];
                    intlStateValidatorId = iOptions[3];                     
                    txtDummyId = iOptions[4];
                }
                validateSelectCorrectState(comboBoxObj, stateBoxId, intlStateTxtId, intlStateValidatorId, txtDummyId);
            }
        }
        catch(e){
            //Log javascript error.
        }
    }
    
    //Ravi 10/28/2011 - To show the mobile text msessage checkbox option
    function showMobileMsgCheckBox(phoneTypeCombo, msgChckBoxContainer)
    {
        if(phoneTypeCombo && msgChckBoxContainer){
            var msgChckBoxEl = document.getElementById(msgChckBoxContainer);
            if(msgChckBoxEl){
                if(phoneTypeCombo.options[phoneTypeCombo.selectedIndex].value == 'MOBILE'){
                    msgChckBoxEl.style.display = 'block';
                }
                else{
                    msgChckBoxEl.style.display = 'none';
                }
            }    
        }
    }
    
    
    //Ravi 11/01/2011 - To Swap online and print prices display in publication screen
    function swapPrintOrOnlinePubsPricing(selectedOption, gridId){
        //Get all spans by name='dPrintOnlinePrice' within grid and find the price attribute and swap it.
        if(selectedOption){
            
            var priceAttr = 'printprice', allowPriceChange = true;
            var currentSel = '';
            var previousSel = '';
            try{
                previousSel = selectedOption.getAttribute('previousSel');
            }
            catch(ex){
                previousSel = '';
            }
            var dPrintRadioBtns = selectedOption.getElementsByTagName('input');
            if(dPrintRadioBtns && dPrintRadioBtns.length > 0){
                for(var l=0;l<dPrintRadioBtns.length;l++){
                    if(dPrintRadioBtns[l].checked == true){
                        currentSel = dPrintRadioBtns[l].value; 
                        if(dPrintRadioBtns[l].value != 'PRINT'){
                            priceAttr = 'onlineprice';
                        }
                    }
                }
            }
            if(currentSel != '' && previousSel != ''){
                if(currentSel == previousSel){
                    allowPriceChange = false;
                }
            }
            if(allowPriceChange == true){
                 var selectedPubs = [];
                 if(gridId){
                    var pubsGrid = document.getElementById(gridId);
                    if(pubsGrid){
                        var spansWithinGrid = pubsGrid.getElementsByTagName('span');
                        var selectedPubsNum = 0;
                        if(spansWithinGrid && spansWithinGrid.length > 0){
                            for(var s=0;s<spansWithinGrid.length;s++){
                                if(spansWithinGrid[s].getAttribute('name') && spansWithinGrid[s].getAttribute('name') == 'dPrintOnlinePrice'){
                                    selectedPubs[selectedPubsNum] = spansWithinGrid[s];    
                                    selectedPubsNum++;                       
                                }
                            }
                        }
                    }
                 }
                 
                 if(selectedPubs && selectedPubs.length > 0){
                    for(var m=0;m<selectedPubs.length;m++){
                        var pubRow = selectedPubs[m];
                           
                        if(pubRow && pubRow.getAttribute(priceAttr)){
                            var otherPrice = pubRow.getAttribute(priceAttr);
                            pubRow.innerHTML = otherPrice;
                            pubRow.textContent = otherPrice; //IE    
                        }
                    }
                 }
                 //Ravi 12/20/2011 to avoid multiple clicks issue.
                 selectedOption.setAttribute('previousSel',currentSel);
             }//allowPriceChange
             
        }
    }
    
    

