function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
		if(typeof(arr) == 'object') { //Array/Hashes/Objects
 			for(var item in arr) {
  				var value = arr[item];
 
  				if(typeof(value) == 'object') { //If it is an array,
   					dumped_text += level_padding + "'" + item + "' ...\n";
   					dumped_text += dump(value,level+1);
  				} else {
  					 dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  				}
 			}
		} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
} 



/*
var greet = 'hello'; 
var name = 'john';
alert(qq('$greet there $name!'));
*/


function qq(str) {
  while (str.indexOf('$') != -1) {
    str = str.replace(/\$[^\s\W]+/,eval(str.match(/\$([^\s\W]+)/,"$1")[1]));
  }
  return str;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							R E S I Z E   W I N D O W
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
ResizeWindow(setWidth,setHeight) 
written by Matt Pressnall 04/15/05

What does it do?
It will resize the current window to supplied dimensions 

How do I use it?
(call to JS file needs to be on a page only once)
<script language="JavaScript"> 
var setWidth = 500;
var setHeight = 500;
ResizeWindow(setWidth,setHeight);
</script> 

Parameters:
setWidth - the window width you want
setHeight - the window height you want

<a href="javascript:ResizeWindow(222,222)">adf</a>

*/

function ResizeWindow(windowWidth,windowHeight,heightOffset) {	
	
	self.window.resizeTo(windowWidth,windowHeight);
	
	var availableWidth = screen.availWidth;
	var availableHeight = screen.availHeight;
	
	var windowLeft = ((availableWidth - windowWidth) / 2);
	var windowTop = ((availableHeight - windowHeight) / 2);
			
	self.window.moveTo(windowLeft,(windowTop + heightOffset));
	
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							R E D I R E C T   O P E N E R   W I N D O W
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/*
RedirectOpenerWindow(url,shouldCloseSelf) 
written by Matt Pressnall 05/16/05

What does it do?
Changes the URL of the opener / parent window and has the ability of closing the child / pop-off window if desired.

How do I use it?
(call to JS file needs to be on a page only once)
<script type="text/javascript" src="/js/standardFunctionality/RedirectOpenerWindow.js"></script> 
<a href="javascript:RedirectOpenerWindow('http://www.pressnall.com','closeSelf')">Will close pop-off window</a>
<a href="javascript:RedirectOpenerWindow('http://www.pressnall.com',)">Will not close anything</a>

Parameters:
url - the URL you want the opener to go to
shouldCloseSelf	(optional) - if you specify a second parameter, the pop off window will close
*/


function RedirectOpenerWindow(url,shouldCloseSelf){
	var isOpenerOpen;
	
	// test if opener window is open
	if(self.opener){
		if(! self.opener.closed){
			isOpenerOpen = 1;
		}
	} 
	
	// the opener is open...refresh the data in that window
	if(isOpenerOpen){
		self.opener.location.href = url;
		if(shouldCloseSelf){
			self.close();
		}
		self.opener.focus();
	// there is no opener window, open a new window
	} else {
		var myWindow = window.open(url,"something");
		if(shouldCloseSelf){
			if(this){
				self.opener = this;
				self.close();
			}
			if(self.parent){
				self.close();
			}
		}
		myWindow.focus();
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							P O P O F F    W I N D O W
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
PopoffWindow(windowName,windowWidth,windowHeight,URL,shouldResize,shouldScroll) 
written by Matt Pressnall 10/24/03

What does it do?
Pops off (or up) a window.  If the window has been called and resides in the background and someone calls it again, it brings the window to the forefront (which most popup code doesn't do).

How do I use it?
(call to JS file needs to be on a page only once)
<script src="/js/standardFunctionality/PopoffWindow.js"></script> 
<a href="javascript:PopoffWindow('test',300,300,'http://www.pressnall.com','no','no')">text</a>

Parameters:
windowName - the name of the window.  Alphabetic characters only!
windowWidth	
windowHeight
URL
shouldResize - yes|no
shouldScroll - yes|no
*/


function PopoffWindow(windowName,windowWidth,windowHeight,URL,shouldResize,shouldScroll) {
	var availableWidth = screen.availWidth;
   	var availableHeight = screen.availHeight;

   	var windowLeft = (availableWidth - windowWidth) / 2;
   	var windowTop = ((availableHeight - windowHeight) / 2) - 16;
   		
	newWindow = window.open(URL,windowName,"width=" + windowWidth + ",height=" + windowHeight + ",left=" + windowLeft + ",top=" + windowTop + ",location=no,resizable=" + shouldResize + ",scrollbars=" + shouldScroll + ",toolbar=no");
	newWindow.focus();
}




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							L O A D    X M L
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/*
LoadXML(xmlFile)
written by Matt Pressnall 09/26/2005

What does it do?
Reads an XML file (cross browser) and returns an XML document

How do I use it?
(call to JS file needs to be on a page only once)
<script src="/js/standardFunctionality/LoadXML.js"></script> 
var xmlDocument = LoadXML("somexml.xml");

Parameters:
xmlFile - with or without HTTP...must be accessible by web browser, though

<buyingPhotos>
	<buyingPhoto>
 		<image>/art/photography/buying_photos/1.jpg</image> 
  	</buyingPhoto>
	<buyingPhoto>
  		<image>/art/photography/buying_photos/2.jpg</image> 
  	</buyingPhoto>
</buyingPhotos>


var xmlDocument = LoadXML("/xml/photography/buyingPhotos.xml");
var photos = xmlDocument.getElementsByTagName("buyingPhoto");
var numPhotos = photos.length;
var randomNumber = (Math.round((numPhotos - 1) * Math.random()));
var randomPhoto = photos[randomNumber];
var image = randomPhoto.getElementsByTagName("image")[0].firstChild.nodeValue; 
document.write('<img src="' + image + '" width="140" height="110" alt="" class="pic">');


*/


function LoadXML (xmlFile) {
    var httpRequest;
    if (typeof ActiveXObject != 'undefined') {
      httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
    }
    else if (typeof XMLHttpRequest != 'undefined') {
      httpRequest = new XMLHttpRequest();
    }
    if (httpRequest) {
      httpRequest.open('GET', xmlFile, false);
      httpRequest.send(null);
      return httpRequest.responseXML;
    }
    else {
      return void 0;
    }
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							G E T   B R O W S E R   O S   V E R S I O N
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/*
GetBrowserOSVersion() 
written by Matt Pressnall 12/09/04

What does it do?
Get's the browser name, version, and OS for a client computer.  Replaces the older "getOSBrowserVersion" that doesn't correctly ID the version because browsers changed the way they represented version info

How do I use it?
<script src="/js/standardFunctionality/GetBrowserOSVersion.js"></script>
<SCRIPT LANGUAGE="JavaScript">
GetBrowserOSVersion();
</SCRIPT>
In global JS variables you will have access to:
browser - can return "Microsoft Internet Explorer", "Netscape", "Opera", etc...
version - can return "4","5", etc...
os      - can return "win" or "mac"
*/


function GetBrowserOSVersion() {
	var is_win   = ( (navigator.userAgent.toLowerCase().indexOf("win")!=-1) || (navigator.userAgent.toLowerCase().indexOf("16bit")!=-1) );
	var is_mac    = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1);

	var agt=navigator.userAgent;
	var lcAgt = agt.toLowerCase();
	var appname = navigator.appName;
	var appversion = navigator.appVersion;
	
	var full_version = parseFloat(appversion);
	var major_version = parseInt(appversion);

	// get version info for IE
	if ((offset=lcAgt.indexOf("msie"))!=-1) {
		full_version = parseFloat(agt.substring(offset+5,agt.length));
		major_version = parseInt(''+full_version);
	}
	
	// get version info for Opera
	if ((offset=lcAgt.indexOf("opera"))!=-1) {
	 	full_version = parseFloat(agt.substring(offset+6,agt.length));
	 	major_version = parseInt(''+full_version);
		appname = "Opera";
	}
	
		// get version info for Opera
	if ((offset=lcAgt.indexOf("safari"))!=-1) {
	 	major_version = parseFloat( lcAgt.substring( lcAgt.lastIndexOf('safari/') + 7 ) );
		appname = "Safari";
	}
	
	// get version info for firefox
	if((offset=lcAgt.indexOf("firefox")) != -1){
		var blah = navigator.userAgent;
		var rev = blah.replace(/^.*Firefox\//g, "");
		appname = "Firefox";
		major_version = rev;
	}
	
	
	browser = appname;
	version = major_version;
	os = "";
	
	if(is_win){
		os = "win";
	}
	if(is_mac){
		os = "mac";
	}

}




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//						G E T   A N D   S E T   F O R M    E L E M E N T S
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*

Allows you to get and set form element values.


var theFormElement = document.getElementById("program");
SetFormElementValue(theFormElement,"some value");	


*/

function SetFormElementValue(formElement, value){
	switch(formElement.type){
		case 'undefined': return;
		case 'radio': formElement.checked = value; break;
		case 'checkbox': formElement.checked = value; break;
		case 'select-one': 
			for(var x=0; x < formElement.length; x++){ 
				if(formElement[x].value == value){
					formElement.selectedIndex = x;
				}
			}
			break;
		case 'select-multiple':
			for(var x=0; x < formElement.length; x++){ 
				formElement[x].selected = value[x];
			}
			break;

		default: formElement.value = value; break;
	}
}


function GetFormElementValue(formElement){
	var type;
	if(formElement.length != null){ 
		type = formElement[0].type;
	}
	if((typeof(type) == 'undefined') || (type == 0)){ 
		type = formElement.type;
	}

	switch(type){
		case 'undefined': return;

		case 'radio':
			var radioLength = formElement.length;
			if(radioLength == undefined){
				if(formElement.checked){
					return formElement.value;
				} else {
					return "";
				}
			}
			for(var i = 0; i < radioLength; i++) {
				if(formElement[i].checked) {
					return formElement[i].value;
				}
			}
			return "";
		case 'select-multiple':
			var myArray = new Array();
			for(var x=0; x < formElement.length; x++) 
				if(formElement[x].selected == true)
					myArray[myArray.length] = formElement[x].value;
			return myArray;

		case 'checkbox': 
			var checkLength = formElement.length;
			if(checkLength == undefined){
				if(formElement.checked){
					return formElement.value;
				} else {
					return "";
				}
			}
			for(var i = 0; i < checkLength; i++) {
				if(formElement[i].checked) {
					return formElement[i].value;
				}
			}
			return "";
		
	
		default: return formElement.value;
	}
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							F O R M A T   D A T E
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
FormatDate(dateobj,format) 
written by Matt Pressnall 11/05/04

What does it do?
You pass a date object and the format you want the date outputted and it'll do it for you.

How do I use it?
(call to JS file needs to be on a page only once)
<script src="/js/standardFunctionality/FormatDate.js"></script> 
<script language="JavaScript"> 
	dateObj = new Date(document.lastModified);
	alert(FormatDate(dateObj,"!Day, !d !Mon !yyyy !Hour:!Min:!Sec !AMPM"));
</script> 

</SCRIPT>

Parameters:
dateObj - a date object
format - the format you want date outputted	
<a href="/test_form/formatCodes.html" target="codes">Format Codes</a>


*/


function FormatDate(dateobj,format){

	var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var mons = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var dys = new Array("Sun","Mon","Tues","Wed","Thurs","Fri","Sat");
	
	
	var m = dateobj.getMonth() + 1;
	var d = dateobj.getDate();
	var yy = dateobj.getYear() % 100;
	
	var yyyy;
	if(dateobj.getYear() > 1900){
	  yyyy = dateobj.getYear();
	} else {
	  yyyy = 1900 + dateobj.getYear();
	}
	
	var Day = days[dateobj.getDay()];
	var Dy = dys[dateobj.getDay()];
	var Month = months[m-1];
	var Mon = mons[m-1];
	
	var mm;
	if(m.toString().length < 2){
	  mm = "0" + m + "";
	} else {
	  mm = m;
	}
	var dd;
	if(d.toString().length < 2){
		dd = "0" + d + "";
	} else {
	  dd = d;
	}
	
	var Hour = dateobj.getHours();


	var ampm  = "am";	
	var AMPM  = "AM";	
	var HHour;
	if(Hour > 12){
		Hour = Hour - 12;
		HHour = "0" + Hour;
		amPM = "pm";
		AMPM  = "PM";	
	}
	if(Hour == "0"){
		Hour = 12;
		HHour = 12;
	}
	
	var Min = dateobj.getMinutes();
	var Sec = dateobj.getSeconds();
	
	

	theDateString = format;
	
	ReplaceHolderWithValue("!Month",Month);
	ReplaceHolderWithValue("!Mon",Mon);
	ReplaceHolderWithValue("!mm",mm);
	ReplaceHolderWithValue("!m",m);
	ReplaceHolderWithValue("!Day",Day);
	ReplaceHolderWithValue("!Dy",Dy);
	ReplaceHolderWithValue("!dd",dd);
	ReplaceHolderWithValue("!d",d);
	ReplaceHolderWithValue("!yyyy",yyyy);
	ReplaceHolderWithValue("!yy",yy);
	
	ReplaceHolderWithValue("!Hour",Hour);
	ReplaceHolderWithValue("!HHour",HHour);
	ReplaceHolderWithValue("!Min",Min);
	ReplaceHolderWithValue("!Sec",Sec);
	ReplaceHolderWithValue("!ampm",ampm);
	ReplaceHolderWithValue("!AMPM",AMPM);
	
	return theDateString;
};

function ReplaceHolderWithValue(holder,value){
	indexOfIt = theDateString.indexOf(holder);
	if(indexOfIt >= 0){
	  holderIt = theDateString.substring(0, indexOfIt);
	  valueIt = theDateString.substring(indexOfIt + holder.length, theDateString.length);
	  theDateString = holderIt + value + valueIt;
	  ReplaceHolderWithValue(holder,value);
	  return true;
  	}
	return false;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							C O N S T R A I N   W I N D O W   S I Z E
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
ConstrainWindowSize(setWidth,setHeight,buffer) 
written by Matt Pressnall 04/15/05

What does it do?
It will check what the current size of a window is and will resize it if it is not within the right dimensions...A buffer can be applied so that there can be a little give and take to account for different browsers and OSs

How do I use it?
(call to JS files need to be on a page only once)

<script type="text/javascript" src="/js/standardFunctionality/GetBrowserOSVersion.js"></script> 
<script type="text/javascript" src="/js/standardFunctionality/ConstrainWindowSize.js"></script> 
<script type="text/javascript" src="/js/standardFunctionality/ResizeWindow.js"></script> 
<script language="JavaScript1.2"> 
var setWidth = 500;
var setHeight = 500;
var buffer = 10;
</script> 
<body onload="ConstrainWindowSize(setWidth,setHeight,buffer);"> 

Parameters:
setWidth - the width you want the window to be
setHeight - the height you want the window to be	
buffer - the amount of pixels you are willing to let the window to be over or under...can be 0 if you want
*/

function ConstrainWindowSize(setWidth,setHeight,buffer){
	GetBrowserOSVersion();
	
	var windowWidth;
	var windowHeight;
	var shouldResize;
	
	
	// get the width of the browser window
	if(browser == "Microsoft Internet Explorer"){
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} else {
		windowWidth = parent.innerWidth;
		windowHeight = parent.outerHeight;
	}
	
	// width is the only way to determine if this is popped off or not
	if(windowWidth){
		// check the window size
		if((windowWidth  > (setWidth + buffer)) || (windowWidth  < (setWidth - buffer))){
			shouldResize = 1;
		}
	}
	
	// make sure we want to resize
	if(shouldResize){
		// can figure out more info from non-ie browsers
		if(browser != "Microsoft Internet Explorer"){
			// already has missing location bar
			if(! window.locationbar.visible){
				shouldResize = 0;
			}
		}
	}
	
	// resizing so need to make the window a little bigger since it has toolbars and whatnot
	if(shouldResize){
		setWidth = setWidth + buffer;
		setHeight = setHeight + buffer + buffer;
		ResizeWindow(setWidth,setHeight);
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							C O N N E C T
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function Connect() {
	var xmlhttp = false;
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(error) { 
		try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(error) { 
			try { xmlhttp = new XMLHttpRequest(); }
			catch(error) { xmlhttp = false; }
		}
	}
	if (! xmlhttp) return null;
	this.connect = function(url,method,parameters,doneFunction) {
		if (! xmlhttp) return false;
		
		method = method.toUpperCase();
		if (method == "GET") {
			xmlhttp.open(method,url+"?"+parameters,true);
			parameters = "";
		} else {
			xmlhttp.open(method,url,true);
			xmlhttp.setRequestHeader("Method","POST "+url+" HTTP/1.1");
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				doneFunction(xmlhttp);
			}
		};
		xmlhttp.send(parameters);
		
		return true;
	};
	return this;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//							C A N   S E T   C O O K I E S
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/*
CanSetCookies() 
written by Matt Pressnall 10/24/03

What does it do?
Lets you know if a user can set cookies on their local computer -- only works if they have JS turned on.  Duh.

How do I use it?
<script src="/js/standardFunctionality/CanSetCookies.js"></script>
<SCRIPT LANGUAGE="JavaScript">
var canSetCookies = CanSetCookies();
</SCRIPT>
It will return true if it's true or false if it is false.
*/


function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function CanSetCookies(){

	var appname = navigator.appName;
	// test for IE and then check if it can set cookies cuz IE reports it always can even if it can't
	if(appname == "Microsoft Internet Explorer"){
		var today = new Date();
		var zero_date = new Date(0,0,0);
		today.setTime(today.getTime() - zero_date.getTime());
		
		var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
		var expires_date = new Date(todays_date.getTime());
		
		Set_Cookie("CanSetCookie","true",expires_date);
		var canSetCookie = Get_Cookie("CanSetCookie");
		Delete_Cookie('CanSetCookie');
		return canSetCookie;
	// other browsers, just ask them nicely and they tell you
	} else {
		var canSetCookie=(navigator.cookieEnabled)? true : false

		if (typeof navigator.cookieEnabled=="undefined" && !canSetCookie){ 
			document.cookie="testcookie"
			canSetCookie=(document.cookie.indexOf("testcookie")!=-1)? true : false
		}
		return canSetCookie;
	}
}

