// JavaScript Document

function delConfirm(Action,id){
	if (window.confirm('确实要删除吗？'))
	window.location.href=APP+"/"+Action+id;
}

//批量选中删除
//id：表单中的数组复选框
//action:删除操作地址
function ArrayDelConfirm(id,action){
     var al = document.getElementsByName(id);
	 var willDelid=[];
	 var len=al.length;
	 var t=0;
	 for(var i=0; i<len; i++) if(al[i].checked){
	   willDelid[t]=al[i].value;
	   t++;
	 }
	 if(t==0){
	   alert('请选择需要删除的数据.');
	   return false;
	 }
	 else if(!confirm('删除的数据不能恢复，确定要删除吗?')) return false;
	 	  else{
		  	window.location.href=APP+'/Admin/'+action+'/id/'+willDelid;
		  }

}
//判断指定选项是否至少选择了一个
function isChecked(id,str){
     var al = document.getElementsByName(id);
	 var willId=[];
	 var len=al.length;
	 var t=0;
	 for(var i=0; i<len; i++) if(al[i].checked){
	   willId[t]=al[i].value;
	   t++;
	 }
	 if(t==0){
	   if(str=='') str="请至少选择一个";
	   alert(str);
	   return false;
	 }

}

//控制tbody的显示与隐藏
function tbodyFlag(obj){
	var element = document.getElementById(obj);
	element.style.display = (element.style.display == '')?('none'):('');
}

//选项卡
$(function(){
	$('.tabHead span').each(function(i){
		var $this = $(this);
		$this.click(function(){
			$('.on').removeClass('on');
			$this.addClass('on').blur();
			$('.tbody').hide();
			$('.tbody').eq(i).show();
			
		})
	})
})

//全选 / 取消
$(function(){
	//全选
	$('#checkAll').click(function(){
		$('input:checkbox').attr('checked', 'checked');		
	})
	
	//反选
	$('#inverse').click(function(){
		$('input:checkbox').each(function(){
			this.checked=!this.checked;
		})
	})
	
	//取消
	$('#noSelAll').click(function(){
		$('input:checkbox').removeAttr('checked');		
	})
})

//折叠菜单 隐藏子菜单
$(function(){
	$('.toggle').toggle(
		function(){
			$(this).addClass('show');
			$('.subMenu'+this.id).show();
		},
		function(){
			$(this).removeClass('show');
			$('.subMenu'+this.id).hide();
		}
	)
})


//全选 
function checkAll(e,itemName)
{
  var al = document.getElementsByName(itemName);
  for (var i=0; i<al.length; i++)
   al[i].checked = e.checked;
}

//图片上传
//fileUpload:文件选择框ID；
//module:对应模块；
//imgUrl:数据库对应字段
//imgBox:图片显示框
function ajaxFileUpload(fileUpload,module,imgUrl,imgBox){
  var ui="#"+fileUpload;
  var imgUrl="#"+imgUrl;
  var imgBox="#"+imgBox;
  if( $(ui).val()==""){
		alert("请选择文件");
		return false;
  }else{
	$("#loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
 
	$.ajaxFileUpload({
		url:module,
		secureuri:false,
		fileElementId:fileUpload,
		dataType: 'json',
		success: function (data, status){
			if (status==1){
				$("#msg").text(data.info);
			}else{
				$(imgUrl).val(data.data.savename);
				$("#msg").text(data.info);
				$(imgBox).html("<img src=\""+APP+"/"+data.data.savename+"\"/>");;
			}
		},
		error: function (data, status, e){
			alert(e);
		}
	})
	return false;
  }
}

// JavaScript Document

function advInit(small, big){
   var smallimg=$('#'+small);
   var bigimg=$('#'+big);
   $('#'+small+' span').each(function(i){
       $(this).mouseover(function(){
	       if($(this).attr('class')=='active'){ return false;}
	       smallimg.find('span').removeClass();
		   $(this).addClass('active');
		   bigimg.find('li').fadeOut(500);
		   bigimg.find('li:eq('+i+')').fadeIn(500);
	   })
   })
}

$(function(){
	//banner
	advInit('smallimg','bigimg');
	
	//产品类别
	$('#categoryList').find('div').click(function(){
		$(this).parent().find('ul').toggle();
		
	})
})

//搜索框验证
function checkSearch(form){
	if(form.elements[0].value==' Search '){
		form.elements[0].focus();
		return false;
	}
	return true;
}

//Open Windows
//-----------------------------------------------
function openwin( url, winName, width, height) 
{
xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 ))
{
xposition = (screen.width - width) / 2;
yposition = (screen.height - height) / 2;
}
theproperty= "width=" + width + "," 
+ "height=" + height + "," 
+ "location=0," 
+ "menubar=0,"
+ "resizable=1,"
+ "scrollbars=1,"
+ "status=1," 
+ "titlebar=0,"
+ "toolbar=0,"
+ "hotkeys=0,"
+ "screenx=" + xposition + "," 
+ "screeny=" + yposition + "," 
+ "left=" + xposition + "," 
+ "top=" + yposition; 
window.open( url,winName,theproperty );
}


