function ow ( s_url, i_w, i_h )
{
	var i_width = i_w;
	var i_height = i_h;

	if ( i_width > screen.width - 50 ) i_width = screen.width - 50;
	if ( i_height > screen.height - 50 ) i_height = screen.height - 50;

	var i_pos_x = ( screen.width - i_width - 10 ) / 2;
	var i_pos_y = ( screen.height - i_height - 29 ) / 2;
   
	if ( typeof ( pop_win ) == "undefined" || pop_win.closed ) pop_win = window.open ( s_url, 'pop_win', 'menubar=0,toolbar=0,location=0,scrollbars=0,screenX='+i_pos_x+',screenY='+i_pos_y+',left='+i_pos_x+',top='+i_pos_y+',width='+i_width+',height='+i_height+',resizable=0');
	else pop_win.location.href = s_url;
  
	pop_win.focus ();
}
function ProductServiceAim1 ()
{
	document.forms['form_registracia'].elements['ProductService'][0].checked = true;
	
	ProductService1 ();
}
function Producer1 ()
{
	document.forms['form_registracia'].elements['ProductService'][1].checked = true;
	
	ProductService1 ();
}
function ProductService1 ()
{
	var o_form = document.forms['form_registracia'];
	var o_obj = o_form.elements['ProductService'];
	
	if ( o_obj[0].checked )
	{
		o_form.elements['Producer'].checked = false;
	}else if ( o_obj[1].checked )
	{
		var i_length = o_form.elements['ProductServiceAim'].length;		
		for ( var i=0; i<i_length; i++ )
		{
			o_form.elements['ProductServiceAim'][i].checked = false;
		}
	}

	o_form.elements['odvetvie'].value = '';
	o_form.elements['odvetvie_names'].value = '';
	
	Branch ( false, 'odvetvie' );
}
function ProductServiceAim2 ()
{
	document.forms['form_registracia'].elements['ProductService'][1].checked = true;
	
	ProductService2 ();
}
function ProductService2 ()
{
	var o_form = document.forms['form_registracia'];
	var o_obj = o_form.elements['ProductService'];
	
	if ( o_obj[0].checked || o_obj[2].checked ) o_form.elements['ProductServiceAim'].selectedIndex = 0;

	o_form.elements['odvetvie'].value = '';
	o_form.elements['odvetvie_names'].value = '';
	
	Branch ( false, 'odvetvie' );
}
function Contacts ( s_url, i_w, i_h )
{
	ow ( s_url, i_w, i_h );
}
function AddContact ( s_id, s_name, s_obj )
{	
	var o_contacts      = top.opener.document.forms['form_reaction'].elements[s_obj];
	var o_contacts_names = top.opener.document.forms['form_reaction'].elements[s_obj + '_names'];

	if ( o_contacts == null || o_contacts_names == null ) return;
	if ( o_contacts.value.indexOf ( '|' + s_id + '|' ) != -1 ) return;	

	{
		if ( o_contacts.value == '' )
		{
			o_contacts.value = '|';
			o_contacts_names.value = '|';
		}
	
		o_contacts.value += s_id + '|';
		o_contacts_names.value += s_name + '|';
	}

 
	Contact( s_obj );
}
function Contact ( s_obj )
{
	var w = top.opener;
	if ( w == null )     w = window; 
	
	var o_branch         = w.document.getElementById ( s_obj + '_branch' );
	var o_contacts       = w.document.forms['form_reaction'].elements[s_obj];
	var o_contacts_names = w.document.forms['form_reaction'].elements[s_obj + '_names'];	
		
	if ( o_branch == null || o_contacts == null || o_contacts_names == null ) return;

	var a_contacts = o_contacts.value.split ( '|' );
	var a_contacts_names = o_contacts_names.value.split ( '|' );
	var i_contacts = a_contacts.length;
	
	var s_branch = '';
	
	for ( i=1; i<i_contacts-1; i++ )
	{
		var s_contact = a_contacts[i];
		var s_contact_name = a_contacts_names[i];
	
		s_branch += '<div><a href="javascript:KillContact(\'' + s_contact + '\',\'' + s_contact_name + '\',\'' + s_obj + '\')" title="' + s_contact_name + '">' + s_contact_name + '</a></div>';
	}
	if ( i_contacts >= 3 && o_branch.style.visibility != 'visible' )
	{
		o_branch.style.visibility = 'visible';		
	}else if ( i_contacts < 3 && o_branch.style.visibility != 'hidden' )
	{
		o_branch.style.visibility = 'hidden';
	}
	
	o_branch.innerHTML = s_branch;	
}
function KillContact( s_id, s_name, s_obj )
{
	var o_contacts      =  document.forms['form_reaction'].elements[s_obj];
	var o_contacts_names = document.forms['form_reaction'].elements[s_obj + '_names'];	
	
	o_contacts.value = o_contacts.value.replace ( '|' + s_id + '|', '|' );
	if ( o_contacts.value == '|' ) o_contacts.value = '';
	
	o_contacts_names.value = o_contacts_names.value.replace ( '|' + s_name + '|', '|' );
	if ( o_contacts_names.value == '|' ) o_contacts_names.value = '';
	
	Contact( s_obj );
}
function Branches ( s_url, i_w, i_h )
{
	var o_obj = document.forms['form_registracia'].elements['ProductServiceAim'];
	
	if ( o_obj[0].checked ) s_url += '&amp;subcontracts=1';
	
	ow ( s_url, i_w, i_h );
}
function Branches1 ( s_url, i_w, i_h )
{
	var o_obj = document.forms['form_registracia'].elements['ProductService'];
	
	if ( o_obj.options[o_obj.selectedIndex].value == 11 ) s_url += '&amp;search=1&amp;subcontracts=1';
	
	ow ( s_url, i_w, i_h );
}
function AddBranch ( s_id, s_name, i_single, s_obj )
{	
	var o_odvetvie = top.opener.document.forms['form_registracia'].elements[s_obj];
	var o_odvetvie_names = top.opener.document.forms['form_registracia'].elements[s_obj + '_names'];
	
	if ( o_odvetvie == null || o_odvetvie_names == null ) return;

	if ( o_odvetvie.value.indexOf ( '|' + s_id + '|' ) != -1 ) return;	

	if ( i_single == '1' )
	{
		o_odvetvie.value = '|' + s_id + '|';
		o_odvetvie_names.value = '|' + s_name + '|';
	}else
	{
		if ( o_odvetvie.value == '' )
		{
			o_odvetvie.value = '|';
			o_odvetvie_names.value = '|';
		}
	
		o_odvetvie.value += s_id + '|';
		o_odvetvie_names.value += s_name + '|';
	}
	
	Branch ( i_single == 1, s_obj );
}
function KillBranch ( s_id, s_name, s_obj )
{
	var o_odvetvie = document.forms['form_registracia'].elements[s_obj];
	var o_odvetvie_names = document.forms['form_registracia'].elements[s_obj+'_names'];
	
	o_odvetvie.value = o_odvetvie.value.replace ( '|' + s_id + '|', '|' );
	if ( o_odvetvie.value == '|' ) o_odvetvie.value = '';
	
	o_odvetvie_names.value = o_odvetvie_names.value.replace ( '|' + s_name + '|', '|' );
	if ( o_odvetvie_names.value == '|' ) o_odvetvie_names.value = '';
	
	Branch ( false, s_obj );
}
function Branch ( b_close, s_obj )
{
	if ( top.opener == null )
	{
		if ( document.forms['form_registracia'].elements[s_obj] == null ) return;
		else
		{
			var o_branch = document.getElementById ( s_obj + '_branch' );
			var o_odvetvie = document.forms['form_registracia'].elements[s_obj];
			var o_odvetvie_names = document.forms['form_registracia'].elements[s_obj + '_names'];
		}			
	}else
	{
		var o_branch = top.opener.document.getElementById ( s_obj + '_branch' );
		var o_odvetvie = top.opener.document.forms['form_registracia'].elements[s_obj];
		var o_odvetvie_names = top.opener.document.forms['form_registracia'].elements[s_obj + '_names'];
	}
	
	var a_odvetvie = o_odvetvie.value.split ( '|' );
	var a_odvetvie_names = o_odvetvie_names.value.split ( '|' );
	var i_odvetvie = a_odvetvie.length;
	
	var s_branch = '';
	
	for ( i=1; i<i_odvetvie-1; i++ )
	{
		var s_odvetvie = a_odvetvie[i];
		var s_odvetvie_name = a_odvetvie_names[i];
	
		s_branch += '<div><a href="javascript:KillBranch(\'' + s_odvetvie + '\',\'' + s_odvetvie_name + '\',\'' + s_obj + '\')" title="' + s_odvetvie_name + '">' + s_odvetvie_name + '</a></div>';
	}
	
	if ( i_odvetvie >= 3 && o_branch.style.visibility != 'visible' )
	{
		o_branch.style.visibility = 'visible';		
	}else if ( i_odvetvie < 3 && o_branch.style.visibility != 'hidden' )
	{
		o_branch.style.visibility = 'hidden';
	}
	
	o_branch.innerHTML = s_branch;
	
	if ( b_close ) top.window.close ();
}
function FormTrigger ( o_elem )
{
	if ( o_elem.elements['ProductService'].value == '2' || o_elem.elements['ProductService'].value == '1' )
	{
		o_elem.action = '/?7';
	}else
	{
		o_elem.action = '/?8';
	}
}
function FormTriggerEN ( o_elem )
{
	if ( o_elem.elements['ProductService'].value == '2' || o_elem.elements['ProductService'].value == '1' )
	{
		o_elem.action = '/?46';
	}else
	{
		o_elem.action = '/?47';
	}
}
function AdvancedSearch ()
{
	var o_form = document.forms['form_search'];
	o_form.elements['text'].value = '';
	FormTrigger ( o_form );
	o_form.submit ();
}
function AdvancedSearchEN ()
{
	var o_form = document.forms['form_search'];
	o_form.elements['text'].value = '';
	FormTriggerEN ( o_form );
	o_form.submit ();
}
s_action = "";
function DoExportOffer ( o_form, s_lang )
{
	if ( s_action == "" ) s_action = o_form.action;
	o_form.action = '/swift_data/scripts/offer/offer.php?what=export_' + s_lang;
}
function DoSearchOffer ( o_form )
{
	if ( s_action != "" ) o_form.action = s_action;
}
function DoExportRegister ( o_form, s_lang )
{
	o_form.action = '/swift_data/scripts/register/register.php?what=export_' + s_lang;
}
