// deprecated - see FrameManager control 
function autoResizeFrame(frame){
        //resize IFrame to fit contents w/o VScroll   
        try {
            var newheight;    
            newheight=frame.contentWindow.document.body.scrollHeight;
            //if (newheight >= 500) {
                frame.style.height=(newheight + 10) + "px";
            //}
        }
        catch(e) {}
}


function showPopup(url, name, width, height) {
	var features='';
	var winH;
	var sWidth = screen.width;
	var sHeight = screen.height;
	
	features += "width=" + width;
	features += ", height=" + height;
	features += ", left=" + ((getWidth() - width)/2);
	features += ", top=" + ((getHeight() - height)/2);
	features += ", scrollbars=1";
	features += ", resizable=1";
	winH = window.open(url, name, features);
	winH.focus();
	return winH;
}

// Get DDL's selected value
function getDDLSelection(ddl){
	if (ddl != null) {return ddl.options[ddl.selectedIndex].value;}
}

// Find element in dom - Cross Browser
function getElement(elementId){ 
	return (document.getElementById) ? document.getElementById(elementId) : document.all[elementId]; 
}

//Find he first parentElement of the currentElement with a matching tagName
function getParent(tagName, currentElement) {
	while (currentElement.parentElement) {
		alert(currentElement.parentElement.tagName);
		if (currentElement.parentElement.tagName == tagName) { return currentElement.parentElement }
		else {currentElement = currentElement.parentElement}
	}
}
//Convert a TR into an array for the TD/TH innerText
function rowToArray(rowElement) {
	var result = new Array();
	for (i=0;i<rowElement.childNodes.length;i++) {
		if (rowElement.childNodes[i].tagName=='TD') {
			result[i]=rowElement.childNodes[i].innerHTML;
			}
		}
	
	return result;
}


// Returns XMLHTTP object - Cross Browser
function GetXMLHTTP() {
    if (document.all) { 
		//ie
		//return new ActiveXObject("Microsoft.XMLHTTP");
		try {
			return new ActiveXObject("Msxml2.XMLHTTP"); 
			}
		catch(e) {
			//legacy IE 5.0 support
			return new ActiveXObject("Microsoft.XMLHTTP");
			}
		
    } else { 
		// Mozilla - based browser 
		return new XMLHttpRequest(); 
    }
}


// Screen width
function getWidth() {
	return (document.all) ? screen.availWidth : window.innerWidth;
}


//Screen height
function getHeight() {
	return (document.all) ? screen.availHeight : window.innerHeight;
}

// DisplayLimit - Restrict length of user input to textareas.
// A CSS Selector called ChrCount should be defined if DisplayLimit functionality is used.
function RestrictInput(maxlength,e,placeholder) {
	if (window.event && event.srcElement.value.length >= maxlength) {return false;}
	else if (e.target && e.target == eval(placeholder) && e.target.value.length >= maxlength) {
		var pressedkey = /[a-zA-Z0-9\.\,\/]/;
		if (pressedkey.test(String.fromCharCode(e.which))) {e.stopPropagation();}
	}
}
function CountLimit(maxlength,e,placeholder) {
	var theform = eval(placeholder);
	var lengthleft = maxlength - theform.value.length;
	var placeholderobj = document.all? document.all[placeholder] : document.getElementById(placeholder);
	if (window.event || e.target && e.target == eval(placeholder)) {
		if (lengthleft < 0) {theform.value = theform.value.substring(0,maxlength);}
		placeholderobj.innerHTML = lengthleft;
	}
}
function DisplayLimit(theform,thelimit){
	var limit_text = '<b class="ChrCount"><span id="' + theform.toString() + '">' + thelimit + '</span> characters remaining</b>';
	document.write(limit_text);
	eval(theform).onkeypress = function() {return RestrictInput(thelimit,event,theform);}
	eval(theform).onkeyup = function() {CountLimit(thelimit,event,theform);}
}
// End DisplayLimit

