function isValidURL(url) {
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(url))
      return false;
    return true;
} 

function isValidURL2(url){
  if (/^w+([.-]?w+)*.w+([.-]?w+)*(.w{2,3})+$/.test(url))
    return true;
  else
    return false;
}


function getemail() {
  s = 'mailto:';
  s += 'snow';
  s += '@';
  s += 'barratt.c';
  s += 'om.au';
  document.location.href = s;
}

function getObjectClass(obj)
{
    if (obj && obj.constructor && obj.constructor.toString)
    {
        var arr = obj.constructor.toString().match(/function\s*(\w+)/);
        return arr && arr.length == 2 ? arr[1] : undefined;
    }
    else
    {
        return undefined;
    }
}

function getQueryString() {
  var args = new Object();
  // Get Query String
  //var query = location.search.substring(1);
  var t = ('' + location).replace(/&amp;#38;/g, '&');  // Fix broken textile links
  t = t.replace(/&#38;/g, '&');  // Fix broken textile links
  var pos = t.indexOf('?');
  var query = t.substring(pos+1);
  //window.alert(t);
  //window.alert(query);

  // Split query at the comma
  var pairs = query.split("&");
  //lat=-36.98582581985&amp;#38;lon=147.139892578125&amp;#38;zoom=12&amp;#38;bg_layer=sat&amp;#38;fg_layers=map&amp;#38;fid=5

  var counter = 0;
  
  // Begin loop through the querystring
  for(var i = 0; i < pairs.length; i++) {

    // Look for "name=value"
    var pos = pairs[i].indexOf('=');

    // if not found, skip to next
    if (pos == -1) continue;

    // Extract the name
    var argname = pairs[i].substring(0,pos);

    // Extract the value
    var value = pairs[i].substring(pos+1); 

    // Store as a property
    if (!args[argname]) {
      args[argname] = unescape(value);
    }
    else {
      args[argname] += ("&" + argname + "=" + unescape(value));
    }
  }
  
  return args; // Return the Object
}

function LZ(x) {
    return (x >= 10 || x < 0 ? "" : "0") + x;
}

function getBaseURL(url) {
  // Return the base url, ie without any query parameters.

  return url.split("?")[0];
}

function findPos(obj) {
  // Find the overall offset position of this object. Useful for determining relative mouse clicks on say an image etc.
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
      curtop = obj.offsetTop
      while (obj = obj.offsetParent) {
	curleft += obj.offsetLeft
	curtop += obj.offsetTop
      }
  }
  return new Array(curleft,curtop);
}

// Load up the given image URL.  Returning true if it is loaded.
var imageCache = new Array();
function cacheImage(url) {
  // Caches the given image , returning true if it is cached.
  if (imageCache[url]) {
    // We have a cached image, see if it is loaded :
    if (imageCache[url].complete) {
      return imageCache[url].loadResult; // Cached or Failed
    } else {
      return 0; // Still Loading
    }
  } else {
    // Cache the image :
    imageCache[url] = new Image();
    imageCache[url].onerror = function() {imageCache[url].loadResult = 2;} // Flag error for the image
    imageCache[url].loadResult = 1;// Assume it will be a success for now.
    imageCache[url].src= url;
    return 0; // Loading started
  }
}
