﻿
$(function () {
	init();
});

function init() {

   $('input[placeholder], textarea[placeholder]').placeholder();
   $("li:last-child").addClass('last-child');
   $.easing.customeaseOutBounce = function (f, a, c, b, d) { return (a /= d) < 1 / 2.75 ? b * 7.5625 * a * a + c : a < 2 / 2.75 ? b * (7.5625 * (a -= 1.5 / 2.75) * a + 0.75) + c : a < 2.5 / 2.75 ? b * (7.5625 * (a -= 2.25 / 2.75) * a + 0.9375) + c : b * (7.5625 * (a -= 2.625 / 2.75) * a + 0.984375) + c }
   $.easing.customeeaseInCirc = function (f, a, c, b, d) { return -b * (Math.sqrt(1 - (a /= d) * a) - 1) + c }

   topMenu();
   contactUs();
   searchInit();
}


function topMenu() {
   $(".topMenu li").hover(function () {
      var parentA = $(this).find('>a');
      var isSelected = parentA.hasClass('selectedPage');
      $(this).find('.subMenu:hidden').slideDown(200).hover(
            function () {
               if (!isSelected) {
                  parentA.addClass('selectedPage');
               }
            },
             function () {
                if (!isSelected) {
                   parentA.removeClass('selectedPage');
                }
               // $(this).slideUp('normal');
             });
   }, function () {
      $(this).find('.subMenu:visible').slideUp(120);
   });
}

/*
* Placeholder plugin for jQuery
* ---
* Copyright 2010, Daniel Stocks (http://webcloud.se)
* Released under the MIT, BSD, and GPL Licenses.
*/

(function (b) {
   function d(a) { this.input = a; a.attr("type") == "password" && this.handlePassword(); b(a[0].form).submit(function () { if (a.hasClass("placeholder") && a[0].value == a.attr("placeholder")) a[0].value = "" }) } d.prototype = { show: function (a) { if (this.input[0].value === "" || a && this.valueIsPlaceholder()) { if (this.isPassword) try { this.input[0].setAttribute("type", "text") } catch (b) { this.input.before(this.fakePassword.show()).hide() } this.input.addClass("placeholder"); this.input[0].value = this.input.attr("placeholder") } },
      hide: function () { if (this.valueIsPlaceholder() && this.input.hasClass("placeholder") && (this.input.removeClass("placeholder"), this.input[0].value = "", this.isPassword)) { try { this.input[0].setAttribute("type", "password") } catch (a) { } this.input.show(); this.input[0].focus() } }, valueIsPlaceholder: function () { return this.input[0].value == this.input.attr("placeholder") }, handlePassword: function () {
         var a = this.input; a.attr("realType", "password"); this.isPassword = !0; if (b.browser.msie && a[0].outerHTML) {
            var c = b(a[0].outerHTML.replace(/type=(['"])?password\1/gi,
"type=$1text$1")); this.fakePassword = c.val(a.attr("placeholder")).addClass("placeholder").focus(function () { a.trigger("focus"); b(this).hide() }); b(a[0].form).submit(function () { c.remove(); a.show() })
         } 
      } 
   }; var e = !!("placeholder" in document.createElement("input")); b.fn.placeholder = function () {
      return e ? this : this.each(function () {
         var a = b(this), c = new d(a); c.show(!0); a.focus(function () { c.hide() }); a.blur(function () { c.show(!1) }); b.browser.msie && (b(window).load(function () { a.val() && a.removeClass("placeholder"); c.show(!0) }),
a.focus(function () { if (this.value == "") { var a = this.createTextRange(); a.collapse(!0); a.moveStart("character", 0); a.select() } }))
      })
   } 
})(jQuery);

/* Easing */
/*jQuery.extend(jQuery.easing, { def: "easeOutQuad", swing: function (f, a, c, b, d) { return jQuery.easing[jQuery.easing.def](f, a, c, b, d) }, easeInOutExpo: function (f, a, c, b, d) { return a == 0 ? c : a == d ? c + b : (a /= d / 2) < 1 ? b / 2 * Math.pow(2, 10 * (a - 1)) + c : b / 2 * (-Math.pow(2, -10 * --a) + 2) + c }, easeInCirc: function (f, a, c, b, d) { return -b * (Math.sqrt(1 - (a /= d) * a) - 1) + c }, easeOutCirc: function (f, a, c, b, d) { return b * Math.sqrt(1 - (a = a / d - 1) * a) + c }, easeInOutCirc: function (f, a, c, b, d) { return (a /= d / 2) < 1 ? -b / 2 * (Math.sqrt(1 - a * a) - 1) + c : b / 2 * (Math.sqrt(1 - (a -= 2) * a) + 1) + c },
    easeInElastic: function (f, a, c, b, d) { var f = 1.70158, e = 0, g = b; if (a == 0) return c; if ((a /= d) == 1) return c + b; e || (e = d * 0.3); g < Math.abs(b) ? (g = b, f = e / 4) : f = e / (2 * Math.PI) * Math.asin(b / g); return -(g * Math.pow(2, 10 * (a -= 1)) * Math.sin((a * d - f) * 2 * Math.PI / e)) + c }, easeOutElastic: function (f, a, c, b, d) { var f = 1.70158, e = 0, g = b; if (a == 0) return c; if ((a /= d) == 1) return c + b; e || (e = d * 0.3); g < Math.abs(b) ? (g = b, f = e / 4) : f = e / (2 * Math.PI) * Math.asin(b / g); return g * Math.pow(2, -10 * a) * Math.sin((a * d - f) * 2 * Math.PI / e) + b + c }, easeInOutElastic: function (f, a, c, b, d) {
        var f =
1.70158, e = 0, g = b; if (a == 0) return c; if ((a /= d / 2) == 2) return c + b; e || (e = d * 0.3 * 1.5); g < Math.abs(b) ? (g = b, f = e / 4) : f = e / (2 * Math.PI) * Math.asin(b / g); return a < 1 ? -0.5 * g * Math.pow(2, 10 * (a -= 1)) * Math.sin((a * d - f) * 2 * Math.PI / e) + c : g * Math.pow(2, -10 * (a -= 1)) * Math.sin((a * d - f) * 2 * Math.PI / e) * 0.5 + b + c
    }, easeInBack: function (f, a, c, b, d, e) { e == void 0 && (e = 1.70158); return b * (a /= d) * a * ((e + 1) * a - e) + c }, easeOutBack: function (f, a, c, b, d, e) { e == void 0 && (e = 1.70158); return b * ((a = a / d - 1) * a * ((e + 1) * a + e) + 1) + c }, easeInOutBack: function (f, a, c, b, d, e) {
        e == void 0 &&
(e = 1.70158); return (a /= d / 2) < 1 ? b / 2 * a * a * (((e *= 1.525) + 1) * a - e) + c : b / 2 * ((a -= 2) * a * (((e *= 1.525) + 1) * a + e) + 2) + c
    }, easeInBounce: function (f, a, c, b, d) { return b - jQuery.easing.easeOutBounce(f, d - a, 0, b, d) + c }, easeOutBounce: function (f, a, c, b, d) { return (a /= d) < 1 / 2.75 ? b * 7.5625 * a * a + c : a < 2 / 2.75 ? b * (7.5625 * (a -= 1.5 / 2.75) * a + 0.75) + c : a < 2.5 / 2.75 ? b * (7.5625 * (a -= 2.25 / 2.75) * a + 0.9375) + c : b * (7.5625 * (a -= 2.625 / 2.75) * a + 0.984375) + c }, easeInOutBounce: function (f, a, c, b, d) {
        return a < d / 2 ? jQuery.easing.easeInBounce(f, a * 2, 0, b, d) * 0.5 + c : jQuery.easing.easeOutBounce(f,
a * 2 - d, 0, b, d) * 0.5 + b * 0.5 + c
    } 
});
*/
function validateEmail(elementValue) { var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return emailPattern.test(elementValue); }

var countrySelection = 3;
function contactUs() {
	$('.ContactAddres').hide();
	$('.addrUS').show();
   $('.countries > a').click(function (event) {
      event.preventDefault();
      flagDiv = $(this).find('> div');
      $(this).parent().find('a').removeClass('selected');
      flagDiv.parent().addClass('selected');
      if (flagDiv.hasClass('NE')) { countrySelection = 1; $('.ContactAddres').hide(); $('.addrALL').show();}
      if (flagDiv.hasClass('GE')) { countrySelection = 2; $('.ContactAddres').hide(); $('.addrALL').show();}
      if (flagDiv.hasClass('US')) { countrySelection = 3; $('.ContactAddres').hide(); $('.addrUS').show();}
      if (flagDiv.hasClass('WORLD')) { countrySelection = 1; $('.ContactAddres').hide(); $('.addrALL').show();}
   });

   $('.submitButton').click(function () {
      var hideTime = 1300, showTime = 500;
      var ContactName = $('#ContactName').val();
      var ContactEmail = $('#ContactEmail').val();
      var ContactSubject = $('#ContactSubject').val();
      var ContactMessage = $('#ContactMessage').val();
      var ContactCompany = $('#ContactCompany').val();
      var Contactphone = $('#Contactphone').val();

      var ContactDiv = $("#formDiv");
      var emptyfields = $(".ContactUs_required ").filter(function () { return $(this).val() == ""; });
      var isValidEmail = validateEmail(ContactEmail);

      if (emptyfields.length) {
         emptyfields.effect("highlight", { color: '#FF4200' }, 2500);
      } else {
         if (!isValidEmail) {
            $('#ContactEmail').effect("highlight", { color: '#FF4200' }, 2500);
            return;
         }

         $('#formDiv').fadeTo(hideTime, 0, function () { $('#formDiv').empty().append("<div class='mailSentMessage'>" + $('#sentText').html() + "</div>").fadeTo(showTime, 1); });

         $.post('/scripts/SendForm.aspx', { 'ContactName': ContactName, 'ContactEmail': ContactEmail, 'ContactSubject': ContactSubject, 'ContactMessage': ContactCompany, 'ContactCompany': ContactMessage, 'Contactphone': Contactphone, 'pageId': pageId, 'countrySelection': countrySelection }, function (data) {
         });
      }
   });
}

// browser detection
$(document).ready(function () { var a = navigator.userAgent.toLowerCase(); $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); if ($.browser.msie) { $('body').addClass('browserIE'); $('body').addClass('browserIE' + $.browser.version.substring(0, 1)) } if ($.browser.chrome) { $('body').addClass('browserChrome'); a = a.substring(a.indexOf('chrome/') + 7); a = a.substring(0, 1); $('body').addClass('browserChrome' + a); $.browser.safari = false } if ($.browser.safari) { $('body').addClass('browserSafari'); a = a.substring(a.indexOf('version/') + 8); a = a.substring(0, 1); $('body').addClass('browserSafari' + a) } if ($.browser.mozilla) { if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1) { $('body').addClass('browserFirefox'); a = a.substring(a.indexOf('firefox/') + 8); a = a.substring(0, 1); $('body').addClass('browserFirefox' + a) } else { $('body').addClass('browserMozilla') } } if ($.browser.opera) { $('body').addClass('browserOpera') } });

function searchInit() {
   var formObj = $('#generalForm');

   $('#searchButton').click(function () {
      sendSearch();
   });
     $("form").bind("keypress", function(e) {
         if (e.keyCode == 13) {
             if ($('#searchTxt').val().length > 0 && $('#searchTxt').val() != "Search") { sendSearch();}
             return false;
        }
     });
}

function sendSearch() {
   var formObj = $('#generalForm');
   var searchTxt = $('#searchTxt').val();
   if (searchTxt.length > 0) {
      formObj.append('<input type="hidden" name="searchTxt_FORM" id="searchTxt_FORM" value="' + searchTxt + '"/>');
      formObj.get(0).setAttribute('action', '/pagetemplates/search.aspx');
      formObj.submit();
   } 
}


