String.prototype.trim = function(){
   var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);
   return (m == null) ? "" : m[1];
}
/* client validation functionality */
var validateFormResult = new Array();
function submitOnEnter(event,formName){
  var key = event.keyCode ? event.keyCode : event.charCode;
  if(key == 13){
    submitForm(formName);
  }
}
function submitForm(formName){


  var form = document.forms[formName];

  if (form && typeof(form.onsubmit) == "function"){
   form.onsubmit();

    for (var i=0; i<validateFormResult.length; i++){

      if (validateFormResult[i].form.name == formName && validateFormResult[i].result){
        form.submit();
      }
      if (validateFormResult[i].form.id == form.id && validateFormResult[i].result){
        form.submit();
      }
    }
  }
}
function resetForm(formName){
  document.forms[formName].reset();
}
function validateForm()
{
  var args = validateForm.arguments;
  var msg = "";
  for (var i=1; i<args.length; i++){
    var errmsg = validate(args[i]);
    if (errmsg.trim().length != 0){
      msg += errmsg + "\n";
    }
  }

  validateFormResult.push({form:args[0], result:msg.trim().length == 0});
  if (msg.trim().length != 0){
    alert(msg);
    return false;
  }
  return false;
}
function validate(args)
{
  var ctrl = document.getElementById(args.id);
  if (!ctrl){
    return "";
  }
  var isValid = true;
  switch (args.type){
    case "chek":
      isValid = validatechek(ctrl)
      break;
	case "rfv":
      isValid = validateRFV(ctrl)
      break;
    case "rev":
      isValid = validateREV(ctrl, args.re)
      break;
    case "cv":
      isValid = validateCV(value, args.cv);
      break;
  }
  if (!isValid){
    return args.msg;
  }
  return "";
}
function validateREV(ctrl, re){
  var value = validateGetValue(ctrl);
  if (value.trim().length == 0)
    return true;
  var rx = null;
  switch (re){
    case "email":
      rx = new RegExp("^[a-zA-Z0-9._-]+\\@[a-zA-Z0-9._-]+\\.([a-zA-Z]{2,4})([;][a-zA-Z0-9._-]+\\@[a-zA-Z0-9._-]+\\.([a-zA-Z]{2,4}))*");
      break;
    case "pic":
      rx = new RegExp("^(.*?)\\.(jpg|jpeg|png|gif)$");
      break;
    default:
      rx = new RegExp(args.re);
      break;
  }
  var matches = rx.exec(value);
  return (matches != null && value == matches[0]);
}
function validateRFV(ctrl){
  return validateGetValue(ctrl).trim().length != 0;
}

function validatechek(ctrl){
if (ctrl.checked == true) { return true;} return false;
}


function validateCV(value, cv){
  var value = validateGetValue(ctrl);
  var args = {Value:value, isValid:true};
  if (typeof(cv) == "string") {
    eval(cv + "(value, args) ;");
  }
  return args.isValid;
}
function validateGetValue(ctrl){
  if (typeof(ctrl.value) == "string" && (ctrl.type != "radio" || ctrl.checked == true)) {
    return ctrl.value;
  }
  return "";
}
/* end client validation functionality */
function ChoosePage(p)
{
  var formObj = document.forms["page_form"];
  formObj.page.value = p;
  formObj.submit();
}
function GetDeleteConfirm()
{
   return window.confirm("Вы действительно хотите удалить эту запись?");
}


function showprops(obj)
{
    var args = showprops.arguments;
    var obj = args[0];
    var isSimple = true;
    if (args.length > 1)
    {
        isSimple = false;
    }

    propertyList = new Array;
    for (property in obj)
    {
      propertyList[propertyList.length] = String(property);
    }
    propertyList.sort();
    if (isSimple)
    {
        alert(propertyList.join(", "))
        return;
    }

    var str = "alert(";
    var prop = "";
    var propDetail = "";
    var divider = "";
    var index = 0;
    for (i=0; i<propertyList.length; i++)
    {
        divider = (index++ % 2 == 1) ? "   +   \"\\n\" + \n" : "+ \"   :   \" +";
        if (i == (propertyList.length - 1))
        {
            divider = "";
        }
        prop = "obj." + propertyList[i].toString();
        propDetail = "((" + prop + ") ? (typeof(" + prop + ") == \"function\") ? \"function\" : " + prop + ".toString() : \"null\")";
        str += "\"" + propertyList[i].toString() + ":\" + " + propDetail + divider;
    }
    str += ");";
    alert(str);
    eval(str);
};
