var xmlHttp;
var xmlHttp1;
var xmlHttp2;
var forma;
function add2basket(form)
{ 
    //document.getElementById("basketBlock").innerHTML='<div align="center"><img src="images/1-1.gif" /></div>';
    document.getElementById("basketBlock").style.display = 'none';
    document.getElementById("basketBlockLoading").style.display = 'block';
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 

    var url="http://www.simply.lt/index.php?page=add2basketajax";
    url=url+"&sr="+Math.random();
    for(y=0;y<form.elements.length;y++)
	{
		temp=form.elements[y];
        if(temp.name && temp.name!='page'){
            if(temp.type=="checkbox"){
                if(temp.checked==true)
                    url=url+"&"+temp.name+"="+temp.value;
            }else if(temp.type=="radio"){
                if(temp.checked==true)
                    url=url+"&"+temp.name+"="+temp.value;
            }else{
                url=url+"&"+temp.name+"="+temp.value;
            }
        }
	}
    forma = form;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    hs.close();
    return false;
}

function showJustAdded(form)
{ 
    xmlHttp1=GetXmlHttpObject();
    if (xmlHttp1==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 

    var url="http://www.simply.lt/index.php?page=justadded";
    url=url+"&sr="+Math.random();
    for(y=0;y<form.elements.length;y++)
	{
		temp=form.elements[y];
        if(temp.name && temp.name!='page' && temp.name!='command' && temp.name!='component'){
            url=url+"&"+temp.name+"="+temp.value;
        }
	}

    xmlHttp1.onreadystatechange=stateChanged2;
    xmlHttp1.open("GET",url,true);
    xmlHttp1.send(null);
}

function getStock(form)
{ 
    //document.getElementById("basketBlock").innerHTML='<div align="center"><img src="images/1-1.gif" /></div>';
    //document.getElementById("basketBlock").style.display = 'none';
    //document.getElementById("basketBlockLoading").style.display = 'block';
    xmlHttp2=GetXmlHttpObject();
    if (xmlHttp2==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    } 

    var url="http://www.simply.lt/index.php?page=getStockAjax";
    url=url+"&sr="+Math.random();
    for(y=0;y<form.elements.length;y++)
	{
		temp=form.elements[y];
        if(temp.name && temp.name!='page'){

            if(temp.name.match('variantids'))
            {
                url=url+"&"+temp.name+"="+temp.value;
            } else if(temp.name=='productid'){
                url=url+"&"+temp.name+"="+temp.value;
            }
        }
	}

    xmlHttp2.onreadystatechange=stateChangedShowStock;
    xmlHttp2.open("GET",url,true);
    xmlHttp2.send(null);
}

function stateChanged() 
{ 
    if (xmlHttp.readyState==4)
    {
        document.getElementById("basketBlock").innerHTML=xmlHttp.responseText;
        document.getElementById("basketBlock").style.display = 'block';
        document.getElementById("basketBlockLoading").style.display = 'none';
        if(!xmlHttp.responseText.match("ico_error_msg.gif")){
            showJustAdded(forma);
        }
    }
}

function stateChanged2() 
{ 
    if (xmlHttp1.readyState==4)
    { 
        document.getElementById("basketProductBlok").innerHTML=xmlHttp1.responseText;
        $$('div.showhideproduct').each( function(e) { e.visualEffect('slide_down',{duration:1.5}) });
    }
}

function stateChangedShowStock() 
{ 
    if (xmlHttp2.readyState==4)
    {
        document.getElementById("pdamount").innerHTML=xmlHttp2.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;
}
