﻿

 //全选
 //flag ,是否选中标记：true，false
 function checkAll(flag)
 {
        $("input[type='checkbox']").each(function(){
            $(this).attr("checked", flag);
        }); 
 } 
 
 //获取选中复选框的值
 function setAllCheckValue()
 {
    var ids=new String();
    $("input[type='checkbox'][@checked]").each(function()
    { //由于复选框一般选中的是多个,所以可以循环输出
      //alert($(this).val());
      if($(this).attr("checked")==true)
      {
        if($(this).val()!="on")
        {
          ids+="," + $(this).val();
        }
      }
    });
    return ids;
 }
 
 

//弹出模态窗口
function OpenWin(url,width,height)
{
    var id = Math.random();
    if(url.indexOf("?")>0)
    {
       url = url  + "&rdm=" + Math.random();
    }
    else
    {
       url = url  + "?rdm=" + Math.random();
    }
    window.showModalDialog(url,'winpopModal','dialogWidth='+width+'px;dialogHeight='+height+'px;');
}


//弹出查看窗口
function OpenViewWin(url,width,height)
{
    var id = Math.random();
    if(url.indexOf("?")>0)
    {
       url = url  + "&rdm=" + Math.random();
    }
    else
    {
       url = url  + "?rdm=" + Math.random();
    }
    window.showModalDialog(url,'winpopModal','dialogWidth='+width+'px;dialogHeight='+height+'px;');
}

//跳转页面
function gotoWin(url)
{
    if (url.indexOf('?') > 0)
        window.location.href = url  + "&rdm=" + Math.random();
    else
        window.location.href = url  + "?rdm=" + Math.random();
  return false;
}


/********************文件上传操作****************************/
///<summary>
///检查文件类型
///</summary>
function checkFileType(fileUpload)
{
    var filestr=document.getElementById(fileUpload).value;
    if(filestr==""){
    alert("请选择一个文件进行上传！");
    return;
    }
    var pos = filestr.lastIndexOf(".");
    var lastname =filestr.substring(pos,filestr.length) 
    //此处文件后缀名也可用数组方式获得str.split(".") 
    if (lastname.toLowerCase()!=".jpg" && lastname.toLowerCase()!=".gif" && lastname.toLowerCase()!=".png"){
       alert("您上传的文件类型为"+lastname+"，图片必须为.jpg,.gif,.png类型!");
       document.getElementById(fileUpload).focus();
       return false;
    }

    /*var FileMaxSize = 100;//限制上传的文件大小100K，单位(k)     
    var val =document.getElementById("image").value;       
    //if(s==""){alert("No image,please select again!");document.RegForm.Img_1.focus(); return   false;}        
    var img= new Image();        
    img.src=val; 
    alert(img.fileSize)
    if(img.fileSize>FileMaxSize*1024){
    alert("文件大小超过了"+FileMaxSize+"K，请重新选择!");
    document.getElementById("image").focus();
    return false;     
    }*/
}


///<summary>
///上传文件及时预览
///</summary>
var allowExt = ['jpg', 'gif', 'bmp', 'png', 'jpeg'];	
      var preivew = function(file, container)
      {	
      	 try{		
      	 	  var pic =  new Picture(file, container);		 
      	 	}
      	 	catch(e)
      	 	{			
      	 	 alert(e);		 
      	 	}	
       }	 
      	  //缩略图类定义     
  	  var Picture  = function(file, container)
  	  {		 
  	     var height	= 0,widht = 0, ext	= '', size	= 0,name   = '',path  	=  '';		
  	     var self 	= this;		 
  	     if(file)
  	     {
  	      		     name = file.value;			 
  	      		     if (window.navigator.userAgent.indexOf("MSIE")>=1)
  	      		     { 				 
  	      		        file.select(); 				 
  	      		        path = document.selection.createRange().text; 			 
  	      		     }
  	      		     else if(window.navigator.userAgent.indexOf("Firefox")>=1)
  	      		     { 				 
  	      		        if(file.files)
  	      		        { 					 
  	      		            path =  file.files.item(0).getAsDataURL(); 
  	      		        }
  	      		        else
  	      		        {					
  	      		             path = file.value;				
  	      		        }			 
  	      		     } 		 
  	      }
  	      else
  	      {			 
  	      throw "bad file";		 
  	      } 		 
  	      ext = name.substr(name.lastIndexOf("."), name.length);		
  	      if(container.tagName.toLowerCase() != 'img')
  	      {			 
  	         throw "container is not a valid img label";			
  	          container.visibility = 'hidden';		
  	      }		
           container.src = path;		
           container.alt = name;		 
           container.style.visibility = 'visible';		
           height = container.height;		 
           widht  = container.widht;		 
           size   = container.fileSize;		 
           this.get = function(name)
           {			 
           return self[name];		 
           }		 
           this.isValid = function()
           {			 
           if(allowExt.indexOf(self.ext) !== -1)
           {				 
           throw 'the ext is not allowed to upload';				 
           return false;			 
    }		 
  	}	 
  }
/********************文件上传结束****************************/



