function SendEmail()
{
  if(sendFromText != $("#tbSendFrom").val())
  {
    if(Page_ClientValidate())
    {
      $.ajax({
               type: "POST",
               url: "http://www.ellesse.com/SendEmailForm.aspx/SendUserMail",
               contentType: "application/json; charset=utf-8",
               dataType: "json",
               data: "{'sendTo':" + $.quoteString($("#tbSendTo").val()) + ",'sendFrom':" + $.quoteString($("#tbSendFrom").val()) + ",'subject':" + $.quoteString($("#subjectContainer").val()) + ",'url':" + $.quoteString($("#urlContainer").val()) + ",'customText':" + $.quoteString($("#tbCustomText").val())+ ",'footerText':" + $.quoteString($("#tbFooterText").val())+"}",
               success: function(msg){
                 if(msg.d)
                 {
                   $("#mailData").hide();
                   $("#ok").show();
                 }
                 else
                 {
                   $("#mailData").hide();
                   $("#error").show();
                 }
               }
             });
    }
  }
  else
  {
     $("#validator").show();
     Page_ClientValidate();
  }
}
function hidediv(ids)
{
  for(var id in ids)
  {

    if (document.getElementById(ids[id]))
    {
      document.getElementById(ids[id]).style.display = 'none';
    }
  }
}

function showdiv(ids)
{
  for(var id in ids)
  {
    if (document.getElementById(ids[id]))
    {
      document.getElementById(ids[id]).style.display = 'block';
    }
  }
}
function SetDefaultTexts(){
	var sendTo='';
	var sendFrom='';
	if (sendToText === '') {
    sendToText = $("#tbSendTo").val()
  }
	jQuery('#tbSendTo').focus(function(){
		sendTo = jQuery(this).val();
		if ((sendTo == sendToText))
		{
			jQuery(this).val('');
		}
	});
	jQuery('#tbSendTo').blur(function(){
		var input = jQuery(this).val();
		if (input == '')
		{
			jQuery(this).val(sendToText);
		}
	});

  if (sendFromText === '') {
    sendFromText = $("#tbSendFrom").val()
  }
	jQuery('#tbSendFrom').focus(function(){
		sendFrom = jQuery(this).val();
		if ((sendFrom == sendFromText))
		{
			jQuery(this).val('');
		}
	});
	jQuery('#tbSendFrom').blur(function(){
		var input = jQuery(this).val();
		if (input == '')
		{
			jQuery(this).val(sendFromText);
		}
		if(sendFromText != $("#tbSendFrom").val())
		{
		   $("#validator").hide();
		}
	});
}

/*
 * Facebox (for jQuery)
 * version: 1.2 (05/05/2008)
 * @requires jQuery v1.2 or later
 *
 * Examples at http://famspam.com/facebox/
 *
 * Licensed under the MIT:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
 *
 * Usage:
 *
 *  jQuery(document).ready(function() {
 *    jQuery('a[rel*=facebox]').facebox()
 *  })
 *
 *  <a href="#terms" rel="facebox">Terms</a>
 *    Loads the #terms div in the box
 *
 *  <a href="terms.html" rel="facebox">Terms</a>
 *    Loads the terms.html page in the box
 *
 *  <a href="terms.png" rel="facebox">Terms</a>
 *    Loads the terms.png image in the box
 *
 *
 *  You can also use it programmatically:
 *
 *    jQuery.facebox('some html')
 *
 *  The above will open a facebox with "some html" as the content.
 *
 *    jQuery.facebox(function($) {
 *      $.get('blah.html', function(data) { $.facebox(data) })
 *    })
 *
 *  The above will show a loading screen before the passed function is called,
 *  allowing for a better ajaxy experience.
 *
 *  The facebox function can also display an ajax page or image:
 *
 *    jQuery.facebox({ ajax: 'remote.html' })
 *    jQuery.facebox({ image: 'dude.jpg' })
 *
 *  Want to close the facebox?  Trigger the 'close.facebox' document event:
 *
 *    jQuery(document).trigger('close.facebox')
 *
 *  Facebox also has a bunch of other hooks:
 *
 *    loading.facebox
 *    beforeReveal.facebox
 *    reveal.facebox (aliased as 'afterReveal.facebox')
 *    init.facebox
 *
 *  Simply bind a function to any of these hooks:
 *
 *   $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
 *
 */
(function($) {
  $.faceboxMail = function(data, klass) {
    $.faceboxMail.loading()

    if (data.ajax) fillfaceboxMailFromAjax(data.ajax)
    else if (data.image) fillfaceboxMailFromImage(data.image)
    else if (data.div) fillfaceboxMailFromHref(data.div)
    else if ($.isFunction(data)) data.call($)
    else $.faceboxMail.reveal(data, klass);
  }
  /*
   * Public, $.faceboxMail methods
   */

  $.extend($.faceboxMail, {
    settings: {
      opacity      : 0.8,
      overlay      : true,
      loadingImage : '/sitecore/shell/themes/Standard/Images/loading.gif',
      closeImage   : '/sitecore/shell/themes/Standard/Images/closelabel.gif',
      imageTypes   : [ 'png', 'jpg', 'jpeg', 'gif' ],
      faceboxMailHtml  : '\
    <div id="faceboxMail" style="display:none;"> \
      <div class="popup"> \
	<div class="body"> \
		<div class="head"> \
                  <a href="#" class="close"><span id="fbclosebtn">Close</span></a> \
		  <h1 id="faceboxMail-title"><span id="fbtMail">&#160;</span></h1>\
                </div> \
                <div class="content"> \
                </div> \
        </div>\
      </div> \
    </div>'
    },

    loading: function() {
      init()
      if ($('#faceboxMail .loading').length == 1) return true
      showOverlay()
      $('#faceboxMail .content').empty()
      $('#faceboxMail .body').children().hide().end().
        append('<div class="loading"><img src="'+$.faceboxMail.settings.loadingImage+'"/></div>')
      $('#faceboxMail').css({
        top:	getPageScroll()[1] + (getPageHeight() / 10),
        left:	(($(window).width()/2) - 193)
      }).show()

      $(document).bind('keydown.faceboxMail', function(e) {
        if (e.keyCode == 27) $.faceboxMail.close()
        return true
      })
      $(document).trigger('loading.faceboxMail')
    },

    reveal: function(data, klass) {
      $(document).trigger('beforeReveal.faceboxMail')
      if (klass) $('#faceboxMail .content').addClass(klass)
      $('#faceboxMail .content').append(data)
      $('#faceboxMail .loading').remove()
      $('#faceboxMail .body').children().fadeIn('normal')
      $('#faceboxMail').css('left', $(window).width() / 2 - ($('#faceboxMail .body').width() / 2))
      $(document).trigger('reveal.faceboxMail').trigger('afterReveal.faceboxMail')
    },

    close: function() {
      $(document).trigger('close.faceboxMail')
      return false
    }
  })

  /*
   * Public, $.fn methods
   */

  $.fn.faceboxMail = function(settings) {
    init(settings)
    function clickHandler() {
      $.faceboxMail.loading(true)
      var klass = this.rel.match(/faceboxMail\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]
        fillfaceboxMailFromHref(this.href, klass)
      return false
    }

    return this.click(clickHandler)
  }

  /*
   * Private methods
   */

  // called one time to setup faceboxMail on this page
  function init(settings) {
    if ($.faceboxMail.settings.inited) return true
    else $.faceboxMail.settings.inited = true

    $(document).trigger('init.faceboxMail')
    makeCompatible()

    var imageTypes = $.faceboxMail.settings.imageTypes.join('|')
    $.faceboxMail.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i')

    if (settings) $.extend($.faceboxMail.settings, settings)
    $('body').append($.faceboxMail.settings.faceboxMailHtml)

    var preload = [ new Image(), new Image() ]
    preload[0].src = $.faceboxMail.settings.closeImage
    preload[1].src = $.faceboxMail.settings.loadingImage

    $('#faceboxMail').find('.b:first, .bl, .br, .tl, .tr').each(function() {
      preload.push(new Image())
      preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
    })

    $('#faceboxMail .close').click($.faceboxMail.close)
    $('#faceboxMail .close_image').attr('src', $.faceboxMail.settings.closeImage)
  }

  // getPageScroll() by quirksmode.com
  function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;
    }
    return new Array(xScroll,yScroll)
  }

  // Adapted from getPageSize() by quirksmode.com
  function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }
    return windowHeight
  }

  // Backwards compatibility
  function makeCompatible() {
    var $s = $.faceboxMail.settings

    $s.loadingImage = $s.loading_image || $s.loadingImage
    $s.closeImage = $s.close_image || $s.closeImage
    $s.imageTypes = $s.image_types || $s.imageTypes
    $s.faceboxMailHtml = $s.faceboxMail_html || $s.faceboxMailHtml
  }

  // Figures out what you want to display and displays it
  // formats are:
  //     div: #id
  //   image: blah.extension
  //    ajax: anything else
  function fillfaceboxMailFromHref(href, klass) {
    // div
    if (href.match(/#/)) {
      var url    = window.location.href.split('#')[0]
      var target = href.replace(url,'')
      $.faceboxMail.reveal($(target).clone().show(), klass)

    // image
    } else if (href.match($.faceboxMail.settings.imageTypesRegexp)) {
      fillfaceboxMailFromImage(href, klass)
    // ajax
    } else {
      fillfaceboxMailFromAjax(href, klass);
    }
  }

  function fillfaceboxMailFromImage(href, klass) {
    var image = new Image()
    image.onload = function() {
      $.faceboxMail.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
    }
    image.src = href
  }

  function fillfaceboxMailFromAjax(href, klass) {
    $.ajax({url: href,
            type: "GET",
            cache: false,
            success: function(html){$.faceboxMail.reveal(html,klass);
                                    var home = "http://www.ellesse.com/"
                                    $("#tbURL").val($('#path').val());
                                    $("#urlContainer").val($('#path').val());
                                    $("#subjectContainer").val(subject);
                                    $("#tbSubject").val(subject);
                                    hidediv(["ok","error","validator"]);
                                    SetDefaultTexts();
                                    },
            error: function ( XMLHttpRequest, textStatus, errorThrown) { $.faceboxMail.reveal('<h1>'+textStatus+'</h1><p>Resource is unaccessible or not found.</p>',klass)},
            complete: function(xhr, status){$(document).trigger('faceboxMail.load',status);
          }});
  }

  function skipOverlay() {
    return $.faceboxMail.settings.overlay == false || $.faceboxMail.settings.opacity === null
  }

  function showOverlay() {
    if ($.browser.msie) {
	jQuery('#newsletter-signup').contents().find('select').hide();
	jQuery('#contactform').contents().find('select').hide();
    }
    if (skipOverlay()) return

    if ($('faceboxMail_overlay').length == 0)
      $("body").append('<div id="faceboxMail_overlay" class="faceboxMail_hide"></div>')

    if ($('#faceboxMail_overlay').css('opacity') == 1 )
    {
      $('#faceboxMail_overlay').hide().addClass("faceboxMail_overlayBG")
        .css('opacity', $.faceboxMail.settings.opacity)
        .click(function() { $(document).trigger('close.faceboxMail') })
        .fadeIn(200)
    }
    $('#faceboxMail_overlay').css({height: $(document).height()});
    return false
  }

  function hideOverlay() {
    if ($.browser.msie) {
	jQuery('#newsletter-signup').contents().find('select').show();
	jQuery('#contactform').contents().find('select').show();
    }
    if (skipOverlay()) return

    $('#faceboxMail_overlay').fadeOut(200, function(){
      $("#faceboxMail_overlay").removeClass("faceboxMail_overlayBG")
      $("#faceboxMail_overlay").addClass("faceboxMail_hide")
      $("#faceboxMail_overlay").remove()
    })

    return false
  }

  /*
   * Bindings
   */

  $(document).bind('close.faceboxMail', function() {
    $(document).unbind('keydown.faceboxMail')
    $('#faceboxMail').fadeOut(function() {
      $('#faceboxMail .content').removeClass().addClass('content')
      $('#faceboxMail .content').text('');
      hideOverlay()
      $('#faceboxMail .loading').remove()
    })
  })

})(jQuery);