/**
 *  Site Search Form Control, version 1.0.0
 *  (c) 2007 Arturo La Monaca - GSSI srl <arturo.lamonaca@gssi.it>
 */

wsm.include("event.js");
wsm.include("dom.js");

var wsm_siteSearch_detailsDiv;
 
function wsm_siteSearch_Submit() {
	var errors = "";
	var searchQuery = $('wsm_siteSearchQuery');
	if (searchQuery.value == "")
		return false;
		
	wsm_siteSearch_detailsDiv = new FloatLayer($('SearchDetailsDiv'));
	wsm_siteSearch_detailsDiv.show();
	
	return false;
}

function wsm_siteSearch_confirm(typeOfSearch) {
	if (typeOfSearch == "allsite") {
		wsm_siteSearch_detailsDiv.hide();
		$('wsm_siteSearch_form').submit();
	} else if(typeOfSearch == "products") {
		wsm_siteSearch_detailsDiv.hide();
		$('wsm_siteSearch_mainFieldName').value = "short-content";
		$('wsm_siteSearch_searchAreaId').value = "prodotti";
		$('wsm_siteSearch_form').submit();
	} else
		wsm_siteSearch_detailsDiv.hide();
}

function FloatLayer(divObj) {
	this.parentdiv = (divObj.parentElement || divObj.parentNode);
	this.div = divObj;
	
	this.reposition = function(e) {
		var w = this.parentdiv.offsetWidth;
		var h = this.parentdiv.offsetHeight;
		
		var absPos = DOM.getAbsPosition(this.parentdiv, Screen.getBody());
		var t = absPos.absTop + h + 1;
		var l = absPos.absLeft;

		this.div.style.width = w + 'px';
		this.div.style.top = t + 'px';
		this.div.style.left = l + 'px';
	}
	
	this.show = function(e) {
		this.reposition(e);
		this.div.style.display = 'block';
	}
	
	this.hide = function() {
		this.div.style.display = 'none';
	}

}