/**
 * Original script that were place in the head of the template
 * Made to execute on load and basically just resorts the menu
 * 
 * 
 */

/* Adds a new tab to the kickapps navigation menu */
/* ALSO adds the footer at the base of the page */
function addTab(){
    if ($('ka_groupsTab')) {
	
		//add blog link
		var NewTab5 = document.createElement('li');
		NewTab5.id = 'ka_blogHeywireTab';
		$('ka_groupsTab').parentNode.appendChild(NewTab5);
		$('ka_blogHeywireTab').innerHTML = '<a href="http://blogs.abc.net.au/heywire/" title="Heywire Blog">Blog</a>';
		
		//add about link
		var NewTab2 = document.createElement('li');
		NewTab2.id = 'ka_aboutHeywireTab';
		$('ka_groupsTab').parentNode.appendChild(NewTab2);
		$('ka_aboutHeywireTab').innerHTML = '<a href="http://blogs.abc.net.au/heywire/about-heywire.html" title="About Us">about</a>';


		/* EVERYTHING BELOW CURRENTLY DISABLED */
		/*
		
		//add competition link
		var NewTab3 = document.createElement('li');
		NewTab3.id = 'ka_competitionHeywireTab';
		$('ka_groupsTab').parentNode.appendChild(NewTab3);
		$('ka_competitionHeywireTab').innerHTML = '<a href="http://blogs.abc.net.au/heywire/competition-heywire.html" title="Heywire Competition">competition</a>';
		
		//add (custom) members link

		var NewTab4 = document.createElement('li');
		NewTab4.id = 'ka_membersHeywireTab';
		$('ka_blogTab').parentNode.appendChild(NewTab4);
		$('ka_membersHeywireTab').innerHTML = '<a href="http://affiliate.kickapps.com/kickapps/service/searchEverything.kickAction?as=13362&mediaType=user&sortType=recent" title="Heywire Members">members</a>';

		
		//add resources link
		var NewTab1 = document.createElement('li');
		NewTab1.id = 'ka_resourcesHeywireTab';
		$('ka_groupsTab').parentNode.appendChild(NewTab1);
		$('ka_resourcesHeywireTab').innerHTML = '<a href="http://blogs.abc.net.au/heywire/resources-heywire.html" title="Resources">resources</a>';
		
		
		*/
		

	}
}



/**
 * 
 */
function editTopNavLinks(){
   if($('ka_headerTopNav')){
           //Relabel tabs
          //$('ka_homeTab').getElementsByTagName('a')[0].innerHTML = "Home";
		  $('ka_blogTab').getElementsByTagName('a')[0].innerHTML = "words";
		  if($('ka_myhomeTab'))
	          $('ka_myhomeTab').getElementsByTagName('a')[0].innerHTML = "My Heywire";

		  
		  /* change the ordering */ 
		  $('ka_myhomeTab').parentNode.insertBefore($('ka_myhomeTab'),$('ka_videoTab')); 
		  $('ka_blogHeywireTab').parentNode.insertBefore($('ka_blogHeywireTab'),$('ka_videoTab'));
		  $('ka_photoTab').parentNode.insertBefore($('ka_photoTab'),$('ka_audioTab'));

		  if($('ka_competitionHeywireTab'))
			  $('ka_competitionHeywireTab').parentNode.insertBefore($('ka_competitionHeywireTab'),$('ka_resourcesHeywireTab'));
		  
		  if($('ka_membersHeywireTab'))
		  	$('ka_membersHeywireTab').parentNode.insertBefore($('ka_membersHeywireTab'),$('ka_groupsTab'));

	}
}





/**
 * 
 */
function rebuildEditAccount(){	

	// Handle the EMail Password Mapping
	if (window.location.href.indexOf("displayManageAccountSettings") != -1) {
		if(document.getElementById('ka_emailReset')&&document.getElementById("ka_emailpassword_redirect")){
			var txtRedirectHTML;
			
			// Remove the password/email handling and insert the new HTML
			txtRedirectHTML = document.getElementById("ka_emailpassword_redirect").innerHTML;	
			document.getElementById('ka_emailReset').innerHTML = txtRedirectHTML;
		}
		
		if (document.getElementById('ka_optionDiv')){
			var txtOptionHTML;
			var txtOptionUCaseHTML;
			var fndIndexStart;
			var remStartStr = 'FIRST NAME';
			var remEndStr = '</DIV>';
			
			// Remove the password/email handling and insert the new HTML
			txtOptionHTML = document.getElementById("ka_optionDiv").innerHTML;
			txtOptionUCaseHTML = 	txtOptionHTML.toUpperCase();
			fndIndexStart = txtOptionUCaseHTML.indexOf(remStartStr);

			// Get the starting point
			if (fndIndexStart > 0) {
				fndIndexStart = (txtOptionUCaseHTML.substr(0, fndIndexStart)).lastIndexOf(remEndStr);				
				fndIndexStart = fndIndexStart + remEndStr.length;	
			};
			
			// Reset the HTML for the element
			if (fndIndexStart > 0) {
				document.getElementById('ka_optionDiv').innerHTML = txtOptionHTML.substr(0, fndIndexStart);
			};
		}
		
	}

}			



/**
 * 
 * @param {Object} strURL
 */
function urlEncode(strURL)
{
  var strURLEncode = escape(strURL);
  
  strURLEncode = strURLEncode.replace("+", "%2B");
  strURLEncode = strURLEncode.replace("/", "%2F"); 
  
  return strURLEncode;
}