function readCookie(name)
  {
	var nameSG=name+"=";
	var ca=document.cookie.split(";");
	var Ret="";
	for (var i=0;i<ca.length;i++)
	  {
		var c=ca[i];
		while (c.charAt(0)==' ') c=c.substring(1,c.length);
		if (c.indexOf(nameSG)==0) Ret=c.substring(nameSG.length,c.length);
		}	
	return Ret;	
	}	
	
function newCookie(name,value,days)
  {
	if (days)
	  {
		var date=new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires=date.toGMTString();
		}
		else var expires="";
	document.cookie = name + "=" +escape( value ) +
		";expires=" + expires + 
		";path=/";
	}	
	
function setLoginButton()	
  {
	if (readCookie("ndsBlog")=='')
	 {
	 document.forms[0].btn_login.value="Login";
	 }
	else
	 {
	 document.forms[0].btn_login.value="Log Out";
	 } 
	}
	
function buttonClick()
  {
	if (document.forms[0].btn_login.value=="Login")
	  {
		if (navigator.cookieEnabled)
  	  newCookie('ndsBlog','Logged In',1)
		else	
		  alert('You must enable cookies to log in')
		}
	else
	  newCookie('ndsBlog','',-1);
	setLoginButton();	
	}	
	
function LogOn(currentSite, currentCat, dataBase)
  {
	window.location.href=("http://"+currentSite+"/cgi/NDS.DLL?site.gotologin::"+currentCat+";"+dataBase);
	}
	
function LogOff()
  {
	newCookie('UserId','',-1);
	newCookie('UserName','',-1);
	window.location.reload();
	}	

function GotoMyAccount(currentSite, currentCat, dataBase)
  {
	var bUser=readCookie("UserId");
  if (bUser!='')
     {
     window.location.href=("http://"+currentSite+"/cgi/NDS.DLL?site.gotomyaccount::"+currentCat+";"+bUser+";"+dataBase);
     }
	}

function AddToFavoriteTopics(currentSite, currentCat, dataBase)
  {
	var bUser=readCookie("UserId");
  if (bUser!='')
     {
     window.location.href=("http://"+currentSite+"/cgi/NDS.DLL?site.addtofavorites::"+currentCat+";"+bUser+";"+dataBase);
     }
	}
	
function AccountLinks(currentSite, currentCat, currentCatName, dataBase)
  {	
	var StringLink1="GotoMyAccount(\'"+currentSite+"','"+currentCat+"','"+dataBase+"')";
	var StringLink2="LogOn(\'"+currentSite+"','"+currentCat+"','"+dataBase+"')";
	var StringLink3="AddToFavoriteTopics(\'"+currentSite+"','"+currentCat+"','"+dataBase+"')";
	
	if (readCookie("UserId")!='')
	   {
		 newCookie('UserId',readCookie("UserId"),5);
		 newCookie('UserName',readCookie("UserName"),5);
	   document.writeln('<div id="UserSection"><hr>');
	 	 document.writeln('<div id="UserWelcome">Welcome '+readCookie("UserName")+'</div><p>');
		 document.writeln('<a href=\"javascript: '+StringLink1+';">Go To<br>My Account</a><p>');
		 document.writeln('<a href=\"javascript: '+StringLink3+';">Add<br>'+currentCatName+'<br>to my favorite topics</a><p>');
		 document.writeln('<div class="submit"><input type="button" name="btn_login" value="Log Off" onclick="LogOff();"><div class="submit">');
		 document.writeln('</div>');
		 } 
		 else
		 {
		 document.writeln('<div class="submit"><input type="button" name="btn_login" value="Login" onclick="' + StringLink2 + ';"><div class="submit">');
		 }	
  }
	
function SuggestCatLinkx(currentSite, currentCat, currentCatName, dataBase)
  {	
  var bUser=readCookie("UserId");
  if (bUser=='')
     {
     document.writeln('<a id="SuggestCat" href=\"http://'+currentSite+'/cgi/NDS.DLL?site.gotosuggesttopic::'+currentCat+';;'+dataBase+'">Add New<br>Topic to<br>'+currentCatName+'</a>');
     }
     else
     {
     document.writeln('<a id="SuggestCat" href=\"http://'+currentSite+'/cgi/NDS.DLL?site.gotosuggesttopic::'+currentCat+';'+bUser+';'+dataBase+'">Add New<br>Topic to<br>'+currentCatName+'</a>');
     }
  }
	
function CommentLinkx(currentSite, currentCat, currentCatName, dataBase)
  {
  var bUser=readCookie("UserId");
  if (bUser=='')
     {
     document.writeln('<a id="AddComment" href="http://'+currentSite+'/cgi/NDS.DLL?site.gotoaddcomment::'+currentCat+';;'+dataBase+'">Add A Comment To '+currentCatName+'</a></td>');
     }
     else
     {
     document.writeln('<a id="AddComment" href="http://'+currentSite+'/cgi/NDS.DLL?site.gotoaddcomment::'+currentCat+';'+bUser+';'+dataBase+'">Add A Comment To '+currentCatName+'</a></td>');
     }
	}

function SuggestCatLink(TopicText, currentSite, currentCat, currentCatName, dataBase)
  {	
  var bUser=readCookie("UserId");
  if (bUser=='')
     {
     document.writeln('<a id="SuggestCat" href=\"http://'+currentSite+'/cgi/NDS.DLL?site.gotosuggesttopic::'+currentCat+';;'+dataBase+'">Add A New<br>'+TopicText+' to<br>'+currentCatName+'</a>');
     }
     else
     {
     document.writeln('<a id="SuggestCat" href=\"http://'+currentSite+'/cgi/NDS.DLL?site.gotosuggesttopic::'+currentCat+';'+bUser+';'+dataBase+'">Add A New<br>'+TopicText+' to<br>'+currentCatName+'</a>');
     }
  }

function CommentLink(commentText, currentSite, currentCat, currentCatName, dataBase)
  {
  var bUser=readCookie("UserId");
  if (bUser=='')
     {
     document.writeln('<a id="AddComment" href="http://'+currentSite+'/cgi/NDS.DLL?site.gotoaddcomment::'+currentCat+';;'+dataBase+'">'+commentText+'</a></td>');
     }
     else
     {
     document.writeln('<a id="AddComment" href="http://'+currentSite+'/cgi/NDS.DLL?site.gotoaddcomment::'+currentCat+';'+bUser+';'+dataBase+'">'+commentText+'</a></td>');
     }
	}

function Admin(currentSite, currentCat, dataBase)
  {
		adminWindow = window.open("http://"+currentSite+"/cgi/NDS.DLL?admin.gotologin::apw=JIM;"+currentCat+";"+dataBase+";;Edit_Topic","AdminPage");
		if (window.focus)
		  adminWindow.focus();
	}
	
function AdminLink(currentSite, currentCat, dataBase)
  {
	var adminLink="Admin(\'"+currentSite+"','"+currentCat+"','"+dataBase+"')";

  document.writeln('<a target="_top" name="AdminPage" href="javascript:'+adminLink+';"><img src="/images/1ptrans.gif" width="1" height="20" border="0" alt=""></a>');
	}		
	
	