$(document).ready(function() 
{

// click function for opening and closing 'siteplan'
	$('#masthead li[title=all]')
	.toggle(function(event)
	{
		var winWidth = $(window) .width();
		var leftSide = winWidth/2 - 500;
		var allPosition = leftSide + 15;
		$('#siteplan') .css('left', allPosition);
		$('#siteplan') .fadeIn('fast');
		$(this) .addClass('all_clicked');
		$(this) .text('site map -  ');
		}, function(event)
		{
			$('#siteplan') .fadeOut('fast');
			$(this) .removeClass('all_clicked');
			$(this) .text('site map+');
	});
	
// click for login_form
	if(!readCookie("username"))
	{
	$('#login')
	.toggle(function(event)
	{
		if ($('#login_form'))
		{
			$('#login_form') .fadeOut('fast');
		};  
		$('#login_form') .css('top', 140);
		var winWidth = $(window) .width();
		var leftSide = winWidth/2 - 500;
		var login_form_pos = leftSide - 1;
		$('#login_form') .css('left', login_form_pos);
		$('#login_form') .fadeIn('fast')
		}, function(event)
		{
			$('#login_form') .fadeOut('fast');
		});
	};
	

// for tabbed interface
	if ($('div') .hasClass('tabbedInterface'))
	{
		$('.tabbedInterface > ul').tabs();
	};
	
	$('div.tabbedInterface') .each(function()
	{
	$('div.tabbedInterface ul li:first-child') .addClass('selectedTab');
	});

	$('.tabbedInterface ul li a')
	.bind('click', function(event)
	{
		var parentThis = $(this).parent();
		var parentUp = $(parentThis).parent();
		var chidrenAll = $(parentUp).children();
		$(chidrenAll) .removeClass('selectedTab');
		$(parentThis) .addClass('selectedTab');
	});
	
// for tabbedInterface_160
	if ($('div') .hasClass('tabbedInterface_160'))
	{
		$('.tabbedInterface_160 > ul').tabs();
	};
	
	$('div.tabbedInterface_160') .each(function()
	{
	$('div.tabbedInterface_160 ul li:first-child') .addClass('selectedTab');
	});

	$('.tabbedInterface_160 ul li a')
	.bind('click', function(event)
	{
		var parentThis = $(this).parent();
		var parentUp = $(parentThis).parent();
		var chidrenAll = $(parentUp).children();
		$(chidrenAll) .removeClass('selectedTab');
		$(parentThis) .addClass('selectedTab');
	});

// for tabbed interface_220
	if ($('div') .hasClass('tabbedInterface_220'))
	{
		$('.tabbedInterface_220 > ul').tabs();
	};
	
	$('div.tabbedInterface_220') .each(function()
	{
	$('div.tabbedInterface_220 ul li:first-child') .addClass('selectedTab');
	});

	$('.tabbedInterface_220 ul li a')
	.bind('click', function(event)
	{
		var parentThis = $(this).parent();
		var parentUp = $(parentThis).parent();
		var chidrenAll = $(parentUp).children();
		$(chidrenAll) .removeClass('selectedTab');
		$(parentThis) .addClass('selectedTab');
	});

	
// for tabbed interface noTop (no top margin)
	if ($('div') .hasClass('tabbedInterface_noTop'))
	{
		$('.tabbedInterface_noTop > ul').tabs();
	};
	
	$('div.tabbedInterface_noTop') .each(function()
	{
	$('div.tabbedInterface_noTop ul li:first-child') .addClass('selectedTab');
	});

	$('.tabbedInterface_noTop ul li a')
	.bind('click', function(event)
	{
		var parentThis = $(this).parent();
		var parentUp = $(parentThis).parent();
		var chidrenAll = $(parentUp).children();
		$(chidrenAll) .removeClass('selectedTab');
		$(parentThis) .addClass('selectedTab');
	});
	
// for tabbed interface noTop2 (no top margin, without rounded corner)
	if ($('div') .hasClass('tabbedInterface_noTop2'))
	{
		$('.tabbedInterface_noTop2 > ul').tabs();
	};
	
	$('div.tabbedInterface_noTop2') .each(function()
	{
	$('div.tabbedInterface_noTop2 ul li:first-child') .addClass('selectedTab');
	});

	$('.tabbedInterface_noTop2 ul li a')
	.bind('click', function(event)
	{
		var parentThis = $(this).parent();
		var parentUp = $(parentThis).parent();
		var chidrenAll = $(parentUp).children();
		$(chidrenAll) .removeClass('selectedTab');
		$(parentThis) .addClass('selectedTab');
	});

// for search result tabs
	if ($('#searchResultsTabs'))
	{
		$('#searchResultsTabs > ul').tabs();
	};
	
	$('#searchResultsTabs') .each(function()
	{
	$('#searchResultsTabs ul li:first-child') .addClass('searchTabFront');
	});

	$('#searchResultsTabs ul li a')
	.bind('click', function(event)
	{
		var parentThis = $(this).parent();
		var parentUp = $(parentThis).parent();
		var chidrenAll = $(parentUp).children();
		$(chidrenAll) .removeClass('searchTabFront');
		$(parentThis) .addClass('searchTabFront');
	});

// left position for hot spot to index
		function linktohomePosition()
		{
			var winWidth = $(window) .width();
			var leftSide = winWidth/2 - 500;
			var linkPosition = leftSide + 300;
			$('#linktohome') .css('left', linkPosition);
		};
		$( window ).resize(linktohomePosition);
		linktohomePosition();
		
// left position for hot spot to stPats page
		function linktostPatsPosition()
		{
			var winWidth2 = $(window) .width();
			var leftSide2 = winWidth2/2 - 500;
			var linkPosition2 = leftSide2 + 693;
			$('#linktostPats') .css('left', linkPosition2);
		};
		$( window ).resize(linktostPatsPosition);
		linktostPatsPosition();

// x position for army masthead
	if($('#armyMasthead'))
	{
		function armyMastheadPosition()
		{
			var winWidth = $(window) .width();
			var leftSide = winWidth/2 - 500;
			var mastPosition = leftSide - 93;
			$('#armyMasthead') .css('left', mastPosition);
		};
		$( window ).resize(armyMastheadPosition);
		armyMastheadPosition();
	};
	
// temp function for main nav highlight while on appropriate page -- for samples; need employ detection and update to accomodate subsection pages
	var locName = $('#mastsectname') .text();
	var locNameBg = "#masthead li[title=" + locName + "]";
	var locNameText = locNameBg + " a:first";
	if (locName == "news" ||locName == "sport" || locName == "entertainment" || locName == "business" || locName == "travel" || locName == "advice" || locName == "opinion" || locName == "multimedia")
	{
		$(locNameBg) .addClass('navMarker');
		$(locNameText) .css('color', '#ffffff');
	};
	
// font-resize functions on articlepage and columnists_article pages
	if ($('#article_main'))
	{
		$('#article_main p') .css('font-size', '110%');
		$('#resize1')
		.toggle(function(event)
			{
				$('#article_main p') .css('font-size', '150%');  
			}, function(event)
			{
				$('#article_main p') .css('font-size', '110%');
		});
	};

// font-resize functions on blog entry pages
	if ($('#blog_cont_re'))
	{
		$('#resize1')
		.toggle(function(event)
			{
				if ($('#blog_cont_re') .css('font-size', '110%'))
				{
				$('#blog_cont_re') .css('font-size', '150%');
				};  
			}, function(event)
			{
				$('#blog_cont_re') .css('font-size', '150%');
		});
	};
	
	// member_center: change password display toggle (3 forms at top of member_center_form.html)
	
	if ($('div.changePassword'))
	{
	$('div.changePassword')
	.toggle(function(event)
	{
		$('div.changePasswordForm') .show();
		}, function(event)
		{
		$('div.changePasswordForm') .hide();
	});
	};

		  
	if ($('#article_main_list p:first'))
    {
		$('#article_main_list p:first') .addClass('theListsFirstPara');
    };
    	
// expanding box for Follow Us box
	if ($('div') .hasClass('newFollowUs_300'))
	{
		    $(function() {
	$('div.newFollowUs_closed')
	.click(function(event){
	$('div.newFollowUs_open') .slideDown('fast');
	$('div.newFollowUs_closed') .fadeOut('fast');
	});
	});
	    $(function() {
	$('span.newFollowUs_shut')
	.click(function(event){
	$('div.newFollowUs_open') .slideUp('fast');
	$('div.newFollowUs_closed') .fadeIn('fast');
	});
	});
	}
    		
// end of $(document).ready(function()
});

	// code using JQuery functionality above, all other below

	// check e-mail validation used by ValidateForm() on register page, ValidateForm2() on login error page, ValidateForm3() on login retrieval
	
		function CheckEmail( str ) {
		var at = "@";
		var dot = ".";
		var lat = str.indexOf(at);
		var lstr = str.length;
		var ldot = str.indexOf(dot);
		if ( str.indexOf(at)==-1) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a valid e-mail address."
			return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a valid e-mail address."
			return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a valid e-mail address."
			return false;
		}
		if (str.indexOf(at,(lat+1))!=-1){
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a valid e-mail address."
			return false;
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a valid e-mail address."
			return false;
		}
		if (str.indexOf(dot,(lat+2))==-1){
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a valid e-mail address."
			return false;
		}
		if (str.indexOf(" ")!=-1){
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a valid e-mail address."
			return false;
		}
 		return true;
	}
	// function for register page validation

        function isProper(username) {
            var result = true;
            var stringLen = username.value.length;
            var string = username.value;
            var iChars = "*|,\":<>[]{}`\';() @&$#%-_";
            for (var i = 0; i < stringLen; i++) {
            if (iChars.indexOf(string.charAt(i)) != -1)
            result = false;
            }
            if (result == false)
            {
            var mess = document.getElementById("logonMessage")
            mess.innerHTML="Please enter a valid screen name of no more than 15 standard characters, no *|,\":<>[]{}`\';()@&$#%-_. or spaces."
            username.value = "";
            username.focus();
            return false;
            }
return true;
        }

	function ValidateForm() { 
		email = document.frm.email ; 
		if ( (email.value==null) || (email.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter an e-mail address."
			email.focus();
			return false;
		}
		if (CheckEmail(email.value) == false) {
			email.value = "" ; 
			email.focus() ; 
			return false ; 
		}
		var username = document.frm.username;
		if ( (username.value==null) || (username.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a screen name."
			username.focus();
			return false;
		}
               if (!  isProper (username)  )  {
                        return false;
               }
		if (username.value.length>15 || username.value.length<7) {
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a valid screen name of 7-15 standard characters, "
			username.value = "";
			username.focus();
			return false;
		}
		var tmpPassWord = document.frm.password1;
		if ( (tmpPassWord.value==null) || (tmpPassWord.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a password."
			tmpPassWord.focus();
			return false;
		}
		if (tmpPassWord.value.length<7) {
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Passwords must be 8 or more characters."
			tmpPassWord.value = "";
			tmpPassWord.focus();
			return false;
		}
		var tmpConfirmPassWord = document.frm.password2;
		if ( (tmpConfirmPassWord.value==null) || (tmpConfirmPassWord.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter your password again in the Confirm Password field."
			tmpConfirmPassWord.focus();
			return false;
		}
		if (tmpConfirmPassWord.value.length<7) {
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Passwords must be 8 or more characters."
			tmpConfirmPassWord.value = "";
			tmpConfirmPassWord.focus();
			return false;
		}
		if ( tmpConfirmPassWord.value != tmpPassWord.value ) {
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="The entered passwords do not match."
			tmpConfirmPassWord.value = "";
			tmpPassWord.value = "";
			tmpPassWord.focus();
			return false;
		}
		return true;
	 }
	 
	 
	// function for login error page validation 
	function ValidateForm2() { 
		email = document.frm.frmEmail; 
		if ( (email.value==null) || (email.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter an e-mail address."
			email.focus();
			return false;
		}
		if (CheckEmail(email.value) == false) {
			email.value = "" ; 
			email.focus() ; 
			return false ; 
		}
		var tmpPassWord = document.frm.frmPassWord;
		if ( (tmpPassWord.value==null) || (tmpPassWord.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a password."
			tmpPassWord.focus();
			return false;
		}
		if (tmpPassWord.value.length!=6) {
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Passwords must be 8 or more characters."
			tmpPassWord.value = "";
			tmpPassWord.focus();
			return false;
		}
		return true;
	 }
	 
	 	// function for the login retrieval page 
	function ValidateForm3() { 
		email = document.frm.frmEmail ; 
		if ( (email.value==null) || (email.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter an e-mail address."
			email.focus();
			return false;
		}
		if (CheckEmail(email.value) == false) {
			email.value = "" ; 
			email.focus() ; 
			return false ; 
		}
		return true;
	 }
	 
	 //check email function used by ValidateForm4() on masthead navigation
	 		function CheckEmail2( str ) {
		var at = "@";
		var dot = ".";
		var lat = str.indexOf(at);
		var lstr = str.length;
		var ldot = str.indexOf(dot);
		if ( str.indexOf(at)==-1) { 
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter a valid <br />e-mail address."
			return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { 
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter a valid <br />e-mail address."
			return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter a valid <br />e-mail address."
			return false;
		}
		if (str.indexOf(at,(lat+1))!=-1){
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter a valid <br />e-mail address."
			return false;
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter a valid <br />e-mail address."
			return false;
		}
		if (str.indexOf(dot,(lat+2))==-1){
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter a valid <br />e-mail address."
			return false;
		}
		if (str.indexOf(" ")!=-1){
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter a valid <br />e-mail address."
			return false;
		}
 		return true;
	}
		// function for masthead logon validation 
	function ValidateForm4() { 
		email = document.frm2.frmEmail2; 
		if ( (email.value==null) || (email.value=="") ) { 
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter an e-mail address."
			email.focus();
			return false;
		}
		if (CheckEmail2(email.value) == false) {
			email.value = "" ; 
			email.focus() ; 
			return false ; 
		}
		var tmpPassWord = document.frm2.frmPassWord2;
		if ( (tmpPassWord.value==null) || (tmpPassWord.value=="") ) { 
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Please enter a password."
			tmpPassWord.focus();
			return false;
		}
		if (tmpPassWord.value.length!=6) {
			var mess = document.getElementById("logonMessage2")
			mess.innerHTML="Passwords must be 8 or more characters."
			tmpPassWord.value = "";
			tmpPassWord.focus();
			return false;
		}
		return true;
	 }

	 	// function for the member_center - to change password 
	function ValidateForm_changePassword() { 
		var tmpPassWord = document.frm.newPassword;
		if ( (tmpPassWord.value==null) || (tmpPassWord.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter a password."
			tmpPassWord.focus();
			return false;
		}
		if (tmpPassWord.value.length!=6) {
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Passwords must be 8 or more characters."
			tmpPassWord.value = "";
			tmpPassWord.focus();
			return false;
		}
		var tmpConfirmPassWord = document.frm.newPasswordConfirm;
		if ( (tmpConfirmPassWord.value==null) || (tmpConfirmPassWord.value=="") ) { 
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="Please enter your password again in the Confirm Password field."
			tmpConfirmPassWord.focus();
			return false;
		}
		if (tmpConfirmPassWord.value.length!=6) {
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="This does not match the password entered."
			tmpConfirmPassWord.value = "";
			tmpConfirmPassWord.focus();
			return false;
		}
		if ( tmpConfirmPassWord.value != tmpPassWord.value ) {
			var mess = document.getElementById("logonMessage")
			mess.innerHTML="This does not match the password entered."
			tmpConfirmPassWord.value = "";
			tmpPassWord.value = "";
			tmpPassWord.focus();
			return false;
		}
		return true;
	 }
	 
	 // function for the member_center - required fields 
	function ValidateForm_requiredFields() { 
		var tmpFirstName = document.frmReq.firstName;
		if ( (tmpFirstName.value==null) || (tmpFirstName.value=="") ) { 
			var mess = document.getElementById("requiredMessage")
			mess.innerHTML="Please enter your first name."
			tmpFirstName.focus();
			return false;
		}
		var tmpLastName = document.frmReq.lastName;
		if ( (tmpLastName.value==null) || (tmpLastName.value=="") ) { 
			var mess = document.getElementById("requiredMessage")
			mess.innerHTML="Please enter your last name."
			tmpLastName.focus();
			return false;
		}
		var tmpDob_year = document.frmReq.dob_year;
		if ( tmpDob_year.selectedIndex == 00 ) {
 			var mess = document.getElementById("requiredMessage")
			mess.innerHTML="Please enter your date of birth."
			return false;
    	}
		var tmpGender = document.frmReq.gender;
		if ( (tmpGender[0].checked == false ) && (tmpGender[1].checked == false ) ) {
			var mess = document.getElementById("requiredMessage")
			mess.innerHTML="Please select Male or Female."
			return false;
   		 }
		var tmpZipCode = document.frmReq.zipCode;
		if ( (tmpZipCode.value==null) || (tmpZipCode.value=="") ) { 
			var mess = document.getElementById("requiredMessage")
			mess.innerHTML="Please enter a zip code."
			tmpZipCode.focus();
			return false;
		}
		var tmpCountryCode = document.frmReq.countryCode;
		if ( tmpCountryCode.selectedIndex == 0 ) {
 			var mess = document.getElementById("requiredMessage")
			mess.innerHTML="Please enter your country."
			return false;
    	}
		return true;
	}
	 
	
/* Client-side access to querystring name=value pairs
	Version 1.3
	28 May 2008
	
	License (Simplified BSD):
	http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
