/* -----------------------------------------------------------
/* ------------------------- cLone ----------------------------
*/
function Popn_form(element) {
  var self = this;
  this.root = element;  
  this.ajaxed = null;
  this.url = '/contact/refer';
  this.jaxer = $('#jax_content');
  this.form_title = 'Email this Page to a Friend';
  this.boxer = {
    xer : 550,
    yer : 550
  }
  this.filter_response = function(html) {
    var tempHtml = $(html).find('#errorExplanation');
    self.ajaxed.find('#errorExplanation').remove();
    if (tempHtml.hasClass('errorExplanation')) {
      self.ajaxed.prepend(tempHtml);
    }
    else {
      self.ajaxed.html("<h3> Success </h3>");
      self.ajaxed.fadeOut(500, function() {self.ajaxed.dialog('close')});
    }
  }
  
  this.send_data = function() {
    $.ajax({
      url: self.url,
      type: "POST",
      data: self.ajaxed.serialize(),
      async: false,
      success: self.filter_response
    });
  }
  
  this.mybuttons = {
    send: self.send_data
  }
  
  this.create_form = function(html) {
    if ($(html).is('form')) {
      self.jaxer.append($(html));
    } else {
      self.jaxer.append($(html).find('form:last'));
    }
    self.ajaxed = self.jaxer.children(':last').addClass('deskman');
    self.ajaxed.find('input[type=submit]').remove();
    self.ajaxed.dialog({
      modal: true,
      title: self.form_title,
      height: self.boxer.yer,
      width: self.boxer.xer,
      resizable: true,
      buttons: self.mybuttons,
      close: function() {
        self.root.bind('click', self.openForm);
        self.ajaxed.dialog('destory').remove();
      }
    });
  }
  this.openForm = function(e) {
    e.preventDefault();
    self.root.unbind('click', self.openForm);
    $.ajax({
      url: self.url,
      async: false,
      success: self.create_form
    });
  }	
  this.root.bind('click', self.openForm);
}
