function sack(file) { this.xmlhttp = null; this.resetData = function() { this.method = "POST"; this.queryStringSeparator = "?"; this.argumentSeparator = "&"; this.URLString = ""; this.encodeURIString = true; this.execute = false; this.element = null; this.elementObj = null; this.requestFile = file; this.vars = new Object(); this.responseStatus = new Array(2);}; this.resetFunctions = function() { this.onLoading = function() { }; this.onLoaded = function() { }; this.onInteractive = function() { }; this.onCompletion = function() { }; this.onError = function() { }; this.onFail = function() { };}; this.reset = function() { this.resetFunctions(); this.resetData();}; this.createAJAX = function() { try { this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (e1) { try { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (e2) { this.xmlhttp = null;}
}
if (! this.xmlhttp) { if (typeof XMLHttpRequest != "undefined") { this.xmlhttp = new XMLHttpRequest();} else { this.failed = true;}
}
}; this.setVar = function(name, value){ this.vars[name] = Array(value, false);}; this.encVar = function(name, value, returnvars) { if (true == returnvars) { return Array(encodeURIComponent(name), encodeURIComponent(value));} else { this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);}
}
this.processURLString = function(string, encode) { encoded = encodeURIComponent(this.argumentSeparator); regexp = new RegExp(this.argumentSeparator + "|" + encoded); varArray = string.split(regexp); for (i = 0; i < varArray.length; i++){ urlVars = varArray[i].split("="); if (true == encode){ this.encVar(urlVars[0], urlVars[1]);} else { this.setVar(urlVars[0], urlVars[1]);}
}
}
this.createURLString = function(urlstring) { if (this.encodeURIString && this.URLString.length) { this.processURLString(this.URLString, true);}
if (urlstring) { if (this.URLString.length) { this.URLString += this.argumentSeparator + urlstring;} else { this.URLString = urlstring;}
}
this.setVar("rndval", new Date().getTime()); urlstringtemp = new Array(); for (key in this.vars) { if (false == this.vars[key][1] && true == this.encodeURIString) { encoded = this.encVar(key, this.vars[key][0], true); delete this.vars[key]; this.vars[encoded[0]] = Array(encoded[1], true); key = encoded[0];}
urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];}
if (urlstring){ this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);} else { this.URLString += urlstringtemp.join(this.argumentSeparator);}
}
this.runResponse = function() { eval(this.response);}
this.runAJAX = function(urlstring) { if (this.failed) { this.onFail();} else { this.createURLString(urlstring); if (this.element) { this.elementObj = document.getElementById(this.element);}
if (this.xmlhttp) { var self = this; if (this.method == "GET") { totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString; this.xmlhttp.open(this.method, totalurlstring, true);} else { this.xmlhttp.open(this.method, this.requestFile, true); try { this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
} catch (e) { }
}
this.xmlhttp.onreadystatechange = function() { switch (self.xmlhttp.readyState) { case 1:
self.onLoading(); break; case 2:
self.onLoaded(); break; case 3:
self.onInteractive(); break; case 4:
self.response = self.xmlhttp.responseText; self.responseXML = self.xmlhttp.responseXML; self.responseStatus[0] = self.xmlhttp.status; self.responseStatus[1] = self.xmlhttp.statusText; if (self.execute) { self.runResponse();}
if (self.elementObj) { elemNodeName = self.elementObj.nodeName; elemNodeName.toLowerCase(); if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") { self.elementObj.value = self.response;} else { self.elementObj.innerHTML = self.response;}
}
if (self.responseStatus[0] == "200") { self.onCompletion();} else { self.onError();}
self.URLString = ""; break;}
}; this.xmlhttp.send(this.URLString);}
}
}; this.reset(); this.createAJAX();}
var ajax = new sack(); function getLinePoint(sel,page,nel){ var sel = document.getElementById(sel); var countryCode = sel.value; document.getElementById(nel).options.length = 0; if(countryCode.length>0){ ajax.requestFile = page+'?route='+countryCode; if(nel=="start"){ ajax.onCompletion = fetchElem;}
else if(nel=="road"){ ajax.onCompletion = fetchElem2;}
else if(nel=="dhmoi"){ ajax.onCompletion = fetchElem3;}
ajax.runAJAX();}
}
function fetchElem()
{ var obj = document.getElementById("start"); eval(ajax.response);}
function fetchElem2()
{ var obj = document.getElementById("road"); eval(ajax.response);}
function fetchElem3()
{ var obj = document.getElementById("dhmoi"); eval(ajax.response);}
function linkIt(url) { location.href = url;}
function refresh()
{ var sURL = unescape(window.location.pathname); window.location.href = sURL;}
function apear(div)
{ var divi= document.getElementById(div); divi.style.height ="30px"; divi.style.visibility="visible"; divi.style.paddingTop="10px"; divi.style.margin="0px";}
function disapear(div)
{ var divi= document.getElementById(div); divi.style.height ="0px"; divi.style.visibility="hidden"; divi.style.padding="0px"; divi.style.margin="0px";}
function acceptValue(divFrom,divTo){ var val2 = document.getElementById(divTo).value; var val1 = document.getElementById(divFrom).value; var parts = val1.split("|"); if(parts[1]){ document.getElementById(divTo).value =parts[1];}else{ document.getElementById(divTo).value = document.getElementById(divFrom).value;}
}
function clearOpts(elem){ document.getElementById(elem).options.length=0;}
function swip(){ var swl = document.getElementById('total'); swl.style.height ="0px"; swl.style.visibility="hidden"; swl.style.padding="0px"; swl.style.margin="0px";}
var ajax2 = new sack(); function getLinePoint2(sel2,page2,nel2){ var sel2 = document.getElementById(sel2); var countryCode2 = sel2.value; document.getElementById(nel2).options.length = 0; if(countryCode2.length>0){ ajax2.requestFile = page2+'?route='+countryCode2; if(nel2=="start2"){ ajax2.onCompletion = fetchElems;}
else if(nel2=="road2"){ ajax2.onCompletion = fetchElems2;}
else if(nel2=="dhmoi2"){ ajax2.onCompletion = fetchElems3;}
ajax2.runAJAX();}
}
function fetchElems()
{ var obj = document.getElementById("start2"); eval(ajax2.response);}
function fetchElems2()
{ var obj = document.getElementById("road2"); eval(ajax2.response);}
function fetchElems3()
{ var obj = document.getElementById("dhmoi2"); eval(ajax2.response);}
function linkIt2(url) { location.href = url;}
function apear2(div2)
{ var divi2= document.getElementById(div2); divi2.style.height ="30px"
divi2.style.visibility="visible"; divi2.style.paddingTop="10px"; divi2.style.margin="0px";}
function disapear2(div2)
{ var divi2= document.getElementById(div2); divi2.style.height ="0px;"
divi2.style.visibility="hidden"; divi2.style.padding="0px"; divi2.style.margin="0px";}
function acceptValue2(divFrom2,divTo2){ var val2_2 = document.getElementById(divTo2).value; var val1_2 = document.getElementById(divFrom2).value; var parts2 = val1_2.split("|")
if(parts2[1]){ document.getElementById(divTo2).value =parts2[1];}else{ document.getElementById(divTo2).value = document.getElementById(divFrom2).value;}
}
function clearOpts2(elem2){ document.getElementById(elem2).options.length=0;}
var dome = new sack(); function whenLoading(){ var e = document.getElementById('replaceme'); e.innerHTML = "<img src='../../img/loading.gif' alt='loader'>";}
function whenLoaded(){ var e = document.getElementById('replaceme'); e.innerHTML = "<img src='../../img/loading.gif' alt='loader'>Data Sent...";}
function whenInteractive(){ var e = document.getElementById('replaceme'); e.innerHTML = "<img src='../../img/loading.gif' alt='loader'>getting data...";}
function whenLoading2(){ var e = document.getElementById('routingDiv'); e.innerHTML = "<img src='../img/loading.gif' alt='loader'>";}
function whenLoaded2(){ var e = document.getElementById('routingDiv'); e.innerHTML = "<img src='../img/loading.gif' alt='loader'>Data Sent...";}
function whenInteractive2(){ var e = document.getElementById('routingDiv'); e.innerHTML = "<img src='../img/loading.gif' alt='loader'>getting data...";}
function doit(){ var form = document.getElementById('forma'); dome.setVar("epiviv", form.epiviv.value);dome.setVar("maxWalk", form.maxWalk.value); dome.setVar("dhmoi", form.dhmoi.value); dome.setVar("start", form.start.value); dome.setVar("road", form.road.value); dome.setVar("dhmoi2", form.dhmoi2.value); dome.setVar("start2", form.start2.value); dome.setVar("road2", form.road2.value); dome.setVar("apovivasi", form.apovivasi.value); dome.requestFile = "procedure.php"; dome.method = 'post'; dome.element = 'replaceme'; dome.onLoading = whenLoading; dome.onLoaded = whenLoaded; dome.onInteractive = whenInteractive; dome.runAJAX(); setTimeout("window.scrollBy(0,300)",2000);}
function doitLess(){ var form = document.getElementById('forma'); dome.setVar("epiviv", form.epiviv.value);dome.setVar("maxWalk", form.maxWalk.value); dome.setVar("start", form.start.value); dome.setVar("road", form.road.value); dome.setVar("start2", form.start2.value); dome.setVar("road2", form.road2.value); dome.setVar("apovivasi", form.apovivasi.value); dome.requestFile = "procedure.php"; dome.method = 'post'; dome.element = 'replaceme'; dome.onLoading = whenLoading; dome.onLoaded = whenLoaded; dome.onInteractive = whenInteractive; dome.runAJAX(); disapear("forma");}
function doLines(){ var form = document.getElementById('forma');dome.setVar("maxWalk", form.maxWalk.value); dome.setVar("lines", form.lines.value); dome.setVar("municipal", form.municipal.value); dome.setVar("tax", form.tax[0].value); dome.setVar("tax1", form.tax[1].value); dome.requestFile = "elabor.php"; dome.method = "post"; dome.element = "routingDiv"; dome.onLoading = whenLoading2; dome.onLoaded = whenLoaded2; dome.onInteractive = whenInteractive2; dome.runAJAX();}
var http_request = false; function makeRequest(url, parameters) { http_request = false; if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/html');}
} else if (window.ActiveXObject) { try { http_request = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}
}
}
if (!http_request) { alert('Cannot create XMLHTTP instance'); return false;}
http_request.onreadystatechange = alertContents; http_request.open('GET', url + parameters, true); http_request.send(null);}
function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { alert(http_request.responseText); result = http_request.responseText; document.getElementById('res').innerHTML = result;} else { alert('There was a problem with the request.');}
}
}
function get(obj) { var getstr = "?"; for (i=0; i<obj.childNodes.length; i++) { if (obj.childNodes[i].tagName == "input") { if (obj.childNodes[i].type == "text") { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";}
if (obj.childNodes[i].type == "checkbox") { if (obj.childNodes[i].checked) { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";} else { getstr += obj.childNodes[i].name + "=&";}
}
if (obj.childNodes[i].type == "radio") { if (obj.childNodes[i].checked) { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";}
}
}
if (obj.childNodes[i].tagName == "select") { var selec = obj.childNodes[i]; getstr += selec.name + "=" + selec.options[selec.selectedIndex].value + "&";}
}
makeRequest('js/get.php', getstr);}
function doMap(){var form = document.getElementById('mapForm');dome.requestFile = "inc.php";dome.method = "post";dome.element = "dispMap";dome.onLoading = whenLoading3;dome.onLoaded = whenLoaded3;dome.onInteractive = whenInteractive3;dome.runAJAX();}

function whenLoading3(){
	var e = document.getElementById('dispMap');  
	e.innerHTML = "<img src='../img/loading.gif' alt='loader'>";
}

function whenLoaded3(){
	var e = document.getElementById('dispMap'); 
	e.innerHTML = "<img src='../img/loading.gif' alt='loader'>Data Sent...";
}

function whenInteractive3(){
	var e = document.getElementById('dispMap'); 
	e.innerHTML = "<img src='../img/loading.gif' alt='loader'>getting data...";
}
