// JavaScript Document
// JavaScript Document

var Rules = {
	'.animatedRow' : function(element){
		element.onmouseover = function()
		{
			if ($('row'+this.id)!=null && $('row'+this.id).checked) return false;
			
			this.style.backgroundColor = "#FFFF66";
			return false;
		}
		element.onmouseout = function()
		{
			if ($('row'+this.id)!=null && $('row'+this.id).checked) return false;
			
			this.style.backgroundColor = "#FFFFFF";
			return false;
		}
	},
	'.rowSelector' : function(element){
		element.onclick = function(){
			if (this.checked) {
				this.parentNode.parentNode.style.backgroundColor = "#A2D2EA";
			} else {
				this.parentNode.parentNode.style.backgroundColor = "#FFFFFF";
			};
			//return false;
		}
	},
	'.selectAll' : function(element){
		element.onclick = function(){
			nodes = $((controller + 'Form')).getElementsByTagName('input');
			checkbox = $A(nodes);
			checkbox.each(function(node){
				if (node.type == 'checkbox') {
					//alert(node.id + ': ' + node.value);
					if (!node.checked) { node.checked = true; node.parentNode.parentNode.style.backgroundColor = "#A2D2EA"; };
				}
			});
			return false;
		}
	},
	'.clearSelection' : function(element){
		element.onclick = function(){
			nodes = $((controller + 'Form')).getElementsByTagName('input');
			checkbox = $A(nodes);
			checkbox.each(function(node){
				if (node.type == 'checkbox') {
					//alert(node.id + ': ' + node.value);
					if (node.checked) { node.checked = false; node.parentNode.parentNode.style.backgroundColor = "#FFFFFF"; };
				}
			});
			return false;
		}
	},
	'.closeIcon' : function(element){
		element.onclick = function(){
			element.parentNode.style.display = 'none';			
			return false;
		}
	},
	'.buttonSearch' : function(element){
		element.onclick = function(){
			$(('search_' + controller + '_Form')).style.display = 'block';
			return false;
		}
	},	
	'.buttonAddToFavotite' : function(element){
		element.onclick = function(){
			$((controller + 'Form')).action += '/add_to_favorite';
			$((controller + 'Form')).submit();
		}
	},
	'.buttonPublish' : function(element){
		element.onclick = function()
		{
			if(confirm("Передавать объявление в Яндекс.Недвижимость?"))
			{
				$((controller + 'Form')).action += '/publish/';
			}
			else
				$((controller + 'Form')).action += '/publish/1';
			
			$((controller + 'Form')).submit();
		}
	},
	'.buttonUnPublish' : function(element){
		element.onclick = function(){
			$((controller + 'Form')).action += '/unpublish/';				
			$((controller + 'Form')).submit();
		}
	},
	'.buttonDelete' : function(element){
		element.onclick = function(){
			if (confirm('Вы действительно желаете произвести удаление?')) 
			{
				$((controller + 'Form')).action += '/delete/';
				$((controller + 'Form')).submit();
			} else {
				return false;
			}
			
		}
	},
	'.buttonDeleteUnpublish' : function(element){
		element.onclick = function(){
			if (confirm('Вы действительно желаете произвести удаление всех снятых объявлений?')) 
			{
				$((controller + 'Form')).action += '/deleteUnpublish/';
				$((controller + 'Form')).submit();
			} else {
				return false;
			}
			
		}
	},
	
	'.buttonClearDelete' : function(element){
		element.onclick = function(){
			if (confirm('Снять пометку о удалении?')) 
			{
				$((controller + 'Form')).action += '/clear_delete/';
				$((controller + 'Form')).submit();
			} else {
				return false;
			}
			
		}
	},	
	'.buttonArchive' : function(element){
		element.onclick = function(){
			element=document.getElementById(('archive_' + controller + '_Form'));
			scrollWidth = document.body.scrollWidth;
			posleft = Math.round(scrollWidth / 2) - 300;
			postop = document.body.scrollTop+window.screen.availHeight/2-250;
			element.style.left = posleft;
			element.style.top = postop;
			element.style.display = 'block';
			return false;
		}
	},		
	'.quickNotesField' : function(element){
		element.onfocus = function(){
			scrollWidth = document.body.scrollWidth;
			posleft = Math.round(scrollWidth / 2) - 210;
			postop = document.body.scrollTop+window.screen.availHeight/2-150;
			$(('notes_' + controller + '_Form')).style.left = posleft;
			$(('notes_' + controller + '_Form')).style.top = postop;

			$(('notes_' + controller + '_Form')).style.display = 'block';
			$((controller + 'NotesForm')).elements['id'].value = this.id;
			//$((controller + 'NotesForm')).elements['notes_text'].innerHTML = this.value;
			$((controller + 'NotesForm')).elements['notes_text'].value = this.value;
			$((controller + 'NotesForm')).elements['notes_text'].focus();
			return false;
		}
	},
	'.quickNotesExField' : function(element){
		element.onfocus = function(){
			scrollWidth = document.body.scrollWidth;
			posleft = Math.round(scrollWidth / 2) - 210;
			postop = document.body.scrollTop+window.screen.availHeight/2-150;
			$(('notes_' + controller + '_Form_ex')).style.left = posleft;
			$(('notes_' + controller + '_Form_ex')).style.top = postop;

			$(('notes_' + controller + '_Form_ex')).style.display = 'block';
			$((controller + 'NotesExForm')).elements['id'].value = this.id;
			//$((controller + 'NotesForm')).elements['notes_text'].innerHTML = this.value;
			$((controller + 'NotesExForm')).elements['notes_text_ex'].value = this.value;
			$((controller + 'NotesExForm')).elements['notes_text_ex'].focus();
			return false;
		}
	},	
	'.quickEmailForm' : function(element){
		element.onfocus = function(){
			scrollWidth = document.body.scrollWidth;
			posleft = Math.round(scrollWidth / 2) - 210;
			postop = document.body.scrollTop+window.screen.availHeight/2-150;
			$(('mail_' + controller + '_Form')).style.left = posleft;
			$(('mail_' + controller + '_Form')).style.top = postop;

			$(('mail_' + controller + '_Form')).style.display = 'block';
			$((controller + 'EmailForm')).elements['order_id'].value = this.id;
			$((controller + 'EmailForm')).elements['email_to'].value = '';
			return false;
		}
	},	
	'.republishField' : function(element){
		element.onfocus = function()
		{
			scrollWidth = document.body.scrollWidth;
			posleft = Math.round(scrollWidth / 2) - 125;
			postop = document.body.scrollTop+window.screen.availHeight/2-75;
			$(('republish_' + controller + '_Form')).style.left = posleft;
			$(('republish_' + controller + '_Form')).style.top = postop;
			
			$(('republish_' + controller + '_Form')).style.display = 'block';
			$((controller + 'RepublishForm')).elements['id'].value = this.id;
			$((controller + 'RepublishForm')).elements['republish_text'].value = this.value;
			$((controller + 'RepublishForm')).elements['republish_text'].focus();
			return false;
		}
	}
	
}
