var newwindow;
function MM_openBrWindow(theURL,winName,features) {
  newwindow=window.open(theURL,winName,features);
  if (window.focus) {
    newwindow.focus()
  }
}

function showplz(id) {
    $select = document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
    if ($select=='eu' || $select=='ww') {
        document.getElementById('plz').style.display='none';
    } else {
        document.getElementById('plz').style.display='';
    }
}

function showaktion(id) {
    $select = document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
    if ($select=='pg') {
        document.getElementById('ks').style.display='none';
        document.getElementById('pg').style.display='';
    } else if ($select=='ks') {
        document.getElementById('pg').style.display='none';
        document.getElementById('ks').style.display='';
    } else {
        document.getElementById('ks').style.display='none';
        document.getElementById('pg').style.display='none';
    }
}

function switchlayer(Layer_Name) {
  var GECKO = document.getElementById?1:0;
  var NS = document.layers?1:0;
  var IE = document.all?1:0;

  if (GECKO) {
      document.getElementById(Layer_Name).style.display=(document.getElementById(Layer_Name).style.display=='block')?'none':'block';
  } else if (NS) {
      document.layers[Layer_Name].display=(document.layers[Layer_Name].display=='block')?'none':'block';
  } else if (IE) {
      document.all[Layer_Name].style.display=(document.all[Layer_Name].style.display=='block')?'none':'block';
  }
}

function zoom(img)
{
	MM_openBrWindow('/bin/zoom.php?img='+img,'araneszoom','width=537,height=798,scrollbars=1');	
}

function phpcode2(token)
{
	var output = '';
	output += '<'+'?='+' lg(\''+token+'\')'+' ?'+'>\n';
	output += 'lg(\''+token+'\')\n';
	output += '<'+'?='+' lg(\''+token+'\',\'\',false)'+' ?'+'>\n';
	output += 'lg(\''+token+'\',\'\',false)\n';
	document.getElementById('phpcode').value = output;
}

function adminpopup(url)
{
	window.opener.SetUrl(url); 
	window.close(); 
	window.opener.focus();
	
}

function mailpopup(url,id,rand) 
{
	if (rand) {
		id += Math.round(Math.random()*1000000,0);
	}
	MM_openBrWindow(url,'mailpopup'+id,'width=710,height=650,resizable=yes,scrollbars=yes');
	return false;
}

function windowwidth () {
  if (window.innerWidth) {
    return window.innerWidth;
  } else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else {
    return 0;
  }
}

function windowheight () {
  if (window.innerHeight) {
    return window.innerHeight;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight;
  } else {
    return 0;
  }
}


function AccessLog(mod_id,mod,account_id){
	
	var elements='mod_id='+mod_id+'&mod='+mod+'&account_id='+account_id+'&f=ajax';
	new Ajax.Request(	'/bin/accesslog.php',
						{	method: 'post', 
							parameters: elements
						}
					);
		
}


function AddStaffelRow(pricegroup_id)
{
	var index = document.getElementById("add_id_"+pricegroup_id).value;
	var new_index=index-1;
	document.getElementById("add_id_"+pricegroup_id).value=new_index;
	
	var table = document.getElementById("price_group_"+pricegroup_id);
	var rows = table.rows.length;
	var tr = table.insertRow(rows);
	
	var td1 = document.createElement("td");
	td1.className ="value";
	var td1input = document.createElement("input"); 
	td1input.name='input[staffeladd]['+pricegroup_id+']['+new_index+'][staffelqty]';
  	td1input.type='text';
  	td1input.className='input';
  	td1input.id='input_staffeladd_'+pricegroup_id+'_'+new_index+'_staffelqty';
  	td1input.maxlength='100';
  	td1input.size='10';
  	td1input.style.width='100px';
  	td1input.onblur = function(e) { this.style.backgroundColor=''; };
  	td1input.onfocus= function(e) { this.style.backgroundColor='#EEEEEE';};
  
  	var td2 = document.createElement("td");
  	td2.className ="value";
  	var td2input = document.createElement("input"); 
	td2input.name='input[staffeladd]['+pricegroup_id+']['+new_index+'][staffelvalue]';
  	td2input.type='text';
  	td2input.className='input';
  	td2input.id='input_staffeladd_'+pricegroup_id+'_'+new_index+'_staffelvalue';
  	td2input.maxlength='100';
  	td2input.size='10';
  	td2input.style.width='100px';
  	td2input.onblur = function(e) { this.style.backgroundColor=''; };
  	td2input.onfocus= function(e) { this.style.backgroundColor='#EEEEEE';};
  	
  	var td3 = document.createElement("td");
  	td3.className ="value";
  	
  	td1.appendChild(td1input);
  	td2.appendChild(td2input);
  	
	tr.appendChild(td1);
	tr.appendChild(td2);
	tr.appendChild(td3);
	
}

function AddArticleOptionRow()
{
    var index = document.getElementById("add_article_option_id").value;
    var new_index=index-1;
    document.getElementById("add_article_option_id").value=new_index;   
    var table = document.getElementById("optiontable");
    var rows = table.rows.length;
    var tr = table.insertRow(rows);
    
    var optionnr = document.getElementById("add_article_optionnr").style;
    var td1 = document.createElement("td");  
    var td1input = GetTDElement('optionnr',optionnr,new_index);   
    
    var optionlabel = document.getElementById("add_article_optionlabel").style; 
    var td2 = document.createElement("td");  
    var td2input = GetTDElement('optionlabel',optionlabel,new_index);
   
    var chk_article_optionsort = document.getElementById("add_article_optionsort"); 
    if(chk_article_optionsort) {
       var optionsort = document.getElementById("add_article_optionsort").style;         
       var td3 = document.createElement("td");  
       var td3input = GetTDElement('sort',optionsort,new_index);
    } 
    
    var chk_article_optionpricediff = document.getElementById("add_article_optionpricediff"); 
    if(chk_article_optionpricediff) {
       var optionpricediff = document.getElementById("add_article_optionpricediff").style;         
       var td4 = document.createElement("td");
       var td4input = GetTDElement('pricediff',optionpricediff,new_index);       
    } 
    
    var chk_article_optionekdiff = document.getElementById("add_article_optionekdiff"); 
    if(chk_article_optionekdiff) {
       var optionekdiff = document.getElementById("add_article_optionekdiff").style;         
       var td5 = document.createElement("td");  
       var td5input = GetTDElement('ekdiff',optionekdiff,new_index);
    } 
    
    var chk_article_optionavailable = document.getElementById("add_article_optionavailable"); 
    if(chk_article_optionavailable) {
       var td6 = document.createElement("td");  
       var td7 = document.createElement("td");  
       
       var optionavailable = document.getElementById("add_article_optionavailable").style;         
       var td8 = document.createElement("td");  
       var td8input = GetTDElement('available',optionavailable,new_index);
    } 
    
    var chk_article_optionbestellt = document.getElementById("add_article_optionbestellt"); 
    if(chk_article_optionbestellt) {    
        var td9 = document.createElement("td");  
    }
    
    
    var chk_article_min_storeqty = document.getElementById("add_article_min_storeqty"); 
    if(chk_article_min_storeqty) {
       var article_min_storeqty = document.getElementById("add_article_min_storeqty").style;         
       var td10 = document.createElement("td");  
       var td10input = GetTDElement('min_storeqty',article_min_storeqty,new_index);
    } 
    
    var chk_article_max_storeqty = document.getElementById("add_article_max_storeqty"); 
    if(chk_article_max_storeqty) {
       var article_max_storeqty = document.getElementById("add_article_max_storeqty").style;         
       var td11 = document.createElement("td");  
       var td11input = GetTDElement('max_storeqty',article_max_storeqty,new_index);
    } 
    
    var td12 = document.createElement("td");   
    var td12input = GetTDElement('active','',new_index);       
     
    
    td1.appendChild(td1input); 
    tr.appendChild(td1); 
    td2.appendChild(td2input);   
    tr.appendChild(td2);  
    if(td3input) {
        td3.appendChild(td3input);    
        tr.appendChild(td3);     
    }
    if(td4input) {
        td4.appendChild(td4input);    
        tr.appendChild(td4);     
    }
    if(td5input) {
        td5.appendChild(td5input);    
        tr.appendChild(td5);     
    }
    if(td6) {
        tr.appendChild(td6);     
    }
    if(td7) {
        tr.appendChild(td7);     
    }
    if(td8input) {
        td8.appendChild(td8input);    
        tr.appendChild(td8);     
    }
    if(td9) {
        tr.appendChild(td9);     
    }
    if(td10input) {
        td10.appendChild(td10input);    
        tr.appendChild(td10);     
    }
    if(td11input) {
        td11.appendChild(td11input);    
        tr.appendChild(td11);     
    }
    if(td12input) {
        td12.appendChild(td12input);    
        tr.appendChild(td12);     
    }
}

function GetTDElement(name,css_declaration,index)
{
    if(css_declaration == '') {
       var elements = document.createElement("input"); 
        elements.name='input[options]['+index+']['+name+']';
        elements.type='checkbox';
        elements.className='input';
        elements.id='input_add_article_option_'+index+'_option'+name;
        elements.value='1';
        elements.checked="checked";    
    }  else{
        var elements = document.createElement("input"); 
        elements.name='input[options]['+index+']['+name+']';
        elements.type='text';
        elements.className='input';
        elements.id='input_add_article_option_'+index+'_option'+name;
        if(css_declaration.size){
            elements.size=css_declaration.size;        
        }
        if(css_declaration.maxlength){
            elements.maxlength=css_declaration.maxlength;        
        }

        elements.style.width=css_declaration.width;
        elements.onblur = function(e) { this.style.backgroundColor=''; };
        elements.onfocus= function(e) { this.style.backgroundColor='#EEEEEE';};
        
    }
    return(elements);       
}
