function returnDocument() 
{
var file_name = document.location.href;
var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

function returnShortDocument() 
{
var file_name = document.location.href;
var end = (file_name.indexOf(".html") == -1) ? file_name.length : file_name.indexOf(".html");
return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

function GetParam(name)
{
var start=location.search.indexOf("?"+name+"=");
if (start<0) start=location.search.indexOf("&"+name+"=");
if (start<0) return '';
start += name.length+2;
var end=location.search.indexOf("&",start)-1;
if (end<0) end=location.search.length;
var result=location.search.substring(start,end);
var result='';
for(var i=start;i<=end;i++) 
{
  var c=location.search.charAt(i);
  result=result+(c=='+'?' ':c);
}
return unescape(result);
}

function AddInvitation(isBottom)
{
  if (Comments == "N") return;
	
  var cmtext = "comments";
  if (Comments == "1") cmtext = "comment";
  var Page = returnShortDocument();

  /* Handle specific 'multpage' invitations */
  if (Page=="submodalities_page2" || Page=="submodalities_page3" || Page=="submodalities_page4" || Page=="submodalities_page5" || Page=="submodalities_page6")
      Page="submodalities";
  else if (Page=="nlp_primer_content_page2" || Page=="nlp_primer_content_page3" || Page=="nlp_primer_content_page4" || Page=="nlp_primer_content_page5" || Page=="nlp_primer_content_page6")
  	  Page="nlp_primer_content";
  else if (Page=="nlp_eye_accessing_page2")
  	  Page="nlp_eye_accessing";
	  
  document.writeln("<div id='invitation'>");
  if (Comments == "0")
  {
	document.write("&nbsp;<span class='textinvitation'>");
	document.write(CommentsText);
	document.write("&nbsp;-&nbsp;</span><a class='textinvitation' href='./");
	document.write("comment.html?p=");
	document.write(Page);
	document.write("&t=");
	document.write(PageTitle);
	document.write("'>Be the first to comment</a>");
  }
  else
  {	
	document.write("&nbsp;<span class='textinvitation'>&nbsp;");
	document.write("<a class='textinvitation' href='./");
	document.write(Page);		
	document.write("_comments.html'>");
	document.write(Comments);
	document.write("&nbsp;");
	document.write(cmtext);
	document.write("</a>&nbsp;&nbsp;|&nbsp;&nbsp;");
	document.write(CommentsText);
	document.write("&nbsp;-&nbsp;</span>");
	document.write("<a class='textinvitation' href='./");
	document.write(Page);
	document.write("_comments.html#comment'>");		
	document.write("Post a comment</a>");
  }
  document.writeln("</div>");
}

function AddComment(Mod, DT, Name, Location, Title, Text)
{
  if (Mod == "Y")
  {
	document.writeln("<hr/><table><tr><td width='100' valign='top'><p class='cm_mod'>");
  }
  else
  {
	document.writeln("<hr/><table><tr><td width='100' valign='top'><p class='cm_name'>");
  }
  document.writeln(Name);
  document.writeln("</p><p class='cm_location'>");
  document.writeln(Location);
  document.writeln("</p></td><td width='500'>");
  document.writeln("<p class='cm_title'>");
  document.writeln(Title);
  document.writeln("</p><p class='cm_dt'>Posted&nbsp;");
  document.writeln(DT);
  document.writeln("</p><p class='cm_text'>");
  document.writeln(Text);
  document.writeln("</p></tr></td></table>");
}

function AddRightBlock(row)
{
	switch (RightBlock.charAt(row-1))
    {
    case 'H':
        AddHypnosisDownloadsTopTen();
		break;
    case 'G':
        AddGoogleAd(7);
		break;
	case 'A':
        AddAmazonBox();
	    break;
	case 'S':
		AddHypnosisDownloadsSearchBox();
		break;
	case 'V':
		document.writeln("<table><tr><td width='150' align='center'>");
		AddHypnosisDownloadsVertical();
		document.writeln("</td><td width='150' align='center'>");
		AddHypnosisDownloadsLearnHypnosisVertical();
		document.writeln("</td></tr></table>");
		break;
	case 'D':
		AddHypnosisDirect120Spiral();
		break;
	case 'E':
		AddHypnosisDirect120Flash();
		break;
	case 'C':
    	AddNLPCoach();
	    break;
}
} 

function AddTopBlock(row)
{
	switch (TopBlock.charAt(row-1))
    {
    case 'H':
	    AddHypnosisBanner(); 
        break;
	case 'G':
    	AddGoogleAd(6);
        break;
	}	 
}

function AddRightBlocks()
{
//if (returnShortDocument() === "hypnosis_downloads") return;
	
document.writeln("<table width='320' bgcolor='#FFFFFF' border=0 cellpadding=0><tr><td height='12'></td></tr><tr><td>");
AddRightBlock(1);
document.writeln("</td></tr><tr><td height='2' align='center'></td></tr><tr><td>");
AddRightBlock(2);
document.writeln("</td></tr><tr><td height='2' align='center'></td></tr><tr><td>");
AddRightBlock(3);
document.writeln("</td></tr><tr><td height='2' align='center'></td></tr><tr><td>");
AddRightBlock(4);
document.writeln("</td></tr></table>");
}