//some jsctipt utilities for forms validation etc. (ssser)

function WriteArray(arrName, array){
	Response.Write("<b>" + arrName + ":</b> ");
//Response.Write(array[7] + "<br/>")
	for(i = 0; i < array.length; i++){
		Response.Write(array[i] + " ");
	}
	Response.Write("<br/>")
}


//<form validation utils>

function isEmail(str){
	atCount = 0;
	perCount = 0;
	for(i = 0; i < str.length; i++){
		temp = str.charAt(i);
		if(temp == "@")
			++atCount;
		if(temp == ".")
			++perCount;
	}
	return (atCount == 1 && perCount > 0)
}


function isText(str){
	for(i = 0; i < str.length; i++){
		code = str.charCodeAt(i);
		if(code > 64 && code < 123 && (code < 91 || code > 96))
			return true;
	}
	return false;
}
			
function isNum(str){
	return !isNaN(parseInt(str));
}

function unfloatMessage(tooltip) {
    //tooltip.style.visibility = 'hidden';
	tooltip.style.display = 'none'; 
}

function floatMessage(str, tooltip) {
	var scrollLeft = f_scrollLeft();
	var scrollTop = f_scrollTop();
	var width = f_clientWidth();
	var height = f_clientHeight();
//	var twidth = tooltip.style.width;
//	var theight = tooltip.style.height;
	tooltip.style.left = (scrollLeft + width / 2) + "px"; // - twidth / 2;
	tooltip.style.top = (scrollTop + height / 2) + "px"; //- theight / 2;
	tooltip.innerHTML = str; // + " w=" + twidth + " h=" + theight;
	tooltip.style.display = "block";
}



function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
    return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
