// JavaScript Document

// ajax functions
var request = null;

function createRequest(){
	try{
		var request = new XMLHttpRequest();
	}catch(ex){
		try{
			var request = new ActiveXObject("MSXML2.XMLHTTP");
		}catch(ex){
			var request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return request;
}

// get radio value
function ecRadioValue(rObj) {
	for (var i = 0; i < rObj.length; i++) 
		if (rObj[i].checked)
			return rObj[i].value;
	return false;
}

// popup input
function ecPopupInput(v,Id) {  
	if (window.opener.document.getElementById(Id).createTextRange) {
		window.opener.document.getElementById(Id).focus();
		window.opener.document.selection.createRange().duplicate().text = v;
	}
	else if (window.opener.document.getElementById && !window.opener.document.all) { // Mozilla
		var tarea = window.opener.document.getElementById(Id);
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter = tarea.value.substring(selEnd, txtLen);
		tarea.value = txtbefore + v + txtafter;
	}
	else
		window.opener.document.getElementById(Id).value += what;
	window.focus();
}

// open a new window
function ecReqWin(desktopURL, alternateWidth, alternateHeight, noScrollbars) {
	if ((alternateWidth && self.screen.availWidth * 0.8 < alternateWidth) || (alternateHeight && self.screen.availHeight * 0.8 < alternateHeight)) {
		noScrollbars = false;
		alternateWidth = Math.min(alternateWidth, self.screen.availWidth * 0.8);
		alternateHeight = Math.min(alternateHeight, self.screen.availHeight * 0.8);
	}
	else
	noScrollbars = typeof(noScrollbars) != "undefined" && noScrollbars == true;
	window.open(desktopURL, 'requested_popup', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=' + (noScrollbars ? 'no' : 'yes') + ',width=' + (alternateWidth ? alternateWidth : 480) + ',height=' + (alternateHeight ? alternateHeight : 220) + ',resizable=no');
	return false;
}

// hide
function ecHide(Id) {
	document.getElementById(Id).style.display = "none";
}

// show
function ecShow(Id) {
	document.getElementById(Id).style.display = "block";
}

// toggle display
function ecToggleDisplay(Id) {
	if (document.getElementById(Id).style.display == 'none')
		document.getElementById(Id).style.display = "block";
	else
		document.getElementById(Id).style.display = "none";
}

// Check all Checkboxes
function ecCheckAll(form) {
	for (var i = 0; i < document.getElementById(form).elements.length ; i++) {
		var e = document.getElementById(form).elements[i];
		if (e.type=='checkbox')
			e.checked = true;
	}
}

// Change Source
function ecChangesrc(Id,Path) {
	document.getElementById(Id).src = Path;
}
