
var chDiv = '';

function addToCart(prod)
{
		
		//alert('qty'+prod);
		var lan = 'bg';
		var qty = document.getElementById('qty'+prod).value;
		
		if(qty == '' || isNaN(qty)) {var qty = 1};
		
		var cartUrl = siteUrl+'scart.php?lan='+lan+'&prod='+prod+'&qty='+qty+'&rand=';
			
		showConts(cartUrl, 'inCart');
		
		//alert(cartUrl);
		
		jQuery.facebox({ ajax: ''+siteUrl+'addedtocart.php' })

}


function bNodes (to,p) 
{

  var myForm = document.createElement("form"); 
  myForm.setAttribute("method","post"); 
  myForm.setAttribute("action",to); 
  myForm.setAttribute("name","sNodes"); 
  myForm.setAttribute("id","sNodes"); 
  
  //var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
  // http://www.thefutureoftheweb.com/blog/detect-ie6-in-javascript

  for (var k in p) 
  {
		var myInput = document.createElement("input") ;
		myInput.setAttribute("id", k+'1') ;
		myInput.setAttribute("name", k) ;
		myInput.setAttribute("value", p[k]);
		myForm.appendChild(myInput) ;
  }
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
  
}

function onlyNumbers(evt)
{
	var e = event || evt; // for trans-browser compatibility
	var charCode = e.which || e.keyCode;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;
	
}

function swOrders(id)
{
		var oClas = document.getElementById("ord"+id);
	
		if(oClas.className.match("toggleOpen"))
		{
			document.getElementById("ord"+id).className = "toggleClose"; 
			if(document.getElementById("ahr"+id)) document.getElementById("ahr"+id).className = "hide";
			//jQuery("#lst"+id).show();
		}
		else
		{
			document.getElementById("ord"+id).className = "toggleOpen"; 
			if(document.getElementById("ahr"+id)) document.getElementById("ahr"+id).className = "del";
			//jQuery("#lst"+id).hide();
		}
		
		jQuery("#lst"+id).slideToggle('normal');

}

function initMenus(id) 
{
	$('#ordersList .toggleContent').hide();	
}

function savePrint(calid, elurl)
{
	if(document.getElementById("prSave"+calid)) 
	{
		document.getElementById("prSave"+calid).className = "hide";
		//jQuery("prSave"+calid).fadeOut(100);
		//alert(elurl);
	}
	deletit = getHTTPObject();
	if (deletit==null)
	 {
		 alert (brwsr);
		 return;
	 } 
	deletit.onreadystatechange = function() {chckFade(calid);};
	deletit.open("GET",elurl,true);
	deletit.send(null);
	
}

function swTypes() 
{ 
		
	var pTag1 = document.getElementById("tabLaser");

	if(pTag1.className.match("current"))
	{
		document.getElementById("tabLaser").className = ""; 
		document.getElementById("tabInkJet").className = "current"; 
		//jQuery("#listInkJet").fadeIn("fast");
		document.getElementById("listInkJet").style.display='block'; 
		document.getElementById("listlaser").style.display='none'; 
	}
	else
	{
		document.getElementById("tabLaser").className = "current"; 
		document.getElementById("tabInkJet").className = ""; 
		//jQuery("#listlaser").fadeOut("fast");
		document.getElementById("listInkJet").style.display='none'; 
		document.getElementById("listlaser").style.display='block'; 
	}
	
}


function WinOpen(url)
{
	window.open(url,"Window" + Math.round(Math.random()*10000)+1,'scrollbars=yes,width=600,height=400,left=200,top=100,resizable=yes');
}

/////////////////////////////////////////// menus //////////////////////////////////////

/*
var blob = {
	
	
	init : function() {
		blob.nav = jQuery('#mainNav ul');
		blob.links = jQuery('#mainNav ul li');
		blob.current = jQuery('#mainNav ul .current');
		if( blob.current.length == 0 )
			blob.current = jQuery('#mainNav a:first').addClass('current');
		blob.currID = blob.current.parent().attr('id');
		blob.slider = jQuery('<li class="back"><div class="left"></div></li>').appendTo(blob.nav);
		jQuery(blob.links).hover(blob.move,blob.goback);
		jQuery(blob.current).each(blob.move);
	},
	move : function() {
		jQuery(blob.slider).stop().animate({ width:this.offsetWidth, left:this.offsetLeft}, 'fast');
	//	$(blob.slider).animate({ width:this.offsetWidth, left:this.offsetLeft}, 'fast');
		blob.timer = clearTimeout(blob.timer);
	},
	goback : function() { blob.timer = setTimeout( blob.moveback, 500 ); },
	moveback : function() {
		var e = document.getElementById(blob.currID);
		jQuery(blob.slider).animate({ width:e.offsetWidth, left:e.offsetLeft}, 'fast');
	}
}
jQuery(document).ready(blob.init);
*/
/////////////////////////////////////////// menus //////////////////////////////////////

function getHTTPObject() 
{
  var xhr = false;
  if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } 
  else if (window.ActiveXObject) 
  {
    try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } 
	catch(e) 
	{
      try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } 
	  catch(e) 
	  {
        xhr = false;
      }
    }
  }
  return xhr;
}

var xmlHttp

function showConts(mkereq, chDiv)
{ 
	xmlHttp=getHTTPObject(); 
	//alert(chDiv);
	if(chDiv == null) { var chDiv = 'content';  }
	//alert(chDiv);
	if (xmlHttp==null)
	 {
		 alert (brwsr);
		 return;
	 }
	var url=mkereq;
	url=url+"/"+Math.random();
	xmlHttp.onreadystatechange = function() {stateChanged(chDiv);};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	if(document.getElementById("apploading")) { document.getElementById("apploading").className = ""; }
}




function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	} 
	else 
	{
		window.onload = function() 
		{
			oldonload();
			func();
		}
	}
}

function stateChanged(chDiv) 
{ 
  if (xmlHttp.readyState == 4) 
  {
    if (xmlHttp.status == 200 || xmlHttp.status == 304) 
	{
	  document.getElementById(chDiv).innerHTML=xmlHttp.responseText; 
    }
  }	 
}

function chckFade(eid) 
{ 
  if (deletit.readyState == 4) 
  {
    if (deletit.status == 200 || deletit.status == 304) 
	{
		if(document.getElementById("prSaved"+eid)) 
		{ 
			document.getElementById("prSaved"+eid).className = "grn"; 
			alert(prSavedTxt);
		}
    }
  }	 
}

/*
$(function () {
    $('ul.spy').simpleSpy().bind('mouseenter', function () {
        $(this).trigger('stop');
    }).bind('mouseleave', function () {
        $(this).trigger('start');
    });
});

(function ($) {
    
$.fn.simpleSpy = function (limit, interval) {
    limit = limit || 3;
    interval = interval || 8000;
    
    function getSpyItem($source) {
        var $items = $source.find('> li');
        
        if ($items.length == 1) {
            // do an hit to get some more
            $source.load(siteUrl+'nprinters.php');
        } else if ($items.length == 0) {
            return false;
        }
        
        // grab the first item, and remove it from the $source
        return $items.filter(':first').remove();
    }
    
    return this.each(function () {
        // 1. setup
            // capture a cache of all the list items
            // chomp the list down to limit li elements
        var $list = $(this),
            running = true,
            height = $list.find('> li:first').height();
            
        // TODO create the $source element....
        var $source = $('<ul />').hide().appendTo('body');
                    
        $list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit });
        
        $list.find('> li').filter(':gt(' + (limit - 1) + ')').appendTo($source);

        $list.bind('stop', function () {
            running = false;
        }).bind('start', function () {
            running = true;
        });

        // 2. effect
        function spy() {
            if (running) {
                var $item = getSpyItem($source);

                if ($item != false) {
                    // insert a new item with opacity and height of zero
                    var $insert = $item.css({
                        height : 0,
                        opacity : 0,
                        display : 'none'
                    }).prependTo($list);

                    // fade the LAST item out
                    $list.find('> li:last').animate({ opacity : 0}, 1000, function () {
                        // increase the height of the NEW first item
                        $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);

                        // AND at the same time - decrease the height of the LAST item
                        // $(this).animate({ height : 0 }, 1000, function () {
                            // finally fade the first item in (and we can remove the last)
                            $(this).remove();
                        // });
                    });             
                }                
            }
            
            setTimeout(spy, interval);
        }
        
        spy();
    });
};
    
})(jQuery);
*/
