function AjaxInit() {
var AjaxObj = false;
if(window.XMLHttpRequest){
AjaxObj = new XMLHttpRequest();
} else if (window.ActiveXObject){
AjaxObj=new ActiveXObject("Msxml2.XMLHTTP");
if (!AjaxObj){
AjaxObj=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return(AjaxObj);
}
function ajaxVars(){
this.colDelim = '|||';
this.rowDelim = '^^^';
this.varDelim = '###';
this.vars = new Array();
this.fnVars = new Array();
this.dbVars = new Array();
this.method = 'POST';
this.gotoFunction = '';
this.status = 'loadingDiv';
this.AjaxPostSQL = AjaxPostSQL;
this.phpFile = "/lib/ajax.data.php";
}
function AjaxPostSQL(){
with(this){
url = this.phpFile;
this.divObj = document.getElementById(this.status);
if(this.divObj) {
window.status = "Loading...";
this.divObj.innerHTML = "Saving changes... Please wait.";
}
var Ajax=AjaxInit();
try {
if(method == 'GET') {
url += '?' + queryStr;
}
Ajax.open(method, url);
Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Ajax.onreadystatechange = function() {
if (Ajax.readyState == 4 && Ajax.status == 200) {
// alert(vars['action'] + " -> " + gotoFunction);
window.status = "Done";
dragFlag = false;
if(divObj) {
divObj.innerHTML = 'Done.';
}
var data = Ajax.responseText;
if(data.indexOf('on line') >= 0) {
document.body.innerHTML = data;
return false;
}
switch(vars['action']) {
case 'mysql_query':
case 'mysql_num_rows':
data = data.replace(/(.*)=/g, '');
eval(gotoFunction + '(data, fnVars)');
break;
case 'mysql_fetch_array':
case 'mysql_fetch_row':
case 'mysql_fetch_assoc':
var dataArr = new Array();
dataArr = createDataArr(data, rowDelim, colDelim, varDelim);
eval(gotoFunction + '(dataArr, fnVars)');
break;
case 'update':
data = data.replace(/(.*)=/g, '');
eval(gotoFunction + '(data, fnVars)');
break;
case 'updateImage':
data = data.replace(/(.*)=/g, '');
eval(gotoFunction + '(data, fnVars)');
break;
case 'modify':
data = data.replace(/(.*)=/g, '');
if(fieldObj)
eval(gotoFunction + '(data, fieldObj)');
else
eval(gotoFunction + '(data)');
break;
case 'runFunction':
data = data.replace(/(.*)=/g, '');
eval(gotoFunction + '(data, fnVars)');
break;
default:
data = data.replace(/(.*)=/g, '');
eval(gotoFunction + '(data, fnVars)');
break;
}
}
}
var queryStr = '&dbVars=' + this.dbVars;
for(key in this.vars){
queryStr += '&' + key + '=' + encodeStr(this.vars[key]);
}
Ajax.send(queryStr + "&random=" + Math.random());
}catch (errv) {
Ajax.send(errv);
}
}
}
function encodeStr(str){
if(isNaN(str)) {
str = str.replace('&', '##AND##');
str = str.replace('=', '##EQUAL##');
str = str.replace('?', '##QUESTION##');
}
return str;
}
function decodeStr(str){
str = str.replace('##AND##', '&');
str = str.replace('##EQUAL##', '=');
str = str.replace('##QUESTION##', '?');
return str;
}
function createDataArr(data, rowDelim, colDelim, varDelim){
var rowCount = 0;
var dataArr = new Array();
if(data.indexOf(rowDelim) >= 0) {
var rowStr = data.split(rowDelim);
for(var i=0; i= 0) {
var colStr = rowStr[i].split(colDelim);
for(var j=0; j= 0) {
var varStr = colStr[j].split(varDelim);
var key = varStr[0];
if(rowCount == 0) dataArr[key] = new Array();
dataArr[key][rowCount] = varStr[1];
}
}
rowCount++;
}
}
}else{
}
return dataArr;
}
function update(table, id, fieldObj, fieldName){
var ajaxVar = new ajaxVars();
ajaxVar.vars['action'] = 'update';
ajaxVar.vars['table'] = table;
ajaxVar.gotoFunction = "updateStatus";
ajaxVar.dbVars = fieldName;
ajaxVar.vars['id'] = id;
ajaxVar.vars[fieldName] = fieldObj.value;
ajaxVar.AjaxPostSQL();
}
function updateImage(table, id, fieldName, fieldImageA,ideaProd){
if(fieldImageA.hasChildNodes()){
var imageNode = fieldImageA.firstChild;
if(ideaProd == 1){
if(imageNode.src.indexOf('/ideasActive.gif')>=0) {
var fieldValue = 0;
var newImg = imageNode.src.replace(/\/ideasActive.gif/g, '/ideasInactive.gif');
}else{
var fieldValue = 1;
var newImg = imageNode.src.replace(/\/ideasInactive.gif/g, '/ideasActive.gif');
}
}else{
if(imageNode.src.indexOf('/active.gif')>=0) {
var fieldValue = 0;
var newImg = imageNode.src.replace(/\/active.gif/g, '/inactive.gif');
}else{
var fieldValue = 1;
var newImg = imageNode.src.replace(/\/inactive.gif/g, '/active.gif');
}
}
imageNode.src = newImg;
}
var ajaxVar = new ajaxVars();
ajaxVar.vars['action'] = 'modify';
ajaxVar.vars['table'] = table;
ajaxVar.vars[fieldName] = fieldValue;
ajaxVar.vars['id'] = id;
ajaxVar.gotoFunction = "empty";
ajaxVar.dbVars = fieldName;
ajaxVar.fieldObj = new Object();
ajaxVar.AjaxPostSQL();
}
function updateAvailability(table, id, fieldName, fieldImageA){
if(fieldImageA.hasChildNodes()){
var imageNode = fieldImageA.firstChild;
if((imageNode.src.indexOf('/notAvail.gif')>=0) || (imageNode.src.indexOf('/3to4.gif')>=0) || (imageNode.src.indexOf('/4to8w.gif')>=0) ){
if(imageNode.src.indexOf('/notAvail.gif')>=0) {
var fieldValue = 1;
var newImg = imageNode.src.replace(/\/notAvail.gif/g, '/3to4.gif');
}else if(imageNode.src.indexOf('/3to4.gif')>=0){
var fieldValue = 2;
var newImg = imageNode.src.replace(/\/3to4.gif/g, '/4to8w.gif');
}else if(imageNode.src.indexOf('/4to8w.gif')>=0){
var fieldValue = 0;
var newImg = imageNode.src.replace(/\/4to8w.gif/g, '/notAvail.gif');
}
}
}
imageNode.src = newImg;
var ajaxVar = new ajaxVars();
ajaxVar.vars['action'] = 'modify';
ajaxVar.vars['table'] = table;
ajaxVar.vars[fieldName] = fieldValue;
ajaxVar.vars['id'] = id;
ajaxVar.gotoFunction = "empty";
ajaxVar.dbVars = fieldName;
ajaxVar.fieldObj = new Object();
ajaxVar.AjaxPostSQL();
}
function updateNewProduct(table, id, fieldName, fieldImageA){
if(fieldImageA.hasChildNodes()){
var imageNode = fieldImageA.firstChild;
if((imageNode.src.indexOf('/old_prod.gif')>=0) || (imageNode.src.indexOf('/new_prod.gif')>=0)){
if(imageNode.src.indexOf('/old_prod.gif')>=0) {
var fieldValue = 1;
var newImg = imageNode.src.replace(/\/old_prod.gif/g, '/new_prod.gif');
}else if(imageNode.src.indexOf('/new_prod.gif')>=0){
var fieldValue = 0;
var newImg = imageNode.src.replace(/\/new_prod.gif/g, '/old_prod.gif');
}
}
}
imageNode.src = newImg;
var ajaxVar = new ajaxVars();
ajaxVar.vars['action'] = 'modify';
ajaxVar.vars['table'] = table;
ajaxVar.vars[fieldName] = fieldValue;
ajaxVar.vars['id'] = id;
ajaxVar.gotoFunction = "empty";
ajaxVar.dbVars = fieldName;
ajaxVar.fieldObj = new Object();
ajaxVar.AjaxPostSQL();
}
function modify(table, fieldElm){
var ajaxVar = new ajaxVars();
ajaxVar.vars['action'] = 'modify';
ajaxVar.vars['table'] = table;
ajaxVar.gotoFunction = "modifyStatus";
switch(fieldElm.type) {
case "radio":
case "text":
case "select":
case "select-one":
ajaxVar.fieldObj = fieldElm;
ajaxVar.dbVars = fieldElm.name;
ajaxVar.vars['id'] = fieldElm.form.id.value;
ajaxVar.vars[fieldElm.name] = fieldElm.value;
break;
default:
if(fieldElm.id.indexOf('__Frame') >=0) {
var frmName = fieldElm.id;
editor_frame = document.getElementById(frmName);
editor_source = editor_frame.contentWindow.document.getElementById('eEditorArea');
var mContents = editor_source.contentWindow.document.body.innerHTML;
hidElm = document.getElementById(frmName.replace(/___Frame/g, ''));
hidElm.value = mContents;
ajaxVar.fieldObj = hidElm;
ajaxVar.dbVars = hidElm.name;
ajaxVar.vars['id'] = hidElm.form.id.value;
ajaxVar.vars[hidElm.name] = hidElm.value;
}
break;
}
ajaxVar.AjaxPostSQL();
}
function updateStatus(data){
}
function modifyStatus(data, fieldObj){
Obj = document.getElementById('loadingdiv');
if(Obj) {
Obj.innerHTML = 'Done';
}
fieldObj.form.id.value = data;
}
function empty(data){
}
function keepSessionActive(timeCount){
timeCount = 1;
var ajaxVar = new ajaxVars();
ajaxVar.vars['action'] = "runFunction";
ajaxVar.vars['func'] = "keepSessionActiveINC";
ajaxVar.vars['nosplit'] = 1;
ajaxVar.gotoFunction = '';
ajaxVar.AjaxPostSQL();
ajaxVar.noLayer = 0;
var t = setTimeout("keepSessionActive("+timeCount+");",600000);
}
/*
function demo(data){
alert (data);
}
var ajaxVar = new ajaxVars();
ajaxVar.vars['sql'] = "select * from persons order by id";
ajaxVar.vars['action'] = "mysql_fetch_array";
ajaxVar.gotoFunction = "demo";
ajaxVar.AjaxPostSQL();
*/