var req;
var checkbox;
var page = "";
var className = "";
var baseDir = 'http://www.dabsmyla.com/';

/////////////////////////////////////////////////////////////////////////////////////////
//XMLHTTPREQUEST FUNCTIONS_______________________________________________________________
function loadXMLDoc(url) {
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open('GET', url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject('Microsoft.XMLHTTP');
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open('GET', url, true);
			req.send();
		}
	}
}

//callBackFunction is set (as a string) as you send XML request and is called on response
var callBackFunction = "";

//processes request
function processReqChange() {
	// only if req shows 'loaded'
	if (req.readyState == 4) {
		// only if 'OK'
		if (req.status == 200) {
			eval(callBackFunction);
			req.stuff = "ee";
		}else{
			alert(req.statusText);
		}
	}
}

//sets the content and vis of ajax_status
function updateStatus(content, vis){
	document.getElementById('ajax_status').innerHTML = content;
	document.getElementById('screen_dimmer').style.display = vis;
}

/////////////////////////////////////////////////////////////////////////////////////////
//TO KEEP FUNCTIONS_______________________________________________________________

//CANCEL/SUBMIT PROMPT******************************************
function cancelPrompt(){
	document.getElementById(theTargetId).innerHTML = '';
	document.getElementById(theTargetId).style.display = 'none';
}
function submitPrompt(callFunction){
	if(event.keyCode == 13){
		eval(callFunction);
	}
}

//XMLHTTPREQUEST CONTENT, INSERT INTO AN ELEMENT***************
var theTargetId = '';
function getContent(theUrl, target){
	var requestUrl = baseDir + theUrl;
	theTargetId = target;
	callBackFunction = "resolveGetContent()";
	updateStatus('Loading...', 'block');
	loadXMLDoc(requestUrl);
//	alert(requestUrl);
}
function resolveGetContent() {
	updateStatus('', 'none');
	//***************** check for failed at start and print error string
	if (req.responseText.substr(0,6) == 'failed') {
		alert(req.responseText.substr(8));
		checkbox.checked = !checkbox.checked;
	} else {
		//first, seperate the javascript
		var splitContent = req.responseText.split("END THE JAVASCRIPT BIT");
		var javascriptContent = splitContent[0];
		var content = splitContent[1];
		//then insert the content
		document.getElementById(theTargetId).innerHTML = '';
		document.getElementById(theTargetId).innerHTML = content;
		document.getElementById(theTargetId).style.display = 'block';
		//then run the javascript
		eval (javascriptContent);
	}
}

//CLOSE ANYTHING******************************
function ungetContent(target){
	document.getElementById(target).innerHTML = '';
	document.getElementById(target).style.display = 'none';
}

//RESIZE DIV********************
function resizeDiv(width, height, target){
	target = document.getElementById(target);
	newWidth = width;
	newHeight = height + 80;
	screenHeight = document.documentElement.clientHeight;
	if(screenHeight < (newHeight + 160))
	{
		newHeight = (screenHeight - 100);
		//target.style.margin = "10px auto 0 auto";
	}
	target.style.width = newWidth + 'px';
	target.style.height = newHeight + 'px';
	//target.style.left = Math.round((screenWidth - newWidth) / 2);
}