
function echo(str) {
	alert(str);
}


/////////////////////////  STATUS REPORT

var orig_animate_msg = "";

function animate_report3() {
	var obj = $("statusReport");
	obj.innerHTML = orig_animate_msg;
}

function animate_report2() {
	var obj = $("statusReport");
	var tmp = obj.innerHTML;

	tmp += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:red;background-color:orange;"> <b>&lt;==</b></span>'
	obj.innerHTML = tmp;
	setTimeout("animate_report3()",500);
}

function animate_report() {
	var obj = $("statusReport");
	var tmp = obj.innerHTML;
	
	orig_animate_msg = tmp;

	tmp += "&nbsp;&nbsp;&nbsp;&nbsp;<b>&lt;==</b>";
	obj.innerHTML = tmp;
	setTimeout("animate_report2()",500);
}


///////////////////////// TO TEXT 


function display_array(aa) {
	var n = aa.length;
	var ss = "";
	var sep = "";
	for ( var i = 0; i < n; i++ ) {
		ss += sep + aa[i]; sep = "\n";
	}
}

function display_arrays(m1,m2) {
	display_array(m1);
	display_array(m2);
}


function object_from_array(arkeys,ival) {
	var obj = new Object();
	var n = arkeys.length;
	for ( i = 0; i < n; i++ ) {
		obj[arkeys[i]] = ival;
	}

	return(obj);
}

function checkExt(extlist,obj) {
	var ss = obj.value;
	
	var sparts = ss.split(".");
	var ext = sparts[sparts.length - 1];
	
	var extensions = extlist.split(",");
	var n = extensions.length;
	
	for ( var i = 0; i < n; i++ ) {
		var cext = extensions[i];
		if ( cext == ext ) return(true);
	}
	
	alert(ss + " is not a zip file type.");
	
	obj = $("uploaderForm");
	obj.reset();

	return(false);
}


function splitSubject(subjTxt) {
	return(subjTxt.split("|",6));
}

/// ==============================

function line_breaks(output) {
	while ( output.indexOf("<br") > -1 ) {
		output = output.replace("<br>","\n");
	}
	return(output);
}


function data_from_element(obj) {
	var tn = obj.nodeName.toLowerCase();
	if ( tn == 'textarea' ) {
		return(""); // These are being handled as tinyMCE areas.
	} else {
		var txt = obj.innerHTML;
		if ( ( txt == null ) || ( txt.length == 0 ) ) {
			txt = obj.value;
		}
		txt = encodeURIComponent(txt);
		return(txt);
	} 
}


function extract_index(str) {
	var bpos = str.indexOf('[') + 1;
	var epos = str.lastIndexOf(']');

	var indx = str.substring(bpos,epos);
	return(indx);
}

/////////////////////////  STATUS REPORT




function find_index_in_array(an_array,int_val) {

	var n = an_array.length;
	for ( var i = 0; i < n; i++ ) {
		if ( an_array[i] == int_val ) return(i);
	}
	return(-1);
}




/////////////////////////  STATUS REPORT



function checkFilledFields(divobjname,txt) {
	var divobj = $(divobjname);
	if ( divobj.value.length == 0 ) {
		alert(txt);
		return(false);
	}
	
	return(true);
}


/////////////////////////  OBJECTS



function merge_objects(value_holder,value_source) {

	if ( value_holder == null ) {
		value_holder = new Object();
	}

	for ( ky in value_source ) {
		value_holder[ky] = value_source[ky];
	}
	return(value_holder);
}


////
function removePropety(list,cnm) {
	var nlist = new Object();
	for ( cc in list ) {
		if ( cc != cnm ) {
			nlist[cc] = list[cc];
			list[cc] = null;
		}
	}
	return(nlist);
}

/////
function stringify(obj,quotes) {
	var str = "";

	var realsep = ",";
	if ( quotes ) realsep = ", \"";

	if ( obj.constructor == "Array" ) {
		str += "[";
		var n = obj.length;
		var sep = "";
		for ( var i = 0; i < n; i++ ) {
			txt = stringify(obj[i]);
			str += sep + txt;
			sep = ",";
		}
		str += "]";
	} else if ( obj.constructor == "String" ) {
		var bounder = '\"';
		str = bounder + obj + bounder;
	} else if ( ( obj.constructor == "Number" ) || ( obj.constructor == "Boolean" ) || ( obj.constructor == "Function" ) ) {
		str = "" + obj;
	} else if ( ( typeof(obj) == "object" ) || ( obj.constructor == "Object" ) ) {
		var objsep = ":";
		if ( quotes ) objsep = "\" :";
		str += "{";
		if ( quotes ) str += "\"";
		var sep = "";
		for ( j in obj ) {
			var txt = j + objsep + stringify(obj[j]);
			str += sep + txt;
			sep = realsep;
		}
		str += "}";
	} else {
		str = "" + obj;
	} 

	return(str);
}


function $(objName) {
	var divObj = document.getElementById(objName);
	return(divObj);
}


function removespace(str) {
	var ostr = "";
	var sp = ' ';
	var tb = '\t';
	var rt = '\n';
	var lf = '\r';
	var n = str.length;
	for ( var i = 0; i < n; i++ ) {
		var c = str.charAt(i);
		if ( ( sp == c ) || ( tb == c ) || ( rt == c ) || ( lf == c ) ) continue;
		ostr += c;
	}
	return(ostr);
}


function fileBase(filestr) {
	var i = filestr.lastIndexOf("/");
	if ( i < 0 ) {
		i = filestr.lastIndexOf("\\");
	}
	
	return(filestr.slice(i+1));
}

function showPart(inputObj) {
	inputObj.style.visibility = "visible";
}

function hidePart(inputObj) {
	inputObj.style.visibility = "hidden";
}


function $show(objName,data) {
	var divObj = $(objName);
	if ( divObj != null ) {
		showPart(divObj);
		if ( data != null ) {
			divObj.innerHTML = data;
		}
	}
	return(divObj);
}

function $hide(objName) {
	var divObj = $(objName);
	if ( divObj != null ) hidePart(divObj);
	return(divObj);
}

function $obj_show(obj) {
	obj.style.visibility = "visible";
}

function $obj_hide(obj) {
	obj.style.visibility = "hidden";
}

function toggleVisPart(inputObj) {
	var viz = inputObj.style.visibility;
	if ( viz != "visible" ) {
		inputObj.style.visibility = "visible";
	} else {
		inputObj.style.visibility = "hidden";
	}
}


function eliminate_plus(treespec) {
	var n = treespec.length;
	var output = "";
	for ( var i = 0; i < n; i++ ) {
		var c = treespec.charAt(i);
		if ( c == "+" ) {
			c = " ";
		}
		output += c;
	}
	return(output);
}



function $showAt(obj,refob) {

	var y = refob.offsetTop;
	var x = refob.offsetLeft;
	
	obj.style.top = y + "px";
	obj.style.left = x + "px";
	
	$obj_show(obj);
}


var g_prev_distance = 0;

function divdistance(x,y,t,l,t2,l2) {
	var cx = l + (l-l2)/2;
	var cy = t + (t - t2)/2;
	var dx = (x - cx);
	dx = dx*dx;
	var dy = (y - cy);
	dy = dy*dy;
	var d = Math.sqrt(dx + dy);

	
	return(d)
}


function iswithin(x,y,dname) {
	var dobj = $(dname);
	//------------------------------
	var t = dobj.offsetTop;
	var l = dobj.offsetLeft;
	var t2 = t + dobj.offsetHeight;
	var l2 = l + dobj.offsetWidth;

//alert(t + ", " + l + ", " + t2 + ", " + l2 + "  " + x + ":" + y);
	if ( ( x > l ) && ( x < l2 ) ) {
		if ( ( y > t ) && ( y < t2 ) ) {
			return(true);
		}
	}
	//------------------------------
	return(false);
}


function hidePopperMsg() {
	var pobj = $('popperMsg');
	pobj.style.visibility = "hidden";
}

function popper_msg(evt,msg) {
	var pobj = $('popperMsg');
	if ( pobj != null ) {
		pobj.innerHTML = msg;
		pobj.style.left = (evt.clientX + 20) + "px";
		pobj.style.top = evt.clientY + "px";
		pobj.style.visibility = "visible";
		setTimeout("hidePopperMsg()",2000);
	}

}




function replace_returns(msgtxt) {
	var jtxt = msgtxt;
	
	while ( jtxt == msgtxt ) {
		jtxt = msgtxt.replace("\n","<br>");
		if ( jtxt != msgtxt ) msgtxt = jtxt;
		else return(jtxt);
	}
	//
	
	return(jtxt);
}

function remove_returns(msgtxt) {
	var jtxt = msgtxt;
	
	while ( jtxt == msgtxt ) {
		jtxt = msgtxt.replace("\n","");
		if ( jtxt != msgtxt ) msgtxt = jtxt;
		else return(jtxt);
	}
	//
	
	return(jtxt);
}




function remove_spaces(str) {
	var ostr = "";
	var sp = ' ';
	var n = str.length;
	for ( var i = 0; i < n; i++ ) {
		var c = str.charAt(i);
		if ( sp == c ) continue;
		ostr += c;
	}
	return(ostr);
}

function tabtrim(str) {
	var ostr = "";
	var sp = '\t';
	var n = str.length;
	for ( var i = 0; i < n; i++ ) {
		var c = str.charAt(i);
		if ( sp == c ) continue;
		ostr += c;
	}
	return(ostr);
}

var g_space_rg = new RegExp('[\n\t ]+','g');
function strim(str) {
	var ostr = "";

	str = str.replace(g_space_rg,' ');
	var oarray = str.split(" ");
	var n = oarray.length;
	sep = "";
	for ( var i = 0; i < n; i++ ) {
		if ( oarray[i] == ' ' ) continue;
		if ( oarray[i].length == 0 ) continue;
		ostr += sep + oarray[i];
		sep = " ";
	}

	return(ostr);	
}


