//-----------------------------------------------------------------------------
// RightNavigation.js
// 2007.10.16 - written by rk7138 for AT&T Communications
//-----------------------------------------------------------------------------
// ASSUMES
// -- writeHTML.js is loaded
// -- RightNavigation.TARGET exists in the rendered HTML received from Teamsite
//    and is in the right-hand column of a 3-column layout
//
// METHODS
//   init()
//
// USAGE
// -- RightNavigation.init() is invoked on window.load
//
// INFORMATION
//   1. Draws widgets for the right-side of the 3-column Teamsite layout.
//   2. Replaces "Contact Us" link at top of page with SMB-specific URL

var RightNavigation = {
	TARGET: 'su_c2c_content',
	CONTACT_US: '?pid=10405',
	
	actionURL: {
		'test': 'http://whc-test.sbcis.sbc.com:5100/SMBWeb/sign-up.jsp',
		'prod': 'https://webhosting.att.com/SMBWeb/sign-up.jsp'	
	},
		
	environs: {
		'webhosting.att.com': 'prod',
		'test-www.att.com': 'test',
		'stage-www.att.com': 'test',
		'att.com': 'prod',
		'www.att.com': 'prod'
	},
			
	getActionURL: function (){
		var uriObj = window.location.toString().split('?');
		var URI = uriObj[0];
		var domain = URI.match( /:\/\/(www\.)?([^\/:]+)/ );
    	domain = domain[2] ? domain[2]:'';		

		var environ = RightNavigation.environs[domain];
		var actionURL = RightNavigation.actionURL[environ];

		return actionURL;
	},
		
	getBlueWidget: function (){		
		var actionURL = RightNavigation.getActionURL();		
		var htmlStr = "";
		
		htmlStr += "<div class='blue-widget'>\n";
		htmlStr += "	<form name='signUpForm' action='" + actionURL + "' method='post' target='_top'>\n";	
		htmlStr += "		<fieldset>\n";
		htmlStr += "			<h2>Sign Up Now</h2>\n";	
		htmlStr += "			<label for='domain'>Domain</label>\n";	
		htmlStr += "			<input type='text' maxlength='60' size='60' name='domain' id='domain' title='Enter the domain you want.' />\n";
		htmlStr += "			<label for='zipcode'>ZIP Code</label>\n";	
		htmlStr += "			<input type='text' size='5' maxlength='5' name='zipcode' id='zipcode' title='Enter your ZIP Code.' />\n";	
		htmlStr += "			<button name='btnArrowSubmit' id='btnArrowSubmit' type='submit' title='Continue'></button>\n";				
		htmlStr += "			<br />\n";
		htmlStr += "			<br />\n";
		htmlStr += "		</fieldset>\n";
		htmlStr += "	</form>\n";
		htmlStr += "</div>\n";
		
		return htmlStr;		
	},
		
	getQuickLinks: function (){
		var uriObj = window.location.toString().split('?');
		var URI = uriObj[0];
		var teamsiteURL = URI + '?';	
		var htmlStr = "";
				
		htmlStr += "<div class='group'>\n";
		htmlStr += "	<!-- WIDGET:text box //-->\n";
		htmlStr += "	<div class='widget'>\n";
		htmlStr += "		<h2>Compare Plans</h2>\n";
		htmlStr += "		<ul>\n";
		htmlStr += "			<li><a href='" + teamsiteURL + "pid=10481' title='Learn about Shared Hosting plans'>Shared Hosting</a>\n";
		htmlStr += "				<ul>\n";
		htmlStr += "					<li><a href='" + teamsiteURL + "pid=10505' title='Learn about Windows Hosting plans'>Windows</a></li>\n";
		htmlStr += "					<li><a href='" + teamsiteURL + "pid=10491' title='Learn about UNIX Hosting plans'>UNIX</a></li>\n";
		htmlStr += "				</ul>\n";
		htmlStr += "			</li>\n";
		htmlStr += "			<li><a href='" + teamsiteURL + "pid=10410' title='Learn about Virtual Dedicated Servers'>Virtual Dedicated Server</a>\n";
		htmlStr += "				<ul>\n";
		htmlStr += "				<li><a href='" + teamsiteURL + "pid=10367' title='Learn about Windows VDS'>Windows</a></li>\n";
		htmlStr += "				<li><a href='" + teamsiteURL + "pid=10359' title='Learn about Linux VDS'>Linux</a></li>\n";
		htmlStr += "				</ul>\n";
		htmlStr += "			</li>\n";
		htmlStr += "			<li><a href='" + teamsiteURL + "pid=10375' title='Learn about Managed Dedicated Servers'>Managed Dedicated Server</a>\n";
		htmlStr += "				<ul>\n";
		htmlStr += "				<li><a href='" + teamsiteURL + "pid=10397' title='Learn about Windows MDS'>Windows</a></li>\n";
		htmlStr += "				<li><a href='" + teamsiteURL + "pid=10388' title='Learn about Linux MDS'>Linux</a></li>\n";
		htmlStr += "				</ul>\n";
		htmlStr += "			</li>\n";
		htmlStr += "		</ul>\n";
		htmlStr += "	</div>\n";
		htmlStr += "	<!-- WIDGET:text box //-->\n";
		htmlStr += "	<div class='widget'><h2><a href='" + teamsiteURL + "pid=10321' title='Access the documentation library'>Documentation Library</a></h2></div>\n";
		htmlStr += "</div>\n";
		
		return htmlStr;		
	},
				
	buildNav: function (){	
		var outputStr = '';
		
		outputStr += RightNavigation.getBlueWidget();
		outputStr += RightNavigation.getQuickLinks();
		
		return outputStr;
	},
		
	drawNavigation: function (){
		var htmlStr = RightNavigation.buildNav();
		var replaceObj = $(RightNavigation.TARGET);
		
		if (replaceObj){
			var replaceNode = replaceObj.parentNode.parentNode;

			setInnerHTML(replaceNode, htmlStr);
			replaceNode.parentNode.style.display = 'block';
		}				
	},
		
	alterContactUs: function (){
		var uriObj = window.location.toString().split('?');
		var URI = uriObj[0];
		var teamsiteURL = URI + RightNavigation.CONTACT_US;
		
		var targetObj = $('header');
		var pTags = targetObj.getElementsByTagName('p');
		var htmlStr = "<a href='" + teamsiteURL + "' title='Visit our support pages'>Contact Us</a>";
		
		if (pTags && pTags.length > 1){
			setInnerHTML(pTags[1], htmlStr);
		}
		
	},

		
	init: function(){
		RightNavigation.drawNavigation();
		RightNavigation.alterContactUs();			
	}
}

addEvent(window, 'load', RightNavigation.init);