function Adress(lat,lng,name,accuracy){
this.lat = lat;
this.lng = lng;
this.name = name;
this.accuracy = accuracy;
}
function Listener(map,event,callback){
var that = this;
this.event = event;
this.callback = callback;
this.map = map;
this.object = null;
that.enabled = false;
this.enable = function (){
if(that.enabled === false){
that.object = that.map.addListener(event,callback);
that.enabled = true;
}
};
this.disable = function(){
if(that.object!==null){
that.map.removeListener(that.object);
}
that.enabled = false;
};
this.isEnabled = function(){return that.enabled;};
}
function ListenerGroup(listeners){
this.enable = function (){
for(var i = 0;i < listeners.length;i++){
listeners[i].enable();
}
};
this.disable = function(){
for(var i = 0;i < listeners.length;i++){
listeners[i].disable();
}
};
}
Listener.SHOWCAMS = null;
Listener.UPDATELOCATIONHEADER = null;
Listener.ADD_CAMERA_MARKER = null;
Listener.UPDATE_VIEWMAP_HASH = null;
//MyMap Class
function MyMap(lat,lng,zoom,canvas,ncCallback){
var that = this;
var map;
var markers = new Array(0);
//convert lat to double
lat*=1.0;
lng*=1.0;
zoom*=1;
if(zoom<=0||zoom===null||zoom===false){zoom=13;}
if (GBrowserIsCompatible()) {
//PRIVATE MEMBERS
//special variable to assign this in privileged functions
//var camAddable = false;
//CONSTRUCT
//TODO check api desc!
map = new GMap2($(canvas));
map.setCenter(new GLatLng(lat, lng,true),zoom);
map.setMapType(G_HYBRID_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.disableScrollWheelZoom();
map.enableContinuousZoom();
//GEvent.addListener(map,"moveend",this.moved);
//FUNCTIONS
/*this.setCamAddable = function (addable){
if(addable&&camAddable===false){
//add listeners and update variable
//GEvent.addListener(map, "click", that.click);
//GEvent.addListener(newMarker, "dragend", that.dragend);
camAddable = addable;
}else if(!addable&&camAddable===true){
//remove listeners and update variable
camAddable = addable;
}
};*/
this.addListener = function (event,callback){return GEvent.addListener(map,event,callback);};
this.addMarker = function (marker){
map.addOverlay(marker);
markers.push(marker);
};
this.getMarkers = function (){return markers;};
this.getZoom = function (){return map.getZoom();};
this.getCenter = function (){return map.getCenter();};
this.removeListener = function (listener){GEvent.removeListener(listener);};
this.removeMarker = function (marker,pos){
map.removeOverlay(marker);
if(pos!==null&&pos>=0&&markers[pos]===marker){
markers.splice(pos,1);
return true;
}
for(var i=0;i < markers.length;i++){
if(markers[i]===marker){
markers.splice(i,1);
//i-- is not required because of the return!
return true;
}
}
return false;
};
this.removeMarkers = function (m){
var ret = true;
for(var i=0 ; i < m.length; i++){
ret = ret && that.removeMarker(m[i]);
i--;
}
return ret;
};
this.removeAllMarkers = function(){
for(var i=0 ; i < markers.length; i++){
map.removeOverlay(markers[i]);
}
markers = [];
};
this.setCenter = function(latlng){return map.setCenter(latlng);};
this.getNorthEast = function (){return map.getBounds().getNorthEast();};
this.getSouthWest = function (){return map.getBounds().getSouthWest();};
this.zoomIn = function(){return map.zoomIn();};
return this;
}else{
//Browser is incompatible
ncCallback();
return false;
}
}
//STATIC VARIABLES
var geocoder = null;
MyMap.getAccuracyZoom = function (accuracy){
switch (accuracy) {
/*closer than city*/
case 7: return 17;
case 6: return 16;
case 5: return 14;
/*city*/
case 3:
case 4: return 12;
/*county*/
case 2: return 7;
/*county county*/
case 1: return 4;
default: return 7;
}
};
MyMap.getGeocoder = function (){
if(geocoder ===null){
geocoder = new GClientGeocoder(new GFactualGeocodeCache());
//Ergebnisse aus Deutschland bevorzugen
geocoder.setBaseCountryCode("de");
//geocoder.setBaseCountryCode("de");
//geocoder.setBaseCountryCode(window.navigator.language);
}
return geocoder;
};
//STATIC FUNCTIONS
MyMap.getLatLng = function (location,callback,ncCallback){
if (GBrowserIsCompatible()) {
MyMap.getGeocoder().getLocations(location, function(responce){
var ret = Array();
if(responce.Status.code==200){
//Placemark gefunden
for(var i = 0;i < responce.Placemark.length;i++){
var pm = responce.Placemark[i];
var p = pm.Point;
var address;
if( typeof(p.address) != "undefined" ){
address = p.address;
}else if( typeof(pm.address) != "undefined" ){
address = pm.address;
}else if( typeof(response.name) != "undefined" ){
address = response.name;
}else{
address = location;
}
ret.push(new Adress(p.coordinates[1],p.coordinates[0],address,pm.AddressDetails.Accuracy));
}
}
callback(ret);
});
return true;
}else{
ncCallback();
return false;
}
};
//MyGmapInterface Class
function MyGmapInterface(){}
//STATIC Variables
MyGmapInterface.activeMarker = null;
MyGmapInterface.loadCamsResponseCache = null;
MyGmapInterface.myMap = null;
MyGmapInterface.newCamMarker = null;
MyGmapInterface.newCamMarkerO1 = null;
MyGmapInterface.newCamMarkerO2 = null;
MyGmapInterface.oldNorthEast = null;
MyGmapInterface.oldSouthWest = null;
MyGmapInterface.oldZoom = -1;
MyGmapInterface.TAB_L = "";
MyGmapInterface.TAB_M = "";
MyGmapInterface.tabsLoaded = false;
MyGmapInterface.userInput = "";
MyGmapInterface.thisCamId = 0;
MyGmapInterface.thisCamTitle = null;
MyGmapInterface.searchResults = null;
MyGmapInterface.selTab = -1;
MyGmapInterface.thisCamTitle = "";
MyGmapInterface.camMarkersById = {};
MyGmapInterface.avoidTabChange = false;
MyGmapInterface.pageSetup = false;
//LISTENERS
//STATIC Function
MyGmapInterface.addNewCamMarkers = function (cams){
if(typeof(cams)==="undefined"){return;}
var cameras = [];
for(var k = 0;k < cams.length;k++){
cameras.push(cams[k]);
}
var markers = MyGmapInterface.myMap.getMarkers();
if(MyGmapInterface.myMap.getZoom()===MyGmapInterface.oldZoom){
for(var i = 0;i < markers.length;i++){
var found = false;
for(k = 0;k < cameras.length;k++){
var p = markers[i].getPoint();
var c = cameras[k];
if(p.lat()==c.lat&&p.lng()==c.lng){
//Kamera bekannt
cameras.splice(k,1);
k--;
found = true;
break;
}
}
if(!found&&markers[i]!==MyGmapInterface.activeMarker){
if(MyGmapInterface.myMap.removeMarker(markers[i],i)){i--;}
}
}
}else{
MyGmapInterface.myMap.removeMarkers(markers);
MyGmapInterface.oldZoom = MyGmapInterface.myMap.getZoom();
}
for(var x= 0; x < cameras.length;x++){
var mr = MyGmapInterface.createCamMarker(cameras[x]);
MyGmapInterface.myMap.addMarker(mr);
MyGmapInterface.camMarkersById[cameras[x].id] = mr;
}
};
MyGmapInterface.createCamMarker = function (camera){
var that = this;
var latlng = new GLatLng(camera.lat,camera.lng);
var gIcon = MyGmapInterface.getCamIcon(camera);
var marker = new GMarker(latlng,
{
//GMarkerOptions
title: camera.title,
clickable: true,
draggable: false,
bouncy: false,
autoPan: false,
icon: gIcon
}
);
var html = "
Titel:
"+camera.title+""+
"
Bewertung: "+Math.round(parseFloat(camera.avg)*100)/100+
"
Webcam ansehen" +
"
"+camera.desc+"
";
GEvent.addListener(marker, 'click', function(latlng){
var zoom = MyGmapInterface.myMap != null?MyGmapInterface.myMap.getZoom():-1;
if(!(zoom==null||zoom < 0)){ zoom = 14; }
MyGmapInterface.activeMarker = marker;
marker.openInfoWindowHtml(html,{maxWidth:350});
var sendData = "camId="+camera.id;
MyGmapInterface.thisCamId = camera.id;
MyGmapInterface.thisCamTitle = camera.title;
MyGmapInterface.TAB_M = RequestCache.getRequest("POST","http://www.camnetwork.org/de/thiscam.js",sendData,null);
if(MyGmapInterface.selTab===TAB_MIDDLE){setTabContent(MyGmapInterface.TAB_M);}
if(!MyGmapInterface.avoidTabChange){tabSelected(TAB_MIDDLE);}
document.title = 'Webcam - '+camera.title;
if(!MyGmapInterface.pageSetup){
ROUTE_SHOW_CAM.executed(new Array(""+camera.id,""+camera.lat,""+camera.lng,""+zoom,camera.title));
MyGmapInterface.activeRoute = ROUTE_SHOW_CAM;
}
}
);
GEvent.addListener(marker, 'infowindowclose', function(){
if(MyGmapInterface.activeMarker === marker){MyGmapInterface.activeMarker = null;}
}
);
//var oldHeader = MyGmapInterface.getMapHeader();
GEvent.addListener(marker, 'infowindowopen', function(){
if(Listener.UPDATELOCATIONHEADER!==null){Listener.UPDATELOCATIONHEADER.disable();}
MyGmapInterface.thisCamTitle = camera.title;
MyGmapInterface.setMapHeader(camera.title);
}
);
GEvent.addListener(marker, 'infowindowclose', function(){
if(Listener.UPDATELOCATIONHEADER!==null){Listener.UPDATELOCATIONHEADER.enable();}
}
);
marker.setActive = function(){
MyGmapInterface.activeMarker = marker;
marker.openInfoWindowHtml(html,{maxWidth:350});
MyGmapInterface.thisCamId = camera.id;
MyGmapInterface.thisCamTitle = camera.title;
var sendData = "camId="+camera.id;
MyGmapInterface.TAB_M = RequestCache.getRequest("POST","http://www.camnetwork.org/de/thiscam.js",sendData,null);
document.title = 'Webcam - '+camera.title;
};
return marker;
};
MyGmapInterface.setCamMarkerActive = function(camId){
if(MyGmapInterface.loadCamsResponseCache===null){
return false;
}
var mycammarker = MyGmapInterface.camMarkersById[camId];
if(mycammarker==null || (typeof mycammarker) == 'undefined'){
return false;
}
mycammarker.setActive();
return true;
};
MyGmapInterface.showThisCam = function (camId){
if(MyGmapInterface.loadCamsResponseCache===null){MyGmapInterface.loadCams();}
var mycammarker = MyGmapInterface.camMarkersById[camId];
if(mycammarker!==null && (typeof mycammarker) != 'undefined' ){
MyGmapInterface.avoidTabChange = MyGmapInterface.selTab===TAB_LEFT;
if(Listener.UPDATE_VIEWMAP_HASH != null && Listener.UPDATE_VIEWMAP_HASH.isEnabled() ){
Listener.UPDATE_VIEWMAP_HASH.disable();
GEvent.trigger(mycammarker,"click");
Listener.UPDATE_VIEWMAP_HASH.enable();
}else{
GEvent.trigger(mycammarker,"click");
}
MyGmapInterface.avoidTabChange = false;
}else{
var sendData = "camId="+camId;
var singleMarkerResponse = RequestCache.getRequest('POST',"http://www.camnetwork.org/camobject.js",sendData,null);
var singleMarker = eval( "(" + singleMarkerResponse + ")" );
var mr = MyGmapInterface.createCamMarker(singleMarker);
MyGmapInterface.myMap.addMarker(mr);
MyGmapInterface.camMarkersById[camId] = mr;
if(Listener.UPDATE_VIEWMAP_HASH != null && Listener.UPDATE_VIEWMAP_HASH.isEnabled() ){
Listener.UPDATE_VIEWMAP_HASH.disable();
GEvent.trigger(mr,"click");
Listener.UPDATE_VIEWMAP_HASH.enable();
}else{
GEvent.trigger(mr,"click");
}
}
};
MyGmapInterface.getCamIcon = function (camera){
var ret = new GIcon(G_DEFAULT_ICON);
var zoom = MyGmapInterface.myMap.getZoom();
var icontype = null;
if(zoom > 13){
icontype = "g";
ret.iconSize = new GSize(38,34);
ret.imageMap = [0,8,11,0,17,0,37,8,38,17,32,22,35,26,35,30,30,30,30,27,29,24,23,27,10,29,4,16,0,12,0,8];
}else if(zoom>6){
icontype = "l";
ret.imageMap = [0,6,9,0,14,1,18,2,23,2,26,3,29,7,30,10,30,13,25,18,26,20,27,22,26,24,24,27,23,20,7,22,6,16,3,13,0,6];
ret.iconSize = new GSize(30,27);
}
else{
icontype = "s";
//TODO imagemap
ret.iconSize = new GSize(22,18);
}
ret.image = "http://www.camnetwork.org/media/img/c"+icontype+Math.round(parseFloat(camera.avg))+".png";
return ret;
};
MyGmapInterface.searchFieldInteractionId = 'top_search_interaction_box';
MyGmapInterface.getMapContainer = function (){return "map_canvas";};
MyGmapInterface.getMapHeader = function (){var h = $("map_header");if(h!==null){return Utils.getSubElements(h,1)[1].innerHTML;}else{return "";}};
MyGmapInterface.initLocation = function (location,preGmapCallback,postGmapCallback,zoom){
if(location!==null&&location!==""){
MyMap.getLatLng(location, function(adresses){
if(adresses.length===1){
//genau ein Treffer
var a = adresses[0];
if((typeof zoom ==="undefined" || zoom < 0) && typeof(a.accuracy) !== "undefined"){
zoom = MyMap.getAccuracyZoom(a.accuracy);
}else if ( typeof(a.accuracy) === "undefined" ){
zoom = 7;
//TODO get accuracy depending zoom
}
if(typeof preGmapCallback !=="undefined" && preGmapCallback != null ){
preGmapCallback();
}
MyGmapInterface.myMap = new MyMap(a.lat,a.lng,zoom,MyGmapInterface.getMapContainer(),MyGmapInterface.notCompatible);
if(postGmapCallback!==null){postGmapCallback();}
}
else if(adresses.length>1){
var interaction = document.getElementById(MyGmapInterface.searchFieldInteractionId);
if(typeof interaction !== 'undefined'){
var i;
var children = interaction.childNodes;
for(i=0; i=0&&selTab<=2){
cb = function(){
MyGmapInterface.selTab = selTab;
tabSelected(selTab);
if(typeof loadTabsCallback == 'function'){
loadTabsCallback();
}
};
}
else{
cb = null;
}
loadTabs(cb);
MyGmapInterface.tabsLoaded = true;
}else{
if(selTab>=0&&selTab<=2){
MyGmapInterface.selTab = selTab;
tabSelected(selTab);
}
}
};
MyGmapInterface.setMapHeader = function (header){
var h = $("map_header");
if(h!==null){h.innerHTML = ""+header+"
";}
};
MyGmapInterface.tabClosed = function(tab){
if(typeof tab !==undefined){
var tabe;
switch(tab){
case TAB_LEFT:
tabe = $("crn_main_tabbed_main");
if(tabe!==undefined){
MyGmapInterface.TAB_L = tabe.innerHTML;
}
break;
case TAB_MIDDLE:
tabe = $("crn_main_tabbed_main");
if(tabe!==undefined){
MyGmapInterface.TAB_M = tabe.innerHTML;
}
break;
case TAB_RIGHT:
break;
}
}
};
MyGmapInterface.configureListeners = function(tab){
switch(tab){
case TAB_LEFT:
Listener.SHOWCAMS.enable();
Listener.UPDATELOCATIONHEADER.enable();
Listener.ADD_CAM_MARKER.disable();
break;
case TAB_MIDDLE:
Listener.SHOWCAMS.enable();
Listener.UPDATELOCATIONHEADER.disable();
Listener.ADD_CAM_MARKER.disable();
break;
case TAB_RIGHT:
Listener.ADD_CAM_MARKER.enable();
Listener.SHOWCAMS.disable();
Listener.UPDATELOCATIONHEADER.disable();
break;
}
if(Listener.UPDATE_LOCATIONHASH_WHENMOVED!=null){Listener.UPDATE_LOCATIONHASH_WHENMOVED.enable();}
};
MyGmapInterface.tabLoaded = function (tab){
var center;
if(typeof tab !=="undefined"){
switch(tab){
case TAB_LEFT:
MyGmapInterface.selTab = TAB_LEFT;
MyGmapInterface.addNewCamMarkers(MyGmapInterface.loadCamsResponseCache!==null?MyGmapInterface.loadCamsResponseCache:MyGmapInterface.loadCams());
MyGmapInterface.updateLocationHeader();
Listener.SHOWCAMS.enable();
Listener.UPDATELOCATIONHEADER.enable();
Listener.ADD_CAM_MARKER.disable();
if(MyGmapInterface.TAB_L===""||MyGmapInterface.TAB_L===null){
MyGmapInterface.TAB_L = MyGmapInterface.getSearchResultsHtml(0);
}
setTabContent(MyGmapInterface.TAB_L);
if(MyGmapInterface.myMap!=null){
center = MyGmapInterface.myMap.getCenter();
ROUTE_SHOW_MAP.executed(new Array(""+MyGmapInterface.myMap.getZoom(), ""+center.lat(), ""+center.lng()));
MyGmapInterface.activeRoute = ROUTE_SHOW_MAP;
}
break;
case TAB_MIDDLE:
MyGmapInterface.selTab = TAB_MIDDLE;
MyGmapInterface.addNewCamMarkers(MyGmapInterface.loadCamsResponseCache!==null?MyGmapInterface.loadCamsResponseCache:MyGmapInterface.loadCams());
if(""===MyGmapInterface.TAB_M){
/*click on one marker to cause a callback that shows a camera*/
for(var cId in MyGmapInterface.camMarkersById){
if(MyGmapInterface.camMarkersById.hasOwnProperty(cId)){
MyGmapInterface.avoidTabChange = true;
GEvent.trigger(MyGmapInterface.camMarkersById[cId],"click");
MyGmapInterface.avoidTabChange = false;
break;
}
}
}
if(MyGmapInterface.thisCamTitle!==null&&MyGmapInterface.thisCamTitle!==""){MyGmapInterface.setMapHeader(MyGmapInterface.thisCamTitle);}
Listener.SHOWCAMS.enable();
Listener.UPDATELOCATIONHEADER.disable();
Listener.ADD_CAM_MARKER.disable();
setTabContent(MyGmapInterface.TAB_M);
break;
case TAB_RIGHT:
MyGmapInterface.selTab = TAB_RIGHT;
MyGmapInterface.setMapHeader("Danke für das Hinzufügen neuer Webcams");
MyGmapInterface.myMap.removeAllMarkers();
Utils.addCSS("http://www.camnetwork.org/newcam.css");
var content = eval("(" + RequestCache.getRequest("GET","http://www.camnetwork.org/de/newcam1.js","",null) + ")");
setTabContent(content.content);
Listener.ADD_CAM_MARKER.enable();
Listener.SHOWCAMS.disable();
Listener.UPDATELOCATIONHEADER.disable();
break;
}
if(Listener.UPDATE_LOCATIONHASH_WHENMOVED!=null){Listener.UPDATE_LOCATIONHASH_WHENMOVED.enable();}
}
};
MyGmapInterface.getSearchResultsHtml = function(page){
if(MyGmapInterface.searchResults===null){
MyGmapInterface.loadCams();
}
if(typeof MyGmapInterface.searchResults[page] == 'undefined'){
/*no search results found*/
return 'Es gibt leider noch keine Kameras in diesem Gebiet.
Um Kameras angezeigt zu bekommen, muss der Zoom verringert oder die Karte verschoben werden.
';
}
return MyGmapInterface.searchResults[page];
};
MyGmapInterface.updateLocationHeader = function(){
var geocoder = MyMap.getGeocoder();
geocoder.getLocations(MyGmapInterface.myMap.getCenter(), function(response){
var prefix = "Die besten Webcams in ";
if (!response || response.Status.code != 200) {
//Fehler
if(MyGmapInterface.userInput===""){
MyGmapInterface.setMapHeader("Webcams weltweit!");
}else{
MyGmapInterface.setMapHeader(prefix + userInput);
}
}else{
var placename = "";
var i;
var country;
var city;
var county;
for(i=0; i11){
//STADT
// placename = placemark.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
placename = city;
}else if(zoom>7 && typeof(placemark.AddressDetails.Country.AdministrativeArea) != 'undefined'){
//BUNDESLAND
// placename = placemark.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
placename = county;
}
else if(zoom>4 && typeof(placemark.AddressDetails.Country) != 'undefined'){
//LAND
placename = country;
}
if(typeof(placename) != 'undefined' && placename !== "" && placename !== null){
MyGmapInterface.setMapHeader(prefix+placename);
}
else{
//WELT
MyGmapInterface.setMapHeader("Webcams weltweit!");
}
}
});
};
MyGmapInterface.userLocSearch = function (location, search_interaction_id){
MyGmapInterface.userInput = location;
if(typeof search_interaction_id !== 'undefined'){
MyGmapInterface.searchFieldInteractionId = search_interaction_id;
}
var preGmapCallback = function(){
MyGmapInterface.preparePage(TAB_LEFT);
};
var postGmapCallback = function(){
MyGmapInterface.initListeners();
if(MyGmapInterface.myMap!=null){
center = MyGmapInterface.myMap.getCenter();
ROUTE_SHOW_MAP.executed(new Array(""+MyGmapInterface.myMap.getZoom(), ""+center.lat(), ""+center.lng()));
MyGmapInterface.activeRoute = ROUTE_SHOW_MAP;
}
addTabSelectedCallback(MyGmapInterface.tabLoaded);
addTabClosedCallback(MyGmapInterface.tabClosed);
MyGmapInterface.tabLoaded(TAB_LEFT);
};
MyGmapInterface.initLocation(location, preGmapCallback, postGmapCallback, -1 );
return false;
};
MyGmapInterface.userNewCamSearch = function (location, search_interaction_id){
MyGmapInterface.userInput = location;
if(typeof search_interaction_id !== 'undefined'){
MyGmapInterface.searchFieldInteractionId = search_interaction_id;
}
var preGmapCallback = function(){
MyGmapInterface.preparePage(TAB_RIGHT);
};
var postGmapCallback = function(){
MyGmapInterface.initListeners();
addTabSelectedCallback(MyGmapInterface.tabLoaded);
addTabClosedCallback(MyGmapInterface.tabClosed);
MyGmapInterface.tabLoaded(TAB_RIGHT);
};
MyGmapInterface.initLocation(location, preGmapCallback, postGmapCallback, 12 );
return false;
};
MyGmapInterface.showcomments = function(camId,start,limit){
var center;
if(MyGmapInterface.myMap!=null && MyGmapInterface.thisCamTitle!=null){
center = MyGmapInterface.myMap.getCenter();
ROUTE_SHOW_COMMENTS.executed(new Array(""+camId,center.lat(),center.lng(),MyGmapInterface.myMap.getZoom(),Math.floor(start/limit+1),MyGmapInterface.thisCamTitle));
MyGmapInterface.activeRoute = ROUTE_SHOW_COMMENTS;
}
var content = eval("(" + RequestCache.getRequest("POST","http://www.camnetwork.org/getComments.js","cam="+camId,null) + ")");
if(content.length===0){
//no comments show create comment
setTabContent("
");
window.setTimeout(function(){
MyGmapInterface.createCommentRedirect(4);
}, 1000);
}else{
//show comments
content.sort(function(a,b){
if(a.dateZurück zur Kamera';
setTabContent(cont);
}
};
MyGmapInterface.showcreateComment = function (){
var content = RequestCache.getRequest("GET","http://www.camnetwork.org/de/newCommentForm.js","",null);
var date = new Date().getTime();
date = date - Math.floor((Math.random() * 10000) + 1);
setTabContent(content);
$("comment_captcha_img").src = "http://www.camnetwork.org/captcha_"+date+".png";
$("comments_cid").value=date;
//$("comment_ip").innerHTML = RequestCache.getRequest("POST","http://www.camnetwork.org/singleVariables.js","var=ip",null);
var t = new TextareaControl($("ncomment_com"),500,$("comment_char_counter"));
if(MyGmapInterface.myMap!=null && MyGmapInterface.thisCamTitle!=null && MyGmapInterface.thisCamId!=0){
$('comments_back_to_cam_link').setAttribute( 'onclick','MyGmapInterface.showThisCam( '+MyGmapInterface.thisCamId+' ); return false;');
$('comments_back_to_cam_link2').setAttribute('onclick','MyGmapInterface.showThisCam( '+MyGmapInterface.thisCamId+' ); return false;');
center = MyGmapInterface.myMap.getCenter();
ROUTE_CREATE_COMMENT.executed(new Array(""+MyGmapInterface.thisCamId,center.lat(),center.lng(),MyGmapInterface.myMap.getZoom(),MyGmapInterface.thisCamTitle));
MyGmapInterface.activeRoute = ROUTE_CREATE_COMMENT;
}
};
MyGmapInterface.createCommentRedirect = function(timer){
if(timer>0){
$("comment_info_timer").innerHTML = timer;
window.setTimeout(function(){
MyGmapInterface.createCommentRedirect(timer-1);
}, 1000);
}else{
MyGmapInterface.showcreateComment();
}
};
MyGmapInterface.createNewComment = function (commentForm){
if(typeof(commentForm)==="object"&&commentForm.tagName.toLowerCase() === "form"){
var nick = $("ncomment_name").value;
var comment = $("ncomment_com").value;
var captcha = $("ncomment_cap").value;
var cid = $("comments_cid").value;
var errcode = 0;
var email = '';
var subscribe=$("ncomment_subscribe").value=='on';
if($('ncomment_subscribe').checked == true){
email = $('ncomment_email').value;
}
if(nick.length>15){errcode|=4;}
if(comment.length>500){errcode|=16;}
if(captcha.length===0){errcode|=32;}
if(nick.length===0){errcode|=2;}
if(comment.length===0){errcode|=8;}
if(errcode!==0){
MyGmapInterface.createNewCommentError(errcode);
}else{
var send = "id="+MyGmapInterface.thisCamId+"&n="+nick+"&c="+comment+"&cco="+captcha+"&cid="+cid+'&eml='+email+"&subscribe="+subscribe;
var response = request("POST","http://www.camnetwork.org/newcomment.js",send,null);
var requ = eval("("+response+")");
if(requ.status==0){
//success
RequestCache.getRequest("POST","http://www.camnetwork.org/getComments.js","cam="+MyGmapInterface.thisCamId,null,true);
MyGmapInterface.showcomments(MyGmapInterface.thisCamId,1,5);
}else{
MyGmapInterface.createNewCommentError(parseInt(requ.status,10));
}
}
}
};
MyGmapInterface.createNewCommentError = function(errCode){
var errEl = $('comments_form_err');
var errMsg = "";
if( (errCode&64) > 0){
errMsg += "Leider wurde ein ungültiger Captcha-Code eingegeben
";
}
if( (errCode&2) > 0){
errMsg += "Bitte geben Sie einen Namen an
";
}
if( (errCode&8) > 0){
errMsg += "Bitte geben Sie einen Kommentar ein
";
}
if( (errCode&15) > 0){
errMsg += "Der angegebene Nickname ist zu lang.
";
}
if( (errCode&32) > 0){
errMsg += "Bitte geben Sie einen Captcha Code ein
";
}
if(errMsg == ""){
errMsg = "Es ist ein unerwarteter Fehler aufgetreten, wir bitten dies zu entschuldigen.";
}
$("comment_captcha_img").src+="?date="+new Date().getTime();
errEl.innerHTML = errMsg;
};
Newcam = function(){};
Newcam.lat = null;
Newcam.lng = null;
Newcam.title = null;
Newcam.desc = null;
Newcam.url = null;
Newcam.id = new Date().getTime();
Newcam.cp = null;
Newcam.isForm1Done = false;
Newcam.isForm2Done = false;
Newcam.handleform1 = function(form){
if(Newcam.lat===null||Newcam.lng===null){
Userinterface.message('Bitte markiere zuerst Deine Webcam auf der Karte.');
}else{
var e = form.elements;
var t_err = false;
var d_err = false;
var u_err = false;
var msg = "";
var title;
var desc;
var url;
for(var i=0;i < e.length;i++){
if(e[i].id==="nc_title"){
title = e[i].value;
if(title===""||title==="Titel der neuen Kamera"){
t_err = true;
msg=msg+(msg===""?"":"\n");
msg+='Bitte gib einen Titel für Deine Webcam an.';
}
}
if(e[i].id==="nc_desc"){
desc = e[i].value;
if(desc===""||desc.indexOf('Wer betreibt die Kamera?')===0){
d_err = true;
msg=msg+(msg===""?"":"\n");
msg+='Bitte gib eine Beschreibung deiner Webcam an.';
}
}
if(e[i].id==="nc_url"){
url = e[i].value;
if(url===""||url==="Link zur Kamera-Webseite"){
u_err = true;
msg=msg+(msg===""?"":"\n");
msg+='Bitte gib den Link zur Webseite zu Deiner Webcam an.';
}
}
}
if(t_err||d_err||u_err){
Userinterface.message(msg);
}else{
//success
Newcam.title = title;
Newcam.desc = desc;
Newcam.url = url;
Newcam.isForm1Done = true;
var content = eval("(" + RequestCache.getRequest("POST","http://www.camnetwork.org/de/newcam2.js","cp_id="+Newcam.id,null) + ")");
setTabContent(content.content);
}
}
return false;
};
Newcam.handleform2 = function(form){
if(Newcam.isForm1Done){
var msg = "";
var captcha;
var err_agb = false;
var err_owner = false;
var err_cp = false;
var e = form.elements;
for(var i=0;i < e.length;i++){
if(e[i].id==="nc_agb"){
if(e[i].checked!==true){
err_agb = true;
msg=msg+(msg===""?"":"\n");
msg+='Bitte bestätige die AGB um fortzufahren.';
}
}
if(e[i].id==="nc_owner"){
if(e[i].checked!==true){
err_owner = true;
msg=msg+(msg===""?"":"\n");
msg+='Du darfst Webcams nur als Kamera-Betreiber eintragen. Wenn du der Betreiber dieser Kamera bist setze bitte den Harken in der Checkbox.';
}
}
if(e[i].id==="nc_captcha_code"){
captcha = e[i].value;
if(captcha===""){
err_cp = true;
msg=msg+(msg===""?"":"\n");
msg+='Bitte übertrage die Buchstaben des Captchabilds in das Textfeld darunter. Das ist notwendig um automatisiertes Eintragen durch PC-Programme zu vermeiden. Danke!';
}
}
}
if(err_agb||err_owner||err_cp){
Userinterface.message(msg);
}else{
//success
var removeLinkToCameras = false;
Newcam.cp = captcha;
var snd = "nc_lat="+Newcam.lat+
"&nc_lng="+Newcam.lng+
"&nc_title="+Newcam.title+
"&nc_desc="+Newcam.desc+
"&nc_url="+Newcam.url+
"&nc_captcha="+Newcam.cp+
"&nc_id="+Newcam.id;
var requ = request("POST","http://www.camnetwork.org/de/addcam.js",snd,null);
var re = eval("("+requ+")");
if(re.status===1){
//success
Newcam.isForm2Done = true;
var content = eval("(" + RequestCache.getRequest("POST","http://www.camnetwork.org/de/newcam3.js","cp_id="+Newcam.id,null) + ")");
setTabContent(content.content);
if(MyGmapInterface.searchResults===null){
MyGmapInterface.loadCams();
if(typeof MyGmapInterface.searchResults[0] == 'undefined'){
removeLinkToCameras = true;
}
}
if(removeLinkToCameras){
$('tab_newcam_submitt_backto_cam').style.display = 'none';
}
}else if(re.status===2){
//wrong captcha code
Userinterface.message('Sorry, Du hast einen ungültigen Captchacode eingebeben. Bitte versuch es nochmal.');
Newcam.reloadCaptcha();
}
}
}
else{
Userinterface.message('Es ist ein unerwarteter Fehler aufgetreten. Der Eintragevorgang wird zurückgesetzt. Sollte es beim zweiten Versuch immernoch Probleme geben informieren Sie uns doch bitte darüber und wir kümmern uns drum.');
var content = eval("(" + RequestCache.getRequest("GET","http://www.camnetwork.org/de/newcam1.js","",null) + ")");
setTabContent(content.content);
Newcam.lat = null;
Newcam.lng = null;
Newcam.title = null;
Newcam.desc = null;
Newcam.url = null;
Newcam.isForm1Done = false;
Newcam.id = new Date().getTime();
}
};
Newcam.setLag = function (lat){Newcam.lat = lat;};
Newcam.setLng = function (lng){Newcam.lng = lng;};
Userinterface = function(){};
Newcam.reloadCaptcha = function(id){
if(typeof id == 'undefined'){
var c = $("nc_captcha");
}else{
var c = $(id);
}
if(c){
c.src = "http://www.camnetwork.org/captcha_"+Newcam.id+".png?date="+new Date().getTime();
}
};
Userinterface.message = function(msg){
alert(msg);
};
MyGmapInterface.activeRoute = null;
if(typeof PrefixedRouterConfig == "function"){
/*A router exists*/
var config = new PrefixedRouterConfig('show_webcam',new Array("\\d+", "-?\\d+(?:\\.\\d+)?", "-?\\d+(?:\\.\\d+)?","\\d+",".+?"));
var ROUTE_SHOW_CAM = new Route(
function(params){
MyGmapInterface.activeRoute = ROUTE_SHOW_CAM;
var camId = params[0];
MyGmapInterface.thisCamId = params[0];
var lat = params[1];
var lng = params[2];
var zoom = params[3];
var sendData = "camId="+camId;
MyGmapInterface.thisCamTitle = params[4];
document.title = 'Webcam - '+params[4];
MyGmapInterface.preparePage(TAB_MIDDLE, function(){
MyGmapInterface.selTab = TAB_MIDDLE;
addTabSelectedCallback(MyGmapInterface.tabLoaded);
addTabClosedCallback(MyGmapInterface.tabClosed);
MyGmapInterface.myMap = new MyMap(lat,lng,zoom,MyGmapInterface.getMapContainer(),MyGmapInterface.notCompatible);
MyGmapInterface.addNewCamMarkers(MyGmapInterface.loadCams());
MyGmapInterface.initListeners();
MyGmapInterface.configureListeners(TAB_MIDDLE);
MyGmapInterface.showThisCam(camId);
});
//MyGmapInterface.TAB_M = RequestCache.getRequest('POST',"http://www.camnetwork.org/de/thiscam.js",sendData,null);
},
config.getParams,
config.getIdentifier,
config.contains
);
ROUTE_SHOW_CAM.register();
config = new PrefixedRouterConfig('show_comments',new Array("\\d+", "-?\\d+(?:\\.\\d+)?", "-?\\d+(?:\\.\\d+)?","\\d+","\\d+",".+?"));
var ROUTE_SHOW_COMMENTS = new Route(
function(params){
MyGmapInterface.activeRoute = ROUTE_SHOW_COMMENTS;
var limit = 5;
var camId = params[0];
MyGmapInterface.thisCamId = params[0];
var lat = params[1];
var lng = params[2];
var zoom = params[3];
var start = (params[4]-1)*limit+1;
/* Ensures the wrapper for the google map and the tabs are avialable
* */
MyGmapInterface.preparePage(TAB_MIDDLE, function(){
/*After the tab has been selected by the program user events can be awaited*/
addTabSelectedCallback(MyGmapInterface.tabLoaded);
addTabClosedCallback(MyGmapInterface.tabClosed);
});
/*Initialize the map at the given position*/
MyGmapInterface.myMap = new MyMap(lat,lng,zoom,MyGmapInterface.getMapContainer(),MyGmapInterface.notCompatible);
/*creates disabled objects for the listeners that interact with map-events*/
MyGmapInterface.initListeners();
MyGmapInterface.configureListeners(TAB_MIDDLE);
MyGmapInterface.addNewCamMarkers(MyGmapInterface.loadCams());
/*Set the camera id and teh page title which might be overwritten by setCamMarkerActive*/
MyGmapInterface.thisCamId = camId;
MyGmapInterface.thisCamTitle = params[5];
document.title = 'Webcam - '+params[5];
/*This function only sets the camera id and the camera title to the gmap interface if the marker is visible*/
MyGmapInterface.setCamMarkerActive(camId);
/*Changes the tab content to display the comments, and fires a router event*/
MyGmapInterface.showcomments(camId,start,limit);
},
config.getParams,
config.getIdentifier,
config.contains
);
ROUTE_SHOW_COMMENTS.register();
config = new PrefixedRouterConfig('create_comment',new Array("\\d+", "-?\\d+(?:\\.\\d+)?", "-?\\d+(?:\\.\\d+)?","\\d+",".+?"));
var ROUTE_CREATE_COMMENT = new Route(
function(params){
MyGmapInterface.activeRoute = ROUTE_CREATE_COMMENT;
var limit = 5;
var camId = params[0];
MyGmapInterface.thisCamId = params[0];
var lat = params[1];
var lng = params[2];
var zoom = params[3];
MyGmapInterface.thisCamId = camId;
MyGmapInterface.thisCamTitle = params[4];
document.title = 'Webcam - '+params[4];
MyGmapInterface.preparePage(TAB_MIDDLE, function(){
addTabSelectedCallback(MyGmapInterface.tabLoaded);
addTabClosedCallback(MyGmapInterface.tabClosed);
});
MyGmapInterface.myMap = new MyMap(lat,lng,zoom,MyGmapInterface.getMapContainer(),MyGmapInterface.notCompatible);
MyGmapInterface.initListeners();
MyGmapInterface.configureListeners(TAB_MIDDLE);
MyGmapInterface.showcreateComment();
//TODO use api v3 and a callback to ensure the bounds of the map are already loded - I had a race condition in chrome
window.setTimeout(function(){
MyGmapInterface.addNewCamMarkers(MyGmapInterface.loadCams());
MyGmapInterface.setCamMarkerActive(camId);
},1500);
},
config.getParams,
config.getIdentifier,
config.contains
);
ROUTE_CREATE_COMMENT.register();
config = new PrefixedRouterConfig('show_map',new Array("\\d+", "-?\\d+(?:\\.\\d+)?", "-?\\d+(?:\\.\\d+)?"));
var ROUTE_SHOW_MAP = new Route(
function(params){
var zoom = params[0];
var lat = params[1];
var lng = params[2];
MyGmapInterface.preparePage(TAB_LEFT, function(){
addTabSelectedCallback(MyGmapInterface.tabLoaded);
addTabClosedCallback(MyGmapInterface.tabClosed);
MyGmapInterface.tabsLoaded = true;
MyGmapInterface.myMap = new MyMap(lat,lng,zoom,MyGmapInterface.getMapContainer(),MyGmapInterface.notCompatible);
MyGmapInterface.addNewCamMarkers(MyGmapInterface.loadCams());
MyGmapInterface.initListeners();
MyGmapInterface.configureListeners(TAB_LEFT);
MyGmapInterface.tabLoaded(TAB_LEFT);
});
},
config.getParams,
config.getIdentifier,
config.contains
);
ROUTE_SHOW_MAP.register();
}
//debug code:
function debug(){
MyGmapInterface.userLocSearch("Marburg");
window.setTimeout(function(){
alert('debug start');
var DEBUG_LISTENER = new Listener(MyGmapInterface.myMap,"click",function(overlay, latlng,overlaylatlng){
alert('zoom:'+MyGmapInterface.myMap.getZoom());
alert('lat: '+latlng.lat()+'lng: '+latlng.lng());
});
DEBUG_LISTENER.enable();
alert('ok');
}, 5000 );
}
'+(comment.abuse?"???":comment.nick)+'
: '+(comment.abuse?'Dieser Kommentare wurde als Spam gemeldet. Er wird versteckt bis ihn ein Admin gelöscht oder entsperrt hat.':comment.comment)+'