BVDT.MAXINZOOM = 5;
BVDT.INPUTZOOM = 0;

BVDT.locationClicker = null;

BVDT.styleMap = new OpenLayers.StyleMap(
{
	'select':OpenLayers.Util.applyDefaults({externalGraphic:"art/graphics/vlag2.png", graphicWidth:32, graphicHeight:32, graphicOpacity:1.0,graphicYOffset:-30,graphicXOffset:-6}, OpenLayers.Feature.Vector.style["select"]),
	'default':OpenLayers.Util.applyDefaults({externalGraphic:"art/graphics/vlag1.png", graphicWidth:32, graphicHeight:32, graphicOpacity:1.0,graphicYOffset:-30,graphicXOffset:-6}, OpenLayers.Feature.Vector.style["default"])
}
);
BVDT.flickrStyleMap = new OpenLayers.StyleMap(
{
	'select':OpenLayers.Util.applyDefaults({externalGraphic:"art/graphics/vlag2.png", graphicWidth:32, graphicHeight:32, graphicOpacity:1.0,graphicYOffset:-30,graphicXOffset:-6}, OpenLayers.Feature.Vector.style["select"]),
	'default':OpenLayers.Util.applyDefaults({externalGraphic:"art/graphics/vlag1.png", graphicWidth:32, graphicHeight:32, graphicOpacity:1.0,graphicYOffset:-30,graphicXOffset:-6}, OpenLayers.Feature.Vector.style["default"])
}
);
BVDT.inputStyleMap = new OpenLayers.StyleMap(
{
	'select':OpenLayers.Util.applyDefaults({externalGraphic:"art/graphics/vlag2.png", graphicWidth:32, graphicHeight:32, graphicOpacity:1.0,graphicYOffset:-30,graphicXOffset:-6}, OpenLayers.Feature.Vector.style["select"]),
	'default':OpenLayers.Util.applyDefaults({externalGraphic:"art/graphics/vlag2.png", graphicWidth:32, graphicHeight:32, graphicOpacity:1.0,graphicYOffset:-30,graphicXOffset:-6}, OpenLayers.Feature.Vector.style["select"])
}
);

// de click handler / controler
BVDT.locationControl = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
		'single': true,
		'double': false,
		'pixelTolerance': 0,
		'stopSingle': false,
		'stopDouble': false,
		'drag':true
	},
initialize: function(options) {
		this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions);
		OpenLayers.Control.prototype.initialize.apply(this, arguments); 
		this.handler = new OpenLayers.Handler.Click(
		this, {
			'click': this.trigger
		}, this.handlerOptions
		);
	}, 
activate: function(){
		OpenLayers.Control.prototype.activate.apply(this, arguments); 
		BVDT.setFlagCursor(true);
	},
deactivate: function(){
		BVDT.setFlagCursor(false);
		OpenLayers.Control.prototype.deactivate.apply(this, arguments); 
	},
trigger: function(e) {
		if(!BVDT.current){
			// hey we're in the intro: do not set a new location
			return;
		}else{
			document.getElementById('formMessages').innerHTML="";
			var xy = BVDT.map.getLonLatFromViewPortPx(e.xy);
			if (BVDT.newLocation){
				BVDT.invoerLayer.removeFeatures([BVDT.newLocation]);
			}
			// new location icon in map.projection
			BVDT.newLocation = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(xy.lon, xy.lat),null);
			if(BVDT.map.zoom<BVDT.INPUTZOOM){
				BVDT.map.setCenter(BVDT.newLocation.geometry.getBounds().getCenterLonLat(), BVDT.INPUTZOOM);
			}			
			// store in displayProjection
			xy.transform(BVDT.map.projection, BVDT.map.displayProjection)
			// zet icon op de kaart
			BVDT.invoerLayer.addFeatures(BVDT.newLocation);
			// fill form
			document.getElementById('bvdtform').style.display="block";
			document.getElementById('lon').value=xy.lon;
			document.getElementById('lat').value=xy.lat;
			BVDT.stapNaar(3); // also deactivates this
			
		}
	}
});

BVDT.icon = new OpenLayers.Icon("art/graphics/vlag1.png", new OpenLayers.Size(32,32), new OpenLayers.Pixel(-6, -30));

BVDT.KMLparser = new OpenLayers.Format.KML({extractStyles: false, extractAttributes:true});

// fix IE's lack of indexOf for array's
if(!Array.indexOf) {
    Array.prototype.indexOf = function(arr) {
        for(var i = 0; i < this.length; i++) {
            if(this[i] == arr){ return i; }
        }
        return -1;
    }
}

//deze functie roept alle start functies aan die geladen moeten worden
function loadPage(){
	BVDT.mapInit();
	tooltip();
	// attach load function to the photo-div
	$('#photo').load(function(){
		$('#flickrcomments').hide().load("index.php", { go: "home.getFlickrComments", photo_id:BVDT.current.photoid });	
		BVDT.stapNaar(1);
	});
	// loading this page with a photoid should load this photo
	if($.getURLParam("photoid")){
		// we set BVDT.current to know we are in doemee
		BVDT.current = {};
		BVDT.loadPhotoById($.getURLParam("photoid"));
	}
}

BVDT.loadPhoto = function(index){
	if(!BVDT.current){
		// no current photo? we're in the flickrkaart, go to doemee
		window.location.href="index.php?go=home.doemee&photoid="+BVDT.photos[index].photoid;
		return;
	}
	BVDT.removeAllPopups();
	if(index<0){
		index=BVDT.photos.length-1;
	}
	else if(index>BVDT.photos.length-1){
		index=0;
	}
	$('#miniphoto').hide();
	BVDT.current = BVDT.photos[index];
	BVDT.currentIndex = index;

	var photowrapper = BVDT.current.server + '/' + BVDT.current.photoid + '_' + BVDT.current.secret + '.jpg';
	$('#flickrcomments').hide();
	$('#locationcomments').hide();
	$('#fotoinfo').hide();
	$('#phototitle').html(BVDT.current.title);
	$('#FlickrURL').attr('href', 'http://www.flickr.com/photos/mapit1418/' + BVDT.current.photoid + '/')
	$('#photowrapper').hide();
	$('#map').show();
	$('#bvdtform').hide();
	
	if (BVDT.current.media=="video"){
		$('#photo').hide();
		$('#video').load("index.php", { go: "home.getVideoHtml", photo_id:BVDT.current.photoid }, function(){
			$('#video').show();
		});
		//		$('#flickrcomments').hide().load("index.php", { go: "home.getFlickrComments", photo_id:BVDT.current.photoid }, function(){
		//			$(this).show();
		//
		//	    });
	}
	else{
		$('#video').innerHTML="";
		$('#video').hide();
		$('#photo').attr('src', photowrapper);
		$('#photo').attr('alt', BVDT.current.title);
		$('#photo').attr('title', BVDT.current.photoTitle);
		$('#photo').show();
	}
	// haal onze comments op van deze foto
	BVDT.getLocationComments(BVDT.current.photoid);
	BVDT.getDescription(BVDT.current.photoid);
	// haal locaties op van deze foto
	BVDT.loadThisPhotoLocations(BVDT.current.server, BVDT.current.photoid, BVDT.current.secret);
	// minifotootje
	document.getElementById('miniphoto').src=BVDT.current.server + '/' + BVDT.current.photoid + '_' + BVDT.current.secret + '_s.jpg';
	$('#miniphoto').show();
}

BVDT.loadPhotoById = function(photoId){
	for (i=0;i<BVDT.photos.length;i++){
		if(BVDT.photos[i].photoid==photoId){
			BVDT.loadPhoto(i);
			break;
		}
	}
}

// haal alle ingevoerde locaties van deze foto op (als KML) (uit onze database)
BVDT.loadThisPhotoLocations = function(flickrUrl, photoID, photoSecret){
	BVDT.removeAllPopups();
	if (BVDT.flickrLayer!=null){
		BVDT.flickrLayer.setVisibility(false);
	}
	if (BVDT.photosLayer!=null){
		BVDT.photosLayer.setVisibility(true);
	}
	// evt aanwezig form verbergen
	$('#bvdtform').hide();
	BVDT.currentPhoto = {flickrurl:flickrUrl, id:photoID, secret:photoSecret};
	locationsURL = "index.php?go=home.getLocations&photo_id="+photoID;
	if (BVDT.photosLayer==null){
		BVDT.photosLayer = new OpenLayers.Layer.GML("PHOTOKML", locationsURL, {
format: OpenLayers.Format.KML,
formatOptions: {
				// adds the thumbnail attribute to the feature
parseFeature: function(node) {
					var feature = OpenLayers.Format.KML.prototype.parseFeature.apply(this, arguments);
					//feature.attributes.thumbnail = this.getElementsByTagNameNS( item, "*", "thumbnail")[0].getAttribute("url");
					//feature.attributes.thumbnail = "http://farm4.static.flickr.com/3603/3726664214_63920e46f4_s.jpg";
					return feature;
				}
			},
			// Giving the style map keys for "default" and "select"
			// rendering intent, to make the image larger when selected
styleMap:BVDT.styleMap,
projection: BVDT.map.displayProjection
		});
		BVDT.map.addLayer(BVDT.photosLayer);
		BVDT.zoomToPhotoLayerFeatures();
		BVDT.photosLayerSelectControl = new OpenLayers.Control.SelectFeature(BVDT.photosLayer, {hover:false});
		BVDT.photosLayer.events.on({
			"featureclicked":BVDT.onLocationClick,
			"featureselected": BVDT.onLocationClick,
			"featureunselected":function(event){
				if(event.feature && event.feature.popup && event.feature.popup.div && $('photopopup') && $('photopopup').display!="none"){
					event.feature.popup.hide();
				}
			},
			"featuresadded": BVDT.onLocationsAdded
		});
		BVDT.map.addControl(BVDT.photosLayerSelectControl);
		BVDT.photosLayerSelectControl.activate();
		
	}
	else{
		BVDT.photosLayer.removeFeatures();
		BVDT.photosLayer.destroyFeatures();
		var request = OpenLayers.Request.GET({
url:locationsURL,
headers: {
				"Content-Type": "application/x-www-form-urlencoded"
			},
callback: handler
		})
	}

	function handler(request) {
		if(request.responseText){
			features = (BVDT.KMLparser.read(request.responseText));
			// reproject features
			for (i=0;i<features.length;i++){
				features[i].geometry.transform(BVDT.map.displayProjection, BVDT.map.projection);
			}
			BVDT.photosLayer.addFeatures(features);
			BVDT.zoomToPhotoLayerFeatures();
		}
		else{
			console.log("Er ging iets fout ...");
		}
	}
}

BVDT.mapInit = function()
{
	BVDT.map = new OpenLayers.Map(
		'map',
		{
			maxExtent: new OpenLayers.Bounds(-20037508,-20037508,20037508,20037508),
			restrictedExtent: new OpenLayers.Bounds(258450.999777,6528700.525003,1010591.19509,7162210.478128),
			buffer:0,
			gutter:0,
			units:'m',
			controls:[
				new OpenLayers.Control.Navigation({zoomWheelEnabled:true,handleRightClicks:false}),
				new OpenLayers.Control.PanZoom(),
				new OpenLayers.Control.Attribution()
			],
			displayProjection: new OpenLayers.Projection("EPSG:4326"),
			projection: new OpenLayers.Projection("EPSG:900913")
		}
	);

	BVDT.bvdtOndergrond = new OpenLayers.Layer.TMS(
		"Openstreetmap",
		"http://tile.openstreetmap.org/",
		{
			type:'png',
			getURL: get_osm_url,
			resolutions: [1222.99245234375,611.496226171875,305.7481130859375,152.87405654296876,76.43702827148438,38.21851413574219,19.109257067871095,9.554628533935547,4.777314266967774,2.388657133483887,1.1943285667419434,0.5971642833709717],
			serverResolutions: [156543.0339,78271.51695,39135.758475,19567.8792375,9783.93961875,4891.969809375,2445.9849046875,1222.99245234375,611.496226171875,305.7481130859375,152.87405654296876,76.43702827148438,38.21851413574219,19.109257067871095,9.554628533935547,4.777314266967774,2.388657133483887,1.1943285667419434,0.5971642833709717],
			border:1,
			buffer:0,
			transitionEffect:'resize',
			attribution:'Kaart <a href="http://creativecommons.org/licenses/by-sa/2.0/nl/">cc-by-sa</a> <a href="http://www.openstreetmap.nl/">OpenStreetMap</a>'
		}
	);
	BVDT.map.addLayer(BVDT.bvdtOndergrond);
	
	if(!BVDT.map.getCenter()) {
		BVDT.zoomToBeneluxBBox();
	}
	
	function get_osm_url (bounds) {
		var res = this.map.getResolution();
		var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
		var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
		var z = this.map.getZoom() + this.serverResolutions.indexOf(this.resolutions[0]);
		var path = z + "/" + x + "/" + y + "." + this.type;
		var url = this.url;
		if (url instanceof Array) {
			url = this.selectUrl(path, url);
		}
		return url + path;
	}

	BVDT.invoerLayer = new OpenLayers.Layer.Vector("invoerlayer", {styleMap:BVDT.inputStyleMap});
	BVDT.map.addLayer(BVDT.invoerLayer);
	
	BVDT.locationClicker = new BVDT.locationControl();
	BVDT.map.addControl(BVDT.locationClicker);
	BVDT.showMapWithFlickrLocations();
}

BVDT.setFlagCursor = function(on){
	if(on==true){
		var tempX=0
		var tempY=0;
		var IE = document.all?true:false;
		
		document.getElementById('map').onmousemove=function(e){
			document.getElementById('flagcursor').style.display="block";
			if (IE) { // grab the x-y pos.s if browser is IE
				tempX = event.clientX + document.body.scrollLeft;
				tempY = event.clientY + document.body.scrollTop;
			}
			else {  // grab the x-y pos.s if browser is NS
				tempX = e.pageX;
				tempY = e.pageY;
			}
			// offset for wrapper
			offset=OpenLayers.Util.pagePosition(document.getElementById('map'));
			// offset for scroll
			scrollOffset=[0,0];
			if(!IE){
				scrollOffset=[document.documentElement.scrollLeft, document.documentElement.scrollTop];
			}
			document.getElementById('flagcursor').style.top=229+tempY-offset[1]-scrollOffset[1]+'px';
			document.getElementById('flagcursor').style.left=5+tempX-offset[0]-scrollOffset[0]+'px';
		}
		document.getElementById('content_links').onmouseout=function(e){
			document.getElementById('flagcursor').style.display="none";
		}
		document.getElementById('content_links').onmouseover=function(e){
			document.getElementById('flagcursor').style.display="block";
		}
	}
	else{
		document.getElementById('map').onmousemove=null;
		document.getElementById('content_links').onmouseout=null;
		document.getElementById('content_links').onmouseover=null;
		document.getElementById('flagcursor').style.display="none";
	}
}

BVDT.zoomToBeneluxBBox = function(){
	var pos = new OpenLayers.LonLat(5.7 , 52.25);
	BVDT.map.setCenter(pos.transform(BVDT.map.displayProjection, BVDT.map.projection), 0);
}

BVDT.removeAllPopups = function(){
	if(BVDT.invoerLayer){
		BVDT.invoerLayer.removeFeatures();
	}
	for (i=0;i<BVDT.map.popups.length;i++){
		BVDT.map.popups[i].hide();
		BVDT.map.popups[i].destroy();
	}
}


BVDT.postLocation = function(){
	// TODO: enkele checks 
	// lat en lon
	var msg = "";
	document.getElementById('formMessages').innerHTML=msg;
	if(!isEmail(document.getElementById('email').value)){
		msg+="<p>Geen of ongeldig email-adres ingevuld. Dit is een verplicht veld.</p>";
	}
	if(!isString(document.getElementById('naam').value)){
		msg+="<p>Geen of ongeldige naam ingevuld. Dit is een verplicht veld.</p>";
	}
	if(!isString(document.getElementById('motivatie').value)){
		msg+="<p>Geen of ongeldig commentaar ingevuld. Dit is een verplicht veld.</p>";
	}
	if(msg.length>0){
		document.getElementById('formMessages').innerHTML=msg;
		return false;
	}
	
	
	document.getElementById('photoid').value=BVDT.current.photoid;
	document.getElementById('photosecret').value=BVDT.current.secret;
	if (document.getElementById('bestand').value!=''){
		$('bvdtform').submit();
		return;
	}
	
	OpenLayers.Request.POST({
url: "index.php?go=home.setLocation",
data: OpenLayers.Util.getParameterString({ 
photoid:BVDT.current.photoid, 
photosecret:BVDT.current.secret,
lon:document.getElementById('lon').value, 
lat:document.getElementById('lat').value,
naam:document.getElementById('naam').value,
email:document.getElementById('email').value,
motivatie:document.getElementById('motivatie').value,
bestand:document.getElementById('bestand').value
		}
		),
headers: {
			"content_links-Type": "application/x-www-form-urlencoded"
		},
callback:function(x){
			document.getElementById("bvdtform").style.display='none';
			alert("Dank je wel");
			BVDT.photosLayer.refresh();
			BVDT.zoomToPhotoLayerFeatures();
		}
	})	
}

BVDT.zoomToPhotoLayerFeatures = function(){
	if(BVDT.photosLayer.getDataExtent()){
		BVDT.map.zoomToExtent(BVDT.photosLayer.getDataExtent());
		//}
		z=BVDT.map.getZoom();
		// als we maar 1 foto hebben zoom je teveel in: zet maximale inzoom op BVDT.MAXINZOOM
		if(z>BVDT.MAXINZOOM){z=BVDT.MAXINZOOM}
		BVDT.map.zoomTo(z);
	}
	else{
		BVDT.zoomToBeneluxBBox();
	}
}

// haal de ( bij ons gecache'te) geogerefereerde posities op van flickr 
BVDT.showMapWithFlickrLocations = function(){
	if (BVDT.flickrLayer!=null){
		BVDT.flickrLayer.setVisibility(true);
	}
	else{ // nieuwe laag aanmaken
		locationsURL = "index.php?go=home.getLocations";
		if (BVDT.flickrLayer==null){
			BVDT.flickrLayer = new OpenLayers.Layer.GML("FlickrKML", locationsURL, {
format: OpenLayers.Format.KML,
formatOptions: {
parseFeature: function(node) {
						var feature = OpenLayers.Format.KML.prototype.parseFeature.apply(this, arguments);
						return feature;
					}
				},
styleMap:BVDT.flickrStyleMap,
projection: BVDT.map.displayProjection
			});
			BVDT.map.addLayer(BVDT.flickrLayer);
			BVDT.FlickrLayerSelectControl = new OpenLayers.Control.SelectFeature(BVDT.flickrLayer, {hover:false});  
			BVDT.flickrLayer.events.on({
				"featureclicked":BVDT.onLocationClick,
				"featureselected": BVDT.onLocationClick,
				"featureunselected":function(event){
					if(event.feature && event.feature.popup && event.feature.popup.div && $('photopopup') && $('photopopup').display!="none"){
						event.feature.popup.hide();
					}
				}
			});
			BVDT.map.addControl(BVDT.FlickrLayerSelectControl);
			BVDT.FlickrLayerSelectControl.activate();
		}
		else{
			BVDT.flickrLayer.removeFeatures();
			BVDT.flickrLayer.destroyFeatures();
			var request = OpenLayers.Request.GET({
url:locationsURL,
headers: {
					"content_links-Type": "application/x-www-form-urlencoded"
				},
callback: function(request) {
					if(request.responseText){
						features = (BVDT.KMLparser.read(request.responseText));
						// reproject features
						for (i=0;i<features.length;i++){
							features[i].geometry.transform(BVDT.map.displayProjection, BVDT.map.projection);
						}
						BVDT.flickrLayer.addFeatures(features);
					}
					else{
						console.log("Er ging iets fout....");
					}
				}
			})
		}
	}
}

BVDT.getLocationComments = function(photoid){
	$('#locationcomments').load("index.php", { go: "home.getComments", photo_id:BVDT.current.photoid }); 
}

BVDT.getDescription = function(photoid){
	$('#photodesc').load("index.php", { go: "home.getDesc", photo_id:BVDT.current.photoid }); 
}

BVDT.onLocationsAdded = function(features) {
	BVDT.zoomToPhotoLayerFeatures();
}

BVDT.onLocationClick = function(event) {
	var feature = event.feature;
	var selectedFeature = feature;
	if (!feature.popup){
		popup = new OpenLayers.Popup.FramedCloud("photopopup", 
		feature.geometry.getBounds().getCenterLonLat(),
		new OpenLayers.Size(50,50),
		(feature.attributes.name?"<h2>"+feature.attributes.name + "</h2>":'') 
		+ 
		(feature.attributes.description?feature.attributes.description:'')
		,
		{size:new OpenLayers.Size(0,0), offset:new OpenLayers.Pixel(3,-17)}, /* anchor */
		true, /* closebox */
		function(){
			this.hide();
			// deselect all maybe selected features 
			if(BVDT.FlickrLayerSelectControl){
				BVDT.FlickrLayerSelectControl.unselectAll();
			}
			if(BVDT.photosLayerSelectControl){
				BVDT.photosLayerSelectControl.unselectAll();
			}
		}
		);
		popup.autoSize=true;
		popup.minSize=new OpenLayers.Size(100,100);
		popup.maxSize=new OpenLayers.Size(300,300);
		//popup.imageSize=new OpenLayers.Size(30,30);
		feature.popup = popup;
		BVDT.map.addPopup(popup);
	}
	else if(feature.popup && feature.popup.div){
		feature.popup.show();
	}
}

BVDT.onLocationUnselect = function(event) {
	var feature = event.feature;
	if(feature.popup && feature.popup.div && $('photopopup')) {
		//BVDT.map.removePopup(feature.popup);
		//feature.popup.destroy();
		//delete feature.popup;
		feature.popup.hide();
	}
}

BVDT.stapNaar = function(nummer){
	if(!BVDT.current){
		// no current photo? fo to doemee first 
		window.location.href="index.php?go=home.doemee&photoid="+BVDT.photos[0].photoid;
		return;
	}
	if(nummer==1){
		$('#stap1').removeClass().addClass("stap01on");
		$('#stap2').removeClass().addClass("stap02off");
		$('#stap3').removeClass().addClass("stap03off");
		$('#photowrapper').hide();
		$('#map').show();
		$('#bvdtform').hide();
		$('#photodesc').hide();
		$('#locationcomments').show()
		$('#lat').val('');
		$('#lon').val('');
		BVDT.locationClicker.deactivate();
		// verwijder evt aanwezige locatie
		if (BVDT.newLocation){BVDT.invoerLayer.removeFeatures([BVDT.newLocation]);}
	}
	else if(nummer==2){
		$('#stap1').removeClass().addClass("stap01off");
		$('#stap2').removeClass().addClass("stap02on");
		$('#stap3').removeClass().addClass("stap03off");
		$('#photowrapper').hide();
		$('#map').show();
		$('#bvdtform').hide();
		$('#photodesc').hide();
		$('#locationcomments').show()
		BVDT.locationClicker.activate();
	}
	else if(nummer==3){
		// alleen als er een x en y staat
		if($('#lat').val() && $('#lon').val()){
			$('#stap1').removeClass().addClass("stap01off");
			$('#stap2').removeClass().addClass("stap02alt");
			$('#stap3').removeClass().addClass("stap03on");
			$('#photowrapper').hide();
			$('#map').hide();
			$('#bvdtform').show();
			BVDT.locationClicker.deactivate();
		}
		else{
			alert('Kies eerst een foto en prik een locatie op de kaart.');
		}
	} else if(nummer==4) {
		//			$('#stap1').removeClass().addClass("stap01off");
		//			$('#stap2').removeClass().addClass("stap02on");
		//			$('#stap3').removeClass().addClass("stap03off");
		$('#photowrapper').show();
		$('#map').hide();
		$('#photodesc').show();
		$('#locationcomments').show()
		BVDT.locationClicker.deactivate();
	}
}

/* Copyright (c) 2006 Mathias Bank (http://www.mathias-bank.de)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
* 
* Thanks to Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
*/
jQuery.extend({
	/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* @example value = $.getURLParam("paramName");
*/ 
getURLParam: function(strParamName){
		var strReturn = "";
		var strHref = window.location.href;
		var bFound=false;
		
		var cmpstring = strParamName + "=";
		var cmplen = cmpstring.length;

		if ( strHref.indexOf("?") > -1 ){
			var strQueryString = strHref.substr(strHref.indexOf("?")+1);
			var aQueryString = strQueryString.split("&");
			for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
				if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
					var aParam = aQueryString[iParam].split("=");
					strReturn = aParam[1];
					bFound=true;
					break;
				}
				
			}
		}
		if (bFound==false) return null;
		return strReturn;
	}
});

function isEmail(strValue)
{
	var objRE = /^[\w-\.\']{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,}$/;

return (strValue != '' && objRE.test(strValue));
}

function isString(strValue)
{
return (typeof strValue == 'string' && strValue != '' && isNaN(strValue));
}

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
		.css("top",(e.pageY - xOffset) + "px")
		.css("left",(e.pageX + yOffset) + "px")
		.fadeIn("fast");		
	},
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
	});	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
		.css("top",(e.pageY - xOffset) + "px")
		.css("left",(e.pageX + yOffset) + "px");
	});			
};

