/*以下二个函数用于上传图片时的预览
要点：
文件控件：<input name="XXXX" type="file" onchange="javascript:FileChange(uploadimage,this);">
新图预览：<IMG id="uploadimage"  onload="javascript:DrawImage(this);" width="1" height="1" border="0">
旧图预览：<IMG id="uploadimage" src="......." onload="javascript:DrawImage(this);" border="0" >
*/
function FileChange(imgObj,obj){
    var filepath=obj.value;
    filepath=filepath.substring(filepath.lastIndexOf('.')+1,filepath.length);
    if(filepath.toLowerCase() != 'jpg' && filepath.toLowerCase() != 'gif' && filepath.toLowerCase() != 'jpeg')
    {
        alert("只能上传JPG或GIF格式的图片");
        obj.createTextRange().execCommand('delete');
    }
    else
    {
        flag=false;
        imgObj.width=10;
        imgObj.height=10;
        imgObj.alt="";
        imgObj.src=obj.value;
    }
}



/*按比例缩小图片,当图片高和宽为0时不处理 -- fire 20061001
传入参数: 
ImgD :图片URL ;
iHH  :高度,可为空
iWW  :宽度,可为空
*/
var flag=false;
function DrawImage(ImgD ,iWW ,iHH){
	if (iHH==""){
		iHH=245;
	}
	if (iWW==""){
		iWW=300
	}
	
	var image=new Image();
	image.src=ImgD.src;
	//当高和宽大于0时处理
	if(image.width>0 && image.height>0){
    	flag=true;
		
		if(image.width/image.height>= iWW/iHH){
		    if(image.width>iWW){  
			    ImgD.width=iWW;
			    ImgD.height=(image.height*iWW)/image.width;
			}
			else
			{
			     ImgD.width=image.width;  
			     ImgD.height=image.height;
		    }
	    }
    	else{
    		if(image.height>iHH){  
		    	ImgD.height=iHH;
				ImgD.width=(image.width*iHH)/image.height;     
			}
			else
			{
			    ImgD.width=image.width;  
		    	ImgD.height=image.height;
		    }
    	}
    }
    
    DrawImage_Two(ImgD ,iWW ,iHH);
   /*else{
    ImgD.src="";
    ImgD.alt=""
    }*/
} 


function DrawImage_Two(ImgD ,iWW ,iHH){
	if (iHH==""){
		iHH=245;
	}
	if (iWW==""){
		iWW=300
	}
	
	var image=new Image();
	image.src=ImgD.src;
	//当高和宽大于0时处理
	if(image.width>0 && image.height>0){
    	flag=true;
		
		if(image.width/image.height>= iWW/iHH){
		    if(image.width>iWW){  
			    ImgD.width=iWW;
			    ImgD.height=(image.height*iWW)/image.width;
			}
			else
			{
			     ImgD.width=image.width;  
			     ImgD.height=image.height;
		    }
	    }
    	else{
    		if(image.height>iHH){  
		    	ImgD.height=iHH;
				ImgD.width=(image.width*iHH)/image.height;     
			}
			else
			{
			    ImgD.width=image.width;  
		    	ImgD.height=image.height;
		    }
    	}
    }
   /*else{
    ImgD.src="";
    ImgD.alt=""
    }*/
} 

/*修改我的照片提交时的判断*/
var clickcounter=0;
function CheckOK()
{	
	if (clickcounter==1){
	  	   alert("你的照片正在上传中，请稍等一会儿……");
		   return false ;
 	 }
/*判断输入是否正确。*/
	if (divPhotoURL.style.display == ""){
		if (Form_Photo.PhotoURL.value==""){
			window.confirm("你还没输入网址呢。\n\r把网址复制下来就可以了 ：）");
			Form_Photo.PhotoURL.focus();
			return false;
		}
		else if(Form_Photo.PhotoURLFirst.value==Form_Photo.PhotoURL.value){
			window.confirm("图片网址没有任何改变，不需要保存呢。");
			Form_Photo.PhotoURL.focus();
			return false;		
		}
		else{			
			clickcounter=clickcounter+1;
			return true;
		}
	}
	
	if (divPhotoUpload.style.display == ""){	 
		if (Form_Photo.Love.value==""){
			window.confirm("你还没选择图片呢。");
			Form_Photo.Love.focus();
			return false;		
		} 
		else{
			clickcounter=clickcounter+1;
			return true;
		}
	}
}


/*以下两个函数用于上传我的照片，在交友和我的西人中
主要功能是判断用户选择的是上传或是网址
*/
function showDivURL() 
{ 
	divPhotoUpload.style.display = "none"; 
	divPhotoURL.style.display = ""; 
	Form_Photo.Love.value =""
}

function showDivUpload() 
{ 
	divPhotoUpload.style.display = ""; 
	divPhotoURL.style.display = "none"; 
	Form_Photo.PhotoURL.value =""
}

