$(document).ready(function(){
	
    $('#sidemenu > dt').mouseover(function() {
    	var sidemenu = $(this);
    	sidemenu.stop().css('background-position', '0 -23px').next('dd:hidden').slideDown('fast').siblings('dd:visible').slideUp('fast');
    	sidemenu.siblings().css('background-position', '0 0');
    });
 
    $('#sbavatars').click(function() { $('#shoutmsgs').hide(); $('#shoutinfo').load('/sbicons').show(); });
    $('#sbsmiles').click(function() { $('#shoutmsgs').hide(); $('#shoutinfo').load('/sbsmiles').show(); });
    $('#sbsmileslist > img').live('click',function(){
    	var shouttext = $("#shoutmsg"); var shoutmsg = shouttext.val().replace(/\s+/, ' ');
    	shoutmsg += ' ' + $(this).attr('alt');
    	shouttext.val(shoutmsg);
    });
    $('#sbiconlist a').live('click', function() { MTaction('sbicon', $(this).html()); showSbMsgs(); return false; });
    $('#sbcolorlist a').live('click', function() { MTaction('sbcolor', $(this).html()); showSbMsgs(); return false; });
    $('#closenoticebox').hover(function() {
        $(this).css('border', '1px solid #fff');
    }, function() {
        $(this).css('border', 'none');
    });
    
    $('#closenoticebox').click(function() { $('#noticebox').slideUp("fast"); });
    
    $('#noticeboxbtn').click(function(){
        $('#noticebox:visible').slideUp("fast");
        $('#noticebox:hidden').slideDown("fast");
        return false;
    });
    
    $('#shoutboxbtn').click(function() {
    	remCookie('sbhide');
     	$('#shoutbox').dialog({ height: 370, width: 600, dialogClass: 'shoutbox', bgiframe: true, title: 'MastiTunes ShoutBox', modal: false, resizable: false, closeOnEscape: false,
	    	close: function(event, ui) { $(this).dialog('destroy'); remCookie('sbleft'); remCookie('sbtop'); setCookie('sbhide', 1);
	    	$('#shoutboxbtn').effect("pulsate", { times:1 }, 300); }, dragStop: function(event, ui) { var pos = $('.shoutbox').offset(); setCookie('sbleft', pos.left); setCookie('sbtop', pos.top); }
     	});
     	var shoutbox = $('.shoutbox');
     	if (!($.browser.msie && /6.0/.test(navigator.userAgent))) {
     		shoutbox.css('position','fixed');
     	}
     	var sbleft = getCookie('sbleft');
     	var sbtop = getCookie('sbtop');
        if (sbleft != null && sbtop != null) {
        	var winheight = $(window).height(); if (winheight-200 <= sbtop) { sbtop = '200'; }
        } else {
        	sbtop = '200'; 
        }
        shoutbox.css({'left' : sbleft + 'px', 'top' : sbtop + 'px'});
        var shoutmsgs = $("#shoutmsgs");
        shoutmsgs.attr({ scrollTop: shoutmsgs.attr("scrollHeight") });
        return false;
    });
    
    $("#shoutmsg").attr("autocomplete", "off").keyup(function(e) { var key = window.event ? e.keyCode : e.which; if (key == 13 || key == 3) { newShout(); return false; }});
    $('#shoutsend').click(function() { newShout(); return false; });
    
    $("#frontusers img").hover(function() {
    	$(this).addClass("hoveravatar");
    }, function() {
    	$(this).removeClass("hoveravatar");
    });
    
    $('#skins > a').click(function() {
    	var s = this.hash.slice(1);
    	var us = $("#userstyle");
    	var s2 = us.attr('href');
    	us.attr({href : s2.substring(0,s2.length - 10) + "style" + s + ".css"});
    	MTaction('style', s);
        return false;
    });

    $('#inlineright').click(function(e) {
        var thisbutton = $(e.target);
        if (thisbutton.is('a')) {
            var song = thisbutton.html();
            if (thisbutton.hasClass('mtaddfav')) {
                thisbutton.addClass("mtloader");
                $.post("/action", { action: 'addfav', song: song }, function(data) {
                    if (data[0].type == 'addfav') {
                        if (data[0].value == 1) {
                            thisbutton.removeClass("mtaddfav").addClass("mtremfav");
                        }
                    }
                    thisbutton.removeClass("mtloader")
                }, "json");
                return false;
            } else if (thisbutton.hasClass('mtremfav')) {
                thisbutton.addClass("mtloader");
                $.post("/action", { action: 'remfav', song: song }, function(data) {
                    if (data[0].type == 'remfav') {
                        if (data[0].value == 1) {
                            thisbutton.removeClass("mtremfav").addClass("mtaddfav");
                            $("#fsong" + song + "").hide("blind", { direction: "vertical" }, 500);
                        }
                    }
                    thisbutton.removeClass("mtloader")
                }, "json");
                return false;
            } else if (thisbutton.hasClass('mtvote')) {
                thisbutton.addClass("mtloader");
                $.post("/action", { action: 'vote', song: song }, function(data) {
                    if (data[0].type == 'success' || data[0].type == 'info') {
                        thisbutton.removeClass("mtvote").addClass("mtunvote");
                        if ($('#publicplaylist').length > 0) { 
        					$('#playlist').load('/playlist');
        				}
                    }
                    MTnotice(data);
                    thisbutton.removeClass("mtloader");
                }, "json");
                return false;
            } else if (thisbutton.hasClass('mtunvote')) {
                thisbutton.addClass("mtloader");
                $.post("/action", { action: 'unvote', song: song }, function(data) {
                    if (data[0].type == 'success' || data[0].type == 'info') {
                        thisbutton.removeClass("mtunvote").addClass("mtvote");
                        if ($('#publicplaylist').length > 0) { 
        					$('#playlist').load('/playlist');
        				} else if ($('#privateplaylist').length > 0) {
        					$("#song" + song + "").hide("blind", { direction: "vertical" }, 500);
        				}
                    }
                    MTnotice(data);
                    thisbutton.removeClass("mtloader");
                }, "json");
                return false;
            } else if (thisbutton.hasClass('mtsample')) {
                $('#toolbox').load('/sample/' + song +'/').dialog({ height: 130, modal: true, closeOnEscape: false, title: 'Song Sample', draggable: false, resizable: false,
                    overlay: { backgroundColor: '#000', opacity: 0.5  }, close: function(event, ui) { $('#toolbox').html(''); $(this).dialog('destroy'); } });
                return false;
            }
        }
    });
   
    $('#inlineright .dice').live('click', function() {
        var song = $(this).html();
            $('#toolbox').load('/rate/' + song +'/').dialog({ width: 350, height: 200, modal: true, closeOnEscape: false, title: 'Rate this song:', draggable: false, resizable: false,
                overlay: { backgroundColor: '#000', opacity: 0.5  },
                buttons: {
                    Cancel: function() { $(this).dialog('destroy'); },
                    'Rate song': function() {
                        var rating = $('#ratesongs input:checked').val();
                        if (typeof(rating) != "undefined") {
                            $.post("/action", { action: 'ratesong', song: song, rating: rating }, function(data) { MTnotice(data); }, "json");
                        };
                        $(this).dialog('destroy');
                    }
                },
                close: function(event, ui) { $('#toolbox').html(''); $(this).dialog('destroy'); }
            });
            return false;
        });

    $('#horoscope img').hover(function() {
        $(this).fadeTo("fast", 0.7);
    }, function() {
        $(this).fadeTo("fast", 1.0);
    });
    
    $('#joined').datepicker({ dateFormat: $.datepicker.ISO_8601, changeMonth: true, changeYear: true, yearRange: "2006:2009", showOn: "button", buttonImage: "../calendar.jpg", buttonImageOnly: true });
    $('#active').datepicker({ dateFormat: $.datepicker.ISO_8601, changeMonth: true, changeYear: true, yearRange: "2006:2009", showOn: "button", buttonImage: "../calendar.jpg", buttonImageOnly: true });

    $('#favfolders .favedit').click(function() {
    	var folderid = $(this).parent().attr('id');
    	var folder = $("#" + folderid + " strong");
    	$('#favfoldername').val('' + folder.html());
    	$('#faveditdialog').dialog({ height: 180, modal: true, closeOnEscape: false, overlay: { backgroundColor: '#000', opacity: 0.5	},
			buttons: {
	    		Cancel: function() { $(this).dialog('destroy'); },
	    		'Change folder name': function() {
		    		var foldername = $('#favfoldername').val();
		    	    if (foldername != null && foldername != '') {
		    	    	$.post("/action", { action: 'editfolder', folder: folderid, name: foldername },
		    	    	        function(data) { 
		    	    	            if (data[0].type == 'editfolder') {
		    	    	                folder.html(''+data[0].value);
		    	    	            }
		    	    	        }, "json");
		    	    };
	    	    	$(this).dialog('destroy');
		    	}
	    	},
	    	close: function(event, ui) { $(this).dialog('destroy'); }
		});
        return false;
    });

    $('#inlineright .favdrag').draggable({helper: 'clone', opacity: '0.80', scroll: 'true', cursor: 'move', revert: true, cursorAt: {top: 25, left: 140}, start: function(e, ui) { 
    	$(ui.helper).addClass('favstartdrag').css('width', '280px'); }
    });
    $('#favfolders .favdrop').droppable({accept: '.favdrag', activeClass: 'favdropactive', hoverClass: 'favdrophover', drop: function(ev, ui) {
    	$(ui.helper).hide();
    	moveFavorite(ui.draggable,this); }
    });
    
    $('#inlineright .favdrag, #privateplaylist2 dl dt').hover(function() {
        $(this).addClass('move');
    }, function() {
        $(this).removeClass('move');
    });
    
    $('#privateplaylist2').sortable({helper: 'clone', opacity: '0.80', scroll: 'true', cursor: 'move', axis: 'y', revert: true, cursorAt: {top: 25, left: 140},
    	start: function(e, ui) { $(ui.helper).addClass('favstartdrag').css('width', '550px'); },
    	update: function(e, ui) { var sortOrder = ''; 
    		$(this).children().each(function(i) { var sortId = $(this).attr('id'); sortOrder += sortId + ','; });
    		sortOrder = sortOrder.replace(/song/g, '').replace(/,$/, '');
    		MTaction('pvtlist', sortOrder);
        }
    });
    
    /* Start */
    $('a.ilink,a.top,a.top2').click(function() {
        var $target = $(this.hash);
        $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
        if ($target.length) {
            var targetOffset = $target.offset().top;
            $('html,body').animate({scrollTop: targetOffset}, 250);
            return false;
        }
    });
    /* End */
   
    $('.mtbutton').hover(function() {
        $(this).addClass('mtbuttonhover');
    }, function() {
        $(this).removeClass('mtbuttonhover');
    });

    if (mTunes == true) {
        oldHeadline = 0;
        timeoutID = setTimeout(mastiTunes, 4000);
        if ($('#pmbtn strong').html() > 0) {
            $('#pmbtn').effect("pulsate", { times:1 }, 300);
        }
        if (getCookie('sbhide') == null) { $('#shoutboxbtn').click(); }
    }
    
    if ($('#totallength').length > 0) {
    	playbarTimer = setTimeout("subtractOne()",1000);
    }
});


function runMarquee() {
    headline = (oldHeadline + 1) % 3;
    $("#nowplaying p").eq(oldHeadline).animate({top: -25},"slow", function() { $(this).css('top', '35px'); });
    $("#nowplaying p").eq(headline).animate({top: 0},"slow"); 
	
	if ($("#frontalbums").length > 0) {
	    $("#frontalbums ul").eq(oldHeadline).animate({top: -150},"slow", function() { $(this).css('top', '170px'); });
	    $("#frontalbums ul").eq(headline).animate({top: 0},"slow"); 
	}
	oldHeadline = headline;
}

function mastiTunes() {
    timeOut = 4000;
    
    sbseq = -1;
    if (getCookie('sbhide') == null) { sbseq = sbSequence; var sbmsgs = $('#shoutmsgs'); }
    plist = -1;
    if(typeof(playList) != 'undefined'){ plist = playList; } 
    var current = 0;
	$.post("/mtunes", { np: nowPlaying, sb: sbseq, pl: plist }, function(data) {
	    $.each(data, function(i,item) {
	        if (item.type == 'nowplaying') {
				$('#nowplaying').html('<p>Song: <a href="/playlist.html" title="Click to see the playlist..">' + item.song + '</a></p><p>Album: <a href="/playlist.html" title="Click to see the playlist..">' + item.artist + '</a></p><p>Requested by: ' + item.requestedby + '</p>');
				$('#nowplaying p').eq(oldHeadline).addClass('active');
				nowPlaying = item.songid;
				timeOut = 2000;
				if ($('#currentsong').length > 0) { 
					$('#currentsong').slideUp('slow').load('/nowplaying').slideDown('slow');
				}
			} else if (item.type == 'sbmsg') {
				sbmsgs.append(item.data);
				sbmsgs.animate({ scrollTop: sbmsgs.attr("scrollHeight") }, 1000);
			} else if (item.type == 'sb') {
				sbSequence = item.data;
			} else if (item.type == 'info') {
				if (item.type2 == 'ntc') {
					MTnotice([item]);
				}
			} else if (item.type == 'clock') {
				$('#clock').html(item.data);
			} else if (item.type == 'plist') {
				if ($('#publicplaylist').length > 0) { 
					$('#playlist').load('/playlist');
				}
			}
		});
		timeoutID = setTimeout(mastiTunes, timeOut);
	}, "json");
	runMarquee();
}


function newShout() {
	var shouttext = $("#shoutmsg"); var shoutmsg = shouttext.val().replace(/\s+/, ' ');	shouttext.val('');
	var sbmsgs = $('#shoutmsgs');
	// Empty message?
	if(shoutmsg.trim() == '') { return false; }
	showSbMsgs();
	$.post("/action", { action: 'newshout', data: shoutmsg }, function(data) { 
		$.each(data, function(i,item) {
			sbmsgs.append(item.value);
			sbmsgs.animate({ scrollTop: sbmsgs.attr("scrollHeight") }, 1000);
		});
	}, "json");
	return false;
}

function showSbMsgs() { 
	$('#shoutinfo').hide();
	var shoutmsgs = $("#shoutmsgs");
	shoutmsgs.show();
    shoutmsgs.attr({ scrollTop: shoutmsgs.attr("scrollHeight") });
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
};

function MTaction(MTaction, MTdata) {
    $.post("/action", { action: MTaction, data: MTdata }, function(data) { MTnotice(data); }, "json");
}

function MTnotice(data) {
    var failed = false;
    
    $.each(data, function(i,item) {
        if (item.type == 'info') {
            $("#notices").prepend('<p class="noticeinfo"><strong>' + item.value + '</strong><br />' + item.value2 + '</p>');
        } else if (item.type == 'error') {
            $("#notices").prepend('<p class="noticeerror"><strong>' + item.value + '</strong><br />' + item.value2 + '</p>');
        } else if (item.type == 'success') {
            $("#notices").prepend('<p class="noticesuccess"><strong>' + item.value + '</strong><br />' + item.value2 + '</p>');
        } else {
            failed = true;
        }
    });
    
    if (!failed) {
        if ($('#notices > p').length > 5) {
    		$('#notices > p:last').remove();
    	}
        $("#notices > .defaultnotice").remove();
        $("#notices > p:first").effect("pulsate", { times:1 }, 300);
    	$('#noticebox').slideDown('fast');
    }
}

function moveFavorite(fav, fold) {
	var favsong = $(fav).attr('id');
	var favfold = $(fold).attr('id');
	var favcount = $("#" + favfold + " span").html();
	var favcountold = $("#favfolders .favopen span").html();
	$.post("/action", { action: 'movefav', song: favsong, folder: favfold }, function(data){ 
	    if (data[0].type == "movefav" && data[0].value == 1) {
	        $('#'+favsong).parent().hide(); 
	        $("#" + favfold + " span").html(''+(parseInt(favcount)+1)); $("#favfolders .favopen span").html(''+(parseInt(favcountold)-1));
	    }
	}, "json");
}

function subtractOne() {
    var clock = $("#timeremaining");
    var time = clock.html().split(":");
    
    var etainfo = $("#etainfo");
    
    if (time[1] <= 0) {
    	--time[0];
    	time[1]=59;
    	if (etainfo.length > 0) { 
			$('#playlist').load('/playlist');
		}
    } else {
    	--time[1];
    }
    
    newValue = (time[0]*60) + time[1];
    var width = Math.round((((playtime - newValue) * 200) / playtime)-200);
    var playbar = $('#playbar > span');
    var height = 0;
    if (width > -45) {
    	height = -40;
    } else if (width > -150) {
    	height = -20;
    }
    playbar.css('background-position', width + 'px ' + height + 'px');

    if (time[1] < 10) {
    	time[1] = '0' + time[1];
    }   
    clock.html(time[0] + ':' + time[1]);
    
    if (etainfo.length > 0) {
    	etainfo.html('ETA:<br/>' + time[0] + ':' + time[1]);
    }

    if (newValue > 0) {
    	playbarTimer = setTimeout("subtractOne()",1000);
    }
}

function openChat() {
    window.open('/openchat.html', 'MastiTunes', 'width=800,height=515,resizable=no');
}

/**
* phpBB3 forum functions
*/

/**
* Window popup
*/
function popup(url, width, height, name) {
	if (!name) {
		name = '_popup';
	}
	window.open(url.replace(/&amp;/g, '&'), name, 'height=' + height + ',resizable=yes,scrollbars=yes, width=' + width);
	return false;
}

/**
* Jump to page
*/
function jumpto() {
	var page = prompt(jump_page, on_page);

	if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) {
		if (base_url.indexOf('?') == -1) {
			document.location.href = base_url + '?start=' + ((page - 1) * per_page);
		} else {
			document.location.href = base_url.replace(/&amp;/g, '&') + '&start=' + ((page - 1) * per_page);
		}
	}
}

/**
* Mark/unmark checklist
* id = ID of parent container, name = name prefix, state = state [true/false]
*/
function marklist(id, name, state) {
	var parent = document.getElementById(id);
	if (!parent) {
		eval('parent = document.' + id);
	}

	if (!parent) {
		return;
	}

	var rb = parent.getElementsByTagName('input');
	
	for (var r = 0; r < rb.length; r++)	{	
		if (rb[r].name.substr(0, name.length) == name) {
			rb[r].checked = state;
		}
	}
}

/**
* Resize viewable area for attached image or topic review panel (possibly others to come)
* e = element
*/
function viewableArea(e, itself) {
	if (!e) return;
	if (!itself) {
		e = e.parentNode;
	}
	if (!e.vaHeight) {
		// Store viewable area height before changing style to auto
		e.vaHeight = e.offsetHeight;
		e.vaMaxHeight = e.style.maxHeight;
		e.style.height = 'auto';
		e.style.maxHeight = 'none';
		e.style.overflow = 'visible';
	} else {
		// Restore viewable area height to the default
		e.style.height = e.vaHeight + 'px';
		e.style.overflow = 'auto';
		e.style.maxHeight = e.vaMaxHeight;
		e.vaHeight = false;
	}
}

/**
* Set display of page element
* s[-1,0,1] = hide,toggle display,show
*/
function dE(n, s) {
	var e = document.getElementById(n);
	if (!s)	{
		s = (e.style.display == '' || e.style.display == 'block') ? -1 : 1;
	}
	e.style.display = (s == 1) ? 'block' : 'none';
}

/**
* Alternate display of subPanels
*/
if (typeof(show_panel) != "undefined") {
	subPanels(show_panel);
}
function subPanels(p) {
	var i, e, t;

	if (typeof(p) == 'string') {
		show_panel = p;
	}

	for (i = 0; i < panels.length; i++) {
		e = document.getElementById(panels[i]);
		t = document.getElementById(panels[i] + '-tab');

		if (e) {
			if (panels[i] == show_panel) {
				e.style.display = 'block';
				if (t) {
					t.className = 'activetab';
				}
			} else {
				e.style.display = 'none';
				if (t) {
					t.className = '';
				}
			}
		}
	}
}
/**
 * Custom dates
 */
if (typeof(date_format) != "undefined" && typeof(default_dateformat) != "undefined") {
	customDates();
}

function customDates() {
	var e = document.getElementById('dateoptions');
	e.selectedIndex = e.length - 1;
	// Loop and match date_format in menu
	for (var i = 0; i < e.length; i++) {
		if (e.options[i].value == date_format) {
			e.selectedIndex = i;
			break;
		}
	}
	// Show/hide custom field
	if (e.selectedIndex == e.length - 1) {
		dE('custom_date',1);
	} else {
		dE('custom_date',-1);
	}
}

/**
* Call print preview
*/
function printPage() {
	if (is_ie) {
		printPreview();
	} else {
		window.print();
	}
}

/**
* Show/hide groups of blocks
* c = CSS style name
* e = checkbox element
* t = toggle dispay state (used to show 'grip-show' image in the profile block when hiding the profiles)
*/
function displayBlocks(c, e, t) {
    var s = (e.checked == true) ?  1 : -1;
    if (t) { s *= -1; }
    var divs = document.getElementsByTagName("DIV");
    for (var d = 0; d < divs.length; d++) {
        if (divs[d].className.indexOf(c) == 0) { divs[d].style.display = (s == 1) ? 'none' : 'block'; }
    }
}

function selectCode(a) {
    // Get ID of code block
    var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];

    // Not IE
    if (window.getSelection) {
        var s = window.getSelection();
        // Safari
        if (s.setBaseAndExtent) {
            s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
        }
        // Firefox and Opera
        else {
            var r = document.createRange();
            r.selectNodeContents(e);
            s.removeAllRanges();
            s.addRange(r);
        }
    }
    // Some older browsers
    else if (document.getSelection)	{
        var s = document.getSelection();
        var r = document.createRange();
        r.selectNodeContents(e);
        s.removeAllRanges();
        s.addRange(r);
    }
    // IE
    else if (document.selection) {
        var r = document.body.createTextRange();
        r.moveToElementText(e);
        r.select();
    }
}

/**
* Play quicktime file by determining it's width/height
* from the displayed rectangle area
*/
function play_qt_file(obj) {
    var rectangle = obj.GetRectangle();
    if (rectangle) {
        rectangle = rectangle.split(',');
        var x1 = parseInt(rectangle[0]);
        var x2 = parseInt(rectangle[2]);
        var y1 = parseInt(rectangle[1]);
        var y2 = parseInt(rectangle[3]);
        var width = (x1 < 0) ? (x1 * -1) + x2 : x2 - x1;
        var height = (y1 < 0) ? (y1 * -1) + y2 : y2 - y1;
    } else {
        var width = 200;
        var height = 0;
    }
    obj.width = width;
    obj.height = height + 16;
    obj.SetControllerVisible(true);
    obj.Play();
}

/**
* Find a member
*/
function find_username(url) {
    popup(url, 760, 570, '_usersearch');
    return false;
}

/**
* Apply onkeypress event for forcing default submit button on ENTER key press
* The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/
* The non-jQuery code is a mimick of the jQuery code ;)
*/
function apply_onkeypress_event()
{
	// jQuery code in case jQuery is used
	if (jquery_present)
	{
		jQuery('form input[type=text], form input[type=password]').live('keypress', function (e)
		{
			var default_button = jQuery(this).parents('form').find('input[type=submit].default-submit-action');
			
			if (!default_button || default_button.length <= 0)
				return true;

			if (phpbb_check_key(e))
				return true;

			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
			{
				default_button.click();
				return false;
			}

			return true;
		});
	
		return;
	}

	var input_tags = document.getElementsByTagName('input');

	for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i])
	{
		if (element.type == 'text' || element.type == 'password')
		{
			// onkeydown is possible too
			element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); };
		}
	}
}

var jquery_present = typeof jQuery == 'function';

/**
* New function for handling multiple calls to window.onload and window.unload by pentapenguin
*/
window.onload = function() {
    for (var i = 0; i < onload_functions.length; i++) {
        eval(onload_functions[i]);
    }
}

window.onunload = function() {
    for (var i = 0; i < onunload_functions.length; i++) {
        eval(onunload_functions[i]);
    }
}

// Cookie functions
function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function remCookie(name) {
    setCookie(name,"",-1);
}
