$(document).ready(function(){
	$('#selectall').click(function(){
		$("input[name='id[]']").each(function(){
			$(this).attr('checked',true);
		});
	});
	$('#cancelall').click(function(){
		$("input[name='id[]']").each(function(){
			$(this).attr('checked',false);
		});
	});
	$('.tablist table tr:even').children('td').css('background','#F9F9F9');	
	$('.tablist table tr td table tr').children('td').css('background','#FFFFFF');	
	/*$('.tablist table tr').mouseover(function(){
					$(this).children('td').css('background','#F0F5FB');		 
								 });
	$('.tablist table tr').mouseout(function(){
					$(this).children('td').css('background','#FFFFFF');		 
								 });*/
});
//滑动门事件
function showbar(cur,total)
{
	for(var i=1;i<=total;i++)
	{
		$('#tab'+i).hide();
		$('#bar'+i).attr('class','tabbar');
	}
	$('#tab'+cur).show();
	$('#bar'+cur).attr('class','curbar');
}

//快速保存——解决方案
function quicksave(obj,url,id)
{
	var tag = obj.firstChild.tagName;
  	if (typeof(tag) != "undefined" && tag.toLowerCase() == "input")
  	{
    	return;
  	}
  	/* 保存原始的内容 */
  	var org = obj.innerHTML;
  	var val = $.browser.msie ? obj.innerText : obj.textContent;

  	/* 创建一个输入框 */
  	var txt = document.createElement("INPUT");
  	txt.value = (val == 'N/A') ? '' : val;
  	txt.style.width = (obj.offsetWidth + 12) + "px" ;

  	/* 隐藏对象中的内容，并将输入框加入到对象中 */
  	obj.innerHTML = "";
  	obj.appendChild(txt);
  	txt.focus();
	txt.select();
  	/* 编辑区输入事件处理函数 */
  	txt.onkeypress = function(e)
  	{
    	var evt = $.fixEvent(e);
    	var obj = $.srcElement(e);

    if (evt.keyCode == 13)
    {
      obj.blur();

      return false;
    }

    if (evt.keyCode == 27)
    {
      obj.parentNode.innerHTML = org;
    }
  }

  /* 编辑区失去焦点的处理函数 */
  txt.onblur = function(e)
  {
    if ($.trim(txt.value).length > 0)
    {
	  $.postJSON(url,{val:$.trim(txt.value),id:id},function(data){
			if(data.message){
				alert(data.message);
			}
			obj.innerHTML = (data.error == 0) ? data.content : org;
			if(data.len) $('#length_'+id).html(data.len);
		});
	}
	else
	{
		obj.innerHTML = org;
	}
  }
}

//ajax上传文件，并预览
function FUpload(field,type,hash,preview,width,height)
{
	$.ajaxFileUpload({
		url:sitepath+'upload.php?field='+field+'&type='+type+'&hash='+hash+'&preview='+preview+'&width='+width+'&height='+height,
		secureuri:false,
		fileElementId:field,
		dataType: 'json',
		success: function (data, status){
			if(data.error > 0){
				alert(data.message);
			}else{
					if(preview == 1 && type == 'image') 
					{
						$('#'+field+'_preview').attr('src', data.prepath);
					}
					$('#'+field+'_input').val(data.path);
				}
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		})
}

