(function(page) {

	// public
	page.gotourl = function(url,params) {
		// Version: 2009 05 13
		// get location
		if (typeof params == 'object') {
			params = '?'+private.objtoqstring(params);
		} else {
			params = '';
		}
		// go to location
		window.location.href = url+params;
	}
	page.downloadurl = function(url,params) {
		// Version 2010 01 25
		// create a new iframe
		var iframeobj = document.createElement('iframe'); // create the iframe
		// create a unique name for the iframe
		var iframeidname = "frame"+new Date().getTime(); // unique idname for this iframe
		iframeobj.id = iframeidname;
		iframeobj.name = iframeidname;
		// style the iframe so that it is invisible and doesn't get in the way
		iframeobj.style.visibility='hidden'; 
		iframeobj.style.position='absolute'; 
		iframeobj.style.zIndex = '1000'; 
		iframeobj.style.top='0'; 
		iframeobj.style.left='0'; 
		// remove iframe handler
		var load_handler = function() { setTimeout(function(){ document.body.removeChild(iframeobj) },1); }
		// attach success and remove functions for IE
		if (iframeobj.attachEvent) iframeobj.attachEvent('onload',load_handler); 
		// attach success and remove functions for non-IE browsers			
		if (iframeobj.addEventListener)	iframeobj.addEventListener('load',load_handler,false);
		// get location
		if (typeof params == 'object') { params = '?'+private.objtoqstring(params); } 
		else { params = ''; }
		// change iframe src to go to url
		iframeobj.src = url+params;
		// attach the iframe to the page body
		document.body.appendChild(iframeobj); 
		// prevent new window in IE
	 	if(self.frames[iframeidname].name != iframeidname) { self.frames[iframeidname].name = iframeidname; }
		// prevent new window in safari 
		iframeobj.style.display='block';					
	}
	page.openurlwindow = function(url) {
		// Version: 2009 06 22
		// args
		var params = {};
		var windowname;
		var windowoptions;
		for(var i=1; i<arguments.length;i++) {
			var arg = arguments[i];
			if (i<=4 && (typeof arg != 'object' || arg == null)) {
				if (typeof windowname == 'undefined') { windowname = arg; }
				else if (typeof windowoptions == 'undefined') { windowoptions = arg; }
				continue;
			}
			else if (i<=4 && typeof arg == 'object') {
				params = arg;
				continue;
			}
			alert('Bad arguments for page.openpagewindow(actionname[,params][,windowname][,windowoptions])');
			return;
		}
		// params
		if (typeof params == 'object' && params != null) {
			var count=0; 
			for(index in params) { count++; }
			if (count>0) {
				params = '?'+private.objtoqstring(params);				
			} else {
				params = '';				
			}
		} else {
			params = '';
		}	
		url = url+params;
		// url
		// open window for location
		if (windowname==null && windowoptions==null) {
			var win = window.open(url);			
		} else if (windowoptions==null) {			
			var win = window.open(url,windowname);
		} else if (windowname==null) {	
			// note: you must use '' in order for IE to let you change the name of the window afterwards
			var win = window.open(url,'',windowoptions);			
		} else {
			var win = window.open(url,windowname,windowoptions);			
		}
		if (!win) { alert('A popup blocker has blocked this window from opening. Please disable your popup blocker'); return; }
		if (win) { win.focus(); }
		
	}
	
	// private
	var private = {};
	private.objtoqstring = function(obj, path) {
		// Version: 2009 06 19
		var result = []; 
		if (!path) path = [];
		var indexcount = 0;
		for(index in obj) {
			if (obj[index]==null) { continue; }
			indexcount++;
			path.push(index);
			if (typeof(obj[index])!=='object') { 
				var front = path[0];
				var rest = path.slice(1).join('][');
				if (rest!='') { 
					var name = front+"["+rest+"]"; 
				}
				else { 
					var name = front 
				};
				if (typeof obj[index] == 'boolean') {
					obj[index] = obj[index] ? 1 : 0;
				}
				if (typeof u == 'function') {
					var topush = ""+u(name)+"="+u(obj[index]);
					result.push( topush );
				} else {
					result.push( name+"="+obj[index] );					
				} 
			}
			if (typeof(obj[index])=='object') {
				result.push( private.objtoqstring(obj[index],path) );
			}
			path.pop();
		}
		if (indexcount==0) {
			var front = path[0];
			var rest = path.slice(1).join('][');
			if (rest!='') { 
				var name = front+"["+rest+"]"; 
			}
			else { 
				var name = front+"" 
			};			
			var topush = ""+u(name)+"=";
			result.push( topush );
		}
		return result.join('&');
	}

})(window.page = (window.page) ? window.page : {});