
//textarea text
  var textareaText;

/* functions begin */

  function GetParentHashVars() {
    var query, qs = self.parent.location.hash.substring(1);
    var queries = qs.split(/\&/);
    for (var i=0; i<queries.length; i++) {
      query = queries[i].split(/\=/);
      this[query[0]] = (typeof query[1] == 'undefined') ? null : unescape(query[1]).replace(/\+/g," ");
    }
  }

    function no() {
      $('#yesnoInput').val('no');
      $('#no').slideDown();
      $('#buttons').slideUp();
      return false;
    }

    function yes() {
      $('#yesnoInput').val('yes');
      send();
      return false;
    }

    function somethingElse() {
      $('#textareaContainer').slideDown('fast').find('textarea').focus();
    }

    function reset() {

      $('#textareaContainer').slideUp('fast').find('textarea').text(textareaText);
      $('#no').slideUp();
      $('#buttons').slideDown();
      $('input').removeAttr('checked');
      return false; //prevent default action from input or anchor
    }


    function send() {
      if(typeof self.parent._hbLink =='function')
        self.parent._hbLink("Download Survey - Sent");
      $('form#dlsurveyForm').submit();
    }


    function close() {
      //self.parent.location.hash ='';
      self.parent.tb_remove();
    }

    function ie6Hovers () {
       $('#no p.option')
       .mouseon( function(){
          $(this).addClass('hover');
        })
        .mouseout( function(){
          $(this).removeClass('hover');
      });
    }

    function initDownloadSurveyUI(target, dltext) {
    //save the description text to memory for recovery upon reset
    textAreaText =   $('#textareaContainer textarea').text();

    //set defaults and do alerts
      if(dltext === undefined)
        dltext = '';
      if(target === undefined) {
        alert('download target not defined');
      }
      
      
      //pass target & target text to form
      $('#dltarget').val(target);
      $('#dltext').text(' '+unescape(dltext));

      //bind actions to links and buttons
      $('#yesBtn').click(yes);
      $('#noBtn').click(no);
      $('#no4').click(somethingElse);
      $('#resetBtn').click(reset);
      $('#yesBtn,#sendBtn').click(send);
      $('.close').click(close);
      $('#textareaContainer textarea')
        .focus( function() {
        //not working for some reason
//           if($(this).text() == '')
//             $(this).text(textareaText);
            
        $(this).addClass('focus').select(); //higlight
        })
        .blur(function() {
          $(this).removeClass('focus');
        });
        

      $('#no p.option').click( function(){
          $('p.selected').removeClass('selected');
          var smt = $(this).find('#no4');
          if(smt.length < 1)
            $('#textareaContainer').slideUp('fast');
            $(this).addClass('selected').find('input.radio:first').click();
      });

      if(typeof self.parent._hbLink == 'function')
        self.parent._hbLink("Download Survey - Viewed");
    }

/* functions end */

/* globals & onload */

    //global GET-vars in an object.
    var gets = new GetParentHashVars();
     //onload
    $(function(){
                initDownloadSurveyUI(gets.dltarget,gets.dltext);
    });
    

