/**
 * check text no-input at document.Target.text
 *
 * set parameter 
 * from document.Target.text
 * for document.Target.inputFreeWord, document.Target.p1, document.Target.shopName, document.Target.q
 */
function multiSearch(message) {
	if('' == document.Target.text.value) {
		alert(message);
		return false;
	} else {
		
		// google custom search is GET method only
		var engine = document.Target.Sel.value;
		var val = document.Target.text.value;
		if (engine.indexOf("site") > 0) {
			document.Target.method = 'GET'; 
		} else {
			document.Target.method = 'POST'; 
			document.Target.shopName.value = val; 
		}
		document.Target.q.value = val; 
		
		// submit by Shift-JIS 
		var org_chr = document.charset;
		document.charset = 'Shift-JIS';
		return true;
	}
}

/**
 * Blocking double-click when form submited.
 * @param button button element.  fix [this]
 * @param target chek text no-input 
 * @param replace word when click button
 */
function doubleClickGuard(button, target, replace) {
	if(target != null && target.value == '') return false;

	button.disabled = true;
	if (replace != null)button.value = replace;
	guardDoubleClick = waitAlert;
	button.form.submit();
	return false;
}

function trim(value) {
	return value.replace(/(^\s*)|(\s*$)/g, "");  
}
/**
 * Blocking double-click when form submited.
 * @param button button element.  fix [this]
 * @param target chek text no-input 
 * @param replace src when click button
 */
function doubleClickGuardImage(target, btn, replace) {

	if(target != null && trim(target.value) == '') {
		alert('入力がありません。')
		return false;
	}
	if (btn == null) return true;
	var button = $(btn);
	
	// use prototype
	if (replace != null) button.writeAttribute('src', replace);
	button.writeAttribute('disabled', 'disabled');
	
	guardDoubleClick = waitAlert;
	return true;
}
function resetGuardImage(target, btn, replace) {

	if(target != null) {
		target.select();
	}
	if (btn == null) return;
	var button = $(btn);
	
	// use prototype
	if (replace != null) button.writeAttribute('src', replace);
	button.writeAttribute('disabled', null);
}


/**
 * This code for Mac safari
 */
function waitAlert() {
	alert('wait a moment');
	return false;
}

/**
 * set YUI auto complete default setting.
 * @param autoComp YAHOO.widget.AutoComplete
function setAutoComp(autoComp) {
	autoComp.minQueryLength = 2; 
	autoComp.queryDelay = .5;
	autoComp.maxResultsDisplayed = 10;
}
 */
/*
 * get modelData from Servlet

function getModelAutoComp(input, suggestDiv) {
	var csv = "/i/f/modelSuggest";
	var element = [",", "\n"];
	var xhrDS = new YAHOO.widget.DS_XHR(csv, element);
	
	xhrDS.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
	xhrDS.maxCacheEntries = 100;
	
	var autoComp = new YAHOO.widget.AutoComplete(input, suggestDiv, xhrDS);
	autoComp.minQueryLength = 2; 
	autoComp.queryDelay = .5;
	autoComp.maxResultsDisplayed = 10;
	
	return autoComp;
}
*/
/**
 * get modelData from Array
 * @see /js/data/models.js
 */
function getModelAutoComp(input, suggestDiv) {

	var array = new YAHOO.widget.DS_JSArray(getModels());
//	array.queryMatchContains = true;
	
	var autoComp = new YAHOO.widget.AutoComplete(input, suggestDiv, array);
	autoComp.minQueryLength = 2; 
	autoComp.queryDelay = .5;
	autoComp.maxResultsDisplayed = 10;
	
	return autoComp;
}

