function toggle_div(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
      e.style.display = 'none';
   else
      e.style.display = 'block';
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function show_layer(byID){
  var e = document.getElementById(byID);
  e.style.display = "block";
}

function hide_layer(byID){
  var e = document.getElementById(byID);
  e.style.display = "none";
}

function layer_message(byID, mess) {
  var e = document.getElementById(byID);
  e.innerHTML = mess;
}

function is_email(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1) return false;
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
		if (str.indexOf(at,(lat+1))!=-1) return false;
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
    if (str.indexOf(dot,(lat+2))==-1) return false;
		if (str.indexOf(" ")!=-1) return false;
 		else return true;					
}

function instr(strSearch, charSearchFor)
{
  return strSearch.indexOf(charSearchFor) + 1;
}

function strlen(str) {
  return str.length;
}

function replace(mainString, thisString, newString) {
  return mainString.replace(thisString, newString);
}

function is_validusername(user) {
  user = replace(user, String.fromCharCode(92), "\\");
  if ( instr(user, String.fromCharCode(47))>0 ) return false;
  if ( instr(user, String.fromCharCode(92))>0 ) return false;
  if ( instr(user, " ")>0 ) return false;
  if ( instr(user, "~")>0 ) return false;
  if ( instr(user, "`")>0 ) return false;
  if ( instr(user, "!")>0 ) return false;
  if ( instr(user, "@")>0 ) return false;
  if ( instr(user, "#")>0 ) return false;
  if ( instr(user, "$")>0 ) return false;
  if ( instr(user, "%")>0 ) return false;
  if ( instr(user, "^")>0 ) return false;
  if ( instr(user, "&")>0 ) return false;
  if ( instr(user, "*")>0 ) return false;
  if ( instr(user, "(")>0 ) return false;
  if ( instr(user, ")")>0 ) return false;
  if ( instr(user, "-")>0 ) return false;
  if ( instr(user, "=")>0 ) return false;
  if ( instr(user, "+")>0 ) return false;
  if ( instr(user, "[")>0 ) return false;
  if ( instr(user, "]")>0 ) return false;
  if ( instr(user, "{")>0 ) return false;
  if ( instr(user, "}")>0 ) return false;
  if ( instr(user, ";")>0 ) return false;
  if ( instr(user, ":")>0 ) return false;
  if ( instr(user, "|")>0 ) return false;
  if ( instr(user, '?')>0 ) return false;
  if ( instr(user, '>')>0 ) return false;
  if ( instr(user, '<')>0 ) return false;
  if ( instr(user, ',')>0 ) return false;
  
  return true;
}

function left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function asc(str)
{
  var code = str.charCodeAt(0);
  return code;
}

function strtolower(str) {
  return str.toLowerCase(); 
}

function strtoupper(str) {
  return str.toUpperCase(); 
}

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
if (!win.opener)
win.opener = self;
}