/*!
 * Ultimate Warfare JavaScript Library v1.0
 * http://ultimate-warfare.com/
 *
 * Copyright 2010, Frank Schreuder
 *
 * Date: Feb 15 20:00:00 2011
 */

var timeDiff=null,timeStart=null,resis=[],timers=[];function popup(a,b,c){wnd=window.open(a,"popup","width="+b+",height="+c+",left=150,top=150,resizable=yes");wnd.focus()}function popup_scroll(a,b,c){wnd=window.open(a,"popup","width="+b+",height="+c+",left=150,top=100,resizable=yes,scrollbars=yes");wnd.focus()}function addTimer(a,b,c){var d=[];d.element=a;d.endTime=b;d.reload=c;timers.push(d)}function startResTicker(a){var b=$('#'+a),start=parseInt(b.html(),10),prod=b.attr("title")/3600,res={};res.name=a;res.start=start;res.prod=prod;resis[a]=res}function getTime(a){if(!a.html()||a.html().length==0)return-1;if(a.html().indexOf('<a ')!=-1)return-1;var b=a.html().split(":");for(var j=1;j<3;j++)if(b[j].charAt(0)=="0")b[j]=b[j].substring(1,b[j].length);var c,days;if(isNaN(b[0])){var d=b[0].split((/[a-z\s]+/i));c=parseInt(d[1],10);days=parseInt(d[0],10)}else{c=parseInt(b[0],10);days=0};var e=parseInt(b[1],10),seconds=parseInt(b[2],10),time=days*3600*24+c*60*60+e*60+seconds;return time}function getLocalTime(){var a=new Date();return Math.floor(a.getTime()/1000)}function gid(a){return $("#"+a)}function startTimer(){var a=getTime($("#serverTime"));timeDiff=a-getLocalTime();timeStart=a;$('span.timer,span.timer_replace').each(function(){startTime=getTime($(this));if(startTime!=-1)addTimer($(this),a+startTime,($(this).hasClass("timer")))});window.setInterval("tick()",1000)}function tickRes(a){var b=a.name,start=a.start,prod=a.prod,now=new Date(),time=(now.getTime()/1000+timeDiff)-timeStart,current=Math.floor(start+prod*time),element=gid(b);element.html(current)}function number_format(a,b){var c=a.toString(),length=(a>0)?3:4;if(c.length<=length)return c;var d=new Array();do{var e=c.length-3;d.push(c.slice(e,c.length));c=c.substring(0,e)}while(c.length>3);d.reverse();for(e in d)c+=b+d[e];return c}function incrementDate(){currentDate=$('#serverDate').html();splitDate=currentDate.split('/');date=splitDate[0];month=splitDate[1]-1;year=splitDate[2];dateObject=new Date(year,month,date);dateObject.setDate(dateObject.getDate()+1);dateString='';date=dateObject.getDate();month=dateObject.getMonth()+1;year=dateObject.getFullYear();if(date<10)dateString+="0";dateString+=date+"/";if(month<10)dateString+="0";dateString+=month+"/";dateString+=year;$('#serverDate').html(dateString)}function formatTime(a,b,c){var d=Math.floor(b/3600);if(c)d=d%24;var e=Math.floor(b/60)%60,seconds=b%60,timeString=d+":";if(e<10)timeString+="0";timeString+=e+":";if(seconds<10)timeString+="0";timeString+=seconds;$(a).html(timeString);if($(a).attr('id')=='serverTime'&&timeString=='0:00:00')incrementDate()}function tickTime(){var a=$("#serverTime");if(a!==null){var b=getLocalTime()+timeDiff;formatTime(a,b,true)}}function tickTimer(a){var b=a.endTime-(getLocalTime()+timeDiff);if(a.reload&&b<0){formatTime(a.element,0,false);var c=$('.popup_style'),hide_reload=false;for(var i=0;i<c.length;i++)if(c[i].style.display!='none'){hide_reload=true;break};if(!hide_reload){document.location.href=document.location.href.replace(/action=\w*/,'');return true}else return false};if(!a.reload&&b<=0){var d=a.element.parent(),next=d.next();if(next.length==0)return false;next.css('display','inline');d.remove();return true};formatTime(a.element,b,false);return false}function tick(){tickTime();for(var a=0;a<timers.length;a++){var b=tickTimer(timers[a]);if(b)timers.splice(a,1)}}function selectAll(a,b){for(var i=0;i<a.length;i++)a.elements[i].checked=b}

