/*******************************************************************************
* +--------------------------[ File Revision Info ]--------------------------+ *
* | $Revision::                                                           $: | *
* | $Date::                                                               $: | *
* | $Author::                                                             $: | *
* +--------------------------------------------------------------------------+ *
* | $Id::                                                                 $: | *
* +--------------------------------------------------------------------------+ *
*******************************************************************************/

<!-- 
function openWindow(theURL,winName,features) { // Open Pop Up
  window.open(theURL,winName,features);
}

function expandCollapse() { // expand/collapse layers
	for (var i=0; i<expandCollapse.arguments.length; i++) {
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}

function checkAll() {
  for (var i = 0; i < document.editform.elements.length; i++) {
    if(document.editform.elements[i].type == 'checkbox'){
      document.editform.elements[i].checked = !(document.editform.elements[i].checked);
    }
  }
}

/*
  forum functions
  found and used graciously from: http://www.iceteks.com/articles.php/javascript/1
*/

//Variables for controlling opening and closing tags (function tag)
var b = 2;
var i = 2;
var u = 2;
var q = 2;
var c = 2;
var url = 2;
var email = 2;
var img = 2;

//Function for creating tags
function tag(v, tagadd, newbut, tagclose, oldbut, name) {
    if (eval(v)%2 == 0) {
        eval("window.document.editform."+name+".value = newbut;");
        var text = window.document.editform.text.value;
        window.document.editform.text.value = text + tagadd;
        window.document.editform.text.focus();
    } else {
        eval("window.document.editform."+name+".value = oldbut;");
        var text = window.document.editform.text.value;
        window.document.editform.text.value = text + tagclose;
        window.document.editform.text.focus();
    }
    eval(v+"++;");
}

//Function to confirm reset
function confirm_reset () {
	if(confirm("Click 'OK' to completely remove all text entered.\n\n Or click 'Cancel' to continue working on your post.")) {
		window.document.editform.text.value = '';
        window.document.editform.text.focus();
		return true;
	}
	else {
		return false;
	}
}

//Check the form submission for errors
function checkForm() {
	var text = document.editform.text;
	
	// Check to make sure post length is sensible
	if (text.value.length < 10) {
		alert("Message is too short (min. 10 characters)\n\n" + "Please go back and try again.");
		return false;
	}
	else {
		return true;
	}
}


// variable for holding contribution level labels and amounts
var contributionLevelLabels = new Array();
var contributionLevelAmounts = new Array();
var contributionLevels = new Array();

// function to add Contribution Level label and amount to levels array
function addContributionLevel() {
	var label = document.editform.contribution_level_label.value;
	var amount = document.editform.contribution_level_amount.value;
	
	if (label=="") {
		alert ("Please enter a contribution level label.");
		return false;
	} else if (amount=="") {
		alert ("Please enter a contribution level amount.");
		return false;
	} else {
		document.editform.contribution_levels.value = document.editform.contribution_levels.value + label + " - $" + amount + "\r\n";
		document.editform.contribution_level_label.value = "";
		document.editform.contribution_level_amount.value = "";
		contributionLevelLabels[contributionLevelLabels.length] = label;
		contributionLevelAmounts[contributionLevelAmounts.length] = amount;
		contributionLevels[contributionLevels.length] = label+':'+amount;
	}
	return true;
}

// function to turn Contribution Levels array into string to be processed by PHP $Post hidden variable
function setContributionLevels() {

	var labels = contributionLevelLabels.toString();
	var amounts = contributionLevelAmounts.toString();
	var levels = contributionLevels.toString();

	document.editform.contribution_level_labels.value = labels;
	document.editform.contribution_level_amounts.value = amounts;
	document.editform.contribution_levels_all.value = levels;
}

// function to get the page's embedded Domain ID to be used by google analytics
function getPageDomainID()
{
	var pageDomainField = document.getElementById('pageDomainID');

	if (pageDomainField)
	{
		if(pageDomainField.value != "")
		{
			return pageDomainField.value;
		}
	}
	return 1;
}

// Get URL parameter
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

// Capitalize Each Word method
function toUpperEachWord(_string) 
{
    r = '';
    for(i=0; i<_string.length; i++) {
        if ((i==0) || _string[i-1].charAt(0)==' ' || _string[i-1].charAt(0)=='/') {
            x = _string[i].charAt(0).toUpperCase();    
        }else {
            x = _string[i].charAt(0);
        }
        r += x;
    }
    return r;
}

// Reverse String method
function stringRev()
{
  r = "";
  for(i=this.length-1; i>=0; i--){
     r += this.charAt(i)}
  return r
}

// IE fix for Suckerfish dropdowns
sfHover = function() 
{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");

	for (var i=0; i<sfEls.length; i++) 
	{
		sfEls[i].onmouseover=function() 
		{
			this.className+=" sfhover";
		}

		sfEls[i].onmouseout=function() 
		{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

//-->