function ChangeDynamicElementVisibleStatus(ID, IsVisible, RepeaterName, RepeaterRepID, Type)
{

	var obj = null;
	if (RepeaterName != "" && RepeaterRepID != "")
	{
	  obj = document.getElementsByName('cwAutoRepControl[_'+RepeaterName+'_'+RepeaterRepID+'_'+ID+']')[0];
	}
	// do check this way in order to make sure that a change request can also go out of
	// a repeat section
	if (obj == null)
	{
	  obj = document.getElementsByName('cwAutoControl['+ID+']')[0];
	}


		//alert('cwAutoControl['+ID+']');
	if (obj != null)
	{
		if (Type == "visibility")
		{
			//alert(obj.style.display);
			obj.style.display = (IsVisible) ? '' : 'none';      // evtl wieder auf inline setzen.
		}
		else if (Type == "checked")
		{
			obj.checked = IsVisible;
		}
	}
	else
	{
		// maybe its a table so look for the ID only
		obj = document.getElementById(ID);
		if (obj != null)
		{
			if (Type == "visibility")
			{
				obj.style.display = (IsVisible) ? '' : 'none'; 	// evtl wieder auf inline setzen.
			}
			else if (Type == "checked")
			{
				obj.checked = IsVisible;
			}
		}
	}
	obj = null;
}

function ChangeType(Type, Field)
{
		// set type
		document.getElementById(Field.substr(0, Field.length-1)+'Type]').innerHTML = Type;

		var NewHTML = "";
		switch (Type)
		{
			case "FIELD":
				NewHTML = document.getElementById('Prototype_Field').innerHTML.replace(/{FIELD}/g, Field);
			break;

			case "STATIC":
				NewHTML = document.getElementById('Prototype_Static').innerHTML.replace(/{FIELD}/g, Field);
			break;

			case "VARIABLE":
				NewHTML = document.getElementById('Prototype_Static').innerHTML.replace(/{FIELD}/g, Field);
			break;
			case "POST":
				NewHTML = document.getElementById('Prototype_Static').innerHTML.replace(/{FIELD}/g, Field);
			break;
			case "GET":
				NewHTML = document.getElementById('Prototype_Static').innerHTML.replace(/{FIELD}/g, Field);
			break;
			case "SESSION":
				NewHTML = document.getElementById('Prototype_Static').innerHTML.replace(/{FIELD}/g, Field);
			break;
			case "COOKIE":
				NewHTML = document.getElementById('Prototype_Static').innerHTML.replace(/{FIELD}/g, Field);
			break;
			case "PERMISSION":
				NewHTML = document.getElementById('Prototype_Permission').innerHTML.replace(/{FIELD}/g, Field);
			break;
			case "ACTION":
				NewHTML = document.getElementById('Prototype_Action').innerHTML.replace(/cwAutoControl\[CallActionField\]/g, Field);
			break;
		}
		document.getElementById(Field+'_span').innerHTML = NewHTML;
		NewHTML = null;
}


// functions for the sequenz boxes
function CopyElement(SourceSelect, DestinationSelect, Save)
{
	var SourceElement = document.getElementById(SourceSelect);
	var DestinationElement = document.getElementById(DestinationSelect);
	var SaveElement = document.getElementById(Save);

	if (SourceElement != null && DestinationElement != null && SaveElement != null)
	{
		// copy entry
		var Entry = DestinationElement.appendChild(document.createElement("option"));
		Entry.text = SourceElement.options[ SourceElement.selectedIndex ].text;
		Entry.value = SourceElement.options[ SourceElement.selectedIndex ].value;
		DestinationElement.selectedIndex = DestinationElement.options.length - 1;
		// IE workaround (manually change chombobox width)
		if('\v'=='v') {
			DestinationElement.style.width = (Entry.text.length + 2) + 'ex';
		}

		UpdateSaveField(DestinationElement, SaveElement);
		Entry = null;
	}
	
	SourceElement = null;
	DestinationElement = null;
	SaveElement = null;
}

function DeleteOption(Element, Save)
{
	var Element = document.getElementById(Element);
	var SaveElement = document.getElementById(Save);

	if (Element != null && SaveElement != null)
	{
		if (Element.selectedIndex != null)
		{
			Element.options[ Element.selectedIndex ] = null;
		}
		UpdateSaveField(Element, SaveElement);
		if (Element.options.length > 0)
		{
			Element.options[ Element.options.length - 1 ].selected = true;
		}
	}
	Element = null;
	SaveElement = null;
}

function MoveOption(Element, Direction, Save)
{
	var Element = document.getElementById(Element);
	var SaveElement = document.getElementById(Save);

	var Index = Element.selectedIndex;

	var options = new Array();

	if (Element != null && SaveElement != null && (Index >= 0))
	{
		// clear list first
		for (i = Element.options.length; i > 0; i--)
		{
			var Entry = document.createElement("option");
				Entry.text = Element.options[i-1].text;
				Entry.value = Element.options[i-1].value;
			options.push(Entry);
			Element.options[i-1] = null;
			Entry = null;
		}
		sortedoptions = new Array();
		// bring options in rihgt order
		for (i = options.length; i > 0; i--)
		{
			sortedoptions.push(options[i-1]);
		}

		var selectedObject = false;
		for (i = 0; i < sortedoptions.length; i++)
		{

			if (Direction == 'UP')
			{
				if (Index-1 == i && Index != 0)
				{
					sortedoptions[i+1].selected = true;
					selectedObject = true;
					Element.add(sortedoptions[i+1], null);
				}
				else if (Index == i && Index != 0)
				{
					Element.add(sortedoptions[i-1], null);
				}
				else
				{
					Element.add(sortedoptions[i], null);
				}
			}
			else if (Direction == 'DOWN')
			{
				if (Index == i && Index != sortedoptions.length - 1)
				{
					Element.add(sortedoptions[i+1], null);
				}
				else if (Index+1 == i && Index != sortedoptions.length - 1)
				{
					sortedoptions[i-1].selected = true;
					selectedObject = true;
					Element.add(sortedoptions[i-1], null);
				}
				else
				{
					Element.add(sortedoptions[i], null);
				}
			}
		}

		if (!selectedObject)
		{
			if (Element.options.length > 0 && Direction == 'DOWN')
			{
				Element.options[ Element.options.length - 1 ].selected = true;
			}
			else if (Element.options.length > 0 && Direction == 'UP')
			{
				Element.options[ 0 ].selected = true;
			}
		}
		UpdateSaveField(Element, SaveElement);
		
		sortedoptions = null;
	}
	options = null;
	Element = null;
	SaveElement = null;
	
}

function UpdateSaveField(List, SaveField)
{
	// clear
	SaveField.innerHTML = "";
	for (i = 0; i < List.options.length; i++)
	{
		SaveField.innerHTML += List.options[i].value;
		if (i+1 != List.options.length)
		{
			SaveField.innerHTML += "|";
		}
	}
}

function VerificationShowPart(Part)
{
	if (Part == 'Confirmation')
	{
		document.getElementById('Condition').style.display = 'none';
		document.getElementById('Confirmation').style.display = 'block';
	}
	else
	{
		document.getElementById('Condition').style.display = 'block';
		document.getElementById('Confirmation').style.display = 'none';
		document.getElementById("cwAutoControl[ConfirmationMessage]").value = '';
	}

}
