// adds a css class to the menu's parent for setting up a menu hover style
function addHoverMenu( triggerId, hoverClass ) {
    document.getElementById(triggerId).onmouseover = function () {
        this.className += " " + hoverClass;
    }
    document.getElementById(triggerId).onmouseout = function () {
        this.className = this.className.replace( hoverClass, "" );
    }
}

// truncates a one-line string to a fixed pixel width
// element must be a <span> or other object without layout
function ellipseListText( elementId, width ) {
    var el   = document.getElementById(elementId);
    if (!el) {
        return;
    }
    
    if( el.offsetWidth > width ) {
      var i = 1;
      var text = el.innerHTML;
      el.innerHTML = ' ';
      while( ( el.offsetWidth < width ) && ( i < text.length ) ) {
         el.innerHTML = text.substr( 0, i ) + '...';
         // el.className = 'ellipsed';
         i++;
      }
      el.title = text;
    }    
}

// expander toggle for breed guides
function toggle(div_id) {
    var div = document.getElementById(div_id);
    if (div) {
        if (div.className == 'show') {
            div.className = 'hide';
        } else {
            div.className = 'show';
        }
    }
}

// constant expander images for right rail category expander tree
var closedImg = 'http://www.petfinder.com/images/library/cat-closed.gif';
var openImg   = 'http://www.petfinder.com/images/library/cat-open.gif';

// function for opening and closing the category tree in the right rail category expander tree
function topicList ( topicImgId, topicSubsId, topicStateId, topicParentId ) {
    
    // topicegory was open. close it.
    if (document.getElementById(topicStateId).innerHTML == 'open') {
        document.getElementById(topicImgId).src = closedImg;
        document.getElementById(topicSubsId).className  = 'category_tree_closed';
        document.getElementById(topicStateId).innerHTML = 'closed';
    }
    
    // topicegory was closed. open it.
    else if (document.getElementById(topicImgId) && document.getElementById(topicSubsId) && document.getElementById(topicStateId)) {
        document.getElementById(topicImgId).src = openImg;
        document.getElementById(topicSubsId).className  = 'category_tree_open';
        document.getElementById(topicStateId).innerHTML = 'open';
        var i = 0;
        var j = 0;
        var k = 0;
        
        // close all other open categories.
        var parent = document.getElementById(topicParentId);
        try {
        for (i in parent.childNodes) {
            var el = parent.childNodes[i];
            if ( (el.className == 'category_tree_open') && (el.id != topicSubsId) ) {
                // close the tree
                el.className = 'category_tree_closed';
            }
            else if ( (el.className == 'category_tree_hidden') && (el.id != topicStateId) && (el.innerHTML != 'closed') ) {
                // set the hidden state field to closed
                el.innerHTML = 'closed';
            }
            else if ( el.nodeName && (el.nodeName.toLowerCase() == 'p') ) {
               for (j in el.childNodes) {
                   var jel = el.childNodes[j];
                   if (jel.nodeName && (jel.nodeName.toLowerCase() == 'a') ) {
                       for (k in jel.childNodes) {
                           var kel = jel.childNodes[k];
	       if ((kel.className == 'cat-img') && (kel.id != topicImgId) && (kel.src == openImg) ) {
                               // change the icon to closed
                               kel.src = closedImg;
	       }
                       }
                   }
               }
            }
        }
        } catch (e) {}
    }
}

// For emailing a friend
function openEmailFriend(subject, text, target_url) {
    var url = "/tools/email-friend/index.cgi?subject=" + subject + "&amp;link_text=" + text + "&amp;target_url=" + target_url;
    newwin = window.open(url,'EmailFriendWindow','top=150,left=150,width=738,height=585,scrollbars=yes,resize=yes');

    // bring the new window to the front, just in case it's hidden
    if (window.focus) {
        newwin.focus();
    }
    
    return false;
}

// For social networking "share" button
function openAddThis() {
    var url = "http://www.addthis.com/bookmark.php";
    newwin = window.open(url,'ShareWindow','top=150,left=150,width=600,height=500,scrollbars=yes,resize=yes');
    
    // bring the new window to the front, just in case it's hidden
    if (window.focus) {
        newwin.focus();
    }
    
    _gaq.push(['_trackPageview', 'outbound/www.addthis.com']);
    return false;
}

function checkContestForm() {
  document.getElementById('citystate').value=document.getElementById('locality').value + ', ' + document.getElementById('region').options[document.getElementById('region').selectedIndex].value;
  if (document.getElementById('pf_sign_in')) {
    if ( document.getElementById('pf_sign_in').checked ) {
      return true;
    }
    else {
      return contestSignUp();
    }
  }
  else {
    return true;	  
  }
  return false;
}

function toggleRegistration() {
  if (document.getElementById('pf_sign_in')) {
    if ( document.getElementById('pf_sign_in').checked ) {
        document.getElementById('login_fields').style.visibility = 'visible';
        document.getElementById('login_fields').style.position   = 'static';
        document.getElementById('registration_fields').style.visibility = 'hidden';
        document.getElementById('registration_fields').style.position   = 'absolute';
        if (signed_in && (signed_in == 1) && document.getElementById('entry_required')) {
          document.getElementById('entry_required').style.visibility = 'visible';
          document.getElementById('entry_required').style.position   = 'static';
        }
    }
    else {
        document.getElementById('registration_fields').style.visibility = 'visible';
        document.getElementById('registration_fields').style.position   = 'static';
        document.getElementById('login_fields').style.visibility = 'hidden';
        document.getElementById('login_fields').style.position   = 'absolute';
        if (signed_in && (signed_in == 1) && document.getElementById('entry_required')) {
          document.getElementById('entry_required').style.visibility = 'hidden';
          document.getElementById('entry_required').style.position   = 'absolute';
        }
    }
  }
}

function noSubmit() {
}

function contestSignIn() {
  var url = 'http://' + window.location.hostname + '/campaign/register';
  var postData = 'action=login&username=' + document.getElementById('login_username').value + 
    '&password=' + document.getElementById('login_password').value;
  if (document.getElementById('signin-progress')) {
    document.getElementById('signin-progress').style.visibility = 'visible';
  }
			
  YAHOO.util.Connect.asyncRequest('POST', url, {
    success: function(next_o) {
      var obj = eval( '(' + next_o.responseText + ')' );
      if (obj.Result.error) {
        alert('Your username/password did not work.  Please try again. \n ' + obj.Result.error);
        document.getElementById('login_username').value = '';
        document.getElementById('login_password').value = '';
      }
      else if(obj.Result.logged_in) {
        
        for (var field in obj.Result) {
          if (field == 'gender') {
            var genderid = 'gender-Male';
            if (obj.Result[field] == 'F') {
              genderid = 'gender-Female';
            }
            if (document.getElementById(genderid)) {
              document.getElementById(genderid).checked = 'true';
            }
          }
          else if ((field == 'locality') && (document.getElementById('locality')) ){
              // city is handled specially if it's part of a city-state set
              document.getElementById('locality').value = obj.Result[field];
          }
          else if ( (field == 'region') && (document.getElementById('region')) ){
              // state is handled specially if it's part of a city-state set
              for (var i=0; i<document.getElementById('region').options.length; i++){
                if (document.getElementById('region').options[i].value == obj.Result[field]) {
                  document.getElementById('region').selectedIndex = i;
                }
              }
          }
          else if (document.getElementById(field)) { 
              document.getElementById(field).value = obj.Result[field];
          }
          else { 
              // this element isn't in the sign-up form.  do nothing.
          }
        }
				if (document.getElementById('entry_required')) {
          document.getElementById('entry_required').style.visibility = 'visible';
          document.getElementById('entry_required').style.position   = 'static'; 
				}
        document.getElementById('login_register_fields').innerHTML = '<p>You are logged in as ' + obj.Result.first_name + ' ' + obj.Result.last_name + '.<br /><a href="http://users.petfinder.com/logout">Log out</a></p>'; 
        signed_in = 1;
      }
      if (document.getElementById('signin-progress')) {
        document.getElementById('signin-progress').style.visibility = 'hidden';
      }
    },
    failure: function(o) {
      alert('an error occurred. we could not sign you in.');
      if (document.getElementById('signin-progress')) {
        document.getElementById('signin-progress').style.visibility = 'visible';
      }
    }
  }, postData);  
}

function votingSignIn(campaignId, categoryId, campaignEntryId, baseUrl) {
  var url = 'http://' + window.location.hostname + '/campaign/register';
  var postData = 'action=login&username=' + document.getElementById('login_username').value + 
    '&password=' + document.getElementById('login_password').value + 
    '&campaign_id=' + campaignId;
  if ( document.getElementById('pf_optin_l') && document.getElementById('pf_optin_l').checked ) {
    postData += '&pf_optin=1';
  }
  if ( document.getElementById('sponsor_optin_l') && document.getElementById('sponsor_optin_l').checked ) {
    postData += '&sponsor_optin=1';
  }
    
  if (document.getElementById('signin-progress')) {
    document.getElementById('signin-progress').style.visibility = 'visible';
  }
			
  YAHOO.util.Connect.asyncRequest('POST', url, {
    success: function(next_o) {
      var obj = eval( '(' + next_o.responseText + ')' );
      if (obj.Result.error) {
        alert('Your username/password did not work.  Please try again. \n ' + obj.Result.error);
        document.getElementById('login_username').value = '';
        document.getElementById('login_password').value = '';
      }
      else if(obj.Result.logged_in) {
        window.opener.galleryVote(campaignId, categoryId, campaignEntryId, baseUrl);
        window.close();
      }
      if (document.getElementById('signin-progress')) {
        document.getElementById('signin-progress').style.visibility = 'hidden';
      }
    },
    failure: function(o) {
      alert('an error occurred. we could not sign you in.');
      if (document.getElementById('signin-progress')) {
        document.getElementById('signin-progress').style.visibility = 'hidden';
      }
    }
  }, postData);  
}

function votingSignUp(campaignId, categoryId, campaignEntryId, baseUrl) {
  var alert_text = '';
  document.getElementById('signup-progress').style.visibility='visible';
	
  var url = 'http://' + window.location.hostname + '/campaign/register';
  var postData = 'action=register&username=' + document.getElementById('pf_username').value + 
    '&password=' + document.getElementById('pf_pass').value +
    '&campaign_id=' + campaignId;
    
  // check to be sure the other parameters exist before adding them to the list of registration fields.
  if (document.getElementById('birth_month')) {
    var elMonth = document.getElementById('birth_month');
    if (elMonth.selectedIndex > 0) {
    postData += '&birth_month=' + elMonth.options[elMonth.selectedIndex].value;
    }
    else {
      alert_text += 'Enter your birth month. ';
    }
  }
  if (document.getElementById('birth_day')) {
    var elDay = document.getElementById('birth_day');
    if (elDay.selectedIndex > 0) {
    postData += '&birth_day=' + elDay.options[elDay.selectedIndex].value;
    }
    else {
      alert_text += 'Enter your birth day. ';
    }
  }
  if (document.getElementById('birth_year')) {
    var elYear = document.getElementById('birth_year');
    if (elYear.selectedIndex > 0) {
      postData += '&birth_year=' + elYear.options[elYear.selectedIndex].value;
    }
    else {
      alert_text += 'Enter your birth year. ';
    }
  }
  if (document.getElementById('pf_username')) {
    if (document.getElementById('pf_username').value.length <= 0) {
      alert_text += 'Enter your username. ';
    }
  }
  if (document.getElementById('pf_pass') && document.getElementById('pf_pass2')) {
    if (document.getElementById('pf_pass').value.length > 0) {
      // check to be sure username and password are the same
      if (document.getElementById('pf_pass').value != document.getElementById('pf_pass2').value) {
        document.getElementById('pf_pass').value = '';
        document.getElementById('pf_pass2').value = ''
        alert_text += 'Your passwords do not match. ';
      }
    }
    else {
      alert_text += 'Enter your password. ';
    }
  }
  if (document.getElementById('email')) {
    if (document.getElementById('email').value.length > 0) {
      postData += '&email=' + document.getElementById('email').value;
    }
    else {
      alert_text += 'Enter your email address. ';
    }
  }
  if ( document.getElementById('pf_optin') && document.getElementById('pf_optin').checked ) {
    postData += '&pf_optin=1';
  }
  if ( document.getElementById('sponsor_optin') && document.getElementById('sponsor_optin').checked ) {
    postData += '&sponsor_optin=1';
  }
    
  document.getElementById('signup-progress').style.visibility = 'visible';
  
  if (alert_text.length > 0) {
    alert('Your entry was not submitted.  Please correct the errors and try again. ' + alert_text);
    return;
  }
			
  YAHOO.util.Connect.asyncRequest('POST', url, {
    success: function(next_o) {
      var obj = eval( '(' + next_o.responseText + ')' );
      if (obj.Result.error) {
        var err = obj.Result.error;
        if (err.indexOf('at /petfinder/www') > 0) {
          err = err.substring(0, err.indexOf('at /petfinder/www'));
        }
        alert(err);
        document.getElementById('signup-progress').style.visibility = 'hidden';
      }
      else if(obj.Result.logged_in) {
        window.opener.galleryVote(campaignId, categoryId, campaignEntryId, baseUrl);
        window.close();
      }
    },
    failure: function(o) {
        alert('an error occurred. we could not sign you up.');
        document.getElementById('signup-progress').style.visibility = 'visible';
        return false;
    }
  }, postData);  
  return false;
}

function contestSignUp() {
  var alert_text = '';
  document.getElementById('signup-progress').style.visibility='visible';
	
  var url = 'http://' + window.location.hostname + '/campaign/register';
  var postData = 'action=register&username=' + document.getElementById('pf_username').value + 
    '&password=' + document.getElementById('pf_pass').value;
    
  // check to be sure the other parameters exist before adding them to the list of registration fields.
  if (document.getElementById('birth_month')) {
    var elMonth = document.getElementById('birth_month');
    if (elMonth.selectedIndex > 0) {
    postData += '&birth_month=' + elMonth.options[elMonth.selectedIndex].value;
    }
    else {
      alert_text += 'Enter your birth month. ';
    }
  }
  if (document.getElementById('birth_day')) {
    var elDay = document.getElementById('birth_day');
    if (elDay.selectedIndex > 0) {
    postData += '&birth_day=' + elDay.options[elDay.selectedIndex].value;
    }
    else {
      alert_text += 'Enter your birth day. ';
    }
  }
  if (document.getElementById('birth_year')) {
    var elYear = document.getElementById('birth_year');
    if (elYear.selectedIndex > 0) {
      postData += '&birth_year=' + elYear.options[elYear.selectedIndex].value;
    }
    else {
      alert_text += 'Enter your birth year. ';
    }
  }
  if (document.getElementById('pf_username')) {
    if (document.getElementById('pf_username').value.length <= 0) {
      alert_text += 'Enter your username. ';
    }
  }
  if (document.getElementById('pf_pass') && document.getElementById('pf_pass2')) {
    if (document.getElementById('pf_pass').value.length > 0) {
      // check to be sure username and password are the same
      if (document.getElementById('pf_pass').value != document.getElementById('pf_pass2').value) {
        document.getElementById('pf_pass').value = '';
        document.getElementById('pf_pass2').value = ''
        alert_text += 'Your passwords do not match. ';
      }
    }
    else {
      alert_text += 'Enter your password. ';
    }
  }
  if (document.getElementById('first_name')) {
    if (document.getElementById('first_name').value.length > 0) {
      postData += '&first_name=' + document.getElementById('first_name').value;
    }
    else {
      alert_text += 'Enter your first name. ';
    }
  }
  if (document.getElementById('last_name')) {
    if (document.getElementById('last_name').value.length > 0) {
      postData += '&last_name=' + document.getElementById('last_name').value;
    }
    else {
      alert_text += 'Enter your last name. ';
    }
  }
  if (document.getElementById('email')) {
    if (document.getElementById('email').value.length > 0) {
      postData += '&email=' + document.getElementById('email').value;
    }
    else {
      alert_text += 'Enter your email address. ';
    }
  }
  if (document.getElementById('gender-Male') && document.getElementById('gender-Female')) {
    var gender = '';
    if (document.getElementById('gender-Male').checked) {
      gender = 'M';
    }
    else if (document.getElementById('gender-Female').checked) {
      gender = 'F';
    }
    else {
      alert_text += 'Select your gender. ';
    }
    postData += '&gender=' + gender;
  }
  if (document.getElementById('street_address')) {
    if (document.getElementById('street_address').value.length > 0) {
      postData += '&street_address=' + document.getElementById('street_address').value;
    }
    else {
      alert_text += 'Enter your street address. ';
    }
  }
  if (document.getElementById('locality') || document.getElementById('city')) {
    var elCity = document.getElementById('city');
    if ( document.getElementById('locality') ) {
      elCity = document.getElementById('locality');
    }
    if (elCity.value.length > 0) {
      postData += '&city=' + elCity.value;
    }
    else {
      alert_text += 'Enter your city. ';
    }
  }
  if (document.getElementById('region') || document.getElementById('state')) {
    var elState = document.getElementById('state');
    if ( document.getElementById('region') ) {
      elState = document.getElementById('region');
    }
    if (elState.selectedIndex > 0) {
      postData += '&state=' + elState.options[elState.selectedIndex].value;
    }
    else {
      alert_text += 'Enter your state. ';
    }
  }
  if (document.getElementById('postal_code')) {
    if (document.getElementById('postal_code').value.length > 0) {
      postData += '&postal_code=' + document.getElementById('postal_code').value;
    }
    else {
      alert_text += 'Enter your zip code. ';
    }
  }
  if (document.getElementById('phone')) {
    if (document.getElementById('phone').value.length > 0) {
      postData += '&phone=' + document.getElementById('phone').value;
    }
    else {
      alert_text += 'Enter your phone number. ';
    }
  }
  if (document.getElementById('pf_optin') && document.getElementById('pf_optin').checked ) {
    postData += '&pf_optin=' + document.getElementById('pf_optin').value;
  }
  document.getElementById('signup-progress').style.visibility = 'visible';
  
  if (alert_text.length > 0) {
    alert('Your entry was not submitted.  Please correct the errors and try again. ' + alert_text);
    return;
  }
			
  YAHOO.util.Connect.asyncRequest('POST', url, {
    success: function(next_o) {
      var obj = eval( '(' + next_o.responseText + ')' );
      if (obj.Result.error) {
        var err = obj.Result.error;
        if (err.indexOf('at /petfinder/www') > 0) {
          err = err.substring(0, err.indexOf('at /petfinder/www'));
        }
        alert(err);
        document.getElementById('signup-progress').style.visibility = 'hidden';
      }
      else if(obj.Result.logged_in) {
        //alert('Your user registration worked.');
			
        // submit form
        document.getElementById('contest').submit();
      }
    },
    failure: function(o) {
        alert('an error occurred. we could not sign you up.');
        document.getElementById('signup-progress').style.visibility = 'visible';
        return false;
    }
  }, postData);  
  return false;
}

// used to fix "enter" in user/pass form fields
function onenter(evt, functionname) {
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if (evt.keyCode == 13)  {eval (functionname + '()'); return false;}
}


// used to display the # of words in a textarea field
function textareaCharCounter(field, counterField, charLimit) {
    if ( ( charLimit - document.getElementById(field).value.length ) < 0) {        
        document.getElementById(field).value = document.getElementById(field).value.substring(0, charLimit);
    }
    document.getElementById(counterField).innerHTML = charLimit - document.getElementById(field).value.length;
}

function submitGalleryVote(loginStatus, campaignId, campaignPath, categoryId, baseUrl) {
  var vote = '';
  for (var i = 0; i < document.vote.finalist_vote.length; i++){
    if (document.vote.finalist_vote[i].checked==true){
      vote = document.vote.finalist_vote[i].value;
      break; //exist for loop, as target acquired.
    }
  }
  if (vote == '') {
    alert('Choose a finalist to vote for and then try again.');
    return false;
  }
  
  if (loginStatus == 'logged_in') {
    // disable so user can't click twice.
    //document.getElementById('vote-progress').style.visibility='visible';
    document.getElementById('votesubmit').disabled = true;
    setTimeout("enableVoteSubmit()", 1000);
    galleryVote(campaignId, categoryId, vote, baseUrl, 1);
    
  }
  else {
    popupRegistration(vote, campaignId, categoryId, vote, campaignPath, baseUrl);
  }
}

function submitPhotoGalleryVote(dummy, campaignId, campaignPath, categoryId, vote, baseUrl) {
	
	// make sure the captcha field isn't empty.
  if (document.getElementById('recaptcha_response_field').value == '') {
		alert('Please check your verification text. Click the refresh button to the right of the verification text field to see additional captchas.');
		return;
	}

	loginStatus = YAHOO.util.Cookie.get('Ticket') ? 'logged_in' : ''; 
  if (loginStatus == 'logged_in') {
    // disable so user can't click twice.
    //document.getElementById('vote-progress').style.visibility='visible';
    document.getElementById('votesubmit').disabled = true;
    setTimeout("enableVoteSubmit()", 1000);
    galleryVote(campaignId, categoryId, vote, baseUrl, 1);
    
  }
  else {
    popupRegistration(vote, campaignId, categoryId, vote, campaignPath, baseUrl);
  }
}

function enableVoteSubmit() {
  document.getElementById('votesubmit').disabled = false;
}

function popupRegistration(vote, campaignId, categoryId, campaignEntryId, campaignPath, baseUrl) {
  //var url = baseUrl + campaignPath + '/vote-popup?vote=' + vote + '&campaign_id=' + campaignId + '&category_id=' + categoryId;
	var url = baseUrl + 'campaign/vote-popup?vote=' + vote + '&campaign_id=' + campaignId + '&category_id=' + categoryId;
  var newwin = window.open(url,'ShareWindow','top=150,left=150,width=590,height=420,scrollbars=yes,resize=yes');
  newwin.focus();
}

function galleryVote(campaignId, categoryId, campaignEntryId, baseUrl) {
  var url = baseUrl + 'campaign/vote';
  var postData = 'format=json&campaign_id=' + campaignId + '&category_id=' + categoryId + '&campaign_entry_id=' + campaignEntryId + '&vote=1';
	
	// add captcha request stuff
	if (document.getElementById('recaptcha_challenge_field') && document.getElementById('recaptcha_response_field') ) {
		postData += '&recaptcha_challenge_field=' + document.getElementById('recaptcha_challenge_field').value + '&recaptcha_response_field=' + document.getElementById('recaptcha_response_field').value;
	}
	
  YAHOO.util.Connect.asyncRequest('POST', url, {
    success: function(next_o) {
      var obj = eval( '(' + next_o.responseText + ')' );
			var err_msg = '';
      if (obj.errors) {
				for (err in obj.errors) {
					err_msg += obj.errors[err] + ' ';
				}
			}
			if (err_msg != '') {
				if ( (err_msg == 'ticket has expired ') || (err_msg == 'ticket mismatch ') ) { 
			    popupRegistration(campaignEntryId, campaignId, categoryId, campaignEntryId, '', baseUrl);
				}
				else {
          alert(err_msg);
				}
			}
				/*
				if (obj.errors.vote) {
					alert(obj.errors.vote);
				}
				else if (obj.errors.user_system) {
					alert(obj.errors.user_system);
				}
				else {
          alert('Your vote did not work.  Please try again. \n ' + obj.errors);
				}
				*/
      else if(obj.success) {
        // update vote and display all vote totals
        document.getElementById('vote-' + campaignEntryId).innerHTML = (parseInt(document.getElementById('vote-' + campaignEntryId).innerHTML) + 1) + ' ';
				
				// update one vote total
				if (obj.vote && obj.vote.results && document.getElementById('vote-' + campaignEntryId)) {
				  var vote_total = obj.vote.results;
				  document.getElementById('vote-' + campaignEntryId).innerHTML = vote_total;
				}
				
        var elements = YAHOO.util.Dom.getElementsByClassName('vote-total', 'span');
        for( var e in elements ) {
          elements[e].style.visibility='visible';
          elements[e].style.position='static';
        }
        
        // update voting & total elements
        var el = document.getElementById('vote-button');
        if (el) {
          el.style.visibility = 'hidden';
          el.style.position   = 'absolute';
        }
        el = document.getElementById('vote-thanks');
        if (el) {
          el.style.visibility = 'hidden';
          el.style.position   = 'absolute';
        }
        el = document.getElementById('vote-recaptcha');
        if (el) {
          el.style.visibility='hidden';
          el.style.position='absolute';
        }
       
        el = document.getElementById('votesubmit');
        if (el) {
          el.style.visibility='hidden';
          el.style.position='absolute';
        }
        el = document.getElementById('voting-results');
        if (el) {
          el.style.visibility='visible';
          el.style.position='static';
        }
        /*
        if (document.getElementById('vote-progress')) {
          document.getElementById('vote-progress').style.visibility='hidden';
        }
        if (obj.voting && obj.voting.entries) {
          for (var prop in obj.voting.entries) {
            if (document.getElementById(prop + " Votes")) {
              if (obj.voting.entries[prop] > 1) {
                document.getElementById(prop + " Votes").innerHTML = obj.voting.entries[prop] + " Entries";
              }
              else {
                document.getElementById(prop + " Votes").innerHTML = obj.voting.entries[prop] + " Entry";
              }
            }
          }
        }
        */
      }
			else {
				alert('Please check your verification text. Click the refresh button to the right of the verification text field to see additional captchas.');
			}
    },
    failure: function(o) {
      alert('an error occurred. we could not sign you in.');
      if (document.getElementById('signin-progress')) {
        document.getElementById('signin-progress').style.visibility = 'hidden';
      }
			/*
      if (document.getElementById('vote-progress')) {
        document.getElementById('vote-progress').style.visibility='hidden';
      }
			*/
    }
  }, postData);  

}

function playSlideshow(url, entryIndex, offset, limit, totalRecords) {
  var postData = 'slideshow=1&entry_index=' + entryIndex + '&offset=' + offset + '&limit=' + limit;

  YAHOO.util.Connect.asyncRequest('POST', url, {
    success: function(next_o) {
      document.getElementById('gallery_content_box').innerHTML = next_o.responseText;
      entryIndex++;
      if (entryIndex >= limit) {
        entryIndex = 0;
        offset = offset + limit;
      }
      if ( (offset + entryIndex) >= totalRecords ) {
        entryIndex = 0;
        offset = 0;
      }
      setTimeout ( "playSlideshow('" + url + "', " + entryIndex + ", " + offset + ", " + limit + ", " + totalRecords + ")", 5000 );
    },
    failure: function(o) {
      //alert('an error occurred. we cannot play the slideshow.');
    }
  }, postData);  

}

