﻿/// <reference path="jquery-1.4.1-vsdoc.js" />
var hideTimer = null;

$(document).ready(function () {

    $('#submit').click(function () {

        $('#reg_ring').show()

        var emailaddress = $('#email').val();

        PageMethods.AddtoMailingList(emailaddress, MailSucceeded)
    })


    $('#reg_ring').hide()

      /// ####################################################################################
    /// Search by keyword setup  #########################################################
    /// ####################################################################################
    $('#btnprodsearch').click(function () {
       window.location = "products.aspx?key=" + $('#txprodSearch').val()
   })

   $('#txprodSearch').focus(function () {
       $(this).val('')
   })

   $('#txprodSearch').keypress(function (e) {
       if (e.which == 13) {
           $(this).blur();
           $('#btnprodsearch').click();
       }
   });


   $('#fb').hover(function () {
       this.src = 'images/fb_over.jpg';
   }, function () {
       this.src = 'images/fb.jpg';
   });

   $('#twt').hover(function () {
       this.src = 'images/twitter_over.jpg';
   }, function () {
       this.src = 'images/twitter.jpg';
   });
})

function MailSucceeded(data) {

    $('#reg_ring').hide()
    $('#uftnewsletter').html('<p>Thank you for your message.<br>We will be in touch with you soon.</p>')

}


function PageMethod(fn, paramArray, successFn, errorFn) {
    var pagePath = 'contact.aspx'// window.location.pathname;
    //Create list of parameters in the form:  
    //{"paramName1":"paramValue1","paramName2":"paramValue2"}  
    var paramList = '';
    if (paramArray.length > 0) {
        for (var i = 0; i < paramArray.length; i += 2) {
            if (paramList.length > 0) paramList += ',';
            paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
        }
    }
    paramList = '{' + paramList + '}';
    //Call the page method  
    $.ajax({
        type: "POST",
        url: pagePath + "/" + fn,
        contentType: "application/json; charset=utf-8",
        data: paramList,
        dataType: "json",
        success: successFn,
        error: errorFn
    })
;
}
