var varListIFrame = '';	
function ShowColorPicker(btn)
{	
	
	var theList = varListIFrame.split(",");
	var theHeader = GetHeaderControlID(btn.id);
	var calFrame =document.getElementById (theHeader + '_colorPickerIframe');
	var curColorInputText = document.getElementById (theHeader + '_currentColorInputText');
	var curColor = document.getElementById (theHeader + '_currentColor');
	var colorControlIDAndProperty = document.getElementById (theHeader + '_colorControlIDAndProperty');
	
	
	if (calFrame != null)
	{
		if(calFrame.style.display == 'none')
		{
			var LeftD=0;
			var TopD=0;
			var AbsoluteItem;
			for(var n2=btn; n2&&n2.tagName!='BODY'; n2=n2.offsetParent)
			{
				if(n2.style.position.toUpperCase() == "ABSOLUTE" || n2.style.overflowY.toUpperCase() == "AUTO")
					break;
				LeftD+=n2.offsetLeft;
				TopD+=n2.offsetTop;
			}
			
			calFrame.style.display = 'block';
			calFrame.style.top = TopD + btn.offsetHeight -22;
			calFrame.style.left = LeftD + 75;
			var tmp = curColorInputText.style.backgroundColor;
			if (tmp.length > 0 && tmp.charAt(0) == '#')
				tmp = tmp.substr(1) ;
			d = new Date();    //today's date	
			//alert('Component/ColorPicker.aspx?parentCurrentColor=' + tmp + '&parentIframeID=' + calFrame.id + '&parentShownCurrentColorID=' + curColorInputText.id);
			calFrame.src = '/Components/User/Tools/ColorPickerPage.aspx?parentCurrentColor=' + tmp + '&parentIframeID=' + calFrame.id +
			'&parentShownCurrentColorID=' + curColorInputText.id + '&curColorID=' + curColor.id +
			'&parentColorControlIDAndProperty=' + colorControlIDAndProperty.id;
			;//+ '&timeStamp=' + d.getSeconds();
			
		}
		else
		{
			calFrame.style.display = 'none';
		}
		
	}
	
	if (theList != null && theList.length > 0)
	{
		var i =0;
		for (; i < theList.length; i++)
		{
			var theIframeControl = document.getElementById(theList[i]);
			if (theIframeControl != null)
			{
				if (calFrame == null)
					theIframeControl.style.display='none';
				else if (calFrame.id != theIframeControl.id)
					theIframeControl.style.display='none';
			}
		}
	}
	
	
}

function OnClickChooseColor(CurrentColor, varShownCurrentColorID, variframeID, varCurrentColorID, varColorControlIDAndProperty)
{
	var IframeControl = document.getElementById(varShownCurrentColorID);
	if (IframeControl != null)
		IframeControl.style.display='none';
		
	var ShownColorControl = document.getElementById(variframeID);
	if (ShownColorControl != null)
		ShownColorControl.style.backgroundColor=CurrentColor;
		
	var CurColorControl = document.getElementById(varCurrentColorID);
	if (CurColorControl != null && CurrentColor.length > 0 && CurrentColor.charAt(0) == '#')
		CurColorControl.value = CurrentColor.substr(1);
	
	/*var changeColorType = document.getElementById(varControlChangeColorType);
	if (changeColorType != null)
	{
		var colorType = changeColorType.value.split(",");
		if (colorType != null && colorType.length > 1)
		{
			//ChangeColorForControl(controlID, thecolor, propertyType)
			if (typeof('ChangeColorForControl' == 'function'))
				ChangeColorForControl(colorType[0], CurColorControl.value, colorType[1]);
		}
	}*/
	//alert(varControlChangeColorType[0] + ' -- ' + varControlChangeColorType[1]);
	
	var changeColorType = document.getElementById(varColorControlIDAndProperty);
	if (changeColorType != null)
	{
		var colorType = changeColorType.value.split(",");
		if (colorType != null && colorType.length > 1)
		{
			//ChangeColorForControl(controlID, thecolor, propertyType)
			if ( typeof(ChangeColorForControl) == 'function' )
			{
				ChangeColorForControl(colorType[0], CurColorControl.value, colorType[1]);
			}
		}
	}
}

function GetHeaderControlID(theObj)
{		
	var lastIndex = theObj.lastIndexOf('_');
	return theObj.substring(0, lastIndex);
}

function DoCloseWindow(obj)
{
	var IframeControl = document.getElementById(obj);
	if (IframeControl != null)
		IframeControl.style.display='none';
}
