//Function to Disable/ Enable a panel

// ID:= object with value to check;  
// checkVal := de waarde waar de ID op getest wordt voor TRUE
// divID = ID from panel(DIV)

function TripleSDivPanel( IDx, checkVal,  divID) 
{
    var checkValArray = checkVal.split(":");
    var divIDArray = divID.split(":");
    if (checkValArray.length != divIDArray.length)
    {
        alert("Something wrong: " + IDx.toString());
    }
    else
    {
        for(var i=0; i<checkValArray.length; i++)
        {
           TripleSDivPanelSingle( IDx, checkValArray[i],  divIDArray[i])  ;
        }
    }
}




function TripleSDivPanelSingle( IDx, checkVal,  divID) 
{
    var idx =document.all ? document.all[IDx] : document.getElementById(IDx);
    if (idx == null)
        return;
        
    var bDisplay;
    if (idx.className=='DropDownListAT')
    {
        bDisplay = TripleSCheckValue(idx.value ,checkVal);
    }
    else if (idx.className=='TextBoxAT')
    {
        bDisplay = TripleSCheckValue(idx.value ,checkVal);
    }
    else if (idx.className =='RadioButtonListAT')
    {
        var x = TripleSRadioButtonListValue(idx, idx.onclick);
        if (x==null)//NO checked value found. 
            bDisplay = (checkVal == 'null') ? true : false;
        else
            bDisplay = TripleSCheckValue(x , checkVal);
   
    }
    else if (idx.type=='checkbox')//className wordt niet gezet in asp.net 2.0 !!!!!
    {
        bDisplay = TripleSCheckValue(idx.checked.toString() ,checkVal);
    }

    var ar = divID.split(";");
    var src, ctrl;
    var bDisp;
    for (var i=0; i<ar.length; i++)
    {
        if (ar[i].charAt(0)=='!')
        {//This is a not condition
            ctrl=ar[i].substr(1);
            bDisp = !bDisplay;
        }
        else
        {//This is a normal condition
            ctrl=ar[i];
            bDisp=bDisplay;
        }
        
        src=document.all ? document.all[ctrl] : document.getElementById(ctrl);
        if (src==null)
        {
            alert("foute control: '" + ctrl + "'  complete: " + divID);
        }
        else
        {
            if (false && src.className == 'FormButtonAT')//Soms wil je de knop enabled en soms weghalen. Ik weet nog niet hoe je dit aan moet geven
                src.disabled = !bDisp;
            else
                src.style.display = (bDisp) ? '' : 'none';
        }
    }
}

function TripleSRadioButtonListValue( idx, idxOnClick )
{
    if (idx.tagName == 'INPUT')//Only take the input objects and if selected
    {
        idx.onclick = idxOnClick;//The original OnClick is only on the main item and not on the individual
        if (idx.checked)
            return idx.value;
    }
    var ret;
    for (var i=0; i < idx.childNodes.length; i++)
    {
       ret = TripleSRadioButtonListValue(idx.childNodes[i], idxOnClick);
       if (ret != null)
        return ret;
    }

    return null;
}


// Check if the val voorkomt in de checkVal
// Checkval kan een single waarde zijn of een waarde met OR | 
function TripleSCheckValue( val, checkVal)
{
    strOR = checkVal.split("|");
    //Check on OR values
    for (var i=0; i<strOR.length; i++)
    {
        if (val== strOR[i])
            return true;
    }
    return false;
}


//Display Message Box with OK/Cancel
//Do this when the value of the control = checkValue
//If Cancel is pressed, set value to CancelValue
function TripleSOkCancel(IDx, checkValue, cancelValue, message) 
{
    var idx = document.all ? document.all[IDx] : document.getElementById(IDx);
    if (idx == null)
        return;

    if (idx.value == checkValue) 
    {
        if (!confirm(message.replace(/<nl>/g, '\n')))
            idx.value = cancelValue;
    }
}



//////////////////////////////////////////////////////////////////
// qTip - CSS Tool Tips - by Craig Erskine
// http://qrayg.com
//
// Multi-tag support by James Crooke
// http://www.cj-design.com
//
// Inspired by code from Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//////////////////////////////////////////////////////////////////

var qTipTag = "a,label,div,img"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX = 0; //This is qTip's X offset//
var qTipY = 15; //This is qTip's Y offset//

//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle, elements;
	
	var elementList = qTipTag.split(",");
	for(var j = 0; j < elementList.length; j++)
	{	
		elements = document.getElementsByTagName(elementList[j]);
		if(elements)
		{
			for (var i = 0; i < elements.length; i ++)
			{
				a = elements[i];
				sTitle = a.getAttribute("title");				
				if(sTitle)
				{
					a.setAttribute("tiptitle", sTitle);
					a.removeAttribute("title");
					a.removeAttribute("alt");
					a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
					a.onmouseout = function() {tooltip.hide()};
				}
			}
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

window.onload = function () {
	tooltip.init ();
}
