var registry = new Array();
registry['grid_prefixes'] = Array();

function go(t,id) {
	if (t.toString().indexOf('?') == -1 )
		t = t+'?';
	if ( id == "" ) return;
	window.location = t + 'industry__id=' + id;
}

function select_selected(list, selected_value) 
{
	var count = list.options.length;
 	for (var current = 0; current < count; current ++) 
 	{
  	if (list.options[current].value == selected_value) 
  	{
   		list.options[current].selected = "1";
   		break;
  	}
 	}
}

function zoom(an_image)
{
	var url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?t=image&image='+an_image;
	var width = 200;
	var height = 200;
	var screen_x = (screen.availWidth-width)/2;
	var screen_y = (screen.availHeight-height)/2;
	window.open(url, 'zoomed', 'width='+width+',height='+height+',resizable=yes,left='+screen_x+',top='+screen_y);	
}

function print_page(t)
{
	//var url = 'index.php?t='+t+'&mode=print'; // normal print
	var url = window.location.protocol + '//' + window.location.host + window.location.pathname + '?mode=print'; // for MOD REFRITE	
	var width = 640;
	var height = 500;
	var screen_x = (screen.availWidth-width)/2;
	var screen_y = (screen.availHeight-height)/2;
	window.open(url, 'print', 'width='+width+',height='+height+',resizable=yes,scrollbars=yes,left='+screen_x+',top='+screen_y);	
}

function submit_action(prefix, action_field, action)
{	
	document.kernel_form.elements[prefix + action_field].value = action;
	submit_kernel_form();
}

function submit_kernel_form()
{
	document.kernel_form.submit();
}

function SubmitCV(prefix, step)
{
	action_field = 'action_form';
	action = 'SubmitCV';
	document.kernel_form.elements[prefix + 'step'].value = step;
	submit_action(prefix, action_field, action);
}

function CopyHearAbout()
{
	for ( var i = 0 ; i < 10; i++ ) { 
		if ( document.kernel_form.hear_about[i].checked == true ) {
			number = i + 1;
			// alert(' number = ' + number);
			origin = document.kernel_form.elements['hear_about_'+number].value;
			document.kernel_form.elements['hear_about_text'].value = origin;	
		}
	}
}

function setSubAction(prefix, sub_action, item_id)
{
	// sets specific sub action (makes requested item selected if needed)
	if(item_id != null)
	{
		document.kernel_form.elements[prefix + 'id'].value = item_id;
		registry[prefix+'selected_count'] = 1; // one item selected	
	}
	submit_action(prefix, 'action_grid', sub_action);	
}

function submit_cv_action(prefix, action_field, action)
{	
	document.cv_form.elements[prefix + action_field].value = action;
	ocument.cv_form.submit();
}

function getStates(country_field, state_field)
{
	c_value = document.kernel_form.elements[country_field].value;

	country = '';
	state	  = '';
	s = '';
	
	var initial_length = document.kernel_form.elements[state_field].options.length;
	
	for (var i = initial_length - 1; i >= 0; i--) 	// obnuljaet massiv optionsov
		document.kernel_form.elements[state_field].options[i] = null; 
	
	if (c_value == 'CA' || c_value == 'US') {
		document.kernel_form.elements[state_field].disabled = false;
		document.kernel_form.elements[state_field].options[0] = new Option('', ''); // add an new empty option

		for(country in countries) { // base countries list
			if (c_value == country) {
				i=1;
				for(state in countries[country]) { // base states list
					//s = s + " => "+  state +"\n";
					document.kernel_form.elements[state_field].options[i] = new Option(countries[country][state], state);
					i++;
				}
			}
		}					
		//alert("States array is: \n" + s);
	}
	else {
		document.kernel_form.elements[state_field].options[0] = new Option('', ''); // add an new empty option
		document.kernel_form.elements[state_field].disabled = true;
	}
}

function show_image(id, img_src)
{
	document.getElementById(id).src = img_src;
}
