//AJAX 
function getXmlHttp(){
	var xmlhttp
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e1) {
      			xmlhttp = false;
		}
	}
	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}

function show_ajax(cloth_id, producer_id, type_id, page, search_word, season_id, ss, pp, tt) {
    // создать объект для запроса к серверу
    var req = getXmlHttp()  
 
    // задать адрес подключения
    req.open('POST', 'show_ajax.php', true);  
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

    // div под мелкими превьюшками
    // в нем будем отображать ход выполнения
    var statusElem = document.getElementById('here_block_ajax') 
 
    req.onreadystatechange = function() {  
        // onreadystatechange активируется при получении ответа сервера
         if (req.readyState == 4) { 
            // если запрос закончил выполняться
            statusElem.innerHTML = req.statusText // показать статус (Not Found, ОК..)
            if(req.status == 200) { 
                //если статус 200 (ОК) - выдать ответ пользователю
                //alert("Ответ сервера: "+req.responseText);
				statusElem.innerHTML = req.responseText
            }else if(req.status == 404){
            	// обработка ошибок запроса
				statusElem.innerHTML = 'No such file... Sorry...'
			}
        }
    }
 
//	window.location.pathname = "/offers.php?page="+page+"&cloth_id="+cloth_id+"&producer_id="+producer_id+"&type_id="+type_id+"&search_word="+search_word+"&season_id="+season_id;
//	var adrstr = "/offers.php%3Fpage="+page;
	var adrstr = "?page="+page;
	if(cloth_id) adrstr = adrstr+"&cloth_id="+cloth_id;
	if(search_word) adrstr = adrstr+"&search_word="+search_word;

	//seasons
	if(!strstr(ss, "|"+season_id+"|")) ss = ss+season_id+"|";
	else {
		sarr = ss.split("|"+season_id+"|");
		ss = sarr[0]+'|'+sarr[1];
		//alert(ss);
	}
	if(ss == "|" || ss == "||" || ss == "|undefined|") ss = "";
	if(ss) adrstr = adrstr+"&ss="+ss;

	//if(producer_id) adrstr = adrstr+"&producer_id="+producer_id;
	//producers
	if(!strstr(pp, "|"+producer_id+"|")) pp = pp+producer_id+"|";
	else {
		parr = pp.split("|"+producer_id+"|");
		pp = parr[0]+"|"+parr[1];
		//alert(ss);
	}
	if(pp == "|" || pp == "||" || pp == "|undefined|") pp = "";
	if(pp) adrstr = adrstr+"&pp="+pp;

	//if(type_id) adrstr = adrstr+"&type_id="+type_id;
	//types
	if(!strstr(tt, "|"+type_id+"|")) tt = tt+type_id+"|";
	else {
		tarr = tt.split("|"+type_id+"|");
		tt = tarr[0]+"|"+tarr[1];
		//alert(ss);
	}
	if(tt == "|" || tt == "||" || tt == "|undefined|") tt = "";
	if(tt) adrstr = adrstr+"&tt="+tt;

//alert(adrstr);
	window.location.href = "http://www.lengri.com/offers.php"+adrstr;

    // объект запроса подготовлен: указан адрес и создана функция onreadystatechange
    // для обработки ответа сервера
    req.send("cloth_id="+cloth_id+"&producer_id="+producer_id+"&type_id="+type_id+"&page="+page+"&search_word="+search_word+"&season_id="+season_id);  // отослать запрос
	statusElem.innerHTML = '<p align="center">Пожалуйста, подождите несколько секунд...</p>'; 
}

function strstr( haystack, needle, bool ) {	// Find first occurrence of a string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	var pos = 0;

	pos = haystack.indexOf( needle );
	if( pos == -1 ){
		return false;
	} else{
		if( bool ){
			return haystack.substr( 0, pos );
		} else{
			return haystack.slice( pos );
		}
	}
}

