$(document).ready( function() {
    function ajaxpager(){
        $(".ajaxpager").bind("click", function(event) {
            event.preventDefault();
            parent = $(this).parent();
            $.get($(this).attr("href"),function(data){
                parent.html(data);
                ajaxpager();
            });
        });
    }
    ajaxpager();

    var has_dialog = false;
    $('.open_login').click(function(event){
    	event.preventDefault();
    	
    	$("#login_form").show();
    	
    	return false;
    });
    $(".ui-dialog-titlebar-close").click(function(){
    	$("#login_form").hide();
    });
    $(".openfilter").click(function(event){
        event.preventDefault();
        $("#sf_admin_bar").dialog({
            
            //width: '600px',
            resizable: false
        });
		
        if (has_dialog == false){
            $("#sf_admin_bar").dialog({
                
//                width: '600px', 
                resizable: false
            });
            has_dialog = true;
        }
        else
            $("#sf_admin_bar").dialog("open");
		
    });
    $("#auth_login").click(function(){
    	
    	$("#auth_login").hide();
    	$("#login_please_await").show();
    	
        $.post("/sfGuardAuth/ajaxsignin3",$("#signin_form").serialize(),function(data){
        	$("#auth_login").show();
        	$("#login_please_await").hide();
            if (data.status==0)
            {
                $("#autherror").hide();
                window.location.href='/signin_gateway.html';
            }else
            {
            	
            	$("#username_error").text('');
            	$("#response_error").text('');
            	$("#password_error").text('');
            	
            	
            	$("#username_error").text(data.errors.username);
            	$("#response_error").text(data.errors.response);
            	$("#password_error").text(data.errors.password);
            	
            	Recaptcha.reload();
            	$("#autherror").show();
            }
                
        },'json');
    });
    window.setTimeout('$(".notify_container").slideUp("slow")',2000);
	
    $(".sf_admin_row").hover(function(){
        $(this).css('background','#ffffb0');
    },function(){
        $(this).css('background','none');
    });

    $("#channel").change(function(){
        var url = window.location.href;
        var re = /\/product\/(\d+)\/chan\/(\d+)/;
        if(!re.test(url)){
            url = url.replace(/\/product\/(\d+)/,"/product/$1/chan/"+$("#channel").val());
        }else{
            if($("#channel").val() != 0){
                url = url.replace(re,"/product/$1/chan/"+$("#channel").val());
            }else{
                url = url.replace(re,"/product/$1")
            }
        }
        window.location.href = url;
    });
	
});


