var status = {
	'true': 'open',
	'false': 'close'
};
window.addEvent('domready', function(){
	$$('input.DatePicker').each( function(el){
		new DatePicker(el);
	});
});

/**
 * Load Issues of a volume
 * @param {int} param 
 */
 function loadIssues(volume) {
 	
 	if ($('dvIss_'+volume).style.display == 'none') {
 		$$('.brVol').each(function(dv) { 
			//if(dv.id.indexOf('dvIss_'+volume) == -1)
			dv.style.display = "none";
		});
 		$$('.imgc').each(function(imgc) { 
			imgc.src = "images/expand.gif";
		});
 		
 		$('dvIss_'+volume).style.display = 'block';
 		$('img_'+volume).src = 'images/collapse.gif';
 		
 		if ($('dvIss_'+volume).innerHTML == '') {
	 		var req = new Request({
				method: 'get',
				url : '__req/article.ajax',
				data: {
					'task'  : 'loadIssues',
					'volume': volume
				},
				onRequest: function() {
					$('dvIss_'+volume).innerHTML = '<img src="images/loading/loading.gif" />';
				},
				onComplete: function(response) {
					$('dvIss_'+volume).innerHTML = response;
				}
			}).send();
 		}
			
 	} else {
 		$('dvIss_'+volume).style.display = 'none';
 		$('img_'+volume).src = 'images/expand.gif';
 	}
 }
	 
 /**
  * act
  * @param {string} param 
  */
  function act(action) {

  	switch (action) {
  		case 'save':
  			
  			savedRecords = '';
  			for(var i=0; i<document.getElementsByName('article_code').length; i++) {
  				if(document.getElementsByName('article_code')[i].checked)
  					savedRecords += ','+document.getElementsByName('article_code')[i].value;  				
  			}
  			
  			if(savedRecords != '') {
  				
  				savedRecords = savedRecords.substr(1);  				
		 		var req = new Request({
					method: 'get',
					url : '__req/article.ajax',
					data: {
						'task'   : 'saveRecords',
						'records': savedRecords
					},
					onRequest: function() {
						showProgress(1, 'Saving Records');
					},
					onComplete: function(response) {
						showProgress(2,response);
					}
				}).send();  					
  			}
  			
  			break;
  		case 'feed':
			x=screen.width/2-300;
			y=screen.height/2-170;
			features='scrollbars=yes,resizable=yes,width=620,height=340,top='+y+',left='+x;
  			window.open('ju.rss','', features);
  			break;
  			
  		case 'print':
			x=screen.width/2-400;
			y=screen.height/2-200;
			features='scrollbars=yes,resizable=yes,width=800,height=400,top='+y+',left='+x;
  			window.open('ju.print?'+document.location, '', features);
  			break;
  			
  		case 'email':
			x=screen.width/2-200;
			y=screen.height/2-150;
			features='scrollbars=yes,resizable=yes,width=450,height=280,top='+y+',left='+x;
  			window.open('ju.email?'+document.location,'', features)
  			break;
  		default:
  			break;
  	}  	
  	
  }
  
  
/**
 * Show Progress bar
 * @param {int} prSt, {string} txt 
 */
 function showProgress(prSt,txt) {
 	
 	if(prSt == 1) {
		$('infobox').innerHTML = '<img src="images/loading/spinner.gif" style="vertical-align:middle" /> '+txt+' ...';
		$('infobox').visibility = 'visible';
		var exampleFx = new Fx.Tween('infobox', {
			property: 'opacity',			
			transition: Fx.Transitions.Quart.easeInOut,
			link: 'chain'
		});
		exampleFx.start(0,1);				
 	}else {
 		
		$('infobox').innerHTML = txt;
		exampleFx = new Fx.Tween('infobox', {
			property: 'opacity',
			duration: 10000, 
			transition: Fx.Transitions.Quart.easeInOut,
			link: 'chain'
			});
			exampleFx.start(1, 0);							
	 		
	 }
	 		 	
 }     
  
window.addEvent('domready', function() {
	if($('dvAds') == null)
		return;
	if($('obanner') != null)
		$('obanner').style.display = 'none';
	var dvAds = new Fx.Slide('dvAds');
	//dvAds.hide();
			
	$('aAds').addEvent('click', function(e){
		e.stop();	
		
		if($('obanner') != null ) {
			if(status[dvAds.open] == 'open') 
				$('obanner').style.display = 'none';
			else
				$('obanner').style.display = 'inline';
		}
		if($('imgAds') != null ) {
			if(status[dvAds.open] == 'open') 
				$('imgAds').src = "images/show_ads.gif";
			else
				$('imgAds').src = "images/close_ads.gif";
		}
		dvAds.toggle();
	});
			
});

 function openImage(img, _width, _height) {
	var wdt = _width;
	var hdt = _height;
	
	if(wdt >= screen.width)
		wdt = screen.width - 50;
	if(hdt >= screen.height)
		hdt = screen.height - 50;
	
	x=screen.width/2-(wdt/2);
	y=screen.height/2-(hdt/2);
	features='scrollbars=yes,width='+wdt+',height='+hdt+',top='+y+',left='+x;
	window.open('enlarge?edt=1&img='+img,'',features);
	 
 }
