function QxHideControl (tagName, subMenu, show)
{
	var x = QxGetX (subMenu);
	var y = QxGetY (subMenu);
	var w = subMenu.offsetWidth;
	var h = subMenu.offsetHeight;
	var i;
	for (i = 0; i < document.all.tags(tagName).length; ++i)
	{
		var obj = document.all.tags(tagName)[i];
		if (!obj || !obj.offsetParent)
			continue;
		var ox = QxGetX (obj);
		var oy = QxGetY (obj);
		var ow = obj.offsetWidth;
		var oh = obj.offsetHeight;

		if (ox > (x + w) || (ox + ow) < x)
			continue;
		if (oy > (y + h) || (oy + oh) < y)
			continue;
			
		if(!show){obj.style.visibility = "visible";}else{obj.style.visibility = "hidden";}
	}
}

function QxHideParentControl(tagName, subMenu, show)
{
	var x = QxGetX (subMenu);
	var y = QxGetY (subMenu);
	var w = subMenu.offsetWidth;
	var h = subMenu.offsetHeight;
	var i;
	for (i = 0; i < window.parent.document.all.tags(tagName).length; ++i)
	{
		var obj = window.parent.document.all.tags(tagName)[i];
		if (!obj || !obj.offsetParent)
			continue;
		var ox = QxGetX (obj);
		var oy = QxGetY (obj);
		var ow = obj.offsetWidth;
		var oh = obj.offsetHeight;

		if (ox > (x + w) || (ox + ow) < x)
			continue;
		if (oy > (y + h) || (oy + oh) < y)
			continue;
			
		if(!show){obj.style.visibility = "visible";}else{obj.style.visibility = "hidden";}
	}
}

function QxGetX (obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function QxGetY (obj)
{
var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y){curtop += obj.y;}
	return curtop;
}


function SetElementPopupLocation(FrameElement, ElementCalled, ElementValue){
var Element = document.getElementById(FrameElement);
if(Element!=null){
	var yLoc =  QxGetY(ElementCalled) + parseInt(ElementCalled.clientHeight)+ 5;
	var xLoc = QxGetX(ElementCalled);  
	Element.style.top = yLoc+'px';
	Element.style.left = xLoc+'px';
	window.frames(Element.name).document.getElementById('ElementFrameName').value= Element.name;
	window.frames(Element.name).document.getElementById('ElementInputName').value= ElementValue.name;
	QxHideControl('select', Element, true);
}
}

function HideElementPopup(FrameElement){
	var TempElementValue = document.getElementById(FrameElement);
	var Element = window.parent.document.getElementById(TempElementValue.value);
	QxHideParentControl('select', Element, false);
	Element.style.top = '-500px';
	Element.style.left = '-500px';
}

function AddToInputElement(InputElement, ElementValue){	
	var Element = document.getElementById(InputElement);
	window.parent.document.getElementById(Element.value).value = ElementValue;
	var isAccountControl = Element.value.indexOf('Account', 0);
	var isItemControl = Element.value.indexOf('Item', 0);
	if(isAccountControl!=-1){
		var isSingleControlDebet = Element.value.indexOf('TransactionDetailDebet0', 0);
		var isSingleControlCredit = Element.value.indexOf('TransactionDetailCredit0', 0);
		var TempElement = window.parent.document.getElementById(Element.value);
		if(isSingleControlDebet!=-1)
		{window.parent.TransactionDetailPopUpOnChangeSingleControl(Element.value);}else
		if(isSingleControlCredit!=-1)
		{window.parent.TransactionDetailPopUpOnChangeSingleControl(Element.value);}else
		{	
		for(var i=0; i< Element.value.length; i++){
			var CharAtIndex = Element.value.charAt(i);
			if(!isNaN(parseInt(CharAtIndex))){var RowID = CharAtIndex;}
		}
		var TempElement = window.parent.document.getElementById(Element.value);
		window.parent.TransactionDetailPopUpOnChange(RowID, Element.value);
	  }
  }
  if(isItemControl!=-1){
		for(var i=0; i< Element.value.length; i++){
			var CharAtIndex = Element.value.charAt(i);
			if(!isNaN(parseInt(CharAtIndex))){var RowID = CharAtIndex;}
		}
		var TempElement = window.parent.document.getElementById(Element.value);
		window.parent.TransactionDetailPopUpItemOnChange(RowID, Element.value);
  }
}

function AddToInputElementNotTree(InputElementID, InputElementValue, ElementID, ElementValue){	
	//alert(InputElementID+"<><>"+InputElementValue+"<><>"+ElementID+"<><>"+ElementValue);
	//alert(document.getElementById(InputElementID).value+"<><>"+document.getElementById(InputElementValue).value);
	if (document.getElementById(InputElementID).value!=""){
  //alert('0');	
	var FElementValue = document.getElementById(InputElementID);
	window.parent.document.getElementById(FElementValue.value).value = ElementValue;
	var FElementID = document.getElementById(InputElementValue);
	window.parent.document.getElementById(FElementID.value).value = ElementID;
  }else{
  //alert('1');	
	var FElementValue = document.getElementById(InputElementValue);
	window.parent.document.getElementById(FElementValue.value).value = ElementID;
  }
}

function SetElementPopupLocationNotTree(FrameElement, ElementCalled, ElementValue, ElementID){
var Element = document.getElementById(FrameElement);
if(Element!=null){
	var yLoc =  QxGetY(ElementCalled) + parseInt(ElementCalled.clientHeight)+ 5;
	var xLoc = QxGetX(ElementCalled);  
	Element.style.top = yLoc+'px';
	Element.style.left = xLoc+'px';
	window.frames(Element.name).document.getElementById('ElementFrameName').value= Element.name;
	window.frames(Element.name).document.getElementById('ElementInputName').value= ElementValue.name;
	window.frames(Element.name).document.getElementById('ElementInputID').value= ElementID.name;
	QxHideControl('select', Element, true);
}
}
