function addcustomprod(code) {
	openwin(code);
} //

function openwin(code) {

	var url = '/ee/index/addtocampaign/code/' + code;
	var win = window.open(url, 'mywindow', 'width=540,height=540');
	if (win)
		win.focus();

} // function openpicwin

function submit_ac_form() {
	
	console.log('submit_ac_form');

	var form = dojo.byId('campform');
	var result = '';

	dojo.xhrPost( {
		url : '/json/savecampaignprice',
		form : 'campform',
		load : function(response, result) {

			var msgLayer = dojo.byId('msgresult');

			dojo.attr(msgLayer, "style", {
				display : "block"
			});

			var fade = dojo.fadeIn( {
				node : msgLayer,
				duration : 100,
				onEnd : function() {
					return false;
//					var fade = dojo.fadeOut( {
//						node : msgLayer,
//						duration : 2000,
//						onEnd : function() {
//
//							dojo.attr(msgLayer, "style", {
//								display : "none"
//							});
//						}
//					});
//					fade.play();

				}
			});
			fade.play();

		} // load:function
	});
	return true;
} // function ajaxSubmitForm

function delcamprow( id ){
 		
		var userInput = confirm("Kas kustutame valitud rea?");

		if (userInput) {
			jsonDeleteCampRow( id );
		} // if...
		
} //

function jsonDeleteCampRow( id ){

	dojo.xhrGet( { //

	url : "/ee/json/deletecampaignrow/id/" + id,
	handleAs : "text",

	timeout : 5000, // Time in milliseconds

	// The LOAD function will be called on a successful response.
	load : function(data) { // 

		if (data == 'OK') {
			var divId = "row-wr-" + id;
			var rowDiv = dojo.byId( divId );
			
			dojo.attr(rowDiv, "style", {
				border : "1px solid red"
			});
			
			var fade = dojo
					.fadeOut( {
						node : divId,
						duration : 300,
						onEnd : function() {
						// eemaldame selle rea div-i
							rowDiv.parentNode
									.removeChild(rowDiv);
							// alert ( parentLi );
						}
					});
			fade.play();

		} // 

		return true;
	},

	// The ERROR function will be called in an error case.
	error : function(response, ioArgs) { // 
		console.error("HTTP status code: ", ioArgs.xhr.status); //
	}
});

	
} // function jsonDeleteCampRow

