var xmlHttp
var progress_bar = new Image();
progress_bar.src = '/adm/images/ajax-loader.gif';


var splitIndex = 0;
var splitArray = new Array();


var timerlen = 5;
var slideAniLen = 250;

var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();


function radius(zip,entf){
    var elmo="areaResults";
    //show_progressbar(elmo);
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)    {
        alert ("Your browser does not support AJAX!");
    return;
    } 
    var url="/aj_getRadius_ax.php";
    url=url+"?q="+zip;
    url=url+"&entf="+entf;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}



function doTheCat(lev, cid){
   
 var elmo="cat" + lev;

    //document.forms['form'].thecat.value = cid;
	if (lev==2){
	obj = document.getElementById('sbut');
	obj.style.visibility = "visible";
    obj.style.display = "block";
	}
    if (lev==1){
        document.getElementById('cat2').innerHTML='';
        document.getElementById('cat3').innerHTML='';
    }
    if (lev==2){
        document.getElementById('cat3').innerHTML='';
    }
    
    show_progressbar(elmo);

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
        {
          alert ("Your browser does not support AJAX!");
            return;
        } 
   
    var url="/aj_dothecat_ax.php";
    url=url+"?q="+cid;
    url=url+"&lev="+lev;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }

    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 
function docarmodel(cid){
   
 var elmo="car-model-select";

    //document.forms['form'].thecat.value = cid;
    show_progressbar(elmo);

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
        {
          alert ("Your browser does not support AJAX!");
            return;
        } 
   
    var url="/aj_docarmodel_ax.php";
    url=url+"?q="+cid;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }

    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}
function slideDiv(objname){
        var updown ='down';
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display != "none")
                updown='up'; // cannot slide down something that is already visible

        moving[objname] = true;
        dir[objname] = updown;
        startslide(objname);
}

function slidedown(objname){
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display != "none")
                return; // cannot slide down something that is already visible

        moving[objname] = true;
        dir[objname] = "down";
        startslide(objname);
}

function slideup(objname){
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display == "none")
                return; // cannot slide up something that is already hidden

        moving[objname] = true;
        dir[objname] = "up";
        startslide(objname);
}

function startslide(objname){
        obj[objname] = document.getElementById(objname);

        endHeight[objname] = parseInt(obj[objname].style.height);
        startTime[objname] = (new Date()).getTime();

        if(dir[objname] == "down"){
                obj[objname].style.height = "1px";
        }

        obj[objname].style.display = "block";

        timerID[objname] = setInterval('slidetick(\'' + objname + '\');',timerlen);
}

function slidetick(objname){
        var elapsed = (new Date()).getTime() - startTime[objname];

        if (elapsed > slideAniLen)
                endSlide(objname)
        else {
                var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
                if(dir[objname] == "up")
                        d = endHeight[objname] - d;
                obj[objname].style.height = d + "px";
        }

        return;
}

function endSlide(objname){
        clearInterval(timerID[objname]);

        if(dir[objname] == "up")
                obj[objname].style.display = "none";

        obj[objname].style.height = endHeight[objname] + "px";

        delete(moving[objname]);
        delete(timerID[objname]);
        delete(startTime[objname]);
        delete(endHeight[objname]);
        delete(obj[objname]);
        delete(dir[objname]);

        return;
}




function messageToSeller(iid, intext){
    var elmo="feedBackBox";
    //show_progressbar(elmo);
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)    {
        alert ("Your browser does not support AJAX!");
    return;
    } 
    var url="/aj_messageToSeller_ax.php";
    url=url+"?q=1";
    url=url+"&iid="+iid;
    url=url+"&intext="+intext;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function do_messageToSeller(iid,intext, fb, subj){
    var elmo="feedBackBox";
    //show_progressbar(elmo);
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)    {
        alert ("Your browser does not support AJAX!");
    return;
    } 
    var url="/aj_messageToSeller_do_ax.php";
    url=url+"?q="+iid;
    url=url+"&intext="+intext;
    url=url+"&fb="+fb;
    url=url+"&subj="+subj;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}


function showMessage(mid){
    var elmo="msg"+mid;
    //show_progressbar(elmo);
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)    {
        alert ("Your browser does not support AJAX!");
    return;
    } 
    var url="/aj_showMessage_ax.php";
    url=url+"?q="+mid;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function giveFeedback(){
    var elmo="feedBackBox";
    //show_progressbar(elmo);
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)    {
        alert ("Your browser does not support AJAX!");
    return;
    } 
    var url="/aj_giveFeedback_ax.php";
    url=url+"?q=1";
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 

function do_giveFeedback(name, fb){
    var elmo="feedBackBox";
    //show_progressbar(elmo);
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)    {
        alert ("Your browser does not support AJAX!");
    return;
    } 
    var url="/aj_giveFeedbackDo_ax.php";
    url=url+"?q="+name;
    url=url+"&fb="+fb;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}



function do_comment(elmo, aid, fb){
    
    //show_progressbar(elmo);
  
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)    {
        alert ("Your browser does not support AJAX!");
    return;
    } 
    var url="/aj_commentDo_ax.php";
    url=url+"?q="+aid;
    url=url+"&fb="+fb;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
        document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function splits(string,text) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return;
    if (i == -1) {
        splitArray[splitIndex++] = string;
        return;
    }

    splitArray[splitIndex++] = string.substring(0,i);
    
    if (i+txtLength < strLength)
        splits(string.substring(i+txtLength,strLength),text);

    return;
}



function replace_html(id, content) {
			document.getElementById(id).innerHTML = content;
		}



		
function show_progressbar(id) {
			replace_html(id, '<img src="/adm/images/ajax-loader.gif" border="0" alt="Loading, please wait..." />');
}
        
 
 
function addMerkliste(iid){
    var elmo="merkListeBox";
    show_progressbar(elmo);

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
    alert ("Your browser does not support AJAX!");
    return;
    } 
    var url="/aj_merken_ax.php";
    url=url+"?q="+iid;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState== 4){
    document.getElementById(elmo).innerHTML=xmlHttp.responseText;
    }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}  
 
function doSlide(elem){
	timeToSlide = 150; // in milliseconds
	obj = document.getElementById(elem);
	if(obj.style.display == "none"){ // si c hidden on fait le slide
		obj.style.visibility = "hidden";
		obj.style.display = "block";
		height = obj.offsetHeight;
		obj.style.height="0px";
		obj.style.visibility = "visible";
		pxPerLoop = height/timeToSlide;
		slide(obj,0,height,pxPerLoop);
		
	} else {
	obj.style.display = "none";
	}
}
function slide(obj,offset,full,px){
	if(offset < full){
		obj.style.height = offset+"px";
		offset=offset+px;
		setTimeout((function(){slide(obj,offset,full,px);}),1);
	} else {
		obj.style.height = "auto"; //Can be usefull in updated divs otherwise
//just use full+"px"
	}
}
function showHide(elem){
	obj = document.getElementById(elem);
	if(obj.style.display == "none"){ 
		obj.style.visibility = "visible";
        obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}

}


function stateChanged(elmo){ 
document.getElementById(elmo).innerHTML=xmlHttp.responseText;
document.getElementById("txtNews").innerHTML=elmo;
if (xmlHttp.readyState==4)
{ 
document.getElementById(elmo).innerHTML=xmlHttp.responseText;
//
}
}



function setSession(ses,wert){

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/aj_setsession_ax.php";
url=url+"?q="+ses;
url=url+"&v="+wert;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){

}

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function loadForm(str){
var elmo="post-form-span";
show_progressbar(elmo);

if (str.length==0)
  { 
  document.getElementById(elmo).innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/aj_loadForm_ax.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState== 4){
document.getElementById(elmo).innerHTML=xmlHttp.responseText;
}
}

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function getSec(str){
var elmo="sec";
show_progressbar(elmo);

if (str.length==0)
  { 
  document.getElementById(elmo).innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/aj_checksec_ax.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState== 4){
document.getElementById(elmo).innerHTML=xmlHttp.responseText;
}
}

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function showEmailHint(str){
var elmo="emailok";
show_progressbar(elmo);

if (str.length==0)
  { 
  document.getElementById(elmo).innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/aj_checkemail_ax.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState== 4){
document.getElementById(elmo).innerHTML=xmlHttp.responseText;
}
}

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 


function showLoginHint(str){
var elmo="loginok";
show_progressbar(elmo);

if (str.length==0)
  { 
  document.getElementById(elmo).innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/aj_checklogin_ax.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState== 4){
document.getElementById(elmo).innerHTML=xmlHttp.responseText;
}
}

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 



function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="clogin.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedMEM_H;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function showSearch(str)
{

//show_progressbar("suchspan");

//document.getElementById("txtHint").innerHTML="<img src='http://stats.initzone.com/images/progress.gif' border='0' alt='Loading, please wait...' />";

if (str.length==0)
  { 
  document.getElementById("suchspan").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/aj_search_ax.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedMEM;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 



function stateChangedMEM() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("suchspan").innerHTML=xmlHttp.responseText;
}
}

function stateChangedMEM_H() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
