function openImageBox(type, target, opt) {
	if(opt == undefined) {
		window.open("/picture.php?o=1&s="+type+"&t="+target,"ArticleImageBox","width=630,height=540,toolbar=no,scrollbars=yes,status=no");
	} else if (opt == 2) {
		window.open("/picture.php?o=2&s="+type+"&t="+target,"ArticleImageBox","width=630,height=540,toolbar=no,scrollbars=yes,status=no");
	}
}

function openFileBox(type, target, opt) {
	window.open("/picture.php?a=file_input&s="+type+"&t="+target,"ArticleImageBox","width=630,height=490,toolbar=no,scrollbars=yes,status=no");
}

function openURLBox(type, target, opt) {
	value1 = prompt("Please insert URL. e.g) http://www.phytophthoradb.org/");
	value2 = prompt("Please insert the name of URL. e.g) Go to Phytophthora Database");
	putURL(type, target, value1, value2);
}

function openMap(x, y, width, height, comment, size, opt) {
	window.open("/location.php?a=map&x="+x+"&y="+y+"&width="+width+"&height="+height+"&comment="+comment+"&opt="+opt+"&size="+size,"ArticleImageBox","width=640,height=480,toolbar=no,scrollbars=no,status=no");
}

function save_pos(obj) {
	if (obj.createTextRange) obj.currentPos = document.selection.createRange().duplicate();
	return true;
}

function set_tag_support(obj, prefix, postfix) {
	if (document.selection) {
		if (obj.createTextRange && obj.currentPos) {
			obj.currentPos.text = prefix + obj.currentPos.text + postfix;
			obj.focus();
			save_pos(obj);
		} else obj.value = obj.value + prefix + postfix;
	} else if (obj.selectionStart && obj.selectionEnd) {
		var s1 = obj.value.substring(0, obj.selectionStart);
		var s2 = obj.value.substring(obj.selectionStart, obj.selectionEnd);
		var s3 = obj.value.substring(obj.selectionEnd);
		obj.value = s1 + prefix + s2 + postfix + s3;
	} else obj.value += prefix + postfix;
	return true; 
} 

function putImage1(id, to, target, width, height) {
	var imageurl = "[img|id="+id+"|border="+document.input.bordersize.value+"|width="+width+"|height="+height+"|vspace="+document.input.vspacesize.value+"|hspace="+document.input.hspacesize.value+"|align="+document.input.aligntype.value+"]";

	var obj = eval('opener.document.'+to+'.'+target);
	opener.set_tag_support(obj, imageurl, '');
	this.close();
}

function putImage2(id, to, target, url, width, height) {
	var obj = eval('opener.document.'+to+'.'+target);
	obj.value = id;
	obj = eval('opener.document.thumb');
	obj.src = url;
	if(to == "modify") {
		opener.document.modify.lifecycle_image_id.value = id;
		opener.document.modify.lifecycle_file_width.value = width;
		opener.document.modify.lifecycle_file_height.value = height;
	} else {
		opener.document.input.lifecycle_image_id.value = id;
		opener.document.input.lifecycle_file_width.value = width;
		opener.document.input.lifecycle_file_height.value = height;
	}
	this.close();
}

function putFile(id, file_name, to, target) {
	var fileurl = "[file|id="+id+"|name="+file_name+"]";
	var obj = eval('opener.document.'+to+'.'+target);
	opener.set_tag_support(obj, fileurl, '');
	this.close();
}

function putURL(to, target, value1, value2) {
	var url = "[url|url="+value1+"|name="+value2+"]";
	var obj = eval('document.'+to+'.'+target);
	set_tag_support(obj, url, '');
}

function checkLoginData(form) {
	if (form.id.value == '') {
		alert('¾ÆÀÌµð¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä');
		form.id.focus();
		return;
	}

	if (form.pw.value == '') {
		alert('¾ÏÈ£¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä');
		form.pw.focus();
		return;
	}

	form.submit();
}

function checkKeyPw() {
	if (event.keyCode == 13) {
		checkLoginData(document.login);
	}
}

function preview(obj) {
	document.contents.contents.value = obj.value;
	window.open("about:blank","Preview","width=800,height=400,toolbar=no,scrollbars=yes,status=no");
	document.contents.target = "Preview";
	document.contents.submit();
}

function goFavorite(form) {
	if(form.fid.value == '') {
		alert("There is no seleted Favorite.");
		return;
	}
	location.href="./iframe.php?a=favorite_dv&id="+form.fid.value;
}

function go_quick_search(form) {
	var opt;
	for(i = 0 ; i < form.search_type.length ; i++) {
		if(form.search_type[i].checked == true) {
			opt = i;
		}
	}
	opt++;
	var sv = form.sv.value;
	switch (opt) {
		case 1:
			location.href = "species.php?sf=SPECIES_NAME&sv="+sv+"&opt=1";
			break;
		case 2: 
			location.href = "isolate.php?sf=NAME&sv="+sv+"&opt=1";
			break;
		case 3: 
			location.href = "marker.php?sf=NAME&sv="+sv+"&opt=1";
			break;
		case 4: 
			location.href = "picture.php?opt=1";
			break;
		defalut:
			break;
	}
}
