var _funcChangePage = 'changePageStd';
var _targetChangePage = '';
var popupWindow = null;

function changePageStd(page)
{
	document.location.href = page;
}

function changePage(page)
{
	eval(_funcChangePage+'(page);');
}

function LUT_refine( doSearch )
{
	var form=window.document.searchForm;
	if( isNaN(doSearch) )
		form.doSearch.value= "";
	else
		form.doSearch.value= doSearch;
	form.submit();
}

function LUT_ddCnt( dd ) // ab neuer suche obsolet 11.09.2008
{
	var txt= "";
	var ddl= dd.length - 1;
	if( ddl > 0 )
	{
		dd.disabled= false;
		txt= "M&ouml;glichkeiten";
		if( ddl == 1 )
		{
			txt= "M&ouml;glichkeit";
			/* dd.selectedIndex= 1; */
		}
		txt= ddl + " " + txt;
	} else
	{
		dd.disabled= true;
		txt= "keine M&ouml;glichkeit";
	}
	document.write("<i>" + txt + "</i>");
}

// ----- search
function searchP(z)
{
	var form=window.document.searchForm;
	form.SearchType.value= "P";
	form.SearchWhatfor.value= z;
	form.submit();
}

function searchMP(z)
{
	var form=window.document.searchForm;
	form.SearchType.value= "MP";
	form.SearchWhatfor.value= z;
	form.submit();
}

// function searchAN()
// {
	// var form=window.document.searchForm;
// 
	// if( form.custartnr.value == ""  )
	// {
		// alert( "Bitte geben Sie eine Artikelnummer ein." );
	// } else
	// {
		// form.SearchType.value= "AN";
		// form.submit();
	// }
// }

// swap search pages
function searchPage( n, t )
{
	var form=window.document.searchForm;
	form.currentSearchPage.value= n;
        if( t == 1 ) form.SearchType.value= "P";
        if (t == 0 ) form.SearchType.value= "MP";
        if (t == "P" ) form.SearchType.value= "P";
        if (t == "MP" ) form.SearchType.value= "MP";
	form.submit();
}

// ---------------------------------------------------------------------------------- AJAX stuff

/* --------------------------------------------------
 * createRequestObject
 * --------------------------------------------------
 *
 * try to create a XMLHttpRequest object
 * based on the browser we are using
 * if something fails this will return FALSE
 *
 * --------------------------------------------------
 */
function createRequestObject()
{
    // branch for native XMLHttpRequest object
    if( window.XMLHttpRequest )
    {
    	try
    	{
			return new XMLHttpRequest();
        } catch( e )
        {
			return false;
        }
    // branch for IE/Windows ActiveX version
    } else if( window.ActiveXObject )
    {
       	try
       	{
        	return new ActiveXObject( "Msxml2.XMLHTTP" );
      	} catch( e )
      	{
        	try
        	{
          		return new ActiveXObject( "Microsoft.XMLHTTP" );
        	} catch( e )
        	{
          		return false;
        	}
		}
    }
}


/* --------------------------------------------------
 * processReqChange
 * --------------------------------------------------
 *
 * handles status change events in the request
 * object
 *
 * --------------------------------------------------
 */
function processRequestChange()
{
    // if state is "loaded"
    if( http.readyState == 4 )
    {
        // and everything is "OK"
        if( http.status == 200 )
        {
			// split response text by ","
			var e = http.responseText.split( "," );

			// get the affected node name
			node= document.getElementById( e[ 1 ] );

			// then process the response data
			if( node )
				node.innerHTML= e[ 2 ] + " Treffer";
        } else
        // if something went wrong we inform the user
        {
//            alert( "There was a problem retrieving the XML data:\n" + http.status + " - " + http.statusText );
        }
    }
}


/* --------------------------------------------------
 * sendRequest
 * --------------------------------------------------
 *
 * try to create a XMLHttpRequest object based on the
 * browser we are using
 * if something fails this will return FALSE
 *
 * --------------------------------------------------
 */
function sendRequest( query, n, l )
{
	// stop transaction if any
	if( http.readyState == 1 )
		http.abort();

	// register function callback for state changes
	http.onreadystatechange= processRequestChange;

	// send request
	url= "index.php?ajax=1&l=" + l + "&t=" + n + "&q=" + query;
	http.open( "GET", url, true );
	http.send( "" );
}


function centeredPopup(url,winName,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable,menubar=no,toolbar=no,location=no,directories=no,status=no'
	popupWindow = window.open(url,winName,settings)
}



/* --------------------------------------------------
 * global stuff
 * --------------------------------------------------
 *
 * initialize the request object
 *
 * --------------------------------------------------
 */
var http= createRequestObject();
if( ! http )
{
	alert( "there was an error initializing the ajax engine" );
}

