//表单提交处理函数，带文件上传的表单
$.fn.ifrPost = function(todo) {
	var submited = false;
	if (!$("#ifr").length) $('<iframe id="ifr" name="ifr" style="display:none;"></iframe>').appendTo($(this));
	if ($(this).attr("target") != "ifr") $(this).attr("target","ifr");
	if (!submited) $(this).submit();	
	var doc = document.all?$(document.frames('ifr').document.body).html():$(document.getElementById('ifr').contentWindow.document.body).html();
	if (doc == '') doc = null;
	if (doc != null){
		//alert(doc);
		document.all?$(document.frames('ifr').document.body).html(''):$(document.getElementById('ifr').contentWindow.document.body).html('');
		todo(doc);
	}else{
		//alert(document.getElementById("ifr").contentDocument.body.innerHTML);
		setTimeout(function(){$(this).ifrPost( todo );},100);
	}
}

$.fn.checkAll = function(name){
	$(this).click(function(){
		if(this.checked == true){
			$(":input[name="+name+"]").attr("checked", true);
			$("#btn_batch").attr("disabled", false);
		}else{
			$(":input[name="+name+"]").attr("checked", false);
			$("#btn_batch").attr("disabled", true);
		}
	});
}


$.fn.note = function(type, note){

	if (!$(this).parent().find('.note').length) $(this).parent().append('<span class="note"></span>');
	if (type == 1){ //填写正确
		$(this).removeClass('ipt_err');
		$(this).parent().find('.note').removeClass('err').addClass('ok').text(note);
	}else if(type == 0){
		$(this).addClass('ipt_err');
		$(this).parent().find('.note').removeClass('ok').addClass('err').text(note);
	}else if(type == -1){
		$(this).parent().find('.note').removeClass('ok err').text(note);
	}
	return this;
}
		


$.fn.mytab = function(e){
	if (!e) e = "click";
	$(this).each(function(){
		var _tab = $(this);
		$(this).find(".tab_head > li").bind(e,function(e){
			$(_tab).find(".tab_head > .tab_on").removeClass("tab_on");
			$(this).addClass("tab_on");
			$(_tab).find(".tab_body > div:visible").hide();//
			$(_tab).find(".tab_body > div:hidden").eq($(this).parent().children().index($(this))).show();//
		});	
	});
}


$.extend({
	jAlert : function(msg, fn, rs){
		var rs = rs=='true'?'msg_right':'msg_err';
		if (!msg) var msg = '无消息内容';
			$("#tb_box_alert").remove(); tb_remove();
			setTimeout(function(){  
				$('<div id="tb_box_alert" style="display:none;" ><p class="'+ rs +'" >'+ msg +'</p><div style="text-align:center"><input type="button" name="btn_ok" id="btn_ok" value="   确定   " onclick="javascript: tb_remove();" /></div></div>').appendTo($("body"));
				tb_show('提示消息', "#TB_inline?height=100&width=360&inlineId=tb_box_alert&modal=false" , null);
				$("#TB_window").draggable({handdle:"#TB_title", cursor : 'move', cancel : '#TB_ajaxContent'});
				if (fn) {
					$("#btn_ok").click(function(){
						tb_remove();
						fn.call();
					});
				}
			}
		,300)
		//alert('ss'); 
	},
	
	jConfirm : function(msg, fn){
		if (!msg) var msg = '无消息内容';
		$("#tb_box_alert").remove(); tb_remove();
		setTimeout(function(){  
		$('<div id="tb_box_alert" style="display:none;" ><p class="confirm" >'+ msg +'</p><div style="text-align:center"><input type="button" name="btn_ok" id="btn_ok" value="   确定   " onclick="javascript: tb_remove();" /> <input type="button" name="btn_alert" id="btn_cancel" value="   取消   " onclick="javascript: tb_remove();" /></div></div>').appendTo($("body"));
		tb_show('提示消息', "#TB_inline?height=100&width=360&inlineId=tb_box_alert&modal=false" , null);
		$("#TB_window").draggable({handdle:"#TB_title" ,cursor : 'move', cancel : '#TB_ajaxContent'});
		$("#btn_ok").click(function(){
			tb_remove();
			fn.call();
		});
		},300);
	},	
	jWindow : function(target, title, width, height, file)
	{
		if (file){
			if (target.indexOf('?') != -1) {
				target += '&';
			}else{
				target += '?';
			}
			tb_show(title, target + "width=" + width + "&height=" + height + "&modal=false" , null);
		}else{
			tb_show(title, "#TB_inline?inlineId=" + target + "&width=" + width + "&height=" + height + "&modal=false" , null);
		}
		$("#TB_window").draggable({handdle:"#TB_title" ,cursor : 'move', cancel : '#TB_ajaxContent'});
	}
	
});



Number.prototype.format=function(decimalPoints,thousandsSep,decimalSep){
 var val=this+'',re=/^(-?)(\d+)/,x,y;
 if (decimalPoints!=null) val = this.toFixed(decimalPoints);
 if (thousandsSep && (x=re.exec(val))){
  for (var a=x[2].split(''),i=a.length-3;i>0;i-=3) a.splice(i,0,thousandsSep);
  val=val.replace(re,x[1]+a.join(''));
 }
 if (decimalSep) val=val.replace(/\./,decimalSep);
 return val;
}
if (typeof Number.prototype.toFixed!='function' || (.9).toFixed()=='0' || (.007).toFixed(2)=='0.00') Number.prototype.toFixed=function(f){
 if (isNaN(f*=1) || f<0 || f>20) f=0;
 var s='',x=this.valueOf(),m='';
 if (this<0){ s='-'; x*=-1; }
 if (x>=Math.pow(10,21)) m=x.toString();
 else{
  m=Math.round(Math.pow(10,f)*x).toString();
  if (f!=0){
   var k=m.length;
   if (k<=f){
    var z='00000000000000000000'.substring(0,f+1-k);
    m=z+m;
    k=f+1;
   }
   var a = m.substring(0,k-f);
   var b = m.substring(k-f);
   m = a+'.'+b;
  }
 }
 if (m=='0') s='';
 return s+m;
}


/*
var doResult = function(res){
	var data = eval('(' + res + ')');
	if (data.result){
		var type = data.result == "true"?"right":"error";	
	}
	
	if (data.msg){
		alert(data.msg);	
	}
	
	if (data.item){
		$("#" + data.item).focus();	
	}
	
	if (data.url){
		if (data.url == "reload"){
			window.document.location.reload();
		}else{
			window.document.location.href = data.url;
		}
	}
}
*/

function gotoPage(url, pm , page){
	window.location.href = url + '?page=' + page + pm ;	
}

function getFckHtmlContents(EditorName)
{ 
    var oEditor = FCKeditorAPI.GetInstance(EditorName); 
    return(oEditor.GetXHTML(true)); 
}

$.fn.rowColor = function(){
	$(this).find("tbody tr:odd").css("background-color", "#f4f4f4");
	$(this).find("tbody tr:even").css("background-color", "#ffffff");
}
