// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var s1 = 5;
var s2 = 5;
var s3 = 5;
var s4 = 5;
$(document).ready(function(){
  $('#survey').mouseover(function(){
    $('#evaluation_instructions b').
      html('Move the sliders below to indicate how strongly you agree')
  });
  $('#slider1').Slider({

    accept : '#indicator1',

    onSlide : function( cordx, cordy, x, y){
      document.getElementById('survey_cordy1').value= Math.round(x/23);
    },

    onChange: function( cordx, cordy, x, y){
      s1 = Math.round(x/23);
      document.getElementById('survey_cordy1').value = s1
    },

    onClick: function() {
      alert('onClick');
    }
  });

  $('#slider2').Slider({

    accept : '#indicator2',

    onSlide : function( cordx, cordy, x, y){
      document.getElementById('survey_cordy2').value= Math.round(x/23);
    },

    onChange: function( cordx, cordy, x, y){
      s2 = Math.round(x/23);
      document.getElementById('survey_cordy2').value = s2;
    }
  });

  $('#slider3').Slider({

    accept : '#indicator3',

    onSlide : function( cordx, cordy, x, y){
      document.getElementById('survey_cordy3').value= Math.round(x/23);
    },

    onChange: function( cordx, cordy, x, y){
      s3 = Math.round(x/23);
      document.getElementById('survey_cordy3').value = s3;
    }
  });

  $('#slider4').Slider({

    accept : '#indicator4',

    onSlide : function( cordx, cordy, x, y){
      document.getElementById('survey_cordy4').value= Math.round(x/23);
    },

    onChange: function( cordx, cordy, x, y){
      s4 = Math.round(x/23);
      document.getElementById('survey_cordy4').value = s4;
    }
  });

  $(function(){
    var text_res = '';
    $('#survey').submit( function() {
      if (s1 > 4) {
        text_res = "<p><b>Stop Email overload:</b> qE uses the Web 2.0 concept of blogs and comments. Blogs have an intrinsic filing method and can be searched. Unique bookmark alerts meant that you will never miss communications on topics that you are interested in. Easy! </p>"
      };
      if (s2 > 4) {
        text_res += "<p><b>Simplify CRM:</b> qE makes CRM easy and let's your sales people get on with their real work. Oh, and qEnterprise CRM also costs a fraction of the price of traditional CRM.</p> "
      };
      if (s3 > 4) {
        text_res += "<p><b>UGC Intranet:</b> Intranets are hard to maintain and keep up to date. qE makes your intranet dynamic by enabling User Generated Content and other Web 2.0 techniques such as tags.</p> "
      };
      if (s4 > 4) {
        text_res += "<p><b>Project tools:</b> Without good communications and collaboration, even the best project is doomed. qE brings simple and effective collaboration to your projects. Let IT work for you, not you for IT.</p> "
      };
      if ( (s1 < 5) && (s2 < 5) && (s3 < 5) && (s4 < 5) ) {
        text_res = "<b>Congratulations!</b> <br/><br/> Your enterprise IT is in good shape!  <br/><br/> You must already use qEnterprise ;-)"
      };

      $(this).fadeOut('slow', function() {
        $(this).html(text_res).fadeIn('slow');
        $("<p class='survey_again'><a href='/'>Try again</a></p>")
         .filter(".survey_again").click(function() {
         }).end().appendTo("#survey");
        $("<p class='contact'>Contact</p>")
         .filter(".contact").click(function() {
	    $('#side_content').load('/customer_contacts/new');
         }).end().appendTo("#survey");
      });

      return false;
    });
  });

 });
