function cpg_insert_image(pid){var ta=document.getElementById("content");var st=document.getElementById("cpg-image-insert-select-type").value;var al=document.getElementById("cpg-image-insert-select-style").value;var shadow=document.getElementById("cpg-image-insert-select-shadow").value;var link=document.getElementById("cpg-image-insert-select-linktype").value;var title=document.getElementById("cpg-image-insert-title").value;var width=document.getElementById("cpg-image-insert-select-width").value;var height=document.getElementById("cpg-image-insert-select-height").value;var opts=pid+':'+al;if(shadow!='')
opts+=':s='+shadow;if(link)
opts+=':l='+link;if(title)
opts+=':'+title;if(width)
opts+=':w='+width;if(height)
opts+=':h='+height;if(st=="thumbnail"){cpg_edInsertContent(ta,"[thumb:"+opts+"]");}
else{if(st=="banner"){cpg_edInsertContent(ta,"[banner:"+opts+"]");}
else{cpg_edInsertContent(ta,"[image:"+opts+"]");}}}
function get_group_opts()
{var ta=document.getElementById("content");var st=document.getElementById("cpg-image-insert-gs").value;var shadow=document.getElementById("cpg-image-insert-gsd").value;var opts='';if(st!='')
opts+=':'+st;if(shadow!='')
opts+=':s='+shadow;return opts;}
function cpg_insert_album(){var aid=document.getElementById("cpg-image-insert-select-album").value;if(aid=='')
return;var ta=document.getElementById("content");var num=document.getElementById("cpg-image-insert-select-album-number").value;var opts=get_group_opts();cpg_edInsertContent(ta,"[album:"+aid+","+num+opts+"]");}
function cpg_insert_grouptag(){var ta=document.getElementById("content");var opts=get_group_opts();cpg_edInsertContent2(ta,"[group"+opts+"]","[/group]");}
function cpg_insert_nl(){var ta=document.getElementById("content");cpg_edInsertContent(ta,"[newline]\n");}
function cpg_move_right(){for(i=cpg_inserter_num-1;i>0;i--){var or=document.getElementById('insert-image-'+i);var ol=document.getElementById('insert-image-'+(i-1));or.innerHTML=ol.innerHTML;}
ol.innerHTML='';}
function cpg_add_image(pid,thumb,title){var i;var ta=document.getElementById("content");for(i=cpg_inserter_num-1;i>=0;i--){var o=document.getElementById('insert-image-'+i);if(!(o.childNodes==null||o.childNodes.length>0))
break;}
if(i<0){cpg_move_right();i=0;}
li=document.getElementById('insert-image-'+i);li.innerHTML='<img src="'+thumb+'" alt="'+title+'" onclick="cpg_insert_image(\''+pid+'\')" />';}
function cpg_edInsertContent(myField,myValue){if(typeof(tinyMCE)=='undefined'){if(document.selection){myField.focus();sel=document.selection.createRange();sel.text=myValue;myField.focus();}
else if(myField.selectionStart||myField.selectionStart=='0'){var startPos=myField.selectionStart;var endPos=myField.selectionEnd;myField.value=myField.value.substring(0,startPos)
+ myValue
+ myField.value.substring(endPos,myField.value.length);myField.focus();myField.selectionStart=startPos+ myValue.length;myField.selectionEnd=startPos+ myValue.length;}else{myField.value+=myValue;myField.focus();}}
else{tinyMCE.activeEditor.selection.setContent(myValue);tinyMCE.execInstanceCommand('mce_editor_0','mceInsertContent',false,myValue);}}
function cpg_edInsertContent2(myField,myValue1,myValue2){if(typeof(tinyMCE)=='undefined'){if(document.selection){myField.focus();sel=document.selection.createRange();sel.text=myValue1+ sel.text+ myValue2;myField.focus();}
else if(myField.selectionStart||myField.selectionStart=='0'){var startPos=myField.selectionStart;var endPos=myField.selectionEnd;var val=myValue1+ myField.value.substring(startPos,endPos)+ myValue2;myField.value=myField.value.substring(0,startPos)
+ val
+ myField.value.substring(endPos,myField.value.length);myField.focus();myField.selectionStart=startPos+ myValue.length;myField.selectionEnd=startPos+ myValue.length;}else{myField.value+=myValue1+ myValue2;myField.focus();}}else{sel='';val=myValue1+ sel+ myValue2;tinyMCE.activeEditor.selection.setContent(val);tinyMCE.execInstanceCommand('mce_editor_0','mceInsertContent',false,val);}}
function cpg_togglediv_but(button,divid)
{var mydiv=document.getElementById(divid);if(mydiv.style.display=='none'){mydiv.style.display='block';if(button.className=='cpg-expand'){button.className='cpg-collapse';}}
else{mydiv.style.display='none';if(button.className=='cpg-collapse'){button.className='cpg-expand';}}}
function cpg_showdiv_but(button,divid)
{cpg_togglediv_but(button,divid);button.style.display="none";}
function cpg_hidediv_but(button,divid,bshowid)
{cpg_togglediv_but(button,divid);button2=document.getElementById(bshowid);button2.style.display="block";}
