



function SetNewPrince() {
  inputs = document.getElementsByTagName('input');
  var totalPrice = 0;
  
  for (var obj in inputs) {
    child = inputs[obj];
    
    if (child.className == 'karta' && child.checked == true) {
      var prince = StrToPrice(child.value);
      totalPrice += prince;
    }
  }
  
  WriteValue('totalPrince',PriceToStr(totalPrice));
}



function StrToPrice(strPrice) {
			var curPrice;
			curPrice = strPrice;
			if (curPrice.search(",")) {
				curPrice = curPrice.replace(",", ".");
			}
			return curPrice*1;
}



function PriceToStr(curPrice) {
			var strRetval;
			strRetval = curPrice.toString().replace(".", ",");
			if (strRetval.search(/,/) > 0) {
				if (strRetval.lastIndexOf(',') == strRetval.length - 1) {
					strRetval = strRetval + "0";
				}
			}
			else {
				strRetval = strRetval + ",00";
			}
			return strRetval;
}

function WriteValue(strElementName, strValue) {
			var input = document.getElementById(strElementName);
			input.value = strValue;
}


function ValidForm(formID) {
    
    
    this.init = function(id) {
      form = document.getElementById(id);
      inputs = form.getElementsByTagName('input');
      
      for (var obj in inputs) {
          child = inputs[obj];
          childClassName = child.className;
      
          if (childClassName == 'ValidFormText') {
            if (!this.text(child.value)) {
              alert(this.dontVaild(child));
              return false;
            }
          }
          
          if (childClassName == 'ValidFormNumber') {
            if (!this.number(child.value)) {
              alert(this.dontVaild(child));
              return false;
            }
          }
          
          if (childClassName == 'ValidFormEmail') {
            if (!this.email(child.value)) {
              alert(this.dontVaild(child));
              return false;
            }
          }

          if (childClassName == 'ValidFormChecked') {
          
            var ret = this.checked(child, inputs);
            if (ret == false) {
              alert(this.dontVaild(child));
              return false;
            }
          }
          
          if (childClassName == 'ValidPassword') {
            if (!this.password(child.value)) {
              alert(this.dontVaild(child));
              return false;
            }
          }
        
          
      }
      alert('Formulář byl úspěšně odeslán.'); 
      return true;
    }
    
    
    
    
    
    this.dontVaild = function(item) {
      
      var dd = item.parentNode;
      var dl = dd.parentNode;
      var dtContent = dl.firstChild.firstChild;
      
      if (dtContent != null) {
        return 'Nebyla vyplněna položka "'+dtContent.nodeValue+'".';
      } else {
        return 'Stále nebyly vyplněny všechny povinné položky.';
      }
      
    }
    
    
    this.password = function(value) {
      var submit = document.getElementById('passwordsubmit');
      
      if (submit.value != value.value) {
        return false;
      }
      
      if (value.value.length < 4) {
        return false;
      }
      
      return true;
    }
    
    
    
    
    
    this.checked = function(item, inputs) {
      if (item.type == 'checkbox') {
        if (item.checked == true) {
          return true;
        }
      } 
      
      if(item.type == 'radio') {
        for (var obj in inputs) {
          if (inputs[obj].name == item.name && inputs[obj].checked) {
            return true;
          }
        } 
      }
      
      return false;
    }
    
    
    this.number = function(value) {
      if (isNaN(value) || value.length == 0) {
        return false;
      }
      return true;
    }
    this.text = function(value) {
      if (value.length <= 0) {
        return false;
      }
      return true;
    }
    this.email = function(mail) {
       if (mail.indexOf("@") != -1 && mail.indexOf(".") != -1) {
          return true;
       } 
	     return false;
    }
    this.getSameRadio = function() {
    
    }
    
    return this.init(formID);
}
