jQuery.fn.OpenWindow = function(title, content, options){
	var tempName=$(this).attr('id');
	var tempWin='<div id="window-'+tempName+'" class="window">';
	var tempWin=tempWin+'<div id="windowTop-'+tempName+'" class="windowTop">';
	var tempWin=tempWin+'<div id="windowTopContent-'+tempName+'" class="windowTopContent">'+title+'</div>';
	var tempWin=tempWin+'<a href="#Close" id="windowClose-'+tempName+'" class="windowClose"><img src="images/blank.gif"></a>';
	var tempWin=tempWin+'</div>';
	var tempWin=tempWin+'<div id="windowBottom-'+tempName+'" class="windowBottom">';
	var tempWin=tempWin+'<div id="windowBottomContent-'+tempName+'" class="windowBottomContent"></div>';
	var tempWin=tempWin+'</div>';
	var tempWin=tempWin+'<img src="images/blank.gif" class="Icon" />';
	var tempWin=tempWin+'<div id="windowContent-'+tempName+'" class="windowContent">'+content+'</div>';
	var tempWin=tempWin+'</div>';
	options = options || {};
	var box='body';
	var width=500;
	var height=300;
	var center=true;
	if(options.box){var box=options.box;};
	if(options.width){var width=options.width;};
	if(options.height){var height=options.height;};
	if(options.center){var center=options.center;};
	$(box).append(tempWin);
	$('input[@type=text],textarea').focus(function(){
		$(this).addClass("inputFocus");
	});
	$('input[@type=text],textarea').blur(function(){
		$(this).removeClass("inputFocus");
	});
	$(this).bind('click',function(){
		if($('#window-'+tempName).css('display') == 'none'){
			$('#window-'+tempName).css({'height':height,'width':width});
			$('#windowContent-'+tempName).css({'height':height-42,'width':width-22});
			$('#windowBottom-'+tempName+', #windowBottomContent-'+tempName).css({'height':height-30});
			if(center){
				var sH=GetScrollTop();
				var cH=document.documentElement.clientHeight;
				var W=document.body.clientWidth;
				var left=W/2-width/2;
				var top=(cH/2+sH)-height/2;
				$('#window-'+tempName).css({'top':top,'left':left});
			};
			$(this).TransferTo({
				to:'window-'+tempName,
				className:'transferer2', 
				duration: 400,
				complete: function(){
					$('#window-'+tempName).show();
				}
			});
		}
		$(this).blur();
		return false;
	});
	$('#windowClose-'+tempName+',#close').bind('click',function(){
		$('#window-'+tempName).TransferTo(
			{
				to:tempName,
				className:'transferer2', 
				duration: 400
			}
		).hide();
		return false;
	});
	$('#windowMin-'+tempName).bind('click',function(){
		$('#windowContent-'+tempName).SlideToggleUp(300);
		$('#windowBottom-'+tempName+', #windowBottomContent-'+tempName).animate({height: 10}, 300);
		$('#window-'+tempName).animate({height:40},300).get(0).isMinimized = true;
		$(this).hide();
		$('#windowResize-'+tempName).hide();
		$('#windowMax-'+tempName).show();
	});
	$('#windowMax-'+tempName).bind('click',function(){
		var windowSize = $.iUtil.getSize($('#windowContent-'+tempName));
		$('#windowContent-'+tempName).SlideToggleUp(300);
		$('#windowBottom-'+tempName+', #windowBottomContent-'+tempName).animate({height: windowSize.hb + 13}, 300);
		$('#window-'+tempName).animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
		$(this).hide();
		$('#windowMin-'+tempName+', #windowResize-'+tempName).show();
	});
	$('#window-'+tempName).Resizable({
		minWidth: 200,
		minHeight: 60,
		maxWidth: 700,
		maxHeight: 400,
		dragHandle: '#windowTop-'+tempName,
		handlers: {
			se: '#windowResize-'+tempName
		},
		onResize:function(size, position){
			$('#windowBottom-'+tempName+', #windowBottomContent-'+tempName).css('height', size.height-36 + 'px');
			var windowContentEl = $('#windowContent-'+tempName).css('width', size.width - 22 + 'px');
			if (!$('#window-'+tempName).isMinimized){
				windowContentEl.css('height', size.height - 48 + 'px');
			};
		}
	});
};

jQuery.fn.offset = function() {
	var left = 0, top = 0, elem = this[0], results;
	if ( elem ) with ( jQuery.browser ) {
		var	absolute     = jQuery.css(elem, "position") == "absolute", 
		    parent       = elem.parentNode, 
		    offsetParent = elem.offsetParent,
		    doc          = elem.ownerDocument,
		    safari2      = safari && parseInt(version) < 522;
		if ( elem.getBoundingClientRect ) {
			box = elem.getBoundingClientRect();
			add(
				box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
				box.top  + Math.max(doc.documentElement.scrollTop,  doc.body.scrollTop)
			);
			if ( msie ) {
				var border = jQuery("html").css("borderWidth");
				border = (border == "medium" || jQuery.boxModel && parseInt(version) >= 7) && 2 || border;
				add( -border, -border );
			};
		} else {
			add( elem.offsetLeft, elem.offsetTop );
			while ( offsetParent ) {
				add( offsetParent.offsetLeft, offsetParent.offsetTop );
				if ( mozilla && /^t[d|h]$/i.test(parent.tagName) || !safari2 )
					border( offsetParent );
				if ( safari2 && !absolute && jQuery.css(offsetParent, "position") == "absolute" )
					absolute = true;
				offsetParent = offsetParent.offsetParent;
			};
			while ( parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
				if ( !/^inline|table-row.*$/i.test(jQuery.css(parent, "display")) )
					add( -parent.scrollLeft, -parent.scrollTop );
				if ( mozilla && jQuery.css(parent, "overflow") != "visible" )
					border( parent );
				parent = parent.parentNode;
			};
			if ( safari2 && absolute )
				add( -doc.body.offsetLeft, -doc.body.offsetTop );
		};
		results = { top: top, left: left };
	}
	return results;
	function border(elem) {
		add( jQuery.css(elem, "borderLeftWidth"), jQuery.css(elem, "borderTopWidth") );
	};

	function add(l, t) {
		left += parseInt(l) || 0;
		top += parseInt(t) || 0;
	};
};

jQuery.cookie = function(name, value, options) { 
    if (typeof value != 'undefined') { // name and value given, set cookie 
        options = options || {}; 
        if (value === null) { 
            value = ''; 
            options.expires = -1; 
        };
        var expires = ''; 
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 
            var date; 
            if (typeof options.expires == 'number') { 
                date = new Date(); 
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 
            } else { 
                date = options.expires; 
            };
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 
        } 
        var path = options.path ? '; path=' + options.path : ''; 
        var domain = options.domain ? '; domain=' + options.domain : ''; 
        var secure = options.secure ? '; secure' : ''; 
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 
    } else { // only name given, get cookie 
        var cookieValue = null; 
        if (document.cookie && document.cookie != '') { 
            var cookies = document.cookie.split(';'); 
            for (var i = 0; i < cookies.length; i++) { 
                var cookie = jQuery.trim(cookies[i]); 
                // Does this cookie string begin with the name we want? 
                if (cookie.substring(0, name.length + 1) == (name + '=')) { 
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 
                    break; 
                };
            };
        };
        return cookieValue; 
    };
};

jQuery.fn.extend({
	CreatSelect:function(options){
		options=options||{};
		var defaults={
			column:false
		};
		var column=options.column||defaults.column;
		$(this).each(function(){
			var c='';
			var t=$(this).find('option[selected]').html();
			var v=$(this).find('option[selected]').val();
			var index=$("*").index(this);
			var w=$(this).width();
			var n=$(this).attr('name');
			var o=$(this).children();
			var l=o.length;
			o.each(function(i){
				var v=$(this).val();
				var h=$(this).html();
				c=c+'<a href="javascript:void(0);" value="'+v+'">'+h+'</a>';
				if(column){
					if(!((i+1)%column)){
						c=c+'<br />';
					};
				};
			});
			$(this).before('<div class="selectBox" id="selectBox'+index+'"><div class="selectTitle" id="selectTitle'+index+'"><div class="selectContent" id="selectContent'+index+'"><div>'+c+'</div></div><span>'+t+'</span><img src="/images/blank.gif" /><input name="'+n+'" value=""></div></div>');
			$('input[name="'+n+'"]').val(v);
			$('#selectTitle'+index).css({'width':w+21});
			$('#selectContent'+index).css({'width':w-18});
			if(column){
				$('#selectContent'+index+' a').css({'float':'left'});
				$('#selectContent'+index+' a').css({'width':w-21});
				$('#selectContent'+index).css({'width':w*column-column*5});
			};
			$('#selectTitle'+index).click(function(){
				event.cancelBubble=true;
				if($('#selectContent'+index).css('display')=='none'){
					$(this).find('span').css({'backgroundPosition':'0 -19px'});
					$(this).find('img').css({'backgroundPosition':'right -19px'});
					$('#selectContent'+index).show();
				}else{
					$(this).find('span').css({'backgroundPosition':'0 0'});
					$(this).find('img').css({'backgroundPosition':'right 0'});
					$('#selectContent'+index).hide();
				};
			});
			$('#selectContent'+index+' a').each(function(i){
				var v=$(this).attr('value');
				var t=$(this).text();
				$(this).click(function(){
					$('#selectTitle'+index+' span').html(t);
					$('input[name="'+n+'"]').val(v);
					$('#selectTitle'+index).find('span').css({'backgroundPosition':'0 0'});
					$('#selectTitle'+index).find('img').css({'backgroundPosition':'right 0'});
				});
			});
			$(this).remove();
			$(document).click(function(){
				$('#selectContent'+index).hide();
				$('#selectTitle'+index).find('span').css({'backgroundPosition':'0 0'});
				$('#selectTitle'+index).find('img').css({'backgroundPosition':'right 0'});
			});
		});
	},
	myToolTip:function(options){
		options=options||{};
		var defaults={
			className:null,
			position:'right',
			attr:'title',
			delay:200
		};
		var className=options.className||defaults.className;
		var position=options.position||defaults.position;
		var attr=options.attr||defaults.attr;
		var delay=options.delay||defaults.delay;
		$(this).each(function(){
			var index=$("*").index(this);
			var a=$(this).attr(attr);
			var t=$(this).offset().top;
			var l=$(this).offset().left;
			var w=$(this).width();
			var b=parseInt($(this).css('borderWidth'));
			t=t-b*2;
			l=l+b*2;
			$(this).before('<div id="myToolTip'+index+'" class="'+className+'">'+a+'</div>');
			var tip=$('#myToolTip'+index);
			tip.css({'top':t,'left':l+w,'zIndex':9999});
			$(this).bind('mouseover',function(){
				tip.animate({
					opacity:'toggle'
				},delay);
			});
			$(this).bind('mouseout',function(){
				tip.animate({
					opacity:'toggle'
				},delay);
			});
		});
	},
	PngForIE:function(options){
		options=options||{};
		var defaults={
			AutoSize:false,
			ReplacImg:'images/blank.gif'
		};
		var AutoSize=options.AutoSize||defaults.AutoSize;
		var ReplacImg=options.ReplacImg||defaults.ReplacImg;
		if($.browser.msie){
			$('img').each(function(){
				var me=$(this);
				var src=me.attr('src').toUpperCase();
				var iType=src.substring(src.length-3,src.length);
				if(iType=="PNG"){
					me.css({'filter':'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+src+'", sizingmethod=scale)'});
					me.attr('src',ReplacImg);
					if(!AutoSize){
						var w=me.width();
						var h=me.height();
						me.css({'width':w,'height':h});
					};
				};
			});
		};
	}
});
