var lastSearchItem1 = "";
var lastSearchItem2 = "";
var lastSearchItem3 = "";

var selected;
var submitter = null;

function submitFunction() {
    submitter = 1;
}
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.getElementById('payment'[0])) {
    document.getElementById('payment'[buttonSelect]).checked=true;
  } else {
    //document.getElementById('payment'[selected]).checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function setRezept(id,preis){
	document.getElementById('id'+id).innerHTML=preis;
	var s=document.getElementsByName(id+'rw');
	for(var i=0;i<s.length;i++){if(s[i].checked)v=s[i].value;}

}

 function newPhotoWindow(winWidth,winHeight,title,text) {
   dt = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>";
pictureWindow = window.open('','picWin','toolbar=no,location=no,scrollbars=yes,status=no,menubar=no,resizable=no,width=' + winWidth + ',height=' + winHeight + '');
pictureWindow.document.write (dt+"<html><head><title>" + title + "</title> <link rel='stylesheet' type='text/css'></head> <body bgcolor='#FFFFFF' text='#000000' > <p align='center'><span > " + text + " </span></p> <table width='554' border='0' cellspacing='0' cellpadding='0' align='center'> <tr> <td bgcolor='#990000' width='25' height='100'></td> <td width='536' height='50' valign='bottom'> <table width='535' border='0' cellspacing='0' cellpadding='0'> <tr> <td valign='bottom' height='50'> <div align='center'> <table width='100%' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='10'></td> <td> <div align='center'></div> </td> </tr> </table> </div> </td> </tr> <tr> <td valign='bottom' height='15'>&nbsp; </td> </tr> </table> <table width='100%' border='0' cellspacing='0' cellpadding='0' align='right'> <tr> <td width='402' height='50'></td> <td width='43' height='50'>&nbsp;</td> <td width='91' height='50'><a href='javascript:window.close()'><img src='../../Images/CloseWindow.gif' width='72' height='72' align='right' border='0'></a></td> </tr> </table> </td> </tr> </table> </body> </html>");
pictureWindow.document.close;
}

function popup(Title,Text) {
newWindow = window.open('','newWin','scrollbars=yes,width=630,height=400');
newWindow.document.write(Text);
newWindow.document.close;
}

//htr
function setPrice(price, ident){
	document.getElementById(ident).innerHTML = price;
}

function hideElement (id)
{
	document.getElementById(id).style.display = 'none';
}

function toggledisplay (id){
  if (document.getElementById) {
    var mydiv = document.getElementById(id);
    mydiv.style.display = (mydiv.style.display=='block'?'none':'block');
  }
}

function check_form_optional(form_name) {
  var form = form_name;

  var firstname = form.elements['firstname'].value;
  var lastname = form.elements['lastname'].value;
  var street_address = form.elements['street_address'].value;

  if (firstname == '' && lastname == '' && street_address == '') {
    return true;
  } else {
    return check_form(form_name);
  }
}

//Funktion zur Arraybildung
function ent(name, category, manufacturer, keyword,  bias, producturl, packagingsize, langid, proid, custid)
{
    this.name=name;
    this.category=category;
    this.manufacturer=manufacturer;
    this.keyword=keyword;
    this.bias=bias;
    this.producturl=producturl;
    this.packagingsize=packagingsize;
    this.langid=langid;
	this.proid=proid;
    this.custid=custid;
}

ent.prototype.toString = function () {
   return this.category;
};

function sortPrename (p1, p2) {
   if (p1.category > p2.category)
     return -1;
   else if (p1.category < p2.category)
     return 1;
   else if (p1.category > p2.category)
     return -1;
   else
     return 1;
}

function OpenNewDocument(address) {
	window.open(address, "_self");
}

function setup() {

SetupMMSuggest(document.quick_find.keywords, {'requestURL': "/mmsuggest/mmsuggest.php?max_results=12&keywords=$v$&query=$v$&shop=apofortuna.de"
, 'onActivate': function(input, rowArray, row) {window.location.href = rowArray[row][4]; }
, 'debug': false
, 'rowFunction': function(target, rows, field_index, i, iDiv) {

		header = '';
		pic = '';
		showPrice = '';
		var tmpInnerHTML = '';
		if (rows[i][0] == 'header')
		{
			iDiv.className = "suggRow2";
			if (rows[i][1] == '')
			{
				header = "Sonstige";
				pic = "../mmsuggest/images/ordner1.gif";
			}
			else if (rows[i][1] == 'ZZZHersteller')
			{
				header = "Zu Ihrer Suchanfrage wurden folgende Hersteller gefunden";
				pic = "../mmsuggest/images/ordner2.gif";
			}
			else
			{
				header = replaceHTMLEntities(rows[i][1]);
				pic = "../mmsuggest/images/ordner1.gif";
			}
			if ( i > 0 )
			{// Strich unter Listing der Hersteller
				if ( rows[i][1] != 'ZZZHersteller' && rows[i-1][1] == 'ZZZHersteller' )
					tmpInnerHTML += "<div style='height: 1px; line-height: 1px; background-color: #7fbc56;'><img width='398' height='1' src='../mmsuggest/images/platzhalter.gif' align='absmiddle'></div>";
			}
			tmpInnerHTML +=	"<div class='suggHeaderItem'>"+
							"<div class='suggHeaderPic' align='absmiddle' style='background-image:url(" + pic + "); background-repeat: no-repeat;'></div>"+
							"<div class='header'><nobr>" + header + "</nobr></div>"+
							"</div>";
		}
		else
		{
			// Bei Herstellern gibt es keine PZN, diese mssen aber ganz links stehen
			if (replaceHTMLEntities(rows[i][7]) != '')
			{
				/*"<div style='float: left; width: 200px; height: 32px;'>" +
					"<div class='suggProduct' style='clean: left;'><nobr>" + replaceHTMLEntities(rows[i][0]) + "</nobr></div>" +
					"<div class='suggMan' style='float: left;'><nobr>"+replaceHTMLEntities(rows[i][9])+"</nobr></div>" +
				"</div>" +*/
				var tmpHersteller = replaceHTMLEntities(rows[i][9]);
				if ( tmpHersteller != "" && ( typeof tmpHersteller != "undefined" ))
				{// Fuer Produkte mit / ohne Hersteller
					iDiv.className = "suggRow";
					tmpInnerHTML = "<div class='suggItem' style='height: 32px;'>" +
					"<div class='suggPic' style='height: 32px;'>&nbsp;</div>" +
					"<div class='suggPZN' style='float: left; height: 32px;'><nobr>" + replaceHTMLEntities(rows[i][7]) + "</nobr></div>";
					tmpInnerHTML += "<div style='float: left; width: 200px; height: 32px;'>" +
							"<div class='suggProduct' style='clean: left;'><nobr>" + replaceHTMLEntities(rows[i][0]) + "</nobr></div>" +
							"<div class='suggMan' style='float: left;'><nobr>"+replaceHTMLEntities(rows[i][9])+"</nobr></div>" +
						"</div>";
				}
				else
				{
					iDiv.className = "suggRow2";
					tmpInnerHTML = "<div class='suggItem' style='height: 16px;'>" +
					"<div class='suggPic' style='height: 16px;'>&nbsp;</div>" +
					"<div class='suggPZN' style='float: left; height: 32px;'><nobr>" + replaceHTMLEntities(rows[i][7]) + "</nobr></div>";
					tmpInnerHTML += "<div style='float: left; width: 200px; height: 16px;'>" +
							"<div class='suggProduct' style='clean: left;'><nobr>" + replaceHTMLEntities(rows[i][0]) + "</nobr></div>" +
						"</div>";
				}
				tmpInnerHTML += "<div class='suggPackagingSize' style='float: right; height:16px;'><nobr>ab&nbsp;" + replaceHTMLEntities(rows[i][5]) + "&nbsp; EUR</nobr></div>"+
				"</div>";
			}
			else
			{
				iDiv.className = "suggRow2";
				tmpInnerHTML = "<div class='suggItem'>" +
				"<span class='suggPic'>&nbsp;</span>" +
				"<span class='suggNoPZN'><nobr>" + replaceHTMLEntities(rows[i][0]) + "</nobr></span>"+
				"</div>";
			}
		}
		iDiv.innerHTML = tmpInnerHTML;

return true;
}, 	'preFunction': function (input, rowArray)
	{
		arr = new Array();

		for(i=0; i<rowArray.length; i++)
		{
	   		arr[i]=new ent(rowArray[i][0], rowArray[i][1], rowArray[i][2], rowArray[i][3], rowArray[i][4], rowArray[i][5], rowArray[i][6], rowArray[i][7], rowArray[i][8], rowArray[i][9]);
       	}

		arr.sort(sortPrename);

       	newarr=new Array();

		for(j=0; j<arr.length; j++)
       	{
			if (j==0)
			{
				zahl = j;
				newarr[zahl]= new Array("header", arr[j].category, "", "", "index.php#", "", "", "", "", "Kategorie durchsuchen");
				zahl++;
			}
			else
			{
				if (arr[j].category != arr[j-1].category)
				{
					newarr[zahl]= new Array("header", arr[j].category, "", "", "index.php#", "", "", "", "", "Kategorie durchsuchen");
					zahl++;
				}
			}
       		newarr[zahl]= new Array(arr[j].name, arr[j].category, arr[j].manufacturer, arr[j].keyword, arr[j].bias, arr[j].producturl, arr[j].packagingsize, arr[j].langid, arr[j].proid, arr[j].custid);
       		zahl++;
       	}

		
	 	return newarr;
	}
, 'headerFunction' : function (parent, rowArray)
{
	tmpArray = new Array();
	var hits=0;
	for (i=0;i<rowArray.length&&hits<5;i++)
	{
		equal=0;
		if ( rowArray[i][0] != 'header' && rowArray[i][0] != '' && rowArray[i][0] != 'ZZZHersteller')
		{
			for (k=0;k<i;k++)
			{
				if ( tmpArray[k] == rowArray[i][0] )
					equal=1;
			}
			if (equal==0)
			{
				tmpArray[hits] = rowArray[i][0];
				hits++;
			}
		}
	}
	
	ergebnis =  "<div class='headline' align='left'>"+
				"<span><nobr>&nbsp;&nbsp;&nbsp;Ergebnisse zu Ihrer Suche:</nobr></span></div>"+
								
 				"<div class='header_background' style='background-color: #EDEDED;'>"+
 				"<div style='float:left;'>&nbsp;&nbsp;&nbsp;&nbsp;W&auml;hlen Sie eine unserer Empfehlungen</div>"+
 				"<div style='float: right;'><a href='javascript:mmHideSuggBox(this.document)'><img width='10' height='10' src='../mmsuggest/images/kreuz.gif' align='absmiddle' style='margin-top: 6px; margin-right: 12px;' alt=''/></a></div></div>"+
 				"<div class='empfehlung' style='background-color: #EDEDED;'>&nbsp;&nbsp;&nbsp;&nbsp;oder lassen Sie <span class='empfehlung_text'><a href='http://apofortuna.de/advanced_search_result.php?keywords="+document.quick_find.keywords.value+"' onmousedown='OpenNewDocument(this.href); return false' style='color: #7fbc56;'>alle Treffer zu \""+document.quick_find.keywords.value+"\" anzeigen.</a></span></div>"+
				"<div style='height: 1px; line-height: 1px; background-color: #7fbc56;'><img width='398' height='1' src='../mmsuggest/images/platzhalter.gif' align='absmiddle'></div>"+
 				//"<div style='height: 1px; line-height: 1px; background-color: #EA3C00;'></div>"+
				"<div class='empfehlung' style='text-indent: 10px;'><b>Passende Ergebnisse zu Ihrer Suche:</b></div>";
				//"<div class='empfehlung' style='text-indent: 20px;'><span class='empfehlung_text'>"+
				//"<a href='http://www.medizinfuchs.de/search_result.php?auswahl=medikamente&medisuche="+document.quick_find.keywords.value+"' onmousedown='OpenNewDocument(this.href); return false' style='color: #EA3C00;'>"+document.quick_find.keywords.value+"</a>"+
				//"</span></div>";
	for (i=0;i<tmpArray.length;i++)
	{
		ergebnis = ergebnis + "<div class='empfehlung' style='text-indent: 20px;'><span class='empfehlung_text'><a href='http://apofortuna.de/advanced_search_result.php?keywords="+replaceHTMLEntities(tmpArray[i])+"' onmousedown='OpenNewDocument(this.href); return false' style='color: #7fbc56;'>"+replaceHTMLEntities(tmpArray[i])+"</a></span></div>";
	}
	ergebnis = ergebnis + "<div style='height: 1px; line-height: 1px; background-color: #7fbc56;'><img width='398' height='1' src='../mmsuggest/images/platzhalter.gif' align='absmiddle'></div>";
//	ergebnis = ergebnis + "<div style='height: 1px; line-height: 1px; background-color: #EA3C00;'></div>";
	return ergebnis;
}
, 'width': 400
, 'align': 'right'
});
}
