//----------------------
// search form functions
//----------------------

// search form HTML string
var sb = "";

// draw the search box
function drawSearchBox(formName,formURL)
{
	sb="<table width=\"435\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"/res/img/new_header/login_right_ground_cerca.gif\" style=\"background-repeat:no-repeat;\">"+
	    "<form name=\"" + formName + "\" target=\"_top\" method=\"POST\" action=\"" + formURL + "\" onSubmit=\"return validateSearchForm(this);\">"+ 
		"<tr valign=\"top\"><td height=\"35\" width=\"210\" >&nbsp;</td>"+
		"<td width=\"105\" align=\"left\"><img class=\"h_ten\" src=\"/res/img/new_header/login_cosa_cerchi.gif\" alt=\"Cosa cerchi?\"></td><td ><input type=\"text\"  name=\"criteria\" class=\"find\" style=\"margin-top:6px;\">&nbsp;&nbsp;</td>"+
		"<td width=\"120\"><!--a href=\"#\"--><input type=\"image\" onFocus=\"if(this.blur)this.blur()\" src=\"/res/img/new_header/btn_login_vai.gif\" border=\"0\" alt=\"Vai\" title=\"Vai\"/><!--/a-->&nbsp;<a href=\"javascript:hideSearchBox();\"><img src=\"/res/img/new_header/btn_login_chiudi.gif\" alt=\"Chiudi\"  border=\"0\"  title=\"Chiudi\"></a></td>"+
		"</tr></form></table>";
	if(!isNS4()) document.write(sb);
}

// draw the search box
function draw_139_SearchBox(formName,formURL)
{	
	sb="<table width=\"139\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"/res/img/new_header/new_loginbar/ricerca_139_back.gif\" style=\"background-repeat:no-repeat;\">"+
	    "<form name=\"" + formName + "\" target=\"_top\" method=\"POST\" action=\"" + formURL + "\" onsubmit=\"return validateSearchForm(this)\">"+ 
		"<tr valign=\"top\">"+
		"<td width=\"65\" height=\"35\" style=\"padding-top:6px;\"><input type=\"text\"  name=\"criteria\" style=\"width:60px;font-size:10px;margin-right:2px;margin-left:3px;\"></td>"+
		"<td width=\"74\" align=\"right\"><input type=\"image\" onFocus=\"if(this.blur)this.blur()\" src=\"/res/img/new_header/new_loginbar/btn_freccie_vai_139.gif\" border=\"0\" alt=\"Vai\" title=\"Vai\"/><a href=\"javascript:hideSearchBox();\" onfocus=\"this.blur();\"><img style=\"margin-left:3px;margin-right:6px;\" src=\"/res/img/new_header/new_loginbar/btn_chiudi_139.gif\" alt=\"Chiudi\"  border=\"0\"  title=\"Chiudi\"></a></td>"+
		"</tr></form></table>";
	if(!isNS4()) document.write(sb);	
}

// draw the search box
function draw_168_SearchBox(formName,formURL)
{	
	sb="<table width=\"168\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" background=\"/res/img/new_header/new_loginbar/ricerca_168_back.gif\" style=\"background-repeat:no-repeat;\">"+
	    "<form name=\"" + formName + "\" target=\"_top\" method=\"POST\" action=\"" + formURL + "\" onsubmit=\"return validateSearchForm(this)\">"+ 
		"<tr valign=\"top\">"+
		"<td width=\"76\" align=\"left\" height=\"35\" style=\"padding-top:6px;\"><input type=\"text\"  name=\"criteria\" style=\"width:70px;font-size:10px;margin-right:3px;margin-left:3px;\"></td>"+
		"<td width=\"92\" align=\"right\"><input type=\"image\" onFocus=\"if(this.blur)this.blur()\" src=\"/res/img/new_header/new_loginbar/btn_login_w_freccie.gif\" border=\"0\" alt=\"Vai\" title=\"Vai\"/><a href=\"javascript:hideSearchBox();\" onfocus=\"this.blur();\"><img style=\"margin-left:3px;margin-right:6px;\" src=\"/res/img/new_header/new_loginbar/btn_login_chiudi.gif\" alt=\"Chiudi\"  border=\"0\"  title=\"Chiudi\"></a></td>"+
		"</tr></form></table>";
	if(!isNS4()) document.write(sb);	
}



// hide the search box
function hideSearchBox()
{
        MM_showHideLayers('hdInnerRicercaOff','','show');
        MM_showHideLayers('hdInnerRicercaOn','','hide');
}

// show the search box
function showSearchBox()
{
        if (isNS4()) setTextOfLayerCouple(sb, "hdOuterRicerca", "hdInnerRicercaOn");
        MM_showHideLayers('hdInnerRicercaOff','','hide');
        MM_showHideLayers('hdInnerRicercaOn','','show');
}

function isStringValid(inputString, compareString)
{
        var length = inputString.length;
        var index;

        for (index = 0; index < length; index++)
        {
                if (compareString.indexOf(inputString.charAt(index), 0) < 0)
                {
                        return false;
                }
        }

        return true;
}

function submitValidateSearchForm(theForm)
{
        if (theForm.criteria.value.length == 0)
        {
                alert("Spiacente: ricerca non eseguibile.\n" + String.fromCharCode(201) + " necessario inserire una stringa di ricerca");
                theForm.criteria.focus();
                return false;
        }

        var graveChars = String.fromCharCode(249,224,232,233,242,236);
        var euroChar = String.fromCharCode(8364); // the euro char

        if (!isStringValid(theForm.criteria.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + 
                                                    graveChars + "'+ -./&_\"" + euroChar))
        {
                alert("Spiacente: ricerca non eseguibile.\nHai utilizzato dei caratteri non validi nella tua ricerca");
                theForm.criteria.focus();
                return false;
        }
		theForm.submit()
        return true;
}

// search form validation
function validateSearchForm(theForm)
{
        if (theForm.criteria.value.length == 0)
        {
                alert("Spiacente: ricerca non eseguibile.\n" + String.fromCharCode(201) + " necessario inserire una stringa di ricerca");
                theForm.criteria.focus();
                return false;
        }

        var graveChars = String.fromCharCode(249,224,232,233,242,236);
        var euroChar = String.fromCharCode(8364); // the euro char

        if (!isStringValid(theForm.criteria.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + 
                                                    graveChars + "'+ -./&_\"" + euroChar))
        {
                alert("Spiacente: ricerca non eseguibile.\nHai utilizzato dei caratteri non validi nella tua ricerca");
                theForm.criteria.focus();
                return false;
        }

        return true;
}
