Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Parameters Description :-
- obj :- On which Object The Box is Setup
- ca :- Array of Words
- isMultiple :- Array is Miltiple
- forwardPage :- indicates Page URL to forward in case of Master Entry
- divID :- The id Of div Tag for Displaying Messages
- isForwardAllow :- Forwarding is Allow or Not
- isRequired :- Must Be Filled or Not
- maxLimit :- Display the content at a time
- gridFunction : Any Grid Function, if this component is attaching with grid
- * to call.
- isEventAllow :- If occuring event is allowed to propogate to its parent component,in case
- * while we using this componet in the grid.
- subGridDef :- Direct SubgridDef to populate child that exist from the
- * same text object on which this autoComplete is populated.
- *
- customEventsFunctions :- this is an object defining custom events for this component.for example
- *
- * 'beforeTableCreation' : we can call or does any procedure before table is creating for first time.,
- * 'beforeTableRecreaion',
- * 'onInit',
- * 'onTableInit',
- * 'onLoad',
- * 'onUnload',
- *
- * we can hook extrenal functions or even other components to act on behalf of this
- * custom event.right now we programme for 'beforeTableCreation' custom event, passing an extrenal
- * function that must be called before actual list is populated to display in to table. (as on Date :- 04-12-2010).
- *
- */
- /*
- @include:-
- 1 :- EventUtil.js
- */
- function autoCompleteMixed(obj, ca, isMultiple, forwardPage, divID,
- isForwardAllow, isRequired, maxLimit, gridFunction, isEventAllow,
- subGridDef, customEventsFunctions) {
- /* Global variable which is pointing to itself , means it holds the reference of
- whole the components including properties,events,methods of this component. */
- var atm = this;
- /*
- this all variables are respoinsible for look & feel
- of autocomplete text box
- */
- if (typeof (maxLimit) == "undefined" || maxLimit == undefined) {
- maxLimit = 10;
- }
- if (typeof (maxLimit) == "string") {
- maxLimit = parseInt(maxLimit, 10);
- }
- this.tblNormalClassName = '';
- var trNormalClassName = 'quickhelp';
- var trSelectedClassName = 'auto_right';
- this.tdNormalClassName = '';
- this.tdSelectdClassName = '';
- var trOnMouseOverClassName = 'right';
- var trOnMouseOutClassName = 'quickhelp';
- /////////////////////////////////////
- this.txtFontSize = '';
- this.txtFontFamily = '';
- this.txtStyleNormal = '';
- this.txtStyleSelected = '';
- /*
- variables for storing Array
- */
- var act_keywords = ca;
- var act_multiple = null;
- this.curObject = obj;
- this.forwardPage = forwardPage;
- /*
- Key bord related Variables
- */
- var blockKeyCode = false;
- /*
- General variable
- */
- var pos = (-1);
- var counter = (-1);
- var actStart = 0;
- var actEnd = 0;
- var selectedidx = 0;
- var isFound = false;
- var isZeroLength = true;
- var isNormalKey = false;
- var t;
- var foundPosition = -1;
- /*
- Variable for calculating upper & lower limit
- */
- var uLimit = 0;
- var dLimit = 0;
- var uDifference = 0;
- var dDifference = 0;
- /*
- this is the Core function which initialized all the things
- */
- /* First Remove Previous Event Handler if Exist */
- /* Date MOdified :- 11-09-09 */
- this.customEventsFunctions = customEventsFunctions;
- if (this.customEventsFunctions != undefined) {
- if (typeof (this.customEventsFunctions) == "string") {
- this.customEventsFunctions = eval(this.customEventsFunctions);
- }
- }
- EventUtil.addEventHandler(obj, "focus", setup);
- EventUtil.addEventHandler(obj, "focus", createTable);
- function setup() {
- // Text Box Events
- // showMessage(divID,"Setup");
- EventUtil.addEventHandler(obj, "blur", clearEvent);
- //if(Def(gridFunction))
- // EventUtil.addEventHandler(obj,"blur",eval(gridFunction));
- // Keyboard Events
- EventUtil.addEventHandler(obj, "keypress", obj_KeyPressed);
- EventUtil.addEventHandler(obj, "keydown", obj_KeyDown);
- }
- /*
- this is the function which removes all the events
- */
- function clearEvent() {
- var oEvent = EventUtil.getEvent();
- EventUtil.removeEventHandler(obj, "keydown", obj_KeyDown);
- EventUtil.removeEventHandler(obj, "keypress", obj_KeyPressed);
- EventUtil.removeEventHandler(obj, "blur", clearEvent);
- showMessage(divID, "");
- removeDisplay();
- if (!isFound)
- obj.value = "";
- }
- /* this function is responsible
- for reseting all gloabl variables for this function
- */
- this.resetGV = function() {
- blockKeyCode = false;
- /*
- General variable
- */
- counter = (-1);
- actStart = 0;
- actEnd = 0;
- selectedidx = 0;
- pos = (-1);
- isFound = false;
- isZeroLength = true;
- isNormalKey = false;
- t = null;
- foundPosition = -1;
- /*
- Variable for calculating upper & lower limit
- */
- uLimit = 0;
- dLimit = 0;
- uDifference = 0;
- dDifference = 0;
- };
- //alert(typeof(this));
- /*
- this function is responsible for creating table dynamically
- */
- /* Date Created :- 27-09-08 */
- /* Function is Responsible for setting Global Array */
- this.resetDataStructure = function(srcDS) {
- if (srcDS.constructor == String) {
- act_keywords[act_keywords.length] = srcDS;
- act_keywords.sort();
- } else {
- act_keywords = srcDS;
- }
- };
- this.setForwardPage = function(fp) {
- forwardPage = fp;
- };
- this.setRequired = function(ir) {
- isRequired = ir; /* either true or false */
- }
- this.beforeTableCreation = function(cef) {
- /*
- cef stands for custom events functions
- */
- if (cef != undefined) {
- alert(atm.customEventsFunctions.beforeTableCreation);
- with (cef) {
- if (beforeTableCreation != undefined) {
- /* We are Passing here in the external functional */
- /* the Object on which this autoComplete is Populating and */
- /* the array that we want to display on it .*/
- /* if the data is passed in the array and if modified from */
- /* the external functions we have to call here resetDataStructure function which
- we are getting from outside. */
- var srcData = window[beforeTableCreation].call(this, obj,
- oEvent);
- this.resetDataStructure(srcData);
- }
- }
- }
- }
- function createTable() {
- if (document.getElementById('tt_table')) {
- document.body.removeChild(document.getElementById('tt_table'));
- }
- /* Hook here before Table creation custom events */
- /* if there is an external function call it here before */
- /* creation of a table. */
- atm.beforeTableCreation(atm.customEventsFunctions);
- // showMessage(divID,"From Table");
- t = document.createElement('table');
- t.id = "tt_table";
- /*
- Here Is Code For Table Class
- t.tblNormalClassName='';
- */
- t.cellPadding = '1px';
- t.cellSpacing = '0px';
- t.style.border = "1px solid";
- t.style.width = obj.offsetWidth;
- t.style.position = 'absolute';
- t.style.zIndex = '99999';
- // This Two Lines are Very Important
- // Setting Top ,Left Of created Table
- var oFFset = objLeftTop(obj);
- //document.getElementById("divDisplayMessage").innerHTML=oFFset;
- /* Date Modified On 17-04-09 */
- if (oFFset == undefined || oFFset == null) {
- //t.style.top= eval(obj.offsetHeight)+'px';
- //t.style.left= obj.offsetLeft;
- removeDisplay();
- } else {
- t.style.top = eval(obj.offsetHeight + oFFset[0]) + 'px';
- t.style.left = oFFset[1] + 'px';
- adjustWindowAuto(obj);
- }
- /////////////////////////////////////
- document.body.appendChild(t);
- for (i = 0; i < act_keywords.length; i++) {
- var r = t.insertRow(-1);
- r.id = 'tblRow' + i;
- r.setAttribute('pos', i);
- r.className = trNormalClassName;
- addMouseEvent(r);
- /*
- Here we put condition
- if i > maxLimit then we stop here &
- put marker here
- */
- if (i == maxLimit && act_keywords.length > maxLimit) {
- leftEntry = act_keywords.length - maxLimit;
- createMarkerCell(r, leftEntry + " more... ");
- break;
- }
- if (isMultiple) {
- createMultiColumnTable(r, act_keywords[i], i);
- } //ends If
- else {
- createSingleColumnTable(r, act_keywords[i], i);
- } //ends Else
- }//ends For
- uLimit = 0;
- dLimit = i - 1;
- if (obj.value.length > 0 && isMultiple)
- showkeywordsmultiple(obj);
- else if (obj.value.length > 0 && !isMultiple)
- showkeywords(obj);
- else {
- }
- // goDown();
- }
- function remake() {
- if (document.getElementById('tt_table')) {
- document.body.removeChild(document.getElementById('tt_table'));
- }
- t = document.createElement('table');
- /*
- Here is Code For Table Class Name
- t.className='';
- */
- t.id = "tt_table";
- t.cellPadding = '1px';
- t.cellSpacing = '0px';
- t.style.border = "1px solid";
- t.style.width = obj.offsetWidth;
- t.style.position = 'absolute';
- t.style.zIndex = '99999';
- var oFFset = objLeftTop(obj);
- /* Date Modified On 19-04-09 */
- if (oFFset == undefined || oFFset == null) {
- //t.style.top= eval(obj.offsetHeight)+'px';
- //t.style.left= obj.offsetLeft;
- removeDisplay();
- } else {
- t.style.top = eval(obj.offsetHeight + oFFset[0]) + 'px';
- t.style.left = oFFset[1] + 'px';
- }
- /////////////////////////////////////
- document.body.appendChild(t);
- if (uLimit > 0) {// && act_keywords.length>maxLimit){
- var r = t.insertRow(-1);
- r.id = 'tblRow' + i;
- r.setAttribute('pos', i);
- r.className = trNormalClassName;
- addMouseEvent(r);
- createMarkerCell(r, uLimit + " more... ");
- }
- var j = 0;
- for (i = 0; i < act_keywords.length; i++) {
- if (i >= uLimit && i <= dLimit) {
- var r = t.insertRow(-1);
- r.id = 'tblRow' + i;
- r.setAttribute('pos', i);
- r.className = trNormalClassName;
- addMouseEvent(r);
- j++;
- if (pos > -1 && pos == i) {
- counter = pos;
- selectedidx = true;
- } //ends IF
- if (isMultiple) {
- createMultiColumnTableRemake(r, act_keywords[i], i, pos);
- } else {
- createSingleColumnTableRemake(r, act_keywords[i], i, pos);
- }//ends Else
- }
- if (j == maxLimit && (act_keywords.length - (dLimit + 1) > 0)) {
- var r = t.insertRow(-1);
- r.id = 'tblRow' + i;
- r.setAttribute('pos', i);
- r.className = trNormalClassName;
- addMouseEvent(r);
- leftEntry = act_keywords.length - (dLimit + 1);
- createMarkerCell(r, leftEntry + " more... ");
- break;
- }
- } //ends For
- }
- /*
- Date Created:- 27-08-08
- */
- function createMarkerCell(tObj, textHTML) {
- var c = tObj.insertCell(-1);
- c.align = "left";
- c.className = "Header_left";
- var txt = document.createTextNode(textHTML);
- c.appendChild(txt);
- }
- function createMultiColumnTable(tObj, mArray, idx) {
- for (j = 0; j < mArray.length; j++) {
- var c = tObj.insertCell(-1);
- c.id = "tblCol" + idx + j;
- var txt = document.createTextNode(mArray[j]);
- c.appendChild(txt);
- }
- }
- function createSingleColumnTable(tObj, sArray, idx) {
- var c = tObj.insertCell(-1);
- var txt = document.createTextNode(sArray);
- c.appendChild(txt);
- c.id = "tblCol" + idx;
- }
- function createMultiColumnTableRemake(tObj, mArray, idx) {
- for (j = 0; j < mArray.length; j++) {
- var c = tObj.insertCell(-1);
- c.id = "tblCol" + idx + j;
- var txt = document.createTextNode(mArray[j]);
- c.appendChild(txt);
- if (selectedidx)
- c.parentNode.className = trSelectedClassName;
- selectedidx = false;
- } //ends if
- }
- function createSingleColumnTableRemake(tObj, sArray, idx) {
- var c = tObj.insertCell(-1);
- var txt = document.createTextNode(sArray);
- c.appendChild(txt);
- c.id = "tblCol" + idx;
- if (selectedidx) {
- c.parentNode.className = trSelectedClassName;
- selectedidx = false;
- }
- }
- function removeDisplay() {
- if (document.getElementById('tt_table')) {
- document.body.removeChild(document.getElementById('tt_table'));
- }
- if (document.getElementById('pMessage')) {
- document.body.removeChild(document.getElementById('pMessage'));
- }
- }
- /*------------------------------End Table Functions-----------------------------*/
- /********************************************************************************/
- /*
- Functions For Mouse Event Processing
- Date Created:- 21-12-07
- Date Modified:- 24-01-08
- */
- function addMouseEvent(robj) {
- //oTarget,sEventType,fnHandler
- robj.onmouseover = function() {
- robj.className = trOnMouseOverClassName;
- // showMessage(divID,' Mouse Over :- Element Name :- '+ this.id +" Pos: "+pos+" Row Pos: "+this.getAttribute('pos'));
- };
- robj.onmouseout = function() {
- if (parseInt(this.getAttribute('pos')) != pos) {
- // showMessage(divID," Mouse Out :- Element Name :- "+ this.id +" Pos: "+pos+" Row Pos: "+this.getAttribute('pos'));
- robj.className = trOnMouseOutClassName;
- } else {
- robj.className = trOnMouseOverClassName;
- }
- };
- robj.onmousedown = function() {
- //showMessage(divID,'Event Type:- Element Name :- '+ this.id +" Pos: "+pos+" Row Pos: "+this.getAttribute('pos'));
- counter = robj.getAttribute('pos');
- // showMessage(divID,'counter:- '+ counter +" word is "+ act_keywords[counter]+ " Row Pos: "+this.getAttribute('pos'));
- isFound = true;
- isZeroLength = false;
- getSelected(obj);
- };
- }
- /*
- function rowMouseOver(){
- var oEvent=EventUtil.getEvent();
- var el=oEvent.target;
- showMessage(divID,'Event Type:- '+oEvent.type+' Element Name :- '+ rowMouseOver.caller +" Pos: "+pos+" Row Pos: "+el.getAttribute('pos'));
- }
- function rowMouseOut(){
- var oEvent=EventUtil.getEvent();
- var el=oEvent.target;
- }
- function rowMouseDown(){
- var oEvent=EventUtil.getEvent();
- var el=oEvent.target;
- }
- */
- /*-------------------------End Mouse Function----------------------------*/
- /*************************************************************************/
- /*
- Functions For Key board Events Processing
- Date Created :- 20-12-07
- Date Modified:- 24-01-08
- */
- function obj_KeyPressed() {
- oEvent = EventUtil.getEvent();
- //showMessage(divID,'blockKeyCode:- '+blockKeyCode+' isFOund :- '+ isFound+ ' isZeroLength:- '+ isZeroLength+ ' isNormalKey:- '+ isNormalKey);
- if (Def(isEventAllow) && !isEventAllow && isRequired) {
- //alert("Event is Stopped");
- oEvent.stopPropagation();
- oEvent.preventDefault();
- return false;
- }
- isZeroLength = !(obj.value.length > 0)
- if ((blockKeyCode && isZeroLength && isRequired)) {
- // showMessage(divID,"Event Type:- "+oEvent.type);
- oEvent.stopPropagation();
- oEvent.preventDefault();
- // showMessage(divID,"Event Type:- "+oEvent.type);
- return false;
- } else if ((!isFound && isZeroLength && !isNormalKey) && isRequired) {
- oEvent.stopPropagation();
- oEvent.preventDefault();
- // showMessage(divID,"Event Type:- "+oEvent.type);
- return false;
- } else if (!isFound && blockKeyCode && !isZeroLength) {
- oEvent.stopPropagation();
- oEvent.preventDefault();
- // showMessage(divID,"Event Type:- "+oEvent.type);
- return false;
- }
- return (!blockKeyCode);
- }
- function getFormFields() {
- var oForm = obj.form;
- var oName, oValue = '', tmpString = '';
- for ( var i = 0; i < oForm.length - 1; i++) {
- if (oForm.elements[i].type.toUpperCase() == "TEXT") {
- if (oForm.elements[i].value.trim().length != '') {
- oName = oForm.elements[i].name;
- oValue = encode(oForm.elements[i].value, 'ascii');
- tmpString += '&' + oName + '=' + oValue;
- }
- }
- if (oForm.elements[i].type.toUpperCase() == "RADIO") {
- if (oForm.elements[i].checked) {
- oName = oForm.elements[i].name;
- oValue = oForm.elements[i].value;
- tmpString += '&' + oName + '=' + oValue;
- }
- }
- if ((oForm.elements[i].type.toUpperCase() == "CHECK" || oForm.elements[i].type
- .toUpperCase() == "CHECKBOX")
- && oForm.elements[i].checked == true) {
- oName = oForm.elements[i].name;
- oValue = oForm.elements[i].value;
- tmpString += '&' + oName + '=' + oValue;
- }
- }
- // alert(tmpString);
- return tmpString;
- }
- function obj_KeyDown() {
- var oEvent = EventUtil.getEvent();
- var k = oEvent.keyCode;
- blockKeyCode = 0;
- if (oEvent.altKey && (k == 67)) {
- if (isForwardAllow)
- if (forwardPage != 'undefined') {
- //var qString=getFormFields();
- //setTimeout(function(){document.location.href=forwardPage+qString;},50);
- createPopupAsType(obj, forwardPage);
- }
- } else if (oEvent.shiftKey && (k == 9)) {
- blockKeyCode = true;
- isNormalKey = false;
- // alert("Shift");
- return false;
- } else {
- switch (k) {
- case 38:
- goUp();
- blockKeyCode = true;
- isNormalKey = false;
- oEvent.stopPropagation();
- oEvent.preventDefault();
- return false;
- break;
- // For UP ARROW KEY
- case 40:
- goDown();
- blockKeyCode = true;
- isNormalKey = false;
- oEvent.stopPropagation();
- oEvent.preventDefault();
- return false;
- break;
- // For Down Arrow KEY
- case 13:
- getSelected(obj);
- if (Def(gridFunction) && (isRequired == true)) {
- //gridFunction=gridFunction+"("+obj+")";
- //logMsg(gridFunction);
- if (gridFunction != undefined) {// && typeof(gridFunction)==""){
- if (Def(subGridDef)) {
- window[gridFunction].call(this, obj, oEvent,
- undefined, subGridDef);
- } else {
- window[gridFunction].call(this, obj, oEvent);
- }
- }
- } else if (!isRequired) {
- if (Def(gridFunction) && typeof (gridFunction) == "string") {
- if (obj.value.trim().length > 0) {
- window[gridFunction].call(this, obj, oEvent);
- }
- if (Def(isEventAllow) && !isEventAllow) {
- window[gridFunction].call(this, obj, oEvent);
- }
- }
- } else {
- /* For Future Use */
- }
- if (Def(isEventAllow) && !isEventAllow) {
- oEvent.stopPropagation();
- oEvent.preventDefault();
- blockKeyCode = true;
- isNormalKey = false;
- return false;
- break;
- }
- blockKeyCode = true;
- isNormalKey = false;
- //showMessage(divID,"isNormalKey : "+isNormalKey+ " isFound : "+ isFound + " blockKeyCode : "+blockKeyCode);
- // alert("isNormalKey : "+isNormalKey+ " isFound : "+ isFound + " blockKeyCode : "+blockKeyCode);
- return false;
- break;
- case 9:
- getSelected(obj);
- blockKeyCode = true;
- isNormalKey = false;
- return false;
- break;
- case 27:
- /* Date Modified On 19-04-09 */
- removeDisplay();
- blockKeyCode = true;
- isNormalKey = false;
- return false;
- break;
- /*
- case 116:
- blockKeyCode=true;
- break;
- // F5
- case 46:
- blockKeyCode=true;
- break;
- // Delete
- */
- default:
- isNormalKey = true;
- blockKeyCode = false;
- /* Here Should Be function for Handling */
- /* Back & Left Arrow Key */
- /* What if Required is Remaining */
- if (k == 8 || k == 37) {
- if (obj.value.length == 0) {
- removeDisplay();
- break;
- } else {
- var cPos = getSelectionStart_AUTO(obj);
- if (cPos == 0) {
- if (!SerachArray_AUTO()) {
- obj.value = "";
- removeDisplay();
- break;
- } else {
- /* Date Modified On 19-04-09 */
- removeDisplay();
- break;
- }
- }
- }
- }
- if (isMultiple) {
- // setTimeout(function(){actb_tocomplete(a)},50);
- setTimeout(function() {
- showkeywordsmultiple(obj)
- }, 50);
- break;
- } else {
- setTimeout(function() {
- showkeywords(obj)
- }, 50);
- break;
- }
- } // ends Switch
- }// ends Else
- } //Ends Function
- /*----------------------------- Ends Keyboard Functions-------------------------*/
- /********************************************************************************/
- /*
- Navigation Functions
- Date Created :- 21-12-07
- Date Modified:- 24-01-07
- */
- function goUp() {
- if (pos <= 0)
- return;
- if ((document.getElementById("tblRow" + pos)) != null) {
- document.getElementById("tblRow" + pos).className = trNormalClassName;
- }
- pos--;
- if (pos < uLimit) {
- uLimit--;
- dLimit--;
- counter = pos;
- isFound = true;
- remake();
- return;
- }
- // showMessage(divID," Go Up After Pos : "+pos + " Array Elements : "+ act_keywords[pos] + " length : " + act_keywords.length);
- if ((document.getElementById("tblRow" + pos)) != null) {
- document.getElementById("tblRow" + pos).className = trSelectedClassName;
- counter = pos;
- isFound = true;
- }
- }
- function goDown() {
- // showMessage(divID,"Before Pos : "+pos + " Array Elements : "+ act_keywords[pos] + " length : " + act_keywords.length);
- if (pos == act_keywords.length - 1) {
- if ((document.getElementById("tblRow" + pos)) != null) {
- document.getElementById("tblRow" + pos).className = trNormalClassName;
- return;
- }
- }
- // showMessage(divID," "+pos);
- if (pos >= 0) {
- if ((document.getElementById("tblRow" + pos)) != null) {
- document.getElementById("tblRow" + pos).className = trNormalClassName;
- }
- }
- pos++;
- if (pos == act_keywords.length || act_keywords.length == 1) {
- if ((document.getElementById("tblRow" + pos)) != null) {
- document.getElementById("tblRow" + pos).className = trSelectedClassName;
- counter = pos;
- isFound = true;
- }
- return;
- }
- // showMessage(divID,"After Pos : "+pos + " Array Elements : "+ act_keywords[pos] + " length : " + act_keywords.length);
- if (pos >= dLimit) {
- uLimit++;
- dLimit++;
- counter = pos;
- isFound = true;
- remake();
- return;
- }
- if ((document.getElementById("tblRow" + pos)) != null) {
- document.getElementById("tblRow" + pos).className = trSelectedClassName;
- counter = pos;
- isFound = true;
- }
- }
- /*-----------------------Ends Navigation Function----------------------------*/
- /*****************************************************************************/
- /*
- Functions For Searching Value From Array
- Date Created :-20-12-07
- Date Modified:-24-01-08
- Date Modified:-25-01-08
- */
- function showkeywords(obj) {
- if (!obj || obj == 'undefined')
- return;
- counter = -1;
- pos = -1;
- isFound = false;
- isZeroLength = false;
- if (obj.value.length == 0) {
- removeDisplay();
- uLimit = 0;
- dLimit = 0;
- createTable();
- showMessage(divID, "");
- isZeroLength = true;
- // blockKeyCode=false;
- }
- for (i = 0; i < act_keywords.length; i++) {
- var regk = new RegExp(act_keywords[i], "i");
- var lchar = act_keywords[i].substr(0, obj.value.length);
- if ((lchar.toLowerCase().indexOf(obj.value.toLowerCase()) > -1)
- && (obj.value.length > 0)) {
- pos = i;
- /* Modified on 27-08-08 */
- uLimit = i;
- dLimit = (parseInt(uLimit, 10) - 1) + maxLimit;
- /*************************/
- removeDisplay();
- // alert(uLimit + " " + dLimit + maxLimit + typeof(maxLimit));
- remake();
- showMessage(divID, "");
- // showMessage(divID," uLimit : " +uLimit + " dLimit : " + dLimit);
- isFound = true;
- // blockKeyCode=false;
- break;
- }//ends if
- } //ends For
- /*
- Here Code For Displaying Error Message
- */
- if (!isFound && !isZeroLength) {
- showMessage(divID, "Spelling Error");
- }
- counter = pos;
- }
- function showkeywordsmultiple(obj) {
- counter = -1;
- pos = -1;
- isFound = false;
- isZeroLength = false;
- var str;
- str = "from Multiple";
- if (obj.value.length == 0) {
- removeDisplay();
- remake();
- showMessage(divID, "");
- isFound = true;
- isZerroLength = true;
- }
- for (i = 0; i < act_keywords.length; i++) {
- for (j = 0; j < act_keywords[i].length; j++) {
- var regk = new RegExp(act_keywords[i][0], "i");
- str = "Value:- " + obj.value + " Original Array :- "
- + act_keywords[i][0];
- var lchar = act_keywords[i][0].substr(0, obj.value.length)
- str = str + " lchar:-" + lchar;
- if (lchar.toLowerCase().indexOf(obj.value.toLowerCase()) > -1
- && obj.value.length > 0) {
- pos = i;
- str = str + "found";
- removeDisplay();
- remake();
- isFound = true;
- showMessage(divID, "");
- break;
- } //ends IF
- } //ends Innner For
- } // ends Outer For
- /*
- Here Code For Displaying Error Message
- */
- if (!isFound && !isZeroLength) {
- showMessage(divID, "Spelling Error");
- }
- counter = pos;
- } //ends Function
- /*-----------------------Ends Searching Function----------------------------------*/
- /***********************************************************************************/
- function adjustWindowAuto(obj) {
- var lf, tp;
- var tmplt = objLeftTop(obj);
- lf = tmplt[1]; /* left according to relative element */
- tp = tmplt[0]; /* top according to relative element */
- var wcw, wch;
- var tmpwh;
- tmpwh = getViewPort();
- wcw = tmpwh[0]; /* which is client widht of the window */
- wch = tmpwh[1]; /* which is client height of the window */
- /* Now get the auto box height */
- var offset = 20; /* to make view more clearer */
- var t = document.getElementById("tt_table");
- var tw, th;
- if (!t) {
- tw = obj.offsetWidth;
- th = 120;
- } else {
- tw = t.offsetWidth;
- th = t.offsetHeight;
- }
- var oh = obj.offsetHeight; /* always consider it */
- /* Now,convert all to Number */
- lf = parseInt(lf, 10);
- tp = parseInt(tp, 10);
- wcw = parseInt(wcw, 10);
- wch = parseInt(wch, 10);
- tw = parseInt(tw, 10);
- th = parseInt(th, 10);
- oh = parseInt(oh, 10);
- offset = parseInt(offset, 10);
- var tow;
- var toh;
- tow = lf + tw;
- toh = tp + th;
- tow = parseInt(tow, 10);
- toh = parseInt(toh, 10);
- var yDiff = 0;
- var xDiff = 0;
- var sTop = getWindowScrollTop();
- var sLeft = getWindowScrollLeft();
- if (sTop > 0) {
- wch += sTop;
- }
- if (sLeft > 0) {
- wcw += sLeft;
- }
- if (toh >= wch) {
- yDiff = Math.abs(toh - wch);
- }
- if (tow >= wcw) {
- xDiff = Math.abs(tow - wcw);
- if (sLeft > 0) {
- xDiff = xDiff + sLeft;
- }
- }
- if (xDiff > 0 || yDiff > 0) {
- window.scrollBy(xDiff, yDiff);
- }
- }
- function getViewPort() {
- var viewportwidth;
- var viewportheight;
- // http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
- // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
- if (typeof window.innerWidth != 'undefined') {
- viewportwidth = window.innerWidth,
- viewportheight = window.innerHeight
- }
- // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
- else if (typeof document.documentElement != 'undefined'
- && typeof document.documentElement.clientWidth != 'undefined'
- && document.documentElement.clientWidth != 0) {
- viewportwidth = document.documentElement.clientWidth,
- viewportheight = document.documentElement.clientHeight
- }
- // older versions of IE
- else {
- viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
- viewportheight = document.getElementsByTagName('body')[0].clientHeight
- }
- //document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
- return [ viewportwidth, viewportheight ];
- }
- function getWindowScrollTop() {
- var stp = document.body.scrollTop;
- if (stp == 0) {
- if (window.pageYOffset)
- stp = window.pageYOffset;
- else
- stp = (document.body.parentElement) ? document.body.parentElement.scrollTop
- : 0;
- }
- return stp;
- }
- function getWindowScrollLeft() {
- var slf = document.body.scrollLeft;
- if (slf == 0) {
- if (window.pageXOffset)
- slf = window.pageXOffset;
- else
- slf = (document.body.parentElement) ? document.body.parentElement.scrollLeft
- : 0;
- }
- return slf;
- }
- function objLeftTop(obj) {
- var cleft = ctop = 0;
- // JS_LOG(obj);
- //document.getElementById("divDisplayMessage").innerHTML=obj.offsetParent;
- if (obj.offsetParent) {
- ctop = obj.offsetTop;
- cleft = obj.offsetLeft;
- while (obj = obj.offsetParent) {
- ctop += obj.offsetTop;
- cleft += obj.offsetLeft;
- }
- return [ ctop, cleft ];
- }
- //return [ctop,cleft];
- }
- function getSelected(obj) {
- if (counter >= 0) {
- if (isMultiple)
- obj.value = act_keywords[counter][0];
- else
- //showMessage(divID,"Counter:="+counter );
- obj.value = act_keywords[counter];
- isZeroLength = false;
- removeDisplay();
- }
- }
- ;
- /*
- This Function Is For Displaying Message
- Date Created:- 24-01-08
- */
- function showMessage(objDiv, sMessage) {
- if (!objDiv)
- return;
- if (document.getElementById('pMessage')) {
- document.body.divID
- .removeChild(document.getElementById('pMessage'));
- }
- /*
- var pMessage=document.createElement('DIV');
- pMessage.className='error';
- pMessage.appendChild(document.createTextNode(sMessage));
- document.body.appendChild(pMessage);
- */
- if (!objDiv) {
- return;
- }
- if (sMessage == "")
- objDiv.innerHTML = "";
- else
- objDiv.innerHTML = "<p class='error'>" + sMessage + "</p>";
- var oFFset = objLeftTop(obj);
- /* Date Modified On 17-04-09 */
- if (oFFset == undefined || oFFset == null) {
- //t.style.top= eval(obj.offsetHeight)+'px';
- //t.style.left= obj.offsetLeft;
- removeDisplay();
- } else {
- if (t) {
- t.style.top = eval(obj.offsetHeight + oFFset[0]) + 'px';
- t.style.left = oFFset[1] + 'px';
- }
- }
- }
- /* Date Created :- 29-03-09 */
- /* Copied Here On 11-04-09 */
- function SerachArray_AUTO(refText) {
- for (i = 0; i < act_keywords.length; i++) {
- var regk = new RegExp(act_keywords[i], "i");
- if (act_keywords[i].toLowerCase() == obj.value.toLowerCase()) {
- return true;
- break;
- }
- }
- return false;
- }
- function getSelectionStart_AUTO(oTextbox) {
- if (oTextbox.createTextRange) {
- var r = document.selection.createRange().duplicate();
- r.moveEnd('character', oTextbox.value.length);
- if (r.text == '')
- return oTextbox.value.length;
- return oTextbox.value.lastIndexOf(r.text);
- } else {
- return oTextbox.selectionStart;
- }
- }
- return this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement