function popupWriteIM(user_id_to, sid) {
	var width = 350;
	var height = 370;
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	if (sid != '') { var sid_str = '&amp;'+sid; } else { var sid_str = ''; }
	imPopup = window.open('/beta/popups/write_im.html?user_id_to='+user_id_to+sid_str, "popupWriteIM", "width="+width+",height="+height+",left="+left+",top="+top+",menubar=no,location=no,resizable=yes,scrollbars=yes,toolbar=no,dependent=yes");
	imPopup.focus();
}

function popupEditSidebarModule(module, module_id) {
	var width = 350;
	var height = 450;
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	editPopup = window.open('popups/edit_'+module+'.html?module_id='+module_id, "popupWriteIM", "width="+width+",height="+height+",left="+left+",top="+top+",menubar=no,location=no,resizable=yes,scrollbars=yes,toolbar=no,dependent=yes");
	editPopup.focus();
}

function popupHelpVideo(url, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	editPopup = window.open(url, "popupHelpVideo", "innerWidth="+width+",innerHeight="+height+",left="+left+",top="+top+",menubar=no,location=no,resizable=yes,scrollbars=no,toolbar=no,dependent=no");
	editPopup.focus();
}

function popupWindow(url, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	editPopup = window.open(url, "popupWindow", "width="+width+",height="+height+",left="+left+",top="+top+",menubar=no,location=no,resizable=yes,scrollbars=no,toolbar=no,dependent=no");
	editPopup.focus();
}

function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit)
      field.value =field.value.substring(0, maxlimit);
    else
      countfield.value = maxlimit - field.value.length;
}

function htmlspecialchars(str,typ) {
    if(typeof str=="undefined") str="";
    if(typeof typ!="number") typ=2;
    typ=Math.max(0,Math.min(3,parseInt(typ)));
    var from=new Array(/&/g,/</g,/>/g);
    var to=new Array("&amp;","&lt;","&gt;");
    if(typ==1 || typ==3) {from.push(/'/g); to.push("&#039;");}
    if(typ==2 || typ==3) {from.push(/"/g); to.push("&quot;");}
    for(var i in from) str=str.replace(from[i],to[i]);
    return str;
}

function showBox(url, boxWidth, boxHeight) {
    $.fn.colorbox({ innerWidth: boxWidth+'px', innerHeight: boxHeight+'px', iframe: true, href: url, opacity: 0.5, scrolling: false });
}