// helpers for public site, pure JS - no ajax helpers
function preventDoubleSubmit( element_id ){
	try {
		var but = document.getElementById(element_id);
		but.disabled = true;
	} catch (e) {}
}



function columnize ( div_id, columns_amount, min_length )
{
	var the_div = document.getElementById(div_id);
	if (the_div == null) { return; }
	
	var div_content = the_div.innerHTML;
	var cont_length = div_content.length;
	
	if (cont_length < min_length) { return; }
	
	if (columns_amount == 2) {
		var start_pos = cont_length / 2;
		var myRegExp1 = /<div|<p|<br<li/;
		
		
		var sec_col_content = div_content.substr( start_pos);
		var matchPos = sec_col_content.search(myRegExp1);
		if (matchPos == -1 ){ return;}
		
		var first_col_content = div_content.substr( 0, start_pos + matchPos);
		sec_col_content = sec_col_content.substr (matchPos);

		the_div.innerHTML = '<div class="left_column">' + first_col_content + '</div>';

		the_div.innerHTML += '<div class="right_column">' + sec_col_content + '</div>';
		the_div.innerHTML += '<div class="clear"> </div>';

	}
}


function doFoldWithImage ( source_image_id, destination_element_id) {
	destination_element = document.getElementById( destination_element_id );
	source_image = document.getElementById( source_image_id );
	
	if ( destination_element.style.display == 'block' ) {
		destination_element.style.display = 'none';
		source_image.src = '/img/icon_plus_1.gif';
	} else {
		destination_element.style.display = 'block';
		source_image.src = '/img/icon_minus_1.gif';
	}
}


//======================================================================
var soundEmbed = null;
//======================================================================
function soundPlay(which, focus_on_element_id){
    if (!soundEmbed)
        {
        soundEmbed = document.createElement("embed");
        soundEmbed.setAttribute("src", "/img/snd/"+which+".wav");
        soundEmbed.setAttribute("hidden", true);
        soundEmbed.setAttribute("autostart", true);
        }
    else
        {
        document.body.removeChild(soundEmbed);
        soundEmbed.removed = true;
        soundEmbed = null;
        soundEmbed = document.createElement("embed");
        soundEmbed.setAttribute("src", "/img/snd/"+which+".wav");
        soundEmbed.setAttribute("hidden", true);
        soundEmbed.setAttribute("autostart", true);
        }
    soundEmbed.removed = false;
    document.body.appendChild(soundEmbed);
	
	if (focus_on_element_id != null) {
		document.getElementById(focus_on_element_id).focus();	
	}
}
