/* ----- Notes ----- 	Last Modified:	2008-03-21 Andy H	HTML files:		wSearchBar	Framework:		Omnis Studio - StudioWorks Framework	Written by: 	Doug Kuyvenhoven, doug@vencor.ca	Copyright: 		Vencor Software 2006, www.vencor.ca*/// ----- Action Methods -----function checkForEnter(evt) {	if (evt.keyCode == 13) {	 submitSearch();	 return false;	 	} else {	return true;	}}function eventClickSearchColsList() {	//Get the current operator		setSearchOperatorsList();	setDefaultSearchOperator();	setSearchEntryField();	setCurrField();}function eventClickSearchOperatorsList() {	setSearchEntryField();	setCurrField();}function initSearchBar() {	setDefaultSearchCol();	setSearchOperatorsList();	setDefaultSearchOperator();	setSearchEntryField();			setDefaultSearchEntryValue();	setCurrField();	var rObj = ExistingSearchCriteriaStringRef();	rObj.value = "" ;	return true;}function retSearchCriteriaString() {		// Figure out the search criteria.		var rCol = SelectedSearchColRef();		var rOperator = SelectedOperatorRef();		var ColType = rCol.value;		var rEntry = SearchEntryFieldRef();		var OperatorValue = rOperator.value; 		var Value = ""		switch (ColType) {			case "checkbox" :							Value = rEntry.checked;				break;						case "date" :				if (OperatorValue=="TODAY") {						Value = " ";						break;						}				else {						Value = rEntry.value;						break;						}			case "hidden" :							Value = "";				break;						default :				Value = rEntry.value;				break;		}				if (Value.length==0) {			Criteria = null;		}		else {					var Criteria = rCol.id+","+rOperator.value+","+Value;		}		return Criteria}function setCurrField() { SearchEntryFieldRef().focus(); }function setDefaultSearchCol() {	// Get the default search criteria string into an array.	var SearchRow = DefaultSearchCriteriaString().split(',');	var ColName = SearchRow[0];	if (ColName) {				// Set the selected column.		if (ColName) {						var rObj= SearchColsListRef();			var OptionsArray = rObj.options;			for (i=0; i<OptionsArray.length; i++) {				if (OptionsArray[i].id==ColName) {					rObj.selectedIndex=i;					break;				}							}		}			} 	else {			SearchColsListRef().selectedIndex=0;	}}function setDefaultSearchEntryValue() {	// Get the default search criteria string into an array.	var SearchRow = DefaultSearchCriteriaString().split(',');	if (SearchRow.length) {			var Value = SearchRow[2];				// Set the search entry value		if (Value) {					SearchEntryFieldRef().value = Value;		}		}	}function setDefaultSearchOperator() {	// Get the default search criteria string into an array.	var SearchRow = DefaultSearchCriteriaString().split(',');	if (SearchRow.length) {		var Operator = SearchRow[1];				// Set the selected operator.		if (Operator) {			var rObj= SearchOperatorsListRef();			var OptionsArray = rObj.options;			for (i=0; i<OptionsArray.length; i++)			{				if (OptionsArray[i].value==Operator)				{					rObj.selectedIndex=i;					break;				}				}		}			}	}function setSearchEntryField() {	if (document.all) { // Is this IE?			setSearchEntryField_IE(); // Call special IE function			} 	else {				var rObj = SearchEntryFieldRef();		var ColType = SelectedSearchColType();				if (ColType=="checkbox") {			if (rObj.type!="checkbox") {				rObj.type="checkbox";				rObj.checked="true";				rObj.disabled="true";			}		}		else {					rObj.disabled="";			if (rObj.type!="text") {										rObj.type="text";			}//	added 2010-01-23 see if we are a fetchall and if so use xmlhttprequest to fill in options//			var rOperatorRef = SelectedOperatorRef();//			if rOperatorRef.fetchall=="yes" {//				alert("fetchall");//			}//			else {//			rObj.InnerHTML=""//			}		}	}}function setSearchEntryField_IE() {	// Workaround for Internet Explorer because	// IE does not allow us to change the 'type'		var rObj = SearchEntryFieldRef();	var ColType = SelectedSearchColType();		if (ColType=="checkbox") {		rObj.disabled="true";		rObj.value="Yes";	} 	else {		rObj.disabled="";		if (rObj.value="Yes") {					rObj.value="";		}//	added 2010-01-23 see if we are a fetchall and if so use xmlhttprequest to fill in options//			var rOperatorRef = SelectedOperatorRef();//			if rOperatorRef.fetchall=="yes" {//				alert("fetchall");//			}//			else {//			rObj.InnerHTML=""//			}			}				}function setSearchOperatorsList() {						var rCol = SelectedSearchColRef();	var ColType = rCol.value;	var rObj = SearchOperatorsListRef();		// Remove the existing options	rObj.options.length = 0;	// Add the options to the suit the column type.	switch (ColType) {		case "checkbox" :					// Boolean			var list = new Array			rObj.options[0] = new Option('is','=');			rObj.options[1] = new Option('is not','<>');			rObj.options[2] = new Option('is null','IS NULL');			rObj.options[3] = new Option('is not null','IS NOT NULL');										break;					case "number" :					rObj.options[0] = new Option('is equal to','=');			rObj.options[1] = new Option('is not equal to','<>');			rObj.options[2] = new Option('is greater than or equal to','>=');			rObj.options[3] = new Option('is less than or equal to','<=');			rObj.options[4] = new Option('is null','IS NULL');			rObj.options[5] = new Option('is not null','IS NOT NULL');			break;					case "date" :					rObj.options[0] = new Option('is on','=');			rObj.options[1] = new Option('is on or after','>=');			rObj.options[2] = new Option('is on or before','<=');			rObj.options[3] = new Option('is today','TODAY');			rObj.options[4] = new Option('is null','IS NULL');			rObj.options[5] = new Option('is not null','IS NOT NULL');			break;								default :					// character						rObj.options[0] = new Option('contains','%LIKE%');			rObj.options[1] = new Option('begins with','LIKE%');			rObj.options[2] = new Option('does not contain','NOT %LIKE%');			rObj.options[3] = new Option('is','=');			rObj.options[4] = new Option('is not equal to','<>');			rObj.options[5] = new Option('is greater than or equal to','>=');			rObj.options[6] = new Option('is less than or equal to','<=');			rObj.options[7] = new Option('is null','IS NULL');			rObj.options[8] = new Option('is not null','IS NOT NULL');			break;	}}function submitSearch() {	// first clear anything that may be in the xml return as we are getting a search directly now	document.getElementById('searchResult').innerHTML = "";	var Criteria = retSearchCriteriaString();	if (Criteria == null) {			alert("Please enter a search value - null criteria set.");	}	else {			// Prepare the form		var rForm = SearchBarFormRef();		var MethodName = "search";		prepareForm(rForm,MethodName)		addWinInstInputs(rForm);				addHiddenInput(rForm,"SearchCriteriaString",Criteria)				//		var Value = document.getElementById('SessionID').value ;//alert(Value);//		addHiddenInput(rForm,"SessionID",Value);						// Submit the form to the Omnis web app server.		// The window instance is not changing, so we can submit the form ourself.		rForm.submit();	}}function addSearch_orig() {	var Criteria = retSearchCriteriaString();	if (Criteria == null) {			alert("Please enter a search value - criteria not yet set.");	}	else {			// Prepare the form		var rForm = SearchBarFormRef();		var MethodName = "addsearch";				prepareForm(rForm,MethodName)		addWinInstInputs(rForm);		addHiddenInput(rForm,"SearchCriteriaString",Criteria)				// Submit the form to the Omnis web app server.		// The window instance is not changing, so we can submit the form ourself.		rForm.submit();	}}function addSearch() {// Validate existing search then amend value of ExistingSearchCriteriaString	var Criteria = retSearchCriteriaString();	if (Criteria == null) {			alert("Please enter a search value - criteria not yet set.");	}	else {			var ExistingString = ExistingSearchCriteriaString();		if (ExistingString.length) {			ExistingString = ExistingString+"//"+Criteria;			}		else {			ExistingString = Criteria;			}		var rObj = ExistingSearchCriteriaStringRef();		rObj.value = ExistingString;				var existingHTML = convertExistingToHTML(ExistingString) ;		document.getElementById('existingEntries').innerHTML = existingHTML ;	}}function convertExistingToHTML(pExistingString) {	var ReturnHTML = "" ;	var LineContent = pExistingString.split("//") ;	var i ;	var j ;	var x ;	var TextToAdd ;	var rObj ;	var OptionsArray ;	if (pExistingString.length) {		for (i in LineContent) {			var FieldContent = LineContent[i].split(",") ;			for (x in FieldContent) {				if 	(x==0) {								rObj= SearchColsListRef();					OptionsArray = rObj.options;					for (j=0; j<OptionsArray.length; j++) {						if (OptionsArray[j].id==FieldContent[0]) {						TextToAdd=OptionsArray[j].innerHTML;						break;						}									}							}				else if (x==1) {					rObj= SearchOperatorsListRef();					OptionsArray = rObj.options;					for (j=0; j<OptionsArray.length; j++) {						if (OptionsArray[j].value==FieldContent[1]) {						TextToAdd=OptionsArray[j].innerHTML;						break;						}									}												}				else {							TextToAdd = FieldContent[x] ;				}										ReturnHTML = ReturnHTML+" " + TextToAdd ;			}					ReturnHTML = ReturnHTML+" and<br>" ;		}	}	return ReturnHTML ;}function removeSearch_orig() {	var Criteria = retSearchCriteriaString();		// Prepare the form		var rForm = SearchBarFormRef();		var MethodName = "removesearch";				prepareForm(rForm,MethodName)		addWinInstInputs(rForm);		addHiddenInput(rForm,"SearchCriteriaString",Criteria)				// Submit the form to the Omnis web app server.		// The window instance is not changing, so we can submit the form ourself.		rForm.submit();	}function removeSearch() {		var ExistingString = ExistingSearchCriteriaString();		var NewString = "" ;		var LineContent ;		var i ;				if (ExistingString.length) {			LineContent = ExistingString.split("//") ;			for (i=0; i< (LineContent.length - 1); i++) {				if (NewString.length==0) {				NewString = LineContent[i] ;				}				else {				NewString = NewString+"//"+LineContent[i];				}			}		var rObj = ExistingSearchCriteriaStringRef();		rObj.value = NewString;		}		var existingHTML = convertExistingToHTML(NewString) ;		document.getElementById('existingEntries').innerHTML = existingHTML ;}function validateSearchBarForm() {		// Figure out the search criteria.		var rCol = SelectedSearchColRef();		var rOperator = SelectedOperatorRef();		var rEntry = SearchEntryFieldRef();		var OperatorValue = rOperator.value; 		var Value = ""		switch (rEntry.type) {					case "checkbox" :							Value = rEntry.checked;				break;						case "hidden" :							Value = "";				break;						default :				Value = rEntry.value;				break;		}				if (Value.length==0) {						if	(OperatorValue == "TODAY") {					alert("You mean today ?");					return true;								}				else {					alert("Please enter a search value - not a date.");					setCurrField();					return false;				}		}				var Criteria = rCol.id+","+rOperator.value+","+Value;}// ----- Property Methods -----function DefaultSearchCriteriaString() { return SearchBarFormRef().DefaultSearchCriteriaString.value; }function ExistingSearchCriteriaString() { return SearchBarFormRef().ExistingSearchCriteriaString.value; }function SearchBarFormRef() { return document.SearchBarForm }function SearchColsListRef() { return SearchBarFormRef().SearchColsList ; }function SearchEntryFieldRef() { return SearchBarFormRef().SearchEntryField ; }function SearchOperatorsListRef() {	return SearchBarFormRef().SearchOperatorsList ; }function ExistingSearchCriteriaStringRef() {	return SearchBarFormRef().ExistingSearchCriteriaString ; }function SelectedOperatorRef() { 	// Return a reference to the selected operator.		var rObj = SearchOperatorsListRef();	if (rObj.length) {		var rOperator = rObj.options[rObj.selectedIndex];		return rOperator;	}	else {		return null	}}function SelectedSearchColRef() { 	var rObj = SearchColsListRef();	var rCol = rObj.options[rObj.selectedIndex];	return rCol;}function SelectedSearchColType() { return SelectedSearchColRef().value; }// ----- Programmer Test Methods -----function ping_searchbar() { alert("ping_searchbar"); }function test_searchbar() {	alert("test");	// Add test code here , or a call to specific function	}/* ----- MODIFICATIONS -----@MOD:1 Created file for use by 'wSearchBar' of the SW framework ;; 2006-02-16 Doug K*/function xmlDetail() {	var Criteria = retSearchCriteriaString();	if (Criteria == null) {			alert("Please enter a search value - null criteria set.");	}	else {			// Prepare the form		var FormText = "";		var FormText2 = "";		var MethodName = "search";			FormText = prepareXML(FormText,MethodName);		FormText = addXMLWinInstInputs(FormText);				var Property = "DefaultSearchCriteriaString";		var Value = document.getElementsByName('DefaultSearchCriteriaString')[0].value;		Value = encode(Value);		FormText = addParamInput(FormText,Property,Value);		Property = "ExistingSearchCriteriaString";		Value = document.getElementsByName('ExistingSearchCriteriaString')[0].value;		Value = encode(Value);		FormText = addParamInput(FormText,Property,Value);		Property = "SearchColsList";	 	Value = SearchColsListRef().value;		if (Value.length>0) {}		else		{		Value = document.getElementsByName('SearchColsList')[0].value;		}		FormText = addParamInput(FormText,Property,Value);		Property = "SearchOperatorsList";	 	Value = SearchOperatorsListRef().value;		if (Value.length>0) {}		else		{		Value = document.getElementsByName('SearchOperatorsList')[0].value;		}		Value = encode(Value);		FormText = addParamInput(FormText,Property,Value);		Property = "SearchEntryField";	 	Value = SearchEntryFieldRef().value;		if (Value.length>0) {}		else		{		Value = document.getElementsByName('SearchEntryField')[0].value;		}		FormText = addParamInput(FormText,Property,Value);		Criteria = encode(Criteria);		FormText = addParamInput(FormText,"SearchCriteriaString",Criteria);		return FormText;			}}var timeoutID = null ;var timerrunning = false ;function ajaxFunction(){	if (timerrunning) {	clearTimeout(timeoutID);	timerrunning = false;	}	timeoutID = setTimeout(delayajax, 500);	timerrunning = true ;}function delayajax(){	// first clear anything that may be in the standard return as we are getting an xml search directly now	document.getElementById('existingResult').innerHTML = "";	if (timerrunning) {	clearTimeout(timeoutID);	timerrunning = false;	}	Value = SearchEntryFieldRef().value;	if (Value.length>0) {}	else		{		Value = document.getElementsByName('SearchEntryField')[0].value;		}	if (Value.length>2)	{		var xmlHttp;	 	 xmlHttp=GetXMLHttpObject();		if (xmlHttp==null)	      {	      alert("Your browser does not support AJAX!");	      return false;		  }			var url=xmlDetail();	 	 xmlHttp.onreadystatechange=function()		{		if(xmlHttp.readyState==4) 		 {		setDataHTML(xmlHttp);	     }		}		xmlHttp.open("GET",url,true);		xmlHttp.send(null);	}}function GetXMLHttpObject(){var xmlHttp=null;try  {  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }catch (e)  {  // Internet Explorer  try    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }  catch (e)    {    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");    }  }return xmlHttp;}function setDataHTML(xmlHttp){	document.getElementById('searchResult').innerHTML = xmlHttp.responseText;}	// public method for url encodingfunction encode(string) {		return escape(this._utf8_encode(string));	} 	// public method for url decodingfunction decode(string) {		return this._utf8_decode(unescape(string));	} 	// private method for UTF-8 encodingfunction _utf8_encode(string) {		string = string.replace(/\r\n/g,"\n");		var utftext = ""; 		for (var n = 0; n < string.length; n++) { 			var c = string.charCodeAt(n); 			if (c < 128) {				utftext += String.fromCharCode(c);			}			else if((c > 127) && (c < 2048)) {				utftext += String.fromCharCode((c >> 6) | 192);				utftext += String.fromCharCode((c & 63) | 128);			}			else {				utftext += String.fromCharCode((c >> 12) | 224);				utftext += String.fromCharCode(((c >> 6) & 63) | 128);				utftext += String.fromCharCode((c & 63) | 128);			} 		} 		return utftext;	} 	// private method for UTF-8 decodingfunction _utf8_decode(utftext) {		var string = "";		var i = 0;		var c = c1 = c2 = 0; 		while ( i < utftext.length ) { 			c = utftext.charCodeAt(i); 			if (c < 128) {				string += String.fromCharCode(c);				i++;			}			else if((c > 191) && (c < 224)) {				c2 = utftext.charCodeAt(i+1);				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));				i += 2;			}			else {				c2 = utftext.charCodeAt(i+1);				c3 = utftext.charCodeAt(i+2);				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));				i += 3;			} 		} 		return string;	} 