function $(id) {
	return document.getElementById(id);
}
function selectedOption(id, value) {
	var options = $(id).options;
	for ( var i = 0; options && i < options.length; i++) {
		if (options[i].value == value) {
			options[i].selected = true;
			break;
		}
	}
}

function winShow(url, width, height) {
   var iTop = (window.screen.availHeight-30-height)/2;        //????λ;
   var iLeft = (window.screen.availWidth-10-width)/2;           //????λ;
	window.open(url, "", "top="+iTop+",left="+iLeft+",innerWidth="+(width-50)+",height="+height+", width="+width+", toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}

function closeSelf(success) {
	if (success == "success") {
		alert("?");
		reSubmitOpenerForm();
		window.close();
	}
}

function reSubmitOpenerForm() {
	var forms = window.opener.document.forms;
	if (forms.length > 0) {
		forms[0].submit();
	}
}

/**
 * @return ?еID?
 */
function getSelections() {
	var selectedIds = new Array();
	var ids = document.all.id;
	if (ids) {
		if(ids.length) {
			for (var i=0; i<ids.length; i++) {
				if (ids[i].checked) {
					selectedIds[selectedIds.length] = ids[i].value;
				}
			}
		} else if (ids.checked) {
			selectedIds[selectedIds.length] = ids.value;
		}
	}
	return selectedIds;
}
function DrawImage(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 isImageFile(path) {
	var index = path.lastIndexOf(".");
	if(index == -1) {
		return false;
	}
	var ext = path.substring(index, path.length);
	var type = /bmp|BMP|jpg|JPG|gif|GIF|jpeg|JPEG/;
	if(!type.test(ext)) {
		return false;
	}
	return true;
}