window.addEvent('load', function() {
  	
	$('print').getElement("a[name=print]").addEvent('click', function(){
		showPhons($(document.body).getElements("a[name=contacthide]"));
		window.print();
	});
	
	$('print').getElement("a[name=bprint]").addEvent('click', function(){
		window.print();
	});
	
	/* hide using opacity on page load */
	$('fb-modal').setStyles({
		opacity:0,
		display:'block'
	});
	
	$('sendtofriend').addEvent('click',function() {
		new Request.JSON({'url': '/req.php?r=/zimerim/sendtofriend/', 'data': {id: $('arid').value},  'onComplete': function(callback) {
			
			/* data */
			$('pop_content').set('html', callback.content);
			
			/* hiders */
			$('fb-close').addEvent('click',function(e) { $('fb-modal').fade('out'); });
			window.addEvent('keypress',function(e) { if(e.key == 'esc') { $('fb-modal').fade('out'); } });
			$(document.body).addEvent('click',function(e) { 
				if($('fb-modal').get('opacity') == 1 && !e.target.getParent('.generic_dialog')) { 
					$('fb-modal').fade('out'); 
				} 
			});
			
			$('fb-send').addEvent('click',function(e) { 
				$('contract-form').set('send', {url: '/req.php?r=zimerim/sendtofriend/send', method: 'post', onSuccess: function(callback){
					var response = JSON.decode(callback);
					var response = JSON.decode(callback);
					if(response.status == "ok")
					{
						$('pop_content').set('html', response.content);
						$('fb-close').addEvent('click',function(e) { $('fb-modal').fade('out'); });
							window.addEvent('keypress',function(e) { if(e.key == 'esc') { $('fb-modal').fade('out'); } });
							$(document.body).addEvent('click',function(e) { 
								if($('fb-modal').get('opacity') == 1 && !e.target.getParent('.generic_dialog')) { 
									$('fb-modal').fade('out'); 
								} 
							});
					}
					else if(response.status == "faild")
					{
						$('note-messege').setProperty('class', 'mfaild').setStyle('display', 'block').getElement('.txt').set('html', response.content); 
					}
				}});
				$('contract-form').send();
			});
			
		}}).send();
		$('fb-modal').fade('in');
	});
	
	// phone
	$(document.body).getElements("a[name=contacthide]").each(function(el){
		el.addEvent('click', function(){
			showPhons(el);
		});
	});
  	
});

function showPhons(el)
{
	$(document.body).getElements("a[name=contacthide]").each(function(el){
		el.getElements('div.infobox').removeClass('hide');
		el.getElement('div[name=data]').addClass('hide');
		el.removeClass('contacthidebtn').setProperty('href', "#");
		el.blur()
	});
	new Request.JSON({url: "/req.php?r=zimerim/showphons/", method: 'post', data: {id: $('arid').value, url: window.location.pathname}, onComplete: function(callback){}}).POST();
}
