
ClShowWait = function() {   
    this.get_win_width = function() {
        var myWidth = 0;
        if( typeof( window.innerWidth ) == 'number' ) //Non-IE
            myWidth = window.innerWidth;
        else if( document.documentElement && document.documentElement.clientWidth ) //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
        else if( document.body && document.body.clientWidth) //IE 4 compatible
            myWidth = document.body.clientWidth;
        return myWidth;
    }
	
    this.get_win_height = function() {
        var myHeight = 0;
        if( typeof( window.innerHeight ) == 'number' ) //Non-IE
            myHeight = window.innerHeight;
        else if( document.documentElement && document.documentElement.clientHeight ) //IE 6+ in 'standards compliant mode'
            myHeight = document.documentElement.clientHeight;
        else if( document.body && document.body.clientHeight) //IE 4 compatible
            myHeight = document.body.clientHeight;
        return myHeight;
    }

    this.get_scrol = function() {
        var yPos = 0;
        if (self.pageYOffset) {
            yPos = self.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollTop){
            yPos = document.documentElement.scrollTop;
        } else if (document.body) {
            yPos = document.body.scrollTop;
        }
        return yPos;
    }

    this.show_box = function() {
        var l = this.get_win_width()/2;
        var t = this.get_win_height()/2 - 50 + this.get_scrol();
        document.getElementById('addok').style.top  = t+'px';
        document.getElementById('addok').style.left = l+'px';
        document.getElementById('addok').style.display='block';	
        setTimeout( "ShowWait.hide_box()", 500);		
    }
	
    this.hide_box = function() {
        document.getElementById('addok').style.display='none';		
    }
}	
var ShowWait =  new ClShowWait();

function AddCart( pid, vid, cnt, res ) {
    ShowWait.show_box();
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {  	
			if (req.responseJS.rq) {
                _v( res ).innerHTML = req.responseJS.rq; 
				_v('basket').className =  ( 0 < req.responseJS.q)  ? 'full' : 'empty';
                _v('cartInfo').innerHTML = req.responseJS.rq1; 	
            }
        }
    }        
    req.caching = false;
    req.open('GET', '/ajax.php', true);
    req.send( {action: "addcart", fm: {pid: pid, vid: vid, cnt: cnt}} );
}

function AddSet( pid, res ) {
    ShowWait.show_box();	
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {      
            if (req.responseJS.rq) {
                _v( res ).innerHTML = req.responseJS.rq; 
				_v('basket').className =  ( 0 < req.responseJS.q)  ? 'full' : 'empty';
                _v('cartInfo').innerHTML = req.responseJS.rq1;			
			}
        }
    }        
    req.caching = false;
    req.open('GET', '/ajax.php', true);
    req.send( {action: "addset", fm: {pid: pid}} );
}

function AddVars( pid, cnt, res )
{
    ShowWait.show_box();
	var fm = new Object();
    var t  = 0;
    for (i = 0; i < cnt; i++) {
        if ( _v('icn'+i).value ) {
            fm[_v('vrn'+i).value] = _v('icn'+i).value;
            t = 1;
        }
    }
    if ( t )
    {
        var req = new JsHttpRequest();
        req.onreadystatechange = function() {
            if (req.readyState == 4) {      
                if (req.responseJS.rq) {
                    _v( res ).innerHTML = req.responseJS.rq; 
                    _v('basket').className =  ( 0 < req.responseJS.q)  ? 'full' : 'empty';
                    _v('cartInfo').innerHTML = req.responseJS.rq1; 
				}
            }
        }        
        req.caching = false;
        req.open('GET', '/ajax.php', true);
        req.send( {action: "addvars", pid: pid, fm: fm} );    
    }
}


function AddPreOrder(pid) {
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {      
            if (req.responseJS.res)
            {
                setcookie('pre_orders[' + pid + ']', 1, req.responseJS.dt_cookie, '/');
                _v('pre_order[' + pid + ']').innerHTML =  'При поступлении товара мы сообщим Вам об этом на E-mail.';
            }
        }
    }        
    req.caching = false;
    req.open('GET', '/', true);
    req.send( {gate: 'ajax', mod: 'orders', action: 'add_pre_order', pid: pid, pre_email: _v('pre_email[' + pid + ']').value} );
}

function Show(img, w, h)
{
    if (!w)
	{
	    w = 100;	
	}
	if (!h)
	{
	    h = 100;	
	}
	window.open( '/galone.php?id='+img,'popup','resizable=1,left=0,top=0, width='+w+', height='+h+', scrollbars=yes'); 	
}
