
function DrawImageOk(ImgD,FitWidth,FitHeight)  
{  
var image=new Image();  
image.src=ImgD.src;  
if(image.width>0 && image.height>0)  
{  
if(image.width/image.height>= FitWidth/FitHeight)  
{  
if(image.width>FitWidth)  
{  
ImgD.width=FitWidth;  
ImgD.height=(image.height*FitWidth)/image.width;  
}  
else  
{  
ImgD.width=image.width;  
ImgD.height=image.height;  
}  
}  
else  
{  
if(image.height>FitHeight)  
{  
ImgD.height=FitHeight;  
ImgD.width=(image.width*FitHeight)/image.height;  
}  
else  
{  
ImgD.width=image.width;  
ImgD.height=image.height;  
}  
}  
}  
}  

function drawImage(ImgD,width,height) {
    var image=new Image();
    image.src=ImgD.src;
    if((width/image.width)>(height/image.height)) {
        ImgD.height = height;
        ImgD.width = (height/image.height)*image.width;
    } else {
        ImgD.width = width;
        ImgD.height = (width/image.width)*image.height;
    }
    ImgD.alt = image.width + "x" + image.height;
}  
function changeImg(mypic,xw,xl){ 

var width = mypic.width; 
var height = mypic.height; 

if (width > xw ) mypic.width = xw; 
if (height > xl ) mypic.height = xl; 
if(width<xw) mypic.width=xw;
if(height<xl)mypic.height=xl;
} 

function showimage(imageUrl,size) {
    var imgObj = new Image()
    imgObj.src = imageUrl;
    if(imgObj.width > imgObj.height) {
        document.write("<img hspace=5 vspace=5 src="+imgObj.src+" border=1 style='border-color:#000000' height=" + imgObj.height*size/imgObj.width + " width=" + size + ">");
    } else if(imgObj.width < imgObj.height) {
        document.write("<img hspace=5 vspace=5 src="+imgObj.src+" border=1 style='border-color:#000000' height=" + size + " width="+ imgObj.width*size/imgObj.height +">");
    } else {
        document.write("<img hspace=5 vspace=5 src="+imgObj.src+" border=1 style='border-color:#000000' height=" + size + " width="+ size + " >");
        }
}

//function imageZoom(imgObj,size){
//    var i ;
//    if(imgObj.width>imgObj.height)
//        i=size/imgObj.width;
//    else
//        i=size/imgObj.height;
//    imgObj.style.zoom=i;
//}


/**判断是否选择数据后转向*/
function gotoUrl(selectObject, str) {
    if(!checkSelected(selectObject)) {
        return;
    }
    if(!checkNotZero(selectObject)) {
        return;
    }
    window.open(str + selectedValue(selectObject));
}
function gotoLocal(selectObject, str) {
    if(!checkSelected(selectObject)) {
        return;
    }
    if(!checkNotZero(selectObject)) {
        return;
    }
    window.location = str + selectedValue(selectObject);
}
/**直接转向*/
function gotoUrlDirect(str) {
    window.open(str);
}
function gotoLocalDirect(str) {
    window.location = str;
}

function checkNotZero(selectObject) {
    if( selectedValue(selectObject) == 0 ) {
        alert("很抱歉您选到分隔符号上了");
        return false;
    } else {
        return true;
    }
}

function selectedValue(selectObject) {
    var currentIndex = selectObject.selectedIndex ;
    var currentId = selectObject.options[currentIndex].value ;
    return currentId;
}

/***检查是否选中列表中的数据 true选中 false没有选择*/
function checkSelected(selectObject) {
    var onSelect = false;
    if (selectObject.selectedIndex == -1) {
        onSelect = false;
    } else {
     	onSelect = true;
    }

    if(!onSelect) {
        alert("请选择列表中数据");
        return false;
    } else {
        return true;
    }
}

/*** selectObject为select元素， gotoUrl为上移的url*/
function upSelected(selectObject, gotoUrl, urlVar) {
    if(!checkSelected(selectObject)) {
        return ;
    }

    var currentIndex = selectObject.selectedIndex ;
    var currentId = selectObject.options[currentIndex].value ;
    if(currentIndex > 0) {
        var upId = selectObject.options[currentIndex-1].value ;
    }
    if(currentIndex == 0 || currentId == 0 ||  upId <= 0) {
        alert("不能上移了");
    } else {
        str = gotoUrl + "?currentid=" + currentId + "&upid=" + upId + urlVar;
        window.location = str;
    }
}

/*** selectObject为select元素， gotoUrl为下移的url*/
function downSelected(selectObject, gotoUrl, urlVar) {
    if(!checkSelected(selectObject)) {
        return ;
    }

    var currentIndex = selectObject.selectedIndex ;
    var maxIndex = selectObject.length-1 ;
    var currentId = selectObject.options[currentIndex].value ;
    if(currentIndex < maxIndex) {
        var downId = selectObject.options[currentIndex+1].value ;
    }
    if( currentId == 0 || downId == 0|| currentIndex >= maxIndex ) {
        alert("不能下移了");
    } else {
        str = gotoUrl + "?currentid=" + currentId + "&downid=" + downId + urlVar;
        window.location = str;
    }
}

/*** 设置隐含字段 **/
function setHiddenId(selectObject, setObject) {
    if(!checkSelected(selectObject)) {
        return false;
    }
    if(!checkNotZero(selectObject)) {
        return false;
    }
    setObject.value=selectedValue(selectObject);
    return true;
}


/*** 删除 **/
function del(selectObject, str) {
    if(!checkSelected(selectObject)) {
        return false;
    }
    if(!checkNotZero(selectObject)) {
        return false;
    }
    var temp = window.confirm("你确定要删除该项吗?" );
    if(temp==true)
	window.location = str + selectedValue(selectObject);
    else
	return false;

}


