
document.write('<script type="text/javascript" src="js/lib/standard.scripts.js"></script>');
document.write('<script type="text/javascript" src="js/lib/sortable.table.js"></script>');
/*
document.write('<script type="text/javascript" src="js/lib/moo.prototype.lite.js"></script>');
document.write('<script type="text/javascript" src="js/lib/moo.fx.js"></script>');
document.write('<script type="text/javascript" src="js/lib/moo.fx.pack.js"></script>');
document.write('<script type="text/javascript" src="js/lib/moo.ajax.js"></script>');
*/

document.write('<script src="js/lib/prototype.js" type="text/javascript"></script>');
document.write('<script src="js/lib/scriptaculous.js?load=effects" type="text/javascript"></script>');



function showReqFields() {
	var input_val = document.forms.updateform.document_location.value;
	divState('url_space', 'none');
	divState('file_space', 'none');

	if(input_val == "url") {
		divState('url_space', 'block');
	} else if(input_val == "file") {
		divState('file_space', 'block');
	}

}


function toggleDivState(div) {
	if (document.getElementById) {

		hza = document.getElementById(div);
		myState = hza.style.display;
		alert(myState);

		if(myState == 'none') {
			alert("setting block");
			hza.style.display = 'block';
		}
		else {
			alert("setting none");
			hza.style.display = 'none';
		}
	}
}


function divState(div, myState) {
	if (document.getElementById) {

		hza = document.getElementById(div);

		if(myState == 'none') {
			hza.style.display = 'none';
		}
		else {
			hza.style.display = 'block';
		}
	}
}

function getWindowSize(returnParam) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  if(returnParam == 'height') {
  return myHeight;
  } else {
  	return myWidth;
  }
}

function changeViewport() {
	//alert("exec");
	if (document.getElementById) {
		var groundheight = getWindowSize('height');
		var groundwidth = getWindowSize('width');

		if (groundheight > 0 && document.getElementById('wrapquestions')) {
			//alert("setting height = "+groundheight);
			var groundElement = document.getElementById('wrapquestions');
			groundElement.style.height = groundheight-220 + 'px';

			var groundElement = document.getElementById('results-box');
			groundElement.style.height = groundheight-220 + 'px';

			//var groundElement = document.getElementById('pageWrapper');
			//groundElement.style.height = groundheight-10 + 'px';

		}
	}
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function submitForm() {

	var theform = document.forms['surveyform']
	var reqobj = formData2QueryString(theform);

    http.open('get', 'interventions.php?action=search&sub=quick&'+reqobj);

    http.onreadystatechange = handleResponse;
    http.send(null);


}


function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
        document.getElementById('results-box').innerHTML = response;
       //new Effect.Highlight('results-box',{endcolor:'#ffffff', duration: 2});
       //new Effect.Pulsate('results-box', {duration:'.5', pulses:'1'});

    }
}




function formData2QueryString(docForm) {

	var strSubmitContent = '';
	var formElem;
	var strLastElemName = '';

	for (i = 0; i < docForm.elements.length; i++) {

		formElem = docForm.elements[i];
		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
				strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				break;

			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
				}
				break;

			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == strLastElemName) {
						// Strip of end ampersand if there is one
						if (strSubmitContent.lastIndexOf('&') == strSubmitContent.length-1) {
							strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
						}
						// Append value as comma-delimited string
						strSubmitContent += ',' + escape(formElem.value);
					}
					else {
						strSubmitContent += formElem.name + '=' + escape(formElem.value);
					}
					strSubmitContent += '&';
					strLastElemName = formElem.name;
				}
				break;

		}
	}

	// Remove trailing separator
	strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
	return strSubmitContent;
}

