//<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

$.getMaxZIndex = function( top_border ){
	if ( 'undefined' == typeof top_border ) top_border = 0;
	var maxIndex = 0;
	var curIndex = 0;
	var layers = $('*');//document.getElementsByTagName(nameTag); 
	var layerLength = layers.length;//(layers.length - 1);
	for( var i = 0; i < layerLength; i++ ) {
		if ( maxIndex < ( curIndex = parseInt( $(layers[i]).css('z-index') ) ) ){
			if ( top_border == 0 || top_border > curIndex ){ //верхний ограничитель индекса
				maxIndex = curIndex;
			}
		}
	}
	return maxIndex;	
}
$.setMaxZIndex = function( obj, top_border ){
	if ( 'undefined' == typeof top_border ) top_border = 0;
	$( obj ).css('z-index', $.getMaxZIndex( top_border ) + 1 );
}

$.toCenterUserWindow = function( obj ){
	var width = $(window).width();
	var height = $(window).height();	
	$(obj).css( 'left', (Math.round(width/2 - $(obj).width()/2)+$(document).scrollLeft()).toString() + 'px' );
	$(obj).css( 'top', (Math.round(height/2 - $(obj).height()/2)+$(document).scrollTop()).toString() + 'px' );	
	
	
}

$.serializeToNorm = function( obj ){
//	var arResult = Array();	
	var oResult = {};
	for( var i = 0; i < obj.length; i++ ){
	
		oResult[obj[i].name] = obj[i].value;
		//arResult.push(o);
	}
	return oResult;
}

$.fn.extend({
    disableSelection : function() {
            this.each(function() {
                    this.onselectstart = function() { return false; };
                    this.unselectable = "on";
                    $(this).css('-moz-user-select', 'none');
            });
    },
    enableSelection : function() {
            this.each(function() {
                    this.onselectstart = function() {};
                    this.unselectable = "off";
                    $(this).css('-moz-user-select', 'auto');
            });
    }
});


//=====================================================================================
/*Добавить слева символы ch чтобы общая длинна строки была не больше num*/
String.prototype.lpad = function(ch,num){
	var t = this.toString();
	if (t.length<num){
		for(var i=t.length; i<num; i++){
			t = ch+t;
		}		
	}
	return t;
}

//=====================================================================================




/*
$.serializeArray = function( obj ){
	var arResult = Array();	
	
	var ob = $(obj).find('input,textarea');
	for ( var i = 0; i < ob.length; i++ ){
		
		var o = {};
		o[$(ob[i]).attr("name")] = $(ob[i]).attr('value');
		arResult.push(o);
//		$(ob[i]).remove();
	}
	
	alert( $.param(arResult) );
	
	
}*/
