//hides elements with the given tagName overlapping the given div
//the hide parameter is boolean 
function HideOverlappingElements(tagName, hide, div){
var a=document.getElementsByTagName(tagName);
var overDiv=div;
for(var i=0;i<a.length;i++){
	obj=a[i];
	obj.style.visibility = '';
	if (!hide){continue;}

	objLeft = obj.offsetLeft;
	objTop = obj.offsetTop;
	objParent = obj.offsetParent;

	while( objParent.tagName.toUpperCase() != 'BODY' )
	{
		objLeft += objParent.offsetLeft;
		objTop  += objParent.offsetTop;
		objParent = objParent.offsetParent;
	}

	objHeight = obj.offsetHeight;
	objWidth = obj.offsetWidth;


		if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
		else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
		else if( overDiv.offsetTop >= ( objTop + objHeight ));
		else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
		else
		{
			obj.style.visibility = 'hidden';
		}
  }
}

//hides 'select' and 'object' elements overlapping the given div
function HideOverlaps(hide, div)
{
	HideOverlappingElements("select", hide, div);
	HideOverlappingElements("object", hide, div);
}

function DisplayLabelText(labelID,labelText)
{
    var label = document.getElementById(labelID);
    if(label)
    {
        label.innerHTML = labelText;
    }
}

var t = 0;
function selectAllByCheckboxName(chkAll, checkBoxesName)
{
	for (var i=0; i<chkAll.form.length; i++)
		if (chkAll.form[i].type=="checkbox" && chkAll.form[i].name.indexOf(checkBoxesName) > -1)
			chkAll.form[i].checked = chkAll.checked
}
function selectAllByCheckboxID(chkAll, checkBoxesId)
{
	for (var i=0; i<chkAll.form.length; i++)
		if (chkAll.form[i].type=="checkbox" && chkAll.form[i].id.indexOf(checkBoxesId) > -1)
			chkAll.form[i].checked = chkAll.checked
}

function toggleSelectAllIfCheckBoxesChange1(checkbox, chkAllClientID,checkBoxesName)
{
    var chkAll = document.getElementById(chkAllClientID);
    if(!checkbox.checked)
    {
        chkAll.checked = false;
    }
    else
    {
	    for (var i=0; i<chkAll.form.length; i++)
	    {
		    if (chkAll.form[i].type == "checkbox" &&  chkAll.form[i].name != chkAll.name && chkAll.form[i].name.indexOf(checkBoxesName) > -1)
		    {        
			    if(!chkAll.form[i].checked)
			    {
			        chkAll.checked = false;
			        return;
			    }
	        }
	    }
	    chkAll.checked = true;
    }
}

function toggleSelectAllIfCheckBoxesChange2(checkbox, chkAllClientID,checkBoxesName1,checkBoxesName2)
{
    var chkAll = document.getElementById(chkAllClientID);
    if(!checkbox.checked)
    {
        chkAll.checked = false;
    }
    else
    {
	    for (var i=0; i<chkAll.form.length; i++)
	    {
		    if (chkAll.form[i].type == "checkbox" &&  chkAll.form[i].name != chkAll.name && 
		    (chkAll.form[i].name.indexOf(checkBoxesName1) > -1 || chkAll.form[i].name.indexOf(checkBoxesName2) > -1))
		    {        
			    if(!chkAll.form[i].checked)
			    {
			        chkAll.checked = false;
			        return;
			    }
	        }
	    }
	    chkAll.checked = true;
    }
}
// This function HTML Encodes input value
function escapeHTML(input) {
    var div = document.createElement('div');
    var text = document.createTextNode(input);
    div.appendChild(text);
    return div.innerHTML;
}; 

//function flipChkAll(field, chkAllClientId){
//    var chkAll = document.getElementById(chkAllClientId)
//    
//    if(chkAll.checked)
//    {
//        checkAll(field);
//    }
//    else
//    {
//        uncheckAll(field)
//    }
//}

//function checkAll(field)
//{
//    var checkboxes = 1
//    if(field.length)
//        checkboxes = field.length;
//    for (var j = 0; j < checkboxes; j++)
//    {
//        if(field[j] && !field[j].disabled)
//        {
//            field[j].checked = true;
//        }
//    }
//}
//function uncheckAll(field)
//{
//    for (var j = 0; j < field.length; j++)
//        field[j].checked = false;
//}


//DO NOT REMOVE THIS
//Needed for ProofOfConcept to determine the end of js file
//ENDOFJS
