// utility.js : Various functions to make life on the AS Forum easier.
// Javascript to extract date in day of week, date, month and year format.

        // First get date.
        today = new Date()
        TimeHrs = today.getHours()
        TimeMin = today.getMinutes()
        DateMth = today.getMonth()+1
        DateDate = today.getDate()
        DateYear = today.getYear()
        DateDy = today.getDay()
        
        // Now, is it am or pm?
        
        if (TimeHrs > 12) 
        {
                TimeHrs = TimeHrs - 12
                if (TimeHrs == 12) 
                {
                        AmPm = "am"
                } 
                else 
                {
                        AmPm = "pm"
                }
        } 
        else 
        {
                if (TimeHrs == 12) 
                {
                        AmPm = "pm"
                } 
                else 
                {
                        AmPm = "am"
                }
        }
        
        // Make sure minute has leading zero if necessary.
        if (TimeMin < 10) 
        {
                TimeMin = "0" + TimeMin
        }
        
        // Text version of month.
        
        var MonthName = new Array("Empty", "January", "February", "March", "April", "May", "June",
                                  "July", "August", "September", "October", "November", "December");
        
        DateMonth = MonthName[DateMth];

        // Text version of day of week.
                
        var DayOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

        DateDay = DayOfWeek[DateDy];
        
        // Allow for little netscape quirk!
        
        brsr=navigator.appName
        if (brsr=="Netscape") 
        {
                if (DateYear < 99) 
                {
                        DateYear = DateYear + 2000
                } 
                else 
                { 
                        DateYear = DateYear + 1900
                }
        }



var newwindow;
function poptastic(url, pagewidth, pageheight)
{
        // New popup window.    
        var Dimensions = "resizeable=0, height="+pageheight+",width="+pagewidth;
        
        newwindow=window.open(url,'name', Dimensions);
        if (window.focus) {newwindow.focus()}

//return 1;
}


function RedirectTo(Where)
{
        // URL redirection ...
        location.href=Where;
        return 0;
}


function LoginStatus()
{
        // If this function has been called it simply means that the 
        // login process from the perl script was successful.  This function
        // allows us to automatically return to home page.
        
        location.href="./products.cgi";
}

function setCookie(name, value, expires, path, domain, secure)
{
        document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString()) + ((path == null) ? "" : "; path=" + path) + ((domain == null) ? "" : "; domain=" + domain) + ((secure == null) ? "" : "; secure");
}

function delCookie (name)
{
        var delDate=new Date("January 1, 1999 23:30:00");
        setCookie(name,null,delDate);
}

// Add Emoticon to Content text...
function AddEmoticon(Emoticon)
{
        
        document.NewTopic.Content.value = document.NewTopic.Content.value + Emoticon;
        document.NewTopic.Content.focus();
        return false;

}

// Add bold, italic, underline, etc... to content.
function FurnishContent(Option)
{
        
        switch(Option)
        {
           case "Bold" :
                                        FurnishContentWith("[b]", "[/b]", "Your Text Here");
                                        break;
                                           
            case "Italic" :
                                        FurnishContentWith("[i]", "[/i]", "Your Text Here");
                                        break;
                                           
        case "Underline" :
                                        FurnishContentWith("[u]", "[/u]", "Your Text Here");
                                        break;
                                           
            case "Quote" :
                                        FurnishContentWith("[quote]", "[/quote]", "Your Text Here");
                                        break;
                                           
        case "Image" :
                                        FurnishContentWithImg("[img]", "[/img]", "Image URL Here");
                                        break;
                                           
            case "URL" :
                                        FurnishContentWithURL("Full URL Here", "URL Text Prompt");
                                        break;
            default :
           alert("Unknown furnish!!!")
               break;
        }       
        
        return false;

}


function FurnishContentWith(LeftSide, RightSide, FurnishText)
{

        // Have we got selected text?
        theSelection = document.selection.createRange().text;
        if (!theSelection)
        {
                // No text selected, so just add to end of textarea.
                document.NewTopic.Content.value = document.NewTopic.Content.value + LeftSide+FurnishText+RightSide;
                document.NewTopic.Content.focus();
        return false;
        }       
                                        
        // Is selected text within a TEXTAREA tag?
        if (document.selection.createRange().parentElement().tagName != 'TEXTAREA')
        {
        return false;
        }
                                                
        document.selection.createRange().text = LeftSide + theSelection + RightSide;
        document.NewTopic.Content.focus();
                                        
        return true;
}


function FurnishContentWithImg(LeftSide, RightSide, FurnishText)
{

        // Setup for image tag.
        document.NewTopic.Content.value = document.NewTopic.Content.value + LeftSide+FurnishText+RightSide;
        document.NewTopic.Content.focus();
    return true;
}


function FurnishContentWithURL(FurnishContentURL, FurnishContentPrompt)
{

        // Setup for url tag.
        document.NewTopic.Content.value = document.NewTopic.Content.value + "[url="+FurnishContentURL+"]"+FurnishContentPrompt+"[/url]";
        document.NewTopic.Content.focus();
        return true;
}


function InitialiseUsername(From)
{
        // Initially UserName has value "Username", onfoucs we clear to proper entry...
        if (document.Login.UserName.value == "Username")
        {
                document.Login.UserName.value = "";
                document.Login.UserName.focus();
        }
        
        return false;

}

function InitialisePassword()
{
        // Always clear password field...
        document.Login.Password.value = "";
        document.Login.Password.focus();
        
        return false;

}


