﻿
var m_slider = '';
var m_TimeOutSlider = '';

Event.observe(window, 'load', function (event) {

    var slider = new MOSlider($('slider'));
    m_slider = slider;
    m_TimeOutSlider = setTimeout("FeatureSlideShow()", 5000);

    $('emailInput').value = '';
    setWatermark('emailInput', 'emailInputLabel', 'DC_NLlabel_Focus', 'DC_NLlabel');
});



function FeatureSlideShow() {


    if (m_slider.n == 3) {
        m_slider.n = -1;
    }
    m_slider.next();
    

    $$('div.DC_SlideBtns_Selected').each(function (e) {
        e.className = 'DC_SlideBtns';
    });

    $('btn_' + m_slider.n ).className = 'DC_SlideBtns_Selected';


    clearTimeout(m_TimeOutSlider);
    m_TimeOutSlider = setTimeout("FeatureSlideShow()", 5000);

}


function changeImage(slideNumber) {

    clearTimeout(m_TimeOutSlider);
    m_slider.n = slideNumber;
     FeatureSlideShow();

 }



 function saveEmailAddress() {
     
     if ($F('emailInput') == '') {
         alert('Please enter email address ');
     }
     else if (!validateEmail($F('emailInput'))) {
         alert('Please enter a valid email address');
     }
     else {
         var a = new Ajax.Request('/saveEmailAddress.ashx', {
             method: 'get',
             parameters: '&email=' + $F('emailInput'),
             onSuccess: function (transport) {
                 var response = transport.responseText || "no response text";
                 $('emailInput').value = '';
                 $('emailInput').focus();
                 setWatermark('emailInput', 'emailInputLabel', 'DC_NLlabel_Focus', 'DC_NLlabel');
                 alert("Thank you for signing up");


             },
             onFailure: function () {

                 $('emailInput').value = '';
                 setWatermark('emailInput', 'emailInputLabel', 'DC_NLlabel_Focus', 'DC_NLlabel');
                 alert('Something went wrong, please try again');

             }
         });
     }
 }


 function validateEmail(elementValue) {
     var emailPattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
     return emailPattern.test(elementValue);
 }  


 function setWatermark(input, label, focusClass, blurClass) {
     if ($(input) != null && $(label) != null) {
         var objInput = $(input);
         var objLabel = $(label);

         objInput.stopObserving('blur');
         objInput.observe('blur', function (event) {
             if ($F(input) == '') {
                 objLabel.className = blurClass;
                 objLabel.show();
             }
         });

         objInput.stopObserving('focus');
         objInput.observe('focus', function (event) {
             objLabel.className = focusClass;
         });

         objInput.stopObserving('keydown');
         objInput.observe('keydown', function (event) {
             objLabel.hide();
         });
     }
 }


 function submitButton(e, but) {

     var characterCode;
     if (!e)
         e = window.event;
     if (e && e.which) {
         e = e;
         characterCode = e.which;
     }
     else {
         e = event;
         characterCode = e.keyCode;
     }

     if (characterCode == 13) {

         if (navigator.appName == "Microsoft Internet Explorer") {
             if (but != null) {
                 try {
                     but.onclick();
                 } catch (e) { if (e.name == "TypeError") eval(but.onclick); }
             }
         }
         else {
             if (but != null) {
                 if (but.value == undefined) {

                     but.onclick();
                 }
                 else {

                     but.click();
                 }
             }

         }


         return false;
     }
     else {
         return true;
     }

 }


  function new_win() {
      var width = 800;
      var height = 600;
      var left = (screen.width - width) / 2;
      var top = (screen.height - height) / 2;
      var params = 'width=' + width + ', height=' + height;
      params += ', top=' + top + ', left=' + left;
      params += ', directories=no';
      params += ', location=no';
      params += ', menubar=no';
      params += ', resizable=no';
      params += ', scrollbars=yes';
      params += ', status=no';
      params += ', toolbar=no';
      newwin = window.open("https://docs.google.com/spreadsheet/viewform?formkey=dFpWd1Itai1nVEZxTkJBdkZBbFhKWnc6MQ&ifq", 'popup', params);
      if (window.focus) {
          newwin.focus()
      }
      return false;
  }


