/* document.write('<DIV id="makelink">
                <FORM name="mklnk" onSubmit="return false;">
                Link: <INPUT class="din" type="text" name="link"><BR>
                Url: <INPUT class="din" type="text" name="url" value="http://"><BR>
                <INPUT type="submit" value="Cancel" onClick="hideDialog(this.form.link,this.form.url,\'makelink\');">
                <INPUT type="submit" value="Add Link" onclick="doit(this.form.link,this.form.url,\'makelink\')">
                </DIV>');
*/

function notice(){
   alert("None of these links work! But I need suggestions.");
   return false;
}

function buildLink(link,url){
   insert = '<A href="'+url+'" target="new">'+link+'</A>';
   return insert;
}

function addTags(txtObj,tag){
   txtObj.value += tag;
}

function doit(link,url,theid){
   //alert(buildLink(link.value,url.value));
   var blogObj = document.getElementById('blogarea');
   //alert(blogObj.value);
   addTags(blogObj,buildLink(link.value,url.value));
   var dialogObj = document.getElementById(theid);
   dialogObj.style.visibility = "hidden";
   link.value="";
   url.value="http://";
}

function createDialog(pObj,dialog){
//function createDialog(pObj){
   x = getposOffset(pObj,"left");
   y = getposOffset(pObj,"top") + pObj.offsetHeight;
   var dialogObj = document.getElementById(dialog);
   dialogObj.style.left = x + "px";
   dialogObj.style.top = y + "px";
   dialogObj.style.visibility = "visible";
//   alert(x+" , "+y);
}

function hideDialog(link,url,theid){
   link.value="";
   url.value="http://";
   var dialogObj = document.getElementById(theid);
   dialogObj.style.visibility = "hidden";
}

function getposOffset(thisEl, offsettype){

   var totaloffset=(offsettype=="left") ? thisEl.offsetLeft : thisEl.offsetTop;
   var parentEl=thisEl.offsetParent;

   while (parentEl!=null){
      totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
      parentEl = parentEl.offsetParent;
   }
   return totaloffset;
}

function addFileInput(objId){
   
   var label = "image";

   var fiDiv = document.getElementById(objId);
   var imgIndex = (fiDiv.childNodes.length/2)+1;

   var newP = document.createElement('p');
   newP.setAttribute('class','fu');

   var newFUp = document.createElement('input');
   newFUp.setAttribute('type','file');
   newFUp.setAttribute('name',label+imgIndex);

   fiDiv.appendChild(newP);
   fiDiv.appendChild(newFUp);

   return false;
}
