function do_changeFont(i) {
	var fsize=(10+i*2)
	document.body.style.fontSize=fsize+'px';
	setCookie('fsize',fsize,365);
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";Path=/;expires="+exdate.toGMTString());
}

function doChangeTitle(title) {   document.title=title;
}

function LoadAvImg(id) {
	document.getElementById('av_img').src=av[id];
}

function reread_mail() {
	$("#mail_span").load("/ajax/dynamic_content.php",{"func":"getmail"});
	window.setTimeout('reread_mail()',30000);
//	if(isset('WeAreOnMailPage')) reread_mail_box();
}

function RequestFriend(login){
	$.getJSON("/ajax/users.php",{"action":"addfriend","login":login},function(data) {
		MB(data.msg);
	});
}

function InitCommentEditor(elem_name) {
	tinyMCE.init({
	// General options
	language : "ru",
	mode : "exact",
	elements : elem_name,
	theme : "simple",
	plugins : "safari,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,spellchecker,",
	spellchecker_languages : "+Русский=ru,English=en"
});}

function AuthFix() {
	$("#authlink").overlay({
		expose: {color: '#333',	loadSpeed: 200,	opacity: 0.9},effect: 'apple',onBeforeLoad:
		function() {
			var wrap = this.getContent().find(".contentWrap");
			wrap.load(this.getTrigger().attr("href"));
		}
	});
}

function InitStars(sel,vtip) {	$(sel).rating({		callback: function(value){
			StarSubmit(value);
		},
		focus: function(value, link){			var tip = $(vtip);
			tip[0].data = tip[0].data || tip.html();
			tip.html(link.title || 'value: '+value);
		},
		blur: function(value, link){
			var tip = $(vtip);
			$(vtip).html(tip[0].data || '');
		}
	});
}

function MBConfirmBox(text, onConf) {
	text='<table class="messagebox"><tr><td>'+text+'<br/><br/><input onclick="'+onConf+'ConfirmBoxClose();" type="button" value="Да" /><input onclick="ConfirmBoxClose();" type="button" value="Нет" /></td></tr></table>';
	$("#overlay .contentWrap").eq(0).html(text);
	messagebox_api = $("#linktop").overlay();
	messagebox_api.load();

}

function SendNewMail(user) {
	window.location.href = '/mail/newmailto_'+user+'/';
}

function MB(text) {
	text='<table class="messagebox"><tr><td>'+text+'<br/><br/><input onclick="ConfirmBoxClose();" type="button" value="OK" /></td></tr></table>';
	$("#overlay .contentWrap").eq(0).html(text);
	messagebox_api = $("#linktop").overlay();
	messagebox_api.load();
}

function ConfirmBoxClose() {
	messagebox_api = $("#linktop").overlay();
	messagebox_api.close();
}

function goDelComm(cfor,id) {	MBConfirmBox("Вы действительно хотите удалить комментарий?","processDelComm('"+cfor+"','"+id+"');");
}

function processDelComm(cfor,id) {	$.getJSON('/ajax/dynamic_content.php',{"func":"delete_comment","for":cfor,"id":id},function(data) {
		if(data.cfor=='photocomm') {   			LoadPhoto(data.id);		}
	});
}

function checkCommentForm() {	if(document.forms['addcom'].comnt.value.length<2) {		MB('Комментарий слишком короткий!');
		return false;	}	return true;
}

function SetRate(rate) {
	var rt=parseInt(rate);
	if(rt>=-5 && rt <= 5)
		document.getElementById('rate_num').innerHTML=rt;
}

function InitCommentsRate() {	ur_api=$(".ratelink").overlay({
		expose: {color: '#333',	loadSpeed: 200,	opacity: 0.9},api:true,effect: 'apple',onBeforeLoad:
		function() {
			var wrap = this.getContent().find(".contentWrap");
			wrap.load(this.getTrigger().attr("href"));
		}
	});
}

function UserRatePost(rfor,rfor2) {	ur_api=$(".ratelink").overlay();
	ur_api.close()
	var rate=parseInt(document.getElementById('rate_num').innerHTML);
	var rtext=document.getElementById('rate_text').value;
	$.getJSON('/ajax/user_rate.php',{"rate":rate,"for":rfor,"for2":rfor2,"text":rtext},function(data) {
		MB(data.msg);
	});
}

function FormComments(data) { 	var div='<h4>Комментарии</h4>';
 	var cc=data.length;
 	$.each(data, function(i,item) {
		div+='<a id="cid'+item.id+'"></a>';
		div+='<a href="/users/'+item.writer+'/">'+item.nick+'</a> '+item.datetime;
		if(data[i].ratebut) {			div+='&nbsp;<a rel="#overlay" class="ratelink" href="/ajax/user_rate.php?for='+item.cfor+'&amp;id='+item.id+'" title="Дайте оценку комментарию"><img width="10" height="10" src="/images/buttons/rate.gif" style="border:none" alt="Оценить" /></a>';		}
		if(data[i].delbut) {
			div+='&nbsp;<a href="javascript:;" onclick="goDelComm(\''+item.cfor+'\','+item.id+')" title="Удалить комментарий"><img width="10" height="10" src="/images/del.gif" style="border:none" alt="Удалить комментарий" /></a>';
		}
		div+='<br /><table class="commTable"><tr><td style="width:10px"><a title="О пользователе '+item.nick+'" href="/users/'+item.writer+'/"><img src="'+item.avatar+'" style="margin-right:10px;border:none" alt="Аватар" /></a></td><td>'+item.text+'</td></tr></table>';
 	});
 	return div;}


function FormCommAddTable(data) {	var div='<h4>Добавить комментарий</h4>';
	if(!data) return div+'Чтобы оставлять комментарии, необходимо авторизоваться.';
	div+='<form id="addcom" method="post" action="'+data.url+'" onsubmit="return checkCommentForm()"><table><tr><td style="width:10px"><select name="av_id" onchange="LoadAvImg(this.value);">';
	av = new Array();
	var avatar='/images/noav_'+((data.gender!="")?data.gender:'u')+'.gif';
	$.each(data.avatars, function(i,item) {    	av[i]=item.path;
    	div+='<option value="'+i+'"';
    	if(data.defav==i) {    		div+=' selected="selected"';
    		avatar=item.path;    	}
    	div+='>'+item.title+'</option>';	});
	div+='</select><br/><img style="border:1px" alt="Аватар" id="av_img" src="'+avatar+'" /></td><td>';
	div+='<textarea name="comnt" rows="4" cols="60"></textarea></td></tr></table><div><input type="submit" name="Submit" value="Добавить" /></div></form>';
 	return div;}

/* ----------- */


function stripHTML(){
 var re= /<\S[^><]*>/g
 for (i=0; i<arguments.length; i++)
   arguments[i].value=arguments[i].value.replace(re, "")
}

function trim() {
  for (i=0; i<arguments.length; i++)
  arguments[i].value=arguments[i].value.replace(/^\s+|\s+$/g,"");
}

function addslashes( str ) {
    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}
/*"*/
function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else return false;
  return false;
}

function initReq() {
  req=false;
  if(window.XMLHttpRequest)
  {
    req=new XMLHttpRequest;
    if (req.overrideMimeType) {
      req.overrideMimeType('text/html');}
  }
  else if(window.ActiveXObject)
  {
     req=new ActiveXObject("Microsoft.XMLHTTP");
  }

  return req;
}

function getElementsByName_fix(tag, name) {

     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}


function SecToWid(sec) {
  hr=0;
  min=0;
  while(sec>=3600) { sec-=3600; hr++; }
  while(sec>=60) { sec-=60; min++; }

  str="";
  if(hr>0) str+=hr+" ч. ";
  if(min>0) str+=min+" мин. ";
  str+=sec+" сек.";
  return str;
}


function InitEditor(elem_name) {
tinyMCE.init({
        // General options
        language : "ru",
        mode : "exact",
        elements : elem_name,
        theme : "advanced",
        plugins : "safari,spellchecker,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,cite,abbr,acronym,attribs,|,visualchars,nonbreaking,blockquote,|,insertfile,insertimage,spellchecker",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Example content CSS (should be your site CSS)
        content_css : "/designs/white/main.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "js/template_list.js",
        external_link_list_url : "js/link_list.js",
        external_image_list_url : "js/image_list.js",
        media_external_list_url : "js/media_list.js",
        spellchecker_languages : "+Русский=ru,English=en"

        // Replace values for the template plugin
});}
