﻿var YemUIparam = {
    selclass: "secili",
    etiket: "#etiketler",
    seletiket: "aktif",
    pasifetiket: "pasif",
    aktiftanim: "aktiftanim",
    pasiftanim: "pasiftanim"
};

var tiklamadurum = 0;
var YemUI = {
    secenekGetir: function (o) {

        $.ajax({
            type: "POST",
            url: $(o).attr("href"),
            beforeSend: function () {
                $('#icerikalani').html('<img src="Assets/img/tasarim/loading.gif" class="loading" />');
            },
            success: function (data) {
                $('#icerikalani').html(data);
            },
            complete: function () {
                YemUI.secenekIsaretle($(o).attr("rel"));
                //kolonesitle();
                YemUI.buttonlar(YemUI.siragetir());
            }
        });


        $('#aciklama span').removeClass('aktif');
        $('#aciklama span#' + $(o).attr("rel") + '-aciklama').addClass('aktif');
        YemUI.akordiyonAc($(o).attr("rel"));
    },
    secenekIsaretle: function (o) {
        var _temp = "";
        $.each($('#' + o + 'list li.' + YemUIparam.seletiket), function () {
            $('#icerikalani #' + o + ' #' + $(this).attr("id").replace("sk", "") + ' span').addClass(YemUIparam.selclass);
        });
    },
    etiketIsaretle: function (o) {
        var obj = $(o).find('span');
        if (obj.hasClass(YemUIparam.selclass)) {
            obj.removeClass(YemUIparam.selclass);
            YemUI.akordiyonmenu(o, 0);
        } else {
            obj.addClass(YemUIparam.selclass);
            YemUI.akordiyonmenu(o, 1);
        }
        //kolonesitle();
    },
    akordiyonmenu: function (o, p) {
        var akmenu = $(o).parent().attr('id');
        var x = $(o).attr('id');

        if ($(YemUIparam.etiket + ' .' + akmenu).length < 1) {
            $(YemUIparam.etiket).append('<div class="' + akmenu + ' aktiftanim">' + $(o).parent().attr("title") + ' (<span></span>)</div><ul class="clearfix" id="' + akmenu + 'list"></ul>');
        }
        if (p == 1) {
            if ($('ul#' + akmenu + 'list li#sk' + x).length > 0) {
                $('ul#' + akmenu + 'list li#sk' + x).addClass(YemUIparam.seletiket).removeClass(YemUIparam.pasifetiket);
            } else {
                var shorttxt = ($(o).attr("title").length > 25) ? ($(o).attr("title")).substring(0, 25) + "..." : $(o).attr("title");
                $('ul#' + akmenu + 'list').append('<li id="sk' + x + '" class="' + YemUIparam.seletiket + '" title="' + $(o).attr("title") + '"><span>' + shorttxt + '</span></li>');
            }
        } else {
            $('ul#' + akmenu + 'list li#sk' + x).removeClass(YemUIparam.seletiket).addClass(YemUIparam.pasifetiket);
        }
        $(YemUIparam.etiket + ' .' + akmenu + " span").text($('ul#' + akmenu + 'list li.' + YemUIparam.seletiket).length);
        YemUI.aramaKontrol();
    },
    akordiyonAc: function (o) {
        $(YemUIparam.etiket + ' ul').slideUp();
        $('#' + o + 'list').slideDown();
        $(YemUIparam.etiket + ' div').addClass(YemUIparam.pasiftanim).removeClass(YemUIparam.aktiftanim);
        $('.' + o).addClass(YemUIparam.aktiftanim).removeClass(YemUIparam.pasiftanim);

    },
    etiketEkleKaldir: function (o) {
        if ($(o).hasClass(YemUIparam.seletiket)) {
            $(o).removeClass(YemUIparam.seletiket).addClass(YemUIparam.pasifetiket);
            $('#icerikalani #' + $(o).attr("id").replace("sk", "") + ' span').removeClass(YemUIparam.selclass);
        } else {
            $(o).addClass(YemUIparam.seletiket).removeClass(YemUIparam.pasifetiket);
            $('#icerikalani #' + $(o).attr("id").replace("sk", "") + ' span').addClass(YemUIparam.selclass);
        }
        YemUI.aramaKontrol();
        var akmenu = ($(o).parent().prev().attr("class")).split(" ");
        var count = $('ul#' + akmenu[0] + 'list li.' + YemUIparam.seletiket).length;
        $(YemUIparam.etiket + ' .' + akmenu[0] + " span").text(count);

        if ($('#kolon3').hasClass('detay')) {
            var arr = "";
            $.each($('#etiketler li.aktif'), function () {
                arr = arr + $(this).attr("id").replace("sk", "") + ", ";
            });
            $('#secim').val(arr);
            $('#formdetay').submit();

        }

        if ($('#kolon3').hasClass('sonuclar')) {
            var arr = "";
            $.each($('#etiketler li.aktif'), function () {
                arr = arr + $(this).attr("id").replace("sk", "") + ", ";
            });

            $.ajax({
                type: "POST",
                url: "/UserControl/AramaYenile.aspx",
                data: "seciliKriter=" + arr,
                beforeSend: function () {
                    tiklamadurum = 1;
                    $('#aramasonuclari').html("<img src='Assets/img/tasarim/loading.gif' alt='' class='loading' />");
                },
                success: function (data) {
                    $('#aramasonuclari').html(data);
                },
                complete: function () {
                    var count = $('.sonucakordiyon ul li').length;
                    $('#basvuruGonderBtn span').text('(' + count + ')');
                    tiklamadurum = 0;
                }
            });

        }
    },
    aramaKontrol: function (p, s) {//p:this id, s:status		
        $('#etiketler li.aktif').length > 0 ? $('#aramayi-baslat').removeClass("pasif") : $('#aramayi-baslat').addClass("pasif");
    },
    onceki: function () {
        var aktiflink = YemUI.siragetir();
        $('#menu a:eq(' + (aktiflink - 1) + ')').click();
        YemUI.buttonlar(aktiflink - 1);
    },
    sonraki: function () {
        var aktiflink = YemUI.siragetir();
        $('#menu a:eq(' + (aktiflink + 1) + ')').click();
        YemUI.buttonlar(aktiflink + 1);
    },
    buttonlar: function (aktiflink) {
        (aktiflink) == 0 ? $('.onceki > span').removeClass('aktif').addClass('pasif') : $('.onceki > span').addClass('aktif').removeClass('pasif');
        (aktiflink) == ($('#menu a').length - 1) ? $('.sonraki > span').removeClass('aktif').addClass('pasif') : $('.sonraki > span').addClass('aktif').removeClass('pasif');
    },
    siragetir: function () {
        var _temp;
        var aktif = $('#icerikalani ul').attr("id");
        $.each($('#menu a'), function (index) {
            var x = $(this).attr("rel");
            if (x == aktif)
                _temp = index;
        });
        return _temp;
    },
    hepsinisec: function () {
        $.each($('#icerikalani li'), function () {
            if ($(this).find('span.secili').length < 1)
                $(this).click();
        });
    },
    hepsinitemizle: function () {
        $.each($('#icerikalani li'), function () {
            if ($(this).find('span.secili').length > 0)
                $(this).click();
        });
    },
    aramabaslat: function () {
        var arr = "";
        if ($('#etiketler li.aktif').length > 0) {
            $.each($('#etiketler li.aktif'), function () {
                arr = arr + $(this).attr("id").replace("sk", "") + ", ";
            });

            $('#secim').val(arr);
            $('#form1').submit();
        }


    }
};


var yui = YemUI;

//function kolonesitle() {
//    $("#kolon2, #kolon3, #yataydoseme").css("height", "");
//    var hKolon1 = $("#tanimlar").height();
//    var icerikalani = $("#icerikalani").height();
//    var hKolon2 = $("#kolon2").height();
//    var hKolon3 = $("#kolon3").height();
//    var hYataydoseme = $("#yataydoseme").height();

//    if (hKolon2 > hKolon3) {
//        $("#kolon3").css("height", hKolon2 + "px");
//        // $("#yataydoseme").css("height", hKolon2 - 35 + "px");
//        // alert("2>3")
//    } else {
//        $("#kolon2").css("height", hKolon3 + "px");
//        $("#yataydoseme").css("height", hKolon3 + "px");
//        //  alert("3>2")
//    }


//}



function movie(type, video, width, height) { //constructor
    this.type = type;
    this.video = video;
    this.width = width;
    this.height = height;
}

function player(p1, p2, p3, p4) {

    var videocontent = "";
    v = new movie(p1, p2, p3, p4);
    switch (v.type) {
        case "flv":
            $('#content').html('<div id="flv"></div>');
            var flashvars = { file: v.video, autostart: 'false' };
            var params = { allowfullscreen: 'true', allowscriptaccess: 'always' };
            var attributes = { id: 'player1', name: 'player1' };
            swfobject.embedSWF('/Assets/video/player.swf', 'flv', v.width, v.height, '9.0.115', 'false', flashvars, params, attributes);
            break;
        case "mpg":
            videocontent = ' <object id="MediaPlayer1" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" type="application/x-oleobject" width="' + v.width + '" height="' + v.height + '">' +
            '<param name="fileName" value="' + v.video + '">' +
            '<param name="animationatStart" value="true">' +
            '<param name="transparentatStart" value="true">' +
            '<param name="autoStart" value="false">' +
            '<param name="showControls" value="true">' +
            '<param name="Volume" value="-450">' +
            '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' + v.video + '" name="MediaPlayer1" width="' + v.width + '" height="' + v.height + '" autostart="0" showcontrols="1" volume="-450">' +
        '</object>';
            $('#content').html(videocontent);
            break;
        case "wmv":
            videocontent = ' <object id="MediaPlayer1" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" type="application/x-oleobject" width="' + v.width + '" height="' + v.height + '">' +
            '<param name="fileName" value="' + v.video + '">' +
            '<param name="animationatStart" value="true">' +
            '<param name="transparentatStart" value="true">' +
            '<param name="autoStart" value="false">' +
            '<param name="showControls" value="true">' +
            '<param name="Volume" value="-450">' +
            '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' + v.video + '" name="MediaPlayer1" width="' + v.width + '" height="' + v.height + '" autostart="0" showcontrols="1" volume="-450">' +
        '</object>';
            $('#content').html(videocontent);
            break;
        case "mov":
            videocontent = '<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' + v.width + '" height="' + v.height + '" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">' +
					'<param name="src" value="' + v.video + '">' +
					'<param name="qtsrc" value="' + v.video + '">' +
					'<param name="autoplay" value="false">' +
					'<param name="loop" value="false">' +
					'<param name="controller" value="true">' +
					'<embed src="' + v.video + '" qtsrc="' + v.video + '" width="' + v.width + '" height="' + v.height + '" autoplay="false" loop="false" controller="true" pluginspage="http://www.apple.com/quicktime/"></embed>' +
					'</object>';
            $('#content').html(videocontent);
            break;
        default:
    }
}

$(function () {
    jQuery.cookie = function (key, value, options) {

        if (arguments.length > 1 && (value === null || typeof value !== "object")) {
            options = jQuery.extend({}, options);

            if (value === null) {
                options.expires = -1;
            }

            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setDate(t.getDate() + days);
            }

            return (document.cookie = [
                    encodeURIComponent(key), '=',
                    options.raw ? String(value) : encodeURIComponent(String(value)),
                    options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
                    options.path ? '; path=' + options.path : '',
                    options.domain ? '; domain=' + options.domain : '',
                    options.secure ? '; secure' : ''
                ].join(''));
        }

        // key and possibly options given, get cookie...
        options = value || {};
        var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
        return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
    };

    if ($('#showcasecarousel').length > 0) {
        $('#showcasecarousel').bxSlider({
            infiniteLoop: false,
            auto: true,
            pager: true,
            controls: false,
            pause: 8000
        });
    }

    $('#etiketler li.aktif').length > 0 ? $('#aramayi-baslat').removeClass("pasif") : $('#aramayi-baslat').addClass("pasif");

    $("#ibirthday")
            .focus(function () {
                var mask = "99/99/9999";
                $(this).unmask(mask).select().mask(mask);
            });

    $(".sonucakordiyon ul li h2:odd").addClass("row");

    $(".sonucakordiyon ul li h2 div").live('click', function () {
        if ($(this).parent().parent().hasClass('aktifsonuc')) {
            $(".sonucakordiyondetay").slideUp();
            $('.sonucakordiyon ul li').removeClass("aktifsonuc");
        } else {
            $(".sonucakordiyondetay").slideUp();
            $('.sonucakordiyon ul li').removeClass("aktifsonuc");
            $(this).parent().next(".sonucakordiyondetay").slideDown();
            $(this).parent().parent().addClass('aktifsonuc');
        }
    });

    $(".sonucakordiyon .checkbox").live('click', function () {
        if ($(this).parent().hasClass("secili")) {
            $(this).parent().removeClass("secili");
        }
        else {
            $(this).parent().addClass("secili");
        }
        $('#basvuruGonderBtn span').text('(' + $('h2.secili').length + ')');
    });



    $.load = function () {
        var link = $('#menu li a:first').attr("href");
        $('#menu li a:first').addClass("secilitanim");
        $('#icerikalani').load(link, function () {
            if ($('#kolon3').attr('class') == "") {
                if ($('#etiketler .menulink1').length > 0) {
                    $('#etiketler .menulink1').removeClass(YemUIparam.pasiftanim).addClass(YemUIparam.aktiftanim);
                    $('#etiketler #menulink1list').show();
                    yui.secenekIsaretle('menulink1');
                }
            }
            //kolonesitle();
        });
    }

    $.load();

    $('.menulink').live('click', function (e) {
        e.preventDefault();
        $('.menulink').removeClass('secilitanim');
        $(this).addClass('secilitanim');
        yui.secenekGetir($(this));

    });

    $('#icerikalani li').live('click', function (e) {
        $('#aramamavicerceve').remove();
        yui.etiketIsaretle(this);
    });

    $('#etiketler div').live('click', function () {
        var link = ($(this).attr("class")).split(" ");
        $('#menu a[rel=' + link[0] + ']').click();
        //kolonesitle();
    });

    $('#etiketler li').live('click', function () {
        if ($("#kolon3").hasClass("sonuclar")) {
            if (tiklamadurum == 0)
                yui.etiketEkleKaldir($(this));
        } else {
            yui.etiketEkleKaldir($(this));
        }
    });

    $('.onceki span').live('click', function () {
        if ($(this).hasClass('aktif')) {
            yui.onceki();
        }
    });
    $('.sonraki span').live('click', function () {
        if ($(this).hasClass('aktif')) {
            yui.sonraki();
        }
    });

    $('.selectall a').click(function (e) {
        e.preventDefault();
        $(this).attr("href") == "hepsini-sec" ? yui.hepsinisec() : yui.hepsinitemizle();
    });

    $('#aramayi-baslat').click(function () {
        yui.aramabaslat();
    });

    $('.sonuclar #etiketler div, .detay #etiketler div').live('click', function () {
        $('#kolon3 #etiketler div').removeClass("aktiftanim").addClass("pasiftanim");
        $('#kolon3 #etiketler div').next("ul").slideUp();
        $(this).addClass('aktiftanim');
        $(this).next("ul").slideDown();
    });

    $('#aramaSonuclarinaDonBtn').click(function (e) {
        e.preventDefault();
        var arr = "";
        $.each($('#etiketler li.aktif'), function () {
            arr = arr + $(this).attr("id") + ", ";
        });
        $('#secim').val(arr);
        $('#formdetay').submit();
    });

    $('#basvuruGonderBtn').live('click', function (e) {
        e.preventDefault();
        var arr = "";
        $.each($('.sonucakordiyon h2.secili'), function () {
            arr = arr + $(this).attr("id") + ", ";
        });
        $('#formdata').val(arr);
        $('#basvuruform').submit();
    });


    /*sehirler selectbox*/
    $('#icity').click(function () {
        if ($("#icitylist").hasClass("show")) {
            $('#icitylist').hide();
            $('#icitylist').removeClass("show");
        } else {
            $('body').append('<div id="hiddenarea"></div>');
            $('#isektorlist, #imesleklist').hide();
            $('#isektorlist, #imesleklist').removeClass("show");
            $('#icitylist').show().addClass("show");
            if ($('#icitylist .jScrollPaneContainer').length < 1)
                $('#pane1').jScrollPane({ showArrows: true, scrollbarWidth: 23 });

        }
    });


    $('#pane1 a').live('click', function () {
        $('#icity').text($(this).text());
        $('#hiddenicity').val($(this).text());
        $('#hiddenicity').next('span').remove();
        $('#icity').click();
    });

    /*sektor selectbox*/
    $('#isektor').click(function () {
        if ($("#isektorlist").hasClass("show")) {
            $('#isektorlist').hide();
            $('#isektorlist').removeClass("show");
        } else {
            $('body').append('<div id="hiddenarea"></div>');
            $('#icitylist, #imesleklist').hide();
            $('#icitylist, #imesleklist').removeClass("show");
            $('#isektorlist').show().addClass("show");
            if ($('#isektorlist .jScrollPaneContainer').length < 1)
                $('#pane2').jScrollPane({ showArrows: true, scrollbarWidth: 23 });

        }
    });


    $('#pane2 a').live('click', function () {
        $('#isektor').text($(this).text());
        $('#hiddenisektor').val($(this).text());
        $('#hiddenisektor').next('span').remove();
        $('#isektor').click();
    });



    //meslek selectbox
    $('#imeslek').click(function () {
        if ($("#imesleklist").hasClass("show")) {
            $('#imesleklist').hide();
            $('#imesleklist').removeClass("show");
        } else {
            $('body').append('<div id="hiddenarea"></div>');
            $('#icitylist, #isektorlist').hide();
            $('#icitylist, #isektorlist').removeClass("show");
            $('#imesleklist').show().addClass("show");
            if ($('#imesleklist .jScrollPaneContainer').length < 1)
                $('#pane3').jScrollPane({ showArrows: true, scrollbarWidth: 23 });

        }
    });


    $('#pane3 a').live('click', function () {
        $('#imeslek').text($(this).text());
        $('#hiddenimeslek').val($(this).text());
        $('#hiddenimeslek').next('span').remove();
        $('#imeslek').click();
    });



    $("#hiddenarea").live('click', function () {
        if ($(".scroll-pane").length > 0) {
            $('#icitylist, #isektorlist').hide();
            $('#icitylist, #isektorlist').removeClass("show");
            $("#hiddenarea").remove();
        }

    });

    $('#fotogaleri li a').live('click', function (e) {
        e.preventDefault();
        var pic = $(this).attr('href');
        var img = new Image();
        $(img).load(function () {
            $(this).hide();
            $('#secilifoto #foto').text('').append(this);
            $(this).fadeIn();
        }).error(function () {
            $('#secilifoto #foto').text("hata var");
        }).attr('src', pic);
        $('#secilifoto #title').text($(this).attr("title"));
        gallery.oklariguncelle(gallery.siragetir());
    });

    $('#videocarousel a').click(function (e) {
        e.preventDefault();
        _vars = ($(this).attr("rel")).split(',');
        player(_vars[0], _vars[1], _vars[2], _vars[3]);
    });

    //    $('#pdfKaydetBtn').click(function (e) {
    //        e.preventDefault();
    //        $('#pdfcikart').submit();
    //    });

    $('#icaptchayenile').live('click', function () {
        $.ajax({ type: "POST",
            url: "/usercontrol/captcha.aspx",
            success: function (data) {
                var date = new Date();
                var t = date.getSeconds() + "" + date.getMilliseconds() + "" + date.getMilliseconds();
                $('#captcha').html('<img id="captcharesimi" width="100" height="60" name="captcharesimi" src="/usercontrol/captcha.aspx?rn=' + t + '" />');
            }
        });
    });

    $('#ibirthday').keyup(function () {
        if ($('#ibirthday').val().length > 0) {
            if (!isDate($('#ibirthday').val())) {
                $('#ibirthday').next('span').html('<label for="ibirthday" class="error">' + $('#ibirthday').attr("rel") + '</label>');
            } else {
                $('#ibirthday').next('span').html('');
            }
        }
    });

    var submitstatus = 0;
    $.validate = function (field, txt, param) {
        var durum = true;
        var mailfilter = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        if ($('#' + field).val() == "") {
            //$('#' + field).addClass('error').focus();
            $('#' + field).next('span').html('<label for="' + field + '" class="error">' + txt + '</label>');
            durum = false;
        }

        if (durum == true && param == "email" && !mailfilter.test($('#' + field).val())) {
            //$('#' + field).addClass('error').focus();
            $('#' + field).next('span').html('<label for="' + field + '" class="error">' + $('#' + field).attr("rev") + '</label>');
            durum = false;
        }

        if (durum == true && param == "rakam" && $('#' + field).val().length < 10) {
            //$('#' + field).addClass('error').focus();
            $('#' + field).next('span').html('<label for="' + field + '" class="error">' + $('#' + field).attr("rev") + '</label>');
            durum = false;
        }

        if (durum == true && $('#ibirthday').val().length > 0) {
            if ($('#ibirthday').val().length < 10 || !isDate($('#ibirthday').val())) {
                $('#ibirthday').next('span').html('<label for="ibirthday" class="error">' + $('#ibirthday').attr("rel") + '</label>');
                durum = false;
            }
        }

        if (durum == true && param == "captcha" && submitstatus == 0) {
            $.ajax({ type: "POST",
                url: "/UserControl/CaptchaKontrol.aspx",
                dataType: "html",
                data: "icaptcha=" + $('#' + field).val(),
                success: function (data) {
                    if (data != "true") {
                        $('#' + field).next('span').html('<label for="' + field + '" class="error">' + $('#' + field).attr("rev") + '</label>');
                        var date = new Date();
                        var t = date.getSeconds() + "" + date.getMilliseconds() + "" + date.getMilliseconds();
                        $('#captcha').html('<img id="captcharesimi" width="100" height="60" name="captcharesimi" src="/usercontrol/captcha.aspx?rn=' + t + '" />');
                        durum = false;
                    }
                }, complete: function () {
                    if (durum == true) {
                        if ($('form').attr("id") == "iletisimform") {
                            var msg;
                            $('#basarilisonuc').hide();
                            $('#basarisizsonuc').hide();
                            $.ajax({ type: "POST",
                                url: "/UserControl/iletisimgonder.aspx",
                                dataType: "html",
                                data: $('#iletisimform').serialize(),
                                beforeSend: function () {
                                    $('#iletisimformGonderBtn').attr("disabled", "disabled");
                                    $('#iletisimformGonderBtn').next('span').addClass("sendload");
                                },
                                success: function (data) {
                                    var date = new Date();
                                    var t = date.getSeconds() + "" + date.getMilliseconds() + "" + date.getMilliseconds();
                                    if (data == "1") {
                                        $.prettyPhoto.open('#durumpenceresi', "", "");
                                        $('#basarilisonuc').show();
                                        $('input, textarea').val('');
                                        $('.error').text('');
                                        $('#captcha').html('<img id="captcharesimi" width="100" height="60" name="captcharesimi" src="/usercontrol/captcha.aspx?rn=' + t + '" />');
                                    } else {
                                        $.prettyPhoto.open('#durumpenceresi', "", "");
                                        $('#captcha').html('<img id="captcharesimi" width="100" height="60" name="captcharesimi" src="/usercontrol/captcha.aspx?rn=' + t + '" />');
                                        $('#basarisizsonuc').show();
                                    }
                                },
                                complete: function () {
                                    $('#iletisimformGonderBtn').removeAttr("disabled");
                                    $('#iletisimformGonderBtn').next('span').removeClass("sendload");
                                }
                            });
                        }
                        else
                            $('#contactform').submit();
                    }
                }
            });
        }

        if (durum == false)
            submitstatus += 1;

    }

    $('form input, form textarea').bind('focus keydown', function () {
        $(this).next('span').text('');
        $(this).removeClass('error');
    });


    $('#iletisimformGonderBtn').click(function (e) {
        e.preventDefault();
        submitstatus = 0;
        $.validate("iname", $("#iname").attr("rel"), "");
        $.validate("ilastname", $("#ilastname").attr("rel"), "");
        $.validate("ifirma", $("#ifirma").attr("rel"), "");
        $.validate("iemail", $("#iemail").attr("rel"), "email");
        $.validate("iphone", $("#iphone").attr("rel"), "rakam");
        $.validate("imessage", $("#imessage").attr("rel"), "");
        $.validate("icaptcha", $("#icaptcha").attr("rel"), "captcha");
        $.validate("imeslek", $("#imeslek").attr("rel"), "");
        $.validate("igorev", $("#igorev").attr("rel"), "");
        $.validate("ifirmaphone", $("#ifirmaphone").attr("rel"), "rakam");

    });


    $('#formuGonderBtn').click(function (e) {
        e.preventDefault();
        submitstatus = 0;
        $.validate("iname", $("#iname").attr("rel"), "");
        $.validate("ilastname", $("#ilastname").attr("rel"), "");
        $.validate("iemail", $("#iemail").attr("rel"), "email");
        $.validate("iphone", $("#iphone").attr("rel"), "rakam");
        $.validate("imobilephone", $("#imobilephone").attr("rel"), "rakam");
        $.validate("hiddenicity", $("#hiddenicity").attr("rel"), "");
        $.validate("ifirma", $("#ifirma").attr("rel"), "");
        $.validate("hiddenisektor", $("#hiddenisektor").attr("rel"), "");
        $.validate("hiddenimeslek", $("#hiddenimeslek").attr("rel"), "");
        $.validate("imessage", $("#imessage").attr("rel"), "");
        $.validate("icaptcha", $("#icaptcha").attr("rel"), "captcha");
        $.validate("imeslek", $("#imeslek").attr("rel"), "");
        $.validate("igorev", $("#igorev").attr("rel"), "");


    });

    $('#tamam').live('click', function () {
        $.prettyPhoto.close();
    });


    $('.aramayi-baslat').live('click', function () {
        window.parent.location.href = "/arama";
    });


    $('textarea[maxlength]').keyup(function () {
        var limit = parseInt($(this).attr('maxlength'));
        var text = $(this).val();
        var chars = text.length;
        if (chars > limit) {
            var new_text = text.substr(0, limit);
            $(this).val(new_text);
        }
    });


    if ($.cookie("tema") != null) {
        var imgsrc = $.cookie("tema");
        var path = "url(/Assets/img/tema/" + imgsrc + ")";
        if ($("body").attr("class") != "fotogaleri" || $("body").attr("class") != "videogaleri") {
            $("body").css("background-image", path);
        }
        // $("#tema").attr("src", "/Assets/img/tema/" + imgsrc);
        $('#temaDegistir a[rel=' + imgsrc + '] span').addClass("secilitema");
    } else {
        $('#temaDegistir a span:first').addClass("secilitema");
    }

    if ($("body").attr("class") != "fotogaleri" || $("body").attr("class") != "videogaleri") {
        $('.tema').live('click', function () {
            var imgsrc = $(this).attr("rel");
            var path = "url(/Assets/img/tema/" + imgsrc + ")";
            $('body').css("background-image", path);
            $.cookie("tema", imgsrc);
            $('#temaDegistir a span').removeClass("secilitema");
            $('#temaDegistir a[rel=' + imgsrc + '] span').addClass("secilitema");
        });
    }


    if ($('#fotocarousel').length > 0 && $('#fotocarousel li').length > 5) {
        jQuery('#fotocarousel').jcarousel();
    }

    if ($('#videocarousel').length > 0 && $('#videocarousel li').length > 5) {
        jQuery('#videocarousel').jcarousel();
    }

    if ($('#logocarousel').length > 0) {
        jQuery('#logocarousel').jcarousel({ auto: 5, wrap: 'circular', animation: 'slow', wrap: 'last' });
    }

    function mycarousel_initCallback(carousel) {
        jQuery('.jcarousel-control a').bind('click', function () {
            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
            return false;
        });
    };


    var gallery = {
        oklariolustur: function () {
            var arrows = '<div id="geri"></div><div id="ileri"></div><span class="ok geri"> < geri</span> <span class="ok ileri">ileri > </span>';
            $('#secilifoto').prepend(arrows);
            gallery.oklariguncelle(gallery.siragetir());
        },
        geri: function () {
            var itemindex = gallery.siragetir();
            if (itemindex > 0) {
                itemindex -= 1;
                $('#fotogaleri a:eq(' + itemindex + ')').click();
            }
            gallery.oklariguncelle(itemindex);
        },
        ileri: function () {
            var itemindex = gallery.siragetir();
            if (itemindex < ($('#fotogaleri li').length - 1)) {
                itemindex += 1;
                $('#fotogaleri a:eq(' + itemindex + ')').click();
            }
            gallery.oklariguncelle(itemindex);
        },
        oklariguncelle: function (i) {
            i == 0 ? $('#geri, .geri').addClass("butongizle") : $('#geri, .geri').removeClass("butongizle");
            i == ($('#fotogaleri li').length - 1) ? $('#ileri').addClass("butongizle") : $('#ileri').removeClass("butongizle");
        },
        siragetir: function () {
            var _temp;
            var aktif = $('#foto img').attr("src");
            $.each($('#fotogaleri li a img'), function (index) {
                var x = $(this).attr("src");
                if (x == aktif)
                    _temp = index;
            });
            return _temp;
        }

    }

    if ($('#fotogaleri li').length > 1) {
        gallery.oklariolustur();
    }

    $('#geri, .geri').hover(function () {
        $(".geri").animate({
            opacity: 0.9
        }, { queue: false, duration: 200 });
    }, function () {
        $(".geri").animate({
            opacity: 0
        }, { queue: false, duration: 200 });
    });

    $('#ileri, .ileri').hover(function () {
        $(".ileri").animate({
            opacity: 0.9
        }, { queue: false, duration: 200 });
    }, function () {
        $(".ileri").animate({
            opacity: 0
        }, { queue: false, duration: 200 });
    });

    $('#geri, .geri').live('click', function () {
        gallery.geri();
    });


    $('#ileri, .ileri').live('click', function () {
        gallery.ileri();
    });

});


function isNumberKey(evt) {
    var e = evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;

    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function nokey(evt) {
    return false;
}


var dtCh = "/";
var minYear = 1900;
var maxYear = 9999;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function isDate(dtStr) {
    if (dtStr.length < 10) {
        return false;
    }
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strDay = dtStr.substring(0, pos1)
    var strMonth = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        return false
    }
    return true
}

function ValidateForm() {
    var dt = document.frmSample.txtDate
    if (isDate(dt.value) == false) {
        dt.focus()
        return false
    }
    return true
}

function ie6close() {
    $.prettyPhoto.close();
}
