
	//***********************************************************************
	//* APPLICATION	: DDF+ Web
	//* COMPONENT	:
	//* PAGE			: This is a javascript library. IT contains the funtions
	//*					used for the searh forms (validation, submit, etc)
	//* CREATION		: 01.05.2000
	//* AUTHOR		: Vincent Graf
	//* CONTENT		:
	//*
	//***********************************************************************
	//* UPDATES		:
	//*
	//***********************************************************************

	//***********************************************************************
	// Function OnSubmit_Search is called when the submitbutton is used.
	// it handles the http request so SiteServer will understand it.
	//***********************************************************************
	function OnSubmit_Search(msg_str,iIsTranslator)
	{
	var ls_ct = "";
	var ls_ctt = "";
		//vgraf, 04.07.2000: removed mandatory dates
		if (false){
			//check the dates format
			setDefDates(); //to initialize the dates
			if (!pf_CheckDate(document.form_simpleSearch.ddsday.value)){
				return false;
			}
			if (!pf_CheckDate(document.form_simpleSearch.ddeday.value)){
				return false;
			}
			if (!pf_CheckDate(document.form_simpleSearch.dpsday.value)){
				return false;
			}
			if (!pf_CheckDate(document.form_simpleSearch.dpeday.value)){
				return false;
			}
			if (!pf_CheckDate(document.form_simpleSearch.drsday.value)){
				return false;
			}
			if (!pf_CheckDate(document.form_simpleSearch.dreday.value)){
				return false;
			}
		}

		// check catalogs value
		if (iIsTranslator == 1){
			for (var i=0; i < document.form_simpleSearch.elements.length; i++) {
				if (document.form_simpleSearch.elements[i].type == "radio") {
					if (document.form_simpleSearch.elements[i].name == "ct") {
						if (document.form_simpleSearch.elements[i].checked) {
							ls_ct = document.form_simpleSearch.elements[i].value;
						}
					}
				}
			}
			for (var j=0; j < document.form_simpleSearch.elements.length; j++) {
				if (document.form_simpleSearch.elements[j].type == "radio") {
					if (document.form_simpleSearch.elements[j].name == "ctt") {
						if (document.form_simpleSearch.elements[j].checked) {
							ls_ctt = document.form_simpleSearch.elements[j].value;
						}
					}
				}
			}

			if (ls_ctt == ls_ct) {
				alert(document.ALERTSAMECATALOGS);
				return false;
			}
		}
		if (!pf_CheckIsFormEmpty()){
			return false;
		}
 		//if (!pf_CheckFullText(msg_str)){
		//	return false;
		//}

                //Trim symbol
                if (document.form_simpleSearch.q2.value != "") {
                  document.form_simpleSearch.q2.value = trim(document.form_simpleSearch.q2.value);
                }

                //Trim full text
                if (document.form_simpleSearch.q1.value != "") {
                  document.form_simpleSearch.q1.value = trim(document.form_simpleSearch.q1.value);
                }

		//for the search, date is translated into yyyy/mm/dd
		ddsDate=document.form_simpleSearch.ddsday.value.slice(6,10)+ "/"  +document.form_simpleSearch.ddsday.value.slice(3,5)+ "/"  +document.form_simpleSearch.ddsday.value.slice(0,2) + ' 00:00:00';
		ddeDate=document.form_simpleSearch.ddeday.value.slice(6,10)+ "/"  +document.form_simpleSearch.ddeday.value.slice(3,5)+ "/"  +document.form_simpleSearch.ddeday.value.slice(0,2) + ' 23:59:59';
		dpsDate=document.form_simpleSearch.dpsday.value.slice(6,10)+ "/"  +document.form_simpleSearch.dpsday.value.slice(3,5)+ "/"  +document.form_simpleSearch.dpsday.value.slice(0,2) + ' 00:00:00';
		dpeDate=document.form_simpleSearch.dpeday.value.slice(6,10)+ "/"  +document.form_simpleSearch.dpeday.value.slice(3,5)+ "/"  +document.form_simpleSearch.dpeday.value.slice(0,2) + ' 23:59:59';
		drsDate=document.form_simpleSearch.drsday.value.slice(6,10)+ "/"  +document.form_simpleSearch.drsday.value.slice(3,5)+ "/"  +document.form_simpleSearch.drsday.value.slice(0,2) + ' 00:00:00';
		dreDate=document.form_simpleSearch.dreday.value.slice(6,10)+ "/"  +document.form_simpleSearch.dreday.value.slice(3,5)+ "/"  +document.form_simpleSearch.dreday.value.slice(0,2) + ' 23:59:59';
		//for SiteServer, q4 and q5 store the doc date
		// q8 and q9 the derestriction date
		// while posting dates will be append to the generic q0 fields later.
		if (ddsDate.length>=17)
			document.form_simpleSearch.q4.value=ddsDate ;
		if (ddeDate.length>=17)
			document.form_simpleSearch.q5.value=ddeDate ;
		if (drsDate.length>=17)
			document.form_simpleSearch.q8.value=drsDate ;
		if (dreDate.length>=17)
			document.form_simpleSearch.q9.value=dreDate ;
		//document.form_simpleSearch.q8.value=(drsDate!='//'?drsDate:'');
		//document.form_simpleSearch.q9.value=(drsDate!='//'?dreDate:'');

		//set the default value of the text_search field used for ???
		//NOTE: full text search is done via the q1 field
		//document.form_simpleSearch.text_search.value=document.form_simpleSearch.q1.value;

		//now starts to build the generic q0 field
		searchStr = new String("");
		if (document.form_simpleSearch.collections.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
		//	if (document.form_simpleSearch.collections.value == "WTO") {
		//		document.form_simpleSearch.collections.value="G OR IP OR JCR OR OFFICE OR PLURI OR S OR SCHD OR WT"
		//	}
			searchStr+="( @meta_Collection " + document.form_simpleSearch.collections.value + ")";
		}


		if (document.form_simpleSearch.restriction_type.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			searchStr+="( @meta_Restriction_Type " + document.form_simpleSearch.restriction_type.value + ")";
		}


		if (document.form_simpleSearch.bodies.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			searchStr+="( @meta_Bodies " + document.form_simpleSearch.bodies.value + ")";
		}

		if (document.form_simpleSearch.countries.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			searchStr+="( @meta_Countries " + document.form_simpleSearch.countries.value + ")";
		}

		if (document.form_simpleSearch.products.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			searchStr+="( @meta_Products " + document.form_simpleSearch.products.value + ")";
		}
		if (document.form_simpleSearch.organizations.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			searchStr+="( @meta_Organizations " + document.form_simpleSearch.organizations.value + ")";
		}

		if (document.form_simpleSearch.subjects.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			searchStr+="( @meta_Subjects  " + document.form_simpleSearch.subjects.value + ")";
		}
		if (document.form_simpleSearch.articles.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			searchStr+="( @meta_Articles " + document.form_simpleSearch.articles.value + ")";
		}

		if (document.form_simpleSearch.types.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			searchStr+="( @meta_Types " + document.form_simpleSearch.types.value + ")";
		}

		if (document.form_simpleSearch.meet_date.value != "") {
			if (searchStr!="") {
				searchStr+=" & ";
			}
			meetDate=document.form_simpleSearch.meet_date.value.slice(0,6) + document.form_simpleSearch.meet_date.value.slice(6,10)
			searchStr+="( @meta_Meet_Date \"" + meetDate + "\")";
			//searchStr+="( @meta_Meet_Date >=" + meetSDate + " & ";
			//searchStr+=" @meta_Meet_Date <=" + meetEDate + ")";
		}

		if (dpsDate.length>=17) {
			if (searchStr!="") {
					searchStr+=" & ";
				}
			searchStr+="( @Posting_Date  >= " + dpsDate  + ")";
		}
		if (dpeDate.length>=17) {
			if (searchStr!="") {
					searchStr+=" & ";
				}
			searchStr+="(@Posting_Date <= " + dpeDate + ")";
		}


		document.form_simpleSearch.q0.value=searchStr;
		return true;
	}


	//**********************************************************************
	//* This function clear the form fields
	//* CREATION	: 01.05.2000
	//* AUTHOR		: Vincent Graf
	//* CONTENT		:
	//*
	//***********************************************************************
	//* UPDATES		:
	//*
	//***********************************************************************
	function btnClearClick() {
		for (var i=0; i< document.form_simpleSearch.elements.length;i++){
			if (document.form_simpleSearch.elements[i].type == "text" ){
				document.form_simpleSearch.elements[i].value ="";
			}
			if (document.form_simpleSearch.elements[i].name == "ct" ){
				document.form_simpleSearch.elements[i].selectedIndex =0;
			}//if (document.form_simpleSearch.elements[i].name == "ctf" ){
				//document.form_simpleSearch.elements[i].selectedIndex =0;
			//}if (document.form_simpleSearch.elements[i].name == "ctt" ){
				//document.form_simpleSearch.elements[i].selectedIndex =0;
			//}
		}
		//set the default date value
		//setDefDates();
    }

	//**********************************************************************
	//* This private function check the date format
	//* CREATION	: 01.05.2000
	//* AUTHOR		: Vincent Graf
	//* CONTENT		: 
	//*		
	//***********************************************************************
	//* UPDATES		:
	//*
	//***********************************************************************
	function pf_CheckDate(ld_Date){
		ls_DateAux=new String(ld_Date);
		if ((ls_DateAux!='') &&
				((ls_DateAux.length != 10)||
				(ls_DateAux.slice(2,3)!="/")||
				(ls_DateAux.slice(5,6)!="/")||
				(ls_DateAux.slice(0,2)>31)||
				(ls_DateAux.slice(0,2)<1)||
				(ls_DateAux.slice(3,5)>12)||
				(ls_DateAux.slice(3,5)<1)))
		{
			alert(document.ALERTDATE);
			return false;			
		}else{
			return true;
		}
	}
	
	//**********************************************************************
	//* This private function check the date format
	//* CREATION	: 01.05.2000
	//* AUTHOR		: Vincent Graf
	//* CONTENT		: 
	//*		
	//***********************************************************************
	//* UPDATES		:
	//*
	//***********************************************************************
	function pf_CheckIsFormEmpty(){
		if ((document.form_simpleSearch.ddsday.value==document.form_simpleSearch.ddeday.value) 
			 	&& (document.form_simpleSearch.ddsday.value=="") 
			 	&& (document.form_simpleSearch.ddeday.value=="") 
			 	&& (document.form_simpleSearch.dpsday.value=="") 
			 	&& (document.form_simpleSearch.dpeday.value=="") 
 				&& (document.form_simpleSearch.collections.value == "")  
			    	&& (document.form_simpleSearch.q2.value == "")
			    	&& (document.form_simpleSearch.q6.value == "") 
			    	&& (document.form_simpleSearch.restriction_type.value == "")  
				&& (document.form_simpleSearch.q3.value == "")
			    	&& (document.form_simpleSearch.subjects.value == "")
			    	&& (document.form_simpleSearch.q1.value == "")
			    	&& (document.form_simpleSearch.countries.value == "")
			    	&& (document.form_simpleSearch.organizations.value == "")  
			    	&& (document.form_simpleSearch.products.value == "")
			    	&& (document.form_simpleSearch.articles.value == "")  
			    	&& (document.form_simpleSearch.bodies.value == "")
			    	&& (document.form_simpleSearch.types.value == "")  
			    	&& (document.form_simpleSearch.meet_date.value == "")
			    	&& (document.form_simpleSearch.drsday.value == "")  )
		{
				alert(document.ALERTFORMEMPTY);
				return false;
		}else{
				return true;
		}
	}
	
	//**********************************************************************
	//* This private function add a leading zero when date day or month are smaller than 10
	//* CREATION	: 01.05.2000
	//* AUTHOR		: Vincent Graf
	//* CONTENT		: 
	//*		
	//***********************************************************************
	//* UPDATES		:
	//*
	//***********************************************************************
	function addLeadingZeros(valStr)
	{
		strT= new String(valStr);
		if (strT.length == 1){
			return "0" + valStr;
		}
		return valStr;
	}

	//**********************************************************************
	//* This private function check set the date default value if date fields 
	//*	are empty
	//* CREATION	: 01.05.2000
	//* AUTHOR		: Vincent Graf
	//* CONTENT		: 
	//*		
	//***********************************************************************
	//* UPDATES		:
	//*
	//***********************************************************************
	function setDefDates ()
	{
		Obj2=document.form_simpleSearch;
		docDayStart="01";
		docMonthStart="01";
		docYearStart="1986";

		postDayStart="01";
		postMonthStart="01";
		postYearStart="2000";

		DocDateDDStart = docDayStart;
		DocDateMMStart = docMonthStart ;
		DocDateYYYYStart =docYearStart; 
		
		DocDatePostDDStart = postDayStart; 
		DocDatePostMMStart = postMonthStart ;
		DocDatePostYYYYStart =postYearStart;

		today = new Date();
		DocDateDDEnd =addLeadingZeros(today.getDate()) ;
		DocDateMMEnd = addLeadingZeros(today.getMonth()+1) ;
		DocDateYYYYEnd =(today.getYear()<1000?today.getYear()+1900:today.getYear()) ;
		
		DocDatePostDDEnd =addLeadingZeros( today.getDate()) ;
		DocDatePostMMEnd =addLeadingZeros( today.getMonth()+1) ;
		DocDatePostYYYYEnd =(today.getYear()<1000?today.getYear()+1900:today.getYear())

		if (Obj2.ddsday.value == ''){
			Obj2.ddsday.value = ""+DocDateDDStart + "/" +DocDateMMStart + "/" + DocDateYYYYStart;
		}
		if (Obj2.ddeday.value == ''){
			Obj2.ddeday.value = ""+DocDateDDEnd + "/" +DocDateMMEnd + "/" +DocDateYYYYEnd;
		}
		if (Obj2.dpsday.value == ''){
			Obj2.dpsday.value = ""+DocDatePostDDStart + "/" +DocDatePostMMStart + "/" + DocDatePostYYYYStart;
		}
		if (Obj2.dpeday.value == ''){
			Obj2.dpeday.value = ""+DocDatePostDDEnd + "/" +DocDatePostMMEnd + "/" +DocDatePostYYYYEnd;
		}
	}

	//**********************************************************************
	//* This private function checks that if the full text field is not empty
	//*	then only one catalog must be selected
	//* CREATION	: 16.08.2000
	//* AUTHOR		: Vincent Graf
	//* CONTENT		: 
	//*		
	//***********************************************************************
	//* UPDATES		:
	//*
	//***********************************************************************
	function pf_CheckFullText (msg_str)
	{
		if (document.form_simpleSearch.ct.options[1].selected && document.form_simpleSearch.ct.options[3].selected && document.form_simpleSearch.ct.options[0].selected)
			 document.form_simpleSearch.ct.options[0].selected=false;
		if (msg_str=='') return true;
		if (document.form_simpleSearch.q1.value == ''){
			return true;
		}else{
			if((document.form_simpleSearch.ct.options[0].selected)||
				(document.form_simpleSearch.ct.options[1].selected && document.form_simpleSearch.ct.options[2].selected)||
				(document.form_simpleSearch.ct.options[1].selected && document.form_simpleSearch.ct.options[3].selected)||
				(document.form_simpleSearch.ct.options[2].selected && document.form_simpleSearch.ct.options[3].selected)||
				(document.form_simpleSearch.ct.options[1].selected && document.form_simpleSearch.ct.options[2].selected && document.form_simpleSearch.ct.options[3].selected))

			{
				alert (msg_str);
				return false;
			}else{
				return true;
			}
		}
	}
	
	function trim(inputString) {
           // Removes leading and trailing spaces from the passed string. Also removes
           // consecutive spaces and replaces it with one space. If something besides
           // a string is passed in (null, custom object, etc.) then return the input.
           if (typeof inputString != "string") { return inputString; }
           var retValue = inputString;
           var ch = retValue.substring(0, 1);
           while (ch == " ") { // Check for spaces at the beginning of the string
              retValue = retValue.substring(1, retValue.length);
              ch = retValue.substring(0, 1);
           }
           ch = retValue.substring(retValue.length-1, retValue.length);
           while (ch == " ") { // Check for spaces at the end of the string
              retValue = retValue.substring(0, retValue.length-1);
              ch = retValue.substring(retValue.length-1, retValue.length);
           }
           /*
           while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
              retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
           }
           */
           return retValue; // Return the trimmed string back to the user
        } // Ends the "trim" function

