var buttonClicked="0";
var filterMultiSelect="";
var buttonName = "";

function getURLForLogo()
{
	var manufacturerName = document.getElementById('manufacturerName').value;
	var logoURL = pathfinder()+'/images/logos/'+manufacturerName+'.gif';
	var	str	= [];
	str.push('<img src="'+logoURL+'" class="logo" alt="Manufacturer Logo" title="Manufacturer Logo" onerror="checkImage()"/>');
	document.getElementById('putImage').innerHTML =  str.join('');
}

function body_Onload()
{
	if(window.event) //If IE
	{
		if(document.CatSearchForm.hidReload.value!="initialvalue")
		{
			//history.go(0);
			//location.reload(true);
			document.CatSearchForm.in_stock.value = document.CatSearchForm.in_stockPreVal.value;
			document.CatSearchForm.eu_rohs.value = document.CatSearchForm.eu_rohsPreVal.value;
			document.CatSearchForm.china_rohs.value = document.CatSearchForm.china_rohsPreVal.value;

			if(document.CatSearchForm.filtMultiSelectPreVal.value!='null')
			{
				document.CatSearchForm.filtMultiSelect.value=document.CatSearchForm.filtMultiSelectPreVal.value;
			}
			else
			{
				document.CatSearchForm.filtMultiSelect.value='';
			}

			document.CatSearchForm.cat.value=document.CatSearchForm.catPreVal.value;
			if(document.CatSearchForm.catLevel !=undefined)
			{
				document.CatSearchForm.catLevel.value=document.CatSearchForm.catLevelPreVal.value;
			}
			document.CatSearchForm.sort1Name.value=document.CatSearchForm.sort1NamePreVal.value;
			document.CatSearchForm.sort1Order.value=document.CatSearchForm.sort1OrderPreVal.value;
			document.CatSearchForm.docid.value=document.CatSearchForm.docidPreVal.value;
			document.CatSearchForm.event.value=document.CatSearchForm.eventPreVal.value;
			document.CatSearchForm.start.value=document.CatSearchForm.startPreVal.value;
			document.CatSearchForm.limit.value=document.CatSearchForm.limitPreVal.value;
			document.CatSearchForm.submit();
		}
		else
		{
			if(document.CatSearchForm.in_stock.checked == true)
			{
				document.CatSearchForm.in_stockPreVal.value = 'on';
			}
			else
			{
				document.CatSearchForm.in_stockPreVal.value = '';
			}
			
			if(document.CatSearchForm.eu_rohs.checked == true)
			{
				document.CatSearchForm.eu_rohsPreVal.value = 'on';
			}
			else
			{
				document.CatSearchForm.eu_rohsPreVal.value = '';
			}
			
			if(document.CatSearchForm.china_rohs.checked == true)
			{
				document.CatSearchForm.china_rohsPreVal.value = 'on';
			}
			else
			{
				document.CatSearchForm.china_rohsPreVal.value = '';
			}

			document.CatSearchForm.filtMultiSelectPreVal.value=document.CatSearchForm.filtMultiSelect.value;			
			
			document.CatSearchForm.catPreVal.value=document.CatSearchForm.catPreVal.value;
			if(document.CatSearchForm.catLevel !=undefined)
			{
				document.CatSearchForm.catLevelPreVal.value=document.CatSearchForm.catLevel.value;
			}
			document.CatSearchForm.sort1NamePreVal.value=document.CatSearchForm.sort1Name.value;
			document.CatSearchForm.sort1OrderPreVal.value=document.CatSearchForm.sort1Order.value;
			document.CatSearchForm.docidPreVal.value=document.CatSearchForm.docid.value;
			document.CatSearchForm.eventPreVal.value=document.CatSearchForm.event.value;
			document.CatSearchForm.startPreVal.value=document.CatSearchForm.start.value;
			document.CatSearchForm.limitPreVal.value=document.CatSearchForm.limit.value;
			document.CatSearchForm.hidReload.value="newvalue";
		}
	}
} 

function checkEnterCartForm(e,myindex)
{
	//alert("checkEnterCartForm called");
	var key;

	if(window.event)
		key = window.event.keyCode;	//IE
	else
		key = e.which;     		//Firefox

	if(key == 13)
	{
		//alert("Enter....");
		onAddToCart(myindex);
	}
}

function checkEnterNewCatSearchForm(e)
{
	//alert("checkEnterNewcatSearchForm called");
	var key;

	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox

	if(key == 13)
	{
		//alert("Enter....");
		subNewCatSearchForm();
	}
}

function checkEnterCatSearchForm(e)
{
	//alert("checkEnterCatSearchForm called");
	var key;

	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = e.which;     //firefox

	if(key == 13)
	{
		//alert("Enter....");
		subCatSearchForm();
	}
}

function getTableHeight () 
{
	var tableHeight=document.getElementById('results-table').clientHeight+50;
	var tableHeightString=tableHeight.toString();
	var versionagent=navigator.userAgent;
	var version6=versionagent.indexOf("6.0");
	if (version6!=-1)
	{
		document.getElementById("search-results").style.height=tableHeightString+"px";
	}
}

// Pagination Logic 
/**
 *	Create a pagination	DOM	or String as needed
 *	@param	count {Integer}	the	number of results
 *	@param	resultsPerPage {Integer} the maximum per page
 *	@param	offset {String}	OPTIONAL: the offset of	the	current	page
 *	@param	noOfLinks {Integer}	:No	of links shown
 *	@return	{String} the DOM string	or empty string	when DOM object	is passed
 */
 function buildPagination(count,resultsPerPage,	offset, noOfLinks) 
 {

    
	if (! offset ||	0 >	offset)	
	{
		offset=0;
	}
	if (count > 3999)
	{
		count = 3999;
	}

	var	str	= [],
	maxPages = noOfLinks,
	numpages = Math.ceil(count / resultsPerPage),
	index =	Math.ceil(offset / resultsPerPage),
	findex = index;
	lindex = index + noOfLinks;

    if(offset==0)
	{
		findex= numpages;
		lindex = numpages + noOfLinks;
	}

	//Add pages text
	if(numpages> 0 && findex>0)
	{
		str.push('&nbsp;');
		str.push('&nbsp;');
		str.push('Page '+findex+' of '+numpages);
		str.push('&nbsp;');
		str.push('&nbsp;');	
		str.push('&nbsp;');
		str.push('&nbsp;');
	}

	//Add |< link		
	str.push('<a href="javascript:callPagination(0)">');
	str.push('<img src="/static/images/layout/link_first.gif" width="7" height="6" alt="first page" title="first page" />');
	str.push('</a>');
	str.push('&nbsp;');
	str.push('&nbsp;');
	str.push('&nbsp;');

	// Add < link
	var	beforeIndex	= 0;
	if(findex >	1)
	{
		beforeIndex	= (findex-1)*resultsPerPage-resultsPerPage;
	}
	else
	{
		beforeIndex	= 0;
	}
	str.push('&nbsp;');
	str.push('&nbsp;');
	str.push('<a href="javascript:callPagination('+beforeIndex+')">');
	str.push('<img src="/static/images/layout/link_prev.gif" width="5" height="5" alt="previous page" title="previous page" />');
	str.push('</a>');
	str.push('&nbsp;');
	str.push('&nbsp;');

	// Add numbers
	var	count1 = 0;
	var	innerCount = 0;
	var roundTotalRecords=Math.ceil(count/resultsPerPage)*resultsPerPage;
	if(Math.abs(resultsPerPage) > Math.abs(count))
	{
		str.push('<a href="javascript:callPagination(0)">');
		str.push('1');
		str.push('</a>');
	}
	else
	{
		var n_index=findex;
		var n_sideLinks=Math.floor((noOfLinks - 1) / 2);
		var n_pages=numpages;
		var n_links=noOfLinks;
		var n_firstLink,n_lastLink;

		if (n_index + n_sideLinks >= n_pages) 
		{
			n_firstLink = n_pages - n_links + 1;
			n_lastLink = n_pages;
		}
		else if (n_index - n_sideLinks <= 0)
		{
			n_firstLink = 1;
			if(numpages <= noOfLinks)
			{
				n_lastLink =numpages;
			}
			else
			{
				n_lastLink = n_links;
			}
		}
		else
		{
			n_firstLink = n_index - n_sideLinks;
			n_lastLink = n_firstLink + n_links - 1;
		}
		if(n_firstLink <= 0)
		{
			n_firstLink=1;
		}
		
		for(var i=n_firstLink;i<=n_lastLink;i++)
		{
			var j=(i*resultsPerPage)-resultsPerPage;
			str.push('&nbsp;');
			str.push('&nbsp;');
			if(i==findex)
			{
				str.push(i);
			}
			else
			{
				str.push('<a href="javascript:callPagination('+j+')">');
				str.push(i);
				str.push('</a>');
			}
			str.push('&nbsp;');
			str.push('&nbsp;');
		}
	}
	//If the results per page is greater the number of records 
	// Add > link
	if(count <=	 findex*resultsPerPage)
	{
		str.push('&nbsp;');
		str.push('&nbsp;');
		str.push('<a href="#">');
		str.push('<img src="/static/images/layout/link_next.gif" width="5" height="5" alt="next page" title="next page" />');
		str.push('</a>');
		str.push('&nbsp;');
		str.push('&nbsp;');
		str.push('<a href="#">');
		str.push('<img src="/static/images/layout/link_last.gif" width="8" height="6" alt="last page" title="last page" />');
   		str.push('</a>');		
	}
	else
	{
		var	afterIndex = 0;
		if(findex <	numpages)
		{
			afterIndex = (findex+1)*resultsPerPage-resultsPerPage;
		}
		else
		{
			afterIndex=0;//(noOfLinks*resultsPerPage)-resultsPerPage;
		}
		str.push('&nbsp;');
		str.push('&nbsp;');
		str.push('<a href="javascript:callPagination('+afterIndex+')">');
		str.push('<img src="/static/images/layout/link_next.gif" width="5" height="5" alt="next page" title="next page" />');
		str.push('</a>');
		str.push('&nbsp;');
		str.push('&nbsp;');

		// Add >| link
		var finalIndex=0;
		finalIndex=Math.floor(count/resultsPerPage)*resultsPerPage;
		if(count%resultsPerPage==0)
		{
			finalIndex=finalIndex-resultsPerPage;
		}
		//finalIndex=Math.floor(count/resultsPerPage)*resultsPerPage;
		str.push('&nbsp;');
		str.push('&nbsp;');
		str.push('<a href="javascript:callPagination('+finalIndex+')">');
		str.push('<img src="/static/images/layout/link_last.gif" width="8" height="6" alt="last page" title="last page" />');
		str.push('</a>');
		str.push('&nbsp;');
		str.push('&nbsp;');
	}
	document.getElementById("paginationId").innerHTML = str.join('');
	getTableHeight();

 }

/*
*Function Name callMultipleSelectBox
*Function Group Advanced Filtering and Manufacturer Multiple Select Box
*/
function callMultipleSelectBox()
{
	//alert("In callMultipleSelectBox");

	filterMultiSelect = document.getElementById("filtMultiSelect").value;
	var tempFilterMultiSelect = "";
	var tempFilterTokenArray;
	var filterArray  = filterMultiSelect.split("&filt=");
	for(counter=1; counter < filterArray.length; counter++)
	{
		tempFilterTokenArray = filterArray[counter].split(escape("!"));
		if ((buttonName == 'mFilterButton' && tempFilterTokenArray[0] !='suppcd') ||
		    (buttonName == 'filterButton' && tempFilterTokenArray[0] =='suppcd'))
		{
			tempFilterMultiSelect = tempFilterMultiSelect+'&filt='+filterArray[counter];
		}
	}
	filterMultiSelect = tempFilterMultiSelect;

	var optionsCount=0
	var optionsSelected="";
	for(counter = 0; null != document.CatSearchForm.elements[counter]; counter++)
	{	
		if(document.CatSearchForm.elements[counter].type=="select-multiple")
		{
			var object = document.CatSearchForm.elements[counter];
			if(null != object)
			{
				if((buttonName == 'mFilterButton' && document.CatSearchForm.elements[counter].name=='suppcd') ||
				    (buttonName == 'filterButton' && document.CatSearchForm.elements[counter].name!='suppcd'))
				for(i = 0; i < object.length; i ++)
				{
					if(object.options[i].selected)
					{
						optionsCount ++;
						optionsSelected = optionsSelected+"!"+object.options[i].value;
					}
				}
				if(optionsCount>0)
				{
					optionsSelected= escape(optionsSelected);

					// Start - code change for PS 1498547
					optionsSelected = optionsSelected.replace (/\+/g,"%2B");
					optionsSelected = optionsSelected.replace (/\&/g,"%26");
					// End - code change for PS 1498547
					
					filterMultiSelect=filterMultiSelect+"&filt="+document.CatSearchForm.elements[counter].name+optionsSelected;
				}
				optionsCount=0;
				optionsSelected = "";
			}
		}
	}
	document.CatSearchForm.filtMultiSelect.value=filterMultiSelect;
}

/*
*Function Name callResetAllFilters
*Function Group Advanced Filtering and Manufacturer Multiple Select Box
*/
function callResetAllFilters()
{
	for(counter = 0; null != document.CatSearchForm.elements[counter]; counter++)
	{
		if(document.CatSearchForm.elements[counter].type=="select-multiple")
		{
			var object = document.CatSearchForm.elements[counter];
			if(null != object)
			{
				if(document.CatSearchForm.elements[counter].name!='suppcd')
				{
					for(i = 0; i < object.length; i ++)
					{
						if(object.options[i].selected)
						{
							object.options[i].selected=false;
						}
					}
				}
			}
		}
	}
	setFilters('filterButton');
}
	
/*
*Function Name removeFilter
*Function will remove the selected filters
*/
function removeFilter(id)
{
	filterMultiSelect = document.getElementById("filtMultiSelect").value;
	var tempFilterMultiSelect = "";
	var tempFilterTokenArray;
	var filterArray  = filterMultiSelect.split("&filt=");
	for(counter=1; counter < filterArray.length; counter++)
	{
		tempFilterTokenArray = filterArray[counter].split(escape("!"));
		if(tempFilterTokenArray[0] != id)
		{
			tempFilterMultiSelect = tempFilterMultiSelect+'&filt='+filterArray[counter];
		}
	}
	filterMultiSelect = tempFilterMultiSelect;
	document.getElementById("filtMultiSelect").value = filterMultiSelect;
	checkSortField();
	subCatSearchForm();
}

/*
*Function Name callCategory
*Function Group Category 
*This function will submit the form with the selected category
*/
function callCategory(id,name)
{
	//alert("Inside callCategory");
	document.CatSearchForm.cat.value=id;
	var levelCount_arr=id.split("/");
	if(levelCount_arr.length==1)
	{
		document.CatSearchForm.level1Name.value=name;
		document.CatSearchForm.level1ID.value=id;
	}
	else if(levelCount_arr.length==2)
	{
		document.CatSearchForm.level2Name.value=name;
		document.CatSearchForm.level2ID.value=id;
	}
	else
	{
		document.CatSearchForm.level3Name.value=name;
		document.CatSearchForm.level3ID.value=id;
	}
	subFiltSortCatSearchForm();
}

/*
*Function Name sortField
*Function Group Sorting Based on field and Order Chosen
*/
function sortField(sortDir,sortValue)
{
	document.CatSearchForm.sort1Name.value=sortValue;
	document.CatSearchForm.sort1Order.value=sortDir;
	if(sortValue=="")
	{
		checkSortField();
	}
	subFiltSortCatSearchForm();
}

function checkSortField()
{

	//alert("In checkSortField");
    if(document.CatSearchForm.sort1Name.value=='' )
	{
		var str=document.CatSearchForm.requestedURL.value;
		var urlLen = str.length;
		var sortIndex= str.indexOf("sort");
		var sortValue="";
		var dirValue="";

		if(sortIndex!=-1)
		{
			var sortSubstr = str.substring(sortIndex,urlLen);
			var ampIndex = sortSubstr.indexOf("&");
			sortValue = sortSubstr.substring(5,ampIndex);
			document.CatSearchForm.sort1Name.value=sortValue;
		}

		var dirIndex= str.indexOf("dir");
		if(dirIndex!=-1)
		{
			var dirSubstr = str.substring(dirIndex,urlLen);
			dirValue = dirSubstr.substring(4,7);
			document.CatSearchForm.sort1Order.value=dirValue;
		}
	}
}

/*
*Function Name callPartDetail
*Function Group General Options
*For Part Detail Page
*/    
function callPartDetail(docid)
{
//	alert("inside callPartDetail");
	document.CatSearchForm.docid.value = docid;
	document.CatSearchForm.event.value='1007';
	document.CatSearchForm.submit();
}

/*
*Function Name pageLimit
*Function Group Category 
*/
function pageLimit(page)
{
	document.CatSearchForm.limit.value=page;
	subFiltSortCatSearchForm();
}

function callPagination(nextStart)	
{
	//alert("Inside call pagination");
	document.CatSearchForm.start.value=nextStart;
	subFiltSortCatSearchForm();
}

function ResetCategory()
{
	document.CatSearchForm.cat.value='';
	if(document.CatSearchForm.catLevel !=undefined)
	{
		document.CatSearchForm.catLevel.value='';
	}
	subFiltSortCatSearchForm();
}

function setFilters(str)
{
	var chkButton=1;
	buttonName = str;
	
	//added for PS 1604918
	var searchToken = document.CatSearchForm.search_token.value; 

	//modified for PS 1604918
	//if ( str == 'filterButton' || str == 'mFilterButton')
	if ( str == 'filterButton' || str == 'mFilterButton' || searchToken == '')
	{
		buttonClicked=1;
	}
	document.getElementById('chkButton').value=chkButton;
	document.CatSearchForm.start.value=0;
	subFiltSortCatSearchForm();
}

function subSearchBreadCrumbs(cat)
{
	//alert("inside subSearchBreadCrumbs");
	if(cat!=undefined)
	{
		document.CatSearchForm.cat.value=cat;
	}
	else
	{
		document.CatSearchForm.cat.value='';
		document.CatSearchForm.catLevel.value='';
	}
	subCatSearchForm();
}

function subFiltSortCatSearchForm()
{

	var chkButton1=document.getElementById("chkButton").value;
	if(chkButton1==1 && buttonClicked==1)
	{
		document.getElementById("chkButton").value=chkButton1;
		callMultipleSelectBox();
	}
	else
	{
		document.getElementById("chkButton").value=chkButton1;
		if(buttonClicked==1)
		{
			callMultipleSelectBox();
		}
		else
		{
			if(document.CatSearchForm.filtMultiSelect.value=='null')
			{
				document.CatSearchForm.filtMultiSelect.value='';
			}
		}
	}
	checkSortField();
	subCatSearchForm();
}

String.prototype.trim = function () 
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function subCatSearchForm()
{
		document.CatSearchForm.application.value='SEARCH';
		
		if(document.CatSearchForm.event.value==1007)
		{
			document.CatSearchForm.event.value=1008;
		}

		document.CatSearchForm.submit();
}

function subDetailBreadCrumbs()
{
	document.brdCrmbs.submit();
}

function subNewCatSearchForm()
{
	if(document.CatSearchForm.search_token_new.value == undefined ||
		document.CatSearchForm.search_token_new.value == null ||
		document.CatSearchForm.search_token_new.value.trim()=='')
	{
		alert('Please enter the search text');
	}
	else
	{
		if(document.CatSearchForm.in_stock_new.checked == true)
		{
			document.CatSearchForm.in_stock.value = 'on';
			document.CatSearchForm.in_stock.checked = true;
		}
		else
		{
			document.CatSearchForm.in_stock.value = '';
			document.CatSearchForm.in_stock.checked = false;
		}
	
		if(document.CatSearchForm.eu_rohs_new.checked == true)
		{
			document.CatSearchForm.eu_rohs.value = 'on';
			document.CatSearchForm.eu_rohs.checked = true;
		}
		else
		{
			document.CatSearchForm.eu_rohs.value = '';
			document.CatSearchForm.eu_rohs.checked = false;
		}
	
		if(document.CatSearchForm.china_rohs_new.checked == true)
		{
			document.CatSearchForm.china_rohs.value = 'on';
			document.CatSearchForm.china_rohs.checked = true;
		}
		else
		{
			document.CatSearchForm.china_rohs.value = '';
			document.CatSearchForm.china_rohs.checked = false;
		}
		document.CatSearchForm.search_token.value = document.CatSearchForm.search_token_new.value;
		document.CatSearchForm.cat.value='';
		if(document.CatSearchForm.catLevel !=undefined)
		{
			document.CatSearchForm.catLevel.value='';
		}
		
		document.CatSearchForm.filtMultiSelect.value = '';
		document.CatSearchForm.sort1Name.value = '';
		document.CatSearchForm.sort1Order.value = '';
		//document.CatSearchForm.limit.value = '';
		document.CatSearchForm.start.value = '';
		document.CatSearchForm.event.value=1009;
		document.CatSearchForm.submit();
		return true;
	}
}

 /*********** Functions to be removed after CSS / style integration ***********/
 /* page init */
 
 function init(thisDocument)
 {
   if(!thisDocument)
   { 
     // event for closing dropdowns //
     document.onmouseup = closeSuggest;
   
     /* init folding Rows for IE */
     if(document.all)
     {
       rows = document.getElementsByTagName("tr");
       for(i = 0; i < rows.length; i++)
       {
         thisRow = rows[i];
         if(thisRow.className.search(/sub/) > -1)
         {
           thisRow.style.display = "none";
         }
       }
     }
 
     thisDocument = document; 
   }
 
   // init Buttons //
   buttons = thisDocument.getElementsByTagName("button");
   for(i = 0; i < buttons.length; i++)
   {
     thisButton = buttons[i];
     if(thisButton.getElementsByTagName("div")[0].className == "bg")
     {
       buttonWidth = thisButton.getElementsByTagName("div")[0].offsetWidth + "Px";
       thisButton.style.width = buttonWidth;
       thisButton.style.visibility = "visible";
     }
   }
 }
 
 /* navi/cart mouseover */
 var openRoller = "";
 var rollerTimeOut = "";
 function openRollOver(roller, stay)
 {
   if(roller)
   {
     if(rollerTimeOut)
     { window.clearTimeout(rollerTimeOut); }
     if(openRoller != roller)
     {
       if(stay != "stay")
       {
         if(openRoller)
         { _closeRollOver(); }
         openRoller = roller;
       }
       if(document.all && roller.id == "cart")
       { document.getElementById("cartdetail").style.width = (roller.offsetWidth + 30) + "Px"; }
       if(roller.getElementsByTagName("ul")[0] && roller.getElementsByTagName("ul")[0].className == "compact")
       { roller.getElementsByTagName("ul")[0].style.width = (roller.offsetWidth - 2) + "Px"; }
       roller.className = "over";
       init(roller);
     }
   }
   return false;
 }
 
 function closeRollOver(roller, stay)
 {
   if(roller)
   {
     if(roller == openRoller)
     { rollerTimeOut = window.setTimeout("_closeRollOver()", 200);  }
   }
   return false;
 }
 
 function _closeRollOver(roller)
 {
   if(!roller)
   { roller = openRoller; }
   if(roller)
   {
     openRoller = "";
     roller.className = "";
   }
 }
 
 function toggleRollOver(roller)
 {
   if(roller)
   {
     if(roller.className.search(/over/) > -1)
     {
       _closeRollOver(roller);
     }
     else
     {
       openRollOver(roller, "stay");
     }
   }
 }  
 
 function openAllRollOvers(parentId)
 {
   toggleAllRollOvers(parentId, "over");
 }
 
 function closeAllRollOvers(parentId)
 {
   toggleAllRollOvers(parentId, "");
 }
 
 function toggleAllRollOvers(parentId, newClass)
 {
   thisBox = document.getElementById(parentId);
   if(thisBox)
   {
     roller = thisBox.getElementsByTagName("li");
     for(i = 0; i < roller.length; i++)
     {
       roller[i].className = roller[i].className.replace(/over/, "") + newClass;
     }
   }
 }
 
 
 /* suggestions for searchfields */
 var dummySuggests = new Array("Test Suggestions", "for testing purpose", "Lorem Ipsum", "sit Dolor", "Amet Resus", "Vel iriure hendrerit", "vulputate", "velit", "esse", "molestie", "consequat");
 var dummyDropdowns = new Array("Lorem Ipsum", "sit Dolor", "Amet Resus", "Vel iriure hendrerit", "vulputate", "velit", "esse", "molestie", "consequat");
 var currencies = new Array("USD", "EUR", "CHF", "Camels", "Goats");
 var suggestTimeOut;
 var suggestBox;
 var keepSuggest;
 
 function suggest(searchBox, thisType, thisList)
 {
   if((thisType == "dropdown" && suggestBox != document.getElementById(searchBox.id.replace(/field/, "suggest")))  || (thisType != "dropdown" && searchBox.value.length > 2))
   {
     keepSuggest = false;
     _closeSuggest();
     keepSuggest = true;
     suggestBox = document.getElementById(searchBox.id.replace(/field/, "suggest"));
     suggestBox.innerHTML = "";
     suggestBox.style.width = (searchBox.offsetWidth - 2) + "Px";
     suggestBox.style.left = positionLeft(searchBox) + "Px";
     if(thisList || thisType == "dropdown")
     {  
       if(!thisList)
       { thisList = dummyDropdowns; }
       suggestWords = getSuggest('', thisList); 
     }
     else
     {  suggestWords = getSuggest(searchBox.value); }
     if(suggestWords.length > 0)
     {
       suggestBox.style.display = "block";
       for(i=0; i<suggestWords.length; i++)
       {
         suggestWordHL = suggestWords[i].replace(new RegExp("(" + searchBox.value + ")", "gi"), '<strong>$1</strong>')
         suggestBox.innerHTML += "<a href=\"#" + suggestWords[i] + "\" onclick=\"takeSuggest('" + searchBox.id + "', this); return false;\">" + suggestWordHL + "</a>";
       }
       var suggestBoxBottom = suggestBox.offsetHeight + positionTop(searchBox) + searchBox.offsetHeight;
       var documentBottom = document.getElementsByTagName("body")[0].offsetHeight;
       var windowBottom = document.documentElement.scrollTop + document.documentElement.clientHeight;
       if(suggestBoxBottom > documentBottom || suggestBoxBottom > windowBottom)
       { suggestBox.style.top = (positionTop(searchBox) - suggestBox.offsetHeight) + "Px"; }
       else
       { suggestBox.style.top = (positionTop(searchBox) + searchBox.offsetHeight) + "Px"; }
     }
   }
 }
 
 function getSuggest(requestString, suggestWords)
 {
   if(!suggestWords)
   { suggestWords = dummySuggests; }
   returnSuggests = new Array();
   for(i=0; i<suggestWords.length; i++)
   {
     if(suggestWords[i].search(new RegExp(requestString, "gi")) > -1)
     {
       returnSuggests.push(suggestWords[i]);
     }
   }
   return returnSuggests;
 }
 
 function takeSuggest(searchBoxId, returnLink)
 {
   searchBox = document.getElementById(searchBoxId);
   searchBox.value = returnLink.innerHTML.replace(/<(|\/)strong>/gi, "");
   keepSuggest = false;
   _closeSuggest();
 }
 
 function closeSuggest()
 {
   suggestTimeOut = window.setTimeout("_closeSuggest()", 5);
 }
 
 function _closeSuggest()
 {
   if(!keepSuggest && suggestBox)
   {
     if(suggestTimeOut)
     { window.clearTimeout(suggestTimeOut); }
     suggestBox.innerHTML = "";
     suggestBox.style.display = "none";
     suggestBox = false;
   }
   keepSuggest = false;
 }
 
 function positionLeft(posTag)
 {
   if(posTag.offsetParent && !hasPos(posTag.offsetParent))
   { return posTag.offsetLeft + positionLeft(posTag.offsetParent); }
   else
   { return posTag.offsetLeft; }
 }
 
 function positionTop(posTag)
 {
   if(!hasPos(posTag.offsetParent))
   { return posTag.offsetTop + positionTop(posTag.offsetParent); }
   else 
   { return posTag.offsetTop; }
 }
 
 function hasPos(thisTag)
 {
   if(thisTag.tagName.search(/body/i) > -1)
   { return true; }
   else if(getStyle(thisTag, "position") == "relative" || getStyle(thisTag, "position") == "absolute" )
   { return true; }
   else
   { return false }
 }
 
 function getStyle(thisTag, styleName){
   if(thisTag)
   {
     if(window.getComputedStyle) // DOM
     { return window.getComputedStyle(thisTag, null).getPropertyValue(styleName); }
     else if(thisTag.currentStyle) // IE
     { return thisTag.currentStyle[styleFormatIE(styleName)]; }
   }
 }
 
 function styleFormatIE(oldString)
 {
   newString = oldString;
   found = oldString.match(/(-\S)/gi);
   if (found)
   for (var i = 0; i < found.length; ++i)
   {
     upperChar = found[i].replace(/-/i, "").toUpperCase();
     newString = newString.replace(/(-\S)/i, upperChar);
   }
   return newString;
 }
 
 /** Flippages **/
 var openPage=new Array();
 function getPage(areaNo, pageNo)
 {
   return document.getElementById("page:" + areaNo + ":" + (pageNo));
 }
 
 function showPage(areaNo, pageNo)
 {
   if(getPage(areaNo, pageNo))
   {
     flipPage=getPage(areaNo, pageNo);
     if(flipPage != openPage[areaNo])
     {
       if(openPage[areaNo])
       { 
         openPage[areaNo].className = openPage[areaNo].className.replace(/ show/, ""); 
       }
       else
       {
         for(i=0; getPage(areaNo, i); i++)
         { 
           otherPage=getPage(areaNo, i);
           before = otherPage.className;
           otherPage.className = otherPage.className.replace(/ show/, ""); 
         }
       }
       flipPage.className += " show";
       openPage[areaNo] = flipPage;
     }
   }
 }
 
 
 /* editierbarer Text */
 function editText(thisLink, textName, prefix, suffix)
 {
   if(!prefix)
   { prefix = ""; }
   if(!suffix)
   { suffix = ""; }
   thisText = document.getElementById(textName);
   thisField = document.getElementById(textName.replace(/:/, "field:"));
   thisContent = thisField.value;
   if(thisField.style.display == "block")
   {
     if(thisContent.length > 0)
     { 
       thisText.innerHTML = prefix + parseHTML(thisContent) + suffix; 
       thisLink.innerHTML = thisLink.innerHTML.replace(/Add/, "Edit");
       thisLink.className = "";
     }
     else
     { 
       thisText.innerHTML = ""; 
       thisLink.innerHTML = thisLink.innerHTML.replace(/Edit/, "Add");
       thisLink.className = "opener";
     }
     thisField.style.display = "none";
   }
   else
   {
     thisField.style.display = "block";
     thisLink.className = "closer";
   }
 }
 
 function parseHTML(thisString)
 {
   return thisString.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br />").replace(/"/g, "&quot;");
 }
 
 /* Input Warnings */
 
 function checkMax(thisField, maxVal)
 {
   if(thisField && (isNaN(thisField.value) || thisField.value > maxVal))
   {
     thisField.className = thisField.className.replace(/( |)error/, "") + " error";
     var errorNode = document.createElement("div");
     if(isNaN(thisField.value))
     { errorText = "Invalid entry. Please enter a number only."; }
     else if(thisField.value > maxVal)
     { errorText = "There are only " + maxVal + " items in stock. Please adjust quantity."; }
     errorNode.innerHTML = "<a href=\"#\" onclick=\"closeWarning(this); return false;\">" + errorText + "</a>";
     errorNode.className="error warning";
     closeWarning(thisField);
     thisField.parentNode.appendChild(errorNode);
     errorNode.style.left = (positionLeft(thisField) - Math.round(errorNode.offsetWidth/2) + Math.round(thisField.offsetWidth/2)) + "Px";
   }
   else 
   {
     thisField.className = thisField.className.replace(/( |)error/, "");
     closeWarning(thisField);
   }
 }
 
 function closeWarning(thisTrigger)
 {
   var errorBox;
   divTags = thisTrigger.parentNode.getElementsByTagName("div");
   for(i = 0; i < divTags.length; i++)
   {
     if(divTags[i].className == "error warning")
     { errorBox = divTags[i]; }
   }
   if(!errorBox)
   {
     divTags = thisTrigger.parentNode.parentNode.getElementsByTagName("div");
     for(i = 0; i < divTags.length; i++)
     {
       if(divTags[i].className == "error warning")
       { errorBox = divTags[i]; }
     }
   }
 
   if(errorBox)
   { errorBox.parentNode.removeChild(errorBox); }
 }
 
 /* min/maximize folding table-rows */
 function toggleSub(rowNum, endNum, method)
 {
   if(!endNum)
   { endNum = rowNum; }
   for(rowNum; rowNum <= endNum; rowNum++)
   {
     thisRow = document.getElementById("main:" + rowNum);
     subRow = document.getElementById("sub:" + rowNum);
     subCells = subRow.getElementsByTagName("td");
     thisImg = thisRow.getElementsByTagName("img")[0];
   
     if(method != "close" && (method == "open" || subCells[0].style.display.length == 0 || subCells[0].style.display.search(/none/) > -1))
     { 
       thisRow.className = thisRow.className.replace(/( |)open/, "") + " open";
       
       if(subRow.style.display == "none")
       { subRow.style.display = "block"; }
       
       if(document.all)
       { styleDisplay = "block"; }
       else
       { styleDisplay = "table-cell"; }
       for(i = 0; i < subCells.length; i++)
       {
         if(subCells[i].className.search(/sub/) > -1)
         { subCells[i].style.display = styleDisplay; }
       }
      
       thisImg.src = thisImg.src.replace(/_opener/, "_closer");
     }
     else
     { 
       thisRow.className = thisRow.className.replace(/( |)open/, "");
       
       if(subRow.style.display == "block")
       { subRow.style.display = "none"; }
       
       for(i = 0; i < subCells.length; i++)
       {
         if(subCells[i].className.search(/sub/) > -1)
         { subCells[i].style.display = "none"; }
       }
   
       thisImg.src = thisImg.src.replace(/_closer/, "_opener");
     }
   }
 }
 
 /* select/clear all formfields */
 function selectAll(thisLink)
 {
   toggleAll(thisLink, true);
 }
 
 
 function clearAll(thisLink)
 {
   toggleAll(thisLink, false);
 }
 
 function toggleAll(thisLink, setting)
 {
   thisNode = thisLink.parentNode;
   do {
     thisNode = thisNode.parentNode;
     inputs = thisNode.getElementsByTagName("input");
     options = thisNode.getElementsByTagName("option");
   } while(inputs.length <= 0 && options.lenght <= 0)
   
   for(i = 0; i < inputs.length; i++)
   {
     if(inputs[i].type == "checkbox")
     {
       if(setting)
       { inputs[i].checked = "checked"; }
       else
       { inputs[i].checked = ""; }
     }
   }
   for(i = 0; i < options.length; i++)
   {
     if(setting)
     { options[i].selected = "selected"; }
     else
     { options[i].selected = ""; }
   }
 }
