function OBJ_Search_Symbol()
{
	this.search_symbol_demo_running = false; // positon reader on/off

	this.show_symbol = function(image, x, y, code, competition_id, competition_type, symbol_id)
	{
		document.write('<img src="http://i.tvnet.lv/search_symbol/'+image+'" style="position:absolute; z-index:9000; top:'+y+'px; left:'+x+'px; cursor: pointer;" onclick="');

		if(competition_type==1)
			document.write('SEARCH_SYMBOL.open_register_form(this,\''+code+'\', '+competition_id+');');
		else
			document.write('SEARCH_SYMBOL.show_message(\''+code+'\', '+competition_id+', '+symbol_id+');');

		document.write('" />');
	}

	// symbol addition pannel
	this.show_symbol_panel = function(ss_lang, ss_site, ss_cat)
	{
		// pannel can use only when browser with is 1024px
		window.resizeTo(1024,800);

		// get site and cat
		var url = window.location.href;
		url = url.substr(0,url.length-24);
		var url_exploded = url.split('/');

		// control panel for demo mode
		document.write('<div style="position: fixed; top: 10px; left: 10px; width: 230px; height: 140px; background-color: #eee; border: 1px solid #ddd; z-index: 9000; padding: 3px;">');
		document.write('<h5>Meklējamo Simbolu Panelis</h5>');
		document.write('<label>x: </label><input style="width: 40px;" type="text" name="x" id="x" />');
		document.write('<label> y: </lable><input style="width: 40px;" type="text" name="y" id="y" />');
		document.write('<lable> valoda: </lable><input style="width: 30px;" type="text" name="ss_lang" id="ss_lang" value="'+ss_lang+'" /><br />');
		document.write('<lable>site: </lable><input style="width: 80xp;" type="text" name="ss_site" id="ss_site" value="'+ss_site+'" /><br />');
		document.write('<lable>kategorija: &nbsp;</lable><input style="width: 80xp;" type="text" name="ss_cat" id="ss_cat" value="'+ss_cat+'" /><br />');
		document.write('<input id="search_symbol_demo_starter" type="button" onclick="SEARCH_SYMBOL.search_symbol_demo_running=true;" value="Start" /><br /><em>(skaitītājs apstāsies izdarot dubulklikšķi)</em>');
		document.write('</div>');

		// stop position reader on double click
		document.ondblclick = function(e)
		{
			SEARCH_SYMBOL.search_symbol_demo_running=false;
		}

		// position reader
		document.onmousemove = function(ev)
		{
			if(SEARCH_SYMBOL.search_symbol_demo_running == true)
			{
				ev = ev || window.event;
				if(ev.pageX || ev.pageY)
				{
					document.getElementById('x').value = ev.pageX;
					document.getElementById('y').value = ev.pageY;
				}
				else
				{
					document.getElementById('x').value = ev.clientX + document.body.scrollLeft - document.body.clientLeft;
					document.getElementById('y').value = ev.clientY + document.body.scrollTop  - document.body.clientTop;
				}
			}
		};
	}

	this.show_message = function(code ,competition_id ,symbol_id)
	{
		window.open('http://www.tvnet.lv/ajax/showsearchsymbolinfo/'+code+'/'+competition_id+'/'+symbol_id,'' ,' height=170, width=340 ,left=200 ,top=200, toolbar=no, menubar=no, location=no, status=no, directories=no');
	}

	this.open_register_form = function(obj,code,competition_id)
	{
		//obj.style.display='none';

		var reg_form=window.open('/search_symbol.html','' ,' height=170, width=340 ,left=200 ,top=200, toolbar=no, menubar=no, location=no, status=no, directories=no');
        reg_form.document.write('<scr' + 'ipt type="text/javascript" src="/assets/js/search_symbol.js"></script>');
        reg_form.document.write('<scr' + 'ipt type="text/javascript" src="/assets/js/jquery-1.3.2.min.js"></script>');
        reg_form.document.write('<style type="text/css" > ');
        reg_form.document.write('label { font-weight: bold; } ');
        reg_form.document.write('body { color:#343434; font-family:Verdana,Geneva,Helvetica,Arial,sans-serif; font-size: 12px; } ');
        reg_form.document.write('.text_field { border:0.083em solid #999999; margin-bottom:0.25em; padding:0.25em; -moz-border-radius:4px 4px 4px 4px; -webkit-border-radius:4px 4px 4px 4px; width: 250px; } ');
        reg_form.document.write('.orange_button { -moz-border-radius:4px 4px 4px 4px; -webkit-border-radius:4px 4px 4px 4px; background-color:#FF6600; border:0.0833em solid #FF6600; color:#FFFFFF; padding:0.167em; margin-left: 20px; } ');
        reg_form.document.write('.center_content { text-align: center; } ');
        reg_form.document.write('.red { color: #FF6600; } ');
        reg_form.document.write('a, a:hover { color: #FF6600; } ');
        reg_form.document.write('</style> ');

        reg_form.document.write('<p id="search_symbol_info_text" class="center_content">');
        reg_form.document.write('<b>Ievadi savu e-pasta adresi lai piereģistrētu atrasto RAMMSTEIN logo!</b><br />');
        reg_form.document.write('Klausies arī "Radio SWH Rock" un uzzini kā vari piedalīties lielā komplekta izlozē. Visa informācija <a href="http://www.radioswh.lv/swhrock/page.php?id=322" target="_blank" >„Radio SWH Rock” mājas lapā.</a>');
        reg_form.document.write('</p>');

        reg_form.document.write('<form method="post">');
        reg_form.document.write('<input type="hidden" name="code" id="code" value="'+code+'">');

        reg_form.document.write('<div class="bottom_margin center_content">');
        reg_form.document.write('<label for="e_mail">e-pasts:</lable> <input class="text_field" type="text" name="e_mail" id="e_mail" >');
        reg_form.document.write('</div>');

        reg_form.document.write('<div class="center_content">');
        reg_form.document.write('<input class="orange_button" type="button" onclick="SEARCH_SYMBOL.send();" value="Sūtīt" >');
        reg_form.document.write('<input class="orange_button" type="button" onclick="self.close();" value="Aizvērt" >');
        reg_form.document.write('</div>');

        reg_form.document.write('</form>');

        reg_form.document.close();
	}


	this.send = function()
	{
    	var check = false;

		var info_text = $('#search_symbol_info_text');
 		var code = $('#code').val();
 		var e_mail = $('#e_mail').val();

		// chect wether all fields filled
		if(code.length > 0 && e_mail.length > 0)
			check = true;
		else
			check = false;

		if(check == true)
		{
			// post data and save success message
			$.post( '/ajax/saveSearchSymbol',
			{ code: code, e_mail: e_mail },
  			function(data){	if(data == 'success') info_text.html('<em>Veiksmīgi piereģistrēts logo!</em>'); else info_text.html('<em class="red"><b>Kļūda!</b> Šo logo esat jau iepriekš piereģistrējis!</em>'); },
  			"html");
		}
		else
		{
			// show error message
			info_text.html('<em class="red"><b>Kļūda!</b> Pārbaudiet vai e-pasts ievadīts korekti!</em>');
		}

	}

}

var SEARCH_SYMBOL = new OBJ_Search_Symbol();

