$(document).ready(function(){
	$(".toggleCatList").click(function(){
		var catList = $("div.category-list");
		var status = catList.height();
		if (status == 550) {
			catList.animate({'height': "0px"}).hide('fast');
		}
		else{
			catList.show().animate({'height':'550px'});
		}
		
	});
})


 function validateEmail(email)
    {
     //alert(email);
     var re = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
     var re2 = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
     var re3 =/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
     var re4 = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
     return email.match( re4 );
    }


function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}


(function($) {

    $(document).ready(function() {
        
       
        var otherCitiesContainer = $('#other-cities-container');
        var showCityElement = $('#show-other-cities');
        showCityElement.hover(function(){
           otherCitiesContainer.show();
        });
        
        showCityElement.mouseleave(function(){
           otherCitiesContainer.hide();
        });
        
        otherCitiesContainer.hover(function(){
            otherCitiesContainer.show();
        });
        
        otherCitiesContainer.mouseleave(function(){
            otherCitiesContainer.hide();
        });
        
        
        
        
                

        $('#crm-form-set').submit(function(event) {
            
            event.preventDefault();

            var user_mail = $('#crmEmail').val();
            //alert( user_mail );
            var user_city = $('#crm-form-city').val();
            
            if( user_mail != ''
                && user_mail != 'E-Posta Adresiniz'
                && validateEmail(user_mail)
                && user_city > 0 ){

                this.submit();
                return true;
            }else{
                if( user_mail == ''
                    || !validateEmail(user_mail) ){

                    $('#crmEmail').css('color', 'red');
                    $('#crmEmail').fadeOut(450).fadeIn(450).fadeOut(450).fadeIn(450);
                    $('#crmEmail').focus();
                }

                if( user_city < 0
                        || user_city == ''){

                    $('#crm-form-city').css('color', 'red');
                    $('#crm-form-city').fadeOut(450).fadeIn(450).fadeOut(450).fadeIn(450);
                    $('#crm-form-city').focus();
                }

                return false;
            }

        });
        
        
        $('#member-popup').submit(function(event) {
            
            event.preventDefault();

            var user_mail = $('#mp-mail').val();
            //alert( user_mail );
            var user_city = $('#mp-city').val();
            
            if( user_mail != ''
                && user_mail != 'E-Posta Adresiniz'
                && validateEmail(user_mail)
                && user_city > 0 ){

                this.submit();
                return true;
            }else{
                if( user_mail == ''
                    || !validateEmail(user_mail) ){

                    $('#mp-mail').css('color', 'red');
                    $('#mp-mail').fadeOut(450).fadeIn(450).fadeOut(450).fadeIn(450);
                    $('#mp-mail').focus();
                }

                if( user_city < 0
                        || user_city == ''){

                    $('#mp-city').css('color', 'red');
                    $('#mp-city').fadeOut(450).fadeIn(450).fadeOut(450).fadeIn(450);
                    $('#mp-city').focus();
                }

                return false;
            }

        });


    
        var existingUser = $.cookie('__fc_user');
        var previousSearch = $.cookie('__usrc');
        
        var src = getParameterByName('src');

        if( ( src == 'search' || previousSearch == 'search' ) && !existingUser ){

            //alert( existingUser );

            //$('.interface-box-open').hide();
            $('.new-interface-box').hide();

            modalWin = $(".new-adwords-box").modal({
                                    overlayClose:false,
                                    opacity: 70,
                                    Height: 898,
                                    Width: 215
                                    });
        }else{

            var formStatus = $.cookie('formStatus');
            if (formStatus == "close") {
                    $('.interface-box-open').show();
                    $('.adwords-box-open').show();
                    $('.new-interface-box').hide();
            }
            else{
                    $('.interface-box-open').hide();
                    $('.adwords-box-open').hide();
                    $('.new-interface-box').show();
            }

            $("#openForm").click(function(){
                    $('.interface-box-open').hide();
                    $('.adwords-box-open').hide();
                    $('.new-interface-box').show();
                    $.cookie('formStatus', 'open', {expires: 365} );
            });
            $("#closeForm").click(function(){
                    $('.interface-box-open').show();
                    $('.adwords-box-open').show();
                    $('.new-interface-box').hide();
                    $.cookie('formStatus', 'close', {expires: 365} );
            });

            if( previousSearch == 'searchRegistered' ){

                $('.new-interface-box').hide();
                $('.adwords-box-open').show();
                
            }

        }




        //modal patlat:
        $('#seo-pop').click(function(){

            modalWin = $("#footer-pop").modal({
                                        overlayClose:true,
                                        opacity: 50,
                                        minHeight: 390,
                                        minWidth: 370
                                        });

        });


    var onceClosed = $.cookie('__fc_no_popup');

    $(document).ready(function() {
        
        var logMsg1 = "FırsatClub'a Giriş Yapın";
        var logMsg2 = "FırsatClub'a giriş yaparak <b>tercih ettiğiniz</b> kategorileri düzenleyebilirsiniz.";
        
        var regMsg1 = "Fırsat Club'a Üye Olun, İndirimleri Kaçırmayın!";
        var regMsg2 = "Fırsat Club'a üye olarak, <strong>tercih ettiğiniz türden</strong> fırsatları tek noktadan takip edin.";

        if( !existingUser && onceClosed != 'yes' ){

            modalWin = $("#landing-box").modal({
                overlayClose:false,
                opacity: 60,
                onClose: function () {
                    $.cookie('__fc_no_popup', 'yes', { expires: 365, path: '/', domain: 'firsatclub.com' });
                    $('#info-area').html(' <a href="#" class="show-register" id="reg1">FırsatClub\'a Üye Olun </a>&nbsp; veya &nbsp; <a href="#" class="show-register" id="log1">Giriş Yapın</a>');
                    $.modal.close(); // must call this!
                    $('.show-register').bind('click', function(event) {
                         showReg(event);
                    });
                }
            });

        }
        
        if( ($('.user-profile').html() == null ) || ($('.user-profile').html().trim().length < 1)){
                
            $('#info-area').html(' <a href="#" class="show-register" id="reg1">FırsatClub\'a Üye Olun </a>&nbsp; veya &nbsp; <a href="#" class="show-register" id="log1">Giriş Yapın</a>');

            $('.show-register').bind('click', function(event) {
                     showReg(event);
            });
        }
       
       
       
        

        $('.show-register').click(function(event) {
            event.preventDefault();
            //console.log("hello world:" + event.target.id );
            
            showReg(event);
        });

        function showReg(event){
            $('#returnToIndexStatus').val('0');
            
            var clickSrc = event.target.id;
            
            if( clickSrc == 'log1' ){
                
                $('#pop-msg1').html(logMsg1);
                $('#pop-msg2').html(logMsg2);
                
            }else{
                
                $('#pop-msg1').html(regMsg1);
                $('#pop-msg2').html(regMsg2);
                
            }
            
            
            //console.log("hello world:" + clickSrc );
            modalWin = $("#landing-box").modal({
                overlayClose:false,
                opacity: 60,
            });

        }

    });

        
       
/*
            modalWin = $("#landing-box").modal({
                                        overlayClose:false,
                                        opacity: 60
                                        });

       
  */      
        




/**
        var cookEmail = $.cookie('email-kayit-adres');
        var cookCity =  $.cookie('email-kayit-sehir');
        if( cookEmail != null && validateEmail( cookEmail )  ){
            $("#gatherEmail").hide();
            $(".kayitli-kullanici").html( cookEmail +  " &nbsp;&nbsp;|&nbsp;&nbsp; " + cookCity );
            $("#email-kayit-cookie").show();

        }

        $('#gatherEmail').submit(function() {
            $('.processForm').trigger('click');
            return false;
        });


        $('.processForm').click(function (){
            //alert("deneme?");
            var user_mail = $('#mail').val();
            var user_city = $('#email-kayit-sehir').val();

            if( validateEmail( user_mail ) ){

                if( user_city == -1 ){

                    $("#gatherEmail").hide();
                    $("#email-kayit-sehir-hata").show();
                    setTimeout( "$('#email-kayit-sehir-hata').hide()", 1700  );
                    setTimeout( "$('#gatherEmail').show();", 1840  );
                }else{

                    $.post("http://www.firsatclub.com/a/save.php", $("#gatherEmail").serialize());
                    //modalWin.close();
                    $("#gatherEmail").hide();
                    $("#email-kayit-tamam").show();

                    $.cookie('email-kayit-adres', user_mail, { expires: 365 } );
                    $.cookie('email-kayit-sehir', user_city, { expires: 365 } );
                }


            }else{

                $("#gatherEmail").hide();
                $("#email-kayit-eposta-hata").show();
                setTimeout( "$('#email-kayit-eposta-hata').hide()", 1500  );
                setTimeout( "$('#gatherEmail').show();", 1640  );
            }

        });

        $('.processForm').submit(function() {
            return false;
        });

        $('.kullanici-degistir').click(function(){
            $.cookie('email-kayit-adres', null );
            $.cookie('email-kayit-sehir', null );
            $("#email-kayit-cookie").hide();
            $('#gatherEmail').show();
        });
**/
    });

})(jQuery)

