var Poolmax = {

   resize:function(){
	   var iMenuHeight = $('menu').getHeight();
	   var iContentHeight = $('content-p1').getHeight();
	   if (iMenuHeight > iContentHeight) {
         var newContentHeight = iMenuHeight-34;
	   	$('content-p1').setStyle("height:"+newContentHeight+"px");
	   	$('content-p3').setStyle("height:"+newContentHeight+"px");
	   }
	},

   submitFormDelay:function(formid){
      var form = $(formid);
      form.submit();
   },

   submitForm:function(formid){
      setTimeout("Poolmax.submitFormDelay('"+formid+"');", 50);
   },

   decrease:function(inputId){
	   if ($(inputId)) {
	   	var componentValue = parseInt($(inputId).value);
	   	if (!isNaN(componentValue) && componentValue >= 2) {
	   	   componentValue--;
	   	   $(inputId).value = componentValue;
	   	}
	   }
	},

	increase:function(inputId){
	   if ($(inputId)) {
	   	var componentValue = parseInt($(inputId).value);
	   	if (!isNaN(componentValue) && componentValue >= 1) {
	   	   componentValue++;
	   	   $(inputId).value = componentValue;
	   	}
	   }
	},

	componentFormToggle:function(formId){
		if ($(formId).getStyle("display") == "block") {
			$(formId).hide();
		}else{
			$$('.componentForm').invoke('hide');
			$(formId).show();
			//setTimeout("$(formId).show();",1000);
		}
	},

	componentFormShow:function(formId){
	   var aForms = $A($$('.componentForm'));
		if (aForms.length >= 1) {
			$$('.componentForm').invoke('remove');
		}
		$(formId).show();
	},

	addRow:function(){

	   var rowId = 'custom'+document.getElementById('customtable').rows.length;

	   var tbody = document.getElementById('customtable').getElementsByTagName("tbody")[0];
      var row = document.createElement("tr");
      row.id = rowId;

      var td1 = document.createElement("td");
      var input1 = document.createElement("input");
      input1.type = 'text';
      input1.className = 'customArtikel';
      input1.name = 'customArtikel[]';
      input1.value = '';
      td1.appendChild(input1);

      var td2 = document.createElement("td");
      var input2 = document.createElement("input");
      input2.type = 'text';
      input2.className = 'customName';
      input2.name = 'customName[]';
      input2.value = '';
      td2.appendChild(input2);

      var td3 = document.createElement("td");
      var input3 = document.createElement("input");
      input3.type = 'text';
      input3.className = 'customPocet';
      input3.name = 'customPopis[]';
      input3.value = '';
      td3.appendChild(input3);

      var td4 = document.createElement("td");

      var link1 = new Element('a', { 'title':'Vymazať riadok','class':'customDel', 'href': 'javascript:;', 'onclick':'javascript:Poolmax.delRow(\''+rowId+'\');'}).update('x');
      td4.appendChild(link1);

      row.appendChild(td1);
      row.appendChild(td2);
      row.appendChild(td3);
      row.appendChild(td4);
      tbody.appendChild(row);
	},

	delRow:function(rowId){
	   var rowsCount = document.getElementById('customtable').rows.length;
	   if (rowsCount >= 3) {
	   	$(rowId).remove();
	   }
	}
}

window.onload = function(){

   Poolmax.resize();

	if (document.getElementById('objectgallery')) {
		gallery.init();
	}
}


