$(document).ready(function() {         
   $('#query').focus(function() {
      $('#query').val('');
   });
});
function doSearch() 
{
   var trimmed = $('#query').val().replace(/^\s+/g, '').replace(/\s+$/g,'');
   if (trimmed.length == 0 || trimmed == 'Enter Name' || trimmed == '') {
      alert("Please enter a search name.");
      $('#query').focus();
      return false;
   }
   $('#query').val(trimmed);
   $("#posterSearch").submit();
}
function toggleShippingAddressSection()
{
   $('#shippingAddressSection').toggle('slow');
}
function updateShipped()
{
   $("#updatePosters").submit();
}
function selectShippedAll()
{
   $("INPUT[type='checkbox']").attr('checked', true);
   $("INPUT[type='checkbox']").val("false");
   return false;
}
function selectShippedNone()
{
   $("INPUT[type='checkbox']").attr('checked', false);
   $("INPUT[type='checkbox']").val("true"); 
   return false;
}
function toggleShippedValue(el)
{
   if (el.value == "true")
   {
      el.value = "false";
   }
   else
   {
      el.value = "true";
   }
}
   
/* ------------------------------------------------------------ 
   Copyright (c) 2006 ManyFutures, Inc. All rights reserved.
   ------------------------------------------------------------ 
   FILE: pandora.js
   DESCRIPTION: Site wide javascript functions for globalgiving.
   We try to place all (most) javascript into one file that will
   be downloaded once and cached for all pages.
   ------------------------------------------------------------ */

/* ********************* GENERAL ** GENERAL ***************** */
/* ********************* GENERAL ** GENERAL ***************** */
/* ********************* GENERAL ** GENERAL ***************** */

/*
 * Function called in ONLOAD for every page to eliminate 
 * use of http://globalgiving.org style URLs, e.g., without
 * a  www hostname prefix.
 */

function forcewww() {
   var url = window.location.href;
   // staging-test servers do not have .com in host name
   dotcom = url.indexOf(".com");
   if (dotcom > 0 && dotcom < 20) {
      www = url.indexOf("www");
      if (www < 0 ) {
         // Get current site address
         stendndx = url.indexOf("://")+3;
         ststartndx = url.indexOf(".com");
         site = url.substring(ststartndx,stendndx)
         // Get site location, if different than the index page
         uslondx = url.indexOf(".com")+4;
         userlocation = url.substring(uslondx);
         // Redirect users to www site, replacing page in history
         newurl = "http://www." + site + ".com" + userlocation;
         window.location.replace(newurl);
      }
   }
}

/*
 * Function called on every page to check if the user is logged in 
 * or not.  If they are logged, we display their display name, handed 
 * to me by the cookie.
 */

/* To be implemented along with sign in */


// Popup a help window
function showhelp(url)
{
  var width = 400;
  var height = 500;
  var name = 'HelpWindow';
  settings="toolbar=no,location=no,directories=no,"
    + "status=no,menubar=no,scrollbars=yes,resizable=no,"
    + "width=" + width + ",height=" + height;
  window.open(url,name,settings);
}

/* ********************* EMAIL ** EMAIL ***************** */
/* ********************* EMAIL ** EMAIL ***************** */
/* ********************* EMAIL ** EMAIL ***************** */

/*
 * Functions used to mask email addresses throughout website.
 * Variations on subject line, body or email address style
 */

function mkaddr5(addr,subj,body,label) {
  document.write('<a class="menutab" href=\"mailto:' + addr + '@' + site 
	+ '?subject=' + subj + '&body=' + body + '\">' 
	+ label + '</a>');
}

function mkaddr4(addr,subj,body,label) {
  site = "globalgiving.org";
  document.write('<a href=\"mailto:' + addr + '@' + site 
	+ '?subject=' + subj + '&body=' + body + '\">' 
	+ label + '</a>');
}

function mkaddr2(addr,label) {
  site = "globalgiving.org";
  document.write('<a class="learnmore" href=\"mailto:' + addr + '@' + site 
        + '\">' + label + '</a>');
}

function mkaddr(addr) {
  site = "globalgiving.org";
  mkaddr2(addr,addr + '@' + site);
}

function protectaddr(addr,domain,label) {
	document.write('<a href=\"mailto:' + addr + '@' + domain 
		+ '\">' + label + '</a>');
}

function protectaddr2(addr,domain) {
	document.write('<a href=\"mailto:' + addr + '@' + domain 
		+ '\">' + addr + '@' + domain + '</a>');
}
 

function emailafriend(body,url,lbl) {
    document.write('<a href="mailto:?body='+body+'  See more details and give directly to this project at http://www.globalgiving.org/'+url+'">'+lbl+'</a>');
}


function emailprofile(subject,body,url,lbl) {
    document.write('<a href="mailto:?subject=' + subject + '&body=' + body + escape(url) + ' ">'+lbl+'</a>');
}

/* ********************* POP UPS * POP UPS ***************** */
/* ********************* POP UPS * POP UPS ***************** */
/* ********************* POP UPS * POP UPS ***************** */

/*
 * Functions that call up a pop-up window.  Settings vary for new window.
 */

// Simple browser window without features
function popup(url, name, width, height) {
  settings=
  "toolbar=no,location=no,directories=no,"+
  "status=yes,menubar=no,scrollbars=no,"+
  "resizable=yes,width="+width+",height="+height;
		  
  MyNewWindow=window.open(url,name,settings);
}

// Simple browser window with only a scrollbar
function popup2(url, name, width, height) {
  settings=
  "toolbar=no,location=no,directories=no,"+
  "status=no,menubar=no,scrollbars=yes,"+
  "resizable=no,width="+width+",height="+height;
		  
  MyNewWindow=window.open(url,name,settings);
 }

/* ********************* DONATIONS ** DONATIONS ***************** */
/* ********************* DONATIONS ** DONATIONS ***************** */
/* ********************* DONATIONS ** DONATIONS ***************** */

/*
 * The following are several functions used in the donation pages. 
 * They range from taking data out of the URL to display on page to
 * creating hyperlinks to giftany functions and comments for verisign.
 */

// This function lets us grab data out of the URL
function getUrlParm(url,parmname) { 
   qndx = url.indexOf("?"); 
   if(qndx < 0) return null; 
   parmndx = url.indexOf(parmname,qndx+1); 
   if(parmndx < 0) return null; 
   eqndx = url.indexOf("=",parmndx); 
   if(eqndx < 0) return null; 
   termndx = url.indexOf("&", eqndx); 
   if( termndx < 0 ) { 
     termndx = url.indexOf("#",eqndx); 
     if(termndx < 0) { 
       return unescape(url.substring(eqndx+1)); 
     } 
   } 
   return unescape(url.substring(eqndx + 1,termndx)); 
 } 

// This function makes the hyperlink to the gift any feature
function makehyperlink(lbl) {
    var url = window.location.href
    var projid = getUrlParm(url,"pid");
    var projpath = getUrlParm(url,"path");
    var projtitle = getUrlParm(url,"ptitle");
    var resturl = "/dy/gifts/pandora.html?cmd=gifta&projid="+projid+"&projpath="+projpath+"&projtitle="+projtitle;
    document.write('<a href="'+resturl+'">'+lbl+'</a>')
}

// Test to make sure entered donation amount is valid
function is_a_num(number) {
    var tester = number * 1;
    // Check to make sure field is not blank
    if ((number == null) || (number.length == 0)){
	alert("Please enter a donation amount");
        return false;
    }
    // Check to make sure number is not negative or 0
    if (number < 1){
	alert("Please enter a positive donation amount");
        return false;
    }
    // Check to make sure number is indeed a number
    if (isNaN(tester) == true){
	alert("Please enter a valid donation amount");
        return false;
    }
    return true;
}

// Create comment field for verisign and submit verisign form
function descvalue() {
    var url = window.location.href
    // Gathering variables needed for comment field
    var projid = getUrlParm(url,"pid");
    var projtitle = getUrlParm(url,"ptitle");
    var donation = document.amt.AMOUNT.value;
    // Converting data from checkboxes into variables
    if(document.amt.ANON.checked){
       var anonymous = "a";
    } else {
      var anonymous = "p";
    }
    if(document.amt.NEWSL.checked){
      var newsletter = "r";
    } else {
      var newsletter = "u";
    }
    // Creating the verisign comment and description field
    document.amt.DESCRIPTION.value = (unescape(projtitle+" ("+projid+")"));
    document.amt.COMMENT1.value = ("d:-1:"+projid+":"+anonymous+":"+newsletter+":"+donation);
    // Submiting form if donation amount is a valid number
    if ( is_a_num(donation) == true ) {
       document.amt.submit();
    }
}

/* ********************* GIFTS GIFTS GIFTS ***************** */
/* ********************* GIFTS GIFTS GIFTS ***************** */
/* ********************* GIFTS GIFTS GIFTS ***************** */
/* ********************* GIFTS GIFTS GIFTS ***************** */

/*
 * The following functions let the user preview the information entered
 * for the gift cards.  there are two functions now as there are two cards
 */

// Gift Any Preview
function old_preview() {
  var projtitle = document.gift.projtitle.value;
  var projid = document.gift.projid.value;
  var projpath = document.gift.projpath.value;
  var recipient = document.gift.recip_fname.value;
  var message = document.gift.recip_msg.value;
  if (message.length > 200) {
     alert("The personalized message is above 200 characters, please reduce it.");
     var msgerror = "toolong";
  };
  var sender = document.gift.sender_fname.value;
  var sendlast = document.gift.sender_lname.value;		  
  if ((msgerror == null) || (msgerror.length == 0)) {
       popup("/gifts/giftprev.html?ptitle="+projtitle+"&pid="+projid+
	     "&path="+projpath+
             "&recname="+recipient+"&recmsg="+message+"&sender="+sender+
             "&lastname="+sendlast, 'Win1', 600, 430); return false;
  }
}

// Gift Package Preview
function preview2() {
  var message = document.gift.recip_msg.value;
  if (message.length > 200){
     alert("The personalized message is above 200 characters, please reduce it.");
     var msgerror = "toolong";
  };
  var sendfirst = document.gift.sender_fname.value;
  var sendlast = document.gift.sender_lname.value;
  var sender = sendfirst + " " + sendlast
  var pid = document.gift.projid.value;
  var path = document.gift.projpath.value;
  var text = document.gift.cardtext.value;
  cardtext = text.replace(/__/, sender);
  if ((msgerror == null) || (msgerror.length == 0)) {
       popup("/gifts/giftpkgprev.html?cardtext="+cardtext+"&pid="+pid+
	     "&path="+path+
             "&recmsg="+message+"&sender="+sendfirst+"&lastname="+sendlast, 
             'Win1', 600, 400); return false;
  };
}

/* ********************* URL MAKER ***************** */
/* ********************* URL MAKER ***************** */
/* ********************* URL MAKER ***************** */

/*  
 * Make the url to run htdig search on project partners for aboutds page
 */

function htdigurl(ngoname) {
document.write('<a href="/cgi-bin/htsearch?config=htdig&amp;restrict=&amp;exclude=&amp;method=and&amp;format=long&amp;sort=score&amp;words='+ngoname+'">View projects</a>')
    }

/*  
 * Make the url for the give now button to link to the donate now page with
 * the project title and project id included in the url.
 */

function giveurl(pid,ptitle,path) {
    document.write('<a href="/dy/cart/ezgivepage/pandora.html?cmd=show&projid='+pid+'"><img alt="Give Now" border="0" src="/cb/pandora/img/givenow.gif"></a>')
	}

/*  
 * Make the url for the give now button to link to the donate now page with
 * the project title and project id included in the url.  This is for cobrands
 * Where the donate page is in the image directory
 */

function giveurl2(pid,ptitle) {
    document.write('<a href="/dy/cart/ezgivepage/pandora.html?cmd=show&projid='+pid+'"><img alt="Give Now" border="0" src="/cb/pandora/img/givenow.gif"></a>')
	}

/* ********************* COUNTRY INFO PAGES ***************** */
/* ********************* COUNTRY INFO PAGES ***************** */
/* ********************* COUNTRY INFO PAGES ***************** */


/*  
 * Makes sure graph bar width is always at least 1 on country stat pages
 */

function ctrywid(wid) {
    if ( wid < 2 ) {
	width = 2;
    }
	}

/*  
 * Navigate between various country info pages
 */

function gotoctry(page){
    selectedctry = document.ctry_nav.recip_ctryid.selectedIndex;
    ctryid = document.ctry_nav.recip_ctryid.options[selectedctry].value;
    ctryurl = '/ctry/ctryi' + page + ctryid + '.html'
    // alert("this is the url:   " + ctryurl)
    location.href = ctryurl;
}

/*  
 * Return to index or hall of fame index pages
 */

function indxlink(url){
    opener.location = url;
    window.close()
}


// CREATE A MAILTO URL OR MAILTO ANCHOR TAG
function createMailto(sourceForm, targetField, urlType) {
  var to      = sourceForm.to.value;
  var cc      = sourceForm.cc.value;
  var bcc     = sourceForm.bcc.value;
  var subject = sourceForm.subject.value;
  var body    = sourceForm.body.value;
  var linkText= sourceForm.linkText.value;
  
  if (linkText == "") {
    linkText = "Link Text";
  }
  
  var urltext = "";

  // IF THE VALUE IS SET, INCLUDE IT IN THE URL
  if (to != "") {
    urltext += to;
  }
  else {
    alert("Sorry, you must fill out the 'To' field");
    sourceForm.to.focus();
    return(1);
  }
  if (cc != "") {
    urltext = addDelimiter(urltext);
    urltext += "CC=" + cc;
  }
  if (bcc != "") {
    urltext = addDelimiter(urltext);
    urltext += "BCC=" + bcc;
  }
  if (subject != "") {
    urltext = addDelimiter(urltext);
    urltext += "Subject=" + escape(subject);
  }
  if (body != "") {
    urltext = addDelimiter(urltext);
    urltext += "Body=" + escape(body);
  }
  if (urlType == "url") {
    urltext = "mailto:" + urltext;
  }
  else {
    urltext = "<A HREF=\"mailto:" + urltext + "\">" + linkText + "</A>";
  }

  // PUT THE NEW URL IN THE FORM FIELD
  targetField.value = urltext;

  // GIVE THE FIELD FOCUS AND HIGHLIGHT THE TEXT -- 
  // TO FACILITATE EASY COPYING AND PASTING OF THE NEW URL
  targetField.focus();
  targetField.select();
  return(1);
}


// ADD THE "?" OR "&" NAME/VALUE SEPARATOR CHARACTER
function addDelimiter(inputString) {
  var inString = inputString;

  // IF '?' NOT FOUND, THEN THIS IS THE FIRST NAME/VALUE PAIR
  if (inString.indexOf("?") == -1) {
    inString += "?";
  }
  // ELSE IT'S A SUBSEQUENT NAME/VALUE PAIR, SO ADD THE '&' CHARACTER
  else {
    inString += "&";
  }
  return inString;
}


// TEST THE MAILTO URL -- ASSIGN THE URL TO THE DOCUMENT LOCATION
// TO POP UP THE MESSAGE WINDOW
function testMailto(loc) {
  var doc = loc;

  // IF MAILTO URL IS EMBEDDED IN AN ANCHOR TAG
  if (doc.indexOf("HREF=") != -1) {
    // EXTRACT THE MAILTO URL FROM THE ANCHOR TAG
    var doc = doc.substring(doc.indexOf("HREF=")+6, doc.indexOf(">")-1);
  }

  // ASSIGN THE MAILTO URL TO THE DOCUMENT (THIS WILL POP UP A MAIL WINDOW)
  window.location = doc;
}


function viewMailto(mailtoText) {
  alert("URL:\n\n" + mailtoText);
}

// VALIDATION FOR RECEIPT FEEDBACK SURVEY

function radioReceiptValidate()
{
// set var radio_choice to false
var radio_choice1 = false;
var radio_choice2 = false;
var radio_choice3 = false;
// Loop from zero to the one minus the number of radio button selections
   for (counter = 0; counter < document.formRecptSurvey.a1.length; counter++)
   {
     if (document.formRecptSurvey.a1[counter].checked) {
       radio_choice1 = true; }
   }
   for (counter = 0; counter < document.formRecptSurvey.a2.length; counter++)
   {
     if (document.formRecptSurvey.a2[counter].checked) {
       radio_choice2 = true; }
   }
   for (counter = 0; counter < document.formRecptSurvey.a3.length; counter++)
   {
     if (document.formRecptSurvey.a3[counter].checked) {
       radio_choice3 = true; }
   }

   if (!radio_choice1 || !radio_choice2 || !radio_choice3)
   {
      alert("Please select an answer for each of the questions.")
         return (false);
   }
   return (true);
}

/*

DISCLAIMER: THESE JAVASCRIPT FUNCTIONS ARE SUPPLIED 'AS IS', WITH 
NO WARRANTY EXPRESSED OR IMPLIED. YOU USE THEM AT YOUR OWN RISK. 
NEITHER PAUL STEPHENS NOR PC PLUS MAGAZINE ACCEPTS ANY LIABILITY FOR 
ANY LOSS OR DAMAGE RESULTING FROM THEIR USE, HOWEVER CAUSED. 

Paul Stephens' NetScape-based cookie-handling library

http://web.ukonline.co.uk/paul.stephens/index.htm

TO USE THIS LIBRARY, INSERT ITS CONTENTS IN A <script></script> BLOCK IN THE 
<HEAD> SECTION OF YOUR WEB PAGE SOURCE, BEFORE ANY OTHER JAVASCRIPT ROUTINES.

Feel free to use this code, but please leave this comment block in.

*/

function setCookie (name, value, lifespan, access_path) {
      
  var cookietext = name + "=" + escape(value)  
    if (lifespan != null) {  
      var today=new Date()     
      var expiredate = new Date()      
      expiredate.setTime(today.getTime() + 1000*60*60*24*lifespan)
      cookietext += "; expires=" + expiredate.toGMTString()
    }
    if (access_path != null) { 
      cookietext += "; PATH="+access_path 
    }
   document.cookie = cookietext 
   return null  
}


function setDatedCookie(name, value, expire, access_path) {
    var cookietext = name + "=" + escape(value)
      + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
     if (access_path != null) { 
      cookietext += "; PATH="+access_path 
     }
   document.cookie = cookietext 
   return null        
}

/**
 * Get the value of a cookie.  If the cookie does not exist, return 'null'.
 *
 * Use this function instead of 'getCookie()' as this function is more
 * appropriately/accurately named.
 */
function getCookieValue( Name ) {
  var search = Name + "="                       
  var CookieString = document.cookie            
  var result = null                               
  if (CookieString.length > 0) {                
    offset = CookieString.indexOf(search)       
    if (offset != -1) {                         
      offset += search.length                   
      end = CookieString.indexOf(";", offset)   
      if (end == -1)                            
        end = CookieString.length               
      result = unescape(CookieString.substring(offset, end))         
                                                
      } 
    }
   return result;                                
}

/** 
 * Check if a cookie exists at all.  Value may still be blank (i.e. an empty
 * string).  Function returns a boolean - true if the cookie exists; otherwise,
 * false.
 */
function userHasCookie( CookieName ) {
  var cookieValue = getCookieValue( CookieName )
  if ( cookieValue == null ) return false
  return true
}

/**
 * This function should really be called getCookieValue(), because it returns
 * a cookie's value, not a cookie object itself.
 */
function getCookie( Name ) {
  return getCookieValue( Name )
}

/** 
 * Get a cookie value ONLY for specified path
 */
function getCookieValue(Name, Path)
{
 var search = Name + "="                       
  var CookieString = document.cookie            
  var result = null                               
  if (CookieString.length > 0) {                
    offset = CookieString.indexOf(search)       
    if (offset != -1) {                         
      offset += search.length                   
      end = CookieString.indexOf(";", offset)   
      if (end == -1)                            
        end = CookieString.length               
      result = unescape(CookieString.substring(offset, end))         
                                                
      } 
    }
   return result;                                
}
/**
 * Remove a cookie.
 */
function deleteCookie(Name, Path) {
  setCookie(Name,"Deleted", -1, Path)
}

