//////////////////////// cookies for date and resolution /////////////////////

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

var dat = new Date();
var res = screen.width+'x'+screen.height;

$.cookie("userTime", dat.getTime(), { expires: 7, path: '/' });
$.cookie("userRes", res, { expires: 7, path: '/' });
//////////////////////// cookies for date and resolution /////////////////////



var chDiv = '';

$(function() {
	$('.previewImg a').lightBox({fixedNavigation:true});
});

$(function() {
	$('.previewCert a').lightBox({fixedNavigation:true});
});


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');
}

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 mainmenu(){
$("#nav ul").css({display: "none"}); // Opera Fix
$("#nav li").hover(function()
{
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn('slow');
		},function()
		{
			//$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeOut('slow');
			$(this).find('ul:first').fadeOut('slow');
		});
}

 $(document).ready(function(){					
	mainmenu();
});
 */
 
    $(document).ready(function() {
      
      function addMega(){
        $(this).addClass("hovering");
        }

      function removeMega(){
        $(this).removeClass("hovering");
        }

    var megaConfig = {
         interval: 100,
         sensitivity: 3,
         over: addMega,
         timeout: 500,
         out: removeMega
    };

    $("li.subMenu").hoverIntent(megaConfig)

      
    });

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 swLog() 
{ 
	if(document.getElementById("sq"))  jQuery("#sq").toggle('blind');
	
	var pTag1 = document.getElementById("user");

	if(pTag1.className.match("expMenu"))
	{
		document.getElementById("user").className = ""; 
	}
	else
	{
		document.getElementById("user").className = "expMenu"; 
	}
	
}

function chkUser()
{
	var pTag1 = document.getElementById("user");
	if(pTag1.className.match("expMenu"))
	{
		if(document.getElementById("sq"))  jQuery("#sq").toggle('slow');
		document.getElementById("user").className = ""; 
	}
}

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 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);
*/

