
//function showimage(imageUrl,width,height) {
//document.body.onload=preLoadImage(imageUrl);
//    var imgObj = new Image();
//    var descHeight;
//    var descWidth;
//    imgObj.src = imageUrl;
//    if((width/imgObj.width)>(height/imgObj.height)) {
//        descHeight = height;
//        descWidth = (height/imgObj.height)*imgObj.width;
//    } else {
//        descWidth = width;
//        descHeight = (width/imgObj.width)*imgObj.height;
//    }
//    document.write("<img hspace=5 vspace=5 src="+imgObj.src+" border=0 width=" + descWidth + " height=" + descHeight + ">");

//}
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 drawImageByStandard(ImgD,standard) {
    var image=new Image();
    image.src=ImgD.src;
    if ((image.width > standard)  || (image.height > standard)) {
    	if (image.width > image.height){
    		ImgD.width = standard;
        ImgD.height = (standard/image.width)*image.height;
    	} else {
    		ImgD.height = standard;
        ImgD.width = (standard/image.height)*image.width;
    	}
    	
    }  
}

function showimage(imageUrl,size) {
    var imgObj = new Image()
    imgObj.src = imageUrl;
    if(imgObj.width > imgObj.height) {
        document.write("<img src="+imgObj.src+" border=1  class=black-border height=" + imgObj.height*size/imgObj.width + " width=" + size + ">");
    } else if(imgObj.width < imgObj.height) {
        document.write("<img src="+imgObj.src+" border=1 class=black-border height=" + size + " width="+ imgObj.width*size/imgObj.height +">");
    } else {
        document.write("<img src="+imgObj.src+" border=1 class=black-border 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;

}

function selectWinOpenId(selObj, focusObj, from) {
  for(var i = 0; i < selObj.length; i++) {
    if(selObj[i].selected) {
      if(selObj[i].value <= 0) {
        alert("很抱歉您选到无效选项上了");
        return;
      }
      for(var j = 0; j < focusObj.length; j++) {
        if(focusObj[j].value == selObj[i].value) {
          focusObj[j].selected = true;
          if(from == null || from.indexOf("search") < 0) {
            if(focusObj.name.indexOf("category_id_") >= 0) {
		      window.opener.checkCatalog();
		      if(focusObj.name.indexOf("category_id_1") >= 0) {
		        window.opener.setEditor(window.opener.catInfo[selObj[i].value],window.opener.document.all.editor);
		      }
		    } else if(focusObj.name.indexOf("subject_id_") >= 0) {
		      window.opener.checkSubject();
		    }
		  }
          window.close();
          window.opener.focus();
          return;
        }
      }
      window.opener.addOption(focusObj, selObj[i].value, selObj[i].innerHtml, from);
      window.close();
      window.opener.focus();
      return;
    }
  }
}

