
opera = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
dom = (document.getElementById)? true : false;
ie4 = (document.all && !dom)? true : false;
nn4 = (document.layers)? true : false;





function getElement(elemId){
    if (dom)
        return document.getElementById(elemId);
    else
        if (ie4)
            return document.all[elemId];
        else
            if (nn4)
                return document.layers[elemId];
    return null;
} 







var fenster; var closed=1;
function windowpopup(popup_name,popup_url,popup_with,popup_height,myWidth,myHeight)
{
if(fenster)
{ if(!closed)
  { fenster.close();
    closed=1;
    fenster=0;
  }
}
   if(!myWidth) {myWidth = 10;}
	if(!myHeight){myHeight = 50;}
	var popup_left = (window.screen.width/2)  - (popup_with/2 + myWidth);
	var popup_top  = (window.screen.height/2) - (popup_height/2 + myHeight);
	var fenster = window.open(popup_url ,popup_name,"toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable=1,width=" + popup_with + ",height=" + popup_height + ",left=" + popup_left + ",top=" + popup_top + ",screenX=" + popup_left + ",screenY=" + popup_top);
	fenster.focus();
}


function divpopup()
{
	popup_left = (document.body.clientWidth/2)  - (200/2)+document.body.scrollLeft;
	popup_top  =  document.body.scrollTop+300;

	getElement('divaddtobag').style.left=popup_left;
	getElement('divaddtobag').style.top=popup_top;
	
	getElement('divaddtobag').style.display='block';
	timer2=setTimeout("closeDivpopup()",10000);
	
}
function closeDivpopup(){
		getElement('divaddtobag').style.display='none';
		clearTimeout(timer2);
}


function addbasket () {
	windowpopup('popupminiwin', '/scripts/miniwin.html', 200,100);
}
function addbasket2 (id) {
	
	divpopup();
	
	var div = 'basket';
	query = 'job=addtov&goods_id=' + id;
	
	var req = new JsHttpRequest();
	req.onreadystatechange = function(){
        if (req.readyState == 4){
            if (req.responseJS) {
            	getElement(div).innerHTML = req.responseJS.q;
            }
			getElement(div).innerHTML = req.responseText;
        }
	}
	req.caching = false;
	req.open('POST', '/includes/shop/addbasket.php', true);
	req.send({ q: query, test:303 });
	
}



function checkLogin () {
	if (document.formlogin.login.value == ''){
		alert('Введите Ваш Логин !'); return false;
	}
	if (document.formlogin.psw.value == '') {
		alert('Введите Ваш Пароль !'); return false;
	}
	else {return true;}
}

var orig_width;
var popup_left = window.screen.width/2;
var popup_top  = window.screen.height/2;

var current;

function showImg(img,id){

	if (current==img.src+'_'+id){
		current='';
		closeShowdiv();
	}
	else{
	
		getElement('divshowimg').style.display='block';
		document.images['showimg'].src=img.src;
		current = img.src+'_'+id;
		
		orig_width=img.width;
		orig_height=img.height;
		gooShowImg(20,orig_width,orig_height);
	}
}

function gooShowImg(i,orig_width,orig_height){

	if (i<=0){
		getElement('catalog_id').style.display='none';
		getElement('brands_id').style.display='none';
		getElement('sort').style.display='none';
		clearTimeout(timer1);
		return false;
	}
	else {
		cur_width = document.images['showimg'].width=parseInt(orig_width/i);
		cur_height = document.images['showimg'].height=parseInt(orig_height/i);
				
		popup_left = (document.body.clientWidth/2)  - (cur_width/2)+document.body.scrollLeft;
		popup_top  = (document.body.clientHeight/2) - (cur_height/2)+document.body.scrollTop;

		getElement('divshowimg').style.left=popup_left;
		getElement('divshowimg').style.top=popup_top;
		
		
		i--;
		timer1=setTimeout("gooShowImg("+i+","+orig_width+","+orig_height+")",10);
		
		
		
	}
}
function gooCloseImg(i,orig_width,orig_height){

	if (i>20){
		getElement('catalog_id').style.display='block';
		getElement('brands_id').style.display='block';
		getElement('sort').style.display='block';
		clearTimeout(timer2);getElement('divshowimg').style.display='none';
		return false;
	}
	else {
		cur_width = document.images['showimg'].width=parseInt(orig_width/i);
		cur_height = document.images['showimg'].height=parseInt(orig_height/i);
		
		popup_left = (document.body.clientWidth/2)  - (cur_width/2)+document.body.scrollLeft;
		popup_top  = (document.body.clientHeight/2) - (cur_height/2)+document.body.scrollTop;

		getElement('divshowimg').style.left=popup_left;
		getElement('divshowimg').style.top=popup_top;

		
		i++;
		timer2=setTimeout("gooCloseImg("+i+","+orig_width+","+orig_height+")",10);
	}
}

function closeShowdiv(){
	clearTimeout(timer1);
	
	gooCloseImg(1,orig_width,orig_height);
	
	
}


lmm = new Image();
lmm.src = "/pictures/-.gif";

lmp = new Image();
lmp.src = "/pictures/+.gif";




function getData(id){
	
	getElement(id).focus();
	getElement(id).select();
	
	therange=getElement(id).createTextRange();
	therange.execCommand("Copy");
	alert('Код скопирован в буфер');
	
}

function showHideDiv(divname){
	if (getElement(divname).style.display=='none'){
		getElement(divname).style.display='block';
		return 1;
	}
	else {
		getElement(divname).style.display='none';
		return 1;
	}

}

/* для Сообщений Тел */
function MakeMessagesTel(query,div){
	
	
	var req = new JsHttpRequest();
	req.onreadystatechange = function(){
        if (req.readyState == 4 && div){
            if (req.responseJS ) {
            	getElement(div).innerHTML = req.responseJS.q;
            }
			getElement(div).innerHTML = req.responseText;
        }
	}
	req.caching = false;
	
	req.open('POST', '/includes/shop/ajax_messagestel.php', true);
	req.send({ q: query, test:303 });
}



