/* main scripts */

function isIE(){  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);}

function showid(id) {
 o=document.getElementById(id);
 if (o) o.style.display='block';
}

function hideid(id) {
 o=document.getElementById(id);
 if (o) o.style.display='none';
}

function hidelaptop(theTable)
{
      obj = document.getElementsByTagName('TR');
       for (i=0; i<obj.length; i++)
     {
            if (obj[i].id == theTable)
          obj[i].style.display = 'none';
     }
}
function showlaptop(theTable)
{
     obj = document.getElementsByTagName('TR');
       for (i=0; i<obj.length; i++)
     {
            if (obj[i].id == theTable) {
              if (isIE()) {
                obj[i].style.display = 'block';
              } else obj[i].style.display = 'table-row';
            }

     }
}

/* product info */
function setSelImgDiv(div) {

  obj = document.getElementsByTagName('DIV');
  for (i=0; i<obj.length; i++)  {
     if (obj[i].id == div.id) { 
         //alert(div.style.className);
         obj[i].className='img_curr2';
     }   
  }
  div.className='img_curr';
}

function change_img(img_obj,img_med,img_big,sys_name) {

setSelImgDiv(img_obj);

pa = document.getElementById('product_image_a');

//document.getElementById('product_image_a').href=img_big;
//document.getElementById('product_image').src=img_med;
pa.setAttribute('href',img_big);
document.getElementById('product_image').setAttribute('src',img_med);

if (img_big=='') {
    pa.setAttribute('rel','');    
    pa.removeAttribute('rel');
    pa.removeAttribute('href');
    pa.onclick = "";        
} else { 
    pa.setAttribute('rel','lytebox['+sys_name+']');  
  }
initLytebox();

}



jQuery.fn.centerScreen = function(loaded) { 
	
	if ($.browser.msie) {
		var w = $(window);
		this.css("position","absolute");
		this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
		this.css("left",(w.width()-this.width())/2+w.scrollLeft() + "px");
		return this;
	} else {
		var obj = this; 
		if(!loaded) { 
			obj.css('top', $(window).height()/2-this.height()/2); 
			obj.css('left', $(window).width()/2-this.width()/2); 
			$(window).resize(function() {
				obj.centerScreen(!loaded); 
			}); 
		} else {
			obj.stop(); 
			obj.animate({ top: $(window).height()/2-this.height()/2, left: $(window).width()/2-this.width()/2}, 200, 'linear'); 
		} 
	}
}



var voted=false;
function vote(id,rank){	
	if (voted){
		return false;
	}
	$('#voters').html("<img src=\""+sSiteAbsUrl+"/design/images/loading.gif\" />");
	
	$.get(sSiteAbsUrl+'ajax.php', {
		id		: id,
		rank	: rank
		}, function(result){
			if (result.success){
				$('#rating').width(result.width+'%');
	  			$('#voters').html(result.voters_str);
	  			$('#voters').show();
	  			
	  			voted=true;
	  		} else {
	  			alert(result.msg);
	  		}
		},'json'
	);		
}

function submitComment() {		
	var name = $('#com-name').val();
	if (name.length < 2) {
		alert('Введите имя!');
		return false;
	} 
	
	var text = $('#com-text').val();
	if (text.length < 2) {
		alert('Введите текст!');
		return false;
	} 
	return true;
	
}

function show_window()
	{		
	$('#axcrt').show();
	$('#axcrt').fadeIn(100);
	$('#text').html('Подождите, добавляем в корзину...');	
	$('#axcrt').centerScreen();	
	}

function hide_window()
	{	
	$('#cart-top-loading').hide();
	$('#axcrt').fadeOut(2000);	
	}
	
function set_window_text(text)	{
	$('#text').html('<b>'+text+'</b>');	
}
