      window.addEvent('domready', function() {

      //Datepicker
      //store titles and text
     $$('a.tipz').each(function(element,index) {
         var content = element.get('title').split('::');
         element.store('tip:title', content[0]);
         element.store('tip:text', content[1]);
     });

     //create the tooltips
     var tipz = new Tips('.tipz',{
         className: 'tipz',
         fixed: true,
         hideDelay: 50,
         showDelay: 50
     });


    });
	function init(gr_id){
		var stretchers = $$('div.menu_content');
		var togglers = $$('div.display');
        var myAccordion = new Accordion(togglers, stretchers, { opacity: false, alwaysHide: true,
          show: gr_id,

			onActive: function(toggler, stretcher){
                toggler.setStyle('font-weight', 'bold');
			},

			onBackground: function(toggler, stretcher){
				toggler.setStyle('font-weight', 'normal');
			}
		});
	}
	function init_greetings(gr_id){
		var stretchers = $$('div.menu_content_greetings');
		var togglers = $$('div.display_greetings');
        var myAccordion = new Accordion(togglers, stretchers, { opacity: false, alwaysHide: true, show:gr_id,


			onActive: function(toggler, stretcher){
                toggler.setStyle('font-weight', 'bold');
			},

			onBackground: function(toggler, stretcher){
				toggler.setStyle('font-weight', 'normal');
			}
		});
	}

	function init_help(gr_id){
		var stretchers = $$('div.menu_content_help');
		var togglers = $$('div.display_greetings');
        var myAccordion = new Accordion(togglers, stretchers, { opacity: true, alwaysHide: true, show:gr_id,


			onActive: function(toggler, stretcher){
                toggler.setStyle('font-weight', 'bold');
                toggler.setStyle('background-color', '#FFE4F3');
			},

			onBackground: function(toggler, stretcher){
				toggler.setStyle('font-weight', 'normal');
                toggler.setStyle('background-color', '');
			}
		});
	}


    function absPosition(obj) {
	this.x = 0;
	this.y = 0;
    while(obj) {
		this.x += obj.offsetLeft;
		this.y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return {x:this.x,y:this.y};
}

function delay(ms) {
	// Защита от некорректных данных
	if (typeof ms == "undefined") return;
	ms = parseInt(ms);
	if (typeof ms >= 0) return;
	// Задаем точки начала измерения
	var before = after = new Date();
	before = before.getTime();
	after = after.getTime();
	// В цикле меняем вторую точку, сравнивая разницу с аргуметом
	while (after < before + ms) {
		after = new Date();
		after = after.getTime();
	}
}

function rgbNormal(color) {
	color = color.toString();
	var re = /rgb\((.*?)\)/i;
	if(re.test(color)) {
		compose = RegExp.$1.split(",");
		var hex = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'];
		var result = "#";
		for (var i = 0; i < compose.length; i++) {
			rgb = parseInt(compose[i]);
			result += hex[parseInt(rgb / 16)] + hex[rgb % 16];
		}
		return result;
	} else return color;
}
function gebi(el){
        return document.getElementById(el);
  }

function AddRemaoveFavorites(card_id,action)
{
  var myRequest = new Request({method: 'post', url: BASE_URL + 'favorites/add_remove_ajax',
                                    onSuccess : function(responseText, responseXML){
                                      AddRemaoveFavoritesResponse(responseText);
                                    }
                                   }).send('card_id='+card_id+'&action='+action);
}
function AddRemaoveFavoritesResponse(responseText)
{
  eval(responseText);
    if (action == 'add')
      {
        document.getElementById('favorite_' + card_id).innerHTML = '<a href="#" OnClick="AddRemaoveFavorites('+ card_id +',\'del\'); return false;"><img src="'+ BASE_URL +'public/images/remove_to_favorite.gif" width="30" height="32" border="0"></a>';
      }
    else
      {
        document.getElementById('favorite_' + card_id).innerHTML = '<a href="#" OnClick="AddRemaoveFavorites('+ card_id +',\'add\'); return false;"><img src="'+ BASE_URL +'public/images/add_to_favorite.gif" width="30" height="32" border="0"></a>';
      }
    if (total_favorite > 0)
      {
        document.getElementById('favorite_card_link').innerHTML = '&nbsp;&nbsp;|&nbsp;&nbsp;<a href="'+ BASE_URL + 'favorites/show">Избранное('+total_favorite+')</a>';
      }
    else
      {
        document.getElementById('favorite_card_link').innerHTML = '';
      }
}

    function hideShowDiv(div,link)
      {
        if (document.getElementById(div).style.display == 'none')
          {
            document.getElementById(div).style.display = '';
            if (link != '') document.getElementById(link).innerHTML = msgHide;
          }
        else
          {
            document.getElementById(div).style.display = 'none';
            if (link != '') document.getElementById(link).innerHTML = msgShow;
          }
      }
    function hideShowDivPM(div,link)
      {
        if (document.getElementById(div).style.display == 'none')
          {
            document.getElementById(div).style.display = '';
            document.getElementById(link).src = BASE_URL + 'public/images/minus.gif';
          }
        else
          {
            document.getElementById(div).style.display = 'none';
            document.getElementById(link).src = BASE_URL + 'public/images/plus.gif';
          }
        var calendar = document.getElementById('calendar_member').style.display;
        var cards = document.getElementById('cards_member').style.display;
        var cabinet = document.getElementById('cabinet_member').style.display;

        var myRequest = new Request({method: 'post', url: BASE_URL + 'member/options/update_left_side_options_ajax'
                                   }).send('calendar='+calendar+'&cards='+cards+'&cabinet='+cabinet);
      }
 function sendMessageToUser(user_id)
  {
    wn=window.open(BASE_URL + 'member/messages/send_message/'+user_id,'window_user','width=500,height=570,top=100,left=100,toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no');
    return false;
  }
 function showProfilePhoto(user_id)
  {
    wn=window.open(BASE_URL + 'member/friend/profile_photo/'+user_id,'profile_photo','width=800,height=700,top=100,left=100,toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no');
    return false;
  }

 function showProfileMenu(obj,name,member_id, is_friend, photo_url)
  {
		gebi("profileMenu").style.top = (absPosition(obj).y + obj.offsetHeight - 60) + "px";
        gebi("profileMenu").style.left = (absPosition(obj).x + obj.offsetWidth - 50) + "px";
        gebi("profileMenu").innerHTML = '<b>'+ name +'</b><br>';
     if (loged == true)
      {
        gebi("profileMenu").innerHTML += '<a href="#" onclick="showProfilePhoto('+member_id+'); return false;" style="line-height:25px;">Увеличить фото</a><br>';
      }
     else
      {
        gebi("profileMenu").innerHTML += '<a href="#" onClick="if (confirm(\'Эта функция доступна только зарегистрированным членам сайта. Вы хотите зарегистрироваться?\')) {location.href=\'' + BASE_URL + 'member/register\'}; return false;" style="line-height:25px;">Увеличить фото</a><br>';
      }
     gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'member/friend/profile/'+member_id+'" style="line-height:25px;">Просмотреть профайл</a><br>';
     if (loged == true)
      {
        if (is_friend == 1)
          {
            gebi("profileMenu").innerHTML += 'уже в друзьях<br>';
          }
        else
          {
            gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'member/friend/invite_form/'+member_id+'" style="line-height:25px;">Добавить в друзья</a><br>';
          }
        gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'member/friend_pictures/show/'+member_id+'" style="line-height:25px;">Личные фото</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onclick="sendMessageToUser('+member_id+'); return false;" style="line-height:25px;">Отослать сообщение</a><br>';
        gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'member/messages/messaging/'+member_id+'" style="line-height:25px;">Просмотреть переписку</a><br>';
      }
     else
      {
        gebi("profileMenu").innerHTML += '<a href="#" onClick="if (confirm(\'Эта функция доступна только зарегистрированным членам сайта. Вы хотите зарегистрироваться?\')) {location.href=\'' + BASE_URL + 'member/register\'}; return false;" style="line-height:25px;">Добавить в друзья</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="if (confirm(\'Эта функция доступна только зарегистрированным членам сайта. Вы хотите зарегистрироваться?\')) {location.href=\'' + BASE_URL + 'member/register\'}; return false;" style="line-height:25px;">Личные фото</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="if (confirm(\'Эта функция доступна только зарегистрированным членам сайта. Вы хотите зарегистрироваться?\')) {location.href=\'' + BASE_URL + 'member/register\'}; return false;" style="line-height:25px;">Отослать сообщение</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="if (confirm(\'Эта функция доступна только зарегистрированным членам сайта. Вы хотите зарегистрироваться?\')) {location.href=\'' + BASE_URL + 'member/register\'}; return false;" style="line-height:25px;">Просмотреть переписку</a><br>';

      }
        gebi("profileMenu").style.display = "";
  }
 function showImageMenuForAll(obj,name,member_id, is_friend,image_id,photoUrl)
  {

    	gebi("profileMenu").style.top = (absPosition(obj).y + obj.offsetHeight - 60) + "px";
        gebi("profileMenu").style.left = (absPosition(obj).x + obj.offsetWidth - 50) + "px";
        gebi("profileMenu").innerHTML = '<b>'+ name +'</b><br>';
        //gebi("profileMenu").innerHTML += '<a href="#" onclick="showProfilePhoto('+member_id+'); return false;" style="line-height:25px;">Увеличить фото</a><br>';
    if (loged == true)
      {
        gebi("profileMenu").innerHTML += '<a href="#" onClick="imageInNewWin('+image_id+'); return false;" style="line-height:25px;">Увеличить фото</a><br>';
        gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'cards/user_pictures/'+image_id+'" style="line-height:25px;">Отослать как открытку</a><br>';
        gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'flash_card/with_user_picture/'+image_id+'" style="line-height:25px;">Дорисовать и отослать</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="sendToMobile(\''+photoUrl+'\'); return false;" style="line-height:25px;">Отослать на мобильный</a><br>';
        gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'member/friend_pictures/show/'+member_id+'" style="line-height:25px;">Все фото пользователя</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onclick="sendMessageToUser('+member_id+'); return false;" style="line-height:25px;">Отослать сообщение</a><br>';
      }
    else
      {
        gebi("profileMenu").innerHTML += '<a href="#" onClick="alert(\'Эта функция доступна только зарегистрированным членам сайта\'); return false;" style="line-height:25px;">Увеличить фото</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="alert(\'Эта функция доступна только зарегистрированным членам сайта\'); return false;" style="line-height:25px;">Отослать как открытку</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="alert(\'Эта функция доступна только зарегистрированным членам сайта\'); return false;" style="line-height:25px;">Дорисовать и отослать</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="alert(\'Эта функция доступна только зарегистрированным членам сайта\'); return false;" style="line-height:25px;">Отослать на мобильный</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="alert(\'Эта функция доступна только зарегистрированным членам сайта\'); return false;" style="line-height:25px;">Все фото пользователя</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onClick="alert(\'Эта функция доступна только зарегистрированным членам сайта\'); return false;" style="line-height:25px;">Отослать сообщение</a><br>';
      }

        gebi("profileMenu").style.display = "";
  }
function sendToMobile(photoUrl)
  {
    window.open('http://zz.smsonline.ru/s/ee.cgi?id=850&f='+escape(photoUrl), 'sms'+parseInt(Math.random()*10000),'width=780,height=560,status=1,resize=0');
  }
function imageInNewWin(image_id)
  {
    var url = BASE_URL+"member/pictures/zoom_picture/"+image_id+'/';

    openWinCentered(url, "view", 700, 670, 'location=no,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes');
  }
function openWinCentered(loc, winname, widthh, heightt, params)
{
    var tp = Math.ceil((screen.height - heightt) / 2);
    var lf = Math.ceil((screen.width - widthh) / 2);
    if (params.length > 0)
	    params = "," + params;

    var win = window.open(loc, winname, "width=" + widthh + ",height=" + heightt + ",top=" + tp + ",left=" + lf + params);
    win.focus();
    return win;
}

  function hideProfileMenu()
  {
	gebi("profileMenu").style.display = "none";
  }
  function showProfileMenuFriend(obj,name,member_id, is_friend,photo)
  {
		gebi("profileMenu").style.top = (absPosition(obj).y + obj.offsetHeight - 60) + "px";
        gebi("profileMenu").style.left = (absPosition(obj).x + obj.offsetWidth) + "px";
        gebi("profileMenu").innerHTML = '<b>'+ name +'</b><br>';
        if (photo != '')
          {
            gebi("profileMenu").style.top = (absPosition(obj).y + obj.offsetHeight - 120) + "px";
            gebi("profileMenu").style.height = "260px";
            gebi("profileMenu").innerHTML += '<img src="'+photo+'" border="0"><br>';
          }
        gebi("profileMenu").innerHTML += '<a href="#" onclick="showProfilePhoto('+member_id+'); return false;" style="line-height:25px;">Увеличить фото</a><br>';
        gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'member/friend/profile/'+member_id+'" style="line-height:25px;">Просмотреть профайл</a><br>';
        gebi("profileMenu").innerHTML += '<a href="#" onclick="sendMessageToUser('+member_id+'); return false;" style="line-height:25px;">Отослать сообщение</a><br>';
        gebi("profileMenu").innerHTML += '<a href="' + BASE_URL + 'member/messages/messaging/'+member_id+'" style="line-height:25px;">Просмотреть переписку</a><br>';
		gebi("profileMenu").style.display = "";
  }

  function str_replace(search, replace, subject)
  {
    return subject.split(search).join(replace);
  }

  function show_flash_card(div_name,file, width, height)
   {
     var s1 = new SWFObject(file,"ply",width,height,"9","#FFFFFF");
     s1.addParam("allowfullscreen","true");
     s1.addParam("allowscriptaccess","always");
     s1.write(div_name);
   }
   function show_flash_banner(div_name,file, width, height,color)
   {
     var s1 = new SWFObject(file,"ply",width,height,"9",color);
     s1.addParam("allowfullscreen","true");
     s1.addParam("allowscriptaccess","always");
     s1.write(div_name);
   }
   function show_flash_with_flashvars(div_name,file, width, height,flashvars)
   {
     var s1 = new SWFObject(file,"ply",width,height,"9","#FFFFFF");
     s1.addParam("allowfullscreen","true");
     s1.addParam("allowscriptaccess","always");
     s1.addParam("flashvars",flashvars);
     s1.write(div_name);
   }

  function show_flash_video(div_name,file,thumbnail)
   {

     var s1 = new SWFObject(BASE_URL + "public/mediaplayer/player.swf","ply","420","350","9","#FFFFFF");
     s1.addParam("allowfullscreen","true");
     s1.addParam("allowscriptaccess","always");
     s1.addParam("flashvars","file="+file+"&autostart=true&image="+thumbnail);
     s1.write(div_name);

    /*
     var flashvars = false;
      var params = {
         menu: "true",
         allowfullscreen: "true",
         allowscriptaccess: "always",
         flashvars: "file="+file+"&autostart=true&image="+thumbnail
      };
      var attributes = {};
      swfobject.embedSWF(BASE_URL + "public/mediaplayer/player.swf", div_name, "420","350", "9.0.0","expressInstall.swf", flashvars, params, attributes);
    */
   }
  function createNewLayerWindow()
   {
      new_layer_window = new Windoo(
       {
         "top": 200,"width": 200,"width": 450,"height": 400,
         ghost: {resize: true, move: true},
         buttons: {menu: true, close: true},
         theme: Windoo.Themes.alphacube,
         resizable: true,
         "container": "body",
         "class": "custom-windoo",
         title: "Otkritka.com",
         destroyOnClose : false,
         "shadow": true
       }).setHTML('<div id="new_layer_window_content" ></div>').hide();

       new_layer_window.addEvent('onClose', function() {
           document.getElementById('new_layer_window_content').innerHTML = '';
        });

   }
function copyFunc(el)
  {
    var txt = document.getElementById(el).value;
    window.event.returnValue = false;
    window.clipboardData.setData("Text", txt);
    alert('Код для  блога скопирован в буфер обмнена');
  }
function selectText(input) {
    if (input.createTextRange) {
        var oRange = input.createTextRange();
        oRange.moveStart("character", 0);
        oRange.moveEnd("character", 0);
        oRange.select();
    } else if (input.setSelectionRange) {
        input.setSelectionRange(0, input.value.length);
    }

    input.focus();
};
function checkEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   else {
      return true;
   }
}

function checkForgotEmail(el)
 {
   if (checkEmail(el.value))
     {
       document.getElementById('forgot_button').disabled = '';
     }
   else
     {
       document.getElementById('forgot_button').disabled = 'disabled';
     }
 }

function change_banner()
 {
   var ban = banners[bnner_index];
   if (ban['type'] == 'code')
     {
        var RndNum4NoCash = Math.round(Math.random() * 1000000000);
        var ar_Tail='unknown'; if (document.referrer) ar_Tail = escape(document.referrer);
        document.getElementById('banner_r').innerHTML = '<iframe src="http://ad.adriver.ru/cgi-bin/erle.cgi'
                                                      + '?sid=121588&bn=0&target=blank&bt=22&pz=0&tail256=' + ar_Tail + '&rnd=' + RndNum4NoCash
                                                      + '" frameborder=0 vspace=0 hspace=0 width=240 height=400'
                                                      + ' marginwidth=0 marginheight=0 scrolling=no></iframe>';
     }
   else
     {
        show_flash_card('banner_r','http://www.otkritka.com/public/banners/' + ban['file'], 240, 400);
     }
   bnner_index++;
   if (bnner_index == banners.length)
     {
       bnner_index = 0;
     }
   var myRequest = new Request({method: 'post', url: BASE_URL + 'banner/click_ajax',
                                    onSuccess : function(responseText, responseXML){

                                    }
                                   }).send('banner_id='+ban['id']+'&bnner_index='+bnner_index);
   setTimeout("change_banner()",30 * 1000)
 }