// Types of mapping search
var blnRoutePlanning = false;
var pageLoadFunctions = new Array();
var ondrag;
var onselectstart;
var onmousedown;


function EnableDrag() {
    document.ondrag = ondrag;
    document.onselectstart = onselectstart;
    document.onmousedown = onmousedown;
}
function DisableDrag() {
    ondrag = document.ondrag;
    onselectstart = document.onselectstart;
    onmousedown = document.onmousedown;
    document.ondrag = function () { return false; };
    document.onselectstart =function () { return false; };
    document.onmousedown = function () { return false; };
}

// shotcut function to get html element by id
function $(id) {
    return document.getElementById(id);
}

// function to call when you want to add a pageload event
function addPageLoadFunction(func) {
    pageLoadFunctions.push(func);
}

// page load function
//this is called hven the page is loaded
function pageLoad() {
    for (i=0;i<pageLoadFunctions.length;i++)
    {
        pageLoadFunctions[i]();
    }
}

function createMethodReference(object, methodName) {
    return function () {
        object[methodName].apply(object, arguments);
    };
};

//function to use when you use object methods for events
function createEventListenerMethodReference(object, methodName) {
    return function (event) {
        object[methodName].call(object, event || window.event);
    };
}

//FAH
//Returns a boolean value whether map navigation is in process
function mapNavigation(inputNames)
{
	var objForm = document.forms[1];
	var value = false;
	
	if (objForm != null)
	{
		while (i < inputNames.length)
		{
			var name = inputNames[i];
			var input = objForm[name];
			
			if(name== 'BoxRight' || name == 'BoxLeft' || name == 'BoxTop' || 
				name == 'BoxBottom' || name == 'ClickX' || name == 'ClickY' || name == 'Zoom')
			{	
				//If mapnavigation is in process return 
				if(input.value!='')
				{	
					value = true;
				}
			}
			
		i++;
		}
	}
	return value;
}

function containsInputValues(inputNames)
{
	var valueCount = 0;

	var objForm = document.forms[1];

	if (objForm != null)
	{
		var i = 0;
		// Unicode support for IE.
		// Codes available at http://subversion.krak.dk/mustang/Krak/KrakPortal/main/Documentation/Javascript unicode charcodes/codes.html
		// or online at http://e-tidsskrift.dk/dev/tegntabel.html
		var re = /[\u00C0-\u00FF\u0100\u0101\u010C\u010D\u011E\u011F\u012A\u012B\u014C\u014D\u0152\u0153\u015A\u015B\u0160\u0161\u016A\u016B\u017D\u017E\u1E0D\u1E24\u1E25\u1E36\u1E37\u1E38\u1E39\u1E42\u1E43\u1E44\u1E45\u1E46\u1E47\u1E5A\u1E5B\u1E5C\u1E5D\u1E62\u1E63\u1E6C\u1E6DA-Za-z0-9_]+/;
        var reg = /\w+/
		while (i < inputNames.length)
		{
			var name = inputNames[i];
			var input = objForm[name];
						
			if (input != null)
			{
				if (input.options)
				{
					if (input.options[input.selectedIndex].value != "")
					{
						valueCount++;
					}
				}
				else if (input.value != "" && input.value.match(reg))
				{
				    if(window.ActiveXObject) {
				        if (input.value.match(re))
					    {
						    valueCount++;
					    }
					    else
					    {
						    input.value = "";
					    }
                    } else {
					    valueCount++;
					}
				}
			}
			i++;
		}
	}
	
	return (valueCount > 0);
}

function showValidationError(data)
{
	var errorDivContainer = $(data.errorDivContainerId);

	if (errorDivContainer != null)
	{
		if (!data.commonErrorShowing)
		{
			var pHtmlElement = document.createElement("P");
			pHtmlElement.className = "feedback";
			var spanHtmlElement = document.createElement("SPAN");
			var textNode = document.createTextNode(data.errorText);

			pHtmlElement.appendChild(spanHtmlElement);
			spanHtmlElement.appendChild(textNode);

			errorDivContainer.appendChild(pHtmlElement);

			data.commonErrorShowing = true;
		}
	}
	else // Container not found so output to alert window
	{
		alert(data.errorText);
	}
}

// Disables all form elements.
function disableFormInputs()
{
	var objForm = document.forms[1];
	for (var i=0; i<objForm.elements.length;i++)
	{
		objForm.elements[i].disabled = true;
	}
}

// Enables specific form elements.
function enableFormInputs(inputNames)
{
	if (inputNames)
	{
		var objForm = document.forms[1];
		
		for (var i = 0; i < inputNames.length; i++)
		{
			var element = objForm.elements[inputNames[i]];

			if (element && element.value && element.value != "")
			{
				element.disabled = false;
			}
		}
	}
}

// Recursive function to find the elements parent
function recursiveLeft(element) {
    var elParent = element.offsetParent;
    if (elParent) {
        return element.offsetLeft + recursiveLeft(elParent);
    }
    else {
        return 0;
    }
}

// Recursive function to find the elements parent
function recursiveTop(element) {
    var elParent = element.offsetParent;
    if (elParent) {
        return element.offsetTop + recursiveTop(elParent);
    }
    else {
        return 0;
    }
}

// Open a popup window
function popup(url, windowName, width, height, replaceDanishChars)
{
	if (replaceDanishChars)
	{
		url = url.replace("\u00E6", "%c3%a6");
		url = url.replace("\u00F8", "%c3%b8");
		url = url.replace("\u00E5", "%c3%a5");
		url = url.replace("\u00C6", "%c3%86");
		url = url.replace("\u00D8", "%c3%98");
		url = url.replace("\u00C5", "%c3%85");
	}
	window.open(url, windowName, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=1,width='+width+',height='+height+',left=100,top=100');
}

// Open a popunder window
function popunder(url, windowName, options)
{
	var win	= window.open(url, windowName, options);
	win.blur();	
}

function companyWebsitePopunder(url)
{
	popunder(url, "companyWebsitePopunder", "");
}

// Selects a specific radio button. Used with a onclick event on resultlists.
function selectRow(strID)
{
	var objRadio = $(strID);
	if (objRadio)
	{
		objRadio.checked = true;
	}
}

/* POC on EXPANDER CLIENT-SIDE FUNCTIONALITY */
function expand(objTrigger){
	var objExpRoot, objExpCurrNode;
	var blnExpState;
	if(objTrigger){
		objExpRoot = previousSiblingElement(objTrigger.parentNode);
		/* .tagName ALWAYS IN UPPERCASE??? */
		if(objExpRoot.tagName == "UL"){
			blnExpState = walkElement(objExpRoot);
			
			if (blnExpState){
				addClassName(objTrigger, "expRev");
			}else{
				removeClassName(objTrigger, "expRev");
			}
		}
	}

	if(blnExpState != null){
		/* WE DID SOMETHING... SUCCESS! */
		return false; /* DO NOT FOLLOW HREF OF TRIGGER (A-TAG) */
	}else{
		/* FAILURE... */
		return true; /* CALL FOR SERVER-SIDE HELP - GO FOR HREF OF TRIGGER (A-TAG) */
	}
}

function walkElement(objElement){
	var objExpCurrNode;
	var blnExpState = null;

	for(var n=0; n<objElement.childNodes.length;n++){
		if(objElement.childNodes[n].tagName == "LI"){
			objExpCurrNode = objElement.childNodes[n];
			if(hasClassName(objExpCurrNode, "expHidden") || hasClassName(objExpCurrNode, "expHiddenNot")){
				blnExpState = hasClassName(objExpCurrNode, "expHidden");
				
				if(blnExpState){
					/* EXPAND */
					replaceClassName(objExpCurrNode, "expHidden", "expHiddenNot");
					//addClassName(objTrigger, "expRev");
				}else{
					/* COLLAPSE */
					replaceClassName(objExpCurrNode, "expHiddenNot", "expHidden");
					//removeClassName(objTrigger, "expRev");
				}

				blnExpState = blnExpState;
			}

			blnSubState = walkElement(objExpCurrNode);

			if (blnExpState == null && blnSubState != null){
				blnExpState = blnSubState;
			}
		}
		else if(objElement.childNodes[n].tagName == "UL"){
			blnExpState = walkElement(objElement.childNodes[n]);
		}
	}

	return blnExpState;
}

/* COMMON FUNCTIONS */
function previousSiblingElement(el){
	if(el && el.previousSibling){
		if(el.previousSibling.nodeType == 1){
			var rtnEl = el.previousSibling;
		}else{
			var rtnEl = previousSiblingElement(el.previousSibling);
		}
	}
	return rtnEl;
}

function hasClassName(el, name){
	var list;
	if(el && el.className){
		list = el.className.split(" ");
		for(var i=0; i<list.length; i++)
			if(list[i]==name) return true;
	}
	return false;
}

function addClassName(el, name){
	if(!hasClassName(el, name)){
		if(el.className==""){
			el.className = name;
		}else{
			el.className = el.className + " " + name;
		}
	}
}

function replaceClassName(el, name, newName){
	var curList;
	if(el && el.className){
		curList = el.className.split(" ");
		for(var i=0; i<curList.length; i++){
			if(curList[i]==name) curList[i] = newName;
		}
		el.className = curList.join(" ");
	}
}

function removeClassName(el, name){
	var curList, newList = new Array();
	if(el && el.className!=null){
		curList = el.className.split(" ");
		for(var i=0; i<curList.length; i++){
			if(curList[i]!=name){
				newList[newList.length] = curList[i];
			}
		}
		el.className = newList.join(" ");
	}
}

function AreaDropDownItemSelected(select, inputName)
{
	var disabledState = false;

	// If the user selected a spacer item, go back to the first item in the list
	if (select.options[select.selectedIndex].value == "")
	{
		select.selectedIndex = 0;
	}
	else
	{
	    $('City').value = '';
		disabledState = true;
	}

	var objForm = document.forms[1];

	if (objForm != null)
	{
		var input = objForm[inputName];
		
		if (input != null)
		{
			input.disabled = disabledState;
		}
	}
}

// Show next/prev add image
function showAddImage(direction, maxIndex)
{
	var index = addImageSelectedIndex + direction;
	
	
	
	if (addImageImages && addImageImagesTexts && addImageImages.length > 0 && addImageImagesTexts.length > 0)
	{
		if (index < 0 || index >= addImageImages.length)
		{	   
			return false;
		}
		else
		{
			var text = addImageImagesTexts[index];
			var image = addImageImages[index];

			try
			{
				// TODO: add support for other browsers
				var addImageText = $('addImageText');
				var addImage = $('addImage');
            
				addImage.src = image;
				addImageText.innerHTML = text;
            
				addImageSelectedIndex = index;
				
            //Backward image button
            if(index > 0)
            {
               $('bckIcon').style.display='';
            }
            else
            {                 
               $('bckIcon').style.display='none';
            }
            
            //Forward image button
            if(index == maxIndex)
            {
               $('fwdIcon').style.display='none';
            }
            else
            {
               $('fwdIcon').style.display='';
            }
               
            
				return false;
			}
			catch(ex)
			{
				return true;
			}
		}
	}

	return true;
}

// Show add image popup (with large images instead of thumbnails)
function showAddImagePopup(basePath, width, height)
{
	// Call generic popup function
	popup(basePath + (addImageSelectedIndex + 1), 'addImagePopup', width, height);
}

function cityChanged(source, areaDropDownId)
{
	var areaDropDown = $(areaDropDownId);
	if (areaDropDown != null)
	{
		if (source.value.length > 0)
		{
		    areaDropDown.selectedIndex = 0;
			areaDropDown.disabled = true;
		}
		else
		{
			areaDropDown.disabled = false;
		}
	}
}

/************************
	
	Focus related code

*************************/

// Set this variable to true on the pages you want to enable focus.
var focusEnabled = false;
var focusInitialized = false;

// Default function that returns the element reference that should get focus.
// This function must be overriden on the pages you want to enable focus.
function getFocusElement()
{
	return null;
}

// Assign focus to element using element id.
function setFocusToElementById(id)
{
	var element = $(id);
	setFocusToElement(element);
}

// Assign focus to element.
function setFocusToElement(element)
{
	if (focusEnabled && !focusInitialized)
	{
		if (element != null && element.focus)
		{

			element.focus();
			focusInitialized = true;
		}
	}
}

// This method is executed when the window onload event fires.
function formFocus()
{
	if (!focusEnabled)
	{
		return;
	}

	var focusElement = getFocusElement();

	if (focusElement != null)
	{
		setFocusToElement(focusElement);
	}
}
addPageLoadFunction(formFocus);

// Returns a reference to the form element with the given name, null if not found.
function getFormElement(name)
{
	var objForm = document.forms[1];

	if (objForm != null)
	{
		return objForm[name];
	}

	return null;
}

// Returns the current path lower cased. Empty string if not available.
function getCurrentPath()
{
	if (document && document.location && document.location.pathname)
	{
		return document.location.pathname.toLowerCase();
	}

	return "";
}

function addLoadEvent(func) {
  var oldonload = window.onload;	
    if (typeof window.onload != 'function') {
	    window.onload = func;
    } else {
	    window.onload = function() {
		    oldonload();
		    func();
		}
	}
}
addLoadEvent(pageLoad);

//Returns the value of the selected radio button
function GetCheckedRadioButton(buttonGroup) 
{
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[1]) 
   {
		for (var i=0; i<buttonGroup.length; i++) {
			if (buttonGroup[i].checked) 
			{
				alert(buttonGroup[i].value);
				//return buttonGroup[i].value;
			}
		}
   } 
   else 
   {
	  if (buttonGroup.checked) 
	  { 
		alert(buttonGroup.value);
		//return buttonGroup.value;
	  }
   }
}

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) 
    {
        var pair = vars[i].split("=");
        if (pair[1] == variable) 
        {
            return pair[1];
        }
    }
} 


// Must match the Krak.Portal.Collections.QueryStringParameters
var mappingSearchInputNames = ["SearchResult", "Road", "City", "Query", "Area", "BoxTop", "BoxLeft", "BoxBottom", "BoxRight", "ClickX", "ClickY", "Event", "MapState", "MapSize", "AddressY", "AddressX", "Knr", "Zoom", "Ortho"];
var mappingSearchInputValidationNames = ["Road", "City", "Event", "Zoom"];
var mappingSearchCoordinateNames = ["Zoom", "BoxTop", "BoxLeft", "BoxBottom", "BoxRight"];

// Perform mapping search.
function mappingSearch(newSearch)
{
	// validate if we have at least one value
	var searchInputValid = containsInputValues(mappingSearchInputValidationNames);
	var searchMapValid = containsInputValues(mappingSearchCoordinateNames);
	var isMapNavigation = mapNavigation(mappingSearchInputNames);

	if (searchInputValid)
	{
		var objForm = document.forms[1];
		if (newSearch)
		{
			mappingSearchInputNames = ["Road", "City", "Query", "Area", "MapState", "MapSize"];
		}

		// Call functions defined in Krak.Common.js
		disableFormInputs();
		enableFormInputs(mappingSearchInputNames);
					
        objForm.action  = (isMapNavigation || newSearch == false) ? window.location.pathname : "/Kort/KortMellemResultat.aspx";
        objForm.method = "get";
		objForm.submit();
	}
	else
	{
		showValidationError(mappingSearchProperties);

		return false;
	}
}

// ID's of the hidden fields containing mapstate values.
var clientsideMapVariables = {
	Ids: {
		boxTop: "BoxTop",
		boxBottom: "BoxBottom",
		boxLeft: "BoxLeft",
		boxRight: "BoxRight",
		clientX: "ClickX",
		clientY: "ClickY",
		event: "Event",
		eventCatcher: "Eventcatcher",
		box: "Box",
		zoomEvent: "ZoomEvent"
	},
	events: {
		click: "Click",
		boxZoom: "Box"
	}
};

function Point(x, y){//Point constructor
	this.x = parseInt(x);
	this.y = parseInt(y);
	this.moveTo = function(x, y){this.x = x; this.y = y;};
	this.moveBy = function(x, y){this.x += x; this.y += y;};
	this.substract = function(point){this.x -= point.x; this.y -= point.y};
	this.add = function(point){this.x += point.x; this.y += point.y};
	this.draw = function(){var m_Element = document.createElement('div');m_Element.style.top = this.y + 'px';m_Element.style.left = this.x + 'px';return m_Element;};
}

function ClientMap(width, height) {
	this.width = width || 640;
	this.height = height || 512;
	this.mouseClicked = false;

	this.startPoint = new Point(0,0);
	this.currentPoint = new Point(0,0);

	this.boxTopInput = null;
	this.boxBottomInput = null;
	this.boxLeftInput = null;
	this.boxRightInput = null;

	this.clientXInput = null;
	this.clientYInput = null;

	this.eventInput = null;

	this.eventCatcherDiv = null;
	this.boxDiv = null;
	
	this.zoomEventInput = null;
}

ClientMap.prototype.setupBrowserEvents = function() {
	var me = this;
	var mouseDownEventFunction = function(event) { me.initDraw(event); };
	var mouseMoveEventFunction = function(event) { me.drawBox(event); };
	var mouseUpEventFunction = function(event) { me.endDrawBox(event); };

	if (!this.eventCatcherDiv)
	{
		return;
	}

	// ie
	if (document.body.attachEvent) {
		this.eventCatcherDiv.attachEvent("onmousedown", mouseDownEventFunction);
		document.body.attachEvent("onmousemove", mouseMoveEventFunction);
		document.body.attachEvent("onmouseup", mouseUpEventFunction);

	} else if (document.body.addEventListener) {
		this.eventCatcherDiv.addEventListener("mousedown", mouseDownEventFunction, false);
		document.body.addEventListener("mousemove", mouseMoveEventFunction, false);
		document.body.addEventListener("mouseup", mouseUpEventFunction, false);
	}
}

ClientMap.prototype.setupLoadEvent = function() {
	var me = this;
	var loadFunction = function(event) {
		me.getHtmlRefs();
		me.setupBrowserEvents(event);
		me.setupCss();
	}

	if (window.attachEvent) {
		window.attachEvent("onload", loadFunction);
	} else if (window.addEventListener) {
		window.addEventListener("load", loadFunction, false);
	}
}

ClientMap.prototype.setupCss = function() {
	var agent = navigator.userAgent.toLowerCase();

	var opera = agent.indexOf("opera") > -1;
	var ie = agent.indexOf("msie") > -1;
	var firefox = agent.indexOf("firefox") > -1;

	if ((ie || firefox) && !opera && this.boxDiv) {
		var styles = this.boxDiv.style;
		styles.backgroundColor = "white";
		styles.mozOpacity = "0.5";
		styles.opacity = "0.5";
		styles.filter = "Alpha(opacity=50)";
	}
}

ClientMap.prototype.getHtmlRefs = function() {
	this.boxTopInput = document.getElementById(clientsideMapVariables.Ids.boxTop);
	this.boxBottomInput = document.getElementById(clientsideMapVariables.Ids.boxBottom);
	this.boxLeftInput = document.getElementById(clientsideMapVariables.Ids.boxLeft);
	this.boxRightInput = document.getElementById(clientsideMapVariables.Ids.boxRight);

	this.clientXInput = document.getElementById(clientsideMapVariables.Ids.clientX);
	this.clientYInput = document.getElementById(clientsideMapVariables.Ids.clientY);

	this.eventInput = document.getElementById(clientsideMapVariables.Ids.event);

	this.eventCatcherDiv = document.getElementById(clientsideMapVariables.Ids.eventCatcher);
	this.boxDiv = document.getElementById(clientsideMapVariables.Ids.box);
	
	this.zoomEventInput = document.getElementById(clientsideMapVariables.Ids.zoomEvent);
}

ClientMap.prototype.clearData = function() {
	this.eventInput.value = "";
	this.boxTopInput.value = "";
	this.boxBottomInput.value = "";
	this.boxLeftInput.value = "";
	this.boxRightInput.value = "";

	this.clientXInput.value = "";
	this.clientYInput.value = "";

	this.boxDiv.style.height = "0px";
	this.boxDiv.style.width = "0px";
	this.boxDiv.style.top = "0px";
	this.boxDiv.style.left = "0px";
	
	this.zoomEventInput.value = "";
}

ClientMap.prototype.initDraw = function(e) {
	this.clearData();
	this.mouseClicked = true;
	this.startPoint = this.getPointElement(e);
}

ClientMap.prototype.drawBox = function(e) {
	if (!this.mouseClicked) {
		return;
	}

	this.currentPoint = this.getPointPage(e);
	this.currentPoint.substract(this.getElementPosition("kortDiv"));

	// determine if we should draw a box
	var doDrawBox = false;

	if (this.startPoint.x != this.currentPoint.x && this.startPoint.y != this.currentPoint.y) {
		doDrawBox = true;
	}

	if (doDrawBox) {
		rectStyle = this.boxDiv.style;

		if (0 > this.currentPoint.x) {
			this.currentPoint.x = 0
		}

		if (this.currentPoint.x > this.width) {
			this.currentPoint.x = this.width;
		}

		if (this.currentPoint.x < this.startPoint.x) {
			rectStyle.left = (this.currentPoint.x) + 'px';
		} else {
			rectStyle.left = (this.startPoint.x) + 'px';
		}

		rectStyle.width = Math.abs(this.currentPoint.x - this.startPoint.x - 4) + 'px';

		if (0 > this.currentPoint.y) {
			this.currentPoint.y = 0
		}

		if (this.currentPoint.y > this.height) {
			this.currentPoint.y = this.height;
		}

		if (this.currentPoint.y < this.startPoint.y) {
			rectStyle.top = (this.currentPoint.y) + 'px';
		} else {
			rectStyle.top = (this.startPoint.y) + 'px';
		}

		rectStyle.height = Math.abs(this.currentPoint.y - this.startPoint.y - 4) + 'px';
	}
}

ClientMap.prototype.endDrawBox = function(e) {
	if (this.mouseClicked == true) {
		var rS = this.boxDiv.style;
		
		var top = parseInt(rS.top);
		var bottom = top + parseInt(rS.height);
		var left = parseInt(rS.left);
		var right = left + parseInt(rS.width);
		var width = this.boxDiv.style.width;
		
		// check om boksen er større end 10 pixels - hvis ikke skal der centreres
		if ( 10 > parseInt(rS.height) && (10 > parseInt(width) || width.length < 1)) {
			// centrer
			// check om der er klikket eller trukket en boks
			if (parseInt(left) > 0) {
				// centrer omkring centrum at boksen
				this.setClickPoint(parseInt((left + right) / 2), parseInt((top + bottom) / 2));
			} else {
				// centrer der hvor der er klikket
				this.setClickPoint(this.getPointElement(e).x, this.getPointElement(e).y);
			}

			this.setEvent(clientsideMapVariables.events.click);
		} else {
			// zoom
			this.setBoxExtend(top, bottom, left, right);
            //alert(top + '#' + bottom + '#' + left + '#' + right);
			this.setEvent(clientsideMapVariables.events.boxZoom);
		}

		if (blnRoutePlanning)
		{
			routeplanningSearch(false);
		}
		else
		{
			mappingSearch(false);
		}
	}

	this.mouseClicked = false;
}

ClientMap.prototype.getElementPosition = function(eId) {
	var element = document.getElementById(eId);
	var recOfx = 0,recOfy = 0;
	
	recOfx = recursiveLeft(element);
	recOfy = recursiveTop(element);
	
	return new Point(recOfx, recOfy);
}

ClientMap.prototype.getScrollingPosition = function(){ //Returns a coordinate with coordinates corresponding to the scrolling position of window.
	var scrlPosX = 0, scrlPosY = 0;
	if (typeof window.pageYOffset != 'undefined') {
		scrlPosX = window.pageXOffset;
		scrlPosY = window.pageYOffset;
	}else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
		scrlPosX = document.documentElement.scrollLeft;
		scrlPosY = document.documentElement.scrollTop;
	}else if (typeof document.body.scrollTop != 'undefined') {
		scrlPosX = document.body.scrollLeft;
		scrlPosY = document.body.scrollTop;
	}
	
	return new Point(scrlPosX, scrlPosY);
}
ClientMap.prototype.getPointPage = function(event){//Returns a coordinate with coordinates corresponding to the page.
	var scrollingPos = this.getScrollingPosition();
	if (typeof event.pageX != 'undefined' && typeof event.x != 'undefined') {
		this.x = event.pageX;
		this.y = event.pageY;
	}else {
		this.x = event.clientX + scrollingPos.x;
		this.y = event.clientY + scrollingPos.y;
	}
	
	return new Point(this.x, this.y);
}

ClientMap.prototype.getPointElement = function(e) {//Returns a point with coordinates corresponding to the containing element. 
	this.x =(e.offsetX)? e.offsetX : (e.layerX)? e.layerX : e.clientX - getParent(e).offsetLeft;
	this.y =(e.offsetY)? e.offsetY : (e.layerY)? e.layerY : e.clientY - getParent(e).offsetTop;

	return new Point(this.x, this.y);
}

ClientMap.prototype.setBoxExtend = function(top, bottom, left, right) {
	this.boxTopInput.value = top;
	this.boxBottomInput.value = bottom;
	this.boxLeftInput.value = left;
	this.boxRightInput.value = right;
}

ClientMap.prototype.setClickPoint = function(x, y) {
	this.clientXInput.value = x;
	this.clientYInput.value = y;
	this.zoomEventInput.value = "in";
}

ClientMap.prototype.setEvent = function(event) {
	this.eventInput.value = event;
}

var clientMap = new ClientMap();
clientMap.setupLoadEvent();

function setZoomAction(oRadio){
    createCookie('zoomAction',oRadio.value,365);
}

function setZoomFactor(oRadio){
    createCookie('zoomFactor',oRadio.value,365);
}