/*******************************************
Client Script
********************************************/

function characterCount(id, inputField, max)
{
    var remaining = max - inputField.value.length;
    
    var o = getE(id);
    
    if (inputField.value.length > max)
    {
        inputField.value = inputField.value.substring(0, max);
        remaining = 0;
    }
    
    o.innerText = "(" + remaining + " Characters Remaining)";
    
    
    
}

function uploadImage()
{
    day = new Date();
    id = day.getTime();
    window.open('/ImageGallery/ImageUpload.aspx', 'UploadImage', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=650,height=350');
}

function goToUrl(o)
{
    location.href = o.options[o.selectedIndex].value;
}

var show_hide_array = new Array();

function show_hide(id)
{
    var o = getE(id);
    
    if (o)
    {
        if (o.style.display == "none")
            o.style.display = "block";
        else
            o.style.display = "none";
    }
}


function formFocus(o)
{
    o.value = "";
}

function formBlur(o, text)
{
    if (o.value.length == "0")
        o.value = text;
}

var activeTab = "Information";

function ShowTab(id)
{
    Hide(getE(activeTab));
    Show(getE(id));

    var o = getE("tab_left_" + activeTab);
    if (o)
        o.className = "tab-left";
        
    o = getE("tab_" + activeTab);
    if (o)
        o.className = "tab";
        
    o = getE("tab_right_" + activeTab);
    if (o)
        o.className = "tab-right";
    
    o = getE("tab_left_" + id);
    if (o)
        o.className = "tab-left-on";
        
    o = getE("tab_" + id);
    if (o)
        o.className = "tab-on";
        
    o = getE("tab_right_" + id);
    if (o)
        o.className = "tab-right-on";

    activeTab = id;
}

function Show(o)
{
    if (o)
        o.style.display = "block";
}

function Hide(o)
{
    if (o)
        o.style.display = "none";
}

function getE(id)
{
    return document.getElementById(id);
}  

function inputOnFocus(o, onLoadText)
{
    if (o.value == onLoadText)
    {
        o.value = "";
        o.style.fontWeight = "bold";
        o.style.color = "#333";
    }
}

function inputOnBlur(o, onLoadText)
{
    if (o.value.length == 0)
    {
        o.value = onLoadText;
        o.style.fontWeight = "normal";
        o.style.color = "#777777";
    }
}

function showHide(show, hide)
{
    var o = getE(show);
    o.style.display = 'block';
    
    o = getE(hide);
    o.style.display = 'none'
}

function popUp(URL) 
{
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=800');");
}

function popUp_PlantPhoto(URL) 
{
    var popUpId = "plantPhoto";
    eval("page" + popUpId + " = window.open(URL, '" + popUpId + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=800');");
    eval("page" + popUpId + ".focus();");
}

/* 
session expire 
*/

function PersistSession()
{
    setInterval("doPersistSession()", 1080000);
    //setInterval("doPersistSession()", 5000);    
}

function doPersistSession()
{
    WilsonGarden.Web.Services.Actions.PersistSession("", OnComplete, OnTimeOut, OnError);
}

function OnComplete(s) 
{
    
}

function OnTimeOut(s)
{
    //alert("Postback Time Out!");
    alert("Timeout: " + s.get_message());
}

function OnError(s)
{
    //alert("Postback Error!");
    alert("Error: " + s.get_message());
}

/* 
session expire 
*/

function printThisPage()
{
    var url = "";
    if (location.href.indexOf("?") > -1)
        url = location.href + "&view=print";
    else
        url = location.href + "?view=print";
    
    var printWindow = window.open(url, "print");
    printWindow.focus();
    window.blur();
}

function bookMarkThisPage()
{
    if (window.external) 
    { 
        window.external.AddFavorite(document.URL,document.title);
    } 
    else 
    { 
        alert("Sorry! Your browser doesn't support this function."); 
    }
}

function emailThisPage()
{
    if (top.location.href.indexOf("Email-A-Page.aspx") > -1)
        return;
    
    top.location.href = "/Email-A-Page.aspx?title=" + document.title + "&page=" + location.href;
}

function setParentHref(url)
{
    if (window.opener != null)
    {
        window.opener.focus();
        window.opener.location.href = url;
    }
}


//
// RTE Insert Image Extracted Functions
//

var rte_Active = null;

function openImageGallery()
{
    eval("imageGallery = window.open('/ImageGallery/ImageGallery.aspx', 'imageGallery', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=515');");
    eval("imageGallery.focus();");
}

function rteInitInsertImage(ed)
{
    rte_Active = ed;
    
    //ed.focus();
    //ed.selection.setContent('<strong>Hello world!</strong>');
    eval("imageGallery = window.open('/ImageGallery/ImageGallery.aspx', 'imageGallery', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=515');");
    eval("imageGallery.focus();");
}

function rteInitInsertLink(ed)
{
    rte_Active = ed;
    
    //ed.focus();
    //ed.selection.setContent('<strong>Hello world!</strong>');
    eval("pageSelect = window.open('/Articles/Edit/Page-Select.aspx', 'pageSelect', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=515');");
    eval("pageSelect.focus();");
}

function rteInitInsertPlant(ed)
{
    rte_Active = ed;
    
    //ed.focus();
    //ed.selection.setContent('<strong>Hello world!</strong>');
    eval("plantSelect = window.open('/Articles/Edit/Plant-Select.aspx', 'plantSelect', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=515');");
    eval("plantSelect.focus();");
}

function rteWrite(txt)
{
    if (rte_Active)
    {
        rte_Active.focus();
        rte_Active.selection.setContent(txt);
    }
    else
    {
        alert("No active RTE was found!");
    }
}