function openWin(url, name) {
        var height=0;var width=0;
        if (self.screen) {     // for NN4 and IE4
                  width = screen.width
                  height = screen.height}
        else
        if (self.java) {   // for NN3 with enabled Java
                  var jkit = java.awt.Toolkit.getDefaultToolkit();
                  var scrsize = jkit.getScreenSize();
                  width = scrsize.width;
                  height = scrsize.height; }
        width -=330/1.4;
        height-=150/2;
        openNew = window.open(url, name, 'width=330,height=150,resize=no,resizable=no,scroll=no,scrollbars=no,location=no,toolbar=no,menubar=no,status=no,left='+width/2+',top='+height/2);
        openNew.focus();
}

function NewWindow(mypage,myname,w,h,scroll,pos)
{
	if(pos=="center"){LeftPosition=(screen.availWidth)?(screen.availWidth-w)/2:50;TopPosition=(screen.availHeight)?(screen.availHeight-h)/2:50;}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	mypage+= (mypage.search(/\/action/)>0 ? '/frame/single' : '&frame=single');
	win=window.open(mypage,myname,settings);
	if(win.focus){win.focus();}
        return false;
}

function rent_film(film_id, obj) {
    if ( (loadTime + 1200 * 1000) < (new Date().getTime()) ) {
        alert('Your session may have timed out. Please refresh the page, and try again.');
        return;
    }

    if (films_rest <=0) {
        alert('Your rental queue is full');
        return;
    }

    // A little entropy to ensure no caching takes place
    var date    = new Date();
    var entropy = String(date.getHours()) + String(date.getMinutes()) + String(date.getSeconds()) + String(date.getMilliseconds());


    obj.old={};
    obj.old.innerHTML = obj.innerHTML;
    obj.old.onclick = obj.onclick;
    obj.onclick = '';
    obj.innerHTML = 'AGREGANDO&hellip;'; //adding...

    var receiver = new Image();
    receiver.onload = function() {
        clearTimeout(waiter);
        films_rest--;
        obj.onclick = '';
        obj.style.cursor = 'default';
        obj.innerHTML = 'Agregada'; // added
        obj.style.backgroundImage = 'url("/images/rent_buttons/norent.png")';
    }
    receiver.src = '/index.php?action=content/rent&film_id=' + film_id +'&r='+entropy;

    waiter = setTimeout(function() {
        obj.onclick = obj.old.onclick;
        obj.innerHTML = obj.old.innerHTML;
    } , 10000);
}

function rate_film(film_id, rating) {
    for (var i=1;i<=5;i++) document.getElementById('r_'+film_id+'_'+i).src='/images/ratings/star'+ ((i<=rating)?'1':'0')+'.gif';
    var i=new Image();
    i.src='/index.php?action=content/vote&film_id='+film_id+'&vote='+rating;
}

// Write a cookie value
function setCookie(name, value, expires, path, domain, secure) {
   var curCookie = name + '=' + escape(value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
   document.cookie = curCookie;
}


// Retrieve a named cookie value
function getCookie(name) {
   var dc = document.cookie;

   // find beginning of cookie value in document.cookie
   var prefix = name + "=";
   var begin = dc.indexOf("; " + prefix);
   if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
   }
   else begin += 2;

   // find end of cookie value
   var end = document.cookie.indexOf(";", begin);
   if (end == -1) end = dc.length;

   // return cookie value
   return unescape(dc.substring(begin + prefix.length, end));
}


// Delete a named cookie value
function deleteCookie(name, path, domain) {
   var value = getCookie(name);
   if (value != null) document.cookie = name + '=' + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
   return value;
}

// Test for cookie support
function supportsCookies(rootPath) {
   setCookie('checking_for_cookie_support', 'testing123', '', (rootPath != null ? rootPath : ''));
   if (getCookie('checking_for_cookie_support')) return true;
   else return false;
}

function check_user_cookies() {
    if (supportsCookies()) return true;
    alert(err_msg);
    return false;
}

$(function() {
    $('div.buy_button')
        .mouseover(function() {
            window.clearTimeout(this.timer);
            if (this.active != true)
            {
                $(this).children('.dropdown').slideDown();
                this.active = true;
            }
        })
        .mouseout(function() {
            var box = $(this).children('.dropdown');
            var _parent = this;

            this.timer = window.setTimeout(function() {
                _parent.active = false;
                box.slideUp()
            }, 0.5 * 1000);
        });
    $('div.dropdown > div')
        .mouseover(function() {
            $(this).addClass('dropdown_item_over');
        })
        .mouseout(function() {
            $(this).removeClass('dropdown_item_over');
        })

    $('div.toggle_box > a').click(function() {
        $(this).next().toggle();
        return false;
    });
});
