/* set an interval to run code every 20 seconds (name it so we can end it later) */
var tabChange = setInterval
(
	/* create an anonymous function to run the code */
	function() {
	/* check if the function '$' exists (since we need to use it) and that
	the tabs have been loaded (second condition) */
		if(typeof $!='undefined' && $('ka_memberTab')) {
			/* add a new <li> to the main navbar */
			var NewTab = document.createElement('li');
			NewTab.id = 'CWMessageBoards';
			$('ka_memberTab').parentNode.appendChild(NewTab);
			
			/* write the link into the new <li> */
			$('CWMessageBoards').innerHTML = '<a id="ka_CWMessageBoards" href="http://lounge.cwtv.com/forumdisplay.php?f=13" title="message boards">message boards</a>';

			/* add a new <li> to the main navbar */
			var NewTab = document.createElement('li');
			NewTab.id = 'CWHome';
			$('ka_photoTab').parentNode.appendChild(NewTab);
			
			/* write the link into the new <li> */
			$('CWHome').innerHTML = '<a id="ka_CWHome" href="http://www.cwtv.com/lounge/vip/supernatural/" title="home">home</a>';
			$('CWHome').parentNode.insertBefore($('CWHome'),$('ka_photoTab'));
			
			/* stop the interval since the code has run successfully */
			clearInterval(tabChange);
		}
	},20
);

// BEGIN mod_09-18-10:36AM
function writeLoginLink() {
	if (document.getElementById('ka_becomeAMember') != null) {
		var loginDiv = '<a href="#" onclick="OpenUserWin( \'register\' );" >join now</a>';
		document.getElementById('ka_becomeAMember').innerHTML = loginDiv; 
	}
}

Ka.addDOMLoadEvent(writeLoginLink);

function rewriteLoginLinks() {
if (window.location.href.indexOf("displayKickPlace") != -1) {
	document.getElementById('ka_profileCommentTopLink').setAttribute("onclick", "scroll(0,400);");

		document.getElementById("ka_profileCommentTopLink").value = "Login to add a comment!";
}

	if (window.location.href.indexOf("MediaPlayPage") != -1) {
		// if (DWRUtil.getValue("loggedInUserId") == "") {
		if (document.getElementById("loggedInUserId").value != "") {
		var shoutBoxText		=	'Please <a href="javascript:scroll(0,400)">login</a> to enter comments.';

		document.getElementById("ka_shoutBoxArea").innerHTML= shoutBoxText;
		
		var ratingAreaText		=	'<a href="javascript:scroll(0,400)">Login</a> to rate.';
		document.getElementById("ratingArea").innerHTML= ratingAreaText;
		}
	}
}
setTimeout(rewriteLoginLinks, 2000);

if (window.location.href.indexOf("MyMedia") != -1) {
	var h3s = document.getElementsByTagName("h3");
	for (var i = 0; i < h3s.length; i++) {
		var theH3 = h3s[i];
		if (theH3.innerHTML.indexOf("Blog") != -1) {
			theH3.className = "ka_mkp_blog_cls";
		}
	}
}

// BEGIN mod_09-18-11:12PM
function ka_toggleDiv(id) {
	if (id != 'ka_photoPreviewDiv') { 
		kap_SSOLoginCheck();
	}

	obj = ka_findObj(id);
	if(obj.style.visibility == "hidden" || obj.style.visibility == "") {
		ka_positionCenter(id);
		obj.style.visibility = "visible";
		try {
			ka_shadeOn();
		}
		catch(e) {
		}
		// START | Oliver Nassar: May 29th
		if(id=='ka_loginPopup') {
			//blank flash video
			toggleFlashVideoOff();
			Ka.$('#username').focus();
		}
		// END
	} else {
		obj.style.visibility = "hidden";
		ka_shadeOff( );
	}
}

// BEGIN mod_09-19-6:38AM
function fixPhotoIconLink() {
	var addPhoto = document.getElementsByClassName('ka_addPhoto')[0];
	if (addPhoto != null) {
		addPhoto.parentNode.href = '/kickapps/service/displayManageAccountSettings.kickAction?STATUS=MAIN&as=7815';
	}
}

Ka.addDOMLoadEvent(fixPhotoIconLink);

// BEGIN mod_09-19-6:50AM
function hideGadgets() {
	if (window.location.href.indexOf("Gadgets") != -1) {
		 ka_myWidgets_showHideWidgets('photo');
	}
}

Ka.addDOMLoadEvent(hideGadgets);

// BEGIN mod_09-19-5:54PM
function removeColons() {
	if (window.location.href.indexOf("manageProfileQuestions") != -1) {
		var strongs = document.getElementsByTagName("label");
		for (var i = 0; i < strongs.length; i++) {
			strongs[i].innerHTML =    strongs[i].innerHTML.replace(":","");
		}
	}
}

Ka.addDOMLoadEvent(removeColons);

function hideBlogLinks() {
	if (window.location.href.indexOf("displayAddBlog") != -1) {
		$('blogTypeVideo').style.display="none";
		$('blogTypeVideo').nextSibling.nodeValue="";
		$('blogTypeAudio').style.display="none";
		$('blogTypeAudio').nextSibling.nodeValue="";
		$('blogTypeBrowseVideo').style.display="none";
		$('blogTypeBrowseVideo').nextSibling.nodeValue="";
		$('blogTypeBrowseAudio').style.display="none";
		$('blogTypeBrowseAudio').nextSibling.nodeValue="";
	}
}

Ka.addDOMLoadEvent(hideBlogLinks);

// BEGIN mod_09-27-5:20pm
function rewriteLoginLinks() {
if (window.location.href.indexOf("displayKickPlace") != -1) {
	document.getElementById('ka_profileCommentTopLink').setAttribute("onclick", "scroll(0,400);");

		document.getElementById("ka_profileCommentTopLink").value = "Login to add a comment!";
}

	if (window.location.href.indexOf("MediaPlayPage") != -1) {
		if (document.getElementById("loggedInUserId").value == "") {
		var shoutBoxText		=	'Please <a href="javascript:scroll(0,400)">login</a> to enter comments.';

		document.getElementById("ka_shoutBoxArea").innerHTML= shoutBoxText;
		
		var ratingAreaText		=	'<a href="javascript:scroll(0,400)">Login</a> to rate.';
		document.getElementById("ratingArea").innerHTML= ratingAreaText;
		}
	}
}

//BEGIN mod_09-28-4:00pm
function kaUncheckTOS(){
	if (document.getElementById('termsOfUse')) {
		$('termsOfUse').checked = false;
	}
}

kaUncheckTOS();

if (document.getElementById('ka_profileUrl')) {
	$('ka_profileUrl').nextSibling.nextSibling.value='http://' + window.location.hostname + '/' + $('username').value;
}

// BEGIN mod_10-02-12:57pm
if (window.location.href.indexOf("ManageAccountSettings") != -1) {
	$('AccountSettings').getElementsByTagName("a")[0].style.display="none";
	$('AccountSettings').getElementsByTagName("label")[0].style.display="none";
	$('AccountSettings').getElementsByTagName("div")[0].style.display="none";
	$('email').style.display="none";
}

//BEGIN registration
function OpenUserWin( command )
{
	var newwin = window.open( "http://register.cwtv.com/user/"+command, command,'width=650,height=664,status=yes,scrollbars=yes,resizable=no,location=no,toolbar=no');
}

function SetLoginPanel( )
{
    SetLoginPanelKA( 'supernatural' );
}
