﻿$(document).ready(function () {


    var filterType = "";
    var friendlyUrl = "";
    var showMoreRow = 0;

    var lang;
    var KeyfruitUI = {
        init: function () {
            KeyfruitUI.cufon();
            lang = $('#lang').attr("rev");
        },
        cufon: function () {
            Cufon.replace('h1', { fontFamily: 'Franchise', textShadow: '#fff 1px 0px, #000 -1px -1px', fontSize: '78px' });
            Cufon.replace('h2', { fontFamily: 'Franchise', fontSize: '40px' });
            Cufon.replace('.notFound h2', { fontFamily: 'Franchise', fontSize: '24px' });
            Cufon.replace('h3', { fontFamily: 'LibelSuit' });
            Cufon.replace('.messages h3', { fontFamily: 'Franchise' });
            Cufon.replace('#sidemenu h3', { fontFamily: 'Franchise' });
            Cufon.replace('#top-menu ul li a', { fontFamily: 'Franchise', hover: true, fontSize: '18px' });
            Cufon.replace(' .sb-cufon a', { fontFamily: 'Franchise', hover: true, fontSize: '22px' });
            Cufon.replace(' #newsletter h3, .latest-blog-box h4, #filtre span, .sortbydate', { fontFamily: 'Franchise' });
            Cufon.replace('#fat-footer h4', { fontFamily: 'Franchise', fontSize: '25px' });
            Cufon.replace('#top', { fontFamily: 'LibelSuit', hover: true, fontSize: '16px' });
            Cufon.replace('.button', { fontFamily: 'LibelSuit', hover: true });
            Cufon.replace('#fat-footer div.button', { fontFamily: 'LibelSuit', hover: true, fontSize: '16px' });
            Cufon.replace('.showcase a.title', { fontFamily: 'LibelSuit', hover: true });
            Cufon.replace('.showmore', { fontFamily: 'LibelSuit', hover: true });
            Cufon.replace('.box300 h3', { fontFamily: 'Franchise' });
            Cufon.replace('.blog h1', { fontFamily: 'LibelSuit', hover: true });
            Cufon.replace(' .keyfruits h3', { fontFamily: 'LibelSuit', hover: true, fontSize: '18px' });
            Cufon.replace(' .keyfruits h4', { fontFamily: 'LibelSuit', hover: true, fontSize: '14px' });
            Cufon.replace(' ul.overview li p a', { fontFamily: 'LibelSuit', fontSize: '18px' });
            Cufon.replace(' ul.overview .more a', { fontFamily: 'LibelSuit', fontSize: '20px' });
            Cufon.replace('.zebra td', { fontFamily: 'LibelSuit', fontSize: '22px' });
            Cufon.replace(' .brand-left', { fontFamily: 'Franchise' });
            Cufon.replace(' .brand-right', { fontFamily: 'LibelSuit', hover: true });
            Cufon.replace(' .plans h3, .latest-blog-box h5 a', { fontFamily: 'LibelSuit' });
            Cufon.replace(' button.plain', { fontFamily: 'LibelSuit', hover: true });
            Cufon.replace(' .homepageSlider h3', { fontFamily: 'Franchise' });
            Cufon.replace('.nextprevlink h4', { fontFamily: 'LibelSuit' });
            Cufon.replace('#latestcomment h3', { fontFamily: 'Franchise' });
        },

        showmore: function () {
            //alert($("#htag").val());
            $('.showmore a').html('<img src="http://www.keyfruit.net/Assets/Imgs/Base/loading.gif" />');
            //            $.ajax({
            //                type: "POST",
            //                url: "/ShowCase/ShowMore",
            //                data: "start=" + showMoreRow + "&tag=" + $("#htag").val(),
            //                cache: false,
            //                success: function (html) {
            //                    $("ul.showcase").append(html);
            //                    if (html.indexOf('##true##') < 0) {
            //                        $('.showmore a').html('<big>+</big> &nbsp;&nbsp;Show More');
            //                        showMoreRow += 5;
            //                    } else {
            //                        $('.showmore').remove();
            //                    }
            //                    KeyfruitUI.cufon();
            //                    //alert(showMoreRow);
            //                }
            //            });



            var postdata = "filterType=" + filterType + "&friendlyUrl=" + friendlyUrl + "&orderAsc=" + $("#filter-date-text").attr("rev") + "&start=" + showMoreRow;

            //alert(postdata);
            $.ajax({
                type: "POST",
                url: "/ShowCaseFilter",
                data: postdata,
                cache: false,
                success: function (html) {
                    $("ul.showcase").append(html);
                    if (html.indexOf('##true##') < 0) {
                        $('.showmore a').html('<big>+</big> &nbsp;&nbsp;Show More');
                        showMoreRow += 5;
                    } else {
                        $('.showmore').hide();
                    }
                    KeyfruitUI.cufon();
                },
                complete: function () {
                    gapi.plusone.go('content');
                }
            });

        },
        hidecombo: function () {
            if ($(".scroll-pane").length > 0) {
                $('#icareerlist, #ireasonlist, .filterlist').hide();
                $('#icareerlist, #ireasonlist, .filterlist').removeClass("show");
                $("#hiddenarea").remove();
            }
        }
        , test: function () {
            alert("test");
        }
    };

    KeyfruitUI.init();
    // Preload images
    var cache = [];
    $.preLoadImages = function () {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }


    $("#hiddenarea").live('click', function () {
        KeyfruitUI.hidecombo();
    });

    $('#deleteFile').live('click', function () {
        $('#uploadResult').hide();
    });

    $.each($('.sitemap .box300'), function (i) {
        if (i % 2 == 0) {
            $(this).appendTo('#col1');
        } else {
            $(this).appendTo('#col2');
        }
    });

    var focustext;
    $(".textbox").focus(function () {
        focustext = $(this).val();
        $(this).addClass("textboxfocus").val('').removeClass('invalid');
        $('#errorcontent').html('');
        KeyfruitUI.hidecombo();
    });

    $(".textbox").blur(function () {
        if ($(this).val() == "")
            $(this).val(focustext);

        $(this).removeClass("textboxfocus");
    });

    //    $('a[rel*=commentsubmit]').bind(
    //        'click',
    //        function (e) {
    //            e.preventDefault();

    //            $('#commentform').submit();
    //        }
    //    );


    $(".textarea").focus(function () {
        $(this).addClass("textboxfocus").removeClass('invalid');
        $('#errorcontent').html('');
    });

    $(".textarea").blur(function () {
        $(this).removeClass("textboxfocus");
    });


    $('a#top').click(function () {
        $('html, body').animate({ scrollTop: '0px' }, 1000);
        return false;
    });

    //$('#tweets').tweetable({ username: 'keyfruit', time: true, limit: 20 });

    $(".wdwd li:nth-child(2n+1)").addClass("mar-r-30");

    $(".zebra tr td:nth-child(2n)").addClass("text");
    $(".zebra tr td:nth-child(2n+1)").addClass("count");
    $(".zebra tr:nth-child(2n)").addClass("alt-row");

    $(".zebra tr:nth-child(2n+1)").addClass("row");
    //$(".sitemap div:nth-child(2n+1)").addClass("mar-r-30");


    $('.showmore a').click(function () {
        KeyfruitUI.showmore();
    });


    $(".overview li").hover(function () {
        $(this).find('.more').slideDown("fast");
        $(this).find('.footer').addClass("footerhover");

    }, function () {
        $(this).find('.more').slideUp("fast");
        $(this).find('.footer').removeClass("footerhover");
    });



    $("#facebooklike").hover(
      function () {
          $("#widgetcontainer").animate({ height: "201px", marginTop: "-201px" }, { queue: false, duration: 500 });
      },
      function () {
          $("#widgetcontainer").animate({ height: "0", marginTop: 0 }, { queue: false, duration: 500 });
      }
    );

      $("#googlebadge").hover(
      function () {
          $("#googlebadgebox").animate({ height: "140px", marginTop: "-140px" }, { queue: false, duration: 500 });
      },
      function () {
          $("#googlebadgebox").animate({ height: "0", marginTop: 0 }, { queue: false, duration: 500 });
      }
    );



    /* $("#facebooklike").hover(function () {
    $("#widgetcontainer").animate({ height: "201px", marginTop: "-201px" }, { queue: false, duration: 500 });

    });

    $("#widgetcontainer").mouseout(function () {
    $("#widgetcontainer").animate({ height: "0", marginTop: 0, overflow: "hidden" }, { queue: false, duration: 500 });
    });*/




    //$("a[rel^='prettyPhoto']").prettyPhoto({the1me:'facebook'});

    $(".founder .kf-content").click(function () {
        $(this).addClass('founderhover');
        $(this).find('.kf-description').show().css({ "clear": "left", "padding-top": "20px" });

    });

    $(".founder .kf-content").mouseleave(function () {
        $(this).removeClass("founderhover");
        $(this).find('.kf-description').hide();
    });

    if ($('ul.keyfruits').length > 0) {
        var s, x, n;
        $.each($('div.kf-content > img'), function () {
            s = $(this).attr("src");
            x = s.split('.');
            n = x[0] + "2." + x[1];
            $(this).data({ "ovr": n, "out": s });
            $.preLoadImages(n);
        });
    }

    $(".keyfruits li").hover(function () {
        $(this).css({ "opacity": "1" });
        var s = $(this).find('div.kf-content > img').data("ovr");
        $(this).find('div.kf-content > img').attr("src", s);
    }, function () {
        var s = $(this).find('div.kf-content > img').data("out");
        $(this).find('div.kf-content > img').attr("src", s);
        $(this).css({ "background-color": "", "cursor": "", "opacity": "0.7" });

    });

    $(".employee li").click(function () {
        $(this).addClass('employeehover');
        $(this).next().addClass('hidekf');
        $(this).find('.kf-description').show();
    });

    $(".employee li").mouseleave(function () {
        $(this).next().removeClass("hidekf");
        $(this).removeClass('employeehover');
        $(this).find('.kf-description').hide();
    });

    $(".employee li:nth-child(4n)").addClass("forth");


    $(".employee li.forth").click(function () {
        $(this).prev().addClass('hidekf');
        $(this).next().removeClass('hidekf');
    });

    $(".employee li.forth").mouseleave(function () {
        $(this).prev().removeClass("hidekf");
    });


    $(".overview li").hover(function () {
        document[$(this).find('object').attr('id')].rotateF();
    }, function () {
        document[$(this).find('object').attr('id')].rotateB();
    });



    function workwithusform() {
        if ($('#uploadResult').hasClass("active")) {
            alert("Dosya yüklemeniz henüz tamamlanmadı.\nLütfen Bekleyiniz.");
            return;
        }
        if (!checkinput('#wwu-iname', 'Your Name')) {
            validation2('wwu-iname', 'You have a name, don\'t you?');
        }

        else if (!checkinput('#wwu-iemail', 'Your e-mail')) {
            validation2('wwu-iemail', 'You have an e-mail, don\'t you?');
        }
        else if ($('#wwu-iemail').val() != "" && !mailfilter.test($('#wwu-iemail').val())) {
            validation2('wwu-iemail', 'Please check your e-mail');
        }
        else if (!checkinput('#wwu-iphone', 'Phone')) {
            validation2('wwu-iphone', 'You have a phone, don\'t you?');
        }
        else if (!checkinput('#wwumessage', '')) {
            validation2('wwumessage', 'Well, you must say something.');
        }
        else if (!checkinput('#wwuicaptchas', '')) {
            validation2('wwuicaptchas', 'Enter secure code.');
        }
        else {
            $.ajax({
                type: "POST",
                url: "/Box/WorkWithUs",
                data: $('#wwu').serialize(),
                cache: false,
                beforeSend: function () {
                    $('.ready-btn').hide();
                    $('.sending').show();
                },
                success: function (html) {
                    $('.white_content').remove();
                    //KeyfruitUI.cufon();
                    if (html == 0) {
                        $('#' + html).hide();
                        $('#exposeMask').hide();
                        $("#workWithUsFail").overlay({
                            mask: { color: '#000', effect: 'apple' },
                            closeOnClick: true,
                            load: true
                        });
                    }
                    if (html == 1) {
                        validation('wwuicaptchas', 'The secure code is wrong.');
                    }
                    if (html != 0 && html != 1) {
                        $('#' + html).hide();
                        $('#exposeMask').hide();
                        $.each($('img'), function (i) {
                            if ($(this).attr("src") == "non") {
                                $(this).remove();
                            }
                        });

                        $("#workWithUsSuccess").overlay({
                            mask: { color: '#000', effect: 'apple' },
                            closeOnClick: true,
                            load: true
                        });
                    }

                    $("#refreshimagecontactus").click();
                }
            });

        }

    }


    $('#workWithUsSubmit').click(function () {
        workwithusform();
    });

    $('#contactformbtn').click(function () {
        contactform();
    });


    $('#sendForm').click(function () {
        fatform();
    });

    $('#newsletterbtn').click(function () {
        newsletterform();
    });


    $('#myform input, #myform textarea, #newsletter input, #contactform input,  #contactform textarea , #workwithus input , #workwithus textarea').focus(function () {
        var el = $(this).attr("id")
        $('#error' + el).remove();
        if ($('#errorcommenterror').length > 0) {
            $('#errorcommenterror').remove();
        }
    });

    $('#ireason').click(function () {
        if ($("#ireasonlist").hasClass("show")) {
            $('#ireasonlist').hide();
            $('#ireasonlist').removeClass("show");
            $('#errorhiddenireason').remove();
        } else {
            $('#errorhiddenireason').remove();
            $('body').append('<div id="hiddenarea"></div>');
            $('#icareerlist').hide();
            $('#icareerlist').removeClass("show");
            $('#ireasonlist').show().addClass("show");
            if ($('#ireasonlist .jScrollPaneContainer').length < 1)
                $('#pane2').jScrollPane({ showArrows: true, scrollbarWidth: 23 });
        }
    });


    $('#pane2 a').live('click', function () {
        $('#ireason').text($(this).text());
        $('#hiddenireason').val($(this).attr("id"));
        $('#ireason').click();
    });


    $('#icareer').click(function () {
        if ($("#icareerlist").hasClass("show")) {
            $('#icareerlist').hide();
            $('#icareerlist').removeClass("show");
        } else {
            $('body').append('<div id="hiddenarea"></div>');
            $('#ireasonlist').hide();
            $('#ireasonlist').removeClass("show");
            $('#icareerlist').show().addClass("show");
            if ($('#icareerlist .jScrollPaneContainer').length < 1)
                $('#pane1').jScrollPane({ showArrows: true, scrollbarWidth: 23 });

        }
    });


    $('div.select-filtre, div.select-filtre2').click(function () {
        var id = "#" + $(this).attr("data-list");
        if ($(id).hasClass("show")) {
            $(id).hide().removeClass("show");
        } else {
            $('body').append('<div id="hiddenarea"></div>');
            $('div.filterlist').hide().removeClass("show");
            $(id).show().addClass("show");
            if ($(id + ' .jScrollPaneContainer').length < 1)
                $(id + ' div.scroll-pane').jScrollPane({ showArrows: true, scrollbarWidth: 23 });
        }
    });

    $('#allProject').click(function (e) {
        e.preventDefault();
        filterType = "";
        friendlyUrl = "";
        showMoreRow = 0;
        $('#filter-category-text').html('Choose');
        $('#filter-brand-text').html('Choose');
        $('#filter-note').hide();
        $('#filter-note-all-project').show();
        $.GetShowCaseData();
    });
    $.GetShowcaseFilterDataByUrl = function () {

        var vars = [], hash;
        //alert(window.location.href.slice(window.location.href.indexOf('#') + 1));
        var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split(',');
        var searchTpye = 0;
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            //alert(hashes[i]);
            //vars.push(hash[0]);
            //vars[hash[0]] = hash[1];
            var key = hashes[i].split('=')[0];
            var val = hashes[i].split('=')[1];

            if (key == 'c') {
                filterType = 'Category';
                friendlyUrl = val;
            }
            if (key == 'b') {
                filterType = 'Brand';
                friendlyUrl = val;
            }
            if (key == 'o') {
                $("#filter-date-text").attr("rev", val);
            }
            if (key == 's') {
                showMoreRow = val;
            }
            //alert(key + ' - ' + val);

        }

    }
    $.GetShowCaseData = function () {

        var postdata = "filterType=" + filterType + "&friendlyUrl=" + friendlyUrl + "&orderAsc=" + $("#filter-date-text").attr("rev") + "&start=" + showMoreRow;
        var url = '#';

        if (filterType == "Category") {
            $("#filterType").html('category');
            var selectedText = $('#filter-category a[rev=' + friendlyUrl + ']').html();
            $("#selectedFilter").html(selectedText);
            $('#filter-brand-text').html('Choose');
            $('#filter-category-text').html(selectedText);
            url += 'c=' + friendlyUrl;
            $('#filter-note').show();
            $('#filter-note-all-project').hide();
        }
        else if (filterType == "Brand") {
            $("#filterType").html('brand');
            var selectedText = $('#filter-brand a[rev=' + friendlyUrl + ']').html();
            $("#selectedFilter").html(selectedText);
            $('#filter-brand-text').html(selectedText);
            $('#filter-category-text').html('Choose');
            url += 'b=' + friendlyUrl;
            $('#filter-note').show();
            $('#filter-note-all-project').hide();
        }

        if ($("#filter-date-text").attr("rev") == "true") {
            $(".orderType").html('newest to oldest');
            $('#filter-date-text').html('Newest to oldest');

        }
        else {
            $(".orderType").html('oldest to newest');
            $('#filter-date-text').html('Oldest to newest');
        }

        url += ',o=' + $("#filter-date-text").attr("rev") + ',s=' + showMoreRow;

        $.ajax({
            type: "POST",
            url: "/ShowCaseFilter",
            data: postdata,
            cache: false,
            success: function (html) {
                $("ul.showcase").html(html);
                KeyfruitUI.hidecombo();

                if (html.indexOf('##true##') < 0) {
                    $('.showmore a').html('<big>+</big> &nbsp;&nbsp;Show More');
                    $('.showmore').show();
                    showMoreRow += 5 * 1;


                } else {
                    $('.showmore').hide();
                }
                document.location = url;
                KeyfruitUI.cufon();
            },
            complete: function () {
                gapi.plusone.go('content');
            }
        });

        KeyfruitUI.hidecombo();
    }



    $('div.filterlist div.scroll-pane a').live("click", function (e) {
        e.preventDefault();
        showMoreRow = 0;
        if ($(this).attr("data-item") == 'project') {
            location.href = $(this).attr("rev");
            return
        }

        var id = '#' + $(this).parents('.filterlist').attr("id") + "-text";

        $(id).text($(this).text());
        $(id).attr("rev", $(this).attr("rev"));

        if (id == "#filter-brand-text" || id == "#filter-category-text" || id == "#filter-brand-link-text" || id == "#filter-category-link-text") {
            filterType = $(this).attr("data-item");
            friendlyUrl = $(this).attr("rev");
        }

        $.GetShowCaseData();
    });

    $('.showcaseitem a.showcase-tag,.showcaseitem a.showcase-brand').live("click", function (e) {
        location.href = $(this).attr('href');
        $.GetShowcaseFilterDataByUrl();
        $.GetShowCaseData();
    });

    if ($('.latest-blog-box #pane1').length > 0) {
        $('#pane1').jScrollPane();
    }

    $('#pane1 a').live('click', function () {
        $('#icareer').text($(this).text());
        $('#hiddenicareer').val($(this).attr("id"));
        $('#icareer').click();
    });

    $(document).keyup(function (e) {
        if (e.keyCode == 27) {
            KeyfruitUI.hidecombo();
        }
    });

    var pstc = $('p.subscribe-to-comments');
    $('div#comment-subscription').html(pstc.html());
    pstc.remove();


    $("#refreshimagenewsletter").click(function () {
        $image = $("#secureimagenewsletter");
        $image.attr('src', '/Captcha?' + (new Date()).getTime());
    });



    $("#refreshimagecontactus").click(function () {
        $image = $("#secureimagecontactus");
        $image.attr('src', '/Captcha?' + (new Date()).getTime());
    });



    $("#refreshimagefatfooter").click(function () {
        $image = $("#secureimagefatfooter");
        $image.attr('src', '/Captcha?' + (new Date()).getTime());
    });

    $("#refreshimagefatfooterblog").click(function () {
        $image = $("#secureimagefatfooter");
        $image.attr('src', '/SendMail/CaptchaSecurityImages.php?width=100&height=40&characters=5&' + (new Date()).getTime());
    });

    if ($('#filtre').length > 0) {
        $.GetShowcaseFilterDataByUrl();
        $.GetShowCaseData();
    }

    if ($('span#page-workwithus').length > 0 && $('#link-workwithus #btn-wwu').length > 0) {
        var src = $("img#btn-wwu").attr("dataovr");
        $("img#btn-wwu").attr("src", src).addClass("active");
    }

    $("img#btn-wwu").hover(function () {
        $(this).attr("src", $(this).attr("dataovr"));
    }, function () {
        if (!$(this).hasClass("active")) {
            $(this).attr("src", $(this).attr("dataout"));
        }
    });
});




var mailfilter = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

function fixpngs() {
    var l = document.getElementsByTagName('img');
    for (i = 0; i < l.length; i++) {
        p = '/Assets/Imgs/0.gif';
        n = l[i].getAttribute('src');
        g = n.toLowerCase();
        if (g.substring(g.length - 3) == "png") {
            l[i].setAttribute('src', p);
            l[i].style.cssText = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src='" + n + "')";
        }
    }
}


function numeric(e) {
    var charCode = (e.which) ? e.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function newsletterform() {
    if (!checkinput('#iname', 'Your name')) {
        validation('iname', 'You have a name, don\'t you?');
    }

    else if (!checkinput('#iemail', 'Your e-mail')) {
        validation('iemail', 'You have an e-mail, don\'t you?');
    }
    else if ($('#iemail').val() != "" && !mailfilter.test($('#iemail').val())) {
        validation('iemail', 'Provide a valid e-mail!');
    }
  
    else {
        $.ajax({
            type: "POST",
            url: "/NewsLetter",
            data: $('#newsletterform').serialize(),
            cache: false,
            beforeSend: function () {
                $('#newsletterform .button').hide();
                $('#newsletterform .sending').show();
            },
            success: function (html) {
                $('#newsletterform .sending').hide();
                
                if (html == "1") {
                    $('#exposeMask').hide();
                    $("#newsletterSuccess").overlay({
                        mask: { color: '#000', effect: 'apple' },
                        closeOnClick: true,
                        load: true
                    });
                    
                    $('#newsletterform #iname').val('Your name');
                    $('#newsletterform #iemail').val('Your e-mail');

                }
                if (html == "2") {
                    $('#exposeMask').hide();
                    $("#newsletterSameEmail").overlay({
                        mask: { color: '#000', effect: 'apple' },
                        closeOnClick: true,
                        load: true
                    });
                }
                if (html == "3") {
                    location.reload(true);
                }
                if (html == "4") {
                    validation('icaptchas', 'The secure code is wrong.');
                }

                $("#refreshimagenewsletter").click();
                $('#newsletterform .button').show();
            }
        });
       
    }

}

function contactform() {
    if (!checkinput('#contactAuthor')) {
        validation('contactAuthor', 'You have a name, don\'t you?');
       // groupvalidation('#contactAuthor', "You have a name, don\'t you?");
    }

    else if (!checkinput('#contactEmail')) {
        validation('contactEmail', 'You have an e-mail, don\'t you?');
        //groupvalidation('#contactEmail', "You have an e-mail, don\'t you?");
       
    }
    else if ($('#contactEmail').val() != "" && !mailfilter.test($('#contactEmail').val())) {
        validation('contactEmail', 'Not so fast: Provide a valid e-mail!');
       // groupvalidation('#contactEmail', "You have an e-mail, don\'t you?");        
    }

    else if (!checkinput('#hiddenireason')) {
        validation('hiddenireason', 'Well, you have to specify what you want to do!');
        //groupvalidation('#contactEmail', "You have an e-mail, don\'t you?");

    }

    else if (!checkinput('#comment')) {
        validation('commenterror', 'Well, you must say something!');
      //  groupvalidation('#comment', "Well, you must say something!");

    }
    else {
        $.ajax({
            type: "POST",
            url: "/ContactForm",
            data: $('#contactform').serialize(),
            cache: false,
            beforeSend: function () {
                $('#contactform .button').hide();
                $('#contactform .sending').show();
            },
            success: function (html) {
                $('#contactform .sending').hide();
                if (html == 1) {
                    $('#contactAuthor').val('');
                    $('#contactEmail').val('');
                    $('#ifile').val('');
                    $('#company').val('');
                    $('#ifphone').val('');
                    $('#icaptchas').val('');
                    $('#comment').val('');
                    $('#icareer').text('Choose');
                    $('#ireason').text('Choose');
                    $("#uploadResult").html('');
                    $("#filePath").val('');
                    $('#exposeMask').hide();
                    $("#contactUsSuccess").overlay({
                        mask: { color: '#000', effect: 'apple' },
                        closeOnClick: true,
                        load: true
                    });
                }
                if (html == 2) {
                    validation('icaptchas-vldn', 'The secure code is wrong.');
                }

                if (html == 0) {
                    
                    $('#exposeMask').hide();
                    $("#contactUsFail").overlay({
                        mask: { color: '#000', effect: 'apple' },
                        closeOnClick: true,
                        load: true
                    });
                }
                $('#contactform .button').show();
                $("#refreshimagecontactus").click();
            }
        });

    }
}


function fatform() {
    if (!checkinput('#ifname', 'Your name')) {
        validation('ifname', 'You have a name, don\'t you?');
    }
    else if (!checkinput('#ifemail', 'Your e-mail')) {
        validation('ifemail', 'You have an e-mail, don\'t you?');
    }
    else if ($('#ifemail').val() != "" && !mailfilter.test($('#ifemail').val())) {
        validation('ifemail', 'Not so fast: Provide a valid e-mail!');
    }
    else if (!checkinput('#imsg', 'Your Message')) {
        validation('imsg', 'Well, you must say something!');
    }
    else {
        $.ajax({
            type: "POST",
            url: "/ContactForm",
            data: $('#myform').serialize(),
            cache: false,
            beforeSend: function () {
                $('#myform .button').hide();
                $('#myform .sending').show();
            },
            success: function (html) {
                $('#myform .sending').hide();
                if (html == 1) {
                    $('#ifname').val('Your name');
                    $('#ifemail').val('Your e-mail');
                    $('#imsg').val('Your Message');
                    $('#ifcompany').val('Your Company');
                    $('#ifphone').val('Your Phone');
                    $('#icaptchas').val('');
                    $('#exposeMask').hide();
                    $("#fatFooterSuccess").overlay({
                        mask: { color: '#000', effect: 'apple' },
                        closeOnClick: true,
                        load: true
                    });
                    
                }
                if (html == 2) {
                    validation('icaptchas', 'The secure code is wrong.');

                }

                if (html == 0) {
                    $('#exposeMask').hide();
                    $("#fatFooterFail").overlay({
                        mask: { color: '#000', effect: 'apple' },
                        closeOnClick: true,
                        load: true
                    });
                }
                $('#myform .button').show();
                $("#refreshimagefatfooter").click();
            }
        });
    }
}

function fafooterblog() {
    if (!checkinput('#ifname', 'Your name')) {
        validation('ifname', 'You have a name, don\'t you?');
    }
    else if (!checkinput('#ifemail', 'Your e-mail')) {
        validation('ifemail', 'You have an e-mail, don\'t you?');
    }
    else if ($('#ifemail').val() != "" && !mailfilter.test($('#ifemail').val())) {
        validation('ifemail', 'Not so fast: Provide a valid e-mail!');
    }
    else if (!checkinput('#imsg', 'Your Message')) {
        validation('imsg', 'Well, you must say something!');
    }
    else {
        $.ajax({
            type: "POST",
            url: "/SendMail/mail.php",
            data: $('form#myform').serialize(),
            cache: false,
            beforeSend: function () {
                $('#myform .button').hide();
                $('#myform .sending').show();
            },
            success: function (html) {
                $('#myform .sending').hide();
                if (html == 1) {
                    $('#ifname').val('Your name');
                    $('#ifemail').val('Your e-mail');
                    $('#imsg').val('Your Message');
                    $('#ifcompany').val('Your Company');
                    $('#ifphone').val('Your Phone');
                    $('#icaptchas').val('');
                    $('#exposeMask').hide();
                    $("#fatFooterSuccess").overlay({
                        mask: { color: '#000', effect: 'apple' },
                        closeOnClick: true,
                        load: true
                    });

                }
                if (html == 2) {
                    validation('icaptchas', 'The secure code is wrong.');

                }

                if (html == 0) {
                    $('#exposeMask').hide();
                    $("#fatFooterFail").overlay({
                        mask: { color: '#000', effect: 'apple' },
                        closeOnClick: true,
                        load: true
                    });
                }
                $('#myform .button').show();
                $("#refreshimagefatfooterblog").click();
            }
        });
    }
}

function validation(el, msg) {
    $("#" + el).addClass('invalid');
    if ($('#error' + el).length > 0) {
        $('#error' + el).addClass('error').find('span').text(msg);
    } else {
        if($('#error' + el ).length < 1)
            $("#" + el).before('<div style="margin-top:-25px;" class="error" id="error' + el + '"><em></em><span>' + msg + '</span></div>');
    }

};

function validation2(el, msg) {
    $("#" + el).addClass('invalid');
    if ($('#error' + el).length > 0) {
        $('#error' + el).addClass('error').find('span').text(msg);
    } else {
        if ($('#error' + el).length < 1)
            $("#" + el).before('<span style="margin-top:-25px;" class="error" id="error' + el + '"><em></em><span>' + msg + '</span></span>');
    }

};

function groupvalidation(el, msg) {
    $('#errorcontent').show().html("<div>" + msg + "</div>");
    $(el).addClass('invalid');
};


function checkinput(el, msg) {
    if ($(el).val() == "" || $(el).val() == msg) {
        return false;
    } else {
        return true;
    }
    

}





