/* --------------------- Utility functions --------------------------------------------------------------------------------------*/
function newWindow(theLink){
    var theURL = theLink.href;
	pdfWindow=window.open(theURL, 'newWin', 'width=700,height=500,Menubar=yes,Toolbar=no,Location=no');
}

function getCSSProp (myElement, prop) {
    var realStyle = null;
    if(myElement.currentStyle){
        realStyle = myElement.currentStyle[prop];
    } else if (document.defaultView && document.defaultView.getComputedStyle) {
	    prop = prop.replace(/([A-Z])/g,"-$1");
	    prop = prop.toLowerCase();
	    return document.defaultView.getComputedStyle(myElement,null).getPropertyValue(prop);
    }
    if(realStyle == "auto"){
        realStyle = myElement.offsetHeight;
    }
    return realStyle;
}

/* --------------------- Ajax functions (implementation presented by Jeremy Keith in "Bulletproof Ajax") ------------*/

// Provides abstraction for xml object
function getHTTPObject(){
	var xhr = false;
	if(window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		try{
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				xhr = false;
			}
		}
	}
	return xhr;
}

// Determines when response is ready
function displayResponse(request){
	if(request.readyState == 4){
		if(request.status == 200 || request.status == 304){
			return true;
		}
	}
}

// Initiates request (example denotes a GET request, but it's easy to implement a POST request)
function submitRequest(file){
	var request = getHTTPObject();
	if(request){
		request.onreadystatechange = function(){
			displayResponse(request);
		};
		request.open("GET", file, true);
		request.send(null);
	}
}

/* --------------------- WireUp functions -----------------------------------------------------------------------------------------*/
function wireNewWindows(){
	if(document.getElementsByTagName){
		var theAnchorLinks = document.getElementsByTagName("a");
		for(var i = 0; i<theAnchorLinks.length; i++){
			var theCurrentNode = theAnchorLinks[i];
			if(theCurrentNode.className.indexOf("new_window") != -1){
				theCurrentNode.onclick = function(){
					newWindow(this);
					return false;
				}
			}
		}
	}else{
		return false;
	}
}

/* --------------------- Set up functions -----------------------------------------------------------------------------------------*/
function setUp(){
	//add events
	wireNewWindows();
}