if (typeof top.xo == "undefined")
{
	top.xo = new Object();
}

// top.xo.cs = "Current Selections"
top.xo.cs = new Object();
top.xo.cs.initialized = false;

top.xo.cs.init = function()
{
	if (top.xo.cs.initialized)
	{
		return true;
	}
	
	var currentSelectionsBoxTitle = document.getElementById("currentSelectionsBoxTitle");
	
	if (!currentSelectionsBoxTitle)
	{
		return false;
	}
	
	top.xo.cs.nodes = new Object();
	top.xo.cs.nodes['container'] = currentSelectionsBoxTitle.parentNode;
	top.xo.cs.nodes['planName'] = document.getElementById("planName");
	top.xo.cs.nodes['monthPrepay'] = document.getElementById("monthPrepay");
	top.xo.cs.nodes['monthly'] = document.getElementById("monthly");
	top.xo.cs.nodes['setupFee'] = document.getElementById("setupFee");
	top.xo.cs.nodes['domNameReg'] = document.getElementById("domNameReg");
	top.xo.cs.nodes['privateRegCost'] = document.getElementById("privateRegCost");
	top.xo.cs.nodes['autorenew'] = document.getElementById("autorenew");
	
	for (nodeID in top.xo.cs.initData)
	{
		if (typeof top.xo.cs.initData[nodeID] == "object")
		{
			var text = top.xo.cs.initData[nodeID].text;
			var value = top.xo.cs.initData[nodeID].value;
			
			top.xo.cs.addTitle(text, nodeID + "_title", nodeID);
			top.xo.cs.changeText(nodeID, value);
			
			if (typeof top.xo.cs.initData[nodeID].contents == "object")
			{
				for (bulletID in top.xo.cs.initData[nodeID].contents)
				{
					var bulletData = top.xo.cs.initData[nodeID].contents;
					
					if (typeof bulletData[bulletID].text == "undefined")
					{
						continue;
					}
					
					var bulletText = bulletData[bulletID].text;
					var bulletValue = bulletData[bulletID].value;
					top.xo.cs.addBullet(bulletText, bulletID);
					top.xo.cs.changeText(bulletID, bulletValue);
				}
			}
		}
	}
	var planRadioButtons = document.forms['regForm'].elements['pPlan'];
	
	if (typeof planRadioButtons != "undefined")
	{
		for (buttonIndex = 0; buttonIndex < planRadioButtons.length; buttonIndex++)
		{
			var button = planRadioButtons[buttonIndex];
			if (button.defaultChecked == true)
			{
				button.onclick.apply(top);
			}
		}
	}
		
	top.xo.cs.initialized = true;
	//top.xo.cs. = document.getElementById("");
}

top.xo.cs.updateAutorenew = function(state)
{
	var container = document.getElementById("contents_planName_title");
	top.xo.cs.setBulletContainer(container);
	
	if (state == "yes")
	{
		if (!top.xo.cs.nodes['autorenew'])
		{
			top.xo.cs.addBullet('Autorenew', 'autorenew');
		}
		// do not change text here.
	}
	else
	{
		top.xo.cs.removeBullet('autorenew');
	}
}

top.xo.cs.updatePrivateReg = function(state)
{
	var container = document.getElementById("contents_planName_title");
	top.xo.cs.setBulletContainer(container);
	if (state == "yes")
	{
		if (!top.xo.cs.nodes['privateRegCost'])
		{
			top.xo.cs.addBullet("Private Domain Registration", "privateRegCost");
		}
		
		top.xo.cs.changeText('privateRegCost', document.getElementById("pPrivateRegCost").value);
	}
	else
	{
		top.xo.cs.removeBullet('privateRegCost');
	}
}

top.xo.cs.updateRegFee = function(regTermSelect)
{
	var container = document.getElementById("contents_planName_title");
	top.xo.cs.setBulletContainer(container);
	var regText = regTermSelect.options[regTermSelect.selectedIndex].text;
	
	var newCost = regText.split(" ")[0];
	
	if (!top.xo.cs.nodes['domNameReg'])
	{
		top.xo.cs.addBullet('Domain Name Registration', 'domNameReg');
	}
	
	top.xo.cs.changeText('domNameReg', newCost);
}

top.xo.cs.updatePrepay = function(numMonths, cost, avg)
{
	var container = document.getElementById("contents_planName_title");
	top.xo.cs.setBulletContainer(container);
	
	top.xo.cs.removeBullet('monthPrepay');
	top.xo.cs.removeBullet('monthPrepayAvg');
	
	if (numMonths != "0" && numMonths != "")
	{
		top.xo.cs.addBullet(numMonths + " Month Prepay", 'monthPrepay');
		top.xo.cs.addBullet('Effective Monthly Cost', 'monthPrepayAvg');
		top.xo.cs.changeText('monthPrepay', cost);
		top.xo.cs.changeText('monthPrepayAvg', avg);
		top.xo.cs.removeBullet("monthly");
	}
	else
	{
		if (cost != 0)
		{
			top.xo.cs.addBullet('Monthly Fee', 'monthly');
			top.xo.cs.changeText('monthly', cost);
		}
	}
}

top.xo.cs.updatePlan = function(newPlan, newMonthly, newSetup)
{
	var container = document.getElementById("contents_planName_title");
	top.xo.cs.setBulletContainer(container);
	if (!top.xo.cs.nodes['planName'])
	{
		top.xo.cs.addTitle('Service Plan', 'planName_title', 'planName');
	}
	
	if (!top.xo.cs.nodes['monthly'])
	{
		top.xo.cs.addBullet('Monthly Fee', 'monthly');
	}
	
	if (!top.xo.cs.nodes['setupFee'])
	{
		top.xo.cs.addBullet('One-time Setup Fee', 'setupFee');
	}
	
	top.xo.cs.changeText("planName", newPlan);
	top.xo.cs.changeText('monthly', newMonthly);
	top.xo.cs.changeText('setupFee', newSetup);
	top.xo.cs.updatePrepay(0, 0, 0);
}

top.xo.cs.updatePackages = function(packs, packId, packName, cost)
{
    var packIsSet = document.getElementById("packageOn" + packId).checked;
    if(packIsSet)
    {
        top.xo.cs.removeBullet("noPacks");
        //top.xo.cs.addBullet(packName + ': $' + cost, 'pack' + packId);
		  var packBulletID = 'pack' + packId;
		  top.xo.cs.addBullet(packName, packBulletID);
		  top.xo.cs.changeText(packBulletID, "$" + cost);
    }
    else
    {
        top.xo.cs.removeBullet('pack' + packId);
        var packList = packs.split(' ');
        var total = 0;
        for(i=0; i<packList.length; i++)
        {
            pSet = document.getElementById("packageOn" + packList[i]).checked;
            if(pSet)
            {    
                total = total + 1;
            }
        }

        if(total == 0)
        {
              top.xo.cs.addBullet('None selected', 'noPacks');
        }
    }
}

top.xo.cs.changeText = function(nodeID, newText)
{
	var node = top.xo.cs.nodes[nodeID];
	
	var textNode = document.createTextNode(newText);
	
	var bullet = node.parentNode;
	
	if (node.childNodes.length > 0)
	{
		node.replaceChild(textNode, node.firstChild);
	}
	else
	{
		if (newText != "")
		{
			var withColon = document.createTextNode(bullet.firstChild.nodeValue + ": ");
			bullet.replaceChild(withColon, bullet.firstChild);
		}
		node.appendChild(textNode, node.firstChild);
	}
}


top.xo.cs.setBulletContainer = function(node)
{
	top.xo.cs.bulletContainer = node;
}


top.xo.cs.addBullet = function(bulletText, nodeID)
{
	var bullet = document.createElement("LI");
	bullet.id = "bullet_" + nodeID;
	bullet.style.fontWeight = "bold";
	var bulletText = document.createTextNode(bulletText);
	bullet.appendChild(bulletText);
	top.xo.cs.bulletContainer.appendChild(bullet);
	
	if (nodeID != "")
	{
		var node = document.createElement("SPAN");
		node.id = nodeID;
		node.style.fontWeight = "normal";
		bullet.appendChild(node);
		top.xo.cs.nodes[nodeID] = node;
	}
}


top.xo.cs.removeBullet = function(nodeID)
{
	var bullet = document.getElementById("bullet_" + nodeID);
	
	if (!bullet)
	{
		return false;
	}
	
	bulletContainer = bullet.parentNode;
	bulletContainer.removeChild(bullet);
	top.xo.cs.nodes[nodeID] = false;
}

top.xo.cs.addTitle = function(titleText, titleBarID, nodeID)
{
	var titleDiv = document.createElement("DIV");
	titleDiv.className = "infobarSubTitleFirst";
	titleDiv.id = titleBarID;
	
	var titleTextNode = document.createTextNode(titleText);
	
	titleDiv.appendChild(titleTextNode);
	top.xo.cs.nodes['container'].appendChild(titleDiv);
	
	var contentDiv = document.createElement("DIV");
	contentDiv.className = "infobarContent";
	contentDiv.id = "contents_" + titleBarID;
	
	if (nodeID != "")
	{
		var node = document.createElement("SPAN");
		node.id = nodeID;
		titleDiv.appendChild(node);
		top.xo.cs.nodes[nodeID] = node;
	}
	
	top.xo.cs.nodes['container'].appendChild(contentDiv);
	top.xo.cs.setBulletContainer(contentDiv);
}

document.onload = top.xo.cs.init;