     var req;
   var reqTimeout;
   var divname='';


   function createRequestObject()
{
    if (window.XMLHttpRequest) {

        try {
            return new XMLHttpRequest();
        } catch (e){}

    } else if (window.ActiveXObject) {
        try {

            return new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){}

        try {
            return new ActiveXObject('Microsoft.XMLHTTP');

        } catch (e){}
    }
    return null;

}

  

function stat(n)
{
  switch (n) {
    case 0:
      return "не инициализирован";
    break;
 
    case 1: 
      return "загрузка...";
    break;
 
    case 2: 
      return "загружено";
    break;
 
    case 3: 
      return "в процессе...";
    break;
 
    case 4: 
      return "готово";
    break;
 
    default:
      return "неизвестное состояние";  
  }  
}

   
   function processreq(){
 //   document.getElementById('state').innerHTML = stat(req.readyState); 
 
 
    if (req.readyState == 4) {
        clearTimeout(reqTimeout);
 
  //      document.getElementById('statusnum').innerHTML = req.status; 
  //      document.getElementById('status').innerHTML = req.statusText; 
 
        // only if "OK"
        if (req.status == 200) {
            document.getElementById(divname).innerHTML=req.responseText;
            divname="";
        } else {
            alert("Не удалось получить данные:\n" + req.statusText);
        }
    }  
   
   }
  
 
   function changeopinion(gid){
   	if(document.getElementById("opinions"+gid).style.display=='none'){
   		loado(gid)
   	}else{
   	  hideo(gid)
    }
   	
   }
   function getfordiv(geturl,divload){
   // alert(divload);
   //	 for(i=0; divname.length>0 && i<5 ;i++){
   	// 	alert('getfordiv '+i);
   	// 	delay(1000);
   	// }
    
    if(divname.length==0){
   	 divname=divload;
   	 httpget(geturl);
    }else{
     setTimeout("getfordiv('"+geturl+"','"+divload+"')",100);
    }
   }
   
   function prparepostdata(plist){
   	ret="";
   	for(i=0;i<plist.length;i++){
   		if(i==0) ret+=plist[i]+'='+encodeURIComponent(document.getElementById(plist[i]).value);
   	  else ret+='&'+plist[i]+'='+encodeURIComponent(document.getElementById(plist[i]).value);
   	}
   	return ret;
   }
   
   function postfordiv(posturl,divload,postdata){
   // alert(postdata);
   //	 for(i=0; divname.length>0 && i<5 ;i++){
   	// 	alert('getfordiv '+i);
   	// 	delay(1000);
   	// }
    
    if(divname.length==0){
   	 divname=divload;
   	 httppost(posturl,postdata);
    }else{
     setTimeout("postfordiv('"+posturl+"','"+divload+"','"+postdata+"')",100);
    }
   }
   
   
   function httpget(geturl){
   	 // Waiting prevision request
   	 
   	 
   	 if(divname.length>0){
      req=createRequestObject();
      if (req) {
        req.onreadystatechange = processreq;
        req.open("GET", geturl, true);
        req.send(null);
        reqTimeout = setTimeout("req.abort();", 5000);
      } else {
        alert("Браузер не поддерживает AJAX");
      }
     }
   	 return req;
   }
   function httppost(posturl,postdata){
   	 // Waiting prevision request
   	 
   	 
   	 if(divname.length>0){
      req=createRequestObject();
      if (req) {
        req.onreadystatechange = processreq;
        req.open("POST", posturl, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf8');
        req.send(postdata);
        reqTimeout = setTimeout("req.abort();", 5000);
      } else {
        alert("Браузер не поддерживает AJAX");
      }
     }
   	 return req;
   }
  
   function hideo(gid){
   	document.getElementById("hideospan"+gid).innerHTML="показать";
   	document.getElementById("opinions"+gid).innerHTML="";
   	document.getElementById("opinions"+gid).style.display="none";
   }
   
   function loado(gid){
    var xmlurl='/goods/opinions_html.php?goods_id='+gid;
    getfordiv(xmlurl,'opinions'+gid);
    if (req) {
        document.getElementById("hideospan"+gid).innerHTML="скрыть";
   	    document.getElementById("opinions"+gid).style.display="block";
    }
    
   }
   
     function descrchange(gid,tp){
    var xmlurl='/goods/descr_html.php?goods_id='+gid+'&type='+tp;
    getfordiv(xmlurl,'descrbody'+gid);
  }

function CartAdd(num){
	v=document.getElementById("sel"+num).value;
	var xmlurl='/editbasket_html.php?goods_id='+num+'&sel='+v;
  getfordiv(xmlurl,'basketinfo');
  y=(document.body.clientHeight - 100)/2;
//  y=y.toFixed(0);
  x=(document.body.clientWidth - 200)/2;
  document.getElementById('basketframe').style.top=document.body.scrollTop+y;
  document.getElementById('basketframe').style.left=document.body.scrollLeft+x;
  document.getElementById('basketframe').style.display='block';
  setTimeout("document.getElementById('basketframe').style.display='none'",2000);	
}
function reloadbasket(rr){
	var xmlurl='/order/basket/basket_html.php?require_related='+rr;
  getfordiv(xmlurl,'baskettable');
  eval("changedmethod()");

	
}



   function sendo(gid){
   	divname='opinions'+gid;
    req=createRequestObject();
    var xmlurl='/goods/opinions_html.php?goods_id='+gid;
    
    if (req) {
        req.onreadystatechange = processreq;
        req.open("POST", xmlurl, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf8');
        if(document.getElementById("raiting"+gid+'_1').checked) r=1;
        if(document.getElementById("raiting"+gid+'_2').checked) r=2;
        if(document.getElementById("raiting"+gid+'_3').checked) r=3;
        if(document.getElementById("raiting"+gid+'_4').checked) r=4;
        if(document.getElementById("raiting"+gid+'_5').checked) r=5;
        reqdata='opiniontext='+encodeURIComponent(document.getElementById("opiniontext"+gid).value)+'&raiting='+r;
     //   alert(reqdata);
        req.send(reqdata);
        reqTimeout = setTimeout("req.abort();", 5000);
        document.getElementById("hideospan"+gid).innerHTML="скрыть";
   	    document.getElementById("opinions"+gid).style.display="block";
    } else {
        alert("Браузер не поддерживает AJAX");
    }
   }
