﻿
	var isel_level = 0; // level of selects to hide
	var s_log_string = ''; // logging of user actions
	var wait_timer=null;  // reference to wait logo timeout 
	var bAllowOpen = true;	
	var gsmoffset=0;
	var bTimer;
    var onloads = new Array();	
    var imar = new Array();

    var ua_ag = (navigator==null||navigator.userAgent==null)?'':navigator.userAgent.toLowerCase();
    var ua_op = (ua_ag.indexOf('opera')!=-1);
    var ua_ie = !ua_op&&(ua_ag.indexOf('msie')!=-1);
    var ua_fx = (ua_ag.indexOf('firefox')!=-1);
    
    var g_user_avatar = '';
    var g_reload_new_users_page = 0;
    var g_reload_new_users_sex  = 0;
    var g_reload_new_users_cnt_pages = 1;
    
	var g_switch_comment = 1; /*1-preview, 2-comments, 3-add comment*/
	var g_comment_guid;
	var g_media_type;/*1-photo,2-video,4-audio*/
	var g_comment_to_page =1; /*1-image, 2-comment*/

	function checkGuestAcces(msg) {
	    if (parseInt(g_user_id) == parseInt(synci.guest_id)) {
	        if ($('form_close_top')) $('form_close_top').onclick();
	        if (msg != '' && msg != undefined) {
	            showForm('p_register', msg);
	        } else {
                showForm('p_register', synci.need_for_registration_actions);
	        }
	        return false;
	    } else {
            return true;	    
	    }
	}
	
	function init_p_register(item_id){
	    wait_hide(0);
	    $('reg_msg_text').innerHTML = item_id;
	    popBrands('','','');
	}
	
	function register_new(){
	    var re = new RegExp(synci.phone_format)
        var gmtoff = gmt_offset();
        var sms_acknowledgement = '';
		if (synci.reg_sms_mode == '1') {
		    var slogin = $('login_name').value.trim();
		    var spassword = $('password').value.trim();
		    var semail = $('email').value.trim();
		    var iphoneid = '';
		    var sphonenumber = '';
		    sms_acknowledgement = $('sms_acknowledgement');
            if (!(/^[A-Za-z0-9]{3,}$/.test(slogin))) {
			    alertw(synci.hm_login_format);
            } else if (!(/^[A-Za-z0-9]{3,}$/.test(spassword))) {
			    alertw(synci.hm_incorrect_repeat_pass);
            } else if (!checkEmail(semail)) {
			    alertw(synci.hm_incorrect_mail_format);
            } else if ($('ch_agree') && !$('ch_agree').checked) {
			    alertw(synci.hm_agreement_not_passed);
            } else if(sms_acknowledgement.value.length==0) {
			    alertw(synci.hm_sms_acknowledgement_not_enter);
            } else {
                var aj = new Ajax.Request(synci.ajax_url,{method: 'get', parameters: 'saction=register&slogin='+escape(slogin)+'&semail='+escape(semail)+'&iphoneid='+iphoneid+'&sphonenumber='+escape(sphonenumber)+'&gmtoff='+escape(gmtoff)+'&spassword='+escape(spassword)+'&sms_code='+escape(sms_acknowledgement.value)+'&fromg=1', onComplete: register_new_ok})
            }
        } else {
            var phone_masks 
		    var is_valid_num = 0
		    var sphonenumber = $('phone_number').value;
		    var slogin = $('login_name').value.trim();
		    var semail = $('email').value.trim();			
		    var iphoneid;
		    if ($('phone_id'))
		        iphoneid = $('phone_id').value;
		    else
		        iphoneid='0';
		    var mre;
		    phone_masks = synci.phone_masks.split(';');
		    for (i = 0; i < phone_masks.length - 1; i++) {
                mre = new RegExp(phone_masks[i]);
                if (mre.test(sphonenumber)) {
                    is_valid_num = 1
                }
            }
		    if (!(/^[A-Za-z0-9]{3,}$/.test(slogin)))
			    alertw(synci.hm_login_format);
		    else if (!checkEmail(semail))
			    alertw(synci.hm_incorrect_mail_format);
		    else if (iphoneid=='') {
			    alertw(synci.hm_phone_not_selected);
            } else if (is_valid_num == 0) {
		        alertw(synci.hm_phone_number_incorrect);
		    } else if  ($('ch_agree') && !$('ch_agree').checked) {
			    alertw(synci.hm_agreement_not_passed);
		    } else {
			    var aj = new Ajax.Request(synci.ajax_url,{method: 'get', parameters: 'saction=register&slogin='+escape(slogin)+'&semail='+escape(semail)+'&iphoneid='+iphoneid+'&sphonenumber='+escape(sphonenumber)+'&gmtoff='+escape(gmtoff)+'&spassword='+escape(spassword)+'&sms_code='+escape(sms_acknowledgement.value)+'&fromg=1', onComplete: register_new_ok})
		    }
        }		    
	}
		
	function register_new_ok(or){
		var x = or.responseXML.documentElement;
		var uid = x.firstChild == null ? '' : x.firstChild.nodeValue;
		if (uid=='') {
			alertw(synci.hm_register_unspec_error);
        } else if (uid=='-1') {
			alertw(synci.hm_customer_wmail_na);
		} else if (uid=='-2') {
			alertw(synci.hm_customer_wlogin_na);
        } else if (uid=='-3') {
				alertw(synci.hm_customer_sms_cod_na);			
		} else if (uid=='-44') {
		    alertw(synci.hm_phone_number_incorrect);
        } else if (uid=='-4') {
			alertw(synci.hm_customer_phone_invalid);
		} else if (uid=='-5') {
			alertw(synci.hm_customer_phone_ne_paycode);
		} else {
		    if (synci.reg_sms_mode == '1') {
		        alertw(synci.register_your_register_ok,register_ok_redir,null,null,register_ok_redir);
		    } else {
			    alertw(synci.register_your_password_by_sms,register_ok_redir,null,null,register_ok_redir);
            }
		}
	}
	
	function register_ok_redir() {
	    window.location.href = 'default.asp?saction=logoff';
	}
	
	
	function Mod(X, Y) { 
		return X - Math.floor(X/Y)*Y;
	};
	
	function Div(X, Y) {
		return Math.floor(X/Y) /* full range */ 
	}

	function unescapeHTML(val){
		var str = new String(val);
		str = str.replace(/&lt;/gi, '<');
		str = str.replace(/&gt;/gi,'>');
		str = str.replace(/&amp;/gi,'&');
		str = str.replace(/&quot;/gi,'\'');
		return str;
	}

	function escapeHTML(val){
		var str = new String(val);
		str = str.replace(/</gi, '&lt;');
		str = str.replace(/>/gi,'&gt;');
		return str;
	}

	/* Strips all HTML tags */		
	function stripTags(val){
		return val.replace(/<\/?[^>]+>/gi, '');
	}

    var local_handler=null;
    var arr_windows = new Array();
	document.onkeydown = ShortCutsHandlers;
	function ShortCutsHandlers(e) {
		var c;
		if (!e) var e = window.event;
		if (e.keyCode) c = e.keyCode;
		else if (e.which) c = e.which;       
		if (c==27) {
			if ($('alert_div')!=null){
	    		remove_video_flash_obj();
	    		remove_audio_flash_obj();
				alertClose();
			}
	    	else if (arr_windows.length>0){
	    		remove_video_flash_obj();
	    		remove_audio_flash_obj();
	        	closeFrm(arr_windows[arr_windows.length-1]);
	        }
		}
		if(local_handler!=null) local_handler(c,e);
	}

    
    function ipage() {	
		window.onerror=cerror;
        for ( var i = 0 ; i < onloads.length; i++ ) onloads[i]();
        
        preload_images('timen.gif','tr/i-bottom.gif','tr/i-repeater.gif','tr/l.gif','tr/minus.gif','tr/page-file.png','tr/page-foldericon.png','tr/page-openfoldericon.png','tr/plus.gif','tr/t.gif', 'lft_tas.gif', 'lft_cal.gif', 'lft_con.gif', 'lft_hlp.gif', 'lft_not.gif', 'lft_set.gif', 'lft_snc.gif', 'timen.gif','vc/em.gif','vc/fax.gif','vc/mb.gif','vc/mr.gif','vc/or.gif','vc/pg.gif','vc/ph.gif','vc/vc.gif','vc/ww.gif','indi3.gif')
        preload_images('su_favor_on.gif', 'su_favor_off.gif', 'su_comments_off.gif','su_avatar_on.gif','su_comments_on.gif','su_friend_on.gif','su_anketa_on.gif','su_msm_on.gif','su_alblum_on.gif','su_prop_on.gif','su_delete_on.gif','su_friend_off.gif','su_avatar_off.gif','su_album_off.gif','su_prop_off.gif','su_anketa_off.gif','su_comment.gif','su_delete_off.gif','su_delete.gif','su_properties.gif','su_msm_off.gif','su_msm.gif','photo_mnub_o.gif','close_im.gif','dj_mnu_bot.gif','dj_mnu_top.gif','dj_photo_menu.jpg','dj_add_photo.jpg','photo_bg.gif','photo_mnut.gif','photo_mnub.gif','menu_gr.gif','menu_grad.gif','cross_alert.gif');
        preload_images('audio_bg1.gif','audio_bg2.gif','audio_cat_ru.gif','audio_cat_ua.gif','audio_instructions_ru.gif','audio_instructions_ua.gif','audio_title_ru.gif','audio_title_ua.gif','audio_visibility_ru.gif','audio_visibility_ua.gif');
        preload_images('forum_unread.gif','forum_alert.gif','forum_close.gif','forum_open.gif','forum_hide.gif','forum_unhide.gif','forum_edit.gif','forum_hidden.gif','forum_move.gif','woman_ico.gif','man_ico.gif');
    }	
    

    function preload_images(){
        for (var x=0; x<preload_images.arguments.length; x++){
            imar[x] = new Image();
            imar[x].src = 'img/'+preload_images.arguments[x];
        }
    }
    
    
	function cerror(msg, url, linen){
	    var bIgnoreError = false;
	    
	    if (msg.indexOf('set_tip is not defined')!=-1 || msg.indexOf('setOpacity is not defined')!=-1)
	        bIgnoreError = true; //fix exit problem in FX
	
	    if (!bIgnoreError) {
		var sHtml=synci.cm_unspecified_error+'<br/><br/>';
		sHtml += '<a href="javascript:err_dt.style.display=\'block\';void(0);" style="font-size:9px">'+synci.cm_more_details+'</a>';
		sHtml += '<div style="display:none" id="err_dt" style="font-size:10px">';
		sHtml += 'err:'+msg+'<br/>';
		sHtml += 'ln:'+linen+'<br/>';		
		sHtml += 'p:'+url+'<br/>';	
		sHtml += 'u:'+unescape(readCookie('uid'))+'<br/>';				
		sHtml += s_log_string;
		sHtml += '</div>'
		
        var opt = {method:'get', parameters:'saction=logerror&uid='+readCookie('uid')+'&err='+escape(msg)+'&line='+escape(linen)+'&url='+escape(url)+'&log='+escape(s_log_string)};
		var aj = new Ajax.Request(synci.ajax_url,opt)		
		
		alertw(sHtml);	
		}
		wait_hide(0);		
		return true
	}

	function fnn(a) {
		if (fnn.caller!=null) {
			var s = fnn.caller.toString();
			var n = s.split ('(')[0];
				n=n.split (/[' '{1,}]/)[1]+'(';
			for (i=0; i<a.length; i++) {
				n+=typeof(a[i]) + ':' + a[i];
				n+= i<a.length-1 ? ',' : '';
			}
			s_log_string = n+')';
			return n+')';		
		}
	}

    //wait logo funcs
    function wait_show(){
		if (wait_timer==null) {
			var d = document;
			var b = document.getElementsByTagName('body');	
			var im = cr('img')
			im.id = 'wait_logo';
			im.className = 'wait_logo';
			im.src='img/timen.gif';
			im.style.visibility='hidden';
			ap(b[0],im);
			im.style.top = (d.documentElement.scrollHeight - im.offsetHeight-200)/2 + "px";
			im.style.left = (d.documentElement.scrollWidth - im.offsetWidth)/2 + "px";	
			im.style.visibility='visible';	
		} else {
			clearTimeout(wait_timer);
			wait_timer = null;
		}
    }
    
   
    function wait_hide(i_timer){
		wait_timer = setTimeout(wait_hide_now,i_timer);
    }    
    function wait_hide_now(){
		if ($('wait_logo')!=null)
			document.getElementsByTagName('body')[0].removeChild($('wait_logo'));
		wait_timer = null;
    }
    
	function bo(){ // block opening on clicks 
		bAllowOpen = false;
        setTimeout(function(){bAllowOpen = true;},100);	
	}
	
	function bo_long(){ // block opening on clicks 
		bAllowOpen = false;
        setTimeout(function(){bAllowOpen = true;},5000);	
	}
    
    function confirmw(txt, fOk, fCancel) {
        alertw(txt, function(){alertClose();fOk();}, null, 'alert_confirm.asph', function(){alertClose();fCancel();});
    }
    
    function upload_media_center() {
        if (document.selection) {
            $('msg_new_text').focus();
            bb_g_um_target = document.selection.createRange();
            $('msg_new_text').focus();
        }
        txt = ''
        alertw(txt, function(){bb_UploadFile_Send();}, null, 'upload_media_center.asph',function(){CloseAlertWindow();});
    }
    
    function re_upload_media_center() {
        txt = ''
        alertw(txt, function(){bb_UploadFile_Send();}, null, 'upload_media_center.asph',function(){CloseAlertWindow();},function(){bb_UploadMediaOldValue();});
    }
    
	// alert and modal functions    	
	function alertw(txt, fInsteadClose, no_rep_cookie_name, sTemplatePage, fCancel, fOnLoad, url_parameters){
		if(url_parameters==null || url_parameters==undefined)
			url_parameters='';
		if ((no_rep_cookie_name!=null) && (readCookie(no_rep_cookie_name)=='on')) return;
				var opt = {
						method: 'get', 
						parameters: url_parameters,
						onComplete : function alertShow(or){
						                var d = document; var b = document.getElementsByTagName('body');	
						                alert_div = $('alert_div');
					                    if ($('alert_div')==null) {
									        alert_div = cr('div');
									        alert_div.id = 'alert_div';
									        alert_div.name = 'alert_div_4dg';
									        ap(b[0],alert_div);	
									        modalShow('alert_div');
						                }
						                alert_div.onmousedown = function(){try {dragStart(event, this.id);} catch (e) {false;}};
										alert_div.innerHTML = or.responseText;
										if (txt!=null) $('alert_message').innerHTML = txt;
										// disable title selection
										if ($('alert_title')!=null) $('alert_title').onselectstart=function (){return false;};
										
										
										if (fInsteadClose==null){
											if($('alert_ok'))
												$('alert_ok').onclick = alertClose;
											if($('alert_close'))
												$('alert_close').onclick = alertClose;
										}
										else{
											if($('alert_ok'))
												$('alert_ok').onclick = fInsteadClose;
											if($('alert_close'))
												$('alert_close').onclick = fInsteadClose;
										}

										if (fCancel!=null){
											if($('alert_cancel'))
										    	$('alert_cancel').onclick = fCancel;
										    if($('alert_close'))
										    	$('alert_close').onclick = fCancel;
										}
										
										if (no_rep_cookie_name!=null) {
											$('alert_no_repeat').style.display='block';
											$('norep_chk').value=no_rep_cookie_name;
										}
										alert_div.style.top = (d.documentElement.scrollHeight - alert_div.offsetHeight)/2 + "px";
										alert_div.style.left = (d.documentElement.scrollWidth - $('alert_message').offsetWidth)/2 + "px";
										if (d.documentElement.scrollHeight - alert_div.offsetHeight < 5) alert_div.style.top = '5px';
										alert_div.style.display='block';
										if (fOnLoad!=null) fOnLoad();
									}						
						}
			    if (sTemplatePage==null) sTemplatePage = 'alert.asph';
			    sTemplatePage = 'xhtml/' + sTemplatePage;
				var aj = new Ajax.Request(sTemplatePage,opt);
	}						
	
	function LightBoxImg(guid, url, stitle, rqt, m_g_category, m_g_tag_id) {
		if(rqt==null || rqt==undefined){
			rqt = 0;
		};
		var func = null;
		var mtype=1;//1-img, 2-video, 4-audio
		if (url.lastIndexOf('flv')>-1) {
			mtype = 2;
		}
		else if(url.lastIndexOf('mp3')>-1) {
			mtype = 4;
			g_audio_mode = 1;
			func = function(){init_audio_swf_object(guid)};
		}
		
		g_switch_comment=1; 
        alertw('',null,null,'media_comment.asp', LightBoxClose, func, 'guid='+guid+'&stitle='+escape(stitle)+"&mtype="+mtype+'&rqt='+rqt+'&m_g_category='+m_g_category + '&m_g_tag_id='+m_g_tag_id);
	}

	function LightBoxClose(){
		remove_video_flash_obj();
        remove_audio_flash_obj();
        alertClose();
	}
	
	function CallAddComment(){
		if (checkGuestAcces('')) {
		    switchComment(3, $('cm_media_type').value, $('cm_guid').value);
        }		    
	}
	function SwitchCommentPage(){
		if(g_comment_to_page==2){
			g_comment_to_page = 1;
			g_switch_comment = 1;
			switchComment(1, $('cm_media_type').value, $('cm_guid').value);
		}
	}
	
	function switchComment(value, media_type, guid){
	    if ($('media_links'))  $('media_links').style.display='none';
		if(value==4){
			if($('cm_comment_new_text').value==synci.comment_your_comment || $('cm_comment_new_text').value==''){
				return true;
			}
			g_comment_guid = guid;
			$('cm_button_add_comment').innerHTML=synci.comment_add_comment;
			$('cm_command_num').value='3';
			reload_addComment(guid, media_type, $('cm_comment_new_text').value);
			$('cm_comments_count').value = parseFloat($('cm_comments_count').value) + 1;
			//$('cm_comment_new_text').value=synci.comment_your_comment;
			$('cm_comment_new_text').onclick=new Function('clearComment(this)');
		}
		else if(value==3){
		
	        smiles_line = 1;
            next_smiles_line();
			g_switch_comment = 2;
			if(media_type==1){
				$('cm_buttons').innerHTML=synci.comment_picture;
			} else if(media_type==2){
				$('cm_buttons').innerHTML=synci.comment_clip;
			} else if(media_type==4){
				$('cm_buttons').innerHTML=synci.comment_audio;
			}
			$('cm_command_num').value='4';
			$('cm_iframe').height='330';
			$('cm_commnets_td').height='337';
			$('cm_comments_tr').style.display='';
			$('cm_image').style.display='none';
			$('cm_comments').style.display='';
			$('cm_button_add_comment').innerHTML=synci.comment_add;
		}
		else{
			$('cm_command_num').value='3';
			//$('cm_comment_new_text').value=synci.comment_your_comment;
			$('cm_comment_new_text').onclick=new Function('clearComment(this)');
			if(g_switch_comment==1){
				g_switch_comment = 2;
				if(media_type==1){
					$('cm_buttons').innerHTML=synci.comment_picture;
				} else if(media_type==2){
					$('cm_buttons').innerHTML=synci.comment_clip;
				} else if(media_type==4){
					$('cm_buttons').innerHTML=synci.comment_audio;
				}

				$('cm_comments_tr').style.display='none';
				$('cm_commnets_td').height='501';
				$('cm_iframe').height='450';

					
				$('cm_image').style.display='none';
				$('cm_comments').style.display='';
			}
			else{
				g_switch_comment = 1;
				$('cm_button_add_comment').innerHTML=synci.comment_add_comment;
				$('cm_buttons').innerHTML=synci.comment_comments + ' (' + $('cm_comments_count').value + ')';
				$('cm_comments').style.display='none';
				$('cm_image').style.display='';
			}
		}
	}
    function reload_addComment(guid, media_type, text){
		if (checkGuestAcces('')) {
		    g_media_type = media_type;    	
		    var opt = {method:'get', parameters:'saction=add_comment&guid='+guid+"&media_type="+media_type+"&comment="+escape(text), onComplete:reload_addComment_ok};
		    var aj = new Ajax.Request(synci.ajax_url,opt);
        }		    
    }
    function reload_addComment_ok(or){
    	if (or.responseText=='-99') isloged();
    	var dt = new Date();
    	$('cm_iframe').src = 'media_comments.asp?guid='+g_comment_guid+'&data_type='+g_media_type+'&dt='+dt.getTime()+'#cm_end';
    	g_switch_comment=1;
    	switchComment(1, g_media_type);
    }
	

	
	function alertClose(){
		if ($('alert_div')!=null) {
			if ($('norep_chk').value!='') 
				if ($('norep_chk').checked) 
					createCookie($('norep_chk').value,'on');
					
			modalHide('alert_div');
			document.getElementsByTagName('body')[0].removeChild($('alert_div'));
			}
        
	}
	
	function CloseAlertWindow(){
		if ($('alert_div')!=null) {
			modalHide('alert_div');
			document.getElementsByTagName('body')[0].removeChild($('alert_div'));
        }
	}
	
	function modalShow(obj_id){
			var d = document; var b = document.getElementsByTagName('body');
				if (!document.getElementById('dmodal'+obj_id)) {
					var mObj = b[0].appendChild(d.createElement('div'));
					mObj.style.zIndex = parseInt(getStyle($(obj_id),'z-index')) -1;
					mObj.id = 'dmodal'+obj_id;
					mObj.className = 'dmodal';
					mObj.style.height=document.body.scrollHeight;
				}
				hideSelects(isel_level++);

	}
	function modalHide(obj_id){
	 if ($('dmodal'+obj_id)!=null) {
			document.getElementsByTagName("body")[0].removeChild($('dmodal'+obj_id));
			hideSelects(--isel_level,true); 		
	 }
	}
	
	//help page functions
	function lhlp(n_help_id){
		if (n_help_id!=null) {
			var o = $('hl'+n_help_id);	
			if (o.getAttribute('has_text')=='0') return true;
			$('hlp_content').setAttribute('help_id',n_help_id);}
		else {
			n_help_id = $('hlp_content').getAttribute('help_id');
			var o = $('hl'+n_help_id);				
		}
		if (o!=null) o.style.color='green';
		var c_parent = o.parentNode;
		while (c_parent.id!='help_nav_tree') {
				removeClass(c_parent,'spanClosed');
				removeClass(c_parent,'closed');				
				c_parent = c_parent.parentNode;
			}
	
		var old_help_id = $('hlp_content').getAttribute('old_help_id');
		if ((old_help_id!='') && (old_help_id!=null)) $('hl'+old_help_id).style.color='';
		$('hlp_content').setAttribute('old_help_id',n_help_id);

		var aj = new Ajax.Request(synci.ajax_url,{method: 'get', parameters: 'saction=gethelp&help_id='+n_help_id, onComplete: shlp})
	}
	function shlp(or){
		$('hlp_content').innerHTML=or.responseText;
		$('edit_block').value = or.responseText;
	}	

    function getHelp(help_id) {
		wait_show();
    	var aj = new Ajax.Request(synci.ajax_url,{method: 'get', parameters: 'saction=gethelp&help_id='+help_id, onComplete: getHelp_ok})    
    }

    function getHelp_ok(or){
		wait_hide(0);    
        var s = or.responseText; 
        var re = /lhlp\(/g; reImg = /<img src/g;
            s = s.replace(re,'getHelp(');
            s = s.replace(reImg,'<img style=\'display:none\' src');
                    
        alertw(s,null,null,'alert_help.asph',null,function (){if (!ua_ie) $('alert_message').style.width='93%';});
    }

	//end help functions
	
	
	//effects 
		function trs(obj){
			for (i=0;i<obj.childNodes.length;i++)	
					obj.childNodes[i].style.backgroundColor = '#F5F5F5'
		}
		function trc(obj){
			for (i=0;i<obj.childNodes.length;i++)	
					obj.childNodes[i].style.backgroundColor = '';
		}	
		
	    function sel_chk(obj_id){
		    this.cc_selected = (this.cc_selected ? false : true);
		    var objs = document.getElementsByTagName('input');
		    for (i=0;i<objs.length;i++) {
			    if (objs[i].type=='checkbox' && objs[i].id==obj_id) objs[i].checked=this.cc_selected;
			    }
	    }	

        function change_chk(obj_name){
            var obj = $(obj_name);
            if (obj!=null) obj.checked=!obj.checked
        }


	// login and settings
	function popBrands(brand_id,phone_id,clearBefore){
	    if ($('phone_brand_id')) {
    		populateSelect('phone_brand_id',arrBrands,clearBefore,brand_id);
	    	$('phone_brand_id').onchange=popModels;
    		$('phone_id').onchange=preparePhoneInfo;
	    	popModels(phone_id, brand_id);
        }
	}
	function popModels(phone_id, brand_id){
		var ibrand_id = (brand_id==null) ? parseInt($('phone_brand_id').options[$('phone_brand_id').selectedIndex].value) : brand_id;
		if (ibrand_id==-1) {
			populateSelect('phone_id',Array(),true);
			$('phone_id').disabled=true;
		} else {
			populateSelect('phone_id',arrPhones[ibrand_id],true,phone_id);
			$('phone_id').disabled=false;
		}
		preparePhoneInfo();
	}
	function preparePhoneInfo(){
		var ph_id = $('phone_id').value;
		if (arrPhoneNotes[ph_id]!=null) {
			$('phone_info').onclick=function (){alertw(arrPhoneNotes[ph_id]);};
			$('phone_info').style.display='inline';
		} else {
			$('phone_info').style.display='none';
		}
	}	

	
	// common logic functions 
	function isloged(){
		if (readCookie('uid')=='' || readCookie('uid')==null) {
			alertw(synci.cm_session_expired,function(){alertClose();logoff();});
			return false;
		}
		else
			return true;
	} 	
	function logoff(){
		window.location.href='default.asp?saction=logoff'
	}
	

    function check_ta_len(o,ml){
        if (o.value.length >= ml)
            o.value = o.value.substring(0,ml);
    }
	
				
	function cr(tag){return document.createElement(tag);}
	function ap(par,el){return par.appendChild(el);}	
	
	function populateSelect(obj_id, arr, clearBefore, selValue) {
		var osel = $(obj_id);
		var start_poz=0;
		if (osel!=null) {
			if (clearBefore) 
				osel.length=0;
			else
				start_poz = osel.length;
			for (i=0; i<arr.length; i+=2) {
					osel.options[start_poz + i/2] = new Option(arr[i+1],arr[i]);
					if ((selValue!=null) && (arr[i].toString()==selValue.toString())) 
						{ osel.selectedIndex = start_poz + i/2;}
				}
		}
	}
	
	function changeSelect(obj, sval) {
	    for (var i=0;i<obj.options.length;i++)
	        if (obj.options[i].value==sval) obj.selectedIndex = i;
	}
	
	function hideSelects(ilevel,isshow){
		var sels=document.getElementsByTagName("select");
		for(i=0; i<sels.length; i++){
			clev = sels[i].getAttribute('level')
			if (clev==null) {sels[i].setAttribute('level',0);clev=0}
			if (parseInt(clev)==ilevel) 
				sels[i].style.visibility = isshow ? 'visible' : 'hidden'
		}
	}
	
	// hides and unhindes item
	function hd_block(obj_id, is_hide){
		var obj = $(obj_id);
		if (obj!=null) 
			if (is_hide)
				{obj.style.display='';obj.style.display='none';}
			else						 
				{obj.style.display= (obj.tagName=='TR')?'':'block';}
	}			   					   
	
	//cookies utils
	function createCookie(name,value,days)
	{
		if (days)
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = escape(name)+"="+value+expires+"; path="+synci.cookies_path;

	}
	
	function readCookie(name)
	{
		var nameEQ = escape(name) + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++)
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
	function eraseCookie(name)	{createCookie(name,"",-1);}
	
	function loadHome(){}
	function loadDesk(){}	


	function ApplyEvents(arrRules){			   
		for (selector in arrRules){
			  var stype = selector.split(':')[0];
			  var svalue = selector.split(':')[1];
			  var spArr = svalue.split(',');					  
			  var oc = new Array();					  

			  if (stype=='id') 
			  	for (j=0;j < spArr.length; j++)
						if (document.getElementById(spArr[j])!=null) arrRules[selector](document.getElementById(spArr[j]));
	
			  if (stype=='class')
			  	for (j=0;j < spArr.length; j++){
						oc = document.getElementsByClassName(spArr[j]);
						for (i=0; i < oc.length; i++)	arrRules[selector](oc[i]);					  
				}
			  if (stype=='tag')
			  	for (j=0;j < spArr.length; j++){
						oc = document.getElementsByTagName(spArr[j]);
						for (i=0; i < oc.length; i++)	arrRules[selector](oc[i]);					  
				}
		}
	
	}			
	
	/* forms logic */
	
	function checkEmail(sValue) {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(sValue))
			return (true);
		else
			return (false);
	}
	
	
	/* date functions */
	
	function show_current_time(){
	    if (arguments.length!=0) gsmoffset = arguments[0];
	    var obj = $('time_info');
	    var dt = new Date();
	    dt.setHours(dt.getHours()-dt.getTimezoneOffset()/60);
	    var sdt = dt.getUTCDate()+'.'+(dt.getUTCMonth()+1)+'.'+dt.getUTCFullYear()+' '+dt.getUTCHours()+':'+add0(dt.getUTCMinutes())+' (GMT+'+gsmoffset+')';
	    if (obj.innerHTML!=sdt) obj.innerHTML=sdt;
        setTimeout(function(){show_current_time()},1000);
	}
	
	function add0(s){
	    if (String(s).length==0)
	        return '00'
	    else if (String(s).length==1)
	        return '0'+s
	    else
            return s+''	    
	}

    function gmt_offset(){
       var d = new Date();
       //return( -1 * d.getTimezoneOffset() / 60);
       return 2;
    }	
    
	function validateDate( strValue, retDate) {
	strValue = strValue.trim();
	var re = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}(\s\d{1,2}\:\d{1,2})?$/
	if(!re.test(strValue))
		return false; 
	else {
		var isOkDate = false;
		if (strValue.split(' ').length==2){
			var strDate = strValue.split(' ')[0];
			var strTime = strValue.split(' ')[1];
		}
		else {
			var strDate = strValue;
			var strTime = '';
		}

		var strSeparator = '.'; //strDate.substring(2,3) 	
		var arrayDate = strDate.split(strSeparator); //split date into month, day, year

		var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31, '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
		var intDay = arrayDate[0];

		if(arrayLookup[arrayDate[1]] != null) {
		if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
			isOkDate = true; 
		}

		var intMonth = parseFloat(arrayDate[1]);
		var intYear = parseFloat(arrayDate[2]);		
		if (intMonth == 2) { 
		if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
			isOkDate = true; 
		}
		if (isOkDate) {
			if (strTime=='' || ((parseInt(strTime.split(':')[0])<24) && (parseInt(strTime.split(':')[1])<60)))
				isOkDate = true; 
			else
				isOkDate = false; 
		}
		if (retDate==null)
		    return isOkDate;
		else {
		    var dtRet;
		    dtRet = new Date(intYear, intMonth-1, intDay,strTime.split(':')[0],strTime.split(':')[1]);
		    return dtRet;
		}
	}

	}

    function getWeek(dt){
        var year = dt.getFullYear();
        var month = dt.getMonth()+1;
        var day = dt.getDate();
        var a = Math.floor((14-(month))/12);
        var y = year+4800-a;
        var m = (month)+(12*a)-3;
        var jd = day + Math.floor(((153*m)+2)/5) + 
                     (365*y) + Math.floor(y/4) - Math.floor(y/100) + 
                     Math.floor(y/400) - 32045;
        var d4 = (jd+31741-(jd%7))%146097%36524%1461;
        var L = Math.floor(d4/1460);
        var d1 = ((d4-L)%365)+L;
        NumberOfWeek = Math.floor(d1/7) + 1;
        return NumberOfWeek;        
    }

	function frDate(dt){
		return dt.getDate() +'.'+fr02(dt.getMonth()+1)+'.'+dt.getFullYear()+' ' + fr02(dt.getHours()) + ':' + fr02(dt.getMinutes());
	}

	
	function fr02(sval){;return (String(sval).length == 1) ? '0' + sval : sval;}	
	
	
	String.prototype.trim = function() {return this.replace(/^\s+|\s+$/, '');}
	/* Encode string for JavaScript Code*/	
	String.prototype.encodeJS = function() {return this.replace(/\\/g,'').replace(/\'/g,'\\\'')}
	
	/* visual effects */ 
	
	function FadeTextIn(obj_id){
		if($(obj_id)){
		    $(obj_id).style.color='';
		    setOpacity($(obj_id+'i'),100);
		}
	}
	function FadeTextOut(obj_id){
		if($(obj_id)){
		    $(obj_id).style.color='#6152FA';
		    setOpacity($(obj_id+'i'),100);
		}
	}

  function getStyle(element, style) {
    var value = element.style[style.camelize()];
    if (!value) {
      if (document.defaultView && document.defaultView.getComputedStyle) {
        var css = document.defaultView.getComputedStyle(element, null);
        value = css ? css.getPropertyValue(style) : null;
      } else if (element.currentStyle) {
        value = element.currentStyle[style.camelize()];
      }
    }

    if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
      if (Element.getStyle(element, 'position') == 'static') value = 'auto';

    return value == 'auto' ? null : value;
  }


    function loadjs(lName) {
        var html_doc = document.getElementsByTagName('head').item(0);
        var js = document.createElement('script');
        js.setAttribute('language', 'javascript');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', lName);
        html_doc.appendChild(js);
        return false;
    }
  


    function findPosX(obj)
    {
	    var curleft = 0;
	    if (obj.offsetParent)
	    {
		    while (obj.offsetParent)
		    {
			    curleft += obj.offsetLeft;
			    obj = obj.offsetParent;
		    }
	    }
	    else if (obj.x)
		    curleft += obj.x;
	    return curleft;
    }

    function findPosY(obj)
    {
	    var curtop = 0;
	    if (obj.offsetParent)
	    {
		    while (obj.offsetParent)
		    {
			    curtop += obj.offsetTop;
			    obj = obj.offsetParent;
		    }
	    }
	    else if (obj.y)
		    curtop += obj.y;
	    return curtop;
    }
    
    function getRadioValue(sname) {
        radioObj = document.getElementsByName(sname);
	    if(!radioObj)
		    return "";
	    var radioLength = radioObj.length;
	    if(radioLength == undefined)
		    if(radioObj.checked)
			    return radioObj.value;
		    else
			    return "";
	    for(var i = 0; i < radioLength; i++) {
		    if(radioObj[i].checked) {
			    return radioObj[i].value;
		    }
	    }
	    return "";
    }
    
    
    function inArr(arr,val){
        val = val.toLowerCase();
        for (var i=0;i<arr.length;i++)
            if (arr[i].toLowerCase()==val) return i;
        return -1;
    }    
    
    function imgFade(img_id){
        var o = $(img_id);
        if (o) {
            setOpacity(o, 0);
            o.style.visibility = 'visible';
            im_fadeIn(img_id,0);
        }
    }
    
    function im_fadeIn(img_id,opacity) {
        o = $(img_id);
        if (opacity <= 100) {
          setOpacity(o, opacity);
          opacity += 25;
          setTimeout("im_fadeIn('"+img_id+"',"+opacity+")", 50);
        }
    }    
    
    function setOpacity(obj, opacity) {
      if (obj) {
          opacity = (opacity == 100)?99.999:opacity;
          obj.style.filter = "alpha(opacity:"+opacity+")";
          obj.style.KHTMLOpacity = opacity/100;
          obj.style.MozOpacity = opacity/100;
          obj.style.opacity = opacity/100;
      }
    }
    
    var g_timerID1=0;
    var g_timerID2=0;
    var g_timerID2_count=0;
	var g_stop_reloading_timer=0;
	var g_prev_mouse_x=-1;  
	var g_prev_mouse_y=-1;
	var g_mouse_x = 0;
	var g_mouse_y = 0;
	

	document.onmousemove=function(e){
     	if (!e) var e = window.event;		
		if (e.pageX) {
			g_mouse_x = e.pageX;
			g_mouse_y = e.pageY;			
		}else {
			g_mouse_x = e.clientX;
			g_mouse_y = e.clientY;
		}
	};
	
    function reload_stat_info(){
    	if (g_prev_mouse_x==g_mouse_x && g_prev_mouse_y==g_mouse_y) 
    		g_stop_reloading_timer+=parseInt(synci.timer_reload_stat);
    	else
    		g_stop_reloading_timer=0;
    	g_prev_mouse_x = g_mouse_x;
    	g_prev_mouse_y =g_mouse_y;
    	if (g_stop_reloading_timer < parseInt(synci.user_time_online_sec)) {
			var opt = {method:'get', parameters:'saction=reload_stat', onComplete:reload_stat_info_ok};
			var aj = new Ajax.Request(synci.ajax_url,opt);
		}
		setTimeout("reload_stat_info()", synci.timer_reload_stat*1000);
    }



    function reload_stat_info_ok(or){
    	var on, at_name,on_val;
		if (or.responseText=='-99') isloged();
		var oroot = or.responseXML.documentElement;
		for (var i=0; i<oroot.childNodes.length; i++) {
			on = oroot.childNodes[i];
			at_name = on.attributes.getNamedItem('name').nodeValue;
			if(on.childNodes.length > 0)
				on_val = unescape(on.childNodes[0].nodeValue);
			else{
				on_val = "";
			}
			switch (at_name) {
				case 'msg_unread_all'		: $('us_msg_cnt_unread').innerHTML = on_val;break;
				case 'msg_unread_new'		: $('us_msg_unread_new').innerHTML = on_val;break;
				case 'msg_guests'			: $('us_msg_guests').innerHTML = on_val;break;				
				case 'users_count_all'		: $('us_users_count_all').innerHTML = on_val;break;
				case 'users_count_online'	: $('us_users_count_online').innerHTML = on_val;break;
				case 'users_count_friend_online': $('us_users_count_friend_online').innerHTML = on_val;break;				
				case 'users_count_reg_today': $('us_users_count_reg_today').innerHTML = on_val;break;
				//case 'photo_count_all'		: $('us_photo_count_all').innerHTML = on_val;break;
				case 'photo_count_all_photo': $('us_photo_count_all_photo').innerHTML = on_val;break;
				case 'photo_count_all_picture': $('us_photo_count_all_picture').innerHTML = on_val;break;
				//case 'photo_count_today'	: $('us_photo_count_today').innerHTML = on_val;break;
				case 'photo_count_today_photo': $('us_photo_count_today_photo').innerHTML = on_val;break;
				case 'photo_count_today_picture': $('us_photo_count_today_picture').innerHTML = on_val;break;
				case 'video_count_all'		: $('us_video_count_all').innerHTML = on_val;break;
				case 'video_count_today'	: $('us_video_count_today').innerHTML = on_val;break;
				case 'audio_count_all'		: $('us_audio_count_all').innerHTML = on_val;break;
				case 'audio_count_today'	: $('us_audio_count_today').innerHTML = on_val;break;				
				//case 'photo_count_friend'	: $('us_photo_count_friend').innerHTML = on_val;break;
				case 'photo_count_friend_photo'	: $('us_photo_count_friend_photo').innerHTML = on_val;break;
				case 'photo_count_friend_picture': $('us_photo_count_friend_picture').innerHTML = on_val;break;
				case 'audio_count_friend'	: $('us_audio_count_friend').innerHTML = on_val;break;
				case 'video_count_friend'	: $('us_video_count_friend').innerHTML = on_val;break;
				case 'bb_unread_topic_cnt'	: $('us_new_in_forum').innerHTML = on_val;break;
				case 'avatar_guid'			: av_guid=on_val;break;
			}

		}
		if(av_guid.length>0 && av_guid!=g_user_avatar){
			g_user_avatar = av_guid;
			$('us_avatar').src = synci.remote_media_server + 'img/sm/' + av_guid + '.jpg';
		}
    }
    
    function reload_new_users(sex){
    	var r_continue=true;
    	if(sex==undefined){
    		g_reload_new_users_sex = 0;
    		g_reload_new_users_page = 0;
    	}
    	else{
    		if(sex!=g_reload_new_users_sex){
    			g_reload_new_users_sex = sex;
    			g_reload_new_users_page = 0;
    		}
    		else{
    			if(g_reload_new_users_cnt_pages==g_reload_new_users_page){
    				r_continue=false;
    			}
    		}
    	}
    	if(r_continue){
    		g_reload_new_users_page++
			var opt = {method:'get', 
					   parameters:'saction=reload_new_users&sex='+g_reload_new_users_sex+"&page="+g_reload_new_users_page, 
					   onComplete:reload_new_users_ok
					  };
		    if (g_stop_reloading_timer < parseInt(synci.user_time_online_sec)) {
				var aj = new Ajax.Request(synci.ajax_url,opt);
			} 
			if (g_reload_new_users_sex==0) 
				setTimeout("reload_new_users()", synci.timer_load_img_new_user*1000);
		}
    }
    
    function reload_new_users_ok(or){
    	var on, at_name,str='',av_guid='',title='';
		if (or.responseText=='-99') isloged();
		var oroot = or.responseXML.documentElement;
		cnt = parseInt(oroot.attributes.getNamedItem('cnt').nodeValue);
		n_us_psize = parseInt(oroot.attributes.getNamedItem('n_us_psize').nodeValue);
		g_reload_new_users_cnt_pages = Math.ceil(cnt/n_us_psize);
		var i=0
		for (i=0; i<oroot.childNodes.length; i++) {
			on = oroot.childNodes[i];
			av_guid = on.attributes.getNamedItem('avat').nodeValue;
			title = on.attributes.getNamedItem('un').nodeValue;
			if(av_guid.length>0){
				if ($('us_im'+(i+1))) $('us_im'+(i+1)).innerHTML = '<img class="us_stat" onclick="m_showUserProfile('+on.attributes.getNamedItem('uid').nodeValue+')" alt="'+title+'" src="'+synci.remote_media_server+'img/av/'+av_guid+'.jpg" style="border:1px solid gray;width:70px;height:70px" />';
			}
			else{
				if ($('us_im'+(i+1))) $('us_im'+(i+1)).innerHTML = '<img class="us_stat" onclick="m_showUserProfile('+on.attributes.getNamedItem('uid').nodeValue+')" alt="'+title+'" src="img/dj_avatar.gif" style="width:70px;" />';
			}
		}
		for(var j=i;j<n_us_psize;j++){
			$('us_im'+(j+1)).innerHTML = '&nbsp;';
		}
    }
    
    function reload_leader() {
		var opt = {method:'get',parameters:'saction=reload_leader',onComplete:reload_leader_ok};
	    if (g_stop_reloading_timer < parseInt(synci.user_time_online_sec)) {
			var aj = new Ajax.Request(synci.ajax_url,opt);
		} 
        setTimeout("reload_leader()", synci.timer_load_img_new_user*1000);
    }
    
    function reload_leader_ok(or) {
        var on, at_name,str='',av_guid='',title='';
		if (or.responseText=='-99') isloged();
		var oroot = or.responseXML.documentElement;
		on = oroot.childNodes[0];
		av_guid = on.attributes.getNamedItem('avat').nodeValue;
		title = on.attributes.getNamedItem('un').nodeValue;
		if(av_guid.length>0){
			$('leader_area').innerHTML = '<img class="us_stat" onclick="m_showUserProfile('+on.attributes.getNamedItem('uid').nodeValue+')" alt="'+title+'" src="'+synci.remote_media_server+'img/av/'+av_guid+'.jpg" style="border:1px solid gray;width:70px;height:70px" />';
		}
		else{
			$('leader_area').innerHTML = '<img class="us_stat" onclick="m_showUserProfile('+on.attributes.getNamedItem('uid').nodeValue+')" alt="'+title+'" src="img/dj_avatar.gif" style="width:70px;" />';
		}
    }
    
    function reload_premium_msg() {
        var opt = {method:'get',parameters:'saction=reload_premium_msg',onComplete:reload_premium_msg_ok};
	    if (g_stop_reloading_timer < parseInt(synci.user_time_online_sec)) {
			var aj = new Ajax.Request(synci.ajax_url,opt);
		} 
        setTimeout("reload_premium_msg()", synci.timer_load_img_new_user*1000);
    }
    
    function reload_premium_msg_ok(or) {
        var on, at_name,str='',av_guid='',title='',premium_msg='';
		if (or.responseText=='-99') isloged();
		var oroot = or.responseXML.documentElement;
		on = oroot.childNodes[0];
		av_guid = on.attributes.getNamedItem('avat').nodeValue;
		title = on.attributes.getNamedItem('un').nodeValue;
		premium_msg = unescape(on.childNodes[0].nodeValue);
		if(av_guid.length>0){
			$('premium_av').innerHTML = '<img class="us_stat" onclick="m_showUserProfile('+on.attributes.getNamedItem('uid').nodeValue+')" alt="'+title+'" src="'+synci.remote_media_server+'img/th32/'+av_guid+'.jpg" style="border:1px solid gray;width:32px;height:32px" />';
		} else {
			$('premium_av').innerHTML = '<img class="us_stat" onclick="m_showUserProfile('+on.attributes.getNamedItem('uid').nodeValue+')" alt="'+title+'" src="img/g-b32.jpg" style="width:32px;" />';
		}
		$('premium_msg').innerHTML = premium_msg;
    }
    
    function reload_unsubscribe_daily_notify(){
		var opt = {method:'get', parameters:'saction=unsubscribe', onComplete:reload_unsubscribe_daily_notify_ok};
		var aj = new Ajax.Request(synci.ajax_url,opt);
    }
    function reload_unsubscribe_daily_notify_ok(or){
    	if (or.responseText=='-99') isloged();
    	if(or.responseText=="1")
    		alertw(synci.daily_notify_unsubscribe);
    }

    function reload_subscribe_daily_notify(){
		var opt = {method:'get', parameters:'saction=subscribe', onComplete:reload_subscribe_daily_notify_ok};
		var aj = new Ajax.Request(synci.ajax_url,opt);
    }
    function reload_subscribe_daily_notify_ok(or){
    	if (or.responseText=='-99') isloged();
    	if(or.responseText=="1")
    		alertw(synci.daily_notify_subscribe);
    }

    function reload_comment_unsubscribe(guid, mt){
		var opt = {method:'get', parameters:'saction=comment_unsubscribe&guid='+escape(guid)+'&mt='+mt, onComplete:reload_comment_unsubscribe_ok};
		var aj = new Ajax.Request(synci.ajax_url,opt);
    }
    function reload_comment_unsubscribe_ok(or){
    	if (or.responseText=='-99') isloged();
    	if(or.responseText=="1")
    		alertw(synci.comment_unsubscribe);
    }
        
    function clearComment(obj){
		obj.value='';
		obj.onclick=null;
    }
    
    function setd(o){
    		o.src='img/dj_avatar.gif';
    }
    
    /* mousemove*/
    function mm(val, type){
    	obj = $(val);
    	if(type==1)
    		obj.style.color='blue';
    	else if(type==2)
    		obj.style.textDecoration='underline';
    	else if(type==3)
    		obj.style.color='green';
    }
    /* mouseout */
    function mo(val, type){
    	obj = $(val);
    	if(type==1)
    		obj.style.color='';
    	else if(type==2)
    		obj.style.textDecoration='none';
    	else if(type==3)
    		obj.style.color='';
    }
    
	/* restore */
    function restore_sync_data(type){
		confirmw(synci.is_sync_restore_data, function(){var opt = {method:'get', parameters:'saction=restore_sync_data&type='+escape(type), onComplete:restore_sync_data_ok};var aj = new Ajax.Request(synci.ajax_url,opt);}, function(){});
    }
    function restore_sync_data_ok(or){
    	if (or.responseText=='-99') isloged();
    	if(or.responseText=="1")
    		alertw(synci.sync_restore_data_success);
    }


    /* smiles for comments */
    var smiles_line = 1;
    function next_smiles_line(){
        if ($('sml'+smiles_line)) {
            $('sml'+smiles_line).className='sml_inactive';
            smiles_line++;
            if ($('sml'+smiles_line)==null) smiles_line = 1;
            $('sml'+smiles_line).className='sml_active';
        }
    }
    
    function $sm(s)     { insIn($('cm_comment_new_text'),'['+s+']'); }
    function $smh(s)    { insIn($('msg_show_text'),'['+s+']'); }
    function $smn(s)    { insIn($('msg_new_text'),'['+s+']'); }
    function $smn_bb(s) { insBB($('msg_new_text'),s); }
    function $smch(s)   { insIn($('text'),'['+s+']'); }
    
   
    function insIn(o,s) {
        var scrrll = o.scrollTop;
        if (document.selection) {
         o.focus();
         var sel = document.selection.createRange();
         sel.text = s;
         o.focus();
        } else if (o.selectionStart || o.selectionStart == '0') {
            var startPos = o.selectionStart;
            var endPos = o.selectionEnd;
            o.value = o.value.substring(0, startPos)+ s + o.value.substring(endPos, o.value.length);
            o.focus();	    
            o.selectionStart = endPos + s.length;
            o.selectionEnd = endPos +  s.length;
        } else {
            o.value += s;
            o.focus();	    
        }        
        o.scrollTop = scrrll;
    }    
    
    function insBB(o,s) {
        var scrrll = o.scrollTop;
        if (document.selection) {
            o.focus();
            var sel = document.selection.createRange();
            sel.text = '['+s+']'+sel.text+'[/'+s+']';
            o.focus();
        } else if (o.selectionStart || o.selectionStart == '0') {
            var startPos = o.selectionStart;
            var endPos = o.selectionEnd;
            o.value = o.value.substring(0, startPos)+ '['+s+']'+o.value.substring(startPos,endPos)+'[/'+s+']' + o.value.substring(endPos, o.value.length);
            o.focus();	    
            o.selectionStart = endPos + s.length;
            o.selectionEnd = endPos +  s.length;
        } else {
            o.value += '['+s+'][/'+s+']';
            o.focus();	    
        } 
        o.scrollTop = scrrll;
    }
        
    function clipB(o){
        if (document.selection) {
            var c = o.createTextRange();
            c.select();
        } else {
            o.setSelectionRange(0,999);
        }
    }
    
    function playMp3(soundobj){
        if (ua_ie)
            document.all.page_sound.src = $(soundobj).src
        else
            try {$(soundobj).Play();}        catch (e) {false}
    }