
Array.prototype.indexOf = function(value)
{
for (ii=0; ii<this.length;ii++)
{
if (this[ii] == value)
{
return ii;
}
}
return -1;
}
Array.prototype.remove = function(index, count)
{
for (this.i=index; this.i <= this.length-count; this.i++)
{
this[this.i] = this[this.i+count];
}
for (this.i=0; this.i < count; this.i++) this.pop(); 
}
String.prototype.remove = function(index, count)
{
start = this.substr(0,index);
end   = this.substr(index+count);
this.value  = start+end;
}
if (Image.prototype)
{
Image.prototype.loaded = function()
{
if (typeof this.complete != "undefined")
{
return this.complete;
}
return (this.naturalWidth > 0);
}
}
if (typeof HTMLImageElement != "undefined")
{
HTMLImageElement.prototype.loaded = function()
{
if (typeof this.complete != "undefined")
{
return this.complete;
}
return (this.naturalWidth > 0);
}
}
ImageLoaded = function(obj)
{
if (!obj)
{
return false;
}
if (typeof obj.complete != "undefined")
{
return obj.complete;
}
if (obj.naturalWidth)
{
return (obj.naturalWidth > 0);
}
return false;
}
ENCODING = function()
{
}
ENCODING.urlEncode = function(str)
{
str = escape(str);
str = str.replace(/\+/g, "%2B");
str = str.replace(/%20/g, "+");
str = str.replace(/\*/g, "%2A");
str = str.replace(/\//g, "%2F");
str = str.replace(/@/g, "%40");
return str;
}
ENCODING.urlDecode = function(str) 
{
str = str.replace(/\+/g, " ");
try
{
str = decodeURIComponent(str);
}
catch (e)
{
}
return str;
}
ENCODING.utf8Encode = function(string) 
{        
string = string.replace(/rn/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;    
}
ENCODING.ISO88591Encode = function(string)
{
for (i=0 ;i < string.length ;i++ )
{
if (string.charCodeAt(i) > 127)
{
string[i] = String.fromCharCode(string.charCodeAt(i)-8090);
}
}
return string;
}
function AJAX()
{
this.responseHandler = null;
this.reset();
this.resetData();
}
AJAX.prototype.variables = function()
{
this.names = new Array();
this.values = new Array();
}
AJAX.prototype.files = function()
{
this.names = new Array();
this.filenames = new Array();
this.data = new Array();
}
AJAX.prototype.initialised = function()
{
return !(this.xmlHttp == null);
}
AJAX.prototype.reset = function()
{
var xmlHttp;
try
{  
xmlHttp=new XMLHttpRequest();  
}
catch (e)
{  
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
}
catch (e)
{    
try
{      
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
}
catch (e)
{      
this.xmlHttp = null;
}
}
}
this.xmlHttp = xmlHttp;
this.setResponseHandler(this.responseHandler);
}
AJAX.prototype.abort = function()
{
try
{
this.xmlHttp.abort();
}
catch (e)
{
}
}
AJAX.prototype.resetData = function()
{
this.variables = new AJAX.prototype.variables();
this.files     = new AJAX.prototype.files();
}
AJAX.prototype.setVariable = function(name, value)
{
if (this.xmlHttp == null)
{
return;
}
index = this.variables.names.indexOf(name);
if (index >= 0)
{
this.variables.values[index] = value;
}
else
{
this.variables.names.push(name);
this.variables.values.push(value);
}
}
AJAX.prototype.removeVariable = function(name)
{
if (this.xmlHttp == null)
{
return false;
}
index = this.variables.names.indexOf(name);
if (index >= 0)
{
this.variables.names[index] = this.variables.names[this.variables.names.length-1];
this.variables.values[index] = this.variables.values[this.variables.values.length-1];
this.variables.names.pop();
this.variables.values.pop();
return true;
}
else 
{
return false;
}
}
AJAX.prototype.setVariables = function(names, values)
{
if (this.xmlHttp == null)
{
return;
}
lmin = Math.min(names.length, values.length);
for (i = 0; i < lmin ; i++ )
{
this.setVariable(names[i],values[i]);
}
}
AJAX.prototype.removeVariables = function(names)
{
if (this.xmlHttp == null)
{
return;
}
for (i = 0; i < names.length ; i++ )
{
this.removeVariable(names[i]);
}
}
AJAX.prototype.sendPostRequest = function(target)
{
if (this.xmlHttp == null)
{
return false;
}
this.data = "";
for (i=0; i < this.variables.names.length ;i++)
{
this.data += encodeURIComponent(this.variables.names[i]) + "=" +encodeURIComponent(this.variables.values[i]) + "&"; 
}
this.data = this.data.substr(0,this.data.length-1);
try
{
this.xmlHttp.open("POST",target,true);
this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.xmlHttp.setRequestHeader("Content-length", this.data.length);
this.xmlHttp.setRequestHeader("Connection", "close");
this.xmlHttp.send(this.data);
}
catch (e)
{
return false;
}
return true;
}
AJAX.prototype.sendGetRequest = function(target)
{
if (this.xmlHttp == null)
{
return false;
}
this.data = target + "?";
for (i=0; i < this.variables.names.length; i++)
{
this.data += encodeURIComponent(this.variables.names[i]) + "=" + encodeURIComponent(this.variables.values[i]) + "&";
}
this.data = this.data.substr(0,this.data.length-1);
try
{
this.xmlHttp.open("GET",this.data, true);
this.xmlHttp.send(null);
}
catch (e)
{
return false;
}
return true;
}
AJAX.prototype.setFile = function(name, filename, filedata)
{
if (this.xmlHttp == null)
{
return;
}
this.index = this.files.names.indexOf(name);
if (this.index >= 0)
{
this.files.filenames[this.index] = filename;
this.files.data[this.index] = filedata;
}
else
{
this.files.names.push(name);
this.files.filenames.push(filename);
this.files.data.push(filedata);
}
}
AJAX.prototype.setFiles = function(names, filenames, filedata)
{
if (this.xmlHttp == null)
{
return;
}
lmin = Math.min(names.length, filenames.length, filedata.length)
for (i = 0; i < lmin ; i++ )
{
this.setFile(names[i], filenames[i], filedata[i]);
}
}
AJAX.prototype.removeFile = function(name)
{
if (this.xmlHttp == null)
{
return;
}
this.index = this.files.names.indexOf(name);
if (this.index >= 0)
{
this.files.names[this.index] = this.files.names[this.files.names.length-1];
this.files.filenames[this.index] = this.files.filenames[this.files.filenames.lenght-1];
this.files.data[this.index] = this.files.data[this.files.data.length-1];
this.files.names.pop();
this.files.filenames.pop();
this.files.data.pop();
}
}
AJAX.prototype.removeFiles = function(names)
{
if (this.xmlHttp == null)
{
return;
}
for (i=0; i<names.length ; i++ )
{
this.removeFile(names[i]);
}
}
AJAX.prototype.upload = function(target)
{
if (this.xmlHttp == null)
{
return false;
}
this.boundarystr = "------------------------------4j4xupl0ader";
this.boundary = "--"+this.boundarystr;
this.data = "";
for (i=0; i < this.variables.names.length ;i++)
{
this.data += 'Content-Disposition: form-data; name="'+ this.variables.names[i]+'"' + '\n' 
 +  '\n' 
 +  this.variables.values[i] + '\n' 
 + this.boundary + '\n'; 
}
for (i=0; i < this.files.names.length ; i++)
{
this.data += 'Content-Disposition: form-data; name="'+this.files.names[i]+'"; filename="' 
 +  this.files.filenames[i] + '"' + '\n' 
 + 'Content-Type: application/octet-stream' + '\n' 
 + '\n'
 + this.files.data[i] + '\n'
 + this.boundary + '\n';
} 
this.data = this.boundary + '\n' + this.data;
this.data = this.data.substr(0,this.data.length-1);
try
{
this.xmlHttp.open('POST', target, true);
this.xmlHttp.setRequestHeader("Content-type", "multipart/form-data; \boundary=\""+this.boundarystr+"\"");
this.xmlHttp.setRequestHeader("Connection", "close");
this.xmlHttp.setRequestHeader("Content-length", this.data.length);
this.xmlHttp.send(this.data);
}
catch (e)
{
return false;
}
return true;
}
AJAX.prototype.getXmlHttp = function()
{
return this.xmlHttp;
}
AJAX.currentXmlHttp = null;
AJAX.prototype.setResponseHandler = function(func)
{
if (this.xmlHttp == null)
{
return;
}
this.responseHandler = func;
AJAX.currentXmlHttp = this.xmlHttp;
this.xmlHttp.onreadystatechange = function()
{
func(this);
}
}
AJAX.request = function(){};
AJAX.request.post   = function(target, varNames, varDatas, handler)
{
this.varNames = varNames;
this.varDatas = varDatas;
this.responseHandler = handler;
this.target = target;
this.process = function()
{
AJAX.manager.ajaxHandler.setVariables(this.varNames, this.varDatas);
AJAX.manager.ajaxHandler.sendPostRequest(this.target);
}
}
AJAX.request.get    = function(target, varNames, varDatas, handler)
{
this.varNames = varNames;
this.varDatas = varDatas;
this.responseHandler = handler;
this.target = target;
this.process = function()
{
AJAX.manager.ajaxHandler.setVariables(this.varNames, this.varDatas);
AJAX.manager.ajaxHandler.sendGetRequest(this.target);
}
}
AJAX.request.upload = function(target, varNames, fileNames, fileDatas, handler)
{
this.varNames = varNames;
this.fileDatas = fileDatas;
this.fileNames = fileNames;
this.target = target;
this.responseHandler = handler;
this.process = function()
{
AJAX.manager.ajaxHandler.setFiles(this.varNames, this.fileNames, this.fileDatas);
AJAX.manager.ajaxHandler.upload(this.target);
}
}
AJAX.manager = function(){};
AJAX.manager.ajaxHandler = new AJAX();
AJAX.manager.requestQueue = new Array();
AJAX.manager.addRequest = function(request)
{
id = AJAX.manager.requestQueue.indexOf(request);
if (id < 0)
{
AJAX.manager.requestQueue.push(request);
if (AJAX.manager.requestQueue.length == 1)
{
AJAX.manager.process();
}
}
}
AJAX.manager.process = function()
{
if (AJAX.manager.ajaxHandler == null || AJAX.manager.requestQueue.length == 0)
{
return;
}
AJAX.manager.ajaxHandler.reset();
AJAX.manager.ajaxHandler.resetData();
AJAX.manager.requestQueue[0].process();
}
AJAX.manager.responseHandler = function(xmlHttp)
{
if (AJAX.currentXmlHttp.readyState == 4)
{
parser = new AJAX.responseParser();
parser.parse(AJAX.currentXmlHttp.responseText);
if (AJAX.manager.requestQueue[0].responseHandler)
{
AJAX.manager.requestQueue[0].responseHandler(parser);
}
AJAX.manager.requestQueue.remove(0,1);
AJAX.manager.process();
}
}
if (AJAX.manager.ajaxHandler != null)
{
AJAX.manager.ajaxHandler.setResponseHandler(AJAX.manager.responseHandler);
}
AJAX.manager.getCurrentRequest = function()
{
if (AJAX.manager.resquestQueue[0])
{
return AJAX.manager.resquestQueue[0];
}
else
{
return null;
}
}
AJAX.manager.done = function()
{
return (AJAX.manager.resquestQueue.length == 0);
}
AJAX.manager.abortRequests = function()
{
AJAX.manager.ajaxHandler.abort();
delete AJAX.manager.requestQueue;
AJAX.manager.requestQueue = new Array();
}
AJAX.response = function(rType, rName, rData)
{
this.set(rType, rName, rData);
}
AJAX.response.prototype.set = function(rType, rName, rData)
{
this.type = rType;
this.name = rName;
this.data = rData;
}
AJAX.response.prototype.getType = function()
{
return this.type;
}
AJAX.response.prototype.getDataById = function(id)
{
if (this.data[id])
{
return this.data[id];
}
else
{
return "";
}
}
AJAX.response.prototype.getDataByName = function(name)
{
id = this.name.indexOf(name)
if (id >= 0)
{
return this.data[id];
}
else
{
return "";
}
}
AJAX.response.prototype.getDataArray = function()
{
res = new Array();
for (i = 0; i < this.name.length ; i++ )
{
res.push(this.data[i]);
}
return res;
}
AJAX.response.prototype.getNameById = function(index)
{
if (this.name[index])
{
return this.name[index];
}
else
{
return null;
}
}
AJAX.responseParser = function()
{
this.index;
this.responses;
this.rawData = "";
}
AJAX.responseParser.prototype.endDeteminer = " END ";
AJAX.responseParser.prototype.parse = function(rawData)
{
this.responses= new Array();
this.index= 0;
this.rawData= rawData;
raw = rawData.split(this.endDeteminer);
for (i = 0; i < raw.length ; i++ )
if (raw[i].length > 0)
{
colData = raw[i].split(" ");
if (colData[0] == "RES")
{
bufferT = "result";
}
else if (colData[0] == "ERR")
{
bufferT = "error";
}
else
{
bufferT = "unknown";
}
bufferD = new Array();
bufferN = new Array();
for (j = 1; j < colData.length ; j++ )
{
parameter = colData[j].split("=");
if (parameter.length == 2)
{
bufferN.push(ENCODING.urlDecode(parameter[0]));
bufferD.push(ENCODING.urlDecode(parameter[1]));
}
}
this.responses.push(new AJAX.response(bufferT, bufferN, bufferD));
}
}
AJAX.responseParser.prototype.getResponse = function()
{
if (this.index < this.responses.length)
{
return this.responses[this.index++]
}
else
{
return null;
}
}
AJAX.responseParser.prototype.resetIndex = function()
{
this.index = 0;
}
AJAX.responseParser.prototype.seekIndex = function(offset)
{
this.index += offset;
}
AJAX.responseParser.prototype.getRaw = function()
{
return this.rawData;
}
function setSelectContent(parser)
{
response = parser.getResponse();
document.getElementById("location").innerHTML = response.getDataByName("location");
}
AJAX.manager.addRequest(new AJAX.request.post("services/location.php",new Array(), new Array(), setSelectContent));

