﻿var Comment1=null, Comment2=null, AnswerCom=null, IsLoadedComments=false;
function CallBackEditor(EditorId, Editor){
    if (EditorId=="CommentText1"){Comment1=Editor;}
    if (EditorId=="CommentText2"){Comment2=Editor;}
    if (EditorId=="AnswerComment"){
        AnswerCom=Editor;
        if (IsLoadedComments){
            AnswerCom.focus();
        }else{
            IsLoadedComments=true;
        }
    }
}
function GetCommentText1(){ try { gebi("CommentText1").value = ReplaceAll(ReplaceAll(Comment1.GetContent(),"<","[-%3C-]"),">","[-%3E-]"); }catch(ex){} ClearEditors(); }
function GetCommentText2(Focus){ try { gebi("CommentText2").value = ReplaceAll(ReplaceAll(Comment2.GetContent(),"<","[-%3C-]"),">","[-%3E-]"); }catch(ex){} if(Focus){gebi("Comment2OutFocusBox").focus();} ClearEditors(); }
function GetAnswerCommetText(){ try { gebi("AnswerComment").value = ReplaceAll(ReplaceAll(AnswerCom.GetContent(),"<","[-%3C-]"),">","[-%3E-]"); }catch(ex){} gebi("AnswerOutFocusBox").focus(); ClearEditors(); }
function GetTextBoxContent(TextBoxId){ return gebi(TextBoxId).value; }
function LoadCommentText(Comment2Focus){
    HideSmiles();
    try { if (gebi("CommentText2")!=null){ GetCommentText2(Comment2Focus); } }catch(ex){}
}

function CheckRightCommentAndPoints(CheckBoxIs){
    try{
        if (Comment2.GetContent().length==0){
            alert('Напишите Ваш комментарий!');
            return false;
        }
        return CheckRightPoints(CheckBoxIs);
    }catch(ex) {return true;}
}

function WriteImageInComment(ImageUrl, ImageAlt, ImageTitle, ImageWidth, ImageHeight){
    if (gebi("AnswerCommentIdText").value == ""){
        if (gebi("CommentText1")){
            Comment1.InsertImage(ImageUrl, ImageAlt, ImageTitle, ImageWidth, ImageHeight);
            gebi("AddCommentButton").focus();
        }else{
            Comment2.InsertImage(ImageUrl, ImageAlt, ImageTitle, ImageWidth, ImageHeight);
            gebi("AddCommentButton1").focus();
        }
    }else{
        AnswerCom.InsertImage(ImageUrl, ImageAlt, ImageTitle, ImageWidth, ImageHeight);
        gebi("AddAnswerComment").focus();
    }
    return false;
}

var TimerShowDiv=null, NowResizeHeight=0, NowDivPrefix="";
function SetPhotoVariantId(PhotoId){
    HidePhotoUploadDiv(NowDivPrefix);
    if (NowDivPrefix==""){
        Comment2.InsertImage("siteimg/photovariant.png", "[pv:" + PhotoId + "]", "вариант фото", 96, 18);
    }else{
        AnswerCom.InsertImage("siteimg/photovariant.png", "[pv:" + PhotoId + "]", "вариант фото", 96, 18);
    }
    return false;
}
function ShowPhotoUploadDiv(DivPrefix){
    HideSmiles();
    if (DivPrefix=="1") { HidePhotoUploadDiv(""); }else{ HidePhotoUploadDiv("1"); }
    NowDivPrefix=DivPrefix;
    if (gebi("UploadPhotoVariantDiv"+DivPrefix).style.display=="none"){
        gebi("UploadPhotoVariantDiv"+DivPrefix).style.display="block";
        gebi("UploadPhotoVariantDiv"+DivPrefix).innerHTML="<iframe src='uploadphotovariant.aspx' name='UploadPhotoVariant' width='650px' height='70px' hspace='0' vspace='0' scrolling='no' frameborder='0' allowTransparency='true'></iframe>";
        gebi("UploadPhotoVariantDiv"+DivPrefix).style.height="1px";
        NowResizeHeight=0;
        TimerShowDiv=window.setInterval("SetDivResize('UploadPhotoVariantDiv"+DivPrefix+"', '70')", "20");
    }else{
        HidePhotoUploadDiv(DivPrefix);
    }
    return false;
}
function HidePhotoUploadDiv(DivPrefix){
    HideSmiles();
    if (DivPrefix=="-1") {DivPrefix=NowDivPrefix;}
    gebi("UploadPhotoVariantDiv"+DivPrefix).style.display="none";
    gebi("UploadPhotoVariantDiv"+DivPrefix).innerHTML="";
    gebi("UploadPhotoVariantDiv"+DivPrefix).style.height="1px";
    if (DivPrefix=="1") { gebi("AnswerSmilesTable").style.height="112px"; }
    return false;
}
function SetDivResize(DivId, MaxHeight){
    if (NowResizeHeight>=MaxHeight){
        gebi(DivId).style.height=MaxHeight+"px";
        if (DivId=="UploadPhotoVariantDiv1"){
            gebi("AnswerSmilesTable").style.height=(parseInt(MaxHeight)+112)+"px";
        }
        if (TimerShowDiv!=null){window.clearInterval(TimerShowDiv);}
        TimerShowDiv=null;
    }else{
        NowResizeHeight+=5;
        gebi(DivId).style.height=NowResizeHeight+"px";
        if (DivId=="UploadPhotoVariantDiv1"){
            gebi("AnswerSmilesTable").style.height=(parseInt(NowResizeHeight)+112)+"px";
        }
    }
}

function InsertSmile(SmileId){
    try{
        if (gebi("SmilesTextBoxId").value=="CommentText1"){ Comment1.InsertImage("siteimg/smiles/"+SmileId+"_white.gif", "[smile:"+SmileId+"]", "", 15, 15); }
        if (gebi("SmilesTextBoxId").value=="CommentText2"){ Comment2.InsertImage("siteimg/smiles/"+SmileId+"_white.gif", "[smile:"+SmileId+"]", "", 15, 15); }
        if (gebi("SmilesTextBoxId").value=="AnswerComment"){ AnswerCom.InsertImage("siteimg/smiles/"+SmileId+"_white.gif", "[smile:"+SmileId+"]", "", 15, 15); }
    }catch(ex){}
    return false;
}

function CtrlEnterClick(EditorDivId){
    if (EditorDivId=="AnswerComment") { if (validate_comment()) gebi("AddAnswerComment").click(); }
    if (EditorDivId=="CommentText2") { if (CheckRightCommentAndPoints('true')) gebi("AddCommentButton1").click(); }
    if (EditorDivId=="CommentText1") { gebi("AddCommentButton").click(); }
}

function RemovieComm(CommentId, e){
    try{
        if (gebi(s_id).style.display == "block"){ hide_add_comment_form(); }
    }catch(ex){}
    HideSmiles();
    LoadCommentText(false);
    gebi("CommentIdText").value=CommentId;
    AjaxNS.AR('RemovieComment','', 'CommentsAjaxPanel', e);
}