// Javascript functions used in the main pages

// to Search Film and Festivals

function GoSearchFest() {
	theForm = this.document.FestSearch;

	//var detail = MiseEnMaj(theForm.DetailNom.value);
	var detail = ConvertCaseNonSensible(theForm.DetailNom.value) ;

	theForm.SQL.value = "select * from fest where fest_nom like '%" + detail +"%' order by fest_nom" ;
	theForm.NOSQL.value = "SELECT fest.fest_num,fest.fest_nom,fest_ville,fest.fest_loc_ville FROM fest WHERE fest.fest_private=1" ;
	SubmitForm(theForm) ;
}

function SubmitForm(form)
{
	form.action='http://www.filmfestivals.com/servlet/JSCRun' ;
	//alert("submit !") ;
	form.submit() ;
}
function ConvertCaseNonSensible(toConvert) 
{

	//var nSizeRadio = myForm.CaseSensible.length;
	var resultat = toConvert.value ;	
	//myForm.key.value = myForm.keyPage.value;
	
	{//begin
		var strConvertOrig = String(toConvert);
		var strConvert = strConvertOrig;
		var strConverted = String(""), strTmp=String("");
		var strLastOne = String("");
		var strKeyToExclureForOR = String("%");
		var strSub = String ("");
		var endspace = 0 ;
		strConvert = strConvert .toUpperCase();
		
		
		var i, nSize = strConvert.length, nPosB = 0;
		var nbsep=0 ;
		var nbexp=0 ;
		
		for (i = 0; i < nSize;i++)
		{
			strTmp = strConvert.charAt(i);
			strTmpLower = strTmp.toLowerCase();

			//alert("strTmp : "+strTmp) ; 
			if (strLastOne == ' ' && strTmp == ' ')
			{
				endspace = 1 ; //nothing, we skip the empty
			}
			else
			{
				if (strTmp == ' ')
				{
				
					if(i==nSize-1)
						endspace = 1 ;
						
					//alert("i="+i+"nbexp="+nbexp+" strConverted : "+strConverted+"("+eval(nPosB+nbexp)+","+eval((Number(i-nbexp)*4)+nbexp)+")") ;
				strSub = strConverted.substring(eval(nPosB+nbexp),eval((Number(i-nbexp)*4)+nbexp));
					//alert("strSub : "+strSub) ;
					
					//alert(nPosB+"-"+eval((Number(i)*4))) ;
					
					strKeyToExclureForOR += strSub + '%';
					//alert("strKeyToExclureForOR : "+strKeyToExclureForOR) ;			
					
					
					strConverted = strConverted + strConvert.charAt(i);
					
					nPosB = eval((Number(i-nbexp)*4)) ;
					nbexp++ ;
				}
				else
				{
				strConverted = strConverted +'['+strConvert.charAt(i)+strTmpLower+']';					
				}
			}
			strLastOne = strTmp;
			
		}//for
		
		//if(endspace==1)
			//alert("finit par un ou des espaces") ;
		//alert(nPosB) ;
		//alert("strConverted + taille substring : "+strConverted+"("+eval(nPosB-1)+"-"+eval((Number(i-1)*4))+")") ;
		//strSub = strConverted.substring(eval(nPosB-4), eval((Number(i-1)*4)));
		
		if(endspace == 0)
		{
		strSub = strConverted.substring(eval(nPosB+nbexp-1),eval((Number(i-nbexp)*4)+nbexp));
		
		//alert("strSub : "+strSub) ;
		strKeyToExclureForOR += strSub + '%';
		}
		//alert("strKeyToExclureForOR : "+strKeyToExclureForOR) ;
		
		}//end
	//alert("strSub"+strSub) ;
	resultat = strKeyToExclureForOR ;
	
	return resultat ;
	
}

