String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
} // -------------------------------------------------------------------------------------------

function truncateForm( form ) {
	for( i = 0 ; i < form.length ; i++ )
	{
	    if( form.elements[i].type == 'text' || form.elements[i].type == 'textarea' )
			form.elements[i].value = form.elements[i].value.trim();
	};
} // -------------------------------------------------------------------------------------------


var popup_id 	= "popup";
var c_popup		= -1;
var last_obj	= 0;
var overpopup 	= 0;

function show_popup(e,obj,id) {
	
	if (id==c_popup) return true;//hidepopup();

	if (arguments.length==4) {
		document.getElementById(popup_id).style.background = "#722500";
		document.getElementById(popup_id).style.border = "";
	}
	
	c_popup = id;
	var x = y = 0;
	var tag = obj;
	while (tag.tagName!="BODY") { 
		y+=tag.offsetTop;
		x+=tag.offsetLeft;
		tag=tag.offsetParent; 
	} 
	
	if (!iex) {
		x=e.pageX;
		y=e.pageY;
	} else {
		x=e.x;
		y=e.y+document.body.scrollTop; 
	} 
    


	var popup = document.getElementById(popup_id);
	y += 16;

	if (x+popups[id][1]+50 > document.body.clientWidth) {
		x = document.body.clientWidth - popups[id][1] - 60;
	}

	popup.innerHTML = '<table width=100% height=100% cellpadding=0 cellspacing=0><tr valign=top><td width=100%>'+popups[id][0]+'</td><td style="padding-left:5px;"><a onclick="hidepopup(); return false;" href=#><img src='+siteurl+'/img/pics/close.jpg width=15 height=15></a></td></tr></table>';
	popup.style.top = y;
	popup.style.left = x;
	popup.style.width = popups[id][1];
	//popup.style.height = popups[id][2];
	popup.style.visibility = "visible";

	//alert(1);
	
	//var aaa = document.getElementsByTagName("body")[0];
	//aaa.focus();

	obj.blur();
	last_obj = obj;

	//overpopup = 1;
	
	e.cancelBubble=true;

	return true;
}

function hidepopup() {
	if (last_obj!=0) {
		last_obj.blur();
	}
	var popup = document.getElementById(popup_id);
	popup.style.visibility = "hidden";
	c_popup = -1;
	last_obj= 0;
	overpopup = 0;
	return true;
}

function openWin(x,title,wid,hei) {

  	myWin= open(x, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+wid+",height="+hei);
  	
	var hWnd = myWin; 
	var nLeftPos, nTopPos; 
	var nWidth = wid;
	var nHeight = hei;
 
    nLeftPos = Math.round(screen.availWidth/2) - Math.round(nWidth/2); 
    nTopPos  = Math.round(screen.availHeight/2) - Math.round(nHeight/2); 
	
	//hWnd.moveTo(nLeftPos,nTopPos);
}


