function form_change(id){
  for(i=1; i<=form_count; i++){
    if(i != id){
      document.getElementById("change_sel"+i).style.display = "none";
    }else{
      document.getElementById("change_sel"+i).style.display = "";
    }   
  }
}

function changeForms( id ){
  
  var formArray = form_data.split("#");

  for( i = 0; i < formArray.length; i++ ){
    if( formArray[i] != id ){
      document.getElementById( "change_sel" + formArray[i] ).style.display = "none";
    }else{
      document.getElementById( "change_sel" + formArray[i] ).style.display = "";
    }   
  }
}

function show_extraform(id){
  var is_hidden = document.getElementById(id).style.display;
  if(is_hidden == ""){
    document.getElementById(id).style.display = "none";
  }else{
    document.getElementById(id).style.display = "";
  }
}

function form_check(frm){
    for (i=1; i < arguments.length; i++) {
        if (frm[arguments[i]].value == '') {
            frm[arguments[i]].focus();
            alert('Vyplnte všetky povinné položky označené hviezdičkou.');
            return false;
        }
    }
    return true;
}

function image_count(){
  if(!t){
    change_preview("images/nopic.jpg");
  }
  t = setTimeout( "image_count()", 4000 );
	if( i < l){
		i++;
	}else{
		i=1;
	}
	change_preview(foto[i-1]);
}

function timeStop() {
  clearTimeout(t)
}

function change_preview(str){	
	document.getElementById("preview").filters[0].Apply();
	document.getElementById("preview").src=eval("\""+str+"\"");
	document.getElementById("preview").filters[0].Play();
}

function previewIm(){
  var src = document.getElementById("previewSrc").value;
  var cache = document.getElementById("previewCache").value.split(";");
  var maxw = 800;
  var maxh = 600;
  
  var width = parseInt( cache[1] ) + 20;
  var height = parseInt( cache[2] ) + 20;
  
  if( width > maxw || width == 0 ){
    width = maxw;
  }
  if( height > maxh || height == 0 ){
    height = maxh;
  }
  
  window.open(src+"/"+cache[0], '_blank', 'width='+width+',height='+height+',location,resizable');
}

function change_preview2(str, image, width, height){
	document.getElementById("preview").src=eval("\""+str+"\"");	
	document.getElementById("previewCache").value=image+";"+width+";"+height;
}

function form_profit(){
  var cost_price_value = document.tovar_add.cost_price.value;
  var price_value = document.tovar_add.price.value;
  if(cost_price_value > price_value)window.alert("Nákupná cena je vyššia ako predajná!");
  document.tovar_add.profit.value = price_value-cost_price_value;
}

function form_customers(id){
  for(i=1; i<=4; i++){
    if(i != id){
      document.getElementById("z_form"+i).style.display = "none";
      document.getElementById("z_form_link"+i).setAttribute('style','font-weight: normal;');
    }else{
      document.getElementById("z_form"+i).style.display = "";
      document.getElementById("z_form_link"+i).setAttribute('style','font-weight: bold;');
    }   
  } 
}

function check_all(theElement) {
  var theForm = theElement.form, z = 0;
	 
  for(z=0; z<theForm.length;z++){
    if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	     theForm[z].checked = theElement.checked;
	  }
  }
}

