
function IIf(i,j,k)
{
	if(i){ return j;} else {return k;}
} 

function ResetCheck()
{
CustomRadioReset();
CustomCheckBoxReset();
}

function CustomCheckBoxReset()
{
	var cbList = document.getElementsByTagName('input');
	for(var x=0;x < cbList.length;x++)
	{ 
		if (cbList[x].getAttribute('DefState') != null )
		{
			var aCB = cbList[x].parentNode;
			cbList[x].value = aCB.getAttribute('Wert');
			aCB.className="cbON";
		}
		else
		{
			if (cbList[x].parentNode.id.substr(0,4)=="cbsp")
			{
				var aCB = cbList[x].parentNode;
				aCB.className="cbOFF";
				cbList[x].value="";
			}
		}
	}
}

function CustomRadioReset()
{
var rbList = document.getElementsByTagName('span');
for(var x=0;x < rbList.length;x++)
{ 
	if (rbList[x].getAttribute('Gruppe') != null )
	{
		if (rbList[x].getAttribute('Checked') != null && rbList[x].getAttribute('Checked') == 'checked')
		{
			rbList[x].className='rbON';
		}
		else
		{
			rbList[x].className='rbOFF';
		}
	}
}
}

function CheckBoxSwitch(aObj)
{
	aObj.className= IIf(aObj.className=='cbOFF','cbON','cbOFF');
	var hiddField=document.getElementById(aObj.id.replace('cbspXmlGeneratedForm','XmlGeneratedForm'));
    hiddField.value=IIf(aObj.className=='cbON',aObj.getAttribute('Wert'),'');
}

function RadioButtonSwitch(aObj)
{
var rbList = document.getElementsByTagName('span');
for(var x=0;x < rbList.length;x++)
{ 
	if (rbList[x].getAttribute('Gruppe')==aObj.getAttribute('Gruppe'))
	{	rbList[x].className='rbOFF';
	//	document.getElementById(rbList[x].id.replace('rbspXmlGen','XmlGen')).value= '';
	}
}
	var rbCtrl = document.getElementById(aObj.id.replace('rbspXmlGen','XmlGen'));
	var rbCtrlId = getCtrlId(rbCtrl.id);
	aObj.className= IIf(aObj.className=='rbOFF','rbON','rbOFF');
	rbCtrl.checked= true;
	rbCtrl.value= rbCtrlId;
}


function getCtrlId(a)
{
var b = ''; var x = a.length; var z =1;
while(a.substr(x-z,1)!= '_'  && z <= x)
	{
	b=a.substr(x-z,1)+b;
	z++;
	}
return '_'+b ;
}


/* Javascript Funtions related to DropDown */

String.prototype.leftTrim = function()
{
	return (this.replace(/^\s+/, ""));
};

String.prototype.rightTrim = function()
{
	return (this.replace(/\s+$/, ""));
};

String.prototype.basicTrim = function()
{
	return (this.replace(/\s+$/, "").replace(/^\s+/, ""));
};

String.prototype.superTrim = function()
{
	return (this.replace(/\s+/g, " ").replace(/\s+$/, "").replace(/^\s+/, ""));
};

String.prototype.removeWhiteSpaces = function()
{
	return (this.replace(/\s+/g, ""));
};

function switchVisibility(obj)
{	
	if (obj.style.display != 'block')
	{		
		showElement(obj);
	}
	else
	{		
		hideElement(obj);		
	}
	return;
}

function hideElementViaTimeOut(obj)
{
	setTimeout(function(){hideElement(obj);},300);
}

function setSelectedValue(obj, selectionFieldId, selectedValueId)
{
	var inputObj = document.getElementById(selectedValueId);
	inputObj.value = obj.childNodes[0].nodeValue.basicTrim();
	hideElementViaTimeOut(document.getElementById(selectionFieldId));
	return;
}

function checkMousePosition(divObj, eventObj)
{
	var offSets = getElementOffsetsRelativeToWholePage(divObj);
	if (divObj.style.display == 'block')
	{
		if (((eventObj.clientX + document.documentElement.scrollLeft) <= (offSets.offsetLeft + 1)) || ((eventObj.clientX + document.documentElement.scrollLeft) > (offSets.offsetLeft + divObj.offsetWidth))) {
			hideElementViaTimeOut(divObj);
		}
		if (((eventObj.clientY + document.documentElement.scrollTop) <= (offSets.offsetTop + 1)) || ((eventObj.clientY + document.documentElement.scrollTop) > (offSets.offsetTop + divObj.offsetHeight))) {
			hideElementViaTimeOut(divObj);
		}
	}
	return;
}

function hideElement(obj)
{
	obj.style.zIndex = 0;
	obj.style.display = 'none';
	
	//reset zIndex back to 0
	var mainDropDownDiv = document.getElementById(obj.id.replace('SelectionField','divCustomDropDownList'));
	mainDropDownDiv.style.zIndex = 0;
	
	//only if browser is IE
	if (document.all)
	{
		//hide iframe if present:
		var iframeToRemove = document.getElementById(obj.id + "_baseIFRAME");
		if (iframeToRemove != null) 
		{			
			iframeToRemove.style.zIndex = 0;
			iframeToRemove.style.display = 'none';
		}
	}
	
}

function showElement(obj)
{
	obj.style.zIndex = 99;
	obj.style.display = 'block';
	
	//set a high zIndex to make sure, that the current dropdown is in front
	var mainDropDownDiv = document.getElementById(obj.id.replace('SelectionField','divCustomDropDownList'));
	mainDropDownDiv.style.zIndex = 97;
	
	//only if browser is IE
	if (document.all)
	{		
		//show or create iframe to overlap all the other html objects like "select" or "input" (IE 6 Problem).
		var iframeObj = document.getElementById(obj.id + "_baseIFRAME");
		if (iframeObj != null) 
		{			
			iframeObj.style.zIndex = 98;
			iframeObj.style.display = 'block';
		}
		else
		{			
			obj.insertAdjacentHTML("afterEnd", '<IFRAME style="position:absolute;z-index:98;display:block;" src="javascript:false;" frameBorder="0" scrolling="no" id="' + obj.id + '_baseIFRAME" />'); 			
			iframeObj = document.getElementById(obj.id + "_baseIFRAME"); 			
			iframeObj.style.top = obj.offsetTop;			
			iframeObj.style.left = obj.offsetLeft;
			iframeObj.style.width = obj.offsetWidth; 
			iframeObj.style.height = obj.offsetHeight;		
		}
	}
}

function getElementOffsetsRelativeToWholePage(element)
{
	var offSets = {offsetLeft:0,offsetTop:0};
	while(element)
	{
		offSets.offsetLeft += element.offsetLeft;
		offSets.offsetTop += element.offsetTop;
		element = element.offsetParent;
	}
	return offSets;
}