// ---
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements)
}
// ---
/*
	Revised to support looking for multiple class names,
	no matter in which order they're applied to the element
*/
function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
// ---
// Array support for the push method in IE 5
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}
// ---
/*
	Examples of how to call the function:
	
	To get all a elements in the document with a "info-links" class:
    getElementsByClassName(document, "a", "info-links");
    
	To get all div elements within the element named "container", with a "col" and a "left" class:
    getElementsByClassName(document.getElementById("container"), "div", ["col", "left"]);
*/
// --</>-


function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}

//Copies value from one element to another in the same user control under another naming container
function CopyValue(fromElement, toContainer, toElement)
{
    var idPath, toElemID, elem;

    //parse 'from' control id
    idPath = fromElement.id.split('_');
    
    //replace last ids with new values
    idPath[idPath.length - 2] = toContainer;
    idPath[idPath.length - 1] = toElement;
    toElemID = idPath.join('_');
    
    //try to find destination element
    elem = document.getElementById(toElemID);
    
     //if element found
    if(elem)
    {
        //if there is no old value in control
        if(!elem.value)
        {
            //set new value
            elem.value = fromElement.value;
        }
    }
}


function scrollToPageTop()
{       

    window.scroll(0,0);                 
}

function SetDefaultSubmittButton(controlId,e)
    {  
       
       var key = (window.event) ? window.event.keyCode : e.which;
       if ( key == 13 )
        {     
            var button = document.getElementById( controlId );
            button.focus();			
        }        
    }

// Copy text to clipboard from input type='text'
function CopyToClipboard( textboxId )
{
    var textBox = document.getElementById( textboxId );            
    
    if ( null == textBox ) { return; }
    
    if ( textBox.createTextRange )
    {
        var copied = textBox.createTextRange();
        copied.execCommand("Copy");
    }
    else
    {
        alert( "This browser doesn't support copy to clipboard functionality!" );
    }
}

function CopyTextToClipboard(copyText)
{
    var id = "copyToClipboardTextArea";
    var holdtext = document.getElementById(id);
    if(!holdtext)
    {
        holdtext = document.createElement("TEXTAREA");
        holdtext.style.display = "none";
        holdtext.id = id;
        document.appendChild(holdtext);
    }    
    holdtext.innerText = copyText;
    copied = holdtext.createTextRange();
    copied.execCommand("Copy");
}
    
    
function CompareString(a, b)
{
    a = a.toLower();
    b = b.toLower();
    
    var length = a.length;
    for(var i = 0; i < length; ++i)
    {
        if(a.charAt[i] < b.charAt[i])
        {
            return true;
        }
        else if (a.charAt[i] > b.charAt[i])
        {
            return false;
        }
    }
    return false;   
}

function PopUp(url)
{
testwindow= window.open (url, "mywindow",
    "location=no,status=1,scrollbars=1,width=800,height=600");
}

function CheckIFramesSrcForSSL()
{
    var iframes = document.getElementsByTagName("IFRAME");
    for(var i = 0; i < iframes.length; i++)
    {
        if(iframes[i].src == "")
        {
           iframes[i].src = "javascript:false"; 
        }
    }
}

function PopupSetlayout(_backgroundElement, _foregroundElement) {

    
    var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    var clientWidth;
    if (window.innerWidth) {
        clientWidth = ((Sys.Browser.agent === Sys.Browser.Safari) ? window.innerWidth : Math.min(window.innerWidth, document.documentElement.clientWidth));
    } else {
        clientWidth = document.documentElement.clientWidth;
    }
    var clientHeight;
    if (window.innerHeight) {
        clientHeight = ((Sys.Browser.agent === Sys.Browser.Safari) ? window.innerHeight : Math.min(window.innerHeight, document.documentElement.clientHeight));
    } else {
        clientHeight = document.body.offsetHeight;
    }

    _backgroundElement.style.left = scrollLeft+'px';
    _backgroundElement.style.top = scrollTop+'px';
    _backgroundElement.style.width = clientWidth+'px';
    //_backgroundElement.style.height = clientHeight+'px';
    _foregroundElement.style.left = scrollLeft+((clientWidth-_foregroundElement.offsetWidth)/2)+'px';
    _foregroundElement.style.top = '10px';//scrollTop+((clientHeight-this._foregroundElement.offsetHeight)/2)+'px';          
    
    _backgroundElement.style.display = "inline";
    _foregroundElement.style.visibility = "visible";
    
}

function HideModalPopupBackground(bgID)
{
    var modalBG = document.getElementById(bgID);
    modalBG.style.display = "none";
}

