/* Miscellaneous functions */

//var $j = jQuery.noConflict(); // prevents jquery form conflcting with mootools

function createAjaxObj(){
var httprequest = false;
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		httprequest = new XMLHttpRequest();
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml');
	}
	else if (window.ActiveXObject){ // if IE
		try {
			httprequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try {
				httprequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
			}
		}
	}
return httprequest;
}

function pagepop() {
	var ajaxOK = createAjaxObj();
	if (!ajaxOK) {}
	else if (ajaxOK) {
		ajaxOK.open("GET", "Survey_page/Survey_template.html");
		
		ajaxOK.onreadystatechange = function() {
			if (ajaxOK.readyState == 4) {
				var innerdiv = ajaxOK.responseText;
				var blckstart = innerdiv.indexOf('<form');
				var blckend = innerdiv.indexOf('</form', blckstart);
				innerdiv = innerdiv.slice(blckstart, blckend);
				$("#pagecontainer").append(innerdiv);
			}
		}
		ajaxOK.send(null);
	}
}

// this will clear the text boxes before someone types
function cleartext() {
	var tfields = $("textarea");
	tfields.click(function () {
	var innode = $(this).html();
	var tstring = "Type here.";
	if(innode == tstring)
	{
		$(this).html("");
	}
	});
}

/* rollover functions for the navigation tabs */
function setupRollover(thisImage) {
	thisImage.mouseout(function(){
		$(this).attr("src", function(){ return "images/default_page/" + this.id + ".png";});
	});
	thisImage.mouseover(function(){
		$(this).attr("src", function(){ return "images/default_page/" + this.id + "_active.png";});
	});
	}

function rolloverInit() {
	var rollim = $("img");
	var regexpr = /.*_active$/gi;
	for (var i=0; i < rollim.length; i++){
			if(regexpr.test(rollim.eq(i).attr('class'))) {
				setupRollover(rollim.eq(i));
		}
	}
}

function dataroll() {
		$("div.dbasewrap").html('<a href="databases.asp"><img width="110" height="30" class="viewdb_active marginbottom" id="viewdb" alt="Click this button for Library Databases" src="images/default_page/viewdb.png"/></a>');
}



/* This fixes the position of the centercontent element, since it comes directly after a relatively positioned element.*/
/*
function fixhgt() {
	var datid = $("h2#pagetitle").text();
	var orhgt = $("div.low_lft_col").height()
	if(navigator.userAgent.indexOf("MSIE", 0) != -1 && datid == "Databases") {
		$("div#centercontent").css('margin-top' , '-' + orhgt + 'px');
	}
}
*/

//$(document).ready(fixhgt);
$(document).ready(dataroll);
$(document).ready(rolloverInit);
