Login   Register  
PHP Classes
elePHPant
Icontem

File: util.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrej Bodor  >  deadatagrid  >  util.js  >  Download  
File: util.js
Role: Auxiliary data
Content type: text/plain
Description: datagrid
Class: deadatagrid
Display MySQL query results in an HTML table
Author: By
Last change:
Date: 2009-10-17 13:23
Size: 6,161 bytes
 

Contents

Class file image Download
//---------------------------------------------------------
elem = 0;
potvrdi = false;

function changeFocus(obj) {
	if (potvrdi) {
		return true;
	} else {
      //if (obj.elements[elem].value=='?') alert('enter ?');
		elem++;
		obj.elements[elem].focus();
		return false;
	}
}
//---------------------------------------------------------
// highlite element in focus
var highlightcolor = "#FFFFB7"
var o = document.getElementById && !document.all
var previous = ''
var eventobj
//Regular expression to highlight only form elements
var intended = /INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function chkElem(which) {
   if (which.style && intended.test(which.tagName)) {
      if (o && eventobj.nodeType == 3) {
         eventobj = eventobj.parentNode.parentNode
      }
      return true
   } else {
      return false
   }
}
//---------------------------------------------------------
//Function to highlight form element
function highlight(e) {
   eventobj = o ? e.target : event.srcElement;
   if (previous != '') {
      if (chkElem(previous)) {
         previous.style.backgroundColor = '';
      }
      previous = eventobj;
      if (chkElem(eventobj)) {
         eventobj.style.backgroundColor = highlightcolor;
      }
   } else {
      if (chkElem(eventobj)) {
         eventobj.style.backgroundColor = highlightcolor;
      }
      previous = eventobj;
   }
}
//---------------------------------------------------------
xmlHttp = null;
function GetXmlHttpObject() {
   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;
}
//-------------------------------------------------------
xamp = '&';

function parseURL(param,div){
   p3 = param.split('?');
   p4 = p3[1].split('=');
   r = p3[1];

   //findgrid
   var inner = /order|where|whereM|page|keyid/
   grid = p4[0].replace(inner,'');

   p0 = document.getElementById('h_t').innerHTML.split('?');
   if(p0[1]) {
      p1 = p0[1].split(xamp);
      for (i in p1) {
         p2 = p1[i].split('=');
         if(p4[0] != p2[0]) {
            if (!(p4[0].substring(0,6) == 'order'+grid & p2[0].substring(0,6) == 'where'+grid)) {
               if ((p4[0].substring(0,6) == 'where'+grid & p2[0].substring(0,5) == 'page'+grid)) {
                  p2[1] = '1';
               }
               if ((p4[0].substring(0,6) == 'order'+grid & p2[0].substring(0,6) == 'keyid'+grid)) {
                  p2[1] = '0';
               }
               r = r + '&' + p2[0] + '=' + p2[1];
            }
         }
      }
   }
   if (!div) div = 'h_d';
   document.getElementById('h_t').innerHTML = p3[0] + '?' + r;
   getUrl(div,p3[0] + '?' + r,grid);
}
//---------------------------------------------------------
// check focus on t_s for ie; work on firefox or opera!!!
function getUrl(div,param,grid) {
   xmlHttp = GetXmlHttpObject();
   if (xmlHttp == null) {
      alert ("Your browser does not support AJAX!");
      return false;
   }
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			p = document.getElementById(div);
			p.innerHTML = xmlHttp.responseText;
         s = document.getElementById('t_s' + grid);
         //if (nosearch == 1){
         //   s.style.visibility = "hidden";
         //} else {
            try {
               s.focus();
            }
            catch(e) {}
         //}
		}
	}
	//a = parseInt(Math.random()*99999999);
	//xmlHttp.open('GET',param + '&' + 'rand=' + a, true);
	xmlHttp.open('GET',param,true);
	xmlHttp.send(null);
}
//---------------------------------------------------------
function showGrid(form,div,obj,grid,order) {
   xmlHttp = GetXmlHttpObject();
   if (xmlHttp == null) {
      alert ("Your browser does not support AJAX!");
      return false;
   }

   p0 = document.getElementById('h_t').innerHTML.split('?');
   if (form == p0[0] || p0[0] != '') {
      document.getElementById('h_t').innerHTML = '';
      document.getElementById('h_d').style.display = 'block'
      showGrid(form,div,obj,grid,order);
   }

	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4){
			p = document.getElementById(div);
			p.innerHTML = xmlHttp.responseText;

         //nosearch = 1;
         //var s = document.getElementById('t_s' + grid);
         //s.style.visibility = "hidden";
      }
	}

	keyid = obj.value;

   if(p0[1]) {
      p1 = p0[1].split(xamp);
      for (i in p1) {
         p2 = p1[i].split('=');
         if(p2[0] == 'order' + grid) {
            if(keyid != '') {
               //alert('have order, no krit');
               p3 = p2[1].split(':');
               parseURL(p0[0] + '?where' + grid + '=' + p3[0] + ':' + keyid + '%',div);
               break;
            } else {
               //alert('have order, no krit');
               parseURL(form + '?where' + grid + '=',div);
            }
         } else {
            //alert('no order');
         }
      }
   }else{
      //alert('start form');
      if(order != '') {
         parseURL(form + '?order' + grid + '=' + order + ':' + 'ASC',div);
      }
   }
}
//---------------------------------------------------------
function doSearch(grid) {
   var p0 = document.getElementById('h_t').innerHTML.split('?');
   if(p0[1]) {
      p1 = p0[1].split(xamp);
      for (i in p1) {
         p2 = p1[i].split('=');
         if(p2[0] == 'order' + grid) {
            p3 = p2[1].split(':');
            text = document.getElementById('t_s' + grid).value;
            parseURL(p0[0] + '?where' + grid + '=' + p3[0] + ':' + text + '%');
            break;
         }
      }
   } else {
      document.getElementById('t_s' + grid).value = '';
   }
}
//---------------------------------------------------------