function Go(link) {
    document.location=link;
	return true;
}

function CGo(link, mesg) {
    if (confirm(mesg)) {
		document.location=link;
		return true;
	}
}

function _v(id)
{
    return document.getElementById(id);
}
function Show(img, num, w, h) {
    if (!w) {
	    w = 100;	
	}
	if (!h) {
	    h = 100;	
	}
	window.open( '/showimg.php?img='+img+'&num='+num,'popup','resizable=1,left=0,top=0, width='+w+', height='+h+', scrollbars=yes'); 	
}

// Cart.js 
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, cnt ) {
    ShowWait.show_box();
	var req = new Subsys_JsHttpRequest_Js();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {  	
			if (req.responseJS.rq) {
                _v( 'carti' ).innerHTML = req.responseJS.rq; 
                _v('cart_content').innerHTML = req.responseJS.q; 
                _v('show_order').style.display = (null != req.responseJS.q2 && 0 < req.responseJS.q2) ? 'block' : 'none';				
                pos = 0;				
            }
        }
    }        
    req.caching = false;
    req.open('GET', '/ajax.php', true);
    req.send( {action: "addcart", fm: {pid: pid, cnt: cnt}} );
}

function UpdCart(pid, cnt) {
    var req = new Subsys_JsHttpRequest_Js();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {      
            if (req.responseJS.rq) {
                _v( 'carti' ).innerHTML = req.responseJS.rq; 
                _v('cart_content').innerHTML = req.responseJS.q;  
                _v('show_order').style.display = (null != req.responseJS.q2 && 0 < req.responseJS.q2) ? 'block' : 'none';
                pos = 0;	
			}
        }
    }        
    req.caching = false;
    req.open('GET', '/ajax.php', true);
    req.send( {action: "editcart", fm: {pid: pid, cnt: cnt}} );
}


function SubmOrder() {
    var req = new Subsys_JsHttpRequest_Js();
    _v('ord_errs').innerHTML = '';
	req.onreadystatechange = function() {
        if (req.readyState == 4) {      
			if ( 0 == req.responseJS.q2 && req.responseJS.rq) {
                _v('ord_errs').innerHTML = req.responseJS.rq;	
			}	

			if ( 1 == req.responseJS.q2 && req.responseJS.rq) {
				_v( 'carti' ).innerHTML = req.responseJS.rq; 
                _v('cart_content').innerHTML = req.responseJS.q; 
				_v('show_order').style.display = 'none';
				adv_cart_done();
			}
        }
    }        
    req.caching = false;
    req.open('GET', '/ajax.php', true);
    req.send( {action: "submorder", fm: { fio:_v('fio').value, phone:_v('phonex').value, city:_v('city').value, indx:_v('indx').value, address:_v('address').value, discount:_v('discount').value, email:_v('email').value, commentary: _v('commentary').value }} );
}


var ar = Array(0, 0, 0, 0);
function Scr( n, wh, id ) {
	if (!n) {
	    nx = ar[id] + 3;
	    if (null != _v(wh+'_'+nx)) {
		    _v(wh+'i_1').innerHTML = (null != _v(wh+'_'+(nx-2))) ? _v(wh+'_'+(nx-2)).innerHTML : '';
		    _v(wh+'i_2').innerHTML = (null != _v(wh+'_'+(nx-1))) ? _v(wh+'_'+(nx-1)).innerHTML : '';
		    _v(wh+'i_3').innerHTML = (null != _v(wh+'_'+nx)) ? _v(wh+'_'+nx).innerHTML : '';

			ar[id] = ar[id] + 1;
		}		
	} else {
	    nx = ar[id] - 1;
	    if ( nx >= 0) {
		    _v(wh+'i_1').innerHTML = (null != _v(wh+'_'+nx)) ? _v(wh+'_'+(nx)).innerHTML : '';
		    _v(wh+'i_2').innerHTML = (null != _v(wh+'_'+(nx+1))) ? _v(wh+'_'+(nx+1)).innerHTML : '';
		    _v(wh+'i_3').innerHTML = (null != _v(wh+'_'+(nx+2))) ? _v(wh+'_'+(nx+2)).innerHTML : '';
			ar[id] = ar[id] - 1;
		}		
	}
}
function ScrStart( wh ) {
    _v(wh+'i_1').innerHTML = (null != _v(wh+'_0')) ? _v(wh+'_0').innerHTML : '';
    _v(wh+'i_2').innerHTML = (null != _v(wh+'_1')) ? _v(wh+'_1').innerHTML : '';
    _v(wh+'i_3').innerHTML = (null != _v(wh+'_2')) ? _v(wh+'_2').innerHTML : '';
}
