function changeImages() {
  if (document.images) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
    }
  }
}
function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}
var flag = 1;
var currentImage = 0;
var imgFileNames=new Array("a1", "b2", "a3", "c1", "d2", "c3"); 
function stop()
{
	flag = 0;
	document[imgFileNames[currentImage]].src = "/i/home_img_" + imgFileNames[currentImage] + ".jpg";
}
function sequencer(imageOff)
{
	if (imageOff == 99) { imageOn = currentImage; imageOff = 0; flag = 1; }
	else if (imageOff >= imgFileNames.length - 1) { imageOn = 0; }
	else { imageOn = imageOff + 1; }
	currentImage = imageOn;
	var imageName = imgFileNames[imageOn];
	if (flag == 1) //if no mouseover is in effect, you may continue recursion
	{
		document[imgFileNames[imageOff]].src = "/i/home_img_" + imgFileNames[imageOff] + ".jpg";
		document[imgFileNames[imageOn]].src = "/i/other_img_" + imgFileNames[imageOn] + "_on.jpg";
		recall = "sequencer(" + imageOn + ");";
		setTimeout(recall, 2000);
	}
}
/*
function randomizer(imageOff)
{
	var imgFileNames=new Array("a1", "a3", "b2", "c1", "c3", "d2"); 
	var rNumber=Math.floor(Math.random()*imgFileNames.length); 
	var imageName = imgFileNames[rNumber];
	document[imageOff].src = "/i/home_img_" + imageOff + ".jpg";
	document[imageName].src = "/i/other_img_" + imgFileNames[rNumber] + "_on.jpg";
	recall = "randomizer('" + imageName + "');";
	setTimeout(recall, 2000);
}
*/
function launchDaily(ID) { window.open("daily_view.php?ID=" + ID,"dailyNote","scrollbars=yes,resizable=yes,width=400,height=375"); }
function dailyNoteWindow(rID) { window.open('/research/dailynotes/'+rID+'/','dailyNote','scrollbars=yes,resizable=yes,width=550,height=500'); }
function mall_printWindow(ID, params) { window.open('/property/mall/'+ID+'/'+params,'','height=700,resizable=yes,scrollbars=yes,width=900'); } 
function mall_mapWindow(params) { window.open('/property/mall/4/'+params,'4','height=740,resizable=yes,scrollbars=no,width=700'); } 
function mall_trialWindow() { window.open('/property/mall/7/','','height=350,resizable=yes,scrollbars=no,width=550'); } 
function strip_printWindow(ID, params) { window.open('/property/strip/'+ID+'/'+params,'','height=700,resizable=yes,scrollbars=yes,width=900'); } 
function strip_mapWindow(params) { window.open('/property/strip/4/'+params,'4','height=740,resizable=yes,scrollbars=no,width=700'); } 
function strip_trialWindow() { window.open('/property/strip/7/','','height=350,resizable=yes,scrollbars=no,width=550'); } 
function soundbite(num, status) {
    if(!document.getElementById('sb_'+num)) return;
	if(status == true) { document.getElementById('sb_'+num).style.display = 'block';
	} else { document.getElementById('sb_'+num).style.display = 'none'; }}
function execcompWindow(rID) { window.open('/research/Execcomp_Print/'+rID+'/','execcompWindow','scrollbars=yes,resizable=yes,width=640,height=500'); } 
function datatoolWindow(rID) { window.open('/research/Data_graph_Print/'+rID+'/','datatoolWindow','scrollbars=yes,resizable=yes,width=800,height=600'); } 


    function processNode(xmlObjArray) {
        return (xmlObjArray.length > 0 && xmlObjArray[0] && xmlObjArray[0].firstChild) ? xmlObjArray[0].firstChild.nodeValue : '';
    }

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function makeEditable(container) {

    var config = {
        toolbar: [
            ['Save', '-', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink', 'TextColor', 'BGColor'],
            ['UIColor'],['PasteText','PasteFromWord']
        ]
    };

    currentEditor = CKEDITOR.replace(container, config);
}

var Tabs = {
    tab: null,
    
    init: function(container, sub) {
        this.container = container;
        this.sub = sub || 'tabs';
        this.parseURL();
        this.clearOut();
        this.load();
    },

    load: function() {
        // set the tabs/etc
        $('#'+this.getTab()).addClass('active');
        // display the correct content
        $('#content-'+this.getTab()).show();
        // set the URL
        window.location = this.setupURL(window.location.toString());
    },

    clearOut: function() {
        $(this.container + ' .' + this.sub + '-content').hide();
        $(this.container + ' ul li a').removeClass('active');
    },

    setTab: function(r) { this.tab = r; },
    getTab: function() { return this.tab; },

    clickTab: function(event) {
        this.clearOut();
        this.setTab($(event.target).get(0).id); //sets to id of clicked element
        this.load();
    },

    parseURL: function() {
        var url = window.location.toString();
        if (url.indexOf('#!/') != -1) {
            this.setTab(url.split('#!/')[1]);
        } else if($(this.container + ' ul.' + this.sub + ' a.default').length) {
            this.setTab($(this.container + ' ul.' + this.sub + ' a.default').get(0).id);
        } else {
            this.setTab($(this.container + ' ul.' + this.sub + ' a').get(0).id);
        }
    },

    setupURL: function(url) {
        var index = url.indexOf('#') == -1 ? url.length : url.indexOf('#');
        return url.substring(0,index) + '#!/' + this.getTab();
    }
}

// http://stackoverflow.com/questions/5375616/extjs4-ie9-object-doesnt-support-property-or-method-createcontextualfragmen
if(navigator.userAgent.indexOf("Trident/5")>-1 && document.documentMode && document.documentMode > 8) {
	if (typeof Range !== "undefined" && typeof Range.prototype.createContextualFragment == "undefined") {
		Range.prototype.createContextualFragment = function (html) {
			var doc = window.document;
			var container = doc.createElement("div");
			container.innerHTML = html;
			var frag = doc.createDocumentFragment(), n;
			while ((n = container.firstChild)) {
				frag.appendChild(n);
			}
			return frag;
		};
	}
}
