//验证图片上传个数
function check_form_upload(image_num)
{

	if(image_num>=6){
		alert(getOtherLanguage(7));
		return false;
	}
	return true;
}
//验证图片格式
function check_file_type(file_name){
	try{
		if(file_name==""){
			alert(getOtherLanguage(9));
			return false;
		}
		var filetype = file_name.substring(file_name.lastIndexOf("."),file_name.length);
	 		if(filetype.toUpperCase()!=".GIF"&&filetype.toUpperCase()!=".BMP"&&filetype.toUpperCase()!=".PNG"&&filetype.toUpperCase()!=".JPEG"&&filetype.toUpperCase()!=".JPG")
	    	{
	 			alert(getOtherLanguage(8));
	 			return false;
	 		}
	    
	    return true;
    }catch(e){
    	alert(getOtherLanguage(8));
    	return false;
    }
}

function resizeImage(tempImgId,fitWidth,fitHeight,i)
{
	//tempImg.style.display="none";
	var width=0,height=0,scale=1;
	var tempImg=document.getElementById(tempImgId);
	var imgs=new Image();
	imgs.src=tempImg.src;
	i=i+1;
	if(document.all)//如果是ie
	{
		if(tempImg.readyState=='complete')
		{
			//tempImg.style.display="block";
			width = imgs.width;//获取源图片宽,高
			height = imgs.height;
			//tempImg.style.display="none";
		}
		else
		{
			return false;
		}
	}
	else if(tempImg.complete)//fire fox ,netscape
	{
		width = imgs.width;
		height = imgs.height;
	}
	else
	{
		return false;
	}
	scale = width/height;//宽度比例因子
	//if(width > fitWidth)//等比例调整
	//{
 		width = fitWidth;
 		height = width/scale;  
 		if(height > fitHeight)
 		{
  			height = fitHeight;
  			width = height*scale;
 		}
	//}
	if(height > fitHeight)
	{
 		height = fitHeight;
 		width = height*scale;
	}
	//width=Math.round(width); 
	//height=Math.round(height);
	//alert("图片"+tempImg.src+"原宽："+tempImg.width+"原长："+tempImg.height +"现宽："+width+"现长："+height);
	tempImg.width = width;//调整后的宽,高
	tempImg.height = height;
	tempImg.style.display="block";
	if(i<10){
		
		setTimeout('resizeImage(\''+tempImgId+'\','+fitWidth+','+fitHeight+','+i+')',1000);
		}
	
  }
    function change_default_image(image_id,form_id,image_num){
  	if(check_form_upload(image_num)){
  		var file=document.getElementById('file').value;
  		if(check_file_type(file)){
	  		display_image();
	  		var form=document.getElementById(form_id);
	  		form.submit();
	  	}
  	}
  }
  
  function replace_image(select_part,image_id,image_src)//image.jsp中的图片转换
  {
  	var cur=document.getElementById("current");
  	cur.id=cur.name;
  	var thispart=document.getElementById(select_part);
  	thispart.id="current";
  	//select_part.name="current";
  	var img=new Image();
  	var real_img=document.getElementById(image_id);
  	img.src=image_src;
  	resizeImage(img.id,652,490,4);
  	real_img.width=img.width;
  	real_img.height=img.height;
  	real_img.src=img.src;
  	
  	
  }
  function display_image(){
	
	var cObj = document.createElement("div");
	cObj.setAttribute("id","cdiv");
	cObj.style.position = "absolute";
	cObj.className="mydiv";
	cObj.style.zIndex = "1000";
	cObj.innerHTML="<img src='"+document.getElementById('upload_image').src+"'/>";
	document.body.appendChild(cObj);
	
}
function changeImg(img_path){
	if(img_path!=""){
		document.getElementById("img_big").src = img_path;
	}
}
