// JavaScript Document

// ajax functions
var request = null;

function ecModRewriteLink(type,plugin,site,id,params) {
	var rlink = '';
	if (modRewrite) {
		rlink += src;
		rlink += 'view/';
		rlink += type + '/';
		if (plugin !== '') {
			rlink += plugin + '/';
		}
		if (site !== '') {
			rlink += site + '/';
		}
		if (id !== 0) {
			rlink += id + '/';
		}
		if (params !== '') {
			rlink += '?' + params;
		}
	}
	else {
		rlink += type + '.php';
		if (plugin !== '') {
			rlink += '?plugin=' + plugin;
		}
		if (site !== '') {
			rlink += '&site=' + site;
		}
		if (id !== 0) {
			rlink += '&id=' + id;
		}
		if (params !== '') {
			rlink += '&' + params;
		}
	}
	
	return rlink;
}

function createRequest(){
	try{
		request = new XMLHttpRequest();
	}catch(ex){
		try{
			request = new ActiveXObject("MSXML2.XMLHTTP");
		}catch(ex){
			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;
}

// 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;
}
