﻿function RegisterNewsletter(_emailid) {
    $(".iletisim_left_box_content .result").html("");
    try {
        var email = $("#" + _emailid).val();
        var errormessage = $("#" + _emailid).attr("ErrorMessage");
        if (!validateEmail(email)) {
            $(".iletisim_left_box_content .result").html(errormessage);
        }
        else {
            $.ajax({
                type: "POST",
                url: "/Content/WebService/ClientSiteWebService.asmx/RegisterNewsletter",
                data: "{Email:'" + email + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    $(".iletisim_left_box_content .result").html(msg.d);
                },
                error: function (msg) {
                    return false;
                }
            });
        }

    } catch (e) {

    }
    return false;
}

function IntervalSlide() {
    var active = $('.fader ul.paging li.active');

    PagingIndex = $(active).attr('index');

    if (PagingIndex != $('.fader ul.slider li').length - 1) {
        $(active).removeClass('active');
        var next = $('.fader ul.paging li[index=' + (parseInt(PagingIndex) + parseInt(1)) + ']');
        $(next).addClass('active');
        var leftFrom = 0;
        leftFrom = (parseInt(PagingIndex) + 1) * 735;
        $('.fader ul.slider').animate({
            left: '-' + leftFrom + 'px'
        }, 750);
    }
    else {
        $('.fader ul.slider').animate({
            left: '0px'
        }, 750);
        $('.fader ul.paging li').removeClass('active');
        $('.fader ul.paging li[index=0]').addClass('active');
    }
}


function SlideViewer(Selector) {
    var list = $(Selector + ' ul.slider li');
    var Width = $(list).length * 735;
    $(Selector + ' ul.slider').width(Width);
    var paging;
    $.each(list, function (i) {
        if (i == 0) {
            paging = '<ul class="paging">';
            paging += '<li class="active" index="' + i + '"></li>';
        }
        else {
            paging += '<li index="' + i + '"></li>';
        }
        if (i == $(list).length - 1)
            paging += '</ul>';
    });
    $(Selector).append(paging);

    $(Selector + ' ul.paging').css({
        left: ((735 - $(Selector + ' ul.paging').width()) / 2) + 'px'
    });
}

function submenu() {
    var list = $('#left-content .menu ul li');
    $.each(list, function (i) {
        if ($(this).attr('index') != null) {
            var item = $('#right-content .submenu .item[index=' + $(this).attr('index') + ']');
            var offf = $(this).offset();
            $(item).css({
                top: offf.top + 'px'
            });
        }
    });
}

var time;
function menuHover(type, index) {
    $('#left-content .menu ul li').removeClass('hover');
    var item = $('#right-content .submenu .item[index=' + index + ']');

    if (type == 0) {
        $('#right-content .submenu .item, #right-content .model-menu').css('visibility', 'hidden');
        $(item).css('visibility', 'visible');
        if (navigator.userAgent.indexOf('MSIE 6.0') > -1) {

        }
        clearTimeout(time);
    }
    else {
        time = setTimeout(function () {
            $(item).css({
                visibility: 'hidden'
            });
        }, 700);
    }
}



function showModels(type) {
    var item = '#right-content .model-menu';
    if (type == 0) {
        $(item + ', #left-content .menu ul li[model=true], #left-content .menu ul li[model=true] a, #right-content .model-menu div, #right-content .model-menu h4, #right-content .model-menu span').mouseover(function () { clearTimeout(time); });
        $(item).css('visibility', 'visible');
        $('#right-content .submenu .item').css('visibility', 'hidden');
    }
    else if (type == 1) {
        time = setTimeout(function () {
            $(item).css({
                visibility: 'hidden'
            });
        }, 1500);
        $('#left-content .menu ul li[model=true]').removeClass('hover');
    }
}


function FillVendors(type, city, searchString) {
    var cityID = $('#' + city).val();
    if (cityID != "" && cityID != " ") {
        var SearchText = $('#' + searchString).val();
        $('#results').html('');
        $('#results').load('/Page/Vendors/Get.aspx?Type=' + type + '&CityID=' + cityID + '&Search=' + SearchText + ' #list', function () {
            var search = "";
            if ($('#' + searchString).val() != "" && $('#' + searchString).val() != ' ') {
                search = $('#' + searchString).val();
            }
            else search = $('#' + city + ' option:selected').text();
            if ($('#right-content div.vendor .results .item').length < 1) {
                $('.vendor h4').text('Sonuç Bulunamadı');
            }
            else
                $('.vendor h4').text("'" + search + "' araması için sonuçlar");

            $('#right-content div.vendor').pngFix();
        });
    }
    else {
        $('.vendor h4').text('Şehir seçiniz !');
    }
}

function Search(ID) {
    var text = $('#' + ID).val();
    document.location = '/Page/Search/?Text=' + text;
};

function controlRBL() {
    var list = $('.rbl');
    $(list).find('table').css('background', 'transparent');
    $(list).find('table').css('color', '#bababa');
    var retVal = true;
    $.each(list, function (i) {
        if ($(this).find('input:checked').width() == null) {
            $(this).children('table').css('background', '#ccc');
            $(this).children('table').css('color', '#000');
            slideNavigation('#' + $(this).attr('id'));
            retVal = false;
            return false;
        }
    });
    if (retVal) {
        $(list).children('table').css('background', 'transparent');
        $(list).children('table').css('color', '#bababa');
    }
    return retVal;
}

function SendForm(Type) {
    if (Type == "Appeal") {
        if (!CheckForm('#AppealForm', 'transparent', '#ccc', '#bababa', '#000'))
            return false;
        $(".result").text("Başvurunuz gönderiliyor...");
        $('input.btn').attr('disabled', 'disabled');
        FormPost("/Content/WebService/ClientSiteWebService.asmx/SendAppealForm", "#AppealForm", ".result");
    }
    else if (Type == "Contact") {
        if (!CheckForm('#ContactForm', 'transparent', '#ccc', '#bababa', '#000'))
            return false;
        else {
            $(".result").text("Başvurunuz gönderiliyor...");
            $('input.btn').attr('disabled', 'disabled');
            FormPost("/Content/WebService/ClientSiteWebService.asmx/SendContactFormWithSubject", "#ContactForm", ".result");
        }
    }
    else if (Type == "HR") {
        if (!CheckForm('#HRForm', 'transparent', '#ccc', '#bababa', '#000')) {
            return false;
        }
        else {
            if (controlRBL()) {
                $(".result").text("Başvurunuz gönderiliyor...!");
                $('input.btn').attr('disabled', 'disabled');
                FormPost("/Content/WebService/ClientSiteWebService.asmx/SendHRForm", "#HRForm", ".result");
            }
        }
    }
}

function FlashSlider(selector) {
    var images = $(selector + ' img.slide');
    $.each(images, function (i) {
        $(this).css({
            visibility: 'visible',
            zIndex: (i + 1),
            opacity: 0
        });
        if (i == 0) {
            $(this).animate({
                opacity: 1
            }, 1000);
        }

        $(this).attr('index', i);
    });
}

function slideAll(selector, index) {
    var images = $(selector + ' img.slide');
    if (index != 0) {
        var item = $(selector + ' img[index=' + index + ']');
        $(item).animate({
            opacity: 1
        }, 1000, function () {
            $(selector + ' img[index=' + (index - 1) + ']').css('opacity', '0');
        });
    }
    else {
        $(selector + ' img[index=' + index + ']').css('opacity', '1');
        var item = $(selector + ' img[index=' + (images.length - 1) + ']');
        $(item).animate({
            opacity: 0
        }, 1000);
    }
}

$(window).load(function () {


    $('#left-content .menu ul li').mouseover(function () { $(this).addClass('hover') });
    $('#left-content .menu ul li').mouseout(function () { $(this).removeClass('hover') });
    $('#left-content .search input[type=text]').focus(function () { if ($(this).val() == 'aranacak kelime') $(this).val(''); });
    $('#left-content .search input[type=text]').blur(function () { if ($(this).val() == '' || $(this).val() == ' ') $(this).val('aranacak kelime'); });
    $('#left-content .search input.btn').mouseover(function () { $(this).addClass('hover'); });
    $('#left-content .search input.btn').mouseout(function () { $(this).removeClass('hover'); });
    $('#right-content .submenu .item ul li').mouseover(function () { clearTimeout(time); $(this).addClass('hover'); });
    $('#right-content .submenu .item ul li').mouseout(function () {
        $(this).removeClass('hover');
        var parent = $(this).parent().parent();
        time = setTimeout(function () {
            $(parent).css({
                visibility: 'hidden'
            });
        }, 700);
    });

    $('#right-content .submenu .item').mouseout(function () { });
    $('#right-content .submenu .item').mouseover(function () { clearTimeout(time); });




    submenu();

    $('#right-content .model-menu, #right-content .model-menu div, #right-content .model-menu h4').mouseover(function () {
        $('#left-content .menu ul li[model=true]').addClass('hover');
        $('#right-content .submenu .item').css('visibility', 'hidden');
        clearTimeout(time);
    });
    $('#right-content .model-menu').mouseout(function () {
        time = setTimeout(function () {
            $('#right-content .model-menu').css({
                visibility: 'hidden',
                opacity: 1
            });
            $('#left-content .menu ul li[model=true]').removeClass('hover');
        }, 1000);
    });

    var ModelMenuWidth1 = 0;
    var ModelMenuWidth2 = 0;
    $.each($('#right-content .model-menu .type'), function (i) {
        $.each($(this).children('.model'), function (y) {
            if (i == 0)
                ModelMenuWidth1 = ModelMenuWidth1 + $(this).width() + 20;
            else if (i == 1)
                ModelMenuWidth2 = ModelMenuWidth2 + $(this).width() + 20;
        });
    });
    if (ModelMenuWidth1 >= ModelMenuWidth2)
        $('#right-content .model-menu').width(ModelMenuWidth1);
    if (ModelMenuWidth1 < ModelMenuWidth2)
        $('#right-content .model-menu').width(ModelMenuWidth2);

    $(document).pngFix();
});


function slideNavigation(navigate) {
    var speed = 1000;
    if ($.browser.opera) {
        $('html').animate({
            scrollTop: $(navigate).offset().top - 20
        }, speed);
    }
    else $('html,body').animate({
        scrollTop: $(navigate).offset().top - 20
    }, speed);
}

function NewsPager() {
    $('#right-content .news .paging div.page').mouseover(function () { $(this).addClass('hover'); });
    $('#right-content .news .paging div.page').mouseout(function () { $(this).removeClass('hover'); });
    $('#right-content .news .paging div.page').click(function () {
        $('#right-content .news .paging div.page').removeClass('active');
        $(this).addClass('active');
        $('#right-content .news .item').css('display', 'none');
        $('#right-content .news .item[index=' + $(this).attr('index') + ']').css('display', 'block');
    });

}

