var arkiv_call_back = null;
var active_page_table_field_id = 0;
var active_table_row_id = 0;
var active_icon = null;
var active_btn = null;
var active_icon_saved_path = "";
var active_icon_saved_label = "";
var active_btn_new_action = null;
/*function save_page_table_field_pic_id(pic_id){
	SqueezeBox.close();
	//here we should save to database
	var myRequest = new Request({method: 'post', url: '../../site/skjema/db/save_page_table_field_pic_id.php', onComplete :function(result){
		if (0 == 0){
			// we could load the media by ajax, but for now we do just refresh
			document.location.reload();
		}
	}});
	myRequest.send('page_table_field_id='+active_page_table_field_id+'&pic_id='+pic_id);
}    */
function velg_bilde_arkiv(page_id){
	// csAlert.options.OverlayStyles['opacity'] = 0.9;csAlert.iFrame_arkiv('../../site/arkiv/media.php?page_id=1580&field_id=36');arkiv_bilde_id=2;
	var myIFrame = new IFrame({
		src: '../../site/arkiv/media.php?page_id=4',
		styles: {
			width: 1,
			height: 1,
			visibility:'hidden',
			border:'none'
		},
		events: {
			mouseenter: function(){
				//alert('Welcome aboard.');
			},
			mouseleave: function(){
				//alert('Goodbye!');
			},
			load: function(){
				var ifr = $(this);
				var loader = $('loading_img');
				ifr.setStyle('height', 600);
				//alert(ifr.setStyle);
				ifr.setStyle('width', 800);
				ifr.setStyle('opacity', '0');
				ifr.setStyle('visibility', 'visible');
				ifr.fade('in');
				loader.dispose();
				$('div_wraper').setStyle('text-align', 'left');
				ifr.removeEvents('load');
			}
		}
	});

	var wraper = new Element('div', {id:'div_wraper', styles:{width:'800px', 'text-align':'center', 'overflow':'hidden'}});
	var bilde = new Element('img', {id:'loading_img', src: '../../site/pages/js_dialogs/images/circle_64x64.gif', styles: { width:"64px"}});
	myIFrame.inject(wraper);
	bilde.inject(wraper);
	SqueezeBox.fromParams({handler:'div', size:{x:820,y:610}, div_cont:wraper, divOptions:{styles:{overflow:'hidden'}}, onClose:function(){
		var bilde_f = bilde;
		var wraper_f = wraper;
		var ifr = myIFrame;
		delete ifr;
		delete bilde_f;
		delete wraper_f;
	}});
}
function save_answer_points(points){
	//here we should save to database
	var table_row_id = active_table_row_id;
	var myRequest = new Request({method: 'post', url: '../../site/skjema/db/save_table_row_points.php', onComplete :function(result){
		if (0 == 0){
			active_icon.src=active_icon_saved_path;
			$(active_icon).set('alt', active_icon_saved_label);
			$(active_btn).set( 'onclick', '' );
			$(active_btn).removeEvents();

			$(active_btn).addEvents({
				'click': function(){
					active_btn_new_action(table_row_id);
				}
			});
			//alert('finished saveing pic:'+pic_id+'page_table_field_id='+result);
		}
	}});
	myRequest.send('table_row_id='+active_table_row_id+'&points='+points);
}
function set_answer_points(table_row_id,points){
	active_table_row_id = table_row_id;
	save_answer_points(points);
}
function set_answer_right(table_row_id){
	//alert("set right");
	active_icon = $("img_qu_answer_"+table_row_id);
	active_btn = $("btn_qu_answer_"+table_row_id);
	active_icon_saved_path = "../../site/pages/img/icons/small/qu_wrong_answer.gif";
	active_icon_saved_label = "Sett som feil svar";
	active_btn_new_action = set_answer_wrong;
	set_answer_points(table_row_id,1);
}
function set_answer_wrong(table_row_id){
	//alert("set wrong");
	active_icon = $("img_qu_answer_"+table_row_id);
	active_btn = $("btn_qu_answer_"+table_row_id);
	active_icon_saved_path = "../../site/pages/img/icons/small/qu_right_answer.gif";
	active_icon_saved_label = "Sett som riktig svar";
	active_btn_new_action = set_answer_right;
	set_answer_points(table_row_id,0);
}
