//
// JavaScript
//
/*
function preload(images) { if (typeof document.body == "undefined") return; try { var div = document.createElement("div"); var s = div.style; s.position = "absolute"; s.top = s.left = 0; s.visibility = "hidden"; document.body.appendChild(div); div.innerHTML = "<img src=\"" + images.join("\" /><img src=\"") + "\" />"; } catch(e) { } }
preload([
	host+'style/indicator.gif',
	host+'style/green_mark.gif',
    host+'style/green_mark.gif',
    host+'style/indicator_small.gif',
    host+'style/ok.gif',
    host+'style/cancel.gif',
    host+'style/heart.gif',
    host+'style/arrow_left.gif',
    host+'style/arrow_right.gif',
    host+'style/arrow_left_over.gif',
    host+'style/arrow_right_over.gif',
    host+'style/arrow_big_left.gif',
    host+'style/arrow_big_right.gif',
    host+'style/arrow_small_left.gif',
    host+'style/arrow_small_right.gif',
    host+'style/i_user.gif',
    host+'style/i_addphoto.gif'
]);
*/
var indicator='<IMG src="'+host+'style/indicator.gif" width="32" height="32" alt="" border="0"/>';
var indicator_small='<IMG src="'+host+'style/indicator_small.gif" width="16" height="16" alt="" border="0"/>';
var indicator_ok='<IMG src="'+host+'style/ok.gif" width="20" height="20" alt="OK" border="0"/>';
var indicator_cancel='<IMG src="'+host+'style/cancel.gif" width="20" height="20" alt="OK" border="0"/>';
var indicator_heart='<img src="'+host+'style/heart.gif" width="15" height="14" alt="" border="0"/>';
var after_rate_comment='<img src="'+host+'style/green_mark.gif" width="9" style="padding: 0px 5px 0px 5px;" height="12" alt="" border="0"/>';
function markAsBusy(target) { $(target).empty(); $(target).set('html',indicator_cancel);  }
function markAsFree(target) { $(target).empty(); $(target).set('html',indicator_ok); }
function errorMessage(target, msg) { $(target).empty(); $(target).set('html',msg); clearByTimer(target); }
function markAsWaiting(target) { $(target).empty(); $(target).set('html',indicator); }
function markAsWaitingSmall(target) { $(target).empty(); $(target).set('html',indicator_small); }
function clearByTimer(target) { setTimeout('$('+target+').empty();', 1500); }
function AjaxRequest(result, url, pars, clear) { var req = new Request.HTML({url:url, onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) { if (result>"") { if (clear==true) { $(result).empty(); }  $(result).set('html', responseHTML);} }, onFailure: function() { if (result>"") { $(result).set('text', 'The request failed.');} } }); req.send(pars); }
var addComment=function () { var text=$('new_comment').get('value');if (text>"") {var id=$('id').get('value');var user_name=$('comment_user_name').get('value');var user_town=$('comment_user_town').get('value');var parent=$('parent').get('value');var pars="id="+id+"&parent="+parent+"&content="+encodeURIComponent(text)+"&user_name="+encodeURIComponent(user_name)+"&user_town="+encodeURIComponent(user_town)+"&action=addComment";var url=host+"modules/ajax.action.php"; layer='comments';var clear=false;AjaxRequest(layer, url, pars, clear);}}
function change_comment(id) { var text=$('change_comment_text_'+id).get('value'); var pars="comment_id="+id+"&content="+encodeURIComponent(text)+"&action=changeComment"; var url=host+"modules/ajax.action.php"; markAsWaitingSmall("comment_boby_"+id); var layer="comment_boby_"+id; var clear=true; AjaxRequest(layer, url, pars, clear); }
function moderator_comment(id) { var text=$('complaint_text').get('value'); if (text>"") { var pars="comment_id="+id+"&content="+encodeURIComponent(text)+"&action=complaintComment"; var url=host+"modules/ajax.action.php"; var layer=""; var clear=false; alert("Спасибо. Рассмотрим - покараем."); AjaxRequest(layer, url, pars, clear);} }
function mark_good_comment(id) { var pars="comment_id="+id+"&action=rateComment"; var url=host+"modules/ajax.action.php"; var layer=""; var clear=false; AjaxRequest(layer, url, pars, clear); $('comment_heart_'+id).set('html', indicator_heart); $('rate_comment_'+id).set('html', after_rate_comment); var url=host+"modules/inc.after.ratecomment.php?id="+id; }
function delete_comment(id) {var pars="comment_id="+id+"&action=deleteComment";var url=host+"modules/ajax.action.php";var layer="comment_"+id; $(layer).destroy();var layer="";var clear=false;AjaxRequest(layer, url, pars, clear);}
function exitRegistration() { var pars="action=exit"; var url=host+"modules/ajax.registration.php"; layer="enterDIV"; var clear=true; markAsWaitingSmall(layer); AjaxRequest(layer, url, pars, clear); setTimeout('window.location="'+thispage+'"', 500); }
function showCalendar(newdata) { var url = host+"modules/ajax.calendar.php"; var pars = "date="+newdata; var layer="newsCalendar"; var clear=true; AjaxRequest(layer, url, pars, clear); }
function GetPos(elem) { var offTrial=document.getElementById(elem); var offL=0; var offT=0; while(offTrial){ offL+=offTrial.offsetLeft; offT+=offTrial.offsetTop; offTrial=offTrial.offsetParent; }	if (navigator.userAgent.indexOf("Mac")!=-1 && typeof document.body.leftMargin!="undefined") { offL+=document.body.leftMargin; offT+=document.body.topMargin; } return {x:offL , y:offT}  }

	function get_comments(parent, id, page) {
  		var layer="comments_"+page;
  		url=host+"modules/ajax.action.php";
  		var pars="action=loadComments&parent="+parent+"&id="+id+"&page="+page;
  		var clear=true;
  		markAsWaiting(layer);
  		AjaxRequest(layer, url, pars, clear);
	}


function getBrowserInfo() { var t,v = undefined; if (window.chrome) t = 'Chrome'; else if (window.opera) t = 'Opera'; else if (document.all) { t = 'IE'; var nv = navigator.appVersion; var s = nv.indexOf('MSIE')+5; v = nv.substring(s,s+1); } else if (navigator.appName) t = 'Netscape'; return {type:t,version:v}; }

function bookmark(a){
    var url = window.document.location;
    var title = window.document.title;
    var b = getBrowserInfo();

    if (b.type == 'IE' && 8 >= b.version && b.version >= 4) window.external.AddFavorite(url,title);
    else if (b.type == 'Opera') {
        a.href = url;
        a.rel = "sidebar";
        a.title = url+','+title;
        return true;
    }
    else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
    else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
    return false;
}


