(function($){
	//Fix jQuery1.4 And IE6 x.php###'s ajax Bug
	$._ajax     = $.ajax;
	$.ajax      = function(s){
		if(s.url){
			var v = $.ajaxSettings.version?$.ajaxSettings.version:"";
			s.url = s.url+(s.url.indexOf("?")==-1?"?_v="+v:"&_v="+v);
			if(window.location.href.match(/#/) && s.url.substring(0,1)=="?"){
				s.url = window.location.href.replace(/(#|\?).*/,'')+s.url;
			}
		}
		$._ajax(s);
	};
	$.parseJSON = function(data){
		try{ return window["eval"]("(" + data + ")"); }catch(e){$.error( "Invalid JSON: " + data );  return ;}
	};
	$.ajaxSetup({
		cache:false,
		beforeSend:function(r){ r.setRequestHeader('Connection', 'Keep-Alive'); },
		complete:function(request,status){ if(request.responseText.substring(0,100).indexOf("@R")!=-1){ window.location.reload(); } }
	});
})($);
$(function(){
	$("form").live("submit",function(){
		var _errno = 0;
		$(":input[_type]",this).each(function(){
			if($(this).attr("_type") == "need" && ($(this).val()=="" || $(this).val()=="0")){
				_errno = 1;
				alert("please complete input");
			}
		});
		return _errno == 0?true:false;
	}).find(":input[_value]").each(function(){
		$(this).val($(this).attr("_value"));	
	});
	if(window != window.parent){
		$("iframe",window.parent.document).attr("height",$("body").height()<500?500:$("body").height()+5);
	}
	$("a[href=#]").attr("href","javascript:;");
	$(".table_list tr").not(".main").click(function(){
		$(this).toggleClass("data");
	});
	$(".table_order tr").not(".main").filter(".timeout").unbind().click(function(){
		if($(this).is(".timeout")){
			$(this).removeClass("timeout").addClass("data");
		}else{
			$(this).removeClass("data").addClass("timeout");
		}
	});
	$(".href_div").hover(function(){
		if(!$("#_div").length){
			$("<div id=_div></div>").appendTo("body");
		}
		$("#_div")
			.html($(this).next().html())
			.css({position:"absolute",backgroundColor:"#FFFFFF",zIndex:1,top:$(this).offset().top,left:$(this).offset().left+50,border:"1px solid #EEEEEE",fontSize:"14px"})
			.show();
	},function(){
		$("#_div")
			.hide();
	}).each(function(){
		$(this).next().hide();
	})
});
var urlencode = encodeURIComponent;
function do_selectall(obj,name){
	$(obj).parents("form").find(":input[name='"+name+"']").each(function(){
		$(this).attr("checked",!$(this).attr("checked"));	
	});
}
function do_action(obj,act,message){
	if(obj.tagName.match(/input/i)){
		if(confirm(message)) $(obj).parents("form").attr("action",act).submit();
	}else{
		if(confirm(message)) $(obj).attr("href",act);
	}
}
function do_loadpage(obj,url){
	$.get(url,function(data){
		$("<div class=_float></div>")
			.appendTo($("body"))
			.css({position:"absolute",zIndex:9999,left:200,top:50})
			.html(data)
			.find(".close")
			.click(function(){$("._float").remove();});
	});
}
function do_selectfill(select,source,selected,text){
	$.get(source,function(data){
		var rs = $.eval_json(data);
		if(!rs){
			return false;
		}else{
			select.each(function(i,_s){
				_s.options.length = 0;
				if(text) _s.options.add(new Option(text,''));
				for(var i=0;i<rs.length;i++){
					var option = new Option(rs[i].text,rs[i].value?rs[i].value:rs[i].text);
					if(selected == rs[i].value) option.selected = true;
					_s.options.add(option);
				}
			});
		}
	});
} 
