function toggle(objectId) {
  var object = document.getElementById(objectId);

  if((object.getAttribute('className') == 'hidden') ||
      object.getAttribute('class') == 'hidden') {
    object.setAttribute('class', '');
    object.setAttribute('className', '');
  } else {
    object.setAttribute('class', 'hidden');
    object.setAttribute('className', 'hidden');
  }
}


var fulltext = '';

function CheckLength(max,ftext,fleft) {


  txt = document.getElementById(ftext);
  txtlen = txt.value.length;

  left = document.getElementById(fleft);

  if (txtlen < max) {
    left.value = (max - txtlen - 1);
    txt.focus();
    if (txt.value == '') left.value = max;
    if(fulltext) { fulltext = '' }
  }
  else {
    if(!fulltext) fulltext = txt.value.substring(0,max-1);
    txt.value = fulltext;
    left.value = 0;
  }

}

function checkRentalForm() {

  var c = document.getElementById('checkcon');

  var f = document.getElementById('form2');

  if (c.checked == true) {
    f.submit();
  }
  else {
    return false;
  }

}

function SubmitForm(url) {

  var f = document.getElementById('form2');

  f.action = url;

  f.submit();

}


function ToggleSubmit() {

  var c = document.getElementById('checkcon');

  var b = document.getElementById('continue');

  if (c.checked == true) {
    b.style.display = "block";
  }
  else {
    b.style.display = "none";
  }

  return false;

}

/**
 * shows printable
 */
function ShowWinPr(url,x,y,name) {
  cx=screen.width/2-(x/2);
  cy=screen.height/2-(y/2);
  window.open(url,name,"toolbar=yes,status=yes,directories=no,menubar=yes,resizable=yes,width="+x+",height="+y+",scrollbars=yes,top="+cy+",left="+cx);
}


/**
 * shows big photo in pop-up window
 */
function ShowWin(url,x,y,name) {
  cx=screen.width/2-(x/2);
  cy=screen.height/2-(y/2);
  window.open(url,name,"toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width="+x+",height="+y+",scrollbars=no,top="+cy+",left="+cx);
}

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function markAllRows( container_id ) {
  var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

  for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                }
            }
  }

  return false;
}

/**
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function unMarkAllRows( container_id ) {
  var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

  for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            if ( checkbox.disabled == false ) {
                checkbox.checked = false;
                }
            }
  }

  return true;
}


/**
 * checks if group form name field is not empty
 */

function CheckGroupForm()
{

  if (Trim(document.GroupForm.name.value) == "")
  {
    alert("Please specify name");
    document.GroupForm.name.focus();
    return false;
  }

  document.GroupForm.submit();

}


/**
 * checks if user form required field are not empty
 */


function CheckUserForm()
{

  if (Trim(document.UserForm.lgn.value)== "")
     {
        alert("Please specify login");
        document.UserForm.lgn.focus();
        return false;
     }

  if (Trim(document.UserForm.firstname.value)== "")
     {
        alert("Please specify firstname");
        document.UserForm.firstname.focus();
        return false;
     }

  if (Trim(document.UserForm.lastname.value)== "")
     {
        alert("Please specify lastname");
        document.UserForm.lastname.focus();
        return false;
     }


  var cs = document.getElementById('UserForm').getElementsByTagName('input');
  var checkboxes = 0;

  for ( var i = 0; i < cs.length; i++ ) {
    if (cs[i].checked == true ) {
      checkboxes++;
    }
  }

  if (checkboxes == 0) {
      alert("Please select at least one group");
      return false;
  }

  document.UserForm.submit();
}


/**
 * checks if apartment form required fields are not empty
 */


function CheckUnitForm(maxlen)
{

  d_en = Trim(document.UnitForm.description_en.value);

  if (d_en.length > maxlen)
     {
        alert("Maximun allowed english description length exceeded");
        document.UnitForm.description_en.focus();
        return false;
     }

  d_es = Trim(document.UnitForm.description_es.value);

  if (d_es.length > maxlen)
     {
        alert("Maximun allowed spanish description length exceeded");
        document.UnitForm.description_es.focus();
        return false;
     }


  d_ru = Trim(document.UnitForm.description_ru.value);

  if (d_ru.length > maxlen)
     {
        alert("Maximun allowed russian description length exceeded");
        document.UnitForm.description_ru.focus();
        return false;
     }


  var photo = escape(document.UnitForm.photo.value);

  if (photo.length){

  photo = photo.toUpperCase();

  var re = /\.((JPG)|(PNG)|(GIF))$/;

    if (!photo.match(re)) {
      alert("You may only upload JPG, GIF or PNG pictures.");
      document.UnitForm.photo.focus();
      return false;
    }

  }

/*
  var id = escape(document.UnitForm.unitid.value);

  if (!id.length && !photo.length){
      alert("You must upload medium image when adding new unit.");
      return false;
  }
*/

  document.UnitForm.submit();
}



/**
 * checks if apartment form required fields are not empty
 */
function CheckUnitItemForm(maxlen)
{

  d_en = Trim(document.UnitForm.description_en.value);

  if (d_en.length > maxlen)
     {
        alert("Maximun allowed english description length exceeded");
        document.UnitForm.description_en.focus();
        return false;
     }

  d_es = Trim(document.UnitForm.description_es.value);

  if (d_es.length > maxlen)
     {
        alert("Maximun allowed spanish description length exceeded");
        document.UnitForm.description_es.focus();
        return false;
     }


  d_ru = Trim(document.UnitForm.description_ru.value);

  if (d_ru.length > maxlen)
     {
        alert("Maximun allowed russian description length exceeded");
        document.UnitForm.description_ru.focus();
        return false;
     }


  var photo = escape(document.UnitForm.photo.value);

  if (photo.length){

  photo = photo.toUpperCase();
  var re = /\.((JPG)|(PNG)|(GIF))$/;

    if (!photo.match(re)) {
      alert("You may only upload JPG, GIF or PNG pictures.");
      document.UnitForm.photo.focus();
      return false;
    }

  }

/*
  var id = escape(document.UnitForm.itemid.value);

  if (!id.length && !photo.length){
      alert("You must upload large image when adding new unit.");
      return false;
  }
*/

  document.UnitForm.submit();
}


/**
 * checks if room form required fields are not empty
 */

function CheckItemRoomForm(maxlen)
{

  d_en = Trim(document.UnitForm.description_en.value);

  if (d_en.length > maxlen)
     {
        alert("Maximun allowed english description length exceeded");
        document.UnitForm.description_en.focus();
        return false;
     }

  d_es = Trim(document.UnitForm.description_es.value);

  if (d_es.length > maxlen)
     {
        alert("Maximun allowed spanish description length exceeded");
        document.UnitForm.description_es.focus();
        return false;
     }


  d_ru = Trim(document.UnitForm.description_ru.value);

  if (d_ru.length > maxlen)
     {
        alert("Maximun allowed russian description length exceeded");
        document.UnitForm.description_ru.focus();
        return false;
     }

  var photo = escape(document.UnitForm.photo.value);

  if (photo.length){

  photo = photo.toUpperCase();
  var re = /\.((JPG)|(PNG)|(GIF))$/;

    if (!photo.match(re)) {
      alert("You may only upload JPG, GIF or PNG pictures.");
      document.UnitForm.photo.focus();
      return false;
    }

  }

/*
  var id = escape(document.UnitForm.roomid.value);

  if (!id.length && !photo.length){
      alert("You must upload large image when adding new unit.");
      return false;
  }
*/

  document.UnitForm.submit();
}


/**
 * checks if iface content form required fields are not empty
 */

function CheckIfaceForm()
{

  if (Trim(document.UnitForm.content_en.value)== "")
     {
        alert("Please specify english part!");
        return false;
     }

  if (Trim(document.UnitForm.content_es.value)== "")
     {
        alert("Please specify spanish part!");
        return false;
     }


  document.UnitForm.submit();
}

/*
  String trimming functions
*/

function Trim(TRIM_VALUE)
{
        if(TRIM_VALUE.length < 1)
        {
                return"";
        }
  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);
  if(TRIM_VALUE=="")
  {
    return "";
  }
  else{
    return TRIM_VALUE;
  }
}


<!--RTrim-->
function RTrim(VALUE){
        var w_space = String.fromCharCode(32);
        var v_length = VALUE.length;
        var strTemp = "";
    if(v_length < 0){
      return"";
    }
    var iTemp = v_length -1;
    while(iTemp > -1)
    {
      if(VALUE.charAt(iTemp) == w_space)
      {
      }
      else{
       strTemp = VALUE.substring(0,iTemp +1);
       break;
      }
       iTemp = iTemp-1;
    }
    return strTemp;
}

<!--LTrim-->
function LTrim(VALUE)
{
        var w_space = String.fromCharCode(32);
  if(v_length < 1)
     {
            return"";
     }
  var v_length = VALUE.length;
  var strTemp = "";
  var iTemp = 0;

  while(iTemp < v_length)
  {
   if(VALUE.charAt(iTemp) == w_space){
  }
  else
  {
   strTemp = VALUE.substring(iTemp,v_length);
   break;
  }
   iTemp = iTemp + 1;
  }
  return strTemp;
}


		function newWindow(uri, title) {
			
			var img = new Image;
			img.src =  uri;

			if(img.complete){
				var window_w = img.width  + 30;
				var window_h = img.height + 30;	
				var screen_w = window.screen.width;
				var screen_h = window.screen.height;
	
				var scrollbars = 'no';
				
				if(window_w > screen_w - 50){ window_w = screen_w - 50; scrollbars = 'yes'; }
				if(window_h > screen_h - 50){ window_h = screen_h - 50; scrollbars = 'yes'; }
			
				var t  = (screen_h/2) - (window_h/2);
				var l = (screen_w/2) - (window_w/2);

				window.open("/img.html?" +
					"" + escape(uri) + 
					"&" + escape(title), "win", "toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollbars="+scrollbars+",width="+window_w+",height="+window_h+",top="+t+",left="+l);
			//	win.focus();	
			}
			img.onload = function(){
				var window_w = img.width  + 30;
				var window_h = img.height + 30;	
				var screen_w = window.screen.width;
				var screen_h = window.screen.height;
	
				var scrollbars = 'no';
				
				if(window_w > screen_w - 50){ window_w = screen_w - 50; scrollbars = 'yes'; }
				if(window_h > screen_h - 50){ window_h = screen_h - 50; scrollbars = 'yes'; }
			
				var t  = (screen_h/2) - (window_h/2);
				var l = (screen_w/2) - (window_w/2);

				window.open("/img.html?" +
					"" + escape(uri) + 
					"&" + escape(title), "trading_equipment_1", "toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollbars="+scrollbars+",width="+window_w+",height="+window_h+",top="+t+",left="+l);
			//	win.focus();				
			};
			if(img.complete) delete(img);			
			return false;
		}

