var errorPicFlag = 0;
function errorimg(x, y) {
	if(errorPicFlag==0){
		x.style.display='';
		if (y == null) {
			x.src = errphoto;
		}
		else {
			x.src = y;
		}
		errorPicFlag++;
	}
}
function errorimg2(x, y) {
	if(errorPicFlag==0){
		x.style.display='';
		if (y == null) {
			x.src = errphoto2;
		}
		else {
			x.src = y;
		}
		errorPicFlag++;
	}
}
function errorimg3(x, y) {
	x.style.display='';
	if (y == null) {
		x.src = errphoto;
	}
	else {
		x.src = y;
	}
	errorPicFlag++;
}
function controlImage(ImgD,lwidth,lheight){
	var image=new Image();
	image.src=ImgD.src;
	//ImgD.style.display='block';
	if(lheight==null)
	{
		if(image.width>0 && image.height>0){
		  //flag=true;
		  
		   if(image.width>lwidth){
			ImgD.width=lwidth;
			ImgD.height=(image.height*lwidth)/image.width;
		   }else{
			ImgD.width=image.width;
			ImgD.height=image.height; 
		   }
		}
	}
	else
	{
		if(image.width>=image.height)
		{
			if(image.width>lwidth){
			ImgD.width=lwidth;
			ImgD.height=(image.height*lwidth)/image.width;
		   }else{
			ImgD.width=image.width;
			ImgD.height=image.height; 
		   }
		}
		else
		{
			if(image.height>lheight){
			ImgD.height=lheight;
			ImgD.width=(image.width*lheight)/image.height;
		   }else{
			ImgD.width=image.width;
			ImgD.height=image.height; 
		   }
		}
	}
	ImgD.style.display='block';
	
}
var imageScrollCount = 0;
function controlImage2(image,lwidth,lheight){
	var checkImage=new Image();
	if(checkImage.width>image.width())
	{
		image.width(checkImage.width);
		image.height(checkImage.height);
	}
	if(lheight==null)
	{
		if(image.width()>30 && image.height()>=30){
		   if(image.width()>lwidth){
			image.width(lwidth);
			image.height((image.height()*lwidth)/image.width());
		   }
		  //alert(image.width());
		}
		else
		{
			image.width(lwidth);
			//image.height(lwidth);
		}
	}
	else
	{
		if(image.width()>30 &&  image.height()>=30){
			if(image.width() / lwidth >= image.height() / lheight)
			{
				if(image.width()>lwidth){
				image.width(lwidth);
				image.height((image.height()*lwidth)/image.width());
			   }
			}
			else
			{
				if(image.height()>lheight){
				image.height(lheight);
				image.width((image.width()*lheight)/image.height());
			   }
			}
		}
		else
		{
			image.width(lwidth);
			//image.height(lwidth);
		}
	}
	
	//alert(image.width());
	imageScrollCount++;
	if(imageScrollCountMax==1){
		image.show();
	}
}

//-----------------主選單游標移過去換圖的程式
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadimages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadimages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function openwin(url,x,y,wname) {
    window.open(url,wname,"height="+y+",width="+x+",left=200,top=150,resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
		//resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no
    //newWindow.focus();	
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
