/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var loadstatustext="<img src='/images/loading.gif' /> Requesting content..."

function ajaxpage(url, containerid){
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
	return false
	document.getElementById(containerid).innerHTML=loadstatustext
	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}
	page_request.open('GET', url, true)
	page_request.send(null)
}
//document.getElementById(containerid).innerHTML=loadstatustext

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
	document.getElementById(containerid).innerHTML=page_request.responseText
}


function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
	var file=arguments[i]
	var fileref=""
	if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function photometric_DoFSCommand(command, args) {
	var photometricObj = isInternetExplorer ? document.all.photometric: document.photometric;
	 if (command == "reset") {
		reset() ;
	 }
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub photometric_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call photometric_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

function loadCustom(){
	var jsCandlePower=document.getElementById? document.getElementById('candela').value : ""
	var jsBeamMin=document.getElementById? document.getElementById('minbeam').value : ""
	var jsBeamMax=document.getElementById? document.getElementById('maxbeam').value : ""
	if ((isNaN(jsCandlePower)) || (jsCandlePower == null) || (jsCandlePower == '')) { jsCandlePower = 0 ;}
	if ((isNaN(jsBeamMin)) || (jsBeamMin == null) || (jsBeamMin == '')) { jsBeamMin = 0 ;}
	if ((isNaN(jsBeamMax)) || (jsBeamMax == null) || (jsBeamMax == '')) { jsBeamMax = jsBeamMin ;}
	window.document.photometric.SetVariable("iCandlePower", jsCandlePower);
	window.document.photometric.SetVariable("iBeamMin", jsBeamMin);
	window.document.photometric.SetVariable("iBeamMax", jsBeamMax);
	document.getElementById('dynFixtureTitle').innerHTML='<b>Fixture:</b> Custom Data';
	document.getElementById('dynFixtureTitle').style.display = ""; 
	document.getElementById('dynLampTitle').style.display = "none"; 
	window.location.hash = "#top";
}

function listenLoadCustomEnter(e, pointID, infid){
var key=e.keyCode || e.which;
	if (key==13){
	loadCustom(pointID, infid);
	}
}

function changeManufacturer(){
	var manufacturer=document.getElementById? document.getElementById('manufacturer') : ""
	var thisList = manufacturer.options[manufacturer.selectedIndex].value ;
	if (thisList != 'null')
	{
		ajaxpage('/fixturedb?manid='+thisList, 'fixture')
		ajaxpage('/lampdb', 'lamp')
	}
}

function changeFixture(){
	var fixturelist=document.getElementById? document.getElementById('fixturelist') : ""
	var thisList = fixturelist.options[fixturelist.selectedIndex].value ;
	if (thisList != 'null')
	{
		var brokenstring=thisList.split("|");
		var fixtureID = brokenstring[0];
		var fixtureName = brokenstring[1];
		var fixtureMin = brokenstring[2];
		var fixtureMax = brokenstring[3];
		var manufacturer= brokenstring[4];
		window.document.photometric.SetVariable("iCandlePower", 0);
		window.document.photometric.SetVariable("iBeamMin", fixtureMin);
		window.document.photometric.SetVariable("iBeamMax", fixtureMax);
		document.getElementById('dynFixtureTitle').innerHTML='<b>Fixture:</b> '+manufacturer+' '+fixtureName;
		document.getElementById('dynFixtureTitle').style.display = ""; 
		document.getElementById('dynLampTitle').style.display = "none"; 	
		window.location.hash = "#top";
		ajaxpage('/lampdb?fixid='+fixtureID, 'lamp')
	}
}

function changeLamp(){
	var lamplist=document.getElementById? document.getElementById('lamplist') : ""
	var thisList = lamplist.options[lamplist.selectedIndex].value ;
	if (thisList != 'null')
	{
		var brokenstring=thisList.split("|");
		var lampName = brokenstring[0];
		var lampCP = brokenstring[1];
		window.document.photometric.SetVariable("iCandlePower", lampCP);
		document.getElementById('dynLampTitle').innerHTML='<b>Lamp:</b> '+lampName;
		document.getElementById('dynLampTitle').style.display = ""; 	
		window.location.hash = "#top";
	}
	//ajaxpage('/fixturedb?manid='+manufacturer.options[manufacturer.selectedIndex].value, 'fixture')
}

function reset(){
		var manufacturer=document.getElementById? document.getElementById('manufacturer') : ""
		manufacturer.selectedIndex = 0;
		var jsCandlePower=document.getElementById? document.getElementById('candela') : ""
		var jsBeamMin=document.getElementById? document.getElementById('minbeam') : ""
		var jsBeamMax=document.getElementById? document.getElementById('maxbeam'): ""
		jsCandlePower.value = '';
		jsBeamMin.value = '';
		jsBeamMax.value = '';
		document.getElementById('dynFixtureTitle').style.display = "none"; 
		document.getElementById('dynLampTitle').style.display = "none"; 
		ajaxpage('/fixturedb', 'fixture')
		ajaxpage('/lampdb', 'lamp')
}


