$.ajaxSetup({ 
    type: "POST",
    dataType: "html",
    contentType: "application/x-www-form-urlencoded;charset=utf-8"
});

function JQAjaxForm(idFormControl, idAjaxContent){
    $(document).ready(function() {
        if(typeof(idAjaxContent) != 'object') { idAjaxContent = document.getElementById(idAjaxContent); }
        if(typeof(idFormControl) != 'object') { idFormControl = document.getElementById(idFormControl); }
        
        $(idFormControl).ajaxForm({ 
            target: idAjaxContent,   // target element(s) to be updated with server response 
            //timeout:   3000,
            beforeSend: function(){
                JQAjaxLoader(idAjaxContent);
            },  // pre-submit callback
            success: function(html){ // post-submit callback 
                $(idAjaxContent).html(html);
            }
        });
    });
}

function JQAjax(szController, idAjaxContent, bLoader, bAppend){
    //$(document).ready(function() {
        bLoader = (typeof(bLoader) == 'undefined' ? 1 : bLoader);
        bAppend = (typeof(bAppend) == 'undefined' ? 0 : bAppend);
        
        if(typeof(idAjaxContent) != 'object') { idAjaxContent = document.getElementById(idAjaxContent); }
            
        var timestamp = Number(new Date());
        
        $.ajax({
            url: "/" + szController + '/////' + timestamp,
            beforeSend: function(){
                if(bLoader){
                    JQAjaxLoader(idAjaxContent);
                }
            },
            success: function(html){
                if(bAppend){
                    $(idAjaxContent).append(html);
                    $(idAjaxContent).fadeIn(300);
                }else{
                    $(idAjaxContent).html(html);
                }
                    
                JQColorBoxReady();
                ResizeColorBox();
            }
        });
    //});
}

function JQAjaxTimer(szController, idAjaxContent, nTime, bLoader){
    nTime   = typeof(nTime) != 'undefined' ? (nTime <= 0 ? 32000 : nTime) : 32000;
    bLoader = typeof(bLoader) != 'undefined' ? bLoader : 1;
    
    if(typeof(idAjaxContent) != 'object') { idAjaxContent = document.getElementById(idAjaxContent); }
        
    var timestamp = Number(new Date());
    
    setInterval(function(){
        $.ajax({
            url: "/" + szController + '/////' + timestamp,
            beforeSend: function(){
                if(bLoader){
                    JQAjaxLoader(idAjaxContent);
                }
            },
            success: function(html){
                $(idAjaxContent).html(html);
                //$(idAjaxContent).fadeIn(500);
            }
        });
    },nTime);
}

function JQAjaxEMailForm(idFormControl){
    $(document).ready(function() {
        idAjaxContent = document.getElementById('index');
        if(typeof(idFormControl) != 'object') { idFormControl = document.getElementById(idFormControl); }
        
        $(idFormControl).ajaxForm({ 
            target: idAjaxContent,   // target element(s) to be updated with server response 
            //timeout:   3000,
            beforeSend: function(){
                JQAjaxLoader(idAjaxContent);
            },  // pre-submit callback
            success: function(html){ // post-submit callback 
                var timestamp = Number(new Date());
                alert('test');
                setInterval(function(){
                    $.ajax({
                        url: '/admin/ddadmin/send_email/////' + timestamp,
                        beforeSend: function(){
                        },
                        success: function(html){
                            $(idAjaxContent).val(html);
                        }
                    });
                },12000);
            }
        });
    });
}

function JQAjaxLoader(idAjaxContent){
    if(typeof(idAjaxContent) != 'object') { idAjaxContent = document.getElementById(idAjaxContent); }
    
    idAjaxContent.style.position = "relative";
    $(idAjaxContent).append('<div class=loader>'+'Yukleniyor...'+'</div>');
}


