var olContribForm = "";
function olcontribDoAjax(theForm)
{
  var thevals = "";
  var passed = true;
  
  $(theForm + " input").each(function()
  {
      thevals += this.value;
      if(passed && this.value == "" && $(this).is(".required"))
      {
        alert("Please enter required item ");
        this.focus();
        passed = false;
      }
  });
  if(!passed)
  {
    return(false);
  }
  $(theForm).ajaxSubmit(function(req){
    alert("Back from ajax call");
    $(theForm).attr("action", "https://www.paypal.com/cgi-bin/webscr");
    document[$(theForm).attr("name")].submit();
  }); 

  return(false);
}

Drupal.behaviors.olpetition = function() {

  try {
      $('.cluetip-title').cluetip({
      splitTitle: '|', // use the invoking element's title attribute to populate the clueTip...
      // ...and split the contents into separate divs where there is a "|"
      showTitle: false, // hide the clueTip's heading
      cluetipClass: 'aktnow',
      arrows: true,
      hoverIntent: {
      sensitivity: 3,
      interval: 200,
      timeout: 0
    },

    fx: {
    open: 'fadeIn',
    openSpeed: ''
    }
  });

  $('.cluetip-campaign').cluetip({
    showTitle: true, // hide the clueTip's heading
    cluetipClass: 'aktnow',
    arrows: true,
    hoverIntent: {
      sensitivity: 3,
      interval: 200,
      timeout: 0
    },

    fx: {
      open: 'fadeIn',
      openSpeed: ''
    }
  });

  $('.olPopup').cluetip({
    showTitle: true,
    cluetipClass: 'aktnow',
    activation: 'click',
    sticky: true,
    closePosition: 'title',
    arrows: true
  });

    $('.petCommentTrunc').cluetip({
      splitTitle: '|', 
      showTitle: false, // hide the clueTip's heading
      cluetipClass: 'aktnow2',
      arrows: true,
      hoverIntent: {    
                     sensitivity:  3,
                     interval:     200,
                     timeout:      0
      }, 
          
      fx: {             
            open:       'fadeIn',
            openSpeed:  ''
      }
    });

    $('.petSig').cluetip({
      splitTitle: '|', 
      showTitle: false, // hide the clueTip's heading
      cluetipClass: 'aktnow2',
      arrows: true,
      hoverIntent: {    
                     sensitivity:  3,
                     interval:     200,
                     timeout:      0
      }, 
          
      fx: {             
            open:       'fadeIn',
            openSpeed:  ''
      }
    });
  }
  catch (e){
    //alert(e);
  }

  $('div#tabs-petsig-1 .pager li a')
  .unbind()
  .bind('click', function(){
      try {
      theIDParts = this.id.split('_')
      nid = theIDParts[1];
      pageNum = theIDParts[2];
      theURL = '/petition/' + nid + '/comments/ajax?page=' + pageNum;
      //theURL = Drupal.settings.basePath ? Drupal.settings.basePath + "/" + theURL : theURL;
      $.get(theURL, null, petCommentsPager);
      return false;
    }
    catch (e) {
      alert(e);
    }
  });

  $('div#tabs-petsig-2 .pager li a')
  .unbind()
  .bind('click', function(){
      try {
      theIDParts = this.id.split('_')
      nid = theIDParts[1];
      pageNum = theIDParts[2];
      theURL = '/petition/' + nid + '/signatures/ajax?page=' + pageNum;
      //theURL = Drupal.settings.basePath ? Drupal.settings.basePath + "/" + theURL : theURL;
      $.get(theURL, null, petSigsPager);
      return false;
    }
    catch (e) {
      alert(e);
    }
  });
// Node form tooltip  
  $(".taxonomy-super-select-radios .state_fieldset").hide();
	$('#edit-state').click(function() {
		$(".taxonomy-super-select-radios .state_fieldset").toggle();
	});
  
  
	/*petition js*/	  
  $(function () {	
	$('.page-node-add-olcampaign-petition #tabs-olcampaign #olcampaign-tab-1 #edit-title').watermark('Give your petition a name.');
	});
	$(function () {	
	$('.page-node-add-olcampaign-petition #tabs-olcampaign #olcampaign-tab-1 #edit-petition-description').watermark('Tell people what your petition is all about and what you want them to help you accomplish.');
	});	
	$(function () {	
	$('.page-node-add-olcampaign-petition #tabs-olcampaign #olcampaign-tab-1 #edit-body').watermark('Enter the text of your petition.');
	});
	/*cta js*/	
$(function () {		
	$('.page-node-add-olcampaign-cta #tabs-olcampaign #edit-title').watermark('Enter the title of this fax campaign.');
	});
	$(function () {	
	$('.page-node-add-olcampaign-cta #tabs-olcampaign #olcampaign-tab-1 #edit-body-wrapper #edit-body').watermark('Explain the issue to your supporters and let them know why they need to get involved and fax their elected officials.');
	});
	$(function () {	
	$('.page-node-add-olcampaign-cta #tabs-olcampaign #edit-message-body').watermark('Enter some suggested talking points that people can use when creating their message. Be sure to separate each paragraph with a blank line.');
	});
	
	/*poll js*/	
	$(function () {	
	$('.page-node-add-olcampaign-poll #tabs-olcampaign #edit-title').watermark('Click here and enter your poll question');
	});
	$(function () {	
	$('.page-node-add-olcampaign-poll #tabs-olcampaign #olcampaign-tab-1 #edit-body').watermark('Give users some background about the subject of your poll and why they should give their opinion');
	});
	//$('#page-node-add-olcampaign-poll #tabs-olcampaign #poll-choices #edit-choice-0-chtext-wrapper').watermark('List the possible responses to your poll question.');
 
	/*pledge js*/	
	$(function () {	 
	$('.page-node-add-olcampaign-pledge #tabs-olcampaign #olcampaign-tab-1 #edit-title').watermark('Give your pledge a name.');
	});
	$(function () {	
	$('.page-node-add-olcampaign-pledge #tabs-olcampaign #olcampaign-tab-1 #edit-petition-description').watermark('Tell people what your pledge is all about and what you want them to help you accomplish.');
	});
	$(function () {	
	$('.page-node-add-olcampaign-pledge #tabs-olcampaign #olcampaign-tab-1 #edit-body').watermark('Enter the text of your pledge.');
	});
	
	 /*olcampaign js*/	
	$(function () {		 
	$('.page-node-add-olcampaign #tabs-olcampaign #olcampaign-tab-1 #edit-title').watermark('Give your campaign a name.');
	});
	$(function () {	
	$('.page-node-add-olcampaign #tabs-olcampaign #olcampaign-tab-1 #edit-petition-description').watermark('Enter the content for your campaign. Also be sure to tell people what it\'s about and why they should participate.');
	});
	$(function () {		
	$('.page-node-add-olcampaign #tabs-olcampaign #olcampaign-tab-1 #edit-body').watermark('Tell people what your campaign is all about and what you want them to help you accomplish.');
	});
	 
	
	/*boycott js*/
	$(function () {	
	$('.page-node-add-olcampaign-boycott #tabs-olcampaign #olcampaign-tab-1 #edit-title').watermark('Give your boycott a name.');
	});
	$(function () {
	$('.page-node-add-olcampaign-boycott #tabs-olcampaign #olcampaign-tab-1 #edit-petition-description').watermark('Tell people what your boycott is all about and what you want them to help you accomplish.');
	});
	$(function () {
	$('.page-node-add-olcampaign-boycott #tabs-olcampaign #olcampaign-tab-1 #edit-body').watermark('Enter the text of your boycott.');
	}); 
	 
	/* Requirment fields seleted by default on wizard page step 2*/
 $(".page-node-add-olcampaign-pledge #edit-taxonomy-16").val(4172);
 $(".page-node-add-olcampaign-cta #edit-taxonomy-16").val(4172);
 $(".page-node-add-olcampaign-petition #edit-taxonomy-16").val(4172);
 $(".page-node-add-olcampaign-boycott #edit-taxonomy-16").val(4172);
 $(".page-node-add-olcampaign-poll #edit-taxonomy-16").val(4172);
 $(".page-node-add-olcampaign #edit-taxonomy-16").val(4172);
 
  // SEARCH box water mark
  var cssObj = {
      'color' : '#9f978d',
      'font-weight' : 'bold',
      'font-size' : '12px'
    }
  $('#edit-search-block-form-1').focus(function(){	
    if ($(this).val() == ' SEARCH') {
      $(this).val('').css('color', '#CDD8E0');			
      $(this).val('').css('font-weight', 'normal');
      $(this).val('').css('font-size', '13px');
    }				
  });
  $('#edit-search-block-form-1').blur(function(){
    if($(this).val() == ''){
      $(this).val(' SEARCH').css(cssObj);
    }
  });

  $('#edit-search-block-form-1').val(' SEARCH').css(cssObj);
  $('#edit-search-block-form-1-wrapper #edit-submit').click(function(){
    if ($('#edit-search-block-form-1').val() == ' SEARCH') {
      return false;
    }		
  });
  
  
   // SEARCH box water mark
  var cssObj = {
      'color' : '#9f978d',
      'font-weight' : 'bold',
      'font-size' : '12px'
    }
  $('#edit-submitted-your-name').focus(function(){	
    if ($(this).val() == ' Your Name') {
      $(this).val('').css('color', '#CDD8E0');			
      $(this).val('').css('font-weight', 'normal');
      $(this).val('').css('font-size', '13px');
    }				
  });
  $('#edit-submitted-your-name').blur(function(){
    if($(this).val() == ''){
      $(this).val(' Your Name').css(cssObj);
    }
  });

  $('#edit-submitted-your-name').val(' Your Name').css(cssObj);
  $('#edit-submitted-your-name-wrapper #edit-submit').click(function(){
    if ($('#edit-submitted-your-name').val() == '') {
      return false;
    }		
  });
    // front buttom box water mark
  var cssObj = {
      'color' : '#9f978d',
      'font-weight' : 'bold',
      'font-size' : '12px'
    }
  $('#edit-submitted-your-email').focus(function(){	
    if ($(this).val() == ' Your Email') {
      $(this).val('').css('color', '#CDD8E0');			
      $(this).val('').css('font-weight', 'normal');
      $(this).val('').css('font-size', '13px');
    }				
  });
  $('#edit-submitted-your-email').blur(function(){
    if($(this).val() == ''){
      $(this).val(' Your Email').css(cssObj);
    }
  });

  $('#edit-submitted-your-email').val(' Your Email').css(cssObj);
  $('#edit-submitted-your-email-wrapper #edit-submit').click(function(){
    if ($('#edit-submitted-your-email').val() == '') {
      return false;
    }		
  });  
}

var petCommentsPager = function(data) {
  $('div#tabs-petsig-1').html(data);
  Drupal.behaviors.olpetition();
}

var petSigsPager = function(data) {
  $('div#tabs-petsig-2').html(data);
  Drupal.behaviors.olpetition();
}
