/*
AJAX Request
© 2008 BENRIC Mediengestaltung
*/

function sendRequest(prdgrp, lang){
 var xmlHttp = null;
 try {
  // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
  xmlHttp = new XMLHttpRequest();
 }catch(e){
  try{
   // MS Internet Explorer (ab v6)
   xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
  }catch(e){
   try{
    // MS Internet Explorer (ab v5)
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
   }catch(e){
    xmlHttp  = null;
   }
  }
 }

 if(xmlHttp){
  xmlHttp.open('POST', '/scripts/ajax/answerrequest.script.php');
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  
  document.getElementById('setcatchoise').innerHTML = '';
  document.getElementById('setsparechoise').innerHTML = '';
  
  xmlHttp.onreadystatechange = function() {
   if(xmlHttp.readyState != 4){	
	document.getElementById('setgrpchoise').innerHTML = '<img src="/style/images/layout/ajax-loader.gif" align="center" style="margin-top:15px;" alt="ladebalken" />';
   }else if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) { 
    document.getElementById('setgrpchoise').innerHTML = xmlHttp.responseText;
   }else{
    document.getElementById('setgrpchoise').innerHTML = '<img src="/style/images/layout/ajax-loader.gif" align="center" style="margin-top:15px;" alt="ladebalken" />';
   }
  };
  xmlHttp.send('id='+prdgrp +'&lang='+lang);
 }
}

function sendPrdRequest(prdcat, lang){
 var xmlHttp = null;
 try {
  // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
  xmlHttp = new XMLHttpRequest();
 }catch(e){
  try{
   // MS Internet Explorer (ab v6)
   xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
  }catch(e){
   try{
    // MS Internet Explorer (ab v5)
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
   }catch(e){
    xmlHttp  = null;
   }
  }
 }

 if(xmlHttp){
  xmlHttp.open('POST', '/scripts/ajax/answerrequest.script.php');
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  
  document.getElementById('setsparechoise').innerHTML = '';
  
  xmlHttp.onreadystatechange = function() {
   if(xmlHttp.readyState != 4){
	document.getElementById('setcatchoise').innerHTML = '<img src="/style/images/layout/ajax-loader.gif" align="center" style="margin-top:15px;" alt="ladebalken" />';
   }else if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) { 
    document.getElementById('setcatchoise').innerHTML = xmlHttp.responseText;
   }else{
    document.getElementById('setcatchoise').innerHTML = '<img src="/style/images/layout/ajax-loader.gif" align="center" style="margin-top:15px;" alt="ladebalken" />';
   }
  };
  xmlHttp.send('prdcat='+prdcat +'&lang='+lang);
 }
}

function sendSpareRequest(prdid, lang){
 var xmlHttp = null;
 try {
  // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
  xmlHttp = new XMLHttpRequest();
 }catch(e){
  try{
   // MS Internet Explorer (ab v6)
   xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
  }catch(e){
   try{
    // MS Internet Explorer (ab v5)
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
   }catch(e){
    xmlHttp  = null;
   }
  }
 }

 if(xmlHttp){
  xmlHttp.open('POST', '/scripts/ajax/answerrequest.script.php');
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  
  
  xmlHttp.onreadystatechange = function() {
   if(xmlHttp.readyState != 4){
	document.getElementById('setsparechoise').innerHTML = '<img src="/style/images/layout/ajax-loader.gif" align="center" style="margin-top:15px;" alt="ladebalken" />';
   }else if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
	   if(prdid!='#30FF'){
	    window.location.href=prdid;
	   }else{
         document.getElementById('setsparechoise').innerHTML = xmlHttp.responseText;
	   }
   }else{
    document.getElementById('setsparechoise').innerHTML = '<img src="/style/images/layout/ajax-loader.gif" align="center" style="margin-top:15px;" alt="ladebalken" />';
   }
  };
  xmlHttp.send('prdid='+prdid +'&lang='+lang);
 }
}

/*
Live Search Productspares
*/

var searchTimeout;
var lastQuery;
var minSearchStringLength = 3;

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
};

function sendSparesLiveRequest(lang) {
	document.getElementById('searchsparesresult').style.display = "none";
	window.clearTimeout(searchTimeout);
	searchTimeout = window.setTimeout("clearSparesSearchString(document.getElementById('searchsparesoption').value, '"+lang+"')", 500);
}

function clearSparesSearchString( q, lang ) {
	document.getElementById('searchsparesresult').style.display = "none";
	var q = q.trim();  // entfernt irrelevante Leerzeichen am Anfang und Ende
	if( q.length >= minSearchStringLength && lastQuery != q ) {
		requestSparesLivesearch(q, lang);
		;
	}	
	lastQuery = q;
}

function requestSparesLivesearch(value, lang){
 var xmlHttp = null;
 try {
  // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
  xmlHttp = new XMLHttpRequest();
 }catch(e){
  try{
   // MS Internet Explorer (ab v6)
   xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
  }catch(e){
   try{
    // MS Internet Explorer (ab v5)
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
   }catch(e){
    xmlHttp  = null;
   }
  }
 }

 if(xmlHttp){
  xmlHttp.open('POST', '/scripts/ajax/livesearch.script.php');
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  
  document.getElementById('searchsparesresult').style.display = "none";
  
  xmlHttp.onreadystatechange = function() {
   if(xmlHttp.readyState != 4){
	document.getElementById('searchsparesresult').innerHTML = '<img src="/style/images/layout/ajax-loader.gif" align="center" style="margin-top:15px;" alt="ladebalken" />';
   }else if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
	document.getElementById('searchsparesresult').style.display = "block";
	document.getElementById('searchsparesresult').innerHTML = xmlHttp.responseText;
   }else{
    document.getElementById('searchsparesresult').innerHTML = '<img src="/style/images/layout/ajax-loader.gif" align="center" style="margin-top:15px;" alt="ladebalken" />';
   }
  };
  xmlHttp.send('value='+value +'&lang='+lang);
 }
}
