

function printPage()
{
	if (window.print)
		window.print()
  else
		alert("Your browser probably does't support Javascript");
}
var windowNote;
function showPic(title, pic, colorBack, wid, hei, idee)
{
	var idee = idee|| "default";
	windowNote = window.open('','Note'+ idee,'top=5, left=5, toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=' + wid + ',height='+ hei);
	image = '<a href="javascript:window.close()"><img src="'+ pic +'" width="'+ wid +'" height="'+ hei +'" border="0" alt="X"></a>';
	text = "<html><head><META HTTP-EQUIV=\"imagetoolbar\" CONTENT=\"no\"><title>"+ title + "</title></head><body bgcolor=\"#" + colorBack +"\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">" + image + "</body></html>";
	windowNote.document.write(text);
	windowNote.focus();
	windowNote.document.close();
	return false;
}
var type = "IE";
BrowserSniffer();
function BrowserSniffer()
{
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";	//Opera
	else if (document.all) type="IE";							//Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN";							//Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO";				//Mozila e.g. Netscape 6 upwards
	else type = "IE";									//I assume it will not get here
}
function hide_div(div_name)
{
	if (type=="IE") eval("document.all."+div_name+".style.display='none'");
	if (type=="NN") eval("document."+div_name+".display='none'");
	if (type=="MO" || type=="OP") eval("document.getElementById(div_name).style.display='none'");
}
function showhide_div(div_name)
{
	if (type=="IE")
	{
		if(eval("document.all."+div_name+".style.display")!='none')
		{
			eval("document.all."+div_name+".style.display='none'");
		}
		else
		{
			eval("document.all."+div_name+".style.display='block'");
		}
	}
	if (type=="NN")
	{
		if(eval("document."+div_name+".display")!='none')
		{
			eval("document."+div_name+".display='none'");
		}
		else
		{
			eval("document."+div_name+".display='block'");
		}
	}
	if (type=="MO" || type=="OP")
	{
		if(eval("document.getElementById(div_name).style.display")!='none')
		{
			eval("document.getElementById(div_name).style.display='none'");
		}
		else
		{
			eval("document.getElementById(div_name).style.display='block'");
		}
	}
}
function submit_form(element_name)
{
	document.getElementById(element_name).submit();
}
function reset_form()
{
	document.getElementById('vorm').reset();
}
function change_picture(id)
{
	document.getElementById('mainpic').src=id;
	
}

Ext.BLANK_IMAGE_URL = '/images/s.gif';
Ext.ns('quicsearch');
quicsearch = function() {
    
	var requesturl = 'http://gf.rong.ee/edel-web/do/search';
	Ext.DatePicker.prototype.startDay = 1;
	
	var convertelements = function(){
		
		if(Ext.getDom('hash')){
			var jsessionid = ';jsessionid='+Ext.getDom('hash').value;
		}else{
			var jsessionid = '';
		}
    	
		//console.log(requesturl+jsessionid);
		
		var tofield = new Ext.form.ComboBox({
			id:'to',
            typeAhead: true,
            triggerAction: 'all',
            transform:'to',
            width:170,
            forceSelection:true
        });
        
        var fromfield = new Ext.form.ComboBox({
        	id:'from',
            typeAhead: true,
            triggerAction: 'all',
            transform:'from',
            width:170,
            forceSelection:true
        });
        
        var datepicker = new Ext.form.DateField({
        	id:'date',
        	startDay: '1', 
            allowBlank:false,
            format: "d.m.Y",
            width:170,
    		applyTo: Ext.get("date"),
    		listeners: {
    		     render: function(){
    		          this.menuListeners.select = function(m, d){
    		                this.setValue(d);
    		                if(Ext.get("iframe")){
    		                	Ext.getDom('request_form').action=requesturl+jsessionid;
    		                	Ext.getDom('request_form').target='iframe';
    		                	Ext.getDom('request_form').submit();
    		                }else{
    		                	Ext.getDom('request_form').submit();
    		                }
    		           }
    		      }
    		 }
        });
    }
	
	var submitsearch = function (fromvalue, tovalue, datevalue){
		if(Ext.getDom('hash')){
			var jsessionid = ';jsessionid='+Ext.getDom('hash').value;
		}else{
			var jsessionid = '';
		}
		
		Ext.getCmp('from').setValue(fromvalue);
		Ext.getCmp('to').setValue(tovalue);
		Ext.getCmp('date').setValue(datevalue);
		Ext.getDom('request_form').action=requesturl+jsessionid;
		Ext.getDom('request_form').target='iframe';
		Ext.getDom('request_form').submit();
	}
	

	
	
    return {
    	
    	submitsearch:submitsearch,
        
    	init: function() {
            convertelements();
            
        }
    };
}();

Ext.onReady(quicsearch.init, quicsearch);