function align_center(id,id2){

      var h = $.browser.opera && $.browser.version > "9.5" && $.fn.jquery <= "1.2.6" ?  document.documentElement["clientHeight"] : $(window).height();

    if(!id2){
        $("#"+id).css('left',$(window).width()/2-$("#"+id).width()/2);
        $("#"+id).css('top','h/2-$("#"+id).height()/2');
    }else{

        $("#"+id).css('margin-left',$("#"+id2).width()/2-$("#"+id).width()/2);
        $("#"+id).css('margin-top',$("#"+id2).height()/2-$("#"+id).height()/2);
    }
}

function init_window(){
    $("body").append("<div id='overlay'></div>");
    var arrPageSizes = getPageSize();
    $('#overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
		});
    $("body").append("<div id='v_k_pd'></div>");
    $("#overlay").fadeTo('slow',0.4);
    align_center("v_k_pd");
    $("#v_k_pd").html('<div id="loader"><img src="/images/ajax-loader.gif"  align="center" />');
    align_center("loader","v_k_pd");
    $("#v_k_pd").fadeTo("slow", 1, function () {
		if(jQuery.browser.msie)
			$(this).get(0).style.removeAttribute('filter');
	});
    
}

function create_window(send_data,url){
    if(!$("#v_k_pd").html()){
        init_window();
    }

    var h = $.browser.opera && $.browser.version > "9.5" && $.fn.jquery <= "1.2.6" ?  document.documentElement["clientHeight"] : $(window).height();
    $("#v_k_pd").html('<div id="loader"><img src="/images/ajax-loader.gif"  align="center" />');
    align_center("loader","v_k_pd");

    $.ajax({
        type: "POST",
        url:url,
        data:send_data,
        error:function ajaxer(textStatus)
        {
        //create_window( w_prl,h_prl, prl_pos_x, prl_pos_y,load_x,load_y,send_data,mode,url);
        },
        success:function (data)
        {
            
            $("#v_k_pd").html("<div id='v_k_' style='display:none'></div>");
            $("#v_k_").append(data);
            
            $(".checkboxUnchecked, .checkboxChecked").click(function(){
		
              if(this.className == "checkboxChecked"){
                $(this).removeClass("checkboxChecked").addClass("checkboxUnchecked");
                $("#" + this.id + " input").removeAttr("checked");
              }
		
              else{
                $(this).removeClass("checkboxUnchecked").addClass("checkboxChecked");
                $("#" + this.id + " input").attr("checked", "on");
              }
            });
            
            $("#v_k_pd").css({
                height:$("#v_k_").height()+20+'px',
                width:$("#v_k_").width()+20+'px',
                left:($(window).width()/2)-($("#v_k_").width()/2),
                top:(h/2)-($("#v_k_").height()/2)
            })

            
                $("#v_k_").fadeIn("slow");

            
        }
    });
}

function close_enter(){

    $("#v_k_pd").fadeOut('slow');
    $("#overlay").fadeOut('slow');
    $("#v_k_").fadeOut('slow',function(){
        if($("#reload").html()){
            window.location.reload();
        };
        $("#v_k_").remove();
        $("#v_k_pd").remove();
        $("#overlay").remove();
    });
}

function getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
};

$(window).resize(function() {
		var arrPageSizes = getPageSize();
    align_center("v_k_pd");
		$('#overlay').css({
			width:		arrPageSizes[0],
			height:		arrPageSizes[1]
		});
});

