//sets messages to be displayed in text boxes
var FormTxt = Array();
FormTxt["search"] = "Enter search Term...";
FormTxt["author"] = "Your Name";
FormTxt["email"] = "Email Address (won't be made public)";
FormTxt["RssEmail"] = "Enter Your Email Address";
FormTxt["url"] = "Add a URL to this comment";
FormTxt["comment-text"] = "Type Your Comment Here...";

function setPrimarySection(sectionName) {
  var navElements = document.getElementById("siteNavMain").getElementsByTagName("li");

  for (var tmpEl = 0; tmpEl < navElements.length; tmpEl++) {
    if (sectionName != "" && navElements[tmpEl].innerHTML.toLowerCase().indexOf(">" + sectionName.toLowerCase()) > -1) {
      BCLink = navElements[tmpEl].getElementsByTagName("a")[0].href;
      navElements[tmpEl].className += " activeNav";
    } 
  }
}
  
//creates cookies
function createCookie(name,value,days)
{
 if (!days)
   days = 14;
    
	     var date = new Date();
 date.setTime(date.getTime()+(days*24*60*60*1000));
 var expires = "; expires="+date.toGMTString();
	
 document.cookie = name+"="+value+expires+"; path=/";
}//end createCookie

//reads a cookie
function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(";");

  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(nameEQ) == 0)
    return c.substring(nameEQ.length,c.length);
	 }
	 return null;
}//end readCookie

//reads stored values into post fields
function readPostValues()
{
  if (readCookie("authorName") != null)
    document.getElementById("author").value = readCookie("authorName");

  if (readCookie("authorEmail") != null)
    document.getElementById("email").value = readCookie("authorEmail");
  
  if (readCookie("ResetCAPTCHA") == "1" && readCookie("commentSave") != null)
  {
    document.getElementById("comment-text").value = decodeURIComponent(readCookie("commentSave"));
    createCookie("ResetCAPTCHA","0",1);
    createCookie("comment-text","",1);
  }
}

//saves data for later use
function saveCommentData()
{
  //saves the user information in cookies
  if (document.getElementById("author").value != "")
    createCookie("authorName",document.getElementById("author").value);

  if (document.getElementById("email").value != "")
    createCookie("authorEmail",document.getElementById("email").value);
    
  if (document.getElementById("comment-text").value != "")
    createCookie("commentSave",encodeURIComponent(document.getElementById("comment-text").value));
}


//run when a user posts a comment
function formSubmit()
{
  if (document.getElementById("author").value == "" && document.getElementById("author").value != "Your Name")
  {
    alert("You must enter a name\nin order to comment.");
    return false;
  }

  if (document.getElementById("RequireEmail") != null && document.getElementById("email").value.search(/^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/) < 0)
  {
    alert("You must enter a valid Email\nin order to comment.");
    return false;
  }

  
  if (document.getElementById("comment-text").value == "")
  {
    alert("You must enter a Comment\nin order to comment.");
    return false;
  }
  
  if (document.getElementById("captcha_code") != null && document.getElementById("captcha_code").value == "")
  {
    alert("You must enter the Security Code\nin order to comment.");
    return false;
  }

  //saves data for later use
  saveCommentData();
  
  //disables posting so we get fewer duplicate posts
  document.getElementById("comment-post").value = "Posting..";
  document.getElementById("comment-post").disabled = true;
  
  return true;
}

function initForms()
{
  AllTags = document.getElementsByTagName("input");
  for (var tmpT=0;tmpT<AllTags.length;tmpT++)
    if (FormTxt[AllTags[tmpT].id])
      setupInpArea(AllTags[tmpT]);
}
  
function setupInpArea(inpEle)
{
  inpEle.onfocus = function() {inpFocus(this)};
  inpEle.onblur = function() {inpBlur(this)};
  inpEle.defaultValue = FormTxt[inpEle.id];
  inpBlur(inpEle);
}
  
function inpBlur(inpEle)
{
  if (inpEle.value == "" || inpEle.value == FormTxt[inpEle.id])
  {
//    inpEle.className += " formUnsel";
    inpEle.value = FormTxt[inpEle.id];
  }
}

function inpFocus(inpEle)
{
  if (inpEle.value == FormTxt[inpEle.id])
  {
    inpEle.value = "";
//    inpEle.className = inpEle.className.replace("formUnsel","");
  }
}

function setDomain()
{
  var curDom = document.domain;
  document.domain = curDom.substr(curDom.indexOf(".")+1);
}

function calendarLoad(rspTxt, rspStatus)
{
  if (rspStatus == "success")
    document.getElementById("CalendarDisplay").innerHTML = rspTxt;
 
 if (location.href.indexOf("test=1") > 0)
  {
    alert(p2);
  }
}

function getCalendar(calURL)
{
  $("#CalendarDisplay").load(calURL,calendarLoad);
}
$.getQueryString = function () {};

function nav(sel) {
   if (sel.selectedIndex == -1) return;
   var opt = sel.options[sel.selectedIndex];
   if (opt && opt.value)
      location.href = opt.value;
}

function NumberComments(TotPosts, DspPosts)
{
  if (TotPosts == "")
    TotPosts = DspPosts;
  
  if (!isNaN(TotPosts) && !isNaN(DspPosts))
  {
    var StrPost = Number(TotPosts) - Number(DspPosts);
    
    if (StrPost < 0)
      StrPost = 0;
  
    $(".CommentNumber").each(function() {this.innerHTML = ++StrPost;});
  }
}

function CommentResetCAPTCHA()
{
  createCookie("ResetCAPTCHA","1",1);
}

function ShowCaptchaReset()
{
  $("<div class='CaptchaOutMsg'><span>This CAPTCHA has expired!</span><br /><button class='CAPTCHAResetBtn' onclick='return refreshCaptcha()'>&nbsp;Refresh Text&nbsp;</button><br /><small>(Your comment will not be lost.)</small></div>").appendTo("#captchaArea");

  document.getElementById("captcha_code").disabled = true;
  document.getElementById("comment-post").disabled = true;
}

function refreshCaptcha()
{
  saveCommentData();
  CommentResetCAPTCHA();
  location.href = location.protocol + "//"+location.host + location.pathname + "#post";
  location.reload();
  return false;
}


$.getQueryString = function () {};



function emailThis(formNum)
{
  document.getElementById("mail_link_"+formNum).submit()
}

//launches the popup for Staying in touch video
function launchVideo(vidID,vidTitle)
{
  window.open('http://blog.beliefnet.com/MarthaWilliamson/popup.php?vidID='+vidID+'&vidTitle='+vidTitle,"MWPopup","height=355,width=705,left=50,top=50,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
}

//launches the partner video
function launchBC(lnk)
{
  //pauses the curently playing video
  if (typeof(callFlash) == "function")
    callFlash("pauseVideo", true);
  window.open(lnk,"bcPlayer","height=550,width=510,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
}

//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
