function openprompt(){

var oglas = {
	tip: {obican: 0, prioritetni: 0, vruci: 0, medijski: 0},
	trajanje: {dana_15: 0, dana_30: 0},
	params: {
		"obican15": {label: "Običan oglas", url_more: "ad_type=obican&TB_iframe=true&height=520&width=920", img:"/new_images/oglasi/obican.jpg", length: "15 dana", price: "3.200 din" },
		"obican30": {label: "Običan oglas", url_more: "ad_type=obican&TB_iframe=true&height=520&width=920", img:"/new_images/oglasi/obican.jpg", length: "30 dana", price: "4.800 din" },
		"prioritetni15": {label: "Prioritetni oglas", url_more: "ad_type=prio&TB_iframe=true&height=520&width=920", img:"/new_images/oglasi/prioritetni.jpg", length: "15 dana", price: "5.000 din" },
		"prioritetni30": {label: "Prioritetni oglas", url_more: "ad_type=prio&TB_iframe=true&height=520&width=920", img:"/new_images/oglasi/prioritetni.jpg", length: "30 dana", price: "7.000 din" },
		"vruci15": {label: "Vrući oglas", url_more: "ad_type=vruci&TB_iframe=true&height=520&width=920", img:"/new_images/oglasi/vruci.jpg", length: "15 dana", price: "12.700 din" },
		"vruci30": {label: "Vrući oglas", url_more: "ad_type=vruci&TB_iframe=true&height=520&width=920", img:"/new_images/oglasi/vruci.jpg", length: "30 dana", price: "20.000 din" },
		"medijski15": {label: "Medijski oglas", url_more: "ad_type=media&TB_iframe=true&height=520&width=920", img:"/new_images/oglasi/medijski.jpg", length: "15 dana", price: "18.000 din" },
		"medijski30": {label: "Medijski oglas", url_more: "ad_type=media&TB_iframe=true&height=520&width=920", img:"/new_images/oglasi/medijski.jpg", length: "30 dana", price: "27.000 din" }
	},
	
	most_important: 0,
	
	total: function(q, v){
		var types = [ "obican", "prioritetni", "vruci", "medijski", "dana_15", "dana_30"];
		
		for (var z in types) {
			if( typeof( types[z] ) != 'undefined' ){
				//alert( "points."+q+"["+v+"]."+types[z]);
				if( typeof( eval( "points."+q+"["+v+"]."+types[z]) ) != 'undefined' ){
					//alert( "points."+q+"["+v+"]."+types[z] +"=" + eval( "points."+q+"["+v+"]."+types[z]));
					if( typeof( eval( "oglas.tip."+types[z]) ) != 'undefined' ) 
						eval( "oglas.tip."+types[z]+"+= points."+q+"["+v+"]."+types[z] );
					else
						eval( "oglas.trajanje."+types[z]+"+= points."+q+"["+v+"]."+types[z] );
				}
				
				if( q == 'ldp_q10' ){
					oglas.most_important = v;
				}
				
			}
		}
		
	},
	
	best_choice: function(){
		var best_type = "prioritetni";
		var ads = [ "vruci", "medijski" ];
		
		for (var m in ads) {
			if( typeof( ads[m] ) != 'undefined' ){
				if( eval( "oglas.tip."+ads[m]+" >= oglas.tip."+best_type ) ){
					best_type = ads[m];
				}
			}
		}
		
		best_length =( oglas.trajanje.dana_15 >= oglas.trajanje.dana_30 ) ? 15 : 30;
		
		var best_options = [];
		best_options[0] = best_type + "" + best_length;
		
		if(oglas.most_important == 1){
			if( best_type == "prioritetni" )
				best_options[1] = "vruci"+best_length;
			else if ( best_type == "vruci" )
				best_options[1] = "medijski"+best_length;
			else{
				if(best_length == 15)
					best_options[1] = "medijski30";
				else
					best_options[1] = "vruci30";
			}
		}
		else if(oglas.most_important == 2){
			if( best_type == "prioritetni" ){
				if(oglas.tip.obican < 0){
					best_options[1] = "obican"+best_length;
				}
				else{
					best_options[1] = "vruci"+best_length;
				}
			}
			else if ( best_type == "vruci" )
				best_options[1] = "prioritetni"+best_length;
			else
				best_options[1] = "vruci"+best_length;
		}
		else if(oglas.most_important == 3){
			if( best_length == 15 )
				best_options[1] = best_type+"30";
			else
				best_options[1] = best_type+"15";
		}
		
		return best_options;
		
		
	},
	
	get_html: function(opt){
		var html = '<p class="option_head">PREPORUČUJEMO VAM JEDAN OD SLEDEĆIH OGLASA:</p>';
		html += oglas.get_one_option_html(opt[0], 1) + oglas.get_one_option_html(opt[1], 2);
		html += '<script>tb_init("#jqi a.my_thickbox");</script>';
		html += '<p class="choose_option">Odaberite opciju koji Vam odgovara:</p>';
		return html;
	},
	
	get_one_option_html: function(opt, num){

		var one_html = '<div class="ad_option"><div class="ad_option_left"><p class="option_num">Opcija '+num+':</p><h3 class="custom_page_subtitle">'+eval("oglas.params."+opt+".label")+'</h3><p class="option_days">('+eval("oglas.params."+opt+".length")+')</p><p class="option_price">'+eval("oglas.params."+opt+".price")+' + PDV</p><p class="option_more"><a name="'+eval("oglas.params."+opt+".label")+' - detalji" href="/index_bootstrap.php?mod=ad_info&'+eval("oglas.params."+opt+".url_more")+'" class="my_thickbox more_action_link">Saznaj više</a></p></div><div class="ad_option_right"><img src="'+eval("oglas.params."+opt+".img")+'" width="190" height="152" alt="'+eval("oglas.params."+opt+".label")+'" /></div></div>';
		
		return one_html;
	}
}

var points = {
	ldp_q1: [,{ obican: -1000},{}],
	ldp_q2: [,{ dana_15: +300}, {dana_30: +300, vruci: +3, medijski: +6}, {dana_15: +5, vruci: +5, medijski: +5}],
	ldp_q3: [,{dana_15: +1000, prioritetni: +5, vruci: +10, medijski: +15},{dana_15: +400, prioritetni: +5, vruci: +10, medijski: +10},{dana_30: +500},{dana_30: +1000, vruci: +5, medijski: +10}],
	ldp_q4: [,{prioritetni: +3, vruci: +3},{dana_30: +10, vruci: +10, medijski: +20},{prioritetni: +5},{}],
	ldp_q5: [,{prioritetni: +3},{vruci: +6},{medijski: +10}],
	ldp_q6: [,{obican: -1000},{}],
	ldp_q7: [,{prioritetni: +10},{prioritetni: +5, vruci: +5},{vruci: +5, medijski: +5},{}],
	ldp_q8: [,{prioritetni: +5},{vruci: +5, medijski: +5},{}],
	ldp_q9: [,{},{vruci: +7, medijski: +10}, {prioritetni: +5, vruci: +5, medijski: +2}, {prioritetni: +10}],
	ldp_q10: [,{vruci: +5, medijski: +10}, {prioritetni: +14}, {prioritetni: +5, vruci: +5}]
	
}

			
var temp = {
		state0: {
			html:'<p>1. Da li zapošljavate radnike za više različitih pozicija? (npr. 2 pravnika, 3 ekonomista)</p>  <div class="field"> 	<input type="radio" name="ldp_q1" id="ldp_q1_1" value="1" class="radioinput" /> 	<label for="ldp_q1_1">DA</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q1" id="ldp_q1_2" value="2" class="radioinput" /> 	<label for="ldp_q1_2">NE</label> </div>',
			buttons: { Odustani: false, 'Dalje >>': true },
			focus: 0,
			submit:function(v,m,f){ 
				if(!v)
					jQuery.ImpromptuClose()
				else {
					an = m.children('.field'); 
					sel_radio = $("input[name='ldp_q1']:checked").val();
					if( typeof sel_radio == 'undefined' ){
						alert('Morate odabrati nesto!')
						an.css("background-color","#ffaaaa");
					}
					else{
						$.ImpromptuGoToState('state1');//go forward
					}
					
				}
				return false; 
			}
		},
		state1: {
			html:'<p>2. Da li vam je novozaposleni potreban što pre, ili vam je bitnije da dobijete veći broj prijava?</p>  <div class="field"> 	<input type="radio" name="ldp_q2" id="ldp_q2_1" value="1" class="radioinput" /> 	<label for="ldp_q2_1">Da što ranije zaposlim.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q2" id="ldp_q2_2" value="2" class="radioinput" /> 	<label for="ldp_q2_2">Veći broj prijava.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q2" id="ldp_q2_3" value="3" class="radioinput" /> 	<label for="ldp_q2_3">Oba</label> </div> ',
			buttons: { '<< Nazad': -1, 'Dalje >>': 1, Odustani: 0 },
			focus: 2,
			submit:function(v,m,f){
				if(v==0)
					jQuery.ImpromptuClose()
				else if(v==1){
					an = m.children('.field'); 
					sel_radio = $("input[name='ldp_q2']:checked").val();
					if( typeof sel_radio == 'undefined' ){
						alert('Morate odabrati nesto!')
						an.css("background-color","#ffaaaa");
					}
					else{
						$.ImpromptuGoToState('state2');//go forward
					}
				}
				else if(v=-1)
					$.ImpromptuGoToState('state0');//go back
				return false; 
			}
		},
		state2: {
			html:'<p>3. Radni odnos bi počeo ...</p>  <div class="field"> 	<input type="radio" name="ldp_q3" id="ldp_q3_1" value="1" class="radioinput" /> 	<label for="ldp_q3_1">... za najviše 15 dana.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q3" id="ldp_q3_2" value="2" class="radioinput" /> 	<label for="ldp_q3_2">... za 15-30 dana.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q3" id="ldp_q3_3" value="3" class="radioinput" /> 	<label for="ldp_q3_3">... više od 30 dana.</label> </div> 	 <div class="field"> 	<input type="radio" name="ldp_q3" id="ldp_q3_4" value="4" class="radioinput" /> 	<label for="ldp_q3_4">... do pronalaženja odgovarajućeg kandidata.</label> </div>',
			buttons: { '<< Nazad': -1, 'Dalje >>': 1, Odustani: 0 },
			focus: 2,
			submit: function(v, m, f){
				if (v == 0) 
					jQuery.ImpromptuClose()
				else 
					if (v == 1){
						an = m.children('.field'); 
						sel_radio = $("input[name='ldp_q3']:checked").val();
						if( typeof sel_radio == 'undefined' ){
							alert('Morate odabrati nesto!')
							an.css("background-color","#ffaaaa");
						}
						else{
							$.ImpromptuGoToState('state3');//go forward
						}
					}
					else 
						if (v = -1) 
							$.ImpromptuGoToState('state1');//go back
				return false;
			}
		},
		
		state3: {
			html:'<p>4. Koliko ste u prošlosti lako došli do odgovarajućeg zaposlenog za  poziciju koju oglasavate?</p>  <div class="field"> 	<input type="radio" name="ldp_q4" id="ldp_q4_1" value="1" class="radioinput" /> 	<label for="ldp_q4_1">Uobičajeno.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q4" id="ldp_q4_2" value="2" class="radioinput" /> 	<label for="ldp_q4_2">Teško.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q4" id="ldp_q4_3" value="3" class="radioinput" /> 	<label for="ldp_q4_3">Lako.</label> </div> 	 <div class="field"> 	<input type="radio" name="ldp_q4" id="ldp_q4_4" value="4" class="radioinput" /> 	<label for="ldp_q4_4">Nikada ranije nismo tražili zaposlenog za ovu poziciju.</label> </div> ',
			buttons: { '<< Nazad': -1, 'Dalje >>': 1, Odustani: 0 },
			focus: 2,
			submit: function(v, m, f){
				if (v == 0) 
					jQuery.ImpromptuClose()
				else 
					if (v == 1) {
						an = m.children('.field'); 
						sel_radio = $("input[name='ldp_q4']:checked").val();
						if( typeof sel_radio == 'undefined' ){
							alert('Morate odabrati nesto!')
							an.css("background-color","#ffaaaa");
						}
						else{
							$.ImpromptuGoToState('state4');//go forward
						}
					}
					else 
						if (v = -1) 
							$.ImpromptuGoToState('state2');//go back
				return false;
			}
		},
		
		
		state4: {
			html:'<p>5. Koliko se Vašim konkursom traži izvršilaca za istu poziciju (npr. 5 pravnika)?</p>  <div class="field"> 	<input type="radio" name="ldp_q5" id="ldp_q5_1" value="1" class="radioinput" /> 	<label for="ldp_q5_1">1-2</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q5" id="ldp_q5_2" value="2" class="radioinput" /> 	<label for="ldp_q5_2">3-4</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q5" id="ldp_q5_3" value="3" class="radioinput" /> 	<label for="ldp_q5_3">5 i više</label> </div>',
			buttons: { '<< Nazad': -1, 'Dalje >>': 1, Odustani: 0 },
			focus: 2,
			submit: function(v, m, f){
				if (v == 0) 
					jQuery.ImpromptuClose()
				else 
					if (v == 1) {
						an = m.children('.field'); 
						sel_radio = $("input[name='ldp_q5']:checked").val();
						if( typeof sel_radio == 'undefined' ){
							alert('Morate odabrati nesto!')
							an.css("background-color","#ffaaaa");
						}
						else{
							$.ImpromptuGoToState('state5');//go forward
						}
					}
					else 
						if (v = -1) 
							$.ImpromptuGoToState('state3');//go back
				return false;
			}
		},
		
		
		state5: {
			html:'<p>6. Da li želite da koristite Vaš brendirani dizajn oglasa (Vaše gotovo oglasno rešenje, PDF) ?</p>  <div class="field"> 	<input type="radio" name="ldp_q6" id="ldp_q6_1" value="1" class="radioinput" /> 	<label for="ldp_q6_1">Da.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q6" id="ldp_q6_2" value="2" class="radioinput" /> 	<label for="ldp_q6_2">Ne.</label> </div>',
			buttons: { '<< Nazad': -1, 'Dalje >>': 1, Odustani: 0 },
			focus: 2,
			submit: function(v, m, f){
				if (v == 0) 
					jQuery.ImpromptuClose()
				else 
					if (v == 1) {
						an = m.children('.field'); 
						sel_radio = $("input[name='ldp_q6']:checked").val();
						if( typeof sel_radio == 'undefined' ){
							alert('Morate odabrati nesto!')
							an.css("background-color","#ffaaaa");
						}
						else{
							$.ImpromptuGoToState('state6');//go forward
						}
					}
					else 
						if (v = -1) 
							$.ImpromptuGoToState('state4');//go back
				return false;
			}
		},
		
		
		state6: {
			html:'<p>7. Koji je minimalni zahtevani nivo obrazovanja za ovu poziciju?</p>  <div class="field"> 	<input type="radio" name="ldp_q7" id="ldp_q7_1" value="1" class="radioinput" /> 	<label for="ldp_q7_1">SSS.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q7" id="ldp_q7_2" value="2" class="radioinput" /> 	<label for="ldp_q7_2">VŠS.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q7" id="ldp_q7_3" value="3" class="radioinput" /> 	<label for="ldp_q7_3">VSS.</label> </div> 	 <div class="field"> 	<input type="radio" name="ldp_q7" id="ldp_q7_4" value="4" class="radioinput" /> 	<label for="ldp_q7_4">Nije bitno.</label> </div>',
			buttons: { '<< Nazad': -1, 'Dalje >>': 1, Odustani: 0 },
			focus: 2,
			submit: function(v, m, f){
				if (v == 0) 
					jQuery.ImpromptuClose()
				else 
					if (v == 1) {
						an = m.children('.field'); 
						sel_radio = $("input[name='ldp_q7']:checked").val();
						if( typeof sel_radio == 'undefined' ){
							alert('Morate odabrati nesto!')
							an.css("background-color","#ffaaaa");
						}
						else{
							$.ImpromptuGoToState('state7');//go forward
						}
					}
					else 
						if (v = -1) 
							$.ImpromptuGoToState('state5');//go back
				return false;
			}
		},
		
		
		state7: {
			html:'<p>8. Koji je minimalni zahtevani nivo ISKUSTVA za ovu poziciju?</p>  <div class="field"> 	<input type="radio" name="ldp_q8" id="ldp_q8_1" value="1" class="radioinput" /> 	<label for="ldp_q8_1">Minimalno iskustvo.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q8" id="ldp_q8_2" value="2" class="radioinput" /> 	<label for="ldp_q8_2">Iskusan profesionalac.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q8" id="ldp_q8_3" value="3" class="radioinput" /> 	<label for="ldp_q8_3">Nije bitno.</label> </div>',
			buttons: { '<< Nazad': -1, 'Dalje >>': 1, Odustani: 0 },
			focus: 2,
			submit: function(v, m, f){
				if (v == 0) 
					jQuery.ImpromptuClose()
				else 
					if (v == 1) {
						an = m.children('.field'); 
						sel_radio = $("input[name='ldp_q8']:checked").val();
						if( typeof sel_radio == 'undefined' ){
							alert('Morate odabrati nesto!')
							an.css("background-color","#ffaaaa");
						}
						else{
							$.ImpromptuGoToState('state8');//go forward
						}
					}
					else 
						if (v = -1) 
							$.ImpromptuGoToState('state6');//go back
				return false;
			}
		},
		
		
		state8: {
			html:'<p>9. Koji je nivo kadra za ovu poziciju?</p>  <div class="field"> 	<input type="radio" name="ldp_q9" id="ldp_q9_1" value="1" class="radioinput" /> 	<label for="ldp_q9_1">Nije bitno.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q9" id="ldp_q9_2" value="2" class="radioinput" /> 	<label for="ldp_q9_2">Menadžerski (upravljački) kadar.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q9" id="ldp_q9_3" value="3" class="radioinput" /> 	<label for="ldp_q9_3">Srednji staf, specijalizovan za funkciju (osoba sa posebnim znanjima).</label> </div> 	 <div class="field"> 	<input type="radio" name="ldp_q9" id="ldp_q9_4" value="4" class="radioinput" /> 	<label for="ldp_q9_4">Izvršilac.</label> </div>',
			buttons: { '<< Nazad': -1, 'Dalje >>': 1, Odustani: 0 },
			focus: 2,
			submit: function(v, m, f){
				if (v == 0) 
					jQuery.ImpromptuClose()
				else 
					if (v == 1) {
						an = m.children('.field'); 
						sel_radio = $("input[name='ldp_q9']:checked").val();
						if( typeof sel_radio == 'undefined' ){
							alert('Morate odabrati nesto!')
							an.css("background-color","#ffaaaa");
						}
						else{
							$.ImpromptuGoToState('state9');//go forward
						}
					}
					else 
						if (v = -1) 
							$.ImpromptuGoToState('state7');//go back
				return false;
			}
		},
		
		state9: {
			html:'<p>10. Šta Vam je važnije prilikom objave oglasa?</p>  <div class="field"> 	<input type="radio" name="ldp_q10" id="ldp_q10_1" value="1" class="radioinput" /> 	<label for="ldp_q10_1">Broj i kvalitet prijava.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q10" id="ldp_q10_2" value="2" class="radioinput" /> 	<label for="ldp_q10_2">Ušteda.</label> </div>  <div class="field"> 	<input type="radio" name="ldp_q10" id="ldp_q10_3" value="3" class="radioinput" /> 	<label for="ldp_q10_3">Podjednako.</label> </div>',
			buttons: { '<< Nazad': -1, Završi: 1, Odustani: 0 },
			focus: 2,
			submit:function(v,m,f){ 
				if(v==0) 
					jQuery.ImpromptuClose()
				else if(v==1){
					an = m.children('.field'); 
					sel_radio = $("input[name='ldp_q10']:checked").val();
					if( typeof sel_radio == 'undefined' ){
						alert('Morate odabrati nesto!')
						an.css("background-color","#ffaaaa");
					}
					else{
						return true; //we're done
					}
				}				
				else if(v=-1)
					$.ImpromptuGoToState('state8');//go back
				return false; 
			}
		}
	}

	$.prompt(temp,{
		// callback: function(v,m,f){ 
			// var str = "You can now process with this given information:<br />";
			// $.each(f,function(i,obj){ 
				// str += i + " - <em>" + obj + "</em><br />";
			// });	
			// $.prompt(str);
		// }
		
		callback: function(v,m,f){ 
			
			$.each(f,function(i,obj){ 
				oglas.total(i, obj);
			});	
			
			my_options = oglas.best_choice();
			
			myhtml = oglas.get_html(my_options);
			
			my_buttons = { 'Odustani' : false, "OPCIJA 1": my_options[0], "OPCIJA 2": my_options[1] };
			//eval( "my_buttons = { 'Odustani' : false, "+my_options[0]+": my_options[0], "+my_options[1]+": my_options[1] };");
			
			$.prompt( myhtml,{
				  callback: mycallbackform,
				  buttons: my_buttons
			});
			
			//DumperAlert(oglas);
			
			//$.prompt(str);
		}
	});
}