// impresa selects
(function($){$.fn.impresa=function(){this.click(function(){var select=$(this).prev()[0];var index=select.selectedIndex;var value=select.options[index].getAttribute('value')||'';if(value&&value!==''&&value!==null)
document.location.href=value;return false;});return this;};})(jQuery);

// impresa editor
(function($){$.fn.editor=function(){var $this=this;var $link=$this.find('a:first');var href=$link.attr('href');var text=$link.text();$this.wrapInner('<a href="'+href+'" title="'+text+'" style="cursor:pointer"></a>');return this;};})(jQuery);

// ec.options
(function($){$.fn.opts=function(){return this.each(function(){$('.print',this).click(function(){window.print();return false;});$('.sendMail',this).click(function(){$(this).next().stop().animate({height:'toggle',opacity:'toggle'},'fast')
return false;}).next().each(function(){var $this=$(this);if($this.attr('action')=='#'){$this.attr('action','http://www.elcomercio.com.pe/ediciononline/macro/recomienda.asp').html(['<input type="hidden" name="pag" value="http://www.elcomercio.com.pe/" id="some_name" /> ','<input type="text" name="nombre1" value="Tu nombre" /> ','<input type="text" name="nombre2" value="Nombre de su Amigo" /> ','<input type="text" name="email2" value="Email de su Amigo" /> ','<input type="hidden" name="flag" value="2" /> ','<button type="submit">Enviar</button>'].join(''));}
$this.submit(function(){var $this=$(this);var action=$this.attr('action');var data=$this.serialize();var flag=false;$this.find(':text').each(function(i){if($(this).val()==this._value){flag=false;}else{flag=true;}});if(flag){$this.append('<img src="/f/image/ajax-loader-mini.gif" alt="" style="position:absolute; top:11px; right:10px;" />');$.get(action,data,function(){setTimeout(function(){$this.text('Su mensaje ha sido enviado');setTimeout(function(){$this.animate({height:'toggle',opacity:'toggle'},'fast');},750);},2000);});return false;}else{return false;}}).find('input[name=pag]').val(encodeURIComponent(document.location.href)).end().find(':input').each(function(){var $this=$(this);this._value=this.value;$this.click(function(){if($this.val()==this._value)
$this.val('');}).blur(function(){if($.trim($this.val())=='')
$this.val(this._value);});});});$('.txtMore',this).click(function(){var $principal=$('.principal');var fs=parseInt($principal.css('font-size'));if(fs<=12&&fs>=10)
$principal.animate({fontSize:(fs+2)},'fast');return false;});$('.txtLess',this).click(function(){var $principal=$('.principal');var fs=parseInt($principal.css('font-size'));if(fs<=14&&fs>=12)
$principal.animate({fontSize:(fs-2)},'fast');return false;});var a=window;var b=document;var c=encodeURIComponent;
var googleUrl="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+c(b.location)+"&title="+c(b.title);
var meneameUrl="http://meneame.net/submit.php?url="+c(b.location.href);
var deliUrl='http://del.icio.us/post?v=4;url='+c(b.location.href)+';title='+c(b.title);var mrwongUrl='http://www.mister-wong.es/index.php?action=addurl&bm_url='+c(b.location.href)+'&amp;bm_description='+c(b.title);
var facebookUrl = 'http://www.facebook.com/sharer.php?u='+c(b.location);
var anyUrl='http://www.addtoany.com/?linkname='+c(b.title)+'&linkurl='+c(b.location.href)+'&type=page';
$('.googleBookmarks',this).click(function(){var d=a.open(googleUrl,"bkmk_popup","left="+((a.screenX||a.screenLeft)+10)+",top="+((a.screenY||a.screenTop)+10)+",height=420px,width=550px,resizable=1,alwaysRaised=1");a.setTimeout(function(){d.focus();},300);return false;}).attr('href',googleUrl);
$('.meneameBookmark',this).click(function(){a.open(meneameUrl,"meneame_popup");return false;}).attr('href',meneameUrl);
$('.facebookBookmark', this).click(function(){a.open(facebookUrl,'facebook_popup','toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes'); return false; }).attr('href',facebookUrl);
$('.deliciousBookmark',this).click(function(){a.open(deliUrl,"delicious_popup");return false;}).attr('href',deliUrl);
$('.mrwongBookmark',this).click(function(){a.open(mrwongUrl,"mrwong_popup");return false;}).attr('href',mrwongUrl);
$('.addtoanyBookmark',this).click(function(){a.open(anyUrl,'addtoany_popup','width=800,height=600,scrollbars=yes,resizable=yes');return false;}).attr('href',anyUrl);
});};})(jQuery);

// ec.date
(function(){$.fn.date=function(){var date=new Date();var d=date.getDate();var day=(d<10)?'0'+d:d;var m=date.getMonth();var months=['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Setiembre','Octubre','Noviembre','Diciembre'];var month=months[m];var yy=date.getYear();var year=(yy<1000)?yy+1900:yy;var today=day+' de '+month+' del '+year;return this.text(today);};})(jQuery);

// archive
(function($){ArchiveCalendar={selectedDay:0,selectedMonth:0,selectedYear:0,prevText:'<img src="/f/image/ico-prev-page.png" alt="Anterior" />',nextText:'<img src="/f/image/ico-next-page.png" alt="Siguiente" />',currentText:'Hoy',appendText:'',dayNames:['Do','Lu','Ma','Mi','Ju','Vi','Sa'],monthNames:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],dateFormat:'DMY/',yearRange:'-10:+10',changeMonth:true,changeYear:true,firstDay:0,showOtherMonths:false,minDate:null,maxDate:null,closeAtTop:true,hideIfNoPrevNext:true,customEvent:false,targetDayURL:"/impresa/edicion/",init:function(target){this.selectingMonthYear=false;this.calendarDiv=$('<div id="archivos-cal"></div>');$(target).append(this.calendarDiv);ArchiveCalendar.showCalendar();ArchiveCalendar.gotoToday();},showFor:function(target){var input=(target.nodeName&&target.nodeName.toLowerCase()=='input'?target:this);ArchiveCalendar.input=$(input);ArchiveCalendar.showCalendar();},showCalendar:function(){$("#archivos-cal").empty();this.popUpShowing=true;var today=new Date();today=new Date(today.getFullYear(),today.getMonth(),today.getDate());var html='<div id="calendar_links"><div class="calendar_controls">'+
(this.canAdjustMonth(-1)?'<a id="calendar_prev" onclick="ArchiveCalendar.adjustDate(-1, \'M\');">'+this.prevText+'</a>':(this.hideIfNoPrevNext?'':'<label id="calendar_prev">'+this.prevText+'</label>'))+'<div class="calendar_actmonth">'+this.monthNames[this.selectedMonth]+'</div>'+
(this.canAdjustMonth(+1)?'<a id="calendar_next" onclick="ArchiveCalendar.adjustDate(+1, \'M\');">'+this.nextText+'</a>':(this.hideIfNoPrevNext?'':'<label id="calendar_next">'+this.nextText+'</label>'))+'</div>';if(!this.changeYear){html+=this.selectedYear;}else{var years=this.yearRange.split(':');var year=0;var endYear=0;if(years.length!=2){year=this.selectedYear-10;endYear=this.selectedYear+10;}
else if(years[0].charAt(0)=='+'||years[0].charAt(0)=='-'){year=this.selectedYear+parseInt(years[0]);endYear=this.selectedYear+parseInt(years[1]);}
else{year=parseInt(years[0]);endYear=parseInt(years[1]);}
year=(this.minDate?Math.max(year,this.minDate.getFullYear()):year);endYear=(this.maxDate?Math.min(endYear,this.maxDate.getFullYear()):endYear);html+='<select id="calendar_newYear" onchange="ArchiveCalendar.selectMonthYear(this, \'Y\');" '+'>';for(;year<=endYear;year++){html+='<option value="'+year+'"'+(year==this.selectedYear?' selected="selected"':'')+'>'+year+'</option>';}
html+='</select>';}
html+='</div>';html+='<table id="calendar" cellpadding="0" cellspacing="0"><thead>'+'<tr class="calendar_titleRow">';for(var dow=0;dow<7;dow++){sund_=(this.dayNames[(dow+this.firstDay)]=="D")?' class="domingo"':'';html+='<td'+sund_+'>'+this.dayNames[(dow+this.firstDay)%7]+'</td>';}
html+='</tr></thead><tbody>';var daysInMonth=this.getDaysInMonth(this.selectedYear,this.selectedMonth);this.selectedDay=Math.min(this.selectedDay,daysInMonth);var leadDays=(this.getFirstDayOfMonth(this.selectedYear,this.selectedMonth)-this.firstDay+7)%7;var currentDate=new Date(this.currentYear,this.currentMonth,this.currentDay);var selectedDate=new Date(this.selectedYear,this.selectedMonth,this.selectedDay);var printDate=new Date(this.selectedYear,this.selectedMonth,1-leadDays);var numRows=Math.ceil((leadDays+daysInMonth)/7);for(var row=0;row<numRows;row++){html+='<tr class="calendar_daysRow">';for(var dow=0;dow<7;dow++){var customSettings=(this.customDate?this.customDate(printDate):[true,'']);var otherMonth=(printDate.getMonth()!=this.selectedMonth);var unselectable=otherMonth||!customSettings[0]||(this.minDate&&printDate<this.minDate)||(this.maxDate&&printDate>this.maxDate);html+='<td class="calendar_daysCell'+
((dow+this.firstDay+6)%7>=6?' calendar_weekEndCell':'')+(otherMonth?' calendar_otherMonth':'')+(printDate.getTime()==selectedDate.getTime()?' calendar_daysCellOver':'')+(!otherMonth||this.showOtherMonths?' '+customSettings[1]:'')+'"'+
(printDate.getTime()==currentDate.getTime()?' id="calendar_currentDay"':(printDate.getTime()==today.getTime()?' id="calendar_today"':''))+'>'+
(otherMonth?(this.showOtherMonths?printDate.getDate():'&nbsp;'):(unselectable?'<span>'+printDate.getDate()+'</span>':'<a href="'+this.targetDayURL+ArchiveCalendar.getDashedDate(printDate)+'">'+printDate.getDate()+'</a>'))+'</td>';printDate.setDate(printDate.getDate()+1);}
html+='</tr>';}
html+='</tbody></table>'+(this.closeAtTop||this.inline?'':controls);this.calendarDiv.append(html).show("fast");},gotoToday:function(){var date=new Date();ArchiveCalendar.selectedDay=date.getDate();ArchiveCalendar.selectedMonth=date.getMonth();ArchiveCalendar.selectedYear=date.getFullYear();ArchiveCalendar.adjustDate();},selectMonthYear:function(select,period){ArchiveCalendar.selectingMonthYear=false;ArchiveCalendar[period=='M'?'selectedMonth':'selectedYear']=select.options[select.selectedIndex].value-0;ArchiveCalendar.adjustDate();},noWeekends:function(date){var day=date.getDay();return[(day>0&&day<6),''];},formatDate:function(day,month,year){month++;var dateString='';for(var i=0;i<3;i++){dateString+=this.dateFormat.charAt(3)+
(this.dateFormat.charAt(i)=='D'?(day<10?'0':'')+day:(this.dateFormat.charAt(i)=='M'?(month<10?'0':'')+month:(this.dateFormat.charAt(i)=='Y'?year:'?')));}
return dateString.substring(this.dateFormat.charAt(3)?1:0);},getDaysInMonth:function(year,month){return 32-new Date(year,month,32).getDate();},getFirstDayOfMonth:function(year,month){return new Date(year,month,1).getDay();},canAdjustMonth:function(offset){var date=new Date(this.selectedYear,this.selectedMonth+offset,1);if(offset<0){date.setDate(this.getDaysInMonth(date.getFullYear(),date.getMonth()));}
return this.isInRange(date);},isInRange:function(date){return((!this.minDate||date>=this.minDate)&&(!this.maxDate||date<=this.maxDate));},adjustDate:function(offset,period,dontShow){var date=new Date(this.selectedYear+(period=='Y'?offset:0),this.selectedMonth+(period=='M'?offset:0),this.selectedDay+(period=='D'?offset:0));date=(this.minDate&&date<this.minDate?this.minDate:date);date=(this.maxDate&&date>this.maxDate?this.maxDate:date);this.selectedDay=date.getDate();this.selectedMonth=date.getMonth();this.selectedYear=date.getFullYear();this.showCalendar();},getDashedDate:function(date){var _today=(date.getDate()<10)?'0'+date.getDate():date.getDate();var _month=(date.getMonth()<9)?'0'+Number(date.getMonth()+1):Number(date.getMonth()+1);var _year=date.getFullYear();var str_date=_year+"-"+_month+"-"+_today;return str_date;}};})(jQuery);

//mediaplayer on note
//(function($){
$.fn.mediaplayer=function(p){var noteclass=this.attr("class").split(" ");var noteinfo=[noteclass[0],noteclass[1],noteclass[0].substr(0,4)];if(noteinfo){this.append("<div class='inner'><div id='player'></div></div>");$('#player').flash({src:'/f/player/player.swf', width: 365, height: 405, flashvars:  {wmode:'transparent', quality:'best', showdisplay:'true', showcontrolbar:'true', showcaptions:'true', showthumbnails:'true', file:"/f/playlist/"+noteinfo[2]+"/playlist"+noteinfo[0]+".xml?t="+(new Date()).getTime(), defaultitem:noteinfo[1], showfilters:'true'}},{version:8});}}
//})(jQuery);
//cache mediaplayer
function mediaplayer(limit){var dl,dt,ds,cl;if($('#tmgen').size()){cl=$('#tmgen').attr('class');dl=new Date(parseInt(cl.substr(0,4)),parseInt(cl.substr(4,2))-1,parseInt(cl.substr(6,2))).getTime(limit);dt=new Date().getTime();ds=Math.floor((dt-dl)/(1000*60*60*24));};if(ds<limit && $('#playerNota').size()){$('#playerNota').mediaplayer();}};
$(document).ready(function(){
    mediaplayer(90);//3 meses
}
);
