dojo.require("dojo.dnd.Moveable");

var _ie = (navigator.appName == "Microsoft Internet Explorer");
var _opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
var _mozilla = (navigator.userAgent.toLowerCase().indexOf("mozilla") != -1);
var ie_version = parseFloat(navigator.appVersion.split("MSIE")[1]);
var legendTooltipShown = false;
var codeTooltipShown = false;
var homePageTooltipShown = true;
var vehiclesAndSeatsTooltipShown = false;
var summaryIncludeTooltipShown = false;
var saleOKMessageIncludeShown = false;
var windowIncludeShown = false;
var intervalLegendTooltip = 0;
var intervalCodeTooltip = 0;
var showCodeDiv = document.createElement('div');
var sessionAlertShown = false;
var sessionActive = true;
var showReturnFilters = false;
var showFromFilters = true;
var showVehicleSeats = false;
var showVehicleReturnSeats = false;
var departure = 0;
var arrive = 1;
var allTicketsCount = 0;
var ticketsTypeArr = null;
var ticketsTypeIdArr = null;
var ticketsNameArr = null;
var ticketsPriceArr = null;
var ticketsDirectionArr = null;
var currentTravelListId = -1;
var currentTypesIdArr = null;
var currentTypesCountArr = null;
var showNextTickets = 1;
var showPreviousTickets = -1;
var numberOfLockedSeats = 0;
var numberOfLockedReturnSeats = 0;
var totalSelectTicketsCount = 0;
var totalSelectTicketsPrice = 0;
var ticketDirectionEachWay = 0;
var ticketDirectionOneWay = 1;
var ticketDirectionTwoWay = 2;
var ticketDirectionBoth = 3;
var showOneWayTickets = false;
var showTwoWayTickets = false;
var ticketTypeOneWay = -1;
var ticketTypeTwoWay = -2;
var ticketTypeDiscount = 0;
var flashLoadedTime = '0,0';
var showSummaryBtn = false;
var canPay = true;
var paymentsResults = new Array();
var paymentsCurrentPage = 1;
var paymentsPageCount = 1;
var paymentsResultsPerPage = 15;
var selectedSaleRowId = null;
var loadedEditData = new Array('','','','');  
var closingWindows = new Array();
var clickedOnWindowTitleBar = false;
var initFlashTimerObjectId = 'initFlashTimerObjectId';
var summaryFlashTimerObjectId = 'summaryFlashTimerObjectId';
var saleCodeCheckInterval = 0;
var saleCodeCheckDelay = 1000;

var filterFromDate = 0;
var filterStartPointId = 1;
var filterEndPointId = 2;
var filterFromHour = 3;
var filterReturnDate = 4;
var filterReturnHour = 5;

var navigatorFirstButtonPressed = 0;
var navigatorLeftButtonPressed = 1;
var navigatorRightButtonPressed = 2;
var navigatorLastButtonPressed = 3;
var navigatorGoButtonPressed = 4;

var errorWindowShown = false;
var warningWindowShown = false;
var infoWindowShown = false;
var loginWindowShown = false;
var registrationConfirmTermsWindowShown = false;
var registrationSubmitWindowShown = false;
var registrationSuccessWindowShown = false;
var profileWindowShown = false;
var changePasswordWindowShown = false;
var paymentsWindowShown = false;
var paymentDetailsWindowShown = false;
var bucketWindowShown = false;
var forgottenPasswordRequestWindowShown = false;
var forgottenPasswordSetNewDataWindowShown = false;
var termsAndConditionsWindowShown = false; 
var privacyPolicyWindowShown = false;
var carterConditionsWindowShown = false;
var paymentOperatorsWindowShown = false;
var FAQWindowShown = false;
var helpWindowShown = false;
var contactsWindowShown = false;
var selectSeatWhenUserIsNotLoggedDIVWindowShown = false;
var sessionIsTimeOutWindowShown = false;
var canCloseWindow = true;
var filterBlocked = false;
var numberOfSummarizedTicket = 0;

var errorOKButton = 'error_ok_btn';
var warningOKButton = 'warning_ok_btn';
var infoOKButton = 'info_ok_btn';
var loginButton = 'login_btn';
var loginHomePageButton = 'login_homePage_btn';
var registrationButton = 'register_btn';
var registrationSuccessOKButton = 'register_success_ok_btn';
var clearRegistrationFormButton = 'clearRegistrationFormData_btn';
var editButton = 'edit_btn';
var editConfirmButton = 'edit_cofirm_btn';
var editReloadButton = 'edit_reload_btn';
var profileChangePasswordOKButton = 'profile_change_password_ok_btn';
var paymentsCurrentPageId = 'paymentsCurrentPageId';
var paymentsCurrentPageLabelId = 'paymentsCurrentPageLabelId';
var paymentDetailsPDFButton = 'payment_details_PDF_btn';
var bucketClearAllButton = 'bucket_clear_all_btn';
var forgottenPasswordContinueButton = 'fogotten_password_continue_btn';
var forgottenPasswordOKButton = 'fogotten_password_ok_btn';
var forgottenPasswordNewDataOKButton = 'fogotten_password_new_data_ok_btn';
var forgottenPasswordNewDataLoginButton = 'fogotten_password_new_data_login_btn';
var sessionIsTimeOutOKButton = 'sessionIsTimeOutOkButton';
var sessionIsTimeOutLoginButton = 'sessionIsTimeOutLoginButton';
var selectSeatWhenUserIsNotLoggedOKButton = 'selectSeatWhenUserIsNotLoggedOKButton';
var selectSeatWhenUserIsNotLoggedLoginButton = 'selectSeatWhenUserIsNotLoggedLoginButton';
var selectSeatWhenUserIsNotLoggedRegistrationButton = 'selectSeatWhenUserIsNotLoggedRegistrationButton';
var navigatorFirstButton = 'navigator_first_btn';
var navigatorLeftButton = 'navigator_left_btn';
var navigatorRightButton = 'navigator_right_btn';
var navigatorLastButton = 'navigator_last_btn';
var navigatorGoButton = 'navigator_go_btn';
var navigatorGoField = 'navigator_go_field';
var navigatorId = 'navigatorId';

var dumpDIVWindow = 'dumpDIVWindow';
var errorDIVWindow = 'errorDIVWindow';
var warningDIVWindow = 'warningDIVWindow';
var infoDIVWindow = 'infoDIVWindow';
var loginHomePageDIVWindow = 'loginHomePageDIVWindow';
var loginDIVWindow = 'loginDIVWindow';
var registrationConfirmTermsDIVWindow = 'registrationConfirmTermsDIVWindow';
var registrationSubmitDIVWindow = 'registrationSubmitDIVWindow';
var registrationSuccessDIVWindow = 'registrationSuccessDIVWindow';
var registrationDIVWindow = 'registrationDIVWindow';
var profileDIVWindow = 'profileDIVWindow';
var changePasswordDIVWindow = 'changePasswordDIVWindow';
var paymentsDIVWindow = 'paymentsDIVWindow';
var paymentDetailsDIVWindow = 'paymentDetailsDIVWindow';
var bucketDIVWindow = 'bucketDIVWindow';
var forgottenPasswordRequestDIVWindow = 'forgottenPasswordRequestDIVWindow';
var forgottenPasswordSetNewDataDIVWindow = 'forgottenPasswordSetNewDataDIVWindow';
var termsAndConditionsDIVWindow = 'termsAndConditionsDIVWindow';
var privacyPolicyDIVWindow = 'privacyPolicyDIVWindow';
var carterConditionsDIVWindow = 'carterConditionsDIVWindow';
var paymentOperatorsDIVWindow = 'paymentOperatorsDIVWindow';
var FAQDIVWindow = 'FAQDIVWindow';
var helpDIVWindow = 'helpDIVWindow';
var contactsDIVWindow = 'contactsDIVWindow';
var selectSeatWhenUserIsNotLoggedDIVWindow = 'selectSeatWhenUserIsNotLoggedDIVWindow';
var sessionIsTimeOutDIVWindow = 'sessionIsTimeOutDIVWindow';
var windowsArray = new Array(loginDIVWindow, registrationConfirmTermsDIVWindow, registrationSubmitDIVWindow, registrationSuccessDIVWindow, profileDIVWindow, changePasswordDIVWindow, paymentsDIVWindow, paymentDetailsDIVWindow, bucketDIVWindow, forgottenPasswordRequestDIVWindow, forgottenPasswordSetNewDataDIVWindow, termsAndConditionsDIVWindow, privacyPolicyDIVWindow, carterConditionsDIVWindow, paymentOperatorsDIVWindow, FAQDIVWindow, helpDIVWindow, contactsDIVWindow, selectSeatWhenUserIsNotLoggedDIVWindow, sessionIsTimeOutDIVWindow);
var windowContentId = 'windowContent_';
var windowButtomContentId = 'bottomContent_';
var windowTopContentId = 'topContent_';
var windowEngineId = 'windowEngineId_';
var windowTitleBarId = 'windowTitleBar_';
var sendToTopOperation = true;
var tmpCurrentDetailsWindowLeftPosition = 0;
var tmpCurrentDetailsWindowTopPosition = 0;
var tmpPaymentDetailsWindowLeftPosition = 0;
var tmpPaymentDetailsWindowTopPosition = 0;
var registrationResponse = responseSuccess;

var errorMsgId = 'error_msg'; 
var warningMsgId = 'warning_msg';
var infoMsgId = 'info_msg';
var loginHomePageErrMsgId = 'login_homePage_err_msg';
var loginErrMsgId = 'login_err_msg'; 
var forgottenPasswordRequestErrMsgId = 'forgotten_password_request_err_msg';
var forgottenPasswordSetNewDataErrMsgId = 'forgotten_password_set_new_data_err_msg';
var registrationErrMsgId = 'registration_err_msg';
var profileErrMsgId = 'profile_err_msg';
var changePasswordErrMsgId = 'change_password_err_msg';
var paymentErrMsgId = 'payment_err_msg';
var sessionTimeOutErrMsgId = 'session_time_out_err_msg';
var selectSeatWhenUserIsNotLoggedErrMsgId = 'select_seat_when_user_is_not_logged_err_msg';

var errorWindowWidth = 440;
var warningWindowWidth = 400;
var infoWindowWidth = 400;
var loginWindowWidth = 420;
var registrationConfirmTermsWindowWidth = 600;
var registrationSubmitWindowWidth = 600;
var registrationResultsWindowWidth = 500;
var profileWindowWidth = 480;
var changePasswordWindowWidth = 490;
var paymentsWindowWidth = 600;
var paymentDetailsWindowWidth = 600;
var bucketWindowWidth = 660;
var forgottenPaswordRequestWindowWidth = 450;
var forgottenPaswordSetNewDataWindowWidth = 450;
var termsAndConditionsWindowWidth = 600;
var privacyPolicyWindowWidth = 600;
var carterConditionsWindowWidth = 600;
var paymentOperatorsWindowWidth = 500;
var FAQWindowWidth = 540;
var helpWindowWidth = 680;
var contactsWindowWidth = 400;
var selectSeatWhenUserIsNotLoggedWindowWidth = 400;
var sessionIsTimeOutWindowWidth = 400;

var errorType = -1;
var warningType = 0;
var infoType = 1;
var blockSeats = true;

var	_allMonthBGName = new Array("Януари","Февруари","Март","Април","Май","Юни","Юли","Август","Септември","Октомври","Ноември","Декември");
var	_allMonthENName = new Array("January","February","March","April","May","June","July","August","September","October","November","December"); 

var _allDayBGName = new Array ("Понеделник","Вторник","Сряда","Четвъртък","Петък","Събота","Неделя");
var _allDayENName = new Array ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");

window.onresize = function clearTooltips() {
	// ;
};

function makeMoveable(node){
		var dnd = new dojo.dnd.Moveable(dojo.byId(node));
};
function makeMoveable(node, _handle){
		var dnd = new dojo.dnd.Moveable(dojo.byId(node), {handle: _handle});
};

function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet") == -1) {
		if (document.embeds && document.embeds[movieName]) {
			return document.embeds[movieName];
		}
	} else {
		return document.getElementById(movieName);
	}
};
function runFlashCountdownTimer(flashMovieName, value) {
	var flashMovie = getFlashMovieObject(flashMovieName);
	try {
		flashMovie.SetVariable("/:message", value);
	} catch (e) {;}
};
function receiveDataFromFlashMovie(flashMovieName) {
	var flashMovie = getFlashMovieObject(flashMovieName);
	var message = flashMovie.GetVariable("message_return");
	return message;
};
function moduleCloseOperation() {
	document.location.href = moduleClosedPage;
};
function sessionTimeOutOperation() {	
	sessionTimeAction();
};
function invalidParametersOperation() {	
	reloadHomePage();
};
function reloadHomePage() {
	document.location.href = moduleHomePage;
};

function StringBuffer() {
	this.buffer = []; 
};

StringBuffer.prototype.append = function(string) {
	this.buffer.push(string);
	return this;
};

StringBuffer.prototype.toString = function() {
	return this.buffer.join("");
};

String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

Date.prototype.format = function(format, locale) {
	var returnStr = '';	
	var replace = (locale == 'BG') ? Date.replaceCharsBG : Date.replaceCharsEN;
	for (var i = 0; i < format.length; i++) {
		var curChar = format.charAt(i);
		if (replace[curChar]) {
			returnStr += replace[curChar].call(this);
		} else {
			returnStr += curChar;
		}
	}
	return returnStr;
};
Date.replaceCharsEN = {
	shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
	longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
	longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
	
	// Day
	d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
	D: function() { return Date.replaceCharsEN.shortDays[this.getDay()]; },
	j: function() { return this.getDate(); },
	l: function() { return Date.replaceCharsEN.longDays[this.getDay()]; },
	N: function() { return this.getDay() + 1; },
	S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
	w: function() { return this.getDay(); },
	z: function() { return "Not Yet Supported"; },
	// Week
	W: function() { return "Not Yet Supported"; },
	// Month
	F: function() { return Date.replaceCharsEN.longMonths[this.getMonth()]; },
	m: function() { return (this.getMonth() < 11 ? '0' : '') + (this.getMonth() + 1); },
	M: function() { return Date.replaceCharsEN.shortMonths[this.getMonth()]; },
	n: function() { return this.getMonth() + 1; },
	t: function() { return "Not Yet Supported"; },
	// Year
	L: function() { return "Not Yet Supported"; },
	o: function() { return "Not Supported"; },
	Y: function() { return this.getFullYear(); },
	y: function() { return ('' + this.getFullYear()).substr(2); },
	// Time
	a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
	A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
	B: function() { return "Not Yet Supported"; },
	g: function() { return this.getHours() % 12 || 12; },
	G: function() { return this.getHours(); },
	h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
	H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
	i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
	s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
	// Timezone
	e: function() { return "Not Yet Supported"; },
	I: function() { return "Not Supported"; },
	O: function() { return (this.getTimezoneOffset() < 0 ? '-' : '+') + (this.getTimezoneOffset() / 60 < 10 ? '0' : '') + (this.getTimezoneOffset() / 60) + '00'; },
	T: function() { return "Not Yet Supported"; },
	Z: function() { return this.getTimezoneOffset() * 60; },
	// Full Date/Time
	c: function() { return "Not Yet Supported"; },
	r: function() { return this.toString(); },
	U: function() { return this.getTime() / 1000; }
};
Date.replaceCharsBG = {
		shortMonths: ['Янр', 'Фев', 'Мар', 'Апр', 'Май', 'Юни', 'Юли', 'Авг', 'Сеп', 'Окт', 'Нов', 'Дек'],
		longMonths: ['Януари', 'Февруари', 'Март', 'Април', 'Май', 'Юни', 'Юли', 'Август', 'Септември', 'Октомври', 'Ноември', 'Декември'],
		shortDays: ['Нед', 'Пон', 'Вт', 'Ср', 'Чет', 'Пет', 'Съб'],
		longDays: ['Неделя', 'Понеделник', 'Вторник', 'Сряда', 'Четвъртък', 'Петък', 'Събота'],
		
		// Day
		d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
		D: function() { return Date.replaceCharsBG.shortDays[this.getDay()]; },
//		j: function() { return this.getDate(); },
		j: function() { return ((this.getDate() < 10) ? '0' + this.getDate() : this.getDate()); },
		l: function() { return Date.replaceCharsBG.longDays[this.getDay()]; },
		N: function() { return this.getDay() + 1; },
		S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'ви' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'ри' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'ти' : 'ти'))); },
		w: function() { return this.getDay(); },
		z: function() { return "Not Yet Supported"; },
		// Week
		W: function() { return "Not Yet Supported"; },
		// Month
		F: function() { return Date.replaceCharsBG.longMonths[this.getMonth()]; },
		m: function() { return (this.getMonth() < 11 ? '0' : '') + (this.getMonth() + 1); },
		M: function() { return Date.replaceCharsBG.shortMonths[this.getMonth()]; },
		n: function() { return this.getMonth() + 1; },
		t: function() { return "Not Yet Supported"; },
		// Year
		L: function() { return "Not Yet Supported"; },
		o: function() { return "Not Supported"; },
		Y: function() { return this.getFullYear(); },
		y: function() { return ('' + this.getFullYear()).substr(2); },
		// Time
		a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
		A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
		B: function() { return "Not Yet Supported"; },
		g: function() { return this.getHours() % 12 || 12; },
		G: function() { return this.getHours(); },
		h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
		H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
		i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
		s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
		// Timezone
		e: function() { return "Not Yet Supported"; },
		I: function() { return "Not Supported"; },
		O: function() { return (this.getTimezoneOffset() < 0 ? '-' : '+') + (this.getTimezoneOffset() / 60 < 10 ? '0' : '') + (this.getTimezoneOffset() / 60) + '00'; },
		T: function() { return "Not Yet Supported"; },
		Z: function() { return this.getTimezoneOffset() * 60; },
		// Full Date/Time
		c: function() { return "Not Yet Supported"; },
		r: function() { return this.toString(); },
		U: function() { return this.getTime() / 1000; }
	};

function clearSelect(element) {
	if (element != undefined) {
		for ( var i = element.length; i > 0; i--) {
			element.options[i] = null;
		}
		var newOpt1 = new Option("Избери...", "");
		element.options[0] = newOpt1;
	}
};
function clearSelectOnlyFirstElement(element) {
	if (element != undefined) {
		if (element.length > 1 && allSpaces(element.options[0].value)) {
			element.options[0] = null;
		}
	}
};
function clearField(element) {
	if (element != undefined) {
		try {
			element.innerHTML = '';
			element.value = '';
		} catch (e) {
			element.value = '';
		}
	}
};

function allSpaces(value) {
	for ( var i = 0; i < value.length; i++) {
		if (value.charAt(i) != ' ') {
			return false;
		}
	}
	return true;
};
function fieldIsEmpty(field, text) {
	if (document.getElementById(field) != undefined) {
		if (allSpaces(document.getElementById(field).value)) {
			alert(text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function checkInterval(value1, value2) {
	if (parseFloat(value1.substring(6, 10)) > parseFloat(value2.substring(6, 10)))
		return false;
	else if (parseFloat(value1.substring(6, 10)) == parseFloat(value2.substring(6, 10))) { // if years are equal
		if (parseFloat(value1.substring(3, 5)) > parseFloat(value2.substring(3,5)))
			return false;
		else if (parseFloat(value1.substring(3, 5)) == parseFloat(value2.substring(3, 5))) { // if months are equal
			if (parseFloat(value1.substring(0, 2)) > parseFloat(value2.substring(0, 2)))
				return false;
		}
	}
	return true;
};
function fieldIsEmptyNoAlert(field) {
	if (document.getElementById(field) != undefined) {
		if (allSpaces(document.getElementById(field).value)) {
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function fieldIsEmptyNoAlertNoFocus(field) {
	if (document.getElementById(field) != undefined) {
		if (allSpaces(document.getElementById(field).value)) {
			return true;
		}
	}
	return false;
};
function fieldIsEmptySetErrorMsgToFieldHomePage(field, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (allSpaces(document.getElementById(field).value)) {
			if (document.getElementById(errField) != undefined) {				
				document.getElementById(errField).innerHTML = text;
				document.getElementById(field).focus();
			}			
			return true;
		}
	}
	return false;
};
function fieldIsEmptySetErrorMsgToField(field, windowId, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (allSpaces(document.getElementById(field).value)) {
			if (document.getElementById(errField) != undefined) {				
				showSystemMessage(errorType, errField, windowId, text);
				document.getElementById(field).focus();
			}			
			return true;
		}
	}
	return false;
};
function fieldIsContainsOnlyDashSetErrorMsgToField(field, windowId, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (document.getElementById(field).value.trim() == '-') {
			if (document.getElementById(errField) != undefined) {				
//				document.getElementById(errField).innerHTML = text;
				showSystemMessage(errorType, errField, windowId, text);
				document.getElementById(field).focus();
			}			
			return true;
		}
	}
	return false;
};
function passIsShort(field, text) {
	if (document.getElementById(field) != undefined) {
		if (document.getElementById(field).value.length < 6) {
			alert(text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function passIsShortSetErrorMsgToField(field, windowId, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (document.getElementById(field).value.length < 6) {
//			document.getElementById(errField).innerHTML = text;
			showSystemMessage(errorType, errField, windowId, text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function isLetter(pword) {
	return (((pword >= "a") && (pword <= "z")) || ((pword >= "A") && (pword <= "Z")));
};
function isBGENLetter(pword) {
	return (((pword >= "a") && (pword <= "z")) || ((pword >= "A") && (pword <= "Z")) || ((pword >= "а") && (pword <= "я")) || ((pword >= "А") && (pword <= "Я")));
};
function isBGLetter(pword) {
	return (((pword >= "а") && (pword <= "я")) || ((pword >= "А") && (pword <= "Я")));
};
function isHasEmail(pword) {
	return ((pword == '-') || (pword == '.') || (pword == '@') || (pword == '_') || isLetterOrDigit(pword));
};
function checkEmailValidity(str) {
	var dot = 0;
	var mail = 0;
	if (str == "")
		return true;
	for ( var i = 0; i < str.length; i++) {
		if ((str.charAt(i) == " " && i != (str.length - 1))
				|| (!isHasEmail(str.charAt(i))))
			return false;
		else if ((str.charAt(i) == "@" && i == 0)
				|| (str.charAt(i) == "@" && i == (str.length - 1))
				|| str.charAt(i) == "\"")
			return false;
		if (str.charAt(i) == "@")
			mail = 1;
		if (mail == 1)
			if (str.charAt(i) == "."
					&& (i >= (str.length - 2) || str.charAt(i - 1) == "@"))
				return false;
		if (str.charAt(i) == ".")
			if (mail == 1)
				dot = 1;
	}
	if (dot == 0 || mail == 0)
		return false;
	else
		return true;
};
function checkEmail(field, text) {
	if (document.getElementById(field) != undefined) {

		if (!checkEmailValidity(document.getElementById(field).value)) {
			alert(text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function checkEmailSetErrorMsgToField(field, windowId, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (!checkEmailValidity(document.getElementById(field).value)) {
			//document.getElementById(errField).innerHTML = text;
			showSystemMessage(errorType, errField, windowId, text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function notFieldsEquals(field1, field2, text) {

	if (document.getElementById(field1) != undefined
			&& document.getElementById(field2) != undefined) {
		if (document.getElementById(field1).value != document
				.getElementById(field2).value) {
			alert(text);
			document.getElementById(field2).focus();
			return true;
		}
	}
	return false;
};
function notFieldsEqualsSetErrorMsgToField(field1, field2, windowId, errField, text) {

	if (document.getElementById(field1) != undefined && document.getElementById(field2) != undefined) {
		if (document.getElementById(field1).value != document.getElementById(field2).value) {
//			document.getElementById(errField).innerHTML = text;
			showSystemMessage(errorType, errField, windowId, text);
			document.getElementById(field2).focus();
			return true;
		}
	}
	return false;
};
function sortNumber(a,b) {
	return a - b;
};
function convertSimbolsToHTML(str) {
	if (str == null || str.length == 0) {
		return '';
	}
	str.replace('&lt;', '<');
	str.replace('&gt;', '>');
	str.replace('&amp;', '&');
	str.replace('&quot;', '"');
	return str;
} 

function isDigit(pword) {
	return ((pword >= "0") && (pword <= "9"))
};
function isLetterOrDigit(pword) {
	return (isLetter(pword) || isDigit(pword))
};
function isBGENLetterOrDigit(pword) {
	return (isBGENLetter(pword) || isDigit(pword))
};
function isAllLettersAndSpace(value) {
	for ( var i = 0; i < value.length; i++) {
		if (!(isLetter(value.charAt(i)) || value.charAt(i) == ' '))
			return false;
	}
	return true;
};
function isAllLettersAndSpaceAndDigits(value) {
	for ( var i = 0; i < value.length; i++) {
//		if (!(isLetter(value.charAt(i)) || value.charAt(i) == ' '
		if (!(isBGENLetter(value.charAt(i)) || value.charAt(i) == ' ' || isDigit(value.charAt(i)) || value.charAt(i) == '_')) {
			return false;
		}
	}
	return true;
};
function isUsernameCorrectSetErrorMsgToFieldHomePage(field, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (!isUsernameCorrect(document.getElementById(field).value)) {
			document.getElementById(errField).innerHTML = text;
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function isUsernameCorrectSetErrorMsgToField(field, windowId, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (!isUsernameCorrect(document.getElementById(field).value)) {
			showSystemMessage(errorType, errField, windowId, text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function isUsernameCorrect(value) {
	if (value.indexOf('--') != -1) {
		return false;
	}
	for ( var i = 0; i < value.length; i++) {
		if (value.charAt(i) == '\'' || value.charAt(i) == '"' || value.charAt(i) == '\\') {
			return false;
		}
	}
	return true;
};
function isAllBGENLettersAndSpace(value) {
	for ( var i = 0; i < value.length; i++) {
		if (!(isBGENLetter(value.charAt(i)) || value.charAt(i) == ' '))
			return false;
	}
	return true;
};
function isAllBGENLettersAndSpaceAndDash(value) {
	for ( var i = 0; i < value.length; i++) {
		if (!(isBGENLetter(value.charAt(i)) || value.charAt(i) == ' ' || value.charAt(i) == '-'))
			return false;
	}
	return true;
};
function notAllLetters(field, text) {
	if (document.getElementById(field) != undefined) {
		if (!isAllLettersAndSpace(document.getElementById(field).value)) {
			alert(text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function notAllBGENLetters(field, text) {
	if (document.getElementById(field) != undefined) {
		if (!isGBENAllLettersAndSpace(document.getElementById(field).value)) {
			alert(text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function notAllLettersSetErrorMsgToField(field, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (!isAllLettersAndSpace(document.getElementById(field).value)) {
			document.getElementById(errField).innerHTML = text;
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function notAllLettersOrDigitsSetErrorMsgToFieldHomePage(field, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (!isAllLettersAndSpaceAndDigits(document.getElementById(field).value)) {
			document.getElementById(errField).innerHTML = text;
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function notAllLettersOrDigitsSetErrorMsgToField(field, windowId, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (!isAllLettersAndSpaceAndDigits(document.getElementById(field).value)) {
			showSystemMessage(errorType, errField, windowId, text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function notAllBGENLettersAndDashSetErrorMsgToField(field, windowId, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (!isAllBGENLettersAndSpaceAndDash(document.getElementById(field).value)) {
//			document.getElementById(errField).innerHTML = text;
			showSystemMessage(errorType, errField, windowId, text);
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function notAllBGENLettersSetErrorMsgToField(field, windowId, errField, text) {
	if (document.getElementById(field) != undefined) {
		if (!isAllBGENLettersAndSpace(document.getElementById(field).value)) {
			showSystemMessage(errorType, errField, windowId, text);
//			document.getElementById(errField).innerHTML = text;
			document.getElementById(field).focus();
			return true;
		}
	}
	return false;
};
function hasDataInField(fields) {
	if (fields != null && fields.length > 0) {
		for ( var i = 0; i < fields.length; i++) {
			if (document.getElementById(fields[i]) != undefined && !allSpaces(document.getElementById(fields[i]).value)) {
				return true;
			}
		}
	}
	return false;
};
function checkAllRequiredFields(fields) {
	if (fields != null && fields.length > 0) {
		for ( var i = 0; i < fields.length; i++) {
			if (document.getElementById(fields[i]) != undefined && allSpaces(document.getElementById(fields[i]).value)) {
				return false;
			}
		}
	}
	return true;
};
function checkState(mode) {
	switch (mode) {
		case 'r': {
			if (hasDataInField(new Array('rFirstName','rLastName','rEmail','rUserName','rPassword','rRetypedPassword'))) {
				setNormalAlphaCursor(document.getElementById(clearRegistrationFormButton));
			} else {
				setDisabledAlphaNotAllowedCursor(document.getElementById(clearRegistrationFormButton));
			}
			if (checkAllRequiredFields(new Array('rFirstName','rLastName','rEmail','rUserName','rPassword','rRetypedPassword'))) {
				setNormalAlphaCursor(document.getElementById(registrationButton));				
			} else {
				setDisabledAlphaNotAllowedCursor(document.getElementById(registrationButton));
			}
			break;
		}
		case 'lhp': {			
			if (checkAllRequiredFields(new Array('lhpUsername', 'lhpPassword'))) {
				setNormalAlphaCursor(document.getElementById(loginHomePageButton));				
			} else {
				setDisabledAlphaNotAllowedCursor(document.getElementById(loginHomePageButton));
			}
			break;			
		}				
		case 'l': {			
			if (checkAllRequiredFields(new Array('lUsername', 'lPassword'))) {
				setNormalAlphaCursor(document.getElementById(loginButton));				
			} else {
				setDisabledAlphaNotAllowedCursor(document.getElementById(loginButton));
			}
			break;			
		}
		case 'e': {			
			if (checkAllRequiredFields(new Array('eFirstName','eLastName','eEmail','eUsername'))) {
				setNormalAlphaCursor(document.getElementById(editConfirmButton));				
			} else {
				setDisabledAlphaNotAllowedCursor(document.getElementById(editConfirmButton));
			}
			break;			
		}	
		case 'chp': {			
			if (checkAllRequiredFields(new Array('chOPassword','chNPassword','chNRetypedPassword'))) {
				setNormalAlphaCursor(document.getElementById(profileChangePasswordOKButton));				
			} else {
				setDisabledAlphaNotAllowedCursor(document.getElementById(profileChangePasswordOKButton));
			}
			break;			
		}				
		case 'fpr': {			
			if (checkAllRequiredFields(new Array('fpUsername', 'fpEmail'))) {
				setNormalAlphaCursor(document.getElementById(forgottenPasswordContinueButton));				
			} else {
				setDisabledAlphaNotAllowedCursor(document.getElementById(forgottenPasswordContinueButton));
			}
			break;			
		}	
		case 'fpn': {			
			if (checkAllRequiredFields(new Array('fpnUsername', 'fpnPassword', 'fpnRPassword'))) {
				setNormalAlphaCursor(document.getElementById(forgottenPasswordNewDataOKButton));				
			} else {
				setDisabledAlphaNotAllowedCursor(document.getElementById(forgottenPasswordNewDataOKButton));
			}
			break;			
		}		
	}
};
function checkEnter(evt, mode) {
	evt = (evt) ? evt : ((window.event) ? event : null);
	if (evt) {

		var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		if (elem) {
			var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
			if (charCode == 13) {
				switch (mode) {
					case 'l': {
						if (isNormalAlpha(document.getElementById(loginButton))) return sendLoginData();
						break;
					}
					case 'lhp': {
						if (isNormalAlpha(document.getElementById(loginHomePageButton))) return loginUser();
						break;
					}					
					case 'r': {					
						if (isNormalAlpha(document.getElementById(registrationButton))) return sendRegistrationData();
						break;
					}
					case 'e': {
						if (isNormalAlpha(document.getElementById(editConfirmButton))) return sendProfileData();
						break;
					}
					case 'chp': {
						if (isNormalAlpha(document.getElementById(profileChangePasswordOKButton))) return sendChangePasswordData();
						break;
					}					
					case 'fpr': {
						if (isNormalAlpha(document.getElementById(forgottenPasswordContinueButton))) return requestForgottenPassword();
						break;
					}
					case 'fpn': {
						if (isNormalAlpha(document.getElementById(forgottenPasswordNewDataOKButton))) return sendForgottenPasswordNewData();
						break;
					}										
					case 'nb': {
						navigatorEvent(navigatorGoButtonPressed );
						break;
					}
				}
			} else {
				return false;
			}
		}
	}
	return false;
};
function checkEnterPress(evt, mode) {
	evt = (evt) ? evt : ((window.event) ? event : null);
	if (evt) {

		var elem = (evt.target) ? evt.target
				: ((evt.srcElement) ? evt.srcElement : null);
		if (elem) {
			var charCode = (evt.charCode) ? evt.charCode
					: ((evt.which) ? evt.which : evt.keyCode);
			if (charCode == 13) {
				switch (mode) {
					case 'l': {
						setBtnHover(document.getElementById(loginButton));
						break;
					}
					case 'r': {		
						setBtnHover(document.getElementById(registrationButton));
						break;
					}
					case 'e': {
						setBtnHover(document.getElementById(editConfirmButton));
						break;
					}
					case 'chp': {
						setBtnHover(document.getElementById(profileChangePasswordOKButton));
						break;
					}					
					case 'fpr': {
						setBtnHover(document.getElementById(forgottenPasswordContinueButton));
						break;
					}
					case 'fpn': {
						setBtnHover(document.getElementById(forgottenPasswordNewDataOKButton));
						break;
					}								
				}
			} else {
				return false;
			}
		}
	}
	return false;
};
function getWindowDIV(windowId) {
	switch (windowId) {
		case error: {
			return errorDIVWindow;	
		}
		case warning: {
			return warningDIVWindow;	
		}
		case info: {
			return infoDIVWindow;	
		}		
		case login: {
			return loginDIVWindow;		
		}
		case registrationConfirmTerms: {
			return registrationConfirmTermsDIVWindow;		 
		}
		case registrationSubmit: {
			return registrationSubmitDIVWindow;		
		}
		case registrationResults: {
			return registrationSuccessDIVWindow;		
		}
		case profile: {
			return profileDIVWindow;		
		}
		case changePassword: {
			return changePasswordDIVWindow;		
		}		
		case payments: {
			return paymentsDIVWindow;		
		}
		case paymentDetails: {
			return paymentDetailsDIVWindow;		
		}
		case bucket: {
			return bucketDIVWindow;
		}
		case forgottenPaswordRequest: {
			return forgottenPasswordRequestDIVWindow;		
		}
		case forgottenPaswordSetNewData: {
			return forgottenPasswordSetNewDataDIVWindow;		
		}		
		case termsAndConditions: {
			return termsAndConditionsDIVWindow;		
		}
		case privacyPolicy: {
			return privacyPolicyDIVWindow;
		}
		case carterConditions: {
			return carterConditionsDIVWindow;
		}
		case paymentOperators: {
			return paymentOperatorsDIVWindow;
		}
		case FAQ: { 
			return FAQDIVWindow;			
		}
		case help: {
			return helpDIVWindow;
		}
		case contacts: {
			return contactsDIVWindow;		
		}		
		case selectSeatWhenUserIsNotLogged: {
			return selectSeatWhenUserIsNotLoggedDIVWindow;		
		}
		case sessionIsTimeOut: {
			return sessionIsTimeOutDIVWindow;		
		}		
	}
};
function getWindowId(windowDIV) {
	if (windowDIV == errorDIVWindow) {
		return error;
	} else if (windowDIV == warningDIVWindow) {
		return warning;
	} else if (windowDIV == infoDIVWindow) {
		return info;				
	} else if (windowDIV == loginDIVWindow) {
		return login;
	} else if (windowDIV == registrationConfirmTermsDIVWindow) {
		return registrationConfirmTerms;
	} else if (windowDIV == registrationSubmitDIVWindow) {
		return registrationSubmit;
	} else if (windowDIV == registrationSuccessDIVWindow) {
		return registrationResults;		
	} else if (windowDIV == profileDIVWindow) {
		return profile;
	} else if (windowDIV == changePasswordDIVWindow) {
		return changePassword;
	} else if (windowDIV == paymentsDIVWindow) {
		return payments;
	} else if (windowDIV == paymentDetailsDIVWindow) {
		return paymentDetails;
	} else if (windowDIV == bucketDIVWindow) {
		return bucket;		
	} else if (windowDIV == forgottenPasswordRequestDIVWindow) {
		return forgottenPaswordRequest;
	} else if (windowDIV == forgottenPasswordSetNewDataDIVWindow) {
		return forgottenPaswordSetNewData;
	} else if (windowDIV == termsAndConditionsDIVWindow) {
		return termsAndConditions;
	} else if (windowDIV == privacyPolicyDIVWindow) {
		return privacyPolicy;
	} else if (windowDIV == carterConditionsDIVWindow) {
		return carterConditions;
	} else if (windowDIV == paymentOperatorsDIVWindow) {
		return paymentOperators;	
	} else if (windowDIV == FAQDIVWindow) {
		return FAQ;
	} else if (windowDIV == helpDIVWindow) {
		return help;
	} else if (windowDIV == contactsDIVWindow) {
		return contacts;	
	} else if (windowDIV == selectSeatWhenUserIsNotLoggedDIVWindow) {
		return selectSeatWhenUserIsNotLogged;
	} else if (windowDIV == sessionIsTimeOutDIVWindow) {
		return sessionIsTimeOut;
	} else if (windowDIV == dumpDIVWindow) {	
		return -1;
	} 
};
function toogleElement(EleName,style){
	var objEle = document.getElementById(EleName);
	if(objEle) {
		objEle.style.display=style;
	}
};
function getSize() {
	var myWidth = 0, myHeight = 0;
	if (typeof (window.innerWidth) == 'number') {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth, myHeight ];
};

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if (typeof (window.pageYOffset) == 'number') {
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
};
function getErrorIcon() {
	return 'images/icon_error.png';
};
function getWarningIcon(){
	return 'images/icon_warning.png';
};
function getInfoIcon() {
	return 'images/icon_info.png';
};
function setDisabledAlpha(obj) {
	if (obj != undefined) {
		obj.style.opacity = 0.3;
		if (_ie)
			obj.style.filter = "alpha(opacity=30)";
		else if (_mozilla)
			obj.style.MozOpacity = "0.3";
	}
};
function setNormalAlpha(obj) {
	if (obj != undefined) {
		obj.style.opacity = 1;
		if (_ie)
			obj.style.filter = "alpha(opacity=100)";
		else if (_mozilla)
			obj.style.MozOpacity = "1";
	}
};
function setDisabledAlphaCursor(obj) {
	if (obj != undefined) {
		obj.style.opacity = 0.3;
		obj.style.cursor = "default";
		if (_ie)
			obj.style.filter = "alpha(opacity=30)";
		else if (_mozilla)
			obj.style.MozOpacity = "0.3";
	}
};
function setDisabledAlphaNotAllowedCursor(obj) {
	if (obj != undefined) {
		obj.style.opacity = 0.3;
		obj.style.cursor = "not-allowed";
		if (_ie) {
			obj.style.filter = "alpha(opacity=30)";
		} else if (_mozilla) {
			obj.style.MozOpacity = "0.3";
		}
	}
};
function setCustomAlphaNotAllowedCursor(obj, _alpha) {
	if (obj != undefined) {
		obj.style.opacity = (_alpha == 100) ? '1' : '0.' + _alpha;
		obj.style.cursor = 'not-allowed';
		if (_ie) {
			obj.style.filter = 'alpha(opacity=' + _alpha + ')';
		} else if (_mozilla) {
			obj.style.MozOpacity = (_alpha == 100) ? '1' : '0.' + _alpha;
		}
	}
};
function setNormalAlphaCursor(obj) {
	if (obj != undefined) {
		obj.style.opacity = 1;
		obj.style.cursor = "pointer";
		if (_ie) {
			obj.style.filter = "alpha(opacity=100)";
		} else if (_mozilla) {
			obj.style.MozOpacity = "1";
		}
	}
};
function setNormalAlphaDefaultCursor(obj) {
	if (obj != undefined) {
		obj.style.opacity = 1;
		obj.style.cursor = "default";
		if (_ie) {
			obj.style.filter = "alpha(opacity=100)";
		} else if (_mozilla) {
			obj.style.MozOpacity = "1";
		}
	}
};
function setZeroAlphaDefaultCursor(obj) {
	if (obj != undefined) {
		obj.style.opacity = 0;
		obj.style.cursor = "default";
		if (_ie) {
			obj.style.filter = "alpha(opacity=0)";
		} else if (_mozilla) {
			obj.style.MozOpacity = "0";
		}	
	}
};
function isDisabledAlpha(obj) {
	if (obj != undefined) {
		if (_ie) {
			return (obj.style.filter == "alpha(opacity=30)") ? true : false;
		} else if (_mozilla) {
			return (obj.style.MozOpacity == "0.3") ? true : false;
		} else if (_opera) {
			return (obj.style.opacity == "0.3") ? true : false;
		}
	}
	return false;
};
function isNormalAlpha(obj) {
	if (obj != undefined) {
		if (_ie)
			return (obj.style.filter == "alpha(opacity=100)" || obj.style.filter == "") ? true : false;
		else if (_mozilla)
			return (obj.style.MozOpacity == "1" || obj.style.MozOpacity == "") ? true : false;
		else if (_opera)
			return (obj.style.opacity == "1" || obj.style.opacity == "") ? true : false;
	}
	return true;
};
function isNormalAlphaName(element) {
	if (document.getElementById(element) != undefined) {
		var obj = document.getElementById(element);
		if (_ie)
			return (obj.style.filter == "alpha(opacity=100)" || obj.style.filter == "") ? true
					: false;
		else if (_mozilla)
			return (obj.style.MozOpacity == "1" || obj.style.MozOpacity == "") ? true
					: false;
		else if (_opera)
			return (obj.style.opacity == "1" || obj.style.opacity == "") ? true
					: false;
	}
};
function setWaitCursor(element) {
	if (document.getElementById(element) != undefined) {
		document.getElementById(element).style.cursor = 'wait';
	}
};
function setMoveCursor(element) {
	if (document.getElementById(element) != undefined) {
		document.getElementById(element).style.cursor = 'move';
	}
};
function setDefaultCursor(element) {
	if (document.getElementById(element) != undefined) {
		document.getElementById(element).style.cursor = 'default';
	}
};
function setNotAllowedCursor(element) {
	if (document.getElementById(element) != undefined) {
		document.getElementById(element).style.cursor = 'not-allowed';
	}
};
function setPointerCursor(element) {
	if (document.getElementById(element) != undefined) {
		document.getElementById(element).style.cursor = 'pointer';
	}
};
function showItem(id) {
	if (document.getElementById(id) != undefined) {
		document.getElementById(id).style.visibility = "visible";
	}
};
function showItemSetDepth(id, _depth) {
	if (document.getElementById(id) != undefined) {
		document.getElementById(id).style.zIndex = parseFloat(_depth);
		document.getElementById(id).style.visibility = "visible";
	}
};
function hideItem(id) {
	if (document.getElementById(id) != undefined) {
		document.getElementById(id).style.visibility = "hidden";
	}
};
function getDateForBanner() {	
	clearTimeout(bannerServerDateInterval);
	var bannerServerDate = new Date();
	bannerServerDate.setTime(currentTime);
	var h,m,s;
	var time="";
	h=bannerServerDate.getHours();
	m=bannerServerDate.getMinutes();
	s=bannerServerDate.getSeconds();
	if(s<=9) s="0"+s;
	if(m<=9) m="0"+m;
	if(h<=9) h="0"+h;
	time+=h;
	time+=":"+m;
	time+=":"+s;	
	document.getElementById("bannerDate").innerHTML=bannerServerDate.format("l, j F Y", 'BG') + '&nbsp;г.&nbsp;' + time;	
	currentTime = parseFloat(currentTime) + 1000;
	bannerServerDateInterval=setTimeout("getDateForBanner()",1000);    	
};


function initState() {
	applicationState = stateHomePage;
	clearChosenSeats();
	clearChosenTickets();
	clearTimers();
	hideAllShowHomePage();
	loadedEditData = new Array('', '', '', '');	
	paymentsResults = new Array();
	paymentsCurrentPage = 1;
	paymentsPageCount = 1;
	paymentsResultsPerPage = 15;
	tmpCurrentDetailsWindowLeftPosition = 0;
	tmpCurrentDetailsWindowTopPosition = 0;
	tmpPaymentDetailsWindowLeftPosition = 0;
	tmpPaymentDetailsWindowTopPosition = 0;	
	numberOfSummarizedTicket = 0;
	saleCodeCheckInterval = 0;
};
function generalInit() {
	numberOfLockedSeats = 0;
	numberOfLockedReturnSeats = 0;
	showReturnFilters = false;
	showVehicleSeats = false;
	showVehicleReturnSeats = false;
	allTicketsCount = 0;
	ticketsTypeArr = null;
	ticketsTypeIdArr = null;
	ticketsNameArr = null;
	ticketsPriceArr = null;
	ticketsDirectionArr = null;
	currentTravelListId = -1;
	currentTypesIdArr = null;
	currentTypesCountArr = null;
	numberOfLockedSeats = 0;
	numberOfLockedReturnSeats = 0;
	totalSelectTicketsCount = 0;
	totalSelectTicketsPrice = 0;
	showOneWayTickets = false; 
	showTwoWayTickets = false;
	flashLoadedTime = '0,0'; 
	showSummaryBtn = false;
	canPay = true; 
	canCloseWindow = true; 
	paymentsResults = new Array();
	paymentsCurrentPage = 1;
	paymentsPageCount = 1;
	paymentsResultsPerPage = 15;
	closingWindows = new Array();
	selectedSaleRowId = null;
	tmpCurrentDetailsWindowLeftPosition = 0;
	tmpCurrentDetailsWindowTopPosition = 0;
	tmpPaymentDetailsWindowLeftPosition = 0;
	tmpPaymentDetailsWindowTopPosition = 0;	
	numberOfSummarizedTicket = 0;
	saleCodeCheckInterval = 0;
	currentSelectOneWayTicketsCount = 0;
	currentSelectTwoWayTicketsCount = 0;
	ticketLeftDepartureCount = 0;
	ticketLeftReturnCount = 0;
	currentSelectTicketType = noCurrentTicketSelected;
	applicationState = stateHomePage;
	clearTimers();
	clearFiltersInitAll();
	initFiltersStatus();
	initTicketsCount(); 
	hideAllShowHomePage();
	closeAllWindowsLocalExceptSessionTimeOut();
};
