/*
 * arnet_fn.js
 * # dependence: jquery 1.2.6
 *
 * Copyright (c) 2009 Bo Gao (elivoa@gmail.com)
 *
 * $Date: 2009-06-10 $
 */

/**
 * Replace invalid characters in a query.
 */
function keyword_parse(s) {
	// alert( s.replace( /[^\w.-]/g , "") );
	return s.replace(/[^\w.-]/g, "");
}

/**
 * Moved from show-img.js
 * 
 * @param div
 * @param minwidth
 * @param minheight
 * @return
 */
function resizeimg(div, minwidth, minheight) {
	div.style.display = 'none';
	if (div.width > minwidth || div.height > minheight) {
		div.resized = true;
		if (div.width/minwidth<div.height/minheight) {
			div.width = minwidth;
		}else if(div.height/minheight<div.width/minwidth) {
			div.height = minheight;
		}
	}
	div.style.display = 'block';
}

/**
 * Arnet specific. Check Forms.
 * 
 * @param type
 * @return
 */
function ckformheader(type) {
	if (type == 1) {
		if (trim(document.form1.keyword.value) == ""
				|| keyword_parse(document.form1.keyword.value) == "") {
			document.form1.keyword.focus();
			return false;
		}
	} else if (type == 2) {
		if (trim(document.form1.person1.value) == ""
				|| keyword_parse(document.form1.person1.value) == ""
				|| trim(document.form1.person2.value) == ""
				|| keyword_parse(document.form1.person2.value) == ""
				|| document.form1.person1.value < 0
				|| document.form1.person2.value < 0) {
			alert("please choose two persons first!");
			return false;
		}
	}
}

/*******************************************************************************
 * Validators
 ******************************************************************************/
function isDigit(s) {
	var patrn = /^[0-9]{1,20}$/;
	if (!patrn.exec(s)) {
		return false;
	}
	return true;
}