(function (window, undefined) {
var handlers = [], logged = false;
window.platform = {
domain: "yandex.com.tr",
language: "ru",
brandID: "ru",
sendMessage: function (message) {
console.log("platform");
console.log(message);
if (message.message === "ready")
{
this.onMessage.execListeners({
message: "init",
data: {
synced: false,
username: null,
settings: {
vb: true,
searchHistory: true},
error: null}});
}
 else
if (message.message === "login")
{
console.log("LOGIN");
if (message.data.captchaKey)
{
this.onMessage.execListeners({
message: "error",
data: {
code: 0}});
}
 else
{
this.onMessage.execListeners({
message: "error",
data: {
code: 5,
captchaURL: "http://lorempixel.com/300/100/",
captchaKey: "asdadsad"}});
}

}
 else
if (message.message === "cancel")
{
this.onMessage.execListeners({
message: "init",
data: {
synced: false,
username: "megatolya"}});
}

}
,
onMessage: {
addListener: function (handler) {
handlers.push(handler);
}
,
removeListener: function (handler) {
handlers[handlers.indexOf(handler)] = null;
}
,
execListeners: function (data) {
handlers.forEach(function (handler) {
handler(data);
}
);
}
}};
}
)(window);
