/*
Copyright (c) 2006, Rapex.dk All rights reserved.
version: 0.0.0
*/
/*

*/

var Tool_Form_Functions = function() {};

Tool_Form_Functions.prototype = Elements.prototype;


Tool_Form_Functions.prototype.InsertLink = function(TargeObject,LinkString, TextString, ClassName)
{
  var returnObject = this.Div(TargeObject);
  returnObject.className = ClassName;
	var returnObject_A = this.A(returnObject);
	returnObject_A.href = LinkString;
  this.Text(TextString,returnObject_A);
  return returnObject;
}

Tool_Form_Functions.prototype.InsertTextLine = function(TargeObject,TextString,ClassName)
{
  var returnObject = this.Div(TargeObject);
  returnObject.className = ClassName;
  this.Text(TextString,returnObject);
  return returnObject;
}

Tool_Form_Functions.prototype.InsertInput = function(TargetObject,InputValue, TextString, ClassName,InputType,InputClass)
{
	var Cont = this.P(TargetObject)
  if (!InputType) InputType = "text";
  var returnObject = this.Div(Cont);
  returnObject.className = ClassName;
  this.Text(TextString,returnObject);
	var InputField = this.Input(returnObject,InputType);
	InputField.name = ClassName;
	if (InputType=="text" || InputType=="hidden" || InputType=="button") InputField.value = InputValue;
	if (InputType=="checkbox") InputField.checked = InputValue;
  if (InputClass) InputField.className = InputClass;
//  returnObject.style.height = parseInt(Height(InputField)*1.2) +"px";
	returnObject.InputField = InputField;
  return returnObject;
}

Tool_Form_Functions.prototype.InputBox = function(TargeObject,InputValue, TextString, ClassName,InputType,InputClass)
{
  if (!InputType) InputType = "text";
  var returnObject = this.Div(TargeObject);
  returnObject.className = ClassName;
  this.Text(TextString,returnObject);
	var InputField = this.Input(returnObject,InputType);
	if (InputType=="text" || InputType=="hidden" || InputType=="button") InputField.value = InputValue;
	if (InputType=="checkbox") InputField.checked = InputValue;
  if (InputClass) InputField.className = InputClass;
  returnObject.style.height = parseInt(Height(InputField)*1.2) +"px";
	returnObject.InputField = InputField;
  return returnObject;
}


Tool_Form_Functions.prototype.InsertSelect = function(TargeObject,TextString,ClassName,SelectObj,SelectTarget,SelectClass,SelectSize,SelectName)
{
  if (!SelectSize) SelectSize = 1;
  if (!SelectName) SelectName  = "StandardName";
  var returnObject = this.Div(TargeObject);
  returnObject.className = ClassName;
  this.Text(TextString,returnObject);
	var SelectField = this.selectType(returnObject,SelectSize,SelectName,SelectObj,SelectTarget);
  if (SelectClass) SelectField.className = SelectClass;
  returnObject.style.height = parseInt(Height(SelectField)*1.2) +"px";
	returnObject.SelectField = SelectField;
  return returnObject;
}

Tool_Form_Functions.prototype.InsertActionButton = function(TargeObject,InputValue,ButtonClass,TargetFunction)
{
  var returnObject = this.Div(TargeObject);
 	var InputField = this.Input(returnObject,"button");
  InputField.className = ButtonClass;
	InputField.value = InputValue;
	this.Click(InputField,TargetFunction,this)
  return returnObject;
}

Tool_Form_Functions.prototype.CheckBoxArray = function(TargeObject,CheckBoxes,CheckBoxValues,ClassName,HeadLineText,HeadLineStyle)
{
  var Element = this.Div(TargeObject);
  var Headline = this.Div(Element);
	this.InsertTextLine(Headline,HeadLineText,HeadLineStyle);
  Element.className = ClassName;
  var Boxes = new Array();
  for (var n=0; n<CheckBoxes.length; n++)
  {
  	var Cont = this.Div(Element);
    Boxes[n] = new Array();
	 	Boxes[n].id = CheckBoxes[n].Id
	 	Boxes[n].box = this.Input(Cont,"checkbox");
	 	Boxes[n].box.checked = CheckBoxValues[n];
	 	Boxes[n].box.title = CheckBoxes[n].Desciption
	 	var TextVal = this.Span(Cont);
	 	TextVal.className = "tab_2";
	 	this.Text(CheckBoxes[n].Rolle,TextVal);
	 	TextVal.title = CheckBoxes[n].Desciption
	}
	return Boxes;
}

Tool_Form_Functions.prototype.TableWriter = function(TargetObj,TableArray,TableHeadline,TableHeadStyle,TableStyle,TableLineStyle1,TableLineStyle2,Table1stLineStyle,TableEndLineStyle)
{
	var oTable = document.createElement('table');
 	if (TableStyle) oTable.className = TableStyle;
	if (TableHeadline!="") {
		var oThead = document.createElement('thead');
		var oTR = document.createElement('tr');
		var oTD = document.createElement('td');
		this.Text(""+TableHeadline,oTD)
	  if (TableHeadStyle) oThead.className = TableHeadStyle;
	  oTD.colSpan = TableArray[0].length;
		oTR.appendChild(oTD);
		oThead.appendChild(oTR);
		oTable.appendChild(oThead);
	}
	var oTBody = document.createElement('tbody');
  for (var n=0; n<TableArray.length; n++)
  {
		var oTR = document.createElement('tr');
    if (even(n) && TableLineStyle1) oTR.className = TableLineStyle1;
    else  if (TableLineStyle2) oTR.className = TableLineStyle2;
//    oTR.title = "Row " + n;
    if (n==0 && Table1stLineStyle) oTR.className = Table1stLineStyle;
    if (n==(TableArray.length-1) && TableEndLineStyle) oTR.className = TableEndLineStyle;
  	for (var t=0; t<TableArray[n].length;t++)
  	{
			var oTD = document.createElement('td');
			this.Text(""+TableArray[n][t],oTD)
			oTR.appendChild(oTD);
		}
		oTBody.appendChild(oTR);
	}
	oTable.appendChild(oTBody);
	TargetObj.appendChild(oTable);
	if (bottomPos(oTable)>bottomPos(TargetObj)) TargetObj.style.height = bottomPos(oTable)+"px";
	return oTable;
}
//document.onmousedown = selectmouse;

Tool_Form_Functions.prototype.BoxModelHeadClose = function(Obj,id)
{
	  Box___Model__Obj__Test[id] = true;
	  Box___Model__Obj[id].style.display ="none"
	  Obj.deleteElements(Box___Model__Obj[id]);
}

Tool_Form_Functions.prototype.BoxModelHead = function(Head,BoxClass,Obj,id)
{
  if (typeof Box___Model__Obj=="undefined") {
	  Box___Model__Obj =new Array();
	  Box___Model__Obj__Test =new Array();
  }
	if (typeof Box___Model__Obj[id]!="object") 
	{
	  Box___Model__Obj[id] = this.Div(document.body);
	  Box___Model__Obj__Test[id] = true
	}

	if (Box___Model__Obj__Test[id]==false) {
	  Obj.BoxModelHeadClose(Obj,id);
	}

  Box___Model__Obj[id].BoxMove = false;
	function fClose()	{}
	function fMove(Obj,id)	{
	  if (Box___Model__Obj[id].BoxMove!=true) return
		Box___Model__Obj[id].style.left = MousePosX - Box___Model__Obj[id].MousePosX + "px";
		Box___Model__Obj[id].style.top = MousePosY - Box___Model__Obj[id].MousePosY+ "px";
	}
	function fDown(Obj,id)	{ 
	  Box___Model__Obj[id].MousePosX = MousePosX-leftPos(Box___Model__Obj[id]);
	  Box___Model__Obj[id].MousePosY = MousePosY-topPos(Box___Model__Obj[id]);
	  Box___Model__Obj[id].BoxMove =true;
	  Box___Model__Obj[id].focus();
	}

	function fFocus(Obj,id)	{ 
	  for (var n=0; n<Box___Model__Obj.length; n++)
	  {
		  if (typeof Box___Model__Obj[n]=="object") Box___Model__Obj[n].style.zIndex = 1;
		}
	  Box___Model__Obj[id].style.zIndex = 100;
	}

	function fUp(Obj,id)	{
	  Box___Model__Obj[id].BoxMove =false;
	}

	Box___Model__Obj__Test[id] = false;
  Box___Model__Obj[id] = Obj.Div(document.body);
  Box___Model__Obj[id].style.display ="block"
	Box___Model__Obj[id].style.left = MousePosX + "px";
	Box___Model__Obj[id].style.top = MousePosY + "px";
	Box___Model__Obj[id].className = BoxClass;
	var HeadElement = Obj.Div(Box___Model__Obj[id]);
	HeadElement.className = BoxClass+"Head";
	Obj.MouseMove(document,fMove,Obj,id)
	Obj.MouseDown(Box___Model__Obj[id],fFocus,Obj,id)
	Obj.MouseDown(HeadElement,fDown,Obj,id)
	Obj.MouseUp(document,fUp,Obj,id)
	Obj.Text(Head,HeadElement)                
	var CloseElement  = Obj.Div(HeadElement);
	Obj.Click(CloseElement,Obj.BoxModelHead,"","",Obj,id)
	return Box___Model__Obj[id];
}

Tool_Form_Functions.prototype.InsertBoxAtPos = function(BoxObj,NameTarget, TitleTarget, LinkTarget,Obj,ObjClass,clearObj)
{
 	var Element = this.Div(BoxObj);
  for (var n=0; n<Obj.length; n++)
  {
    var newLink  = this.InsertLink(Element,"Javascript: "+NameTarget+".value='"+ Obj[n].Name + "'; "+LinkTarget+".value='"+ Obj[n].Link + "'; "+TitleTarget+".value='"+ Obj[n].Desciption + "'; " +clearObj + ".style.display='none'; void(0);", Obj[n].Name, ObjClass);
    newLink.title = Obj[n].Desciption;
	  
	}
	return Element;
}

Tool_Form_Functions.prototype.EditBoxClose = function(Obj)
{
  Obj.EditBox_Obj.style.display = "none"
}

Tool_Form_Functions.prototype.EditBox = function(BoxObjClass,TargeObject,InputArray)
{
	function WClose(Element){}
	if (this.EditBox_Obj)  this.deleteElements(this.EditBox_Obj);
  else this.EditBox_Obj = this.Div(document.body);
  this.EditBox_Obj.style.display = "block"
 	this.EditBox_Obj.className = BoxObjClass;
 	this.EditBox_Obj.style.left = MousePosX + "px";
 	this.EditBox_Obj.style.top = MousePosY + "px";
	
 	this.EditBox_ReturnArray = new Array();
  for (var n=0; n<InputArray[0].length; n++)
  {
	  var ReturnField = this.InsertInput(this.EditBox_Obj,InputArray[0][n],InputArray[1][n], '',InputArray[2][n],'tab_5')
	  this.EditBox_ReturnArray[n] = ReturnField.InputField;
	}
	this.EditBox_ReturnArray.Close = this.EditBox_Obj;
	
 	this.EditBoxActionButton = this.InsertActionButton(this.EditBox_Obj,txt.Text_0073 ,"Admin_Function_Save",TargeObject);
//	this.Click(this.EditBoxActionButton,this.EditBoxClose,this)
 	this.EditBoxCanselButton = this.InsertActionButton(this.EditBox_Obj,txt.Text_0083 ,"Admin_Function_Cancel",WClose);
	this.Click(this.EditBoxCanselButton,this.EditBoxClose,this)

	return this.EditBox_ReturnArray;
}
Tool_Form_Functions.prototype.BoxStyle = "BoxStyle";
Tool_Form_Functions.prototype.BoxHeadLineStyle = "BoxHeadLineStyle";
Tool_Form_Functions.prototype.BoxBodyLineStyle = "BoxBodyLineStyle";

Tool_Form_Functions.prototype.CreateBox = function(Obj,HeadLine)
{
	var BoxObj = this.Div(Obj);
	BoxObj.className = this.BoxStyle;
	var HeadObj = this.Div(BoxObj);
	HeadObj.className = this.BoxHeadLineStyle;
	this.Text(HeadLine,HeadObj);
	return BoxObj
}

Tool_Form_Functions.prototype.AddToBox = function(Obj,TextLine,LinkLine,Acces,htmText)
{
	var BoxObj = this.Div(Obj);
	var LinkObj = this.A(BoxObj);
	BoxObj.className = this.BoxBodyLineStyle;
	if (Acces != false && LinkLine != false) 
		{
			this.Text(TextLine,LinkObj); 
			LinkObj.href = LinkLine;
		}
		else 
		{
			this.Text(TextLine,BoxObj);
			LinkObj.style.color = "gray";
		}
	if (typeof htmText=="string") this.Text(htmText,BoxObj);
	return true;
}

