
//* Convenience DOM-Functions
function $(n, index, element, specification, state) {
/* Valid State Provided */
if(typeof(state) == 'string')
return $(n + '[' + index + ']', element, specification, state);
/* Valid Specification Provided */
if(typeof(specification) == 'string')
return $(n + '[' + index + ']', element, specification);
/* Valid Element Provided */
if(typeof(element) == 'string')
return $(n + '[' + index + ']', element);
/* Only Node Provided */
if(typeof(index) == 'undefined') {
if(typeof(n) == 'object')
return n;
if(typeof(n) != 'string')
return null;
return document.getElementById(n);
}
/* Valid Index Provided */
return $(n + '[' + index + ']');
}
function $_REVERSE(node) {
var n = $(node);
// Substract Values
var a = n.id.replace(/]/g, '').split('[');
// Return Value
var r = {};
r['n'] = a[0];
r['index'] = a[1];
r['element'] = a[2];
r['specification'] = a[3];
return r;
}
function $_EXIST(n, index, element, specification, state) {
return $(n, index, element, specification, state) != null;
}
function $Element(n, classname) {
var e = document.createElement(n);
if(classname)
e.className = classname;
return e;
}
function $Text(n, style) {
if(style != undefined) {
var span = $Span();
for(s in style)
span.style[s] = style[s];
span.appendChild(document.createTextNode(n));
return span;
}
else
return document.createTextNode(n);
}
function $Div(classname, width) {
var e = $Element('div', classname);
if(width != undefined)
e.style.width = width + 'px';
return e;
}
function $Span(classname, width) {
var e = $Element('span', classname);
if(width != undefined)
e.style.width = width + 'px';
return e;
}
function $Img(src, classname, width, height) {
var e = $Element('img', classname);
e.src = src;
if(width)
e.style.width = width + 'px';
if(height)
e.style.height = height + 'px';
return e;
}
function $Table(classname) {
return $Element('table', classname);
}
function $Tr(classname) {
return $Element('tr', classname);
}
function $Td(classname, colspan, width) {
var e = $Element('td', classname);
if(colspan)
e.colSpan = colspan;
if(width)
e.style.width = width + 'px';
return e;
}
function $Link(url, content, target, classname, title) {
var a = $Element('a', classname);
a.href = url;
if(target)
a.target = target;
if(typeof(content) == 'object')
a.appendChild(content);
else
a.appendChild($Text(content));
if(title)
a.setAttribute('title', title);
return a;
}
function setClass(e, classname, exclusive) {
e = $(e);
if(!e)
return;
exclusive = (exclusive == undefined) ? false : exclusive;
if(exclusive == true) {
e.className = classname;
return;
}
var cn = e.className.split(' ');
if(cn.indexOf(classname) != -1)
return;
cn.push(classname);
e.className = cn.join(' ');
}
function unsetClass(e, classname) {
e = $(e);
if(!e)
return;
var cn = e.className.split(' ');
var i = cn.indexOf(classname);
if(i == -1)
return;
cn.splice(i, 1);
e.className = cn.join(' ');
}
function display(node, type) {
var n = $(node);
if(!n)
return;
n.style.display = type;
}
function toggle_display(node, type_on, type_off) {
var n = $(node);
if(!n)
return;
if(n.style.display == type_on)
n.style.display = type_off;
else if(n.style.display == type_off)
n.style.display = type_on;
}
function show(node, optional_index) {
unsetClass($(node, optional_index), 'hide');
}
function hide(node, optional_index) {
setClass($(node, optional_index), 'hide');
}
function isHidden(node) {
return hasClass(node, 'hide');
}
function clear(node) {
var n = $(node);
if(!n)
return;
while(n.firstChild)
n.removeChild(n.firstChild)
}
function setText(node, s, style) {
clear(node);
if(typeof(s) != 'string')
return;
$(node).appendChild($Text(s, style));
}
function resetForm(node) {
var n = $(node);
if(!n)
return;
n.reset();
}
function getText(node) {
var n = $(node);
if(!n)
return '';
if(node.innerText)
return node.innerText;
if(node.textContent)
return node.textContent;
return '';
}
function nextNode(node, name) {
if(node == null)
return null;
var x = node.nextSibling;
while(x != null) {
if(x.nodeName.toLowerCase() == name)
return x;
x = x.nextSibling;
}
return null;
}
function getMaxHeight(node) {
var n = $(node);
if(!n)
return 0;
var posy = n.offsetTop;
while((n = n.offsetParent) != null)
posy += n.offsetTop;
var innerHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
return (innerHeight - posy);
}
function maximizeElement(name, offset) {
var height = getMaxHeight(name) + offset;
$(name).style.height = height + 'px';
}
function swap_visibility(hide, show) {
display(hide, 'none');
display(show, '');
}
function getAbsolutePosition(node) {
var n = $(node);
var pos = {x: 0, y: 0};
pos.x = n.offsetLeft;
pos.y = n.offsetTop;
while((n = n.offsetParent) != null) {
pos.x += n.offsetLeft;
pos.y += n.offsetTop;
}
return pos;
}
function getDimension(node) {
var dim = { topleft: {x: 0, y: 0}, bottomright: {x: 0, y: 0}};
dim.topleft = getAbsolutePosition(node);
dim.bottomright.x = dim.topleft.x + node.offsetWidth;
dim.bottomright.y = dim.topleft.y + node.offsetHeight;
return dim;
}
function getRelativePosition(child, parent) {
var cpos = this.getAbsolutePosition(child);
var ppos = this.getAbsolutePosition(parent);
var pos = {x: 0, y: 0};
pos.x = cpos.x - ppos.x;
pos.y = cpos.y - ppos.y;
return pos;
}
function getPageDimension() {
var dim = {x: 0, y: 0};
if (document.body.scrollHeight > document.body.offsetHeight) {
dim.x = document.body.scrollWidth;
dim.y = document.body.scrollHeight;
}
else {
dim.x = document.body.offsetWidth;
dim.y = document.body.offsetHeight;
}
return dim;
}
function getInnerDimension() {
var dim = {x: 0, y: 0};
if (self.innerHeight) {
dim.x = self.innerWidth;
dim.y = self.innerHeight;
}
else if(document.documentElement && document.documentElement.clientHeight) {
dim.x = document.documentElement.clientWidth;
dim.y = document.documentElement.clientHeight;
}
else if(document.body) {
dim.x = document.body.clientWidth;
dim.y = document.body.clientHeight;
}
return dim;
}
//* AJAX Toolkit
//* Copyright 2006 OPAG Online Promotion AG
function AJAX(url, callback, data, sync) {
this.sync = sync || false;
if(window.ActiveXObject)
this.request = new ActiveXObject('Microsoft.XMLHTTP');
else
this.request = new XMLHttpRequest();
if(this.sync == false) {
this.request.open('POST', url + '?rand=' + Math.random(), true);
var a = this;
this.request.onreadystatechange = function() {
var r = a.request;
if(r.readyState == 4) {
try { a.ontransferend(); } catch(e) {}
if(r.status == 200)
a.callback(a.parseJSON(r.responseText), a.data);
else
a.callback(null, a.data);
}
};
}
else
this.request.open('POST', url + '?rand=' + Math.random(), false);
this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
if(callback)
this.callback = callback;
else
this.callback = this.success;
this.data = data;
this.parameter = '';
}
AJAX.prototype.success = function(s, d) {
alert(s);
}
AJAX.prototype.parseJSON = function(text) {
if(text.length == 0)
return null;
var rex = /[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/
var reprex = /"(\\.|[^"\\])*"/g
if(rex.test(text.replace(reprex, '')) == true)
return null;
var obj;
try {
obj = eval('(' + text + ')');
}
catch(e) {
obj = null;
}
return obj;
}
AJAX.prototype.setParameter = function(parameter, value) {
this.parameter = this.parameter + '&' + encodeURIComponent(parameter) + '=' + encodeURIComponent(value);
}
AJAX.prototype.setForm = function(fid) {
var f = document.getElementById(fid);
if(!f)
return;
var p = '';
for(var i = 0; i < f.elements.length; i++) {
switch(f.elements[i].type) {
case 'hidden':
case 'text':
case 'password':
case 'textarea':
p = p + '&' + encodeURIComponent(f.elements[i].name) + '=' + encodeURIComponent(f.elements[i].value);
break;
case 'checkbox':
case 'radio':
if(f[i].checked)
p = p + '&' + encodeURIComponent(f.elements[i].name) + '=' + encodeURIComponent(f.elements[i].value);
break;
case 'select-one':
p = p + '&' + encodeURIComponent(f.elements[i].name) + '=' + encodeURIComponent(f.elements[i].value);
break;
case 'select-multiple':
for(var j = 0; j < f.elements[i].options.length; j++) {
if(f.elements[i].options[j].selected)
p = p + '&' + encodeURIComponent(f.elements[i].name) + '=' + encodeURIComponent(f.elements[i].options[j].value);
}
break;
case 'button':
case 'submit':
case 'reset':
default:
break;
}
}
this.parameter = this.parameter + p;
}
AJAX.prototype.send = function() {
try { this.ontransferstart(); } catch(e) {}
this.request.send('utf8=ä' + this.parameter);
if(this.sync == false)
return;
if(this.request.status == 200) {
try { this.ontransferend(); } catch(e) {}
return this.parseJSON(this.request.responseText);
}
try { this.ontransferend(); } catch(e) {}
return null;
}
AJAX.prototype.ontransferstart = function() {}
AJAX.prototype.ontransferend = function() {}
function set_position_text(id, point) {
var deg = get_degrees(point);
setText(id, deg.lat + ' ' + deg.lng);
}
function get_degrees(center) {
var lat = center.lat();
var lng = center.lng();
var deg = new Object();
// Latitude
var sign = (lat > 0 ? 'N' : 'S');
lat = Math.abs(lat);
var degrees = Math.floor(lat);
var minutes = Math.floor((lat - degrees) * 60);
var seconds = Math.floor(((lat - degrees) * 60 - minutes) * 60);
deg.lat = degrees + '°' + minutes + '\' ' + seconds + '" ' + sign;
// Longitude
sign = (lng > 0 ? 'E' : 'W');
lng = Math.abs(lng);
degrees = Math.floor(lng);
minutes = Math.floor((lng - degrees) * 60);
seconds = Math.floor(((lng - degrees) * 60 - minutes) * 60);
deg.lng = degrees + '°' + minutes + '\' ' + seconds + '" ' + sign;
return deg;
}
function get_icon(type, webcamid) {
if(typeof(type) == 'undefined')
type = 'marker';
if(typeof(webcamid) == 'undefined')
webcamid = '';
var icon = new GIcon();
if(type == 'bubble') {
icon.image = '/img/marker_bubble.png';
icon.shadow = '';
icon.iconSize = new GSize(28, 28);
icon.shadowSize = new GSize(0, 0);
icon.iconAnchor = new GPoint(14, 14);
icon.infoWindowAnchor = new GPoint(14, 0);
}
else if(type == 'icon') {
icon.image = 'http://images.webcams.travel/icon/' + webcamid + '.png';
icon.shadow = '';
icon.iconSize = new GSize(32, 32);
icon.shadowSize = new GSize(0, 0);
icon.iconAnchor = new GPoint(16, 16);
icon.infoWindowAnchor = new GPoint(16, 0);
}
else if(type == 'position') {
icon.image = '/img/map/position.png';
icon.shadow = '';
icon.iconSize = new GSize(70, 69);
icon.shadowSize = new GSize(0, 0);
icon.iconAnchor = new GPoint(35, 34);
icon.infoWindowAnchor = new GPoint(35, 0);
}
else {
icon.image = '/img/marker.png';
icon.shadow = '';
icon.iconSize = new GSize(20, 34);
icon.shadowSize = new GSize(0, 0);
icon.iconAnchor = new GPoint(9, 34);
icon.infoWindowAnchor = new GPoint(9, 2);
}
return icon;
}
var _places = new Array();
var _map = null;
var _marker = null;
function load() {
if(_loadmap && GBrowserIsCompatible()) {
_map = new GMap2(document.getElementById("map"));
_map.setCenter(new GLatLng(20.0, 0.0), 1);
_map.addMapType(G_PHYSICAL_MAP);
_map.addControl(new GHierarchicalMapTypeControl());
_map.addControl(new GSmallMapControl());
GEvent.addListener(_map, 'click', function(overlay, point) {
if(overlay)
return;
if(_marker == null) {
_marker = new GMarker(point, {icon: get_icon(), clickable: false, draggable: true});
GEvent.addListener(_marker, 'drag', function() { set_position_text('map_position', _marker.getLatLng()); });
GEvent.addListener(_marker, 'dragend', function() { set_position_text('map_position', _marker.getLatLng()); });
_map.addOverlay(_marker);
set_position_text('map_position', _marker.getLatLng());
}
else {
_marker.setLatLng(point);
set_position_text('map_position', _marker.getLatLng());
}
});
$('find_place').onkeydown = function(e) {
if(!e)
e = window.event;
var key = null;
if(e.which)
key = e.which;
else
key = e.keyCode;
if(key == 10 || key == 13)
find_place();
return;
}
}
}
function unload() {
if(_loadmap)
GUnload();
}
function add_webcam() {
$('add_webcam').setAttribute('disabled', 'true');
display('add_webcam_error', 'none');
display('add_webcam_ok', 'none');
display('add_webcam_busy', '');
var a = new AJAX('/ajax/addwebcam.php', function(response, data) {
display('add_webcam_busy', 'none');
if(response == null) {
var n = $('add_webcam_error');
clear(n);
n.appendChild($Text('There was a problem saving your webcam. Please try again later.'));
display(n, '');
$('add_webcam').removeAttribute('disabled');
return;
}
if(response.status == 200) {
display('add_webcam', 'none');
display('add_webcam_ok', '');
return;
}
else {
var n = $('add_webcam_error');
clear(n);
for(var i = 0; i < response.errors.length; i++) {
n.appendChild($Text(response.errors[i]));
n.appendChild($Element('br'));
}
display(n, '');
$('add_webcam').removeAttribute('disabled');
return;
}
}, null, false);
a.setParameter('webcam[title]', $('webcam_title').value);
a.setParameter('webcam[image]', $('webcam_image').value);
a.setParameter('webcam[page]', $('webcam_page').value);
a.setParameter('webcam[description_en]', $('webcam_description_en').value);
a.setParameter('webcam[description_native]', $('webcam_description_native').value);
if(_marker != null) {
a.setParameter('webcam[lat]', _marker.getLatLng().lat());
a.setParameter('webcam[lng]', _marker.getLatLng().lng());
}
a.setParameter('webcam[owner]', $('webcam_owner').checked == true ? $('webcam_owner').value : '');
a.send();
}
function find_place() {
var n = $('find_place');
var place = n.value;
if(place.length == 0)
return;
display('find_place_none', 'none');
display('find_place_results', 'none');
display('find_place_loading', '');
var a = new AJAX('/ajax/findplace.php', function(response, data) {
display('find_place_loading', 'none');
display_places(response);
return;
}, null, false);
a.setParameter('p', place);
a.send();
}
function center_place(p) {
var place = _places[p];
var zoom = 13;
if(place.fcl == 'A')
zoom = 6;
_map.setCenter(new GLatLng(place.lat, place.lng), zoom);
}
function display_places(places) {
var n = $('find_place_results');
if(places == null) {
display('find_place_none', '');
return;
}
if(places.totalResultsCount == 0) {
display('find_place_none', '');
return;
}
clear(n);
display(n, '');
_places = new Array();
var text = '';
var link = null;
var place = null;
for(var i = 0; i < places.geonames.length; i++) {
place = places.geonames[i];
if(place.fcl == 'A') {
text = place.name + ' (' + place.countryCode + ')';
}
else {
text = place.name + ' (';
if(place.adminName1)
text = text + place.adminName1 + ', ';
text = text + place.countryName + ')';
}
link = $Link('javascript: center_place(' + _places.length + ')', text);
n.appendChild(link);
n.appendChild($Element('br'));
_places.push(place);
}
if(_places.length == 1)
center_place(0);
}
