	var AC_FL_RunContent = 0;
	var bStayOpen = true;
    var screenshot = "";
    var floorSelected = false;
    var counterSelected = false;
	var rotate;
	var reset_degree = 0;
	var light;
	var proj_exists = 0;
	var sel_object_id = 0;
	var sel_object_instance_id = 0;
	var paint_context = "Cabinet";
	
	
	var agt=navigator.userAgent.toLowerCase();
	var appVer = navigator.appVersion.toLowerCase();
	var is_konq = false;
	var kqPos   = agt.indexOf('konqueror');
	if (kqPos !=-1) {
		is_konq  = true;
		is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
		is_major = parseInt(is_minor);
	}
	var is_safari= ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
	var is_khtml = (is_safari || is_konq);
	var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
	var agt=navigator.userAgent.toLowerCase();
	var appVer = navigator.appVersion.toLowerCase();
	var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
						(agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
						(agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
						(is_gecko) &&
						((navigator.vendor=="")||(navigator.vendor=="Mozilla")));
	
	function LaunchWizardApp(mLengthFeet,mWidthFeet) {
		var isIE = (navigator.appName.indexOf("Microsoft Internet Explorer")>-1);
		var url = "designapp/check_sys.jsp?mode_id=3&mLengthFeet="+mLengthFeet+"&mWidthFeet="+mWidthFeet;
		
		//var 
		//var
		
		if (AppInstalled() || !isIE) {
			if (window.appWin && window.appWin.open && !window.appWin.closed) {
				window.appWin.focus();
			} else {
				app_popup = window.open(
					url,
					'FisherHamiltonVisualizer',
					'status=no,scrollbars=no,resizable=no,width=1026,height=630,top=0,left=0'
				);
				app_popup.opener = window.self;
				app_popup.opener.name = "main_win";
				app_popup.focus();
			}
			
		} else {

			//launch the installer
			url = url.replace("?","%3F");
			url = url.replace(/&/g,"%26");
			var pwlh=parent.window.location.href;
			
			if (pwlh.indexOf("?") > -1) {
				parent.window.location.href=pwlh+'&f=install&callingfn=LaunchWizardApp&mLengthFeet='+mLengthFeet+'&mWidthFeet='+mWidthFeet;
			} else {
				parent.window.location.href=pwlh+'?f=install&callingfn=LaunchWizardApp&mLengthFeet='+mLengthFeet+'&mWidthFeet='+mWidthFeet;
			}				
		}
	}
	
	function LaunchApp(project_id,mode_id){
		var isIE = (navigator.appName.indexOf("Microsoft Internet Explorer")>-1);
		var url = 'designapp/check_sys.jsp?project_id='+project_id+'&mode_id='+mode_id;
		
		if (AppInstalled() || !isIE) {
			if (window.app_popup && window.app_popup.open && !window.app_popup.closed) {
				window.app_popup.focus();
			} else {
				app_popup = window.open(
					url,
					'FisherHamiltonLabPlanner',
					'scrollbars=no,resizable=no,status=yes,location=yes,width=1026,height=630,top=0,left=0'
				);
				app_popup.opener = window.self;
				app_popup.opener.name = "main_win";
				app_popup.focus();
			}
		} else {

			var pwlh=window.location.href;
			
			if (pwlh.indexOf("?") > -1) {
				window.location.href=pwlh+'&f=install&callingfn=LaunchApp&project_id='+project_id+'&mode_id='+mode_id;
			} else {
				window.location.href=pwlh+'?f=install&callingfn=LaunchApp&project_id='+project_id+'&mode_id='+mode_id;
			}				
		}
	}
	
	function AppInitialized(){
		view22RTE.SetView(2); //set to 3d view as default
		InitToolbar();
		initTips();
        if (mode_id==1) { //start from scratch
			view22RTE.SendAppMessage("NewRoom","width=20,height=15");
            view22RTE.Zoom("fitToView");
			proj_exists = 0;
        } else if(mode_id==2) { //open a pre existing project
            view22RTE.OpenProject(project_id,0);
            proj_exists = 1;
        } else if(mode_id==3) { //walkthrough mode
            var command = "width="+mLength+".5,height="+mWidth+".5";
            view22RTE.SendAppMessage("NewRoom",command);
			view22RTE.SendAppMessage("ChangeCamera","next");
			proj_exists = 0;
		} else if(mode_id==4) { //open a pre existing project
            view22RTE.NewProject(project_id,0);
            proj_exists = 0;
		}
    }
	
	function InitToolbar(){
		$$('.icon').each(function(el){
			el.addEvent('mouseover', function(){
				var newString = el.getProperty('src').replace('_nm','_hv');
				el.setProperty('src', newString);
			});
			el.addEvent('mouseout', function(){
				var newString = el.getProperty('src').replace('_hv','_nm');
				el.setProperty('src', newString);
			});
		});
		
		//new Asset.images(preloaded_images, {});
	}
	
	function v22ErrorHandler(location,errorCode,message,display){
		//alert('location:'+location+'\n errorCode='+errorCode+'\n message='+message+'\n display='+display);
        if(errorCode==-400){
            return;
        }
        if(display){
            if(location==1){
                document.view22RTE.SetStatus("The View22 Server reports error:["+errorCode+"] ["+message+"]",10);
            } else if (location==2){
                document.view22RTE.SetStatus("The View22 Runtime Engine reports error:["+errorCode+"] ["+message+"]",10);
            } else if (location==3){
                document.view22RTE.SetStatus("The View22 Application Module reports error:["+errorCode+"] ["+message+"]",10);
            } else {
                document.view22RTE.SetStatus("ERROR:["+location+"] ["+errorCode+"] ["+message+"]",10);
            }
        }
    }
	
	function Close(){
		if (window.confirm("Are you sure you want to exit?")){
			window.close();
		}
	}
    function Undo(){ document.view22RTE.Undo() }
    function Delete(){ document.view22RTE.Cut() }
    function CameraMap(){ document.view22RTE.ClientCommand(2,2050) }
    function DragObject(objectid){ document.view22RTE.DragDropItem(objectid) }
	function ModelViewer(){
		var instanceID = view22RTE.SendAppMessage("GetSelectedObjects","");
		var first_comma = instanceID.indexOf(",");
		var second_comma = instanceID.indexOf(",", first_comma + 1);
		if (second_comma == -1) {
	        id = instanceID.substring(first_comma + 1, instanceID.length);
		} else {
	        id = instanceID.substring(first_comma + 1, instanceID.indexOf(",", first_comma+1));
		}
		if (id > 12) {
			document.view22RTE.ShowModelViewer(id);
		} else {
			alert('Please select an object in the scene to inspect.');
		}
	}
	
	/* Rotation functions BEGIN */
	function StartRotate(direction){
		if(direction=='CW') {
			RotateCW();
		} else {
			RotateCCW();
		}
	}
	function RotateCW(){ 
		var direction = "";
		reset_degree = reset_degree -1;
		var instancID = view22RTE.SendAppMessage("GetSelectedObjects","");
		id = instancID.substring(instancID.indexOf(",")+1, instancID.length);
		command = "instanceID="+id+" degrees="+direction+"15";
		view22RTE.SendAppMessage("Rotate",command);
		rotate = setTimeout("RotateCW()", 100);
	}
	function RotateCCW(){ 
		var direction = "-";
		reset_degree = reset_degree +1;
		var instancID = view22RTE.SendAppMessage("GetSelectedObjects","");
		id = instancID.substring(instancID.indexOf(",")-1, instancID.length);
		command = "instanceID="+id+" degrees="+direction+"15";
		view22RTE.SendAppMessage("Rotate",command);
		rotate = setTimeout("RotateCCW()", 100);
	}
	function StopRotate(){ 
		clearTimeout(rotate);
	}
	/* Rotation functions END */
	
	/* Light functions BEGIN */
	/*function StartIncreaseDecreaseLight(direction){
		if(direction=='increase') {
			IncreaseLight();
		} else {
			DecreaseLight();
		}
	}
	function IncreaseLight(){
		document.view22RTE.ClientCommand(2,2063);
		light = setTimeout("IncreaseLight()", 70);
    }
    function DecreaseLight(){
        document.view22RTE.ClientCommand(2,2064);
		light = setTimeout("DecreaseLight()", 70);
    }
	function StopIncreaseDecreaseLight(){ 
		clearTimeout(light);
	} */
	/* Light functions END */
	
	
	/* Help functions BEGIN */
	function Help() {
		alert("Coming Soon");
		//Help_Menu();
		//document.getElementById("help_layer").style.visibility = (document.getElementById("help_layer").style.visibility=="visible")?("hidden"):("visible");
		//document.getElementById("help_layer").style.display = (document.getElementById("help_layer").style.display=="")?("none"):("");
	}
	function Help_Menu(){
		document.getElementById("help").src = "Help/Menu.htm";
	}
	/* Help functions END */
	
	
	/* Save functions BEGIN */
	function SaveVisibile(){
		return ($('save_layer').getStyle('display')=="block")
	}
	function SaveShow(){
		var tLeft = 450;
		var tTop = 250;
		
		$('iframe_shim').setStyles('display:block; width:302px; height:192px; left:'+tLeft+'px; top:'+tTop+'px');
		$('save_layer').setStyles('display:block; width:300px; height:190px; left:'+tLeft+'px; top:'+tTop+'px');
	}
	function SaveHide(){
		$('iframe_shim').setStyle('display','none');
		$('paint_layer').setStyle('display','none');
	}
	function Save(){
		if (proj_exists==1) {
			document.view22RTE.Save(1);
		} else {
			SaveShow();
		}
	}
	function SaveAs(){
		var name = $('save_name').getValue();
		
		var ok_name= "";
		var charZ = "";
		var charZ_num = "";
		for (var count=0; count<name.length;count++ ){
			charZ = name.charAt(count);
			charZ_num = name.charCodeAt(count);
			switch(charZ_num){
				case 60 :
					charZ = "_";
					break;
				case 62 :
					charZ = "_";
					break;
				default:
					break;
			}
			ok_name = ok_name + charZ;
		}
		proj_exists = 1;
		SaveHide();
		document.view22RTE.SaveAs(ok_name,1,1);
	}
	function SaveComplete(project_id){
		//save the description
		var parameters = "project_id="+project_id+"&description="+$('save_description').getValue();
		new Ajax('save_desc.jsp', {
			data: parameters,
			onComplete: function(){
				alert('Your layout has been saved.');
			}
		}).request();
		
		proj_exists = 1;
	}
	/* Save functions END */
	
	/* Paint functions BEGIN */
	function PaintVisibile(){
		return ($('paint_layer').getStyle('display')=="block")
	}
	function PaintToggle(objectInstanceID,objectID){
		
		if (!(objectInstanceID==0 && objectID==0)){
			sel_object_id = objectID;
			sel_object_instance_id = objectInstanceID;
		}
		
		//if (sel_object_id==-2) { return; }
		
		if (!PaintVisibile()){
			
			var tLeft = 450;//event.client.x-150;
			var tTop = 200;//event.client.y-150;
			var tWidth = 330;
			var tHeight = 320;
			$('iframe_shim').setStyles('display:block; width:'+(tWidth+2)+'px; height:'+(tHeight+2)+'px; left:'+tLeft+'px; top:'+tTop+'px');
			$('paint_layer').setStyles('display:block; width:'+tWidth+'px; height:'+tHeight+'px; left:'+tLeft+'px; top:'+tTop+'px; border: 1px solid #666');
			$('paint_layer').empty();
			
			new Ajax('popups/paint.jsp', {
				update: 'paint_layer',
				data: 'object_instance_id='+sel_object_instance_id+'&object_id='+sel_object_id
				//data: 'object_id='+sel_object_id,
				//onComplete: function(response){
				//	var obj_type = response.trim();
				//	//alert(obj_type);
				//}
			}).request();
		} else {
			$('iframe_shim').setStyle('display','none');
			$('paint_layer').setStyle('display','none');
			PaintSetContext('Cabinet');
		}
	}
	function PaintSwitchTabs(strTab){
		paint_context = strTab;
		
		if (strTab=="Cabinet") {
			$('PaintTabBase').setStyle('background-image','url(images/tabSelected.png)');
			$('PaintTabDoors').setStyle('background-image','url(images/tabUnselected.png)');
		} else if (strTab=="Door") {
			$('PaintTabBase').setStyle('background-image','url(images/tabUnselected.png)');
			$('PaintTabDoors').setStyle('background-image','url(images/tabSelected.png)');
		}
	}
	function PaintSetContext(context){
		paint_context = context;
	}
	function PaintWalls(hexColour){
		view22RTE.SendAppMessage("PaintWalls",hexColour);
		view22RTE.SendAppMessage("PaintCeiling",hexColour);
	}
	function PaintFloor(object_id){
		view22RTE.SendAppMessage("SetFloor",object_id);
	}
	function PaintObject(colour){
		
		var PaintAllObjects = $("PaintAllObjects").getProperty("checked");
		var intPaintContext = 0;
		if (paint_context == "Door") { intPaintContext=3; } 
		
		if (PaintAllObjects){
			//get a listing of all object in the scene
			var strObjectList = view22RTE.SendAppMessage("GetObjectsText","");
			var arrObjectList = strObjectList.split(",");
			//alert(strObjectList);
			//paint all objects in the scene
			for(var i=0; i<=(arrObjectList.length-2); i+=2){
				//alert(arrObjectList[i]);
				//view22RTE.SendAppMessage("SetMaterialProperty","objectID="+arrObjectList[i]+" index="+intPaintContext+" materialID="+colour);
				view22RTE.SetMaterial(arrObjectList[i+1], paint_context, colour);
				
			}
			
			//view22RTE.SendAppMessage("SetMaterialProperty","objectID="+" index="+intPaintContext+" materialID="+colour);
			//view22RTE.SetMaterial(sel_object_instance_id, paint_context, colour);
		} else {
			view22RTE.SetMaterial(sel_object_instance_id, paint_context, colour);
		}
	}
	/* Paint functions END */
	
	
	function app_div_control(visible) {
		if (!is_moz) {
			document.getElementById("view22rte").style.visibility = (visible)?("visible"):("hidden");
			document.getElementById("view22rte").style.display = (visible)?(""):("none");
		}
	}
	
	function deSelect(objectInstanceID,objectID){
		
		sel_object_id = objectID;
		sel_object_instance_id = objectInstanceID;
		
		if (PaintVisibile()) { PaintToggle(0,0) }
		
        if((objectID==-2) && (objectID==objectInstanceID)){

		} else {
            if (objectID== -2) {
                floorSelected = true;
                counterSelected = false;
            } else if (objectID == -3) {
                counterSelected = true;
                floorSelected = false;
            } else {
                floorSelected = false;
                counterSelected = false;
            }
        }
    }
	
	function ObjectSelectionsDC(objectInstanceID,objectID){
        if (objectID == "" || objectID == "-1" || objectID == "-2" || objectID == "-3" || objectID == "-4" || objectID == "-5") {

		} else {
            document.view22RTE.ClientCommand(2,35);
        }
     }
	 
	/* Tips functions BEGIN */
	function initTips(){
		var show = Cookie.get('showTips');
		if (!show) {
			Cookie.set('showTips','yes');
		}
		if (Cookie.get('showTips')=='yes') {
			showTips();
		}	
	}
	function showTips(){
		$('tip_layer').setStyle('display','block');
	}
	function hideTips(){
		if ($('chkShowTips').getValue()=='on') {
			Cookie.set('showTips','no');
		} else {
			Cookie.set('showTips','yes');
		}
		$('tip_layer').setStyle('display','none');
	}
	/* Tips functions END */