var xmlhttp;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}

function myXMLHttpRequest() {
  var xmlhttplocal;
  try {
    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
    xmlhttplocal=false;
  }
 }

if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
 try {
  var xmlhttplocal = new XMLHttpRequest();
 } catch (e) {
  var xmlhttplocal=false;
  alert('couldn\'t create xmlhttp object');
 }
}
return(xmlhttplocal);
}

/*
function addIngredient() {

	//var points = document.forms[0].elements["ergebnis_" +exercise].value;
    var neww;
    neww = 'aaaa';
    xmlhttp.open('get', 'login.php?row='+neww);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
}
/*
function handleResponse() {
    if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
        var response = xmlhttp.responseText;
        alert(response);
        var tables = document.getElementById('table');
        alert(tables);
        var newTR = document.createElement('tr');
        var newTD = document.createElement('td');
        var newMassField = document.createElement('input');
        
        newTD.appendChild( newMassField );
        newTR.appendChild( newTD );
        
        tables.appendChild( newTR );
		}
    }
}
/*
function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    
    if (DOM) {
        var viewer = document.getElementById(div2show)
        //alert(text);
        viewer.innerHTML=text
    }
    else if(IE) {
        document.all[div2show].innerHTML=text
    }
}
*/

function ZeileErzeugen(Index)
{
   // hole bisherige Ahnzahl Zutaten
   var index = document.getElementById("count").value;
   
   var indexNext = parseInt(index) +1;
   document.getElementById("count").setAttribute("value", indexNext);
   
/*   var Tabelle =  document.getElementById('ingredients');
   // TextNodes fzer Zelleninhalte erzeugen
   var Zelle_0 = document.createElement('input');
   var Zelle_1 = document.createElement('select');
   var Zelle_2 = document.createElement('input');
   var Zelle_x = document.createTextNode('x');
   Zelle_0.type = 'text';
   Zelle_0.name = 'mass_'+indexNext;
   Zelle_0.setAttribute('class', 'login');
   Zelle_0.setAttribute('style', 'width: 40px');
   
   Zelle_1.name = 'unit_'+indexNext;
   Zelle_1.setAttribute('class', 'pulldown_mass');
   
   Zelle_2.type = 'text';
   Zelle_2.name = 'ingredient_'+indexNext;
   Zelle_2.setAttribute('class', 'login');
   Zelle_2.setAttribute('style', 'width: 280px');   
 */  

  var TR = document.getElementById("ingredients").insertRow(indexNext);
  TR.setAttribute('class', 'header02b');
  TR.setAttribute('height', '24');
  TR.setAttribute('valign', 'middle');
  
  var TD1 = document.createElement("td");
  var TD1Element = document.createElement('input');
  
  var TD2 = document.createElement("td");
  
  var TD3 = document.createElement("td");
  
  var TD3Element = document.createElement('select');
  
  var TD4 = document.createElement("td");
    
  var TD5 = document.createElement("td");
  var TD5Element = document.createElement('input');
  
    
  TD1Element.type = 'text'; 
  TD1Element.name = 'mass_'+indexNext;
  TD1Element.setAttribute('class', 'login');
  TD1Element.setAttribute('className', 'login');
  TD1Element.style.width = "40px";
   
  TD3Element.name = 'unit_'+indexNext;
  TD3Element.setAttribute('class', 'pulldown_mass');
  TD3Element.setAttribute('className', 'pulldown_mass');
  
  TD5Element.type = 'text'; 
  TD5Element.name = 'ingredient_'+indexNext;
  TD5Element.setAttribute('class', 'login');
  TD5Element.setAttribute('className', 'login');
  TD5Element.style.width = "280px";
  
  TD1.appendChild(TD1Element);
  TD3.appendChild(TD3Element);
  TD5.appendChild(TD5Element);
  
  var opt = new Array();
  var value = new Array();
	var text = new Array();

  var units = new Array('g', 'kg', 'l', 'ml', 'Pk', 'Schuss', 'Stück', 'EL', 'TL', 'Prise', 'Dose', 'Bund', 'Z', 'zw', 'Beutel', 'Becher', 'Tube', 'Stange', 'cl', 'etwas');
    
  for(var i=0; i <= units.length-1; i++) {
    opt[i] = document.createElement("option");
	  value[i] = document.createAttribute("value");
	  value[i].nodeValue = units[i];
	  opt[i].setAttributeNode(value[i]);
	  text[i] = document.createTextNode(units[i]);
	  opt[i].appendChild(text[i]);
	  TD3Element.appendChild(opt[i]);
  }
  
  TR.appendChild(TD1);
  TR.appendChild(TD2);
  TR.appendChild(TD3);
  TR.appendChild(TD4);
  TR.appendChild(TD5);
}

function ZeileLoeschen(Index) 
{
   var Tabelle =  document.getElementById('ingredients')
   Tabelle.deleteRow(Index);
   Zaehlen(Tabelle,Index);
}

function Zaehlen(Tabelle,Index)
{
   /* Nummern in der ersten Spalte anpassen */
   for (var i=Index; i<Tabelle.rows.length; i++)
      Tabelle.rows[i].cells[0].firstChild.nodeValue = i;
}

function setVisibility() {
  var val = document.newRecipe.category.selectedIndex;
  if (val == 19) {
    diet.style.display = 'none';
    vegetarian.style.display = 'none';
  } else {
      diet.style.display = 'block';
      vegetarian.style.display = 'block';
    }
}

function getPrint(rid, persons) {
   window.open("index.print.php?php=recipes.detail.print&rid=" +rid +"&persons=" +persons, "Printansicht", "width=550,height=600,menubar=no,toolbar=no,scrollbars=1");
}

function sendMail(rid) {
   window.open("index.print.php?php=recipes.send&rid=" +rid, "Rezeptversand", "width=550,height=600,menubar=no,toolbar=no");
}

function getPrintList() {
   window.open("index.print.php?php=login.plan.print", "Printansicht", "width=550,height=600,menubar=no,toolbar=no,scrollbars=1");
}

function getPrintIngredients() {
   window.open("index.print.php?php=login.ingredients.print", "Printansicht", "width=550,height=600,menubar=no,toolbar=no, scrollbars=1");
}

