
function changepic( formName, textAreaName, idname, type )
{
    fixbase = "";
    if ((document.title == 'SubTopics Menu') ||
        (document.title == 'Popups Editing'))    {
        fixbase = "../";
    }
    pagelink = fixbase + "dyno/mediapopup.html?MediaType=" + type
        + "&type=" + idname 
        + "&form=" + formName 
        + "&textarea=" + textAreaName;
    winstatus=window.open(pagelink,'',"scrollbars,resizable,width=500,height=300");

}

function clearpic() 
{
    document.inputform.MainPicture.value = "";
    document.inputform.ThePicture.value = "";
}

function makegenerallink() {

    // ask for a link address
    linkaddress = prompt("Enter the address of the page you want to link.","http://");
    if ( linkaddress === null ) {
        return;
    }
    // ask for a link page name
    linkpagename = prompt("Enter the name of the page you are linking.\n "+
               "Example: if you are linking to http://www.google.com/ "+
               "you might use the name 'Search Engine'", "");
    // or just use LINK DESCRIPTION if they dont specify
    if ( linkpagename === null ) {
        linkpagename = 'LINK DESCRIPTION';
    }

    // ask what color, green or orange
    linkcolor = prompt("What color should the link be?\n"+
		       "(valid colors are 'green' or 'orange')","orange");

    thelinktoinsert = '<a href="'
                    + linkaddress + '"'
                    + ' class="' + linkcolor + '"'
                    + '>' 
		    + linkpagename
                    + '</a>';

    window.document.maineditform.sometext.value =
         window.document.maineditform.sometext.value + " " + thelinktoinsert;

}

function mediapopup( thelink ) {
    winstatus=window.open(thelink,"","resizable,width=150,height=150");
}


//
//  Safe way to get the object.  
//  Most browsers will usually work with the first one
//
function getElement( id ) {
    if (document.getElementById) {
        return (document.getElementById(id));
    } else if (document.all) {
        return (document.all[id]);
    } else {
        alert (" Unable to add text: Message-001 ");
    }
}

//
// add the given textToAdd to the textarea specified by "id"
//
function perform_update()
{
    document.subtopicform.little_update.value = 'Y';
    document.subtopicform.submit();
}

//
// add the given textToAdd to the textarea specified by "id"
//
function dynoInsert(id, textToAdd )
{
    // get the current textarea
    theTextArea = getElement( id );

    tagStart = "";
    tagEnd = "";
    fontSelect = getElement( "messageFont" );
    fontClass = fontSelect.value;
    if (fontClass == "quickbold") {
        tagStart = '<b>';
        tagEnd = '</b>';
    } else if (fontClass == "quickunderline") {
        tagStart = '<u>';
        tagEnd = '</u>';
    } else if (fontClass == "quickitalic") {
        tagStart = '<i>';
        tagEnd = '</i>';
    } else if (fontClass == "superscript") {
        tagStart = '<sup>';
        tagEnd = '</sup>';
    } else if (fontClass == "verysmall") {
        tagStart = '<font size="-3">';
        tagEnd = '</font>';
    } else if ( (fontClass != "") && (fontClass != "plain") ) {
        tagEnd = '</span>';
        tagStart = '<span class="' + fontClass + '">';
    }

    theTextArea.value = theTextArea.value + ' ' 
                           + tagStart + textToAdd + tagEnd;
}


//
//  dynamic way to add "special" text to a textarea
//  (the textarea is specified by "id")
//
function dynoText( id, boxId ) {
    // Get the text from the little text box
    textToAdd = getElement( boxId );
    // check if empty
    if ( textToAdd.value == "" )
    {
	errorMessage = "You must specify what text to add";
	alert(errorMessage);
	textToAdd.focus();
    }
    else
    {
        //alert( "you would add [" + textToAdd.value + "] to textarea " + id );
        dynoInsert( id, textToAdd.value );
    }
}

//
// if we want to delete a topic 
//
function delete_topic( topicnumber, topicname ) {
    if ( confirm( "Are you sure you want to delete:\n    " + 
	topicname + " (topic #" + topicnumber + ") ?" )   ) {
        document.topicform.topictodelete.value = topicnumber;
        document.topicform.submit();
    } else {
        alert (" Topic was not deleted ");
    }
}

//
// if we want to delete something
//
function delete_something( theForm, itemnumber, itemname, description ) {
    if ( confirm( "Are you sure you want to delete:\n    " + 
	itemname + " ("+description+" #" + itemnumber + ") ?" )   ) {
        textField = eval("document." + theForm + ".itemtodelete");
        textField.value = itemnumber;
        formObject = eval("document." + theForm);
        formObject.submit();
    } else {
        alert ( " " + description + " was not deleted ");
    }
}


function popupstarter( tipnumber )
{
    thelink = "./conversationstarter.html?tip=" + tipnumber;
    winstatus=window.open(thelink,"","scrollbars,resizable,width=448,height=300");
}

function popuptip( tipnumber, topic )
{
    thelink = "../tips.html?tip=" + tipnumber + "&topic=" + topic;
    winstatus=window.open(thelink,"","scrollbars,resizable,width=448,height=300");
}

function popupvideo( videofile )
{
    thelink = "/issues/video.html?vid=" + videofile;
    winstatus=window.open(thelink,"","resizable,width=350,height=300");
}

function popuptranscript( transcriptfile )
{
    thelink = "/issues/transcript.html?transcript=" + transcriptfile;
    winstatus=window.open(thelink,"","scrollbars,resizable,width=350,height=300");
}

//
// if we want to delete a tip 
//
function delete_tip( tipnumber, tipname ) {
    if ( confirm( "Are you sure you want to delete:\n    " + 
	tipname + " (tip #" + tipnumber + ") ?" )   ) {
        document.tipform.tiptodelete.value = tipnumber;
        document.tipform.submit();
    } else {
        alert (" Tip was not deleted ");
    }
}

//
// if we want to delete an additional content 
//
function delete_content( contentnumber, contentname ) {
    //alert ( contentnumber );
    //alert ( contentname  );
    if ( confirm( "Are you sure you want to delete:\n    " + 
	contentname + " (content #" + contentnumber + ") ?" )   ) {
        document.addcontentform.contenttodelete.value = contentnumber;
        document.addcontentform.submit();
    } else {
        alert (" Additional content was not deleted ");
    }
}

//
// if we want to delete a news item
//
function delete_news( newsnumber, newsname ) {
    //alert ( newsnumber );
    //alert ( newsname  );
    if ( confirm( "Are you sure you want to delete:\n    " + 
	newsname + " (news #" + newsnumber + ") ?" )   ) {
        document.newseditform.newstodelete.value = newsnumber;
        document.newseditform.submit();
    } else {
        alert (" Additional news was not deleted ");
    }
}



//
// if we want to delete a multimedia item
//
function delete_media( medianumber, mediadescription ) {
    //alert ( medianumber );
    //alert ( mediadescription  );
    if ( confirm( "Are you sure you want to delete:\n    " + 
	mediadescription + " (media #" + medianumber + ") ?" )   ) {
        document.mediaform.mediatodelete.value = medianumber;
        document.mediaform.submit();
    } else {
        alert (" Specified Multimeda was not deleted ");
    }
}

//
// 
//
function order_changed()
{
    document.topicform.order_update.value = 'true';
}

function setClass(whattext,whatstyle)
{
    var littletextstyle = getElement( whattext ).style;
    if (('bodybold'==whatstyle)||('quickbold'==whatstyle)) {
        littletextstyle.fontWeight = 'bold';
        littletextstyle.fontStyle = 'normal';
        littletextstyle.fontSize = '12';
    } else if ('bodybolditalic'==whatstyle) {
        littletextstyle.fontWeight = 'bold';
        littletextstyle.fontStyle = 'italic';
        littletextstyle.fontSize = '12';
    } else if (('bodyitalic'==whatstyle)||('quickitalic'==whatstyle)) {
        littletextstyle.fontWeight = 'normal';
        littletextstyle.fontStyle = 'italic';
        littletextstyle.fontSize = '12';
    } else if ('quickunderline'==whatstyle) {
        littletextstyle.fontWeight = 'normal';
        littletextstyle.fontStyle = 'normal';
        littletextstyle.fontSize = '12';
        littletextstyle.textDecoration = 'underline';
    } else if ('headline'==whatstyle) {
        littletextstyle.fontWeight = 'normal';
        littletextstyle.fontStyle = 'normal';
        littletextstyle.fontSize = '14';
    } else if ('headlinebold'==whatstyle) {
        littletextstyle.fontWeight = 'bold';
        littletextstyle.fontStyle = 'normal';
        littletextstyle.fontSize = '14';
    } else if ('plain'==whatstyle) {
        littletextstyle.fontWeight = 'normal';
        littletextstyle.fontStyle = 'normal';
        littletextstyle.fontSize = '12';
    } else if ('superscript'==whatstyle) {
        littletextstyle.fontWeight = 'normal';
        littletextstyle.fontStyle = 'normal';
        littletextstyle.fontSize = '10';
    } else if ('verysmall'==whatstyle) {
        littletextstyle.fontWeight = 'normal';
        littletextstyle.fontStyle = 'normal';
        littletextstyle.fontSize = '9';
    } else {
        var sampleText = getElement(whattext);
        sampleText.className = whatstyle;
    }
}

//
// add the given textToAdd to the textarea specified by "id"
//
function dynoInsert(id, textToAdd )
{
    // get the current textarea
    theTextArea = getElement( id );

    tagStart = "";
    tagEnd = "";
    fontSelect = getElement( "messageFont" );
    fontClass = fontSelect.value;
    if (fontClass == "quickbold") {
        tagStart = '<b>';
        tagEnd = '</b>';
    } else if (fontClass == "quickunderline") {
        tagStart = '<u>';
        tagEnd = '</u>';
    } else if (fontClass == "quickitalic") {
        tagStart = '<i>';
        tagEnd = '</i>';
    } else if (fontClass == "superscript") {
        tagStart = '<sup>';
        tagEnd = '</sup>';
    } else if (fontClass == "verysmall") {
        tagStart = '<font size="-3">';
        tagEnd = '</font>';
    } else if ( (fontClass != "") && (fontClass != "plain") ) {
        tagEnd = '</span>';
        tagStart = '<span class="' + fontClass + '">';
    }

    theTextArea.value = theTextArea.value + ' ' 
                           + tagStart + textToAdd + tagEnd;
}

// textArea - the textarea to add the text to
// boxId - the textarea containting the text to add to id above
// fontSelect - the selectbox with the font we want
function newDynoText( textArea, boxId, fontSelect ) {
    // Get the text from the little text box
    textToAdd = getElement(boxId).value;
    // check if empty
    if ( textToAdd == "" )
    {
	errorMessage = "You must specify what text to add";
	alert(errorMessage);
	boxId.focus();
    }
    else
    {
        fontToUse = getElement( fontSelect ).value;
        newDynoInsert( textArea, textToAdd, fontToUse );
    }
}

//
// add the given textToAdd to the textarea specified by "textArea"
// with the font specified in the fontSelect
//
function newDynoInsert(textArea, textToAdd, fontToUse )
{
    // get the current textarea
    theTextArea = textArea;

    tagStart = "";
    tagEnd = "";
    if (fontToUse == "quickbold") {
        tagStart = '<b>';
        tagEnd = '</b>';
    } else if (fontToUse == "quickunderline") {
        tagStart = '<u>';
        tagEnd = '</u>';
    } else if (fontToUse == "quickitalic") {
        tagStart = '<i>';
        tagEnd = '</i>';
    } else if (fontToUse == "superscript") {
        tagStart = '<sup>';
        tagEnd = '</sup>';
    } else if (fontToUse == "verysmall") {
        tagStart = '<font size="-3">';
        tagEnd = '</font>';
    } else if ( (fontToUse != "") && (fontToUse != "plain") ) {
        tagStart = '<span class="' + fontToUse + '">';
        tagEnd = '</span>';
    }

    theTextArea.value = theTextArea.value + ' ' + tagStart + textToAdd + tagEnd;
}

//
//  textArea -- the name of the textarea to add it to
//
function makenewlink(textArea) {

    linkaddress = prompt("Enter the address of the page you want to link.","http://");
    if ( linkaddress === null ) {
        return;
    }
    // ask for a link page name
    linkpagename = prompt("Enter the name of the page you are linking.\n "+
               "Example: if you are linking to http://www.google.com/ "+
               "you might use the name 'Search Engine'", "");
    // or just use LINK DESCRIPTION if they dont specify
    if ( linkpagename === null ) {
        linkpagename = 'LINK DESCRIPTION';
    }

    thelinktoinsert = '<a href="' + linkaddress + '"' + '>' 
		    + linkpagename + '</a>';

    textArea.value = textArea.value + " " + thelinktoinsert;
}

//  popupselect : allow user to select what popup they want to insert
//
//  textArea -- the name of the textarea to add it to
//
function popupselect(textArea, popUpSelect) {
    popUpElement = getElement(popUpSelect);
    popUpIndex = popUpElement.selectedIndex;
    popUpNumber = popUpElement.value;
    popUpLinkText = popUpElement.options[popUpIndex].text;
    popUpLink = "pop.htm?pop=" + popUpNumber;
    fullPopUp = "<a href=\"" + popUpLink + "\" onclick=\"" +
	"gen_popup('" +popUpLink+ "','WinName');return false;\">" + 
        popUpLinkText + "</a>";
    textArea.value = textArea.value + " " + fullPopUp;
}


