 
 

jQuery.fn.autoZoomLoadImage = function(scaling, width, height, loadPic) {
  if (loadPic == null) loadPic = "/SKCMS/images/loading.gif";
  return this.each(function() {
    var t = $(this);
    var src = $(this).attr("src");
    var img = new Image();
    //alert("Loading")
    img.src = src;
    //自动缩放图片
    var autoScaling = function() {
      if (scaling) {
        if (img.width > 0 && img.height > 0) {
          if (img.width / img.height >= width / height) {
            if (img.width > width) {
              t.width(width);
              t.height((img.height * width) / img.width);
            }
            else {
              t.width(img.width);
              t.height(img.height);
            }
          }
          else {
            if (img.height > height) {
              t.height(height);
              t.width((img.width * height) / img.height);
            }
            else {
              t.width(img.width);
              t.height(img.height);
            }
          }
        }
      }
    }
    //处理ff下会自动读取缓存图片
    if (img.complete) {
      //alert("getToCache!");
      autoScaling();
      return;
    }
    $(this).attr("src", "");
    var loading = $("<img alt=\"Load...\" title=\"Load...\" src=\"" + loadPic + "\" />");
    t.hide();
    t.after(loading);
    $(img).load(function() {
      autoScaling();
      loading.remove();
      t.attr("src", this.src);
      t.show();
      //alert("finally!")
    });
  });
}

 var api = frameElement.api, W = api.opener;
 
/*打开窗口 ID，标题，网址，宽，高，最大按钮，最小按钮，锁屏，是否拉大*/
function SK_window( id,title,url,k,g,ma,mi,sp,tj) 
{ $.dialog({id:id,title:title,content:url,width:k,height:g,max:ma,min:mi,lock:sp,parent:api,resize:tj,cache:false,fixed:true,zIndex:9999});  

 } 
 


function SK_windown( id,title,url,k,g,ma,mi,sp,tj) 
{ $.dialog({id:id,title:title,content:url,width:k,height:g,max:ma,min:mi,lock:sp,resize:tj,cache:false,fixed:true,zIndex:9999,parent:api});} 


function SK_windowback(id,title,url,k,g,ma,mi,sp,tj,idname,z) 
{ $.dialog({id:id,title:title,content:url+"?idname="+idname+"&IdList="+ document.getElementById(idname).value,width:k,height:g,max:ma,min:mi,lock:sp,resize:tj,cache:false,fixed:true,parent:api,zIndex:z});} 
 
 


function SK_confirm(cont,fname,url)
{  
 $.dialog.confirm(cont, function(){ 
	 document.getElementById(fname).method="post";
     document.getElementById(fname).action=url;
	 document.getElementById(fname).submit();
	
}, function(){ 
});
 }
 
 
 
 
 
 /*选择数据，以POST方式提交*/
 function CheckAll(form)  
  {  for (var i=0;i<form.elements.length;i++)  
    {  
    var e = Article.elements[i];  
   if (e.name != 'chkall')  
      e.checked = Article.chkall.checked;  
     $.dialog.tips('选取数据',2,'32X32/succ.png')
   }  
  }
  
 function SK_success(cont)     
{ $.dialog.tips(cont,3,'32X32/succ.png'); }
  function SK_error(cont)     
{ $.dialog.tips(cont,3,'32X32/fail.png'); }  
  

function SK_load(cont,id)    
{
$.dialog({ 
	id:id,
	zIndex:999999,
	title:false,
    lock: true, 
    content: cont, 
    icon: 'loading.gif'
}).zindex();
}
 
function SK_close(id)    
{
$.dialog.list[id].close(); 
}

 
 
function alert(content)
{ $.dialog.alert(content);}	


function IMGAddTj(idname,url){
 this[idname](url,url,'photo');
}



 
/*询问确认转到网址*/
function ifbtn(cont,url){
$.dialog.confirm(cont, function(){ 
    location=url;
}, function(){ 
});
}


function fifbtn(cont,url){
W.$.dialog.confirm(cont, function(){ 
    location=url;
}, function(){ 
});
} 
 
 
 

function oclick(msg,url)	
{
 $.dialog.confirm(msg, function(){ 
	$.dialog.tips('正在处理中...',1000,'loading.gif'); 
	self.location=url;
}, function(){ 
	 return true;
}); 
 }	
 

 
  function GetCheckfolderItem()
{
	var allSel='';
	if(document.Article.ID.value) return document.Article.ID.value;
	for(i=0;i<document.Article.ID.length;i++)
	{
		if(document.Article.ID[i].checked)
		{
			if(allSel=='')
			allSel=document.Article.ID[i].value;
			else
			allSel=allSel+","+document.Article.ID[i].value;
		}
	}
	return allSel;
}
 function Batch_tools(tit,acurl,k,g)
{var ID = GetCheckfolderItem();
	if(ID=='') {
		var dg = $.dialog.alert('最少要选择一个数据');
		return false;}
	
	$.dialog({id:'SKCMSLAN',title:tit,content:''+acurl+'&id='+ID+'',width:k,height:g,max: false,min: false,lock:true,cache:false,fixed:true,parent:api,zIndex:9999});}

 
 
 
function fadeIn(element, opacity) {
	var reduceOpacityBy = 5;
	var rate = 30;	// 15 fps
	if (opacity < 100) {
		opacity += reduceOpacityBy;
		if (opacity > 100) {
			opacity = 100;
		}
		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}
	if (opacity < 100) {
		setTimeout(function () {
			fadeIn(element, opacity);
		}, rate);
	}
}




 
/*按比例生成缩略图*/
function DrawImage(ImgD,W,H){ 
  var flag=false; 
  var image=new Image(); 
  image.src=ImgD.src; 
  if(image.width>0 && image.height>0){ 
    flag=true; 
    if(image.width/image.height>= W/H){ 
      if(image.width>W){
        ImgD.width=W; 
        ImgD.height=(image.height*H)/image.width; 
      }
	  else{ 
        ImgD.width=image.width;
        ImgD.height=image.height; 
      } 
      ImgD.alt= ""; 
    } 
    else{ 
      if(image.height>H){
        ImgD.height=H; 
        ImgD.width=(image.width*W)/image.height; 
      }
	  else{ 
        ImgD.width=image.width;
        ImgD.height=image.height; 
      } 
      ImgD.alt=""; 
    } 
  }
}

 
 
 