// JavaScript Document

/*
函數功能：引入更多javascript 資源檔案
日    期：2009/04/26
*/

function include(file) {
var script = document.createElement('script');
script.src = file;
script.type = 'text/javascript';

document.getElementsByTagName('head').item(0).appendChild(script);
}

//引入更多之Javascript檔案--------------
//include("jquery-latest.min.js");
//--------------------------------------


//阻止右鍵行為
//alert(navigator.appName);
function safe_M1(){
	if (navigator.appName.indexOf("Internet Explorer") != -1) {
	  document.onmousedown =function(){return false};
	  document.ondragstart =function(){return false};
	  document.oncontextmenu =function(){return false};
	  
	}
}
//safe_M1();  //執行安全行為  

//數字型別判斷
function isNum(N){ 
  numtype=".0123456789"; 
  for(i=0;i<N.length;i++){ //檢討是否有不在 0123456789之內的字 
    if(numtype.indexOf(N.substring(i,i+1))<0) 
      return false;            //是的話....結束迴圈;傳回false 
  } 
  return true; 
}


//檢驗需運算的值(!="" && !isNaN )
function Chk_Value(Uvlaue){
	
   if(Uvlaue!="" && !isNaN(Uvlaue)){
	  return true;	   
   }else{
	  return false; 
   }
}

//帳號判斷
function isLegal_account(N){ 
  numtype="_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  N=N.toUpperCase();
  for(i=0;i<N.length;i++){ //檢討是否有不在 0123456789之內的字 
    if(numtype.indexOf(N.substring(i,i+1))<0) 
      return false;            //是的話....結束迴圈;傳回false 
  } 
  return true; 
}

//預覽圖片(僅適用IE6以前版本)
function show_pic_old(fn,sobj){ 
 
 if(fn!=""){     
	 var x=fn.substr(fn.length-3,3);
	 //alert(x);
	 if(x.toUpperCase()=="JPG" || x.toUpperCase()=="GIF" || x.toUpperCase()=="JPEG"){
	   sobj.src=fn;
	   upload_chk="OK";
	 }else{
	   alert("只允許上傳檔案類型為「.jpg、.gif」");	
	   upload_chk="ERR";   	
	   return false;   
	 }
 }
}

//預覽圖片(適用IE7以上)
/*
使用規範：
1.要加入以下CSS~
#sphoto
{
    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
}
2.加入以下顯示物件~
<div id='sphoto' style="width:200px; height=150px; border:solid; border-width: 1px;"></div>

*/
var upload_chk="";
function show_pic(imgobj,sobj){       

 //偵測目前執行的物件
 var actobj=window.document.activeElement; 
 //獲取Client 圖片
 
 if(typeof(actobj)=='object' && actobj.type=='file'){ 
 
	  actobj.select();
	  var imgSrc = document.selection.createRange().text;
	  //alert('imgSrc='+imgSrc); 
	
	 if(imgSrc!=""){     
		 var x=imgSrc.substr(imgSrc.lastIndexOf(".")+1);  //附檔名
		 //alert(x);
		 if(x.toUpperCase()=="JPG" || x.toUpperCase()=="GIF" || x.toUpperCase()=="JPEG"){  
		   sobj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;	   
		   upload_chk="OK";
		 }else{
		   alert("只允許上傳檔案類型為「.jpg、.gif」");	
		   upload_chk="ERR";   	
		   return false;   
		 }
	 }
 }else if(typeof(imgobj)=='string'){//傳入 圖檔路徑參數
    var x=imgobj.substr(imgobj.lastIndexOf(".")+1);  //附檔名
		 //alert(x);
    if(x.toUpperCase()=="JPG" || x.toUpperCase()=="GIF" || x.toUpperCase()=="JPEG"){  
	  sobj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgobj;   	 
	}
 }

}



//當母視窗關閉則關閉子視窗
function close_subwin(obj){
  if (obj!= null && obj.open) obj.close();
} 

//列印函數群組---------------------------------------
//說明：
//像素公分換算(以解析度=96dpi計算)=> (100px / 96 ) * 2.54 = 2.645 公分 (每100px)
//1.A4頁寬=700px / 頁高=1077px  /上下邊界各留 23px / 可編輯區域=1041px 以內   
//2.A5頁寬(21*14)=700px / 頁高=525px /上下邊界各留 23px / 可編輯區域=480px 以內 
//-----
<!--// 列印

function fnPrint() {
    try    {
        // 儲存原本頁首頁尾的設定，然後設定空白
        var ret = saveAndClearSetting();
        // 列印
        window.print();
        // 回存原本頁首頁尾的設定
        //if ( ret ) restoreSetting();
    } catch (e) { alert("err="+e.description); }
}
var hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
var hkey_key_header = hkey_path+"header"; // 頁首
var hkey_key_footer = hkey_path+"footer"; // 頁尾
var hkey_key_margin_bottom = hkey_path+"margin_bottom"; // 邊界（下）
var hkey_key_margin_left = hkey_path+"margin_left"; // 邊界（左）
var hkey_key_margin_right = hkey_path+"margin_right"; // 邊界（右）
var hkey_key_margin_top = hkey_path+"margin_top"; // 邊界（上）
var old_header = "&w&b第 &p 頁，共 &P 頁";
var old_footer = "&u&b&d";
// 儲存原本頁首頁尾的設定，然後設定空白
function saveAndClearSetting() {
  try {
    var RegWsh = new ActiveXObject("WScript.Shell");
    old_header = RegWsh.RegRead(hkey_key_header);
    old_footer = RegWsh.RegRead(hkey_key_footer);
    RegWsh.RegWrite(hkey_key_header,"");
    RegWsh.RegWrite(hkey_key_footer,"");
    RegWsh.RegWrite(hkey_key_margin_left,0.20);   //5
    RegWsh.RegWrite(hkey_key_margin_right,0.20);   //5 
    RegWsh.RegWrite(hkey_key_margin_top,0.20);    //5
    RegWsh.RegWrite(hkey_key_margin_bottom,0.20);	//5
    return true;
  } catch (e) { 
    if ( e.description.indexOf("伺服程式無法產生物件") != -1 ) {
        alert("請調整IE瀏覽器的安全性\n網際網路選項＼安全性＼自訂層級\n「起始不標示為安全的ActiveX控制項」設定為啟用或提示。"); 
    } // if
    else {
        alert("ERR="+e.description); 
    } // else
  } // catch
    return false;
}
// 回存原本頁首頁尾的設定
function restoreSetting() {
  try {
    var RegWsh = new ActiveXObject("WScript.Shell");
    RegWsh.RegWrite(hkey_key_header,old_header);
    RegWsh.RegWrite(hkey_key_footer,old_footer);
  } catch (e) {
    if ( e.description.indexOf("伺服程式無法產生物件") != -1 ) {
        alert("請調整IE瀏覽器的安全性\n網際網路選項＼安全性＼自訂層級\n「起始不標示為安全的ActiveX控制項」設定為啟用或提示。"); 
    } // if
    else {
        alert("ERR="+e.description); 
    } // else
  } // catch
}

function printPage() {
   window.toolbar.style.display="none";
   fnPrint();
   window.toolbar.style.display="";
}


//作業式多重輸入，按下enter跳下一欄
function Chk_Enter(UrNo,nextObj){  

  //alert(window.event.keyCode);
  if(window.event.keyCode==13 || window.event.keyCode==40){
	 event.returnValue = false; 
	 if(nextObj[UrNo]){
	  nextObj[UrNo].focus();
	 }
	 
  }else if(window.event.keyCode==38){
	 event.returnValue = false;
	 if(nextObj[UrNo]){
	  nextObj[UrNo].focus();
	 }
  }

}

//------------


//日曆函數-----
function chkvalue(strValue)
	{
		var oddnum=new Array(1,3,5,7,8,10,12);
		var evennum=new Array(4,6,9,11);
		var intpos=-1;
		var strtemp="";
		var strtemp1="";
		var intI=true;
		strtemp=strValue;
		if (strtemp!="")
		{
			intpos=strtemp.indexOf("/");
			if (intpos>0) 
			{
				strtemp1=strtemp.substring(0,intpos);
				flag=isNaN(strtemp1)
				if (flag==true)
				{			
					alert("年必須為數值");
					return false;
				}
				var intyear=parseInt(strtemp1,10);
				if (intyear<1911) 
				{	
					alert("年輸入錯誤");
					return false;
				}else
				{
					strtemp=strtemp.substring(intpos+1,strtemp.length);
					intpos=strtemp.indexOf("/");
					if (intpos>0)
					{
						strtemp1=strtemp.substring(0,intpos);
						flag=isNaN(strtemp1)
						if (flag==true)
						{			
							alert("月份必須為數值");
							return false;
						}
						var intmonth=parseInt(strtemp1,10);
						if (intmonth>12)
						{
							alert("月份輸入錯誤");
							return false;
						}else
						{
							if (intmonth==2)
							{
								//intyear+=1911//年度轉為西元年
								intDay1=0
								if ((intyear % 400)==0)
								{
									intDay1=29;
								}else if ((intyear % 100)==0)
								{
									intDay1=28;
								}else if ((intyear % 4)==0)
								{
									intDay1=29;
								}else
								{
									intDay1=28;
								}
								strtemp=strtemp.substring(intpos+1,strtemp.length);
								var intday=parseInt(strtemp,10);
								if (intday>intDay1)
								{
									switch (intDay1)
									{
										case 28:
											alert("二月天數(不為閏年)最多為" + intDay1 + "天");
											return false;
											break;
										case 29:
											alert("二月天數(閏年)最多為" + intDay1 + "天");
											return false;
											break;
									}									
								}				
								
							}else
							{
								for (var i=0;i<oddnum.length;i++)
								{
									if (oddnum[i]==intmonth) 
									{
										intI=false;//為奇數月
										break;
									}
								}
								switch (intI)
								{
									case true:
										strtemp=strtemp.substring(intpos+1,strtemp.length);
										flag=isNaN(strtemp)
										if (flag==true)
										{				
											alert("日期必須為數值");
											return false;
										}
										var intday=parseInt(strtemp,10);
										if (intday>30)
										{
											alert("偶數月天數最多為30天");
											return false;
										}				
										break;
									case false:
										strtemp=strtemp.substring(intpos+1,strtemp.length);
										flag=isNaN(strtemp)
										if (flag==true)
										{				
											alert("日期必須為數值");
											return false;
										}
										var intday=parseInt(strtemp,10);
										if (intday>31)
										{
											alert("奇數月天數最多為31天");
											return false;
										}				
										break;
								}
							}							
						}
					}
					else
					{
						alert("日期輸入錯誤");
						return false;
					}
				}				
			}
			else
			{
				alert("日期輸入錯誤");
				return false;
			}
				
		}
		return true;
	}
/**
*函式名稱：getInputDate(objText)
*函式功能：另開小視窗，顯示萬年曆。
*          該萬年曆可變更，年、月，
*          點選該日，則將該年月日帶入
*          呼叫本函式的位置
*日    期：90/11/14
*/
function getInputDate(objText){

    var x=window.event.screenX;
    var y=window.event.screenY;    

    var inCalendar = window.showModalDialog("../../js/calendar.htm",null,"status:no;scroll:no; dialogLeft:"+(x+30)+"px ; dialogTop:"+y+"px ; dialogWidth:240px ; dialogHeight:240px ;");
    //回傳值設定
    if(inCalendar!=""){
	 objText.value = inCalendar;
	}
	
    objText.blur();
}

//-------------

//keycode反應
function Chk_keycode(active_keycode){
	
   //alert(active_keycode);	
   switch(active_keycode){ 
     case 27:  //ESC 鍵
	 event.returnValue = false;
	 window.self.close();
    break;
   }

	
}

/**
*函式名稱：urlencode(objText)
*函式功能：搭配PHP urlencode使用
*日    期：2009/04/03
*/
function urlencode(s) {
  s = encodeURIComponent(s);
  return s.replace(/~/g,'%7E').replace(/%20/g,'+');
}


/*
函數功能：除去頭尾空白
日    期：2009/04/26
*/
function strTrim(str){

  s=str.replace(/(^\s*)|(\s*$)/g,"");
  return s;  
	
}


/*
函數功能：Javascript client資料排序
日    期：2009.04.27
使用規範：
1.需要在欲處理的PHP檔的 Javascript區域引述下面資訊

//javascript client資料排序編輯區------------------
var CROSS_COLOR2="<?=CROSS_COLOR2?>";
var CROSS_COLOR1="<?=CROSS_COLOR1?>";

2.顯示的table id="show_data"

3.資料標題需要加入  
<tr>
<td id="col0" onclick="sortdata(0)"......>標題文字<span id="arr0" class=sort>5</span></td> 
....
</tr>
(注意：id="colN" 及 <span id="arrN....> 每列都要加 依序 0、1、2、3、...N)
(注意：onclick="sortdata(N) 及  class='sort' 需要排序欄位才需要加 依序 0、1、2、3、...N)
(注意：不需排序的欄位 class='sort_no')
(注意：內容對齊方式不要寫在 TD 的 align，要在<td></td>內加入<div align="left">....)

新增：
sort_data_class 可紀錄每一欄TD的class樣式
sort_data_align 可紀錄每一欄TD align對齊方式
(注意：每項TD內容格式設定盡量寫在 class 內，尤其是 前台應用)
 //-----------------------------------------------

*/
//清除所有資料列
function remove_rec(Tid){
  var add_TB=window.document.getElementById(Tid); 
	  while(add_TB.rows.length>1){
	   var myRow = add_TB.deleteRow(1); 
	  }  
}


//將表格顯示資料都入陣列
var temp_data= new Array;
var sort_data_class=new Array;  //紀錄每一欄樣式
var sort_data_align=new Array;  //紀錄每一欄對齊方式
function get_data(Tid){  
  
  var sel_TB=window.document.getElementById(Tid);
  var now_rows=sel_TB.rows.length;	
  
  for(R=1;R<now_rows;R++){  
    var sel_TR=sel_TB.rows[R];
	var now_cols=sel_TR.cells.length;
	temp_data[R-1]="";
	for(C=0;C<now_cols;C++){
	  var Cvalue=sel_TB.rows[R].cells[C].innerHTML;  //內容
	  temp_data[R-1]+=Cvalue+"^";
	  sort_data_class[C]=sel_TB.rows[R].cells[C].className;	 //紀錄 class
	  sort_data_align[C]=sel_TB.rows[R].cells[C].align;     //紀錄 align
	  //alert("Row="+R+"/Col="+C+" -->"+Cvalue);	 
	}	
	temp_data[R-1]=temp_data[R-1].substr(0,temp_data[R-1].length-1);
    //alert(temp_data[R-1]);
  }   
    /*
	for(t=0;t<sort_data_class.length;t++){
		alert(sort_data_class[t]); 
	}
	*/
	
}
//-----------------------------------------------


//排序資料列
var UclassName="admin_list";
var sort_r=false//預設值設成正向排序
var sort_p=1000//無意義，大於陣列數即可

function sortdata(s){

var temp_0=new Array
var temp_1=new Array
var sort_w="5"

if(temp_data.length==0){
  //alert("come here!");	
  get_data("show_data");
}

for(x=0;x<temp_data.length;x++){
   temp_0[x]=temp_data[x];
}

remove_rec("show_data");  //移除原先的資料

for(i=0;i<temp_0.length;i++){
temp_0[i]=temp_0[i].split("^")//轉換成二維陣列
temp_1[i]=new Array
//alert(temp_0[i].length);
  for(j=0;j<temp_0[i].length;j++){
  temp_0[i][j]=temp_0[i][j].replace(/^[\s]+/g,"").replace(/[\s]+$/g,"")//去除頭尾的空白字元
  temp_1[i][j]=temp_0[i][j]//將 temp_0 的資料置入 temp_1
  }
//將排序項目與第一個陣列位置互換
temp_1[i][0]=temp_0[i][s]
temp_1[i][s]=temp_0[i][0]
}

temp_1.sort()//陣列排序
if(sort_p==s){
sort_r=(sort_r==false)?true:false
sort_w=(sort_w=="5")?"6":"5"//更換箭頭符號
}

if(sort_r){temp_1.reverse()}//陣列反向排序
sort_p=s
for(i=0;i<j;i++){
 if(eval('arr'+i).className=="sort"){
   eval('arr'+i).style.color="#FFFFFF";
   eval('arr'+i).innerHTML=sort_w;
 }
}
eval('arr'+s).style.color="#FF9933"

for(i=0;i<temp_1.length;i++){
  for(j=0;j<temp_1[i].length;j++){
  temp_0[i][j]=temp_1[i][j]//將temp_1的資料置入temp_0  
  }
//將排序項目換回原來的陣列位置
temp_0[i][0]=temp_1[i][s]
temp_0[i][s]=temp_1[i][0]
}
for(i=0;i<temp_0.length;i++){
    var add_TB=window.document.getElementById("show_data");
    var now_rows=add_TB.rows.length;	
	var add_TR=add_TB.insertRow(i+1);	
	if(add_TB.rows.length%2==0){
	  RowColor=CROSS_COLOR1;
	}else{
	  RowColor=CROSS_COLOR2;
	}	
	add_TR.bgColor=RowColor;

  for(j=0;j<temp_0[i].length;j++){
  
	var myCell=add_TR.insertCell(j);
	//myCell.height="20";
    myCell.align=sort_data_align[j];
	//myCell.className=UclassName;
	myCell.className=sort_data_class[j];
	myCell.innerHTML=temp_0[i][j];
  }

}

}


//----------------------------------

/*
函數功能：window.open視窗至中
日    期：2009/04/30
*/
function OpenWin(targetURL,wname,winWidth,winHeight,winset){
    screenW=screen.width/2;
    screenH=screen.height/2;
    winL=screenW-(winWidth/2);
    winT=screenH-(winHeight/2);
	if(winset==""){
	  winset='toolbar=no,resizable=no,scrollbars=no,status=no,menubar=no';	
	}
    window.open(targetURL,wname,winset+",width="+winWidth+",height="+winHeight+",left="+winL+",top="+winT); 
}


/*
開新視窗的以POST方式傳值
*/
function  doSubmit(fmobj,targetURL,winWidth,winHeight){  
     
  fmobj.action=targetURL;   
  fmobj.target="_process"; 
  screenW=screen.width/2;
  screenH=screen.height/2;
  winL=screenW-(winWidth/2);
  winT=screenH-(winHeight/2);
  //var popupWin=window.showModelessDialog(targetURL,"_process","status:no;scroll:no; dialogLeft:"+winL+"px ; dialogTop:"+winT+"px ; dialogWidth:"+winWidth+"px ; dialogHeight:"+winHeight+"px ;");
  var popupWin=OpenWin(targetURL,'_process',winWidth,winHeight,'');   
  fmobj.submit();   
    
}

/*
背景母視窗鎖定
*/
function Lock_PWin(Ustatus){
	
  if(!$('LockWinDiv')){	
    var newdiv = document.createElement('div'); 
	var divIdName = 'LockWinDiv'; 
	newdiv.setAttribute('id',divIdName);
	if(Ustatus!="ON"){	 
	 newdiv.style.display="none";
	}else{	 
	 newdiv.style.display="";	
	}
	newdiv.style.zIndex=500;	
	newdiv.style.width = screen.width-25; 
	newdiv.style.height = screenH=screen.height; 
	newdiv.style.left = "0px"; 
	newdiv.style.top = "0px"; 
	newdiv.style.position = "absolute"; 
	newdiv.style.background = "#999999"; 
	newdiv.style.border = "1px solid #000";
	newdiv.className = "set_filter50";
	//newdiv.style.z-index = 500;
	//newdiv.style.filter=alpha(opacity=50);
	newdiv.innerHTML = ''; 
	document.body.appendChild(newdiv);  
  }else{
	
	var LockWin=document.getElementById('LockWinDiv');
	 if(Ustatus!="ON"){
	   LockWin.style.display="none"; 
	 }else{
	   LockWin.style.display="";	 
	 }
  }
}

/*
增加編輯資料行(TR)
TID：table id（讀取既有TABLE）

*該頁面需設定

//javascript Add_Rec_List() 專用----------------
var CROSS_COLOR2="<?=CROSS_COLOR2?>";
var CROSS_COLOR1="<?=CROSS_COLOR1?>";

*/
function Add_Rec_List(Tid){

  //取得目前table的結構 <tr>..........</tr>
  var sel_TB=window.document.getElementById(Tid);
  var now_rows=sel_TB.rows.length;	
  
  var sel_TR=sel_TB.rows[now_rows-1];
  var now_cols=sel_TR.cells.length;
  var Temp_data = new Array;
	for(C=0;C<now_cols;C++){
	  var Cvalue=sel_TB.rows[now_rows-1].cells[C].innerHTML;  //內容
	  Temp_data[C]=Cvalue;
	}	


    //產生新的編輯列
	var add_TR=sel_TB.insertRow();	
	if(sel_TB.rows.length%2==0){
	  RowColor=CROSS_COLOR2;
	}else{
	  RowColor=CROSS_COLOR1;
	}	
	add_TR.bgColor=RowColor;
	
	for(j=0;j<Temp_data.length;j++){
	
		var myCell=add_TR.insertCell();
		myCell.height="20";
		myCell.align="center";
		myCell.className="bottom_dotted";
		if(j==0){
		 myCell.innerHTML=parseInt(Temp_data[j]) +1; 
		}else{
		 myCell.innerHTML=Temp_data[j];
		}
	
	}
  
    //將新增TR資料列內容清除
  for(C=1;C<now_cols-1;C++){  //C=0 為項次欄位 不需清除  C=now_cols-2 為垃圾桶欄位 不需處理 
	  //var Cvalue=sel_TB.rows[sel_TB.rows.length-1].cells[C].innerHTML;  //內容	  
    var inputelements = sel_TB.rows[sel_TB.rows.length-1].cells[C].getElementsByTagName('input'); 
    var maxj = inputelements.length; 
    for(j = 0; j < maxj; j++) 
    { 
        if(inputelements[j].getAttribute('type') == 'text' || inputelements[j].getAttribute('type') == 'hidden') { 
            //alert(inputelements[j].getAttribute('value'));
			inputelements[j].setAttribute('value','');
        } 
    } 
	

   }	


}


//刪除資料列
function Del_Rec_List(Tid){

 var add_TB=window.document.getElementById(Tid);
 var rowItm=window.document.activeElement.parentElement;

 //alert(rowItm.rowIndex);
 if(window.Mtype_mod.CH_TNAME[rowItm.rowIndex-1].value!=""){
  if(confirm("您確定要刪除「"+window.Mtype_mod.CH_TNAME[rowItm.rowIndex-1].value+"」這筆資料嗎？ \n\n※注意：編輯完成記得按「確定修改」鈕進行更新。")){
   var myRow = add_TB.deleteRow(rowItm.rowIndex); 
  }
 }else{
   var myRow = add_TB.deleteRow(rowItm.rowIndex);	 
 }
 
}

/*
即時時間顯示
*/

timerID = 10;
function Time_show(msg)
{
ct = new Date();
Y=ct.getYear();
M="0"+(ct.getMonth()+1);
D=ct.getDate();
h = "0"+ct.getHours();
m = "0"+ct.getMinutes();
s = "0"+ct.getSeconds();
h = h.substring(h.length-2,h.length+1);
m = m.substring(m.length-2,m.length+1);
s = s.substring(s.length-2,s.length+1);
cl = "現在時間:【"+Y+"年"+M+"月"+D+"日  "+h+"時"+m+"分"+s+"秒】";
f = ct.getSeconds() & 1;
f == 0 ? str = " " : str = msg;
document.getElementById('showtime').innerHTML = cl+str;
clearTimeout(timerID);
timerID = setTimeout("Time_show('"+msg+"')",100);
}

//共享檔案選取專用--------------------------

function chk_Fsrc(chkobj,fobj1,fobj2){

  if(chkobj.checked==true && $(chkobj).value=="1"){
    $(fobj1).style.display="";
	$(fobj2).style.display="none";
  }else if(chkobj.checked==true && $(chkobj).value=="2"){
    $(fobj2).style.display="";
	$(fobj1).style.display="none";
  }

}

function Select_SFile(targetURL){
 
  child=OpenWin(targetURL,'SF',650,500,'toolbar=no,resizable=no,scrollbars=yes,status=yes,menubar=no');

}
//----------------------------------------
//圖片按比例縮放
var flag=false;
function DrawImage(ImgD){
	var image=new Image();
	var iwidth = 200; //定義允許圖片寬度
	var iheight =150; //定義允許圖片高度
	image.src=ImgD.src;
  if(image.width>0 && image.height>0){
		flag=true;

	if(image.width/image.height>= iwidth/iheight){
		if(image.width>iwidth){
			ImgD.width=iwidth;
			ImgD.height=(image.height*iwidth)/image.width;
		}else{
			ImgD.width=image.width;
			ImgD.height=image.height;
		}
	    ImgD.alt=image.width+"×"+image.height;
	
	}else{
		if(image.height>iheight){
			ImgD.height=iheight;
			ImgD.width=(image.width*iheight)/image.height;
		}else{
			ImgD.width=image.width;
			ImgD.height=image.height;
		}
		ImgD.alt=image.width+"×"+image.height;
	}
	
  }
}