// JavaScript Document
var ChanelContact = new Class({
    Extends: Popup,
    initialize: function(adoptElement){
        this.parent({'title': 'Chanel Contact', 'width': 455, height: 200, 'adoptElement': adoptElement});
    },
    
    createPopup: function() {
      this.parent();
      $('cc-submit').addEvent('click', function() {
        this.validateAndSend();
      }.bindWithEvent(this));
    },
    
    validateAndSend: function() {
      var valid = true;
      var fields = [$('cc-telephone'), $('cc-email')];
      fields.each(function(item) {
        item.removeClass('invalid');
        if (item.get('value') == '') {
          valid = false;
          item.addClass('invalid');
        }
      });
      if (!valid) {
        return;
      }
      var jSonRequest = new Request.JSON({url: 'sendChanelContact.php', onComplete: function() {
        $('chanelContactForm').set('html', '<p>Thank you for submitting your contact form, we\'ll get back to you as soon as possible.</p>');
      }}).post({'query': {'chanelprodid': $('chanelprodid').value, 'name': $('cc-name').value, 'email': $('cc-email').value, 'cust_telephone': $('cc-telephone').value, 'chanelprodname': $('chanelprodname').value}});
    }
});

var chanelContactPopup;

function setupChanelContactForm() {
	if ($defined($('chanelContactForm'))) {
		chanelContactPopup = new ChanelContact($('chanelContactForm'));
	}
	
	if ($defined($('aChanelContact'))) {
		 $('aChanelContact').addEvent('click', function() {
		 	  chanelContactPopup.show();
			  return false;
		  });
	 }
}

window.addEvent('domready', function() {
	setupChanelContactForm();
});
