﻿pageLoaded=false;
formSubmited=false;

function getObj(obj_id){
	return document.getElementById(obj_id);
}

function showLayer(obj_id){
	getObj(obj_id).style.display='';
}

function hideLayer(obj_id){
	getObj(obj_id).style.display='none';
}

function toogleLayerVisibility(obj_id)
{
	if(getObj(obj_id).style.display=='none')
	{
		showLayer(obj_id);
		getObj(obj_id).scrollIntoView(true);
	}
	else
	{
		hideLayer(obj_id);
	}
}

function init()
{
	icons=getObj('scriptIcons').getElementsByTagName('img');
	for(i=0;i<icons.length;i++)
	{
			icons[i].onclick=function()
			{
				scriptSelected(this.getAttribute('id').substring(11)); 
			}
	}
	document.forms['process'].reset();
	pageLoaded=true;
}

function scriptSelected(script_id)
{
	if(pageLoaded)
	{
		document.forms['process'].script_id.value=script_id;
		hideLayer('stepScript');
		if(getObj('result')){
			hideLayer('result');
		}
		showLayer('stepPhoto');
	}
}

function photoSelected()
{
	if(pageLoaded && document.forms['process'].image.value!="")
	{
		hideLayer('stepPhoto');	showLayer('stepUpload');
		startUpload();
	}
}

function startUpload()
{
	if(!formSubmited)
	{
		document.forms['process'].submit();
		setTimeout("updateProgressIndicator()",200);
		formSubmited=true;
	}
}

function updateProgressIndicator()
{
	getObj('progressIndicatorImage').src='/templates/images/photoPattern/process.gif';
}

function getAjaxObject()
{
	obj=null;
	if(window.XMLHttpRequest)
	{
        	try
		{
            		obj=new XMLHttpRequest();
        	}
		catch(e){}
	}
	else if(window.ActiveXObject)
	{
        	try
		{
			obj=new ActiveXObject('Msxml2.XMLHTTP');
        	}
		catch(e)
		{
			try
			{
				obj=new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch(e){}
		}
	}
	return obj;
}

function loadScriptPrompt(script_id)
{
	req=getAjaxObject();
	if(req)
	{
		req.onreadystatechange=processScriptPromptLoad;
		req.open('GET','/?prompt='+script_id,true);
		req.send(null);
	}
	else
	{
		getObj('promptControls').innerHTML='Unable to retrieve data';
	}
}
 
function processScriptPromptLoad()
{
    	if(req.readyState==4)
	{
        	if(req.status==200)
		{
			getObj('promptControls').innerHTML=req.responseText;
		}
		else
		{
			getObj('promptControls').innerHTML='Unable to retrieve data';
		}
	}
}
