var selectedTab;
var map_focus;
var ROUTE_FOCUS = "route";
var MARKER_FOCUS = "marker";

	function onResize() {
		if ($("map").style.display == "none")
			return;
			
		// resize the map
		var m = $("map");
		var d = getDimensions(m);
		var windowHeight = getWindowHeight();
		m.style.height = (windowHeight - d.top - 46) + "px";
		if (map) map.checkResize();
		d = getDimensions(m);
		var e = $("left_panel");
		e.style.height = (windowHeight - d.top - 46) + "px";
		var ns = $("not_scrollable");
		var c = $("scrollable_page");
		c.style.height = (windowHeight - d.top - 45 - getDimensions(ns).height) + "px";
	}

	function Dimensions(left, top, width, height) {
		this.left = left;
		this.top = top;
		this.width = width;
		this.height = height;
	}
	
	function getDimensions(control) {
		var tmp = control;
		var left = 0;
		var top = 0;
	
		while (tmp != null) {
			left += tmp.offsetLeft;
			top += tmp.offsetTop;
			tmp = tmp.offsetParent;
		}
	
		return new Dimensions(left, top, control.offsetWidth, control.offsetHeight);
	}

	function getWindowHeight()
	{
		var windowHeight=0;
		if (typeof(window.innerHeight)=='number')
			windowHeight=window.innerHeight;
		else if (document.documentElement&&document.documentElement.clientHeight)
			windowHeight=document.documentElement.clientHeight;
		else if (document.body&&document.body.clientHeight)
			windowHeight=document.body.clientHeight;
	
		return windowHeight;
	}
	
	function getWindowWidth()
	{
		var windowWidth=0;
		if (typeof(window.innerWidth)=='number')
			windowWidth=window.innerWidth;
		else if (document.documentElement&&document.documentElement.clientWidth)
			windowWidth=document.documentElement.clientWidth;
		else if (document.body&&document.body.clientWidth)
			windowWidth=document.body.clientWidth;
	
		return windowWidth;
	}		

	function renderMenu(tab) {
	   selectedTab = tab;
	   var nav_menu = '<ul>';
	   for (i=0;i<menu.length;i++) {
	       if (tab==menu[i][0]) {
	           nav_menu += "<li id=\"current\"><a href=\"#\">"+menu[i][1]+"</a></li>";
	       } else {
	           nav_menu += "<li><a href=\"#\" onclick=\"menuSelect('"+menu[i][0]+"','"+menu[i][2]+"','"+menu[i][3]+"');return false;\">"+menu[i][1]+"</a></li>";
	       }
	   }
       nav_menu += '</ul>';
       $('nav').innerHTML = nav_menu;
    }
	
    function highlightSelect(color) {
        self.document.PdfInfo.highlight_color.value=color;
        $('highlightPopup').style.visibility='hidden';
    }
    
    function grayscaleSelect(color) {
         self.document.PdfInfo.shade_color.value=color;
        $('grayscalePopup').style.visibility='hidden';    
    }
	
	function showLocation(request) {
	    var xmlDoc = request.responseXML;
	    var locx = xmlDoc.documentElement;
		var longitude = parseFloat(locx.getAttribute("long"));
		var latitude = parseFloat(locx.getAttribute("lat"));
		var delta = parseFloat(locx.getAttribute("delta"));
		if (delta) {
			var startPoint = new GPoint(longitude, latitude);
	        var minZoom = map.spec.getLowestZoomLevel(startPoint, new GSize(delta,delta), map.viewSize);
	        map_focus = ROUTE_FOCUS;
			map.centerAndZoom(startPoint, minZoom+1);
		} else {
		    invalidLocation();
		}
    }
    
    function invalidLocation() {
	   alert('Your search returned no matches.  Either enter a\ntwo character state code or allow autocomplete\n to make a city or county suggestion.');
	}
    
	


// Base Objects


    // Wrapper object for points
    function RsPoint(gpoint, pt_id) {
        this.gpoint=gpoint;
        this.pt_id=pt_id;
        //this.ptIdSort = RsPoint_ptIdSort;
        this.serialize = RsPoint_serialize;
    }

    function RsPoint_serialize() {
        return this.gpoint.lng()+"|"+this.gpoint.lat();
    }

    // Wrapper object for markers
    function RsMarker(pt_index, gmarker, rspoint, mk_id, mk_dist, array_idx, description) {
        this.pt_index = pt_index;
        this.gmarker=gmarker;
        this.rspoint=rspoint;
        this.mk_id=mk_id;
        this.array_idx=array_idx;
        this.mk_direction='';
        this.mk_pdflabel='';
        this.description=description;
        this.mk_distance=mk_dist;
        this.serialize   = RsMarker_serialize;
    }
	
	
	function RsMarker_serialize() {
	   // the below value is WRONG!
	   return this.pt_index-lastSavedPoint+"|"+this.description;
	}
		
	// Wrapper for faster map rendering
	function PolylineMgr() {
	   this.polylines = new Array();
	   this.currentPolyline = new Array();
	   this.addPoint = PolylineMgr_addPoint;
	   this.removePoint = PolylineMgr_removePoint;
	   this.clear = PolylineMgr_clear;
	}
	
	function PolylineMgr_clear() {
	   this.polylines = new Array();
	   this.currentPolyline = new Array();
	}
	
	function PolylineMgr_addPoint(point) {
	   this.currentPolyline.push(point);
	   if (this.currentPolyline.length >= 50) {
	       this.currentPolyline.push(point);
		   var saved = new Array();
		   for (i=0 ; i< this.currentPolyline.length ; i++) saved.push(this.currentPolyline[i]);
	       this.polylines.push(saved);
	       this.currentPolyline = new Array();
	       this.currentPolyline.push(point);
	   }
	}
		
	function PolylineMgr_removePoint() {
	   if (this.polylines.length==0 && this.currentPolyline.length<=1) return;
	   if (this.currentPolyline.length>1) {
	       this.currentPolyline.pop();	   
	   } else {
	       this.currentPolyline = this.polylines.pop();
	       this.currentPolyline.pop();
	       this.currentPolyline.pop();
	   }
	}

// Windowing library	
// Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)

function openHelp(title, url) {
	if (WindowManager.getWindow()) {
	   if (WindowManager.contentUrl==url) {
	       return;
	   } else {
	       WindowManager.close();
	   }
    }
    win2 = new Window('sample3', {className: "default", title: title, width:500, height:300, top:200, left: 200, url: url, zIndex:150, opacity:1, resizable: true})
    win2.setDestroyOnClose();
    win2.setCookie();
    win2.show();
}


var Window = Class.create();
Window.prototype = {
	// Constructor
	// Available parameters : className, title, minWidth, minHeight, maxWidth, maxHeight, width, height, top, left, bottom, right, resizable, zIndex, opacity, 
	//                        hideEffect, showEffect, showEffectOptions, hideEffectOptions, effectOptions, url, draggable, closable, minimizable, maximizable, parent
	initialize: function(id, parameters) {
		this.hasEffectLib = String.prototype.parseColor != null;
		this.minWidth = parameters.minWidth || 100;
		this.minHeight = parameters.minHeight || 20;
		this.maxWidth = parameters.maxWidth;
		this.maxHeight = parameters.maxHeight;
		this.showEffect = parameters.showEffect || (this.hasEffectLib ? Effect.Appear : Element.show);
		this.hideEffect = parameters.hideEffect || (this.hasEffectLib ? Effect.Fade : Element.hide);
		
		this.showEffectOptions = parameters.showEffectOptions || parameters.effectOptions;
		this.hideEffectOptions = parameters.hideEffectOptions || parameters.effectOptions;
		this.draggable = parameters.draggable != null ? parameters.draggable : true;
				  
		var resizable = parameters.resizable != null ? parameters.resizable : true;
		var closable = parameters.closable != null ? parameters.closable : true;
		var minimizable = parameters.minimizable != null ? parameters.minimizable : true;
		var maximizable = parameters.maximizable != null ? parameters.maximizable : true;
		var className = parameters.className != null ? parameters.className : "dialog";
		this.className = className;
		
		var parent = parameters.parent || document.getElementsByTagName("body").item(0);
		this.element = this.createWindow(id, className, parent, resizable, closable, minimizable, maximizable, parameters.title, parameters.url);
		
		// Bind event listener
	    this.eventMouseDown = this.initDrag.bindAsEventListener(this);
	  	this.eventMouseUp   = this.endDrag.bindAsEventListener(this);
	  	this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
	  	this.eventOnLoad = this._getWindowBorderSize.bindAsEventListener(this);
	    //alert("element id = ["+this.element.id + "_top]");
		this.topbar = $(this.element.id + "_top");
		this.bottombar = $(this.element.id + "_bottom");
		//alert("topbar ="+topbar+", bottombar ="+bottombar);
		Event.observe(this.topbar, "mousedown", this.eventMouseDown);
		Event.observe(this.bottombar, "mousedown", this.eventMouseDown);
		Event.observe(window, "load", this.eventOnLoad);
		
		if (this.draggable)  {
			this.bottombar.addClassName("bottom_draggable");
			this.topbar.addClassName("top_draggable");
	    }		
	    
		var offset = [0,0];
		if (resizable) {
		   this.sizer = $(this.element.id + "_sizer");
		   Event.observe(this.sizer, "mousedown", this.eventMouseDown);
	    }	
		var width = parseFloat(parameters.width) || 200;
		var height = parseFloat(parameters.height) || 200;
	
		if (parameters.left != null) {
			this.element.setStyle({left: parseFloat(parameters.left) + offset[0] + 'px'});
			this.useLeft = true;
		}
	
		if (parameters.right != null) {
			this.element.setStyle({right: parseFloat(parameters.right) + 'px'});
			this.useLeft = false;
		}
	
		if (parameters.top != null) {
			this.element.setStyle({top: parseFloat(parameters.top) + 'px'});
			this.useTop = true;
		}
	
		if (parameters.bottom != null) {
			this.element.setStyle({bottom: parseFloat(parameters.bottom) + 'px'});			
			this.useTop = false;
		}
	
	    this.storedLocation = null;
	    
		if (parameters.zIndex)
			this.setZIndex(parameters.zIndex)
	
		this.destroyOnClose = false;
	
	    this._getWindowBorderSize();
		
		this.setSize(width, height);
		
		WindowManager.register(this, parameters.url);	    
		
    },
  
	// Destructor
 	destroy: function() {
	  	Event.stopObserving(this.topbar, "mousedown", this.eventMouseDown);
	  	Event.stopObserving(this.bottombar, "mousedown", this.eventMouseDown);
		Event.stopObserving(window, "load", this.eventOnLoad);
	
		if (this.sizer)
		  Event.stopObserving(this.sizer, "mousedown", this.eventMouseDown);

	 	if(this.iefix) 
			Element.hide(this.iefix);

		var objBody = document.getElementsByTagName("body").item(0);
		objBody.removeChild(this.element);

	},
  	
	// Sets window deleagte, should have functions: "canClose(window)" 
	setDelegate: function(delegate) {
		this.delegate = delegate
	},
	
	// Gets current window delegate
	getDelegate: function() {
		return this.delegate;
	},
	
	// Gets window content
	getContent: function () {
		return $(this.element.id + "_content");
	},
	
	// Sets the content with an element id
	setContent: function(id, autoresize, autoposition) {
		var d = null;
		var p = null;

		if (autoresize) 
			d = Element.getDimensions(id);
		if (autoposition) 
			p = Position.cumulativeOffset($(id));

		var content = this.getContent()
		content.appendChild($(id));
		
		if (autoresize) 
			this.setSize(d.width, d.height);
		if (autoposition) 
		  this.setLocation(p[1] - this.heightN, p[0] - this.widthW);	  
	},
	
	// Stores position/size in a cookie, by default named with window id
	setCookie: function(name, expires, path, domain, secure) {
		name = name || this.element.id;
		this.cookie = [name, expires, path, domain, secure];
		
		// Get cookie
		var value = WindowUtilities.getCookie(name)
		// If exists
		if (value) {
			var values = value.split(',');
			var x = values[0].split(':');
			var y = values[1].split(':');

			this.setSize(parseFloat(values[2]), parseFloat(values[3]));

			this.useLeft = x[0] == "l";
			this.useTop = y[0] == "t";

			this.element.setStyle(this.useLeft ? {left: x[1]} : {right: x[1]});
			this.element.setStyle(this.useTop ? {top: y[1]} : {bottom: y[1]});
		}
	},
	
	// Gets window ID
	getId: function() {
		return this.element.id;
	},
	
	// Detroys itself when closing 
	setDestroyOnClose: function() {
		this.destroyOnClose = true;
	},
	
	// initDrag event
	initDrag: function(event) {
		// Register global event to capture mouseUp and mouseMove
		Event.observe(document, "mouseup", this.eventMouseUp);
  	    Event.observe(document, "mousemove", this.eventMouseMove);
		// Get pointer X,Y
  	    this.pointer = [Event.pointerX(event), Event.pointerY(event)];
		this.doResize = false;
		
		// Check if click on close button, 
		var closeButton = $(this.getId() + '_close');
		if (closeButton && Position.within(closeButton, this.pointer[0], this.pointer[1])) {
		  alert("Close button clicked");
			return;
		}
		this.toFront();

		// Check if click on sizer
		if (this.sizer && Position.within(this.sizer, this.pointer[0], this.pointer[1])) {
			this.doResize = true;
	    	this.widthOrg = this.width;
	    	this.heightOrg = this.height;
	    	this.bottomOrg = parseFloat(this.element.getStyle('bottom'));
	    	this.rightOrg = parseFloat(this.element.getStyle('right'));
		}
		else {
  		if (! this.draggable) 
  		  return;
		}
  	
		// Register global event to capture mouseUp and mouseMove
		//Event.observe(document, "mouseup", this.eventMouseUp);
  	    //Event.observe(document, "mousemove", this.eventMouseMove);
		
		// Add an invisible div to keep catching mouse event over the iframe
  	Event.stop(event);
  },

  // updateDrag event
	updateDrag: function(event) {
   	    var pointer = [Event.pointerX(event), Event.pointerY(event)]; 
   	    
   	       
		var dx = pointer[0] - this.pointer[0];
		
		var dy = pointer[1] - this.pointer[1];
		
		// Resize case, update width/height
		if (this.doResize) {
			this.setSize(this.widthOrg + dx , this.heightOrg + dy);
			
	        dx = this.width - this.widthOrg
	        dy = this.height - this.heightOrg
				
		    // Check if it's a right position, update it to keep upper-left corner at the same position
			if (! this.useLeft) 
				this.element.setStyle({right: (this.rightOrg -dx) + 'px'});
			// Check if it's a bottom position, update it to keep upper-left corner at the same position
			if (! this.useTop) 
				this.element.setStyle({bottom: (this.bottomOrg -dy) + 'px'});
				
			if (this.tmpDiv) {
			     this.tmpDiv.style['width'] = this.width+"px";
			     this.tmpDiv.style['height'] = this.height+"px";
			}
		}
		// Move case, update top/left
		else {
		    // stop overrunning the edge of the screen
		    //x-direction
			if (dx + this.element.offsetLeft + this.width > getWindowWidth()-10) 
			  dx = getWindowWidth()-10 - this.element.offsetLeft - this.width;
			if (dx + this.element.offsetLeft < 0 ) 
			  dx = -this.element.offsetLeft;
            //y-direction
			if (dy + this.element.offsetTop + this.height > getWindowHeight()-50)
			 dy = getWindowHeight() - 50 - this.element.offsetTop - this.height;
			if (dy + this.element.offsetTop < 0 )
			 dy = -this.element.offsetTop;

		    this.pointer = pointer;
  		
			if (this.useLeft) 
				this.element.setStyle({left: parseFloat(this.element.getStyle('left')) + dx + 'px'});
			else 
				this.element.setStyle({right: parseFloat(this.element.getStyle('right')) - dx + 'px'});
			
			if (this.useTop) 
				this.element.setStyle({top: parseFloat(this.element.getStyle('top')) + dy + 'px'});
		    else 
				this.element.setStyle({bottom: parseFloat(this.element.getStyle('bottom')) - dy + 'px'});
		}
		if (this.iefix) 
			this._fixIEOverlapping(); 
			
		this._removeStoreLocation();
        Event.stop(event);
	},

	 // endDrag callback
 	endDrag: function(event) {
		// Release event observing
		Event.stopObserving(document, "mouseup", this.eventMouseUp);
        Event.stopObserving(document, "mousemove", this.eventMouseMove);
        Event.stop(event);
    },

	
	// Creates HTML window code
	createWindow: function(id, className, parent, resizable, closable, minimizable, maximizable, title, url) {
		win = document.createElement("div");
		win.setAttribute('id', id);
		win.className = "dialog";
	 	if (!title)
			title = "&nbsp;";

		helpPanel = "\
		    <div class='"+ className +"_border'>\
	           <div class='"+ className +"_close' id='"+ id +"_close' onclick='WindowManager.close();'> </div>\
	           <div class='"+ className +"_title' id='"+id+"_top'>"+title+"</div>\
               <div class='" +className +"_content' id='"+id+"_content'></div>\
               <div class='"+ className +"_footer' id='"+id+"_bottom'><div id='"+ id + "_sizer' class='"+ className +"_sizer'></div></div>\
            </div>";
                
        win.innerHTML = helpPanel;

		Element.hide(win);
		parent.insertBefore(win, parent.firstChild);

        new Ajax.Request(url,
                         {method: 'get',
              onComplete: function(request) {
		         $(id + "_content").innerHTML = request.responseText;
	          }	
	       }
	    );  		    
		
		if (!closable)
		  Element.hide(id +"_close")
	  	if (!minimizable)
	  	  Element.hide(id +"_minimize")
	  	if (!maximizable)
	  	  Element.hide(id +"_maximize")

		return win;
	},
	
	// Sets window location
	setLocation: function(top, left) {
		if (top < 0)
		    top = 0;
	    if (left < 0)
	        left= 0
			this.element.setStyle({top: top + 'px'});
			this.element.setStyle({left: left + 'px'});
			this.useLeft = true;
			this.useTop = true;
		},
		
	// Sets window size
	setSize: function(width, height) {    
		// Check min and max size
		if (width < this.minWidth)
			width = this.minWidth;

		if (height < this.minHeight)
			height = this.minHeight;
			
		if (this.maxHeight && height > this.maxHeight)
			height = this.maxHeight;

		if (this.maxWidth && width > this.maxWidth)
			width = this.maxWidth;

  	    this.width = width;
		this.height = height;
		this.element.setStyle({width: width + this.widthW + this.widthE + "px"})
		this.element.setStyle({height: height + this.heightN + this.heightS + "px"})

		// Update content height
		var content = $(this.element.id + '_content')
		content.setStyle({height: height  + 'px'});
		content.setStyle({width: width  + 'px'});
	},
	
	// Brings window to front
	toFront: function() {
        this.setZIndex(20);
	},
	
	// Displays window modal state or not
	show: function(modal) {
		this.setSize(this.width, this.height);
		if (this.showEffect != Element.show && this.showEffectOptions )
			this.showEffect(this.element, this.showEffectOptions);	
		else
			this.showEffect(this.element);	
			
        this._checkIEOverlapping();
	},
	
	// Displays window modal state or not at the center of the page
	showCenter: function(modal) {
		this.setSize(this.width, this.height);
		this.center();
		
		this.show(modal);
	},
	
	center: function() {
		var windowScroll = WindowUtilities.getWindowScroll();    
		var pageSize = WindowUtilities.getPageSize();    

        this.setLocation(windowScroll.top + (pageSize.windowHeight - (this.height + this.heightN + this.heightS))/2, 
                     windowScroll.left + (pageSize.windowWidth - (this.width + this.widthW + this.widthE))/2);
        this.toFront();
	},
	
	setZIndex: function(zindex) {
		this.element.setStyle({zIndex: zindex});
	},
	
		
	// Closes a window with its id
	close: function() {
	   alert("Close invoked");
  		this.hide();
    	this.destroy();
	},
	
	
	_checkIEOverlapping: function() {
    if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && (navigator.userAgent.indexOf('Opera')<0) && (this.element.getStyle('position')=='absolute')) {
        new Insertion.After(this.element.id, '<iframe id="' + this.element.id + '_iefix" '+ 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' + 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
        this.iefix = $(this.element.id+'_iefix');
    }
    if(this.iefix) 
			setTimeout(this._fixIEOverlapping.bind(this), 50);
	},

	_fixIEOverlapping: function() {
	    Position.clone(this.element, this.iefix);
	    this.iefix.style.zIndex = this.element.style.zIndex - 1;
	    this.iefix.show();
	},
	
	_getWindowBorderSize: function(event) {
    // Hack to get real window border size!!
    var div = this._createHiddenDiv(this.className + "_n")
		this.heightN = Element.getDimensions(div).height;		
		div.parentNode.removeChild(div)

    var div = this._createHiddenDiv(this.className + "_s")
		this.heightS = Element.getDimensions(div).height;		
		div.parentNode.removeChild(div)

    var div = this._createHiddenDiv(this.className + "_e")
		this.widthE = Element.getDimensions(div).width;		
		div.parentNode.removeChild(div)

    var div = this._createHiddenDiv(this.className + "_w")
		this.widthW = Element.getDimensions(div).width;
		div.parentNode.removeChild(div);
  },
 
  _createHiddenDiv: function(className) {
    var objBody = document.getElementsByTagName("body").item(0);
    var win = document.createElement("div");
		win.setAttribute('id', this.element.id+ "_tmp");
		win.className = className;
		win.style.display = 'none'
		win.innerHTML = ''
		objBody.insertBefore(win, objBody.firstChild)   
		return win
  },
	_storeLocation: function() {
	  if (this.storedLocation == null) {
	    this.storedLocation = {useTop: this.useTop, useLeft: this.useLeft, 
	                           top: this.element.getStyle('top'), bottom: this.element.getStyle('bottom'),
	                           left: this.element.getStyle('left'), right: this.element.getStyle('right'),
	                           width: this.width, height: this.height };
	  }
	},
	
  _restoreLocation: function() {
    if (this.storedLocation != null) {
        this.useLeft = this.storedLocation.useLeft;
        this.useTop = this.storedLocation.useTop;      
        this.element.setStyle(this.useLeft ? {left: this.storedLocation.left} : {right: this.storedLocation.right});
  		this.element.setStyle(this.useTop ? {top: this.storedLocation.top} : {bottom: this.storedLocation.bottom});
		this.setSize(this.storedLocation.width, this.storedLocation.height);      
		this._removeStoreLocation();
    }
  },
  
  _removeStoreLocation: function() {
        this.storedLocation = null;
  }
	
}






// Windows containers, register all page windows
var WindowManager = {
  managedWindow: null,
  contentUrl: null,


  // Gets window from its id
  getWindow: function() {
	  return this.managedWindow;
  },

  // Registers a new window (called by Windows constructor)
  register: function(win, url) {
    this.managedWindow=win;
    this.contentUrl = url;
  },
  
  // Closes a window with its id
  close: function() {
  	//this.managedWindow.hide();
    this.managedWindow.destroy();
    this.managedWindow = null;
  }
  
};







	


var WindowUtilities = {
  // From script.aculo.us
  getWindowScroll: function() {
    var w = window;
      var T, L, W, H;
      with (w.document) {
        if (w.document.documentElement && documentElement.scrollTop) {
          T = documentElement.scrollTop;
          L = documentElement.scrollLeft;
        } else if (w.document.body) {
          T = body.scrollTop;
          L = body.scrollLeft;
        }
        if (w.innerWidth) {
          W = w.innerWidth;
          H = w.innerHeight;
        } else if (w.document.documentElement && documentElement.clientWidth) {
          W = documentElement.clientWidth;
          H = documentElement.clientHeight;
        } else {
          W = body.offsetWidth;
          H = body.offsetHeight
        }
      }
      return { top: T, left: L, width: W, height: H };
    
  }, 
  //
  // getPageSize()
  // Returns array with page width, height and window width, height
  // Core code from - quirksmode.org
  // Edit for Firefox by pHaez
  //
  getPageSize: function(){
  	var xScroll, yScroll;

  	if (window.innerHeight && window.scrollMaxY) {	
  		xScroll = document.body.scrollWidth;
  		yScroll = window.innerHeight + window.scrollMaxY;
  	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  		xScroll = document.body.scrollWidth;
  		yScroll = document.body.scrollHeight;
  	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  		xScroll = document.body.offsetWidth;
  		yScroll = document.body.offsetHeight;
  	}

  	var windowWidth, windowHeight;

  	if (self.innerHeight) {	// all except Explorer
  		windowWidth = self.innerWidth;
  		windowHeight = self.innerHeight;
  	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  		windowWidth = document.documentElement.clientWidth;
  		windowHeight = document.documentElement.clientHeight;
  	} else if (document.body) { // other Explorers
  		windowWidth = document.body.clientWidth;
  		windowHeight = document.body.clientHeight;
  	}	
  	var pageHeight, pageWidth;

  	// for small pages with total height less then height of the viewport
  	if(yScroll < windowHeight){
  		pageHeight = windowHeight;
  	} else { 
  		pageHeight = yScroll;
  	}

  	// for small pages with total width less then width of the viewport
  	if(xScroll < windowWidth){	
  		pageWidth = windowWidth;
  	} else {
  		pageWidth = xScroll;
  	}

  	return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
  },
  
  	setCookie: function(value, parameters) {
    document.cookie= parameters[0] + "=" + escape(value) +
      ((parameters[1]) ? "; expires=" + parameters[1].toGMTString() : "") +
      ((parameters[2]) ? "; path=" + parameters[2] : "") +
      ((parameters[3]) ? "; domain=" + parameters[3] : "") +
      ((parameters[4]) ? "; secure" : "");
  },

  getCookie: function(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
    } else {
      begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
      end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
  }
}


  
	
	