var _show_assessment_form = false;
//var _login_timeout_id = null;
var _timer = null;

/* --------------------------------------------------------------------------------------- *
 * Login
 * --------------------------------------------------------------------------------------- */
function init_login()
{
	return;
}

function show_login()
{
	$('#login-area-id').fadeIn();
//	$('#login-area-id').show();
	$('#login-name').focus();
//	_login_timeout_id = window.setTimeout( "hide_login();", 8000 );

	// lösche den Timer, wenn eines der Eingabefelder aktiviert wurde
//	$('#login-name,#login-pwd').click( function(){
//		window.clearTimeout( _login_timeout_id );
//	});
}

function hide_login()
{
	$('#login-area-id').fadeOut();
//	$('#login-area-id').slideUp();
}

function login()
{
	var loginname = $('#login-name').val();
	var loginpwd = $('#login-pwd').val();

	if( !!loginname == false || !!loginpwd == false ){
		alert("Please enter all needed login-data!");
		return;
	}

	var ajax = new msAjax();
	ajax.send(
		'login',
		function( result ){
			if( !!result == true ){
				location.reload();
			}else{
				alert("Einloggen nicht möglich");
			}
		},
		{
			'loginname'	: loginname,
			'loginpwd'	: loginpwd
		}
	);
}

function logout()
{
	var ajax = new msAjax();
	ajax.send(
		'logout',
		function( $result ){
			location.reload();
		}
	);
}

/* --------------------------------------------------------------------------------------- *
 * 
 * --------------------------------------------------------------------------------------- */
function hide_submenu( sm )
{
	$('#' + sm).hide();
}

function show_submenu( sm )
{
	$('#' + sm).show();
}

function show_assessment_form( yes, no )
{
	if( !!_show_assessment_form == false )
	{
		_show_assessment_form = true;
		$('#your_assessment').fadeIn( 1000 );
		$('#yes_i_would').html( no );
	}
	else
	{
		_show_assessment_form = false;
		$('#your_assessment').fadeOut( 1000 );
		$('#yes_i_would').html( yes );
	}
}

function show_content( id )
{
/*	$('.canopen').hide();
	$('#' + id).fadeIn();*/
}

/* --------------------------------------------------------------------------------------- *
 *
 * --------------------------------------------------------------------------------------- */
function unblock()
{
	$.unblockUI();
}

/* --------------------------------------------------------------------------------------- *
 *
 * --------------------------------------------------------------------------------------- */
function locked_download_dlg( lang, file, link, info, sect )
{
	var ajax = new msAjax();
	ajax.send(
		'locked_download_dlg',
		function( result ){
			if( !!result.status == true ){
				$.blockUI({ message: result.widget });
			}else{
				alert("Download nicht möglich");
			}
		},
		{
			'lang' : lang,
			'file' : file,
			'sect' : sect,
			'link' : link,
			'info' : info
		}
	);
}

/* --------------------------------------------------------------------------------------- *
 *
 * --------------------------------------------------------------------------------------- */
function locked_download( lang, file, link, info, sect )
{
	var pwd = $('#pwd-id').val();
	unblock();

	var ajax = new msAjax();
	ajax.send(
		'locked_download',
		function( result ){
			if( !!result.status == true ){
				$.blockUI({ message: result.widget });
			}else{
				alert( result.msg );
			}
		},
		{
			'lang' : lang,
			'file' : file,
			'sect' : sect,
			'link' : link,
			'info' : info,
			'pwd'  : pwd
		}
	);
}

/* --------------------------------------------------------------------------------------- *
 * shop_menu_products
 * --------------------------------------------------------------------------------------- */
function shop_menu_products()
{
	$('#prod-list').show();
	return;
}

/* --------------------------------------------------------------------------------------- *
 * switch_headline
 * --------------------------------------------------------------------------------------- */
function switch_headline()
{
	$('#fair-id').animate({
		"opacity" : "toggle"
		},{duration: 1000});
	$('#training-id').animate({
		opacity: "toggle"
		},{duration: 1000});
}

function start_interval()
{
	_timer = setInterval("switch_headline()",10000);
}

function add_prod_req( title, cnt_id, type, src )
{
	cnt = $('#' + cnt_id).val();
//	alert("type = " + type + "\ntitle = " + title + "\ncnt = " + cnt );

	var ajax = new msAjax();
	ajax.send(
		'add_prod_req',
		function( result ){
			if( !!result.status == true ){
				location.reload();
			}else{
				alert( result.msg );
			}
		},
		{
			'title' : title,
			'cnt'  : cnt,
			'type' : type,
			'src' : src
		}
	);
}

function rem_prod_req( type, title )
{
	var ajax = new msAjax();
	ajax.send(
		'rem_prod_req',
		function( result ){
			if( !!result.status == true ){
				location.reload();
			}else{
				alert( result.msg );
			}
		},
		{
			'title' : title,
			'type' : type
		}
	);
}

function send_prod_req()
{
	firm = $('#firm_id').val();
	name = $('#name_id').val();
	firstname = $('#firstname_id').val();
	street = $('#street_id').val();
	zip = $('#zip_id').val();
	place = $('#location_id').val();
	land = $('#country_id').val();
	phone = $('#phone_id').val();
	fax = $('#fax_id').val();
	email = $('#email_id').val();
	msg = $('#msg_id').val();
	var ajax = new msAjax();
	ajax.send(
		'send_prod_req',
		function( result ){
			if( !!result.status == true ){
				//location.reload();
				$('#prod-req-form').html( result.template );
			}else{
				cnt = result.errors.length;
				for( i = 0; i < cnt; i++ ){
					$('#' + result.errors[i].id).html( result.errors[i].err ).show();
				}
			}
		},
		{
			'firm' : firm,
			'name' : name,
			'fname' : firstname,
			'street' : street,
			'zip' : zip,
			'place' : place,
			'country' : land,
			'phone' : phone,
			'fax' : fax,
			'email' : email,
			'msg' : msg
		}
	);
}
