function bbimg(o){
	if(event.ctrlKey) {
var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+'%';
return false;
}else
  return true;
}
function invitewin(theurl,thetitle)
{
    window.open("/invite?vurl="+theurl+"&vtitle="+thetitle,"推荐给朋友","height=400,width=550,status=yes,toolbar=no,menubar=no,location=no,scrollbars=1")
}
function col12cmd(sn,up,down)
{
    id1="COL12_h_"+sn+"_"+down;
    id2="COL12_"+sn+"_"+down;
    document.getElementById(id1).className="col12normal";
    document.getElementById(id2).style.display="none";
    id1="COL12_h_"+sn+"_"+up;
    id2="COL12_"+sn+"_"+up;
    document.getElementById(id1).className="col12select";
    document.getElementById(id2).style.display="";
}
function openclosediv(id,flag)
{
     var d = document.getElementById(id);
     if (d.style.display=="none")
     {
         d.style.display="";
         flag.src="/image/mi.gif";
         flag.alt="收缩";
     }
     else
     {
         d.style.display="none";
         flag.src="/image/pl.gif";
         flag.alt="展开";
     }
}
function menudisplay(id)
{
     var d = document.getElementById(id);
     d.style.display = "";
}
function menuclose(id)
{
     var d=document.getElementById(id);
     d.style.display="none";
}
function addTag(win,tag)
{
       if (win.document.form.taginput.value=="")
           win.document.form.taginput.value=tag;
       else
          win.document.form.taginput.value=win.document.form.taginput.value+' '+tag;
}

function clickDoc(username,title)
{
       document.docform.uid.value=username;
       document.docform.title.value=title;
       return;
}
function insertDoc()
{
       if (document.docform.uid.value=="" || document.docform.title.value=="")
           return

       tagOpen='[['+document.docform.uid.value+'/'+document.docform.title.value

       window.opener.insertTag(tagOpen,'|',document.docform.txt.value,']]');
       window.close()
}
function insertQuote()
{
    txtarea=window.document.quoteform.src;
    text=txtarea.value;

    if(window.document.selection)
    {
         txtarea.focus();
         var theSelection = window.document.selection.createRange().text;
         if(theSelection)
         { 
             text=theSelection
         }
    }
    else if(txtarea.selectionStart || txtarea.selectionStart == '0')
    {
         var startPos = txtarea.selectionStart;
         var endPos = txtarea.selectionEnd;
         var scrollTop=txtarea.scrollTop;
         var myText = (txtarea.value).substring(startPos, endPos);
         if(myText)
            text=myText; 
    }

    tagOpen='[[quote:'+window.document.quoteform.uid.value+'/'+window.document.quoteform.title.value+']]';

    window.opener.insertTag(tagOpen,'',text,'[[/quote]]');
    window.close()
}
function selectPhoto(id)
{
       window.opener.document.form.photo.value=id;
       window.opener.document.userphoto.src='/thumb?id='+id;
       window.close();
}
function selectSysPhoto(id)
{
       window.document.form.photo.value=id;
       window.document.userphoto.src='/headimages'+id;
}
function clickImage(username,title,file_id)
{
       document.picform.uid.value=username;
       document.picform.title.value=title;
       document.selectimage.src='/thumb?id='+file_id;
       return;
}
function insertImage()
{
       if (document.picform.uid.value=="" || document.picform.title.value=="")
           return

       tagOpen='[[image:'+document.picform.uid.value+'/'+document.picform.title.value
       if (document.picform.thumb.checked)
           tagOpen=tagOpen+'|thumb';

       if (document.picform.align[0].checked)
              tagOpen=tagOpen+'|'+document.picform.align[0].value;
       if (document.picform.align[1].checked)
              tagOpen=tagOpen+'|'+document.picform.align[1].value;

       if (document.picform.link.checked)
              tagOpen=tagOpen+'|link';

       window.opener.insertTag(tagOpen,'|',document.picform.txt.value,']]');
//       window.close()
}
function clickMultimedia(username,title,file_id,filetype)
{
       document.form_multimedia.uid.value=username;
       document.form_multimedia.title.value=title;
       if (filetype=="image/jpeg" || filetype=="image/pjpeg" || filetype=="image/gif" ||filetype=="image/jpg")
       {
           document.form_multimedia.media[0].checked=true;
           document.selectmultimedia.src='/thumb?id='+file_id;
       }
       else
       {
           if (filetype=="audio/mpeg")
               document.form_multimedia.media[1].checked=true;
           else if (filetype=="video/mpeg")
               document.form_multimedia.media[2].checked=true;
           else if (filetype=="application/x-shockwave-flash")
               document.form_multimedia.media[3].checked=true;
           else
               document.form_multimedia.media[4].checked=true;

           document.selectmultimedia.src='/image/media.gif';
       }
       return;
}

var currfieldname='';

function insertTag(tagOpen,sp,text,tagClose)
{
    txtarea=window.document.form[currfieldname];
    if(window.document.selection)
    {
         txtarea.focus();
         var theSelection = window.document.selection.createRange().text;
         if(!theSelection)
         { 
             theSelection=text;
         }
         if (theSelection=="")
             sp="";

         window.document.selection.createRange().text = tagOpen + sp+theSelection + tagClose; 
    }
    else if(txtarea.selectionStart || txtarea.selectionStart == '0')
    {
         var startPos = txtarea.selectionStart;
         var endPos = txtarea.selectionEnd;
         var scrollTop=txtarea.scrollTop;
         var myText = (txtarea.value).substring(startPos, endPos);
         if(!myText)
            { myText=text;} 

         if (myText=="")
             sp="";

         subst = tagOpen + sp+myText + tagClose;

         txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos,txtarea.value.length);
         txtarea.focus();
         var cPos=startPos+(tagOpen.length+myText.length+tagClose.length); 
         txtarea.selectionStart=cPos;
         txtarea.selectionEnd=cPos; 
         txtarea.scrollTop=scrollTop;
    }
}
var theElementID=""
function handleHttpResponse() {
  if (httpObject.readyState == 4) {
    // Split the comma delimited response into an array
    result = httpObject.responseText;
    document.getElementById(theElementID).innerHTML=result;
  }
}
function updateElement(id,url) {
  theElementID=id
  httpObject.open("GET", url,true);
  httpObject.onreadystatechange = handleHttpResponse;
  httpObject.send(null);
 }
function getHTTPObject() {
  var req;
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
  return req;
}
var httpObject = getHTTPObject(); // We create the HTTP Object



function writeStandardHeader(win,win_title)
{
    win.document.writeln("<html>");
    win.document.writeln("<head>");
    win.document.writeln('<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"> ');
    win.document.writeln("");
    win.document.writeln("<title>"+win_title+"</title>");
    win.document.writeln("</head>");
    win.document.writeln("<body>");

}
function writeStandardFooter(win)
{

    win.document.writeln("<p><hr></p>");
    win.document.writeln("<div align=center>注意哦：遵纪守法，言行自律；互助关爱，家园美丽。</div>");
    win.document.writeln("<div align=right>——博博客旅行生活网</div>");
    win.document.writeln("</body>");
    win.document.writeln("</html>");
    win.document.close();

//    win.focus();
}
function insertString(win,left_bracket,right_bracket)
{
       insertTag(left_bracket,'',win.document.form_str.txt.value,right_bracket);
       win.close()
}
function insertExtquote(win)
{
       insertTag('[quote:'+win.document.form_quote.url.value,' ',win.document.form_quote.txt.value,']');
       insertTag('','',win.document.form_quote.src.value,'[/quote]');
       win.close()
}
function insertExtlink(win)
{
       insertTag('['+win.document.form.url.value,' ',win.document.form.txt.value,']');
       win.close()
}
function openStringWindow(string_name,fieldname,left_bracket,right_bracket)
{
    currfieldname=fieldname;
    win=window.open("","toolbarpop","height=200,width=500,status=yes,toolbar=no,menubar=no,location=no");
    writeStandardHeader(win,"插入"+string_name);

    win.document.writeln("<form name='form_str'>");
    win.document.writeln("<table width=100%>");
    win.document.writeln("<caption align=top>插入"+string_name+"</caption>");
    win.document.writeln("<tr><td nowrap>"+string_name+"</td><td><input type='text' name='txt' size=50></td></tr>");
    win.document.writeln("</table>");

    win.document.writeln("<table width=70%>");
    win.document.writeln("<tr align=center>");
    win.document.writeln("<td width=30%>");
    win.document.write("<td><input type='button' name='cmd' value=' 确定 ' onclick='window.opener.insertString(window,")
      win.document.write('"'+left_bracket+'","'+right_bracket+'"');
      win.document.writeln(")'></td>");
    win.document.writeln("<td><input type='button' value=' 取消 ' onclick='window.close()'></td>");
    win.document.writeln("</tr>");
    win.document.writeln("</table>");
    win.document.writeln("</form>");

    writeStandardFooter(win);
    win.document.form_str.txt.focus();
}

function insert_string(fieldname,left_bracket,string_name,right_bracket)
{
   currfieldname=fieldname;
    txtarea=window.document.form[fieldname];
   if(window.document.selection)
    {
         txtarea.focus();
         var theSelection = window.document.selection.createRange().text;
         if(!theSelection)
             openStringWindow(string_name,fieldname,left_bracket,right_bracket);
         else
             insertTag(left_bracket,'','',right_bracket);
    }
    else if(txtarea.selectionStart || txtarea.selectionStart == '0')
    {
         var startPos = txtarea.selectionStart;
         var endPos = txtarea.selectionEnd;
         var myText = (txtarea.value).substring(startPos, endPos);
         if(!myText)
             openStringWindow(string_name,fieldname,left_bracket,right_bracket);
         else
             insertTag(left_bracket,'','',right_bracket);
    }
}
function openextquote(fieldname)
{
    currfieldname=fieldname;
    win=window.open("","toolbarpop","height=600,width=550,status=yes,toolbar=no,menubar=no,location=no,scrollbars=1");
    writeStandardHeader(win,"引用外部文章");

    win.document.writeln("<form name='form_quote'>");
    win.document.writeln("<table width=100%>");
    win.document.writeln("<caption align=top>引用外部文章</caption>");
    win.document.writeln("<tr><td nowrap>地址(URL)</td><td><input type='text' name='url' size=50></td></tr>");
    win.document.writeln("<tr><td nowrap>引用的标题</td><td><input type='text' name='txt' size=50></td></tr>");
    win.document.writeln("<tr><td nowrap valign=top>引用的正文</td><td><textarea rows=22 cols=50 name='src'></textarea></td></tr>");
    win.document.writeln("</table>");

    win.document.writeln("<table width=70%>");
    win.document.writeln("<tr align=center>");
    win.document.writeln("<td width=50%>");
    win.document.writeln("<td><input type='button' name='cmd' value=' 确定 ' onclick='window.opener.insertExtquote(window)'></td>");
    win.document.writeln("<td><input type='button' value=' 取消 ' onclick='window.close()'></td>");
    win.document.writeln("</tr>");
    win.document.writeln("</table>");
    win.document.writeln("</form>");

    writeStandardFooter(win);
    win.document.form_quote.url.focus();
}

function openextlink(fieldname)
{
    currfieldname=fieldname;
    win=window.open("","toolbarpop","height=230,width=500,status=yes,toolbar=no,menubar=no,location=no");
    writeStandardHeader(win,"插入外部链接");

    win.document.writeln("<form name='form'>");
    win.document.writeln("<table width=100%>");
    win.document.writeln("<caption align=top>插入外部链接</caption>");
    win.document.writeln("<tr><td nowrap>链接地址(URL)</td><td><input type='text' name='url' size=50></td></tr>");
    win.document.writeln("<tr><td nowrap>链接标题</td><td><input type='text' name='txt' size=50></td></tr>");
    win.document.writeln("</table>");

    win.document.writeln("<table width=70%>");
    win.document.writeln("<tr align=center>");
    win.document.writeln("<td width=30%>");
    win.document.writeln("<td><input type='button' name='cmd' value=' 确定 ' onclick='window.opener.insertExtlink(window)'></td>");
    win.document.writeln("<td><input type='button' value=' 取消 ' onclick='window.close()'></td>");
    win.document.writeln("</tr>");
    win.document.writeln("</table>");
    win.document.writeln("</form>");

    writeStandardFooter(win);
    win.document.form.url.focus();
}
function openworkarea(fieldname)
{
    currfieldname=fieldname;
    win=window.open("/blog/u/toolbar/picarea","toolbarpop","height=550,width=720,status=yes,toolbar=no,menubar=no,location=no,scrollbars=1");
    win.focus();
}
function openinsertdoc(fieldname)
{
    currfieldname=fieldname;
    win=window.open("/blog/u/toolbar/insertdoc","toolbarpop","height=600,width=500,status=yes,toolbar=no,menubar=no,location=no,scrollbars=1");
    win.focus();
}
function openinsertquote(fieldname)
{
    currfieldname=fieldname;
    win=window.open("/blog/u/toolbar/insertquote","toolbarpop","height=600,width=500,status=yes,toolbar=no,menubar=no,location=no,scrollbars=1");
    win.focus();
}
function openinsertimage(fileid)
{
    win=window.open("/blog/u/toolbar/insertimage?file_id="+fileid,"insertimage","height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,scrollbars=1");
    win.focus();
}
function insertTagToField(fieldname,tagOpen,sp,text,tagClose)
{
    thecurr=currfieldname;
    currfieldname=fieldname;
    insertTag(tagOpen,sp,text,tagClose)
    currfieldname=thecurr;
}

