/*
AJAX Request
© 2008 BENRIC Mediengestaltung
*/

function checkLen(id,zaehler,anzahl) {  
 var maxLen=anzahl;  
 obj=document.getElementById(id); 
 zaehler=document.getElementById(zaehler);  
 if(obj.value.length>maxLen) {  
  obj.value=obj.value.substring(0,maxLen);  
  zaehler.value=0;  
 }else {  
  zaehler.value=maxLen-obj.value.length;  
 }  
}  


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);
 }
}

function showComments(id) {
 if(document.getElementById('faq_comment_'+id).style.display == 'none'){
  allMyPrettyDivs = document.getElementsByTagName('div');
  for(var i = 0; i < allMyPrettyDivs.length; i++){
   divname = allMyPrettyDivs[i].id;
   if(divname.substr(0,11)=="faq_comment"){
    allMyPrettyDivs[i].style.display = 'none';
   }
  }
  document.getElementById('faq_comment_'+id).style.display = 'block';
 }else{
  document.getElementById('faq_comment_'+id).style.display = 'none';
 }
}

function sendComments(faqid){
 
 voting = radioWert(document.forms["rate_faq"+faqid+""].elements["vote"+faqid+""]);
 comment = document.getElementById('comment').value;
 if((voting!=0)||(comment!='')){
 
 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/savecomments.script.php');
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
  xmlHttp.onreadystatechange = function() {
   if(xmlHttp.readyState != 4){
	document.getElementById('faq_comment_'+faqid).innerHTML = 'laden...';
   }else if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
	document.getElementById('faq_comment_'+faqid).style.display = 'block';
	document.getElementById('faq_comment_'+faqid).innerHTML = xmlHttp.responseText;
   }else{
    document.getElementById('faq_comment_'+faqid).innerHTML = 'laden....';
   }
  };
  xmlHttp.send('faqid='+faqid +'&voting='+voting +'&comment='+comment);
 }
 }
}

function radioWert(rObj) {
 for (var i=0; i<rObj.length; i++){
  if (rObj[i].checked){ 	
   return rObj[i].value;
  }
 }
 return 0;
}


