// -----------------
// jQUERY
// -----------------
$(document).ready(function () {
	$('#loadCarousel').show();
	$('#mycarousel').jcarousel({
		auto: 8,
		wrap: 'circular',
		animation: 'slow',
		scroll: 1,
		easing: 'linear',
		initCallback: mycarousel_initCallback
	});
	$(".itineraryPop").colorbox({ scrolling: false, overlayClose: false });
	$(".btnRegister").colorbox({ innerHeight: '500px' });
	contestMonth();
});
// -----------------
// CONTEST MONTH
// -----------------
function contestMonth() {
	var curentDate = new Date();
	var curentMonth = new Array(12);
	curentMonth[0] = "January";
	curentMonth[1] = "February";
	curentMonth[2] = "March";
	curentMonth[3] = "April";
	curentMonth[4] = "May";
	curentMonth[5] = "June";
	curentMonth[6] = "July";
	curentMonth[7] = "August";
	curentMonth[8] = "September";
	curentMonth[9] = "October";
	curentMonth[10] = "November";
	curentMonth[11] = "December";
	var thisMonth = curentMonth[curentDate.getMonth()];
	$(".monthlycontest").addClass(thisMonth + "contest");
	$(".fontface .monthlycontest").html(thisMonth + " Contest");
};
// -----------------
// CAROUSEL
// -----------------
 function mycarousel_initCallback(carousel) {
     carousel.buttonNext.bind('click', function () {
         carousel.startAuto(0);
     });
     carousel.buttonPrev.bind('click', function () {
         carousel.startAuto(0);
     });
     carousel.clip.hover(function () {
         carousel.stopAuto();
     }, function () {
         carousel.startAuto();
     });
 };
        

// -----------------
// BROWSER DETECTION
// -----------------
function detect() {
	// simplify things
	var agent 		= navigator.userAgent.toLowerCase();
	
	// detect platform
	this.isMac		= (agent.indexOf('mac') != -1);
	this.isWin		= (agent.indexOf('win') != -1);
	this.isWin2k	= (this.isWin && (
			agent.indexOf('nt 5') != -1));
	this.isWinSP2	= (this.isWin && (
			agent.indexOf('xp') != -1 || 
			agent.indexOf('sv1') != -1));
	this.isOther	= (
			agent.indexOf('unix') != -1 || 
			agent.indexOf('sunos') != -1 || 
			agent.indexOf('bsd') != -1 ||
			agent.indexOf('x11') != -1 || 
			agent.indexOf('linux') != -1);
	
	// detect browser
	this.isSafari	= (agent.indexOf('safari') != -1);
	this.isSafari2 	= (this.isSafari && (parseFloat(agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).substring(0,agent.substring(agent.indexOf("applewebkit/")+"applewebkit/".length,agent.length).indexOf(' '))) >=  300));
	this.isOpera	= (agent.indexOf('opera') != -1);
	this.isNN		= (agent.indexOf('netscape') != -1);
	this.isIE		= (agent.indexOf('msie') != -1);
	this.isFirefox	= (agent.indexOf('firefox') != -1);
}
var browser = new detect();

// -------------------
// GENERAL XML PARSING
// -------------------
function getElementTextNS(prefix, local, parentElem, index) {
	/**
	* Explorer for Windows (at least through Version 6) does not implement the DOM 
	* getElementsByTagNameNS() function. Instead it treats namespace tag names literally. 
	* For example, the <content:encoded> element is treated as an element whose tag name 
	* is content:encoded, rather than a tag whose local name is encoded and whose 
	* prefix is content.
	*/
	var result = "";
	if (prefix && browser.isIE) {
		result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
	} else {
		result = parentElem.getElementsByTagName(local)[index];
	}
	if (result) {
		if (result.childNodes.length > 1) {
			return result.childNodes[1].nodeValue;
		} else {
			return result.firstChild.nodeValue;
		}
	} else {
		return "";
	}
}

// TRIGGER EVENTS ON-LOAD
// addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
function addEvents( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
	} else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}
function removeEvents( obj, type, fn ) {
	if (obj.removeEventListener) {
		obj.removeEventListener( type, fn, false );
	} else if (obj.detachEvent) {
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

// ======================================================================================================================
// LINKS THAT OPEN IN NEW WINDOWS (Code start)
// ======================================================================================================================
// Create fixed size (pop-up) window
function openPopup(e) {
	var event;
	if (!e) event = window.event;
	else event = e;		
	var newWindow = window.open(this.getAttribute('href'), 'popup', 'width=580,height=550,resizable=no,scrollbars=1');
	if (newWindow) {
		if (newWindow.focus) {
		newWindow.focus();
		}
	return false;
	}
return true;	
}

// INTERACTIVE MAP 
function openInteractiveMap() {
    window.open('/visitorinformation/interactivemap.aspx','win','width=740, height=550, top=10, left=10');
    }

// Create full-size window
function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {		
		var newWindow = window.open(this.getAttribute('href'), 'popup');
		if (newWindow) {
			if (newWindow.focus) {
			newWindow.focus();
			}
		return false;
		}
	return true;
	}
}

// Add the openInNewWindow function to the onclick event of links with a class name of "non-html"
function getNewWindowLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {		
		var strNewWindowAlert = " (opens in a new window)";
		// Find all links
		var objWarningText;
		var link;
		var links = document.getElementsByTagName('a');
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			// Find all links with a class name of "non-html"
			if (/\bnon\-html\b/.test(link.className)) {
				// Create an em element containing the new window warning text and insert it after the link text
				// HIDE WINDOW ALERT objWarningText = document.createElement("em");
				// objWarningText.appendChild(document.createTextNode(strNewWindowAlert));
				// link.appendChild(objWarningText);
				link.onclick = openInNewWindow;
			}
			// Find all links with a class name of "off-site"
			if (/\boff\-site\b/.test(link.className)) {				
				link.onclick = openInNewWindow;
			}
			// Find all links with a class name of "pop-up"
			if (/\bpop\-up\b/.test(link.className)) {
				link.onclick = openPopup;
			}
			// Find all links with a class name of "featuresite" (CUSTOM FOR DISCOVER OHIO WEB SITE)
			if (/\bfeaturesite\b/.test(link.className)) {				
				link.onclick = openInNewWindow;
			}	
		}
	objWarningText = null;
	}
}
// ======================================================================================================================
// LINKS THAT OPEN IN NEW WINDOWS (Code end)
// ======================================================================================================================

// WRITE E-MAIL ADDRESS TO HIDE IT FROM SPAM SPIDERS
function writeAddress(name,url) {
	document.write('<a href="mailto:' + name + '@' + url + '">' + name + '@' + url + '</a>');
}

// ----------------
// TABBED WIDGET(S)
// ----------------
// Search Tools
// Top Searches
// Ohio's Best

// CLICK EVENT
function tabbedWidgetClick(thisObj, page, target, args) {
	// Make the Ajax call
	var ao = newAjaxObject();
	ao.getAjaxRequest(page, args, "txt", tabbedWidgetCallback, target);
	
	// Hilight the clicked tab
	var selectedIndex = selectListItem(thisObj);
	
	// Change the background of the selected tab
	var ulobj = thisObj.parentNode.parentNode;
	if (selectedIndex == 0){
		ulobj.style.backgroundImage = "url(/images/widgets/tabs_onoff.gif)";
	} else {
		ulobj.style.backgroundImage = "url(/images/widgets/tabs_offon.gif)";
	}
}

// SELECT HOT TAB (WIDGETS)
function selectListItem(linkObj) {
	if (linkObj) {
		var ullist = linkObj.parentNode.parentNode.getElementsByTagName("li");
		var selectedIndex = 0;
		for (var i = 0; i < ullist.length; i++) {
			if (ullist[i] ==linkObj.parentNode) {
				ullist[i].className = "selected";
				selectedIndex = i;
			} else {
				ullist[i].className = "";
			}
		}
		// linkObj.parentNode.className = "selected";
		return selectedIndex;
	}
}

// SEARCH TOOL SWITCHER
function switchSearchTools(thisObj, objOn, objOff) {	
	// Show search tool
	document.getElementById(objOn).style.display = 'block';
	document.getElementById(objOff).style.display = 'none';	
	// Change the background of the selected tab
	var ulobj = thisObj.parentNode.parentNode;	
	if (objOn == 'keyword') {
		ulobj.style.backgroundImage = 'url(http://consumer.discoverohio.com/images/widgets/tabs_offon.gif)';
	} 
	else {
		// Default image
		ulobj.style.backgroundImage = 'url(http://consumer.discoverohio.com/images/widgets/tabs_onoff.gif)';
	}
	if (objOn == 'keyword1') {
		ulobj.style.backgroundImage = 'url(http://consumer.discoverohio.com/images/widgets/tabs_offon.gif)';
	} 
	else {
		// Default image
		ulobj.style.backgroundImage = 'url(http://consumer.discoverohio.com/images/widgets/tabs_onoff.gif)';
	}
	// Change the color of the selected tab text
	var selectedIndex = selectListItem(thisObj);
}

// AJAX CALLBACK
function tabbedWidgetCallback(ajaxObj) {
	var myajax = ajaxObj.reqObj;
	var myfiletype = ajaxObj.filetype;
	var mycallbackargs = ajaxObj.callbackargs;	
					
	if (myajax.readyState == 4) { // If request of file completed
		if (myajax.status == 200 || window.location.href.indexOf("http") == -1) { // If request was successful or running script locally
			if (myfiletype == "txt") {
				document.getElementById(mycallbackargs).innerHTML = myajax.responseText;					
			} else {
				// myajax.responseXML;				
			}
		} else {
		    alert("There was a problem retrieving the XML data:\n" + myajax.statusText);
		}
	} else {
	    // readyState: 0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, 4 = complete
		// readyStateArray = Array('uninitialized','loading','loaded','interactive','complete');
		// document.getElementById(mycallbackargs).innerHTML = readyStateArray[myajax.readyState];
	}
}

// ------------------------
// EVENT CALENDAR WIDGET(S)
// ------------------------
// Event Calendar

function eventCalendarInit() {
	// Today's date	
	var today = new Date();
	var monthnum = today.getMonth()+1;
	var yearnum = today.getFullYear();
	
	// Set div content
	var monthnumObj = document.getElementById('monthnum');
	if (monthnumObj && monthnumObj != '') {
	    monthnumObj.innerHTML = monthnum + "," + yearnum;	
    	
	    // Swap title graphic
	    eventCalendarSwapTitle('monthtitle', monthnum);
	    
		// Make initial call...
		// var ao = newAjaxObject();
		// ao.getAjaxRequest(page+'?m='+monthnum + '&y=' + yearnum, "", "txt", eventCalendarWidgetCallback, args);
	}
}

// CLICK EVENT
function eventCalendarWidgetClick(thisObj, step, page, args) {	
	
	// Get current values
	var monthnumObj = document.getElementById('monthnum');	
	// REM GML var monthnum = Number(monthnumObj.innerHTML);
	var str = monthnumObj.innerHTML;
	arr = str.split(",");
	var monthnum = Number(arr[0]);
	var yearnum = Number(arr[1]);
	
	// Increment month/year
	monthnum += step; // step value range is -1 to 1
	if (monthnum>12) {
		monthnum = 1;
		yearnum++;
	} else if (monthnum<1) {
		monthnum = 12;
		yearnum--;
	}
	
	// Save div content
	monthnumObj.innerHTML = monthnum + "," + yearnum;
	
	// Swap title graphic
	eventCalendarSwapTitle('monthtitle', monthnum);

	// Make the Ajax call
	var ao = newAjaxObject();
	ao.getAjaxRequest(page+'?m='+monthnum + '&y=' + yearnum, "", "txt", eventCalendarWidgetCallback, args);
}

function eventCalendarSwapTitle(divTitle, monthnum) {
	// Swap title graphic
	var monthtitleObj = document.getElementById(divTitle);
	monthtitleObj.setAttribute('src','/images/widgets/eventcalendar/month'+monthnum+'.gif');
	monthtitleObj.src = '/images/widgets/eventcalendar/month'+monthnum+'.gif';
	var monthArr = ['January','February','March','April','May','June','July','August','September','October','November','December'];
	var altText = monthArr[monthnum-1];
	var titleText = altText;
	monthtitleObj.setAttribute('alt',altText);
	monthtitleObj.setAttribute('title',titleText);
}

// AJAX CALLBACK
function eventCalendarWidgetCallback(ajaxObj) {
	var myajax = ajaxObj.reqObj;
	var myfiletype = ajaxObj.filetype;
	var mycallbackargs = ajaxObj.callbackargs;
					
	if (myajax.readyState == 4) { // If request of file completed
		if (myajax.status == 200 || window.location.href.indexOf("http") == -1) { // If request was successful or running script locally
			if (myfiletype == "txt") {
				if ((myajax.responseText).length < 1) {
				    document.getElementById(mycallbackargs).innerHTML = "<ul><li>We're sorry, no events are available for this date.</li></ul>";
				} else {
				    document.getElementById(mycallbackargs).innerHTML = myajax.responseText;
				}
			} else {
				// myajax.responseXML;
			}
		} else {
			document.getElementById(mycallbackargs).innerHTML = "<ul><li>We're sorry, no events are available for this date.</li></ul>";			
		}
	} else {
		// readyState: 0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, 4 = complete
		// readyStateArray = Array('uninitialized','loading','loaded','interactive','complete');
		// document.getElementById(mycallbackargs).innerHTML = readyStateArray[myajax.readyState];
	}
}

// -----------------
// STEPPER WIDGET(S)
// -----------------
// Microsites

// FOR MICROSITES NAVIGATION 
// Steps through list and hides all but selected
function listItemStepper(linkObj,step) {
	if (linkObj) {
		var ullist = linkObj.parentNode.getElementsByTagName("li");
		var selectedIndex = 0;
		for (var i = 0; i < ullist.length; i++) {
			if (ullist[i].className == "selected") {
				selectedIndex = i;
			}
			ullist[i].className = "";
		}
		selectedIndex += step;
		if (selectedIndex < 0) {
			selectedIndex = ullist.length - 1;
		} else if (selectedIndex > ullist.length - 1) {
			selectedIndex = 0;
		}
		ullist[selectedIndex].className = "selected";
	}
}

// selects random microsite for initial display
function listItemRandomSelect() {
	var linkObj = document.getElementById('microsites_back');	
	if (linkObj) {	    
		var ullist = linkObj.parentNode.getElementsByTagName("li");
		var ran_number = Math.floor(Math.random()*(ullist.length-1));
		for (var i = 0; i < ullist.length; i++) {
			if (i == ran_number) {
			    ullist[i].className = "selected";	
			} else {
			    ullist[i].className = "";
			}
		}
	}	
}

// ---------------------
// "I WANT TO..." WIDGET
// ---------------------
function iwantto_subjectOnChange() {
    url = document.getElementById('iwantto_subject').value;
	if (url) {
	    switch (url) {
	        case 'gfa':
	            location = '/searchresults.aspx?type=' + url;
	            break;
	        case 'gfi':
	            var newWindow = window.open('/consumer/support/itinerary_srch.asp','popup','width=630,height=640,resizable=yes,scrollbars=yes');
                newWindow.focus();	            
	            //location = '/searchresults.aspx?type=' + url;
	            break;
	        default:
		        location = '/searchresults.aspx?category=' + url;
		        break;
		    }
	    }
    }
//
function keyword_go_onclick() {
    url = document.getElementById('searchtools_keyword').value;
	if (url) {
		location = '/keywordsearch.aspx?s=' + url;
	}  
}

function enter_go_onclick(e)
{
    var event;
    event = e || window.event;
    var codigoCaracter = e.keyCode;
    if (codigoCaracter == 13)
    {        
       url = document.getElementById('searchtools_keyword').value;
	    if (url) 
	        {
	            document.location = '/keywordsearch.aspx?s=' + url;
	            //alert('document.location');	            
	            return false;
	        }  
    }
    
}

//
function get_large_header_image() {
    arr = [];
    arr = [
        ['cinci_zoo.jpg'],
        ['malabar.jpg'],
        ['public_square.jpg']
        ];
    var ran_number = Math.floor(Math.random()*(arr.length)); 
    return arr[ran_number];      
}
function get_small_header_image() {
    arr = [];
    arr = [
        ['dogsled.jpg'],
				['ice_fishing.jpg'],
        ['snowmobile.jpg'],
        ['snowy_owl.jpg']
        ];
     var ran_number = Math.floor(Math.random()*(arr.length)); 
     return arr[ran_number];      
    //return arr[0];      
}
//
function iwantto_select(form) {
	arr = [];
	switch (form.options[form.selectedIndex].value) {
		case 'go':
			arr = [
			    ['28','to an art museum or gallery'],
			    ['32','to a show'],
			    ['34','to an amusement park'],
			    ['6','get away'],
			    ['99','commune with nature'],
			    ['62','skiiing']
			    ];
			break;
		case 'find':
			arr = [
			    ['170','convention and meeting facilities'] ,
			    ['gfa','group friendly attractions and events'],
			    ['gfi','group friendly itineraries']
			    ];
			break;		
		case 'shop':
			arr = [
			    ['114','at a mall'],
			    ['65','for antiques'],
			    ['95','for arts and crafts']
			    ];
			break;
		case 'take':
			arr = [
			    ['68','a tour']
			    ];
			break;
		case 'eat':
			arr = [
			    ['23','and I\'m in a hurry'],
			    ['24','some place casual'],
			    ['80','some place nice']
			    ];
			break;
		case 'drink':
			arr = [
			    ['33','some wine']
			    ];
			break;
		case 'learn':
			arr = [
			    ['108','the land'],
			    ['50','heritage'],
			    ['52','recent history'],
			    ['49','cities'],
			    ['53','black history'],
			    ['47','cival war history'],
			    ['109','aviation']
			    ];
			break;
		case 'stay':
			arr = [
			    ['13','at a resort'],
			    ['7','at a hotel'],
			    ['6','at a bed and breakfast'],
			    ['12','in a motel'],			    
			    ['81','in a cabin'],
			    ['8','in my tent']
			    ];
			break;
		case 'play':
			arr = [
			    ['9','some golf']
			    ];
			break;
		case 'do':
			arr = [
			    ['171','something extreme'],
			    ['59','an outdoor activity'],
			    ['112','some boating'],
			    ['103','some hunting']
			    ];
			break;
		case 'see':
			arr = [
			    ['93','birds'],
			    ['43','animals'],
			    ['106','plants'],
			    ['6','sports'],
			    ['2','racing']
			    ];
			break;
	}
    ////////////////////////////////////	
	obj = document.getElementById('iwantto_subject');
	
	for (i=obj.options.length-1; i>0; i--) {
		obj.options[i] = null;
	}
	
	obj.options[0] = new Option('-- Select --','');
	
	for (i=0; i<arr.length; i++) {
		obj.options[i+1] = new Option(arr[i][1],arr[i][0]);
	}
}
// ----------------------------

// -----------------------
// SUB-NAVIGATION EXPANDER
// -----------------------
function showNav(theObj) {
	
	// Set variables
	var arrowOn = 'url(/images/navigation/arrow_down_secondary.gif)';
	var arrowOff = 'url(/images/navigation/arrow_right_secondary.gif)';
	var listOn = 'block';
	var listOff = 'none';
	
	// Get element
	var theList = theObj.parentNode.getElementsByTagName('ul');
		
	// Determine if results are currently displayed
	if (theList[0].style.display == listOn) {
		// Change arrow
		theObj.style.backgroundImage = arrowOff;
		// Display results
		theList[0].style.display = listOff;
	}
	else {		
		// Change arrow
		theObj.style.backgroundImage = arrowOn;
		// Display results
		theList[0].style.display = listOn;
	}	
}

// EMULATE DROP-DOWN SELECT BOX SO THAT SEARCH ENGINES CAN FOLLOW LINKS
function emulateSelectElement() {
	var menuOpen = 'block';
	var menuClose = 'none';
	var theElement = document.getElementById('pseudoselect_options');
	switch (theElement.style.display) {
		case menuOpen:			
			theElement.style.display = menuClose;
			break;
		case menuClose:			
			theElement.style.display = menuOpen;
			break;
		default:			
			theElement.style.display = menuClose;
			break;
	}
}

//-----------------------------------------------------------------------------------------------------
//--- COOKIES FUNCTIONS -------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
function GetValueCookie(indice) {
	var oCookie = document.cookie
	var finDeCadena = oCookie.indexOf(";", indice)
	if (finDeCadena == -1)
		finDeCadena = oCookie.length
	return unescape(oCookie.substring(indice, finDeCadena))
	}

function GetCookie(nombre) {
	var oCookie = document.cookie
	var arg = nombre + "="
	var alen = arg.length
	var glen = oCookie.length

	var i = 0
	while (i < glen) {
		var j = i + alen
		if (oCookie.substring(i, j) == arg)	
			return GetValueCookie(j)

		i = oCookie.indexOf(" ", i) + 1
		if (i == 0)
			break
	}
	return null
}

function SaveCookie (nombre, valor, caducidad) {
	if(!caducidad)
		caducidad = Caduca(0)
	document.cookie = nombre + "=" + escape(valor) + "; expires=" + caducidad + "; path=/"
}

function Caduca(dias) {
	var oToday = new Date()
	var msEnXDias = eval(dias) * 24 * 60 * 60 * 1000

	oToday.setTime(oToday.getTime() + msEnXDias)
	return (oToday.toGMTString())
}

function BorrarCookie(nombre) {
	document.cookie = nombre + "=; expires=" + Caduca(-1) + "; path=/"
}

function IntroducirCookie(nombre, valor) {
	var _31dias = Caduca(31)
	if (nombre != "") 
		SaveCookie(nombre, valor, _31dias)
}
//-----------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------

// ON-LOAD EVENTS 
addEvents(window, 'load', eventCalendarInit);
addEvents(window, 'load', getNewWindowLinks);

// Search functions
function toggleFilterPanel() {
    $("#search-filters").toggle();
    
    if ($("#search-filters").css("display") == "none") {
        $("#btnShowHide").attr("src", "/images/global/relatedlinks_expand.gif");
        $(".showhide").text("Show search options");
    }
    else {
        $("#btnShowHide").attr("src", "/images/global/relatedlinks_contract.gif");
        $(".showhide").text("Hide search options");
    }
    return false;
}
// --------------------------------------------------
// AJAX
// --------------------------------------------------
function createAjaxObj() {
	// alert("createAjaxObj()");
	
	var reqObj = false;
	
	if (window.XMLHttpRequest) {
		// If Mozilla, Safari etc
		reqObj = new XMLHttpRequest();
		if (reqObj.overrideMimeType) {
			reqObj.overrideMimeType('text/xml');
		}
	} else {
		if (window.ActiveXObject) {
			// If IE
			var aXmlHttpVersions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];

			for (var i = 0; i < aXmlHttpVersions.length; i++) {
				try {
					reqObj = new ActiveXObject(aXmlHttpVersions[i]);
					if (reqObj) {
						break;
					}
				}
				catch (objException) {
					// Catch object exception errors so they don't display to the user...
				}
			}
		}
	}
	return reqObj;
}

function newAjaxObject() {
	var ajaxObj = new Object();
	
	ajaxObj.basedomain = "http://" + window.location.hostname;
	ajaxObj.reqObj = createAjaxObj();
	ajaxObj.filetype = "txt";
	ajaxObj.addrandomnumber = 0; // Set to 1 or 0. See documentation.
	
	ajaxObj.getAjaxRequest = function(url, parameters, filetype, callbackfunc, callbackargs) {
		
		ajaxObj.reqObj = createAjaxObj(); // Recreate ajax object to defeat cache problem in IE
		
		if (ajaxObj.addrandomnumber == 1) { // Further defeat caching problem in IE?
			var parameters = parameters + "&ajaxcachebust=" + new Date().getTime();
		}
		
		if (this.reqObj) {
			this.filetype = filetype;
			this.callbackargs = callbackargs;
			this.reqObj.onreadystatechange = function() {
				callbackfunc(ajaxObj);
			}
			if (parameters == '') {
			    this.reqObj.open('GET', url, true);
			} else {
			    if (url.indexOf("?") == -1) {
			        url = url + "?";
			    }
			    this.reqObj.open('GET', url + parameters, true);
			}
			this.reqObj.send(null);
		}
	};
	
	ajaxObj.postAjaxRequest = function(url, parameters, callbackfunc, filetype, callbackargs) {
		// alert("postAjaxRequest()");
		
		ajaxObj.reqObj = createAjaxObj(); // Recreate ajax object to defeat cache problem in IE
		
		if (this.reqObj) {
			this.filetype = filetype;
			this.callbackargs = callbackargs;
			this.reqObj.onreadystatechange = function() {
				callbackfunc(ajaxObj);
			}
			this.reqObj.open('POST', url, true);
			this.reqObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.reqObj.setRequestHeader("Content-length", parameters.length);
			this.reqObj.setRequestHeader("Connection", "close");
			this.reqObj.send(parameters);
		}
	};
	
	return( ajaxObj );
}
