function makeRequest(url) {

    var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        // Читайте ниже об этой строке
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {

        return false;
    }
    http_request.onreadystatechange = function() {
        alertContents(http_request);
    };
    http_request.open('GET', '/basket.php?'+url, true);
    http_request.send(null);
}

function add2bask() {
    /*alert('?add='+$('#i').attr('value')+'c='+$('#qqq').attr('value'));*/
    makeRequest('add='+$('#i').attr('value')+'&c='+$('#qqq').attr('value'));
    //alert('add='+$('#i').attr('value')+'c='+$('#qqq').attr('value'));
    show_add(false,0);
}


function alertContents(http_request) {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            document.getElementById('basket_div').innerHTML=http_request.responseText;
        }
    }
}


function clientSize() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return {
        width: myWidth,
        height: myHeight
    };
}



function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //FF
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM 
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return {
        x: scrOfX,
        y: scrOfY
    };
}


function getPageHeight() {
    var xScroll, yScroll;
    if(window.innerHeight && window.scrollMaxY){
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }else if(document.body.scrollHeight > document.body.offsetHeight){
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }else{
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if(self.innerHeight){
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }else if(document.documentElement && document.documentElement.clientHeight){
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }else if(document.body){
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    }else{
        pageHeight = yScroll;
    }
    return pageHeight;
} 

function show_call( mode , elem )
{
    obj = document.getElementById('call1');
    if (mode)
    {
 
        document.getElementById('order_main').style.height = getPageHeight()+'px';
        obj.style.top = (getScrollXY().y+100)+'px';//ia 100 ieenaeae ie?a aa?oiae a?aieou eeeaioneie iaeanoe
        obj.style.left = (clientSize().width/2-150)+'px';//ia 200 ieenaeae eaaaa na?aaeiu eeeaioneie iaeanoe
        document.getElementById('order_main').style.display = 'block';
        obj.style.display = 'block';
    }
    else
    {
        obj.style.display = 'none';
        document.getElementById('order_main').style.display = 'none';
    }
}

function show_add( mode, i )
{
    obj = document.getElementById('add1');
    $(obj).find('#i').attr('value', i);
    $('#qqq').attr('value','1');
    if (mode)
    {

        document.getElementById('order_main').style.height = getPageHeight()+'px';
        obj.style.top = (getScrollXY().y+100)+'px';//ia 100 ieenaeae ie?a aa?oiae a?aieou eeeaioneie iaeanoe
        obj.style.left = (clientSize().width/2-150)+'px';//ia 200 ieenaeae eaaaa na?aaeiu eeeaioneie iaeanoe
        document.getElementById('order_main').style.display = 'block';
        obj.style.display = 'block';
    }
    else
    {
        obj.style.display = 'none';
        document.getElementById('order_main').style.display = 'none';
    }
}



function fixPNG(element)
{
    if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
    {
        var src;
		
        if (element.tagName=='IMG')
        {
            if (/\.png$/.test(element.src))
            {
                src = element.src;
                element.src = "i/blank.gif";
            }
        }
        else
        {
            src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
            if (src)
            {
                src = src[1];
                element.runtimeStyle.backgroundImage="none";
            }
        }
		
        if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
    }
}
