/* ## Common Javascript Functions ############### */
var $pic_selected = 0;

function change_lang( $curr ) {
	var $sel = document.all['frm'].language[document.all['frm'].language.selectedIndex].value;

	if ( $sel != undefined ) {
		if ( $sel != "" ) {
			if ( $sel != $curr ) {
				set_cookie( "co_user_lang", $sel, true );
				document.location.reload();
			}
		}
	}
}

function set_cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 4800;
	}

	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" + escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function get_cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;
	
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )	{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}

			return cookie_value;
			break;
		}

		a_temp_cookie = null;
		cookie_name = '';
	}

	if ( !b_cookie_found )
		return null;
}

function showMenu( $id, $url ) {
	var $lang = get_cookie( 'co_user_lang' );
	document.all['menu_1'].src = document.all['menu_1'].src.replace("_y", "_b");
	document.all['menu_2'].src = document.all['menu_2'].src.replace("_y", "_b");
	document.all['menu_3'].src = document.all['menu_3'].src.replace("_y", "_b");
	document.all['menu_4'].src = document.all['menu_4'].src.replace("_y", "_b");
	document.all['menu_5'].src = document.all['menu_5'].src.replace("_y", "_b");
	document.all['menu_6'].src = document.all['menu_6'].src.replace("_y", "_b");

	document.all['menu_'+$id].src = document.all['menu_'+$id].src.replace("_b", "_y");
	document.all['img_page_header'].src = "images/" + $lang + "/header_" + $url + ".gif";

	document.all['pg_content'].src = $url + ".php";
}

function change_picture( $photo_title, $photo ) {
	document.all['main_pic'].src = "admin/photos/gallery_" + $photo;
	document.all['main_text'].innerHTML = "<center>" + $photo_title + "</center>";
}

function prev_picture() {
	$pic_selected--;
	if ( $pic_selected < 0 ) $pic_selected = 0;
	change_picture( document.all["small_" + $pic_selected].className, document.all["small_" + $pic_selected].alt );
}

function next_picture( $max ) {
	$pic_selected++;
	if ( $pic_selected >= $max ) $pic_selected = $max-1;

	change_picture( document.all["small_" + $pic_selected].className, document.all["small_" + $pic_selected].alt );
}

function open_construct() {
	document.all['pg_content'].src = "construct.php";
}