// Copyright 2010 DataCom/OTA, Inc.
// JavaScript Document

// Dave's mongo image array
var theBar = new Array();
theBar[0] = "/images/bar/0.jpg";
theBar[1] = "/images/bar/1.jpg";
theBar[2] = "/images/bar/2.jpg";
theBar[3] = "/images/bar/3.jpg";
theBar[4] = "/images/bar/4.jpg";
theBar[5] = "/images/bar/5.jpg";
theBar[6] = "/images/bar/6.jpg";
theBar[7] = "/images/bar/7.jpg";
theBar[8] = "/images/bar/8.jpg";
theBar[9] = "/images/bar/9.jpg";
theBar[10] = "/images/bar/10.jpg";
theBar[11] = "/images/bar/11.jpg";
theBar[12] = "/images/bar/12.jpg";
theBar[13] = "/images/bar/13.jpg";
theBar[14] = "/images/bar/14.jpg";
theBar[15] = "/images/bar/15.jpg";
theBar[16] = "/images/bar/16.jpg";
theBar[17] = "/images/bar/17.jpg";
theBar[18] = "/images/bar/18.jpg";
theBar[19] = "/images/bar/19.jpg";
theBar[20] = "/images/bar/20.jpg";
theBar[21] = "/images/bar/21.jpg";
theBar[22] = "/images/bar/22.jpg";
theBar[23] = "/images/bar/23.jpg";
theBar[24] = "/images/bar/24.jpg";
theBar[25] = "/images/bar/25.jpg";
theBar[26] = "/images/bar/26.jpg";
theBar[27] = "/images/bar/27.jpg";
theBar[28] = "/images/bar/28.jpg";
theBar[29] = "/images/bar/29.jpg";
theBar[30] = "/images/bar/30.jpg";
theBar[31] = "/images/bar/31.jpg";
theBar[32] = "/images/bar/32.jpg";
theBar[33] = "/images/bar/33.jpg";
theBar[34] = "/images/bar/34.jpg";
theBar[35] = "/images/bar/35.jpg";
theBar[36] = "/images/bar/36.jpg";
theBar[37] = "/images/bar/37.jpg";
theBar[38] = "/images/bar/38.jpg";
theBar[39] = "/images/bar/39.jpg";
theBar[40] = "/images/bar/40.jpg";
theBar[41] = "/images/bar/41.jpg";
theBar[42] = "/images/bar/42.jpg";
theBar[43] = "/images/bar/43.jpg";
theBar[44] = "/images/bar/44.jpg";
theBar[45] = "/images/bar/45.jpg";
theBar[46] = "/images/bar/46.jpg";
theBar[47] = "/images/bar/47.jpg";
theBar[48] = "/images/bar/48.jpg";
theBar[49] = "/images/bar/49.jpg";
theBar[50] = "/images/bar/50.jpg";
theBar[51] = "/images/bar/51.jpg";
theBar[52] = "/images/bar/52.jpg";
theBar[53] = "/images/bar/53.jpg";
theBar[54] = "/images/bar/54.jpg";
theBar[55] = "/images/bar/55.jpg";
theBar[56] = "/images/bar/56.jpg";
theBar[57] = "/images/bar/57.jpg";
theBar[58] = "/images/bar/58.jpg";
theBar[59] = "/images/bar/59.jpg";
theBar[60] = "/images/bar/60.jpg";
theBar[61] = "/images/bar/61.jpg";
theBar[62] = "/images/bar/62.jpg";
theBar[63] = "/images/bar/63.jpg";
theBar[64] = "/images/bar/64.jpg";
theBar[65] = "/images/bar/65.jpg";
theBar[66] = "/images/bar/66.jpg";
theBar[67] = "/images/bar/67.jpg";
theBar[68] = "/images/bar/68.jpg";
theBar[69] = "/images/bar/69.jpg";
theBar[70] = "/images/bar/70.jpg";
theBar[71] = "/images/bar/71.jpg";
theBar[72] = "/images/bar/72.jpg";
theBar[73] = "/images/bar/73.jpg";
theBar[74] = "/images/bar/74.jpg";
theBar[75] = "/images/bar/75.jpg";
theBar[76] = "/images/bar/76.jpg";
theBar[77] = "/images/bar/77.jpg";
theBar[78] = "/images/bar/78.jpg";
theBar[79] = "/images/bar/79.jpg";
theBar[80] = "/images/bar/80.jpg";
theBar[81] = "/images/bar/81.jpg";
theBar[82] = "/images/bar/82.jpg";
theBar[83] = "/images/bar/83.jpg";
theBar[84] = "/images/bar/84.jpg";
theBar[85] = "/images/bar/85.jpg";
theBar[86] = "/images/bar/86.jpg";
theBar[87] = "/images/bar/87.jpg";
theBar[88] = "/images/bar/88.jpg";
theBar[89] = "/images/bar/89.jpg";
theBar[90] = "/images/bar/90.jpg";
theBar[91] = "/images/bar/91.jpg";
theBar[92] = "/images/bar/92.jpg";
theBar[93] = "/images/bar/93.jpg";
theBar[94] = "/images/bar/94.jpg";
theBar[95] = "/images/bar/95.jpg";
theBar[96] = "/images/bar/96.jpg";
theBar[97] = "/images/bar/97.jpg";
theBar[98] = "/images/bar/98.jpg";
theBar[99] = "/images/bar/99.jpg";
theBar[100] = "/images/bar/100.jpg";
theBar[101] = "/images/bar/101.jpg";
theBar[102] = "/images/bar/102.jpg";
theBar[103] = "/images/bar/103.jpg";
theBar[104] = "/images/bar/104.jpg";
theBar[105] = "/images/bar/105.jpg";
theBar[106] = "/images/bar/106.jpg";
theBar[107] = "/images/bar/107.jpg";
theBar[108] = "/images/bar/108.jpg";
theBar[109] = "/images/bar/109.jpg";
theBar[110] = "/images/bar/110.jpg";
theBar[111] = "/images/bar/111.jpg";
theBar[112] = "/images/bar/112.jpg";
theBar[113] = "/images/bar/113.jpg";
theBar[114] = "/images/bar/114.jpg";
theBar[115] = "/images/bar/115.jpg";
theBar[116] = "/images/bar/116.jpg";
theBar[117] = "/images/bar/117.jpg";
theBar[118] = "/images/bar/118.jpg";
theBar[119] = "/images/bar/119.jpg";
theBar[120] = "/images/bar/120.jpg";
theBar[121] = "/images/bar/121.jpg";
theBar[122] = "/images/bar/122.jpg";
theBar[123] = "/images/bar/123.jpg";
theBar[124] = "/images/bar/124.jpg";
theBar[125] = "/images/bar/125.jpg";
theBar[126] = "/images/bar/126.jpg";
theBar[127] = "/images/bar/127.jpg";
theBar[128] = "/images/bar/128.jpg";
theBar[129] = "/images/bar/129.jpg";


// Set cookies
function setCookie(theName, theValue) {
	var expDate = new Date;
	expDate.setMonth(expDate.getMonth()+6);
	document.cookie = theName + "=" + theValue +";path=/;expires=" + expDate.toGMTString() +";"
}

// Read cookies
function getCookie(cookieName) {
  var cookieData = document.cookie;
  var i = 0;
  var cEnd;
  while (i < cookieData.length) {
    var j = i + cookieName.length;
    if (cookieData.substring(i, j) == cookieName) {
      cEnd = cookieData.indexOf(";", j);
      if (cEnd == -1)
        cEnd = cookieData.length;
      return decodeURIComponent(cookieData.substring(j + 1, cEnd));
    }
    i++;
  }
  return "";
}

// Delete Cookie
function deleteCookie (name, path, domain) {
	if (getCookie(name))
    	document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

// Choose picture
function picPic() {
	var p = theBar.length;
	var preBuffer = new Array()
	for (i = 0; i < p; i++){
	    preBuffer[i] = new Image()
	    preBuffer[i].src = theBar[i]
	}
	var whichSpot = "b" + Math.floor(Math.random()*(14));
	var whichImage = Math.floor(Math.random()*(p));

	// Swap image
	document[whichSpot].src=theBar[whichImage];
	
	setTimeout ("picPic()", 500);
}

// Open Files
function openFile(theFile) {
    window.open (theFile);
}

// index page layout
function setDiv(theFile, theDiv, theAgency) {
	var dyaca = getCookie('agency');
	if( dyaca != theAgency) {
		try { document.getElementById(dyaca).style.backgroundColor = 'transparent';
		      document.getElementById(dyaca).style.color = '#777F5F';
		} catch(e) {}
		document.getElementById(theAgency).style.backgroundColor = '#E4E7D7';
		document.getElementById(theAgency).style.color = '#000000';
		setCookie('agency', theAgency);
		getFile(theFile, theDiv);
	} else {
		document.getElementById(dyaca).style.backgroundColor = 'transparent';
		document.getElementById(dyaca).style.color = '#777F5F';
		setCookie('agency', 'dyac');
		getFile('/agencies/dyac.htm', theDiv);
	}
	
}
// AJAX File Request
function getFile(theFile, theDiv) {
	var pageReq = false;
	
    if (window.XMLHttpRequest) {
        pageReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
		try {
			pageReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				pageReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				pageReq = false;
			}
		}
	}
	
    pageReq.open('GET', theFile, true);
    pageReq.onreadystatechange = function() {
        if (pageReq.readyState == 4) {
			document.getElementById(theDiv).innerHTML = pageReq.responseText;
		}
    }
    pageReq.send(null);
}
