var map;
var import_row;
var stopimportflag = false;
var nodecount = 0;
var nodemax = 0;
var allmarker;
var activeinfo;
var markers;
var marker_offset = 0;
var marker_count = 25;
function initialize(element, lat, lng, contentString, address) {
var latlng = new google.maps.LatLng(lat, lng);
zoom = 8;
if(document.getElementById('DISTANCE').value<50) {
zoom = 9;
}
if(document.getElementById('DISTANCE').value<20) {
zoom = 11;
}
if(document.getElementById('DISTANCE').value<10) {
zoom = 12;
}
if(document.getElementById('DISTANCE').value<5) {
zoom = 13;
}
if(document.getElementById('DISTANCE').value>50) {
zoom = 7;
}
var myOptions = {
zoom: zoom,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(element),myOptions);
var result_target = $('result');
result_target.update('');
if(document.getElementById('CITY')!=null) {
if((document.getElementById('CITY').value!='')) {
address = document.getElementById('CITY').value;
codeAddress(address);
}
}
}
function codeAddress(address) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': address}, function(results, status) {
if(status==google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var umkreis = {
map: map,
center: results[0].geometry.location,
radius: document.getElementById('DISTANCE').value*1000,
strokeColor: "#777777",
strokeOpacity: 0.8,
strokeWeight: 1,
//fillColor: "#7777ff",
fillOpacity: 0.05
}
new google.maps.Circle(umkreis);
if(document.getElementById('SERIECB').checked) {
loadMarker(document.getElementById('SERIE').value,'','',document.getElementById('CITY').value,document.getElementById('DISTANCE').value, map,results[0].geometry.location.lat(),results[0].geometry.location.lng());
} else {
loadMarker('%','','',document.getElementById('CITY').value,document.getElementById('DISTANCE').value, map,results[0].geometry.location.lat(),results[0].geometry.location.lng());
}
} else {
}
});
}
function makeMarker(lat, lng, content, map) {
var marker = new google.maps.Marker({
map:map,
draggable:false,
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng(lat,lng),
content: content
});
google.maps.event.addListener(marker,'click',function() {
if(activeinfo!=null) activeinfo.close();
activeinfo = new google.maps.InfoWindow({
content: content
});
activeinfo.open(map,marker);
});
return marker;
}
function showMarker(index) {
//allmarker[index].infowindow.open(map,allmarker[index]);
window.scrollTo(0,0);
if(activeinfo!=null) activeinfo.close();
activeinfo = new google.maps.InfoWindow({
content: allmarker[index].content
});
activeinfo.open(map,allmarker[index]);
map.setCenter(allmarker[index].position);
}
function clearMarker() {
if(allmarker) {
allmarker.each(function(i) {
i.setMap(null);
});
}
}
function loadMarker(serie, land, plz, city, umkreis, map, lat, lng)
{
var result_target = $('result');
result_target.update('
');
new Ajax.Request('php/custom.keuco/loadmarker.php', {
parameters: {'serie': serie, 'land': land, 'plz':plz, 'city':city, 'umkreis':umkreis, 'lat':lat, 'lng':lng},
onSuccess: function (r) {
markers = r.responseText.evalJSON();
marker_offset=0;
showTable();
}
});
}
function showTable() {
var result_target = $('result');
result_target.update('
');
content_string = '
';
var daiswas = false;
content_string = content_string + markers.header;
clearMarker();
allmarker = new Array();
var i = 0;
markers.data.each(function(item) {
if((i=marker_offset)) {
allmarker[i] = makeMarker(item.lat,item.lng,item.content, map);
daiswas=true;
if(item.serie!=null) {
content_string = content_string + '| '+item.name+' | '+item.strasse+' '+item.plz+' '+ item.ort +' | '+item.serie+' | '+item.www+' | ' + item.distance + ' km |
';
} else {
content_string = content_string + '| '+item.name+' | '+item.strasse+' '+item.plz+' '+ item.ort +' | '+item.www+' | ' + item.distance + ' km |
';
}
}
i++;
});
content_string = content_string+'
| ';
if(marker_offset>0) {
content_string = content_string+' | ';
}
i=0;
var j=0;
while(i' + j + '';
} else {
content_string = content_string+'' + j + '';
}
i+=marker_count;
}
if(marker_offset+marker_count ';
}
content_string = content_string+' | |
| |
';
if(daiswas) {
result_target.update(content_string);
} else {
result_target.update('');
}
ReCalcLayout();
}
function geoImportGeoCode(land, plz, city, strasse)
{
var address = land + ' ' + plz + ' ' + city + ' ' + strasse;
if(land=='F') address = city + ', ' + strasse + ', ' + plz;
if((land!='')||(plz!='')||(city!='')||(strasse!='')) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': address}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
setRowValue('.lat',results[0].geometry.location.lat());
setRowValue('.lng',results[0].geometry.location.lng());
new Ajax.Request('import_geocoords.php', {
parameters: {'land': land, 'plz': plz, 'city': city, 'strasse': strasse, 'lat': results[0].geometry.location.lat(), 'lng': results[0].geometry.location.lng()},
onSuccess: function(r) {
import_row.addClassName('status_ok');
nextNode();
}
});
} else {
import_row.addClassName('status_nok');
$('log').innerHTML = $('log').innerHTML + '
Keine Koordinaten gefunden: ' + land + ' ' + plz + ' ' + city + ' ' + strasse
nextNode();
}
});
} else {
nextNode();
}
}
function beginImport(num_nodes)
{
nodemax = num_nodes;
var nodetable = $('nodes');
import_row = nodetable.down('tr');
nodecount = 0;
importNode();
}
function nextNode()
{
import_row = import_row.next('tr');
setTimeout(function() {if(! stopimportflag) importNode();}, 1000);
}
function skipNode()
{
import_row = import_row.next('tr');
importNode();
}
function getRowValue(value)
{
var obj = import_row.down(value);
var retval = '';
if(typeof obj !== "undefined") {
retval = obj.innerHTML;
}
return retval;
}
function setRowValue(field, value)
{
var obj = import_row.down(field);
if(typeof obj !=="undefined") {
obj.innerHTML = value;
}
}
function stopImport()
{
stopimportflag = true;
}
function makeProgress()
{
var status = $('status');
var bar = $('statusbar');
bar.setStyle({'width':(nodecount/nodemax*100)+'%'});
}
function importNode()
{
if(typeof import_row !== "undefined") {
nodecount = nodecount + 1;
$('nc').update(nodecount + ' / ' + nodemax + ' : ' + getRowValue('.land') + ' ' + getRowValue('.plz') + ' ' + getRowValue('.city') + ' ' + getRowValue('.strasse'));
makeProgress();
if((getRowValue('.lat')!='')&&(getRowValue('.lng')!='')) {
skipNode();
} else {
geoImportGeoCode(getRowValue('.land'), getRowValue('.plz'), getRowValue('.city'), getRowValue('.strasse'));
}
}
}
var MerkzettelCounter = Class.create();
MerkzettelCounter.prototype = {
initialize: function() {
this.refresh();
},
refresh: function() {
$$('.merkzettelcounter').each( function(item) {
new Ajax.Updater(item,'php/custom.keuco/merkzettelcounter.php', {
});
});
}
}
var AusstellerCB = Class.create();
AusstellerCB.prototype = {
initialize: function() {
var objs = $$('.seriecb');
objs.checked = false;
$('SERIE').disable();
objs.each(function(item) {
item.observe('click', function(e) {
if(item.checked) {
$('SERIE').enable();
} else {
$('SERIE').disable();
}
})
//item.checked = true;
//$('SERIE').enable();
});
}
}
var Modalbox = Class.create();
var ModalboxStopObserve = false;
Modalbox.prototype = {
form: undefined,
confirm: 0,
otc: 0,
initialize: function() {
var objBody = $$('body')[0];
objBody.appendChild(Builder.node('div',{id:'modaloverlay'}));
objBody.appendChild(Builder.node('div',{id:'modalbox'}));
$('modaloverlay').hide().observe('click', (function(event) {
this.end(0);
}).bind(this));
$('modalbox').hide().observe('click', (function(event) {
}).bind(this));
this.insertHook();
},
insertHook: function() {
var mb = this;
$$('.modal').each(function(f) {f.up('form').observe('submit', (function(event){
if(ModalboxStopObserve==false) {
mb.start(this,mb);
mb.form = this;
event.stop();
}
}));
});
},
start: function(frame, instance) {
$$('select', 'object', 'embed').each(function(node){node.style.visibility = 'hidden'});
var arrayPageSize = this.getPageSize();
$('modaloverlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px'});
new Effect.Appear($('modaloverlay'), {duration: 1, from:0.0, to:0.7});
$('modalbox').innerHTML = frame.down('.modal').innerHTML;
var arrayPageScroll = document.viewport.getScrollOffsets();
var toppos = 100 + arrayPageScroll[1];
$('modalbox').setStyle({top:toppos+'px',left:'100px',right:'100px'});
$('modalbox').show();
$('modalbox').select('input').each( function(e) {
if(e.name=='OTC') instance.otc=e.value;
if(e.name=='CONFIRM') e.observe('click', function(){instance.confirm=this.value});
if(e.name=='CLOSE') e.observe('click', function(){instance.end(instance.confirm)});
});
},
end: function(commit) {
$('modalbox').hide();
if(commit==1) {
this.form.action = this.form.action + '&OTC=' + this.otc;
this.form.submit();
} else {
new Effect.Fade($('modaloverlay'), {duration: 1});
$$('select', 'object', 'embed').each(function(node){node.style.visibility = 'visible'});
}
},
getPageSize: function() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
if(document.documentElement.clientWidth){
windowWidth = document.documentElement.clientWidth;
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
return [pageWidth,pageHeight];
}
}
document.observe('dom:loaded',function() {new Modalbox();});
document.observe('dom:loaded',function() {new MerkzettelCounter();});
document.observe('dom:loaded',function() {new AusstellerCB();});