
var QUERYURL=js_server+"json";var LIST="all";var CATEGORY="";var SEARCHT="";var CATEGORY_SIZE=0;var SORT=2;var show;var result;var ALLSELECTED=false;var actPage=0;var pages;var timeout;var recentHash="";function jsonp(url,name,query){if(url.indexOf("?")>-1)
url+="&callback="
else
url+="?callback="
url+=name+"&";if(query)
url+=query+"&";url+=new Date().getTime().toString();var script=document.createElement("script");script.setAttribute("src",url);script.setAttribute("type","text/javascript");document.body.appendChild(script);}
function makeRequest(){recentHash=window.location.hash;if(ALLSELECTED){jsonp(QUERYURL,"cbMovieList","type=movies&list="+LIST+"&sid="+SID+"&search="+SEARCHT+"&cat=&sort="+SORT+"&maxresults=10&firstresult="+actPage*10);}else{jsonp(QUERYURL,"cbMovieList","type=movies&list="+LIST+"&sid="+SID+"&search="+SEARCHT+"&cat="+CATEGORY+"&sort="+SORT+"&maxresults=10&firstresult="+actPage*10);}}
function infoHide(){$(this).find(".infocover").hide();}
function infoShow(){$(this).find(".infocover").show();}
function cbMovieList(movieList){cbSessionStatus(movieList);getSessionData();$("#movies").empty();generatePagination(movieList.count);if(movieList.count==0){$("#main>.content").html("<div class=\"noResults\">"+noResults+"</div>");}else{$("#main>.content").html("<ul class=\"film\"  id =\"movies\"></ul>");max=Math.min(10,movieList.movies.length);for(i=0;i<max;i++){var item=movieList.movies[i];movie=$("#movietemplate").clone();movie.removeAttr("id");movie.find(".foto").attr("src",item.cover);movie.find(".link").attr("href","pelicula/"+item.url+"#"+LIST+","+CATEGORY+","+SEARCHT+","+actPage);movie.find(".title").append("<a href=\"pelicula/"+item.url+"\">"+item.title.substring(0,30)+"</a>");movie.find(".rate").attr("class","rate"+item.rating);movie.find(".cover").attr("id","cover"+item.id);movie.css("display","");if(item.price=="0,00"||item.price=="0.00"){movie.find("#quantity").html(free_var);movie.find(".currency").remove();}else{movie.find("#quantity").html(item.price);}
movie.find("#quantity").attr("id","quantity"+item.id);if(item.directors[0]!=null){movie.find(".director").html(item.directors[0].name);}
for(var j=0;j<2;j++){if(item.actors[j]!=null){movie.find(".actors").append("<li>"+item.actors[j].name+"</li>");}}
movie.find(".sinopsis").append(item.description);movie.find(".age").append("EXP: "+item.exp+" ("+item.age+")");movie.appendTo("#movies");}
$(".infocover").hide();$(".cover").hover(infoShow,infoHide);$(".infocover").click(function(){window.location=$(this).parent().find(".link").attr("href");});}}
function showNumbers(s,e,act){var out="";while(s<=e){var c="";if(s==act){out+="<a id='"+(s-1)+"' class='selectPage actual' href='#"+LIST+","+CATEGORY+","+SEARCHT+","+(s-1)+"'>"+s+"</a>";}else{out+="<a id='"+(s-1)+"' class='selectPage selectOther' href='#"+LIST+","+CATEGORY+","+SEARCHT+","+(s-1)+"'>"+s+"</a>";}
s++;}
return out;}
function showPagination(act,count){var out="";var fsize=2;var lsize=2;var size=11;if(count<size)size=count;var left=size;var fs=1;var fe=fsize;if(fe>count)fe=count;var le=count;var ls=count-lsize+1;if(ls<=fe)ls=fe+1;var left=size-fsize-lsize;var cs=Math.round(act-(left-1)/2);if(cs<=fe)cs=fe+1;var ce=cs+left-1;if(ce>=ls){ce=ls-1;cs=ce-left+1;if(cs<=1)cs=1;}
var fp=false;if(fe+1<cs&&ce>cs){fp=true;cs++;}
var lp=false;if(ce+1<ls&&ce>cs){lp=true;ce--;}
out+=showNumbers(fs,fe,act);if(fp)out+="<span>...</span>";out+=showNumbers(cs,ce,act);if(lp)out+="<span>...</span>";out+=showNumbers(ls,le,act);return out;}
function generatePagination(count){pages=(Math.floor((count-1)/10)+1);$("#pagination").empty().append(showPagination(actPage+1,pages));$(".selectOther").click(function(){actPage=$(this).attr("id");});}
function init(){$("#mapGeneros>ul>li").click(function(){$("#categories>.selected").removeClass("selected");$("#categories>.allSelected").removeClass("allSelected");var selCat=$(this).attr("id");LIST="all";SEARCHT="";$("#searchText").attr("value","");actPage=0;ALLSELECTED=false;CATEGORY=selCat+",";window.location.href="#"+LIST+","+CATEGORY+","+SEARCHT+","+actPage;$("#categories>#"+selCat).addClass("selected");makeRequest();});repopCategories();}
function repopCategories(){$("#CatSelect>option").each(function(i){if($(this).attr("value")==CATEGORY){var title=$('#CatSelect_ms_a_'+i).attr("title");MSDropDown.setRepopSelected('CatSelect_ms',title,'CatSelect_ms_a_'+i,CATEGORY,'undefined');}});}
function repopulate(){URL=unescape(location.href);var xstart=URL.indexOf("#")+1;var xend=URL.length;if(xstart!=0&&xend>xstart){var urlsubstring=URL.substring(xstart,xend);if(urlsubstring=="complete")return;if(urlsubstring=="fail")return;if(urlsubstring=="registrar")return;if(urlsubstring=="ayuda")return;if(urlsubstring=="canjear")return;if(urlsubstring=="login")return;var data=urlsubstring.split(",");LIST=data[0];CATEGORY=data[1];SEARCHT=data[2];actPage=parseInt(data[3]);dynamicTitle();$("#searchText").val(SEARCHT);$("#tabSelect>option").each(function(i){if($(this).attr("value")==LIST){var title=$('#tabSelect_ms_a_'+i).attr("title");MSDropDown.setRepopSelected('tabSelect_ms',title,'tabSelect_ms_a_'+i,LIST,'undefined');}});}}
function dynamicTitle(){var s=title;if(LIST=="all"&&SEARCHT!=""){s+=" - "+SEARCHT;}
else if(LIST=="all"&&SEARCHT==""){s=title;}
else if(LIST=="featured"){s+=" - "+featured_var;}else if(LIST=="new"){s+=" - "+new_var;}else if(LIST=="offers"){s+=" - "+offers_var;}else if(LIST=="views"){s+=" - "+views_var;}else if(LIST=="gratis"){s+=" - "+free_var;}
if(LIST!="all"&&SEARCHT!=""){s+=" - "+SEARCHT;}
$(document).attr("title",s);}
function changeSearch(){if($("#searchText").val().length>2){SEARCHT=$("#searchText").val();actPage=0;window.location.href="#"+LIST+","+CATEGORY+","+SEARCHT+","+actPage;makeRequest();dynamicTitle();}else if(SEARCHT!=""){SEARCHT="";makeRequest();}}
function changeURL(){if(window.location.hash==recentHash){return;}
repopulate();repopCategories();makeRequest();}
function transactionResults(){URL=unescape(location.href);var xstart=URL.indexOf("?")+1;var xend=URL.length;if(xstart!=0&&xend>xstart){var urlsubstring=URL.substring(xstart,xend);var data=urlsubstring.split("&");var param1=data[0];var param2=data[1];if(param1!='undefined'&&param2!='undefined'){var param1array=param1.split("=");var param1name=param1array[0];var param1value=param1array[1];var param2array=param2.split("=");var param2name=param2array[0];var param2value=param2array[1];}}
if(param1name=="show"){if(param1value=="true"){if(param2name=="result")
if(param2value=="ok"){tb_show("","/manta/thank.jsp?KeepThis=true&m=1&maamp;TB_iframe=true&amp;height=125&amp;width=322","");}else{tb_show("","/manta/cancel.jsp?KeepThis=true&amp;TB_iframe=true&amp;height=125&amp;width=322","");}}}}
function OrderChange(){var NEW_SORT=$("#CBorderBy").val();if(SORT!=NEW_SORT){SORT=NEW_SORT;makeRequest();}}
function TabChange(){var NEW_LIST=$("#tabSelect").val();if(LIST!=NEW_LIST){LIST=NEW_LIST;dynamicTitle();actPage=0;window.location.href="#"+LIST+","+CATEGORY+","+SEARCHT+","+actPage;makeRequest();}}
function CatChange(){var NEW_CATEGORY=$("#CatSelect").val();if(NEW_CATEGORY=="catAdult"){tb_show("","util/verify-age/index.php?KeepThis=true&m=1&maamp;TB_iframe=true&amp;height=125&amp;width=720","");}else if(NEW_CATEGORY=="catCine"){window.location.href=nonadultlink;}else{if(CATEGORY!=NEW_CATEGORY){CATEGORY=NEW_CATEGORY;actPage=0;window.location.href="#"+LIST+","+CATEGORY+","+SEARCHT+","+actPage;makeRequest();}}}
function showHelp(){tb_show("","help/index.php?KeepThis=true&m=1&maamp;TB_iframe=true&amp;height=470&amp;width=740","");}
function showComplete() {tb_show("",js_server+"login.jsp?KeepThis=true&m=1&maamp;TB_iframe=true&amp;height=150&amp;width=322","");}
function showDisabled(){tb_show("",js_server+"login_disabled.jsp?KeepThis=true&m=1&maamp;TB_iframe=true&amp;height=150&amp;width=322","");}
$(document).ready(function(){imgLoader=new Image();imgLoader.src=tb_pathToImage;MSDropDown.init("#CBorderBy");setTimeout("refreshSessionStatus();",300000);repopulate();SORT=$("#CBorderBy").val();makeRequest();transactionResults();setInterval(changeURL,200);$("#doSearch").click(function(){SEARCHT=$("#searchText").val();dynamicTitle();actPage=0;window.location.href="#"+LIST+","+CATEGORY+","+SEARCHT+","+actPage;makeRequest();});$("#clearSearch").click(function(){$("#searchText").attr("value","");SEARCHT="";dynamicTitle();actPage=0;window.location.href="#"+LIST+","+CATEGORY+","+SEARCHT+","+actPage;makeRequest();});$("#searchform").submit(function(){return false;});$("#searchText").keyup(function(e){if((e.which&&e.which==13)||(e.keyCode&&e.keyCode==13)){SEARCHT=$("#searchText").val();dynamicTitle();actPage=0;$(this).parent().attr("action","#"+LIST+","+CATEGORY+","+SEARCHT+","+actPage);makeRequest();}
else{if(timeout){clearTimeout(timeout);}
timeout=setTimeout("changeSearch();",200);}});init();if(document.location.href.indexOf("#complete")!=-1)showComplete();else if(document.location.href.indexOf("#fail")!=-1)showDisabled();else if(document.location.href.indexOf("#registrar")!=-1){tb_show("","/manta/createaccount.jsp?KeepThis=true&TB_iframe=true&height=470&width=712","");}
else if(document.location.href.indexOf("registrar")!=-1){tb_show("","/manta/createaccount.jsp?KeepThis=true&TB_iframe=true&height=470&width=712","");}
else if(document.location.href.indexOf("ayuda")!=-1){tb_show("","/help/index.php?KeepThis=true&TB_iframe=true&height=490&width=735","");}
else if(document.location.href.indexOf("canjear")!=-1){tb_show("","/manta/promo.jsp?KeepThis=true&TB_iframe=true&height=150&width=322","");}
else if(document.location.href.indexOf("login")!=-1){tb_show("","/manta/login.jsp?KeepThis=true&TB_iframe=true&height=150&width=322","");}});