﻿
    var theReturn;
    var heavyImage;
    var AsyncImageUrl = "";
    var popupLocked = true;
    var currentdd = "";
    var currentZIndex = 0;

    function toggleImage(controlName,imageName) {
        try {
            document.getElementById(controlName).src = imageName;
        }
        catch (ex) { }
    }    

    function toggleHREF(hrefName,turnOn)
    {
        if(turnOn)
            document.getElementById(hrefName).style.textDecoration="underline";
        else
            document.getElementById(hrefName).style.textDecoration="none";
    }    
        
    function deleteMessage()
    {
        theChecks = ReadMailID;
        if(theChecks.length == 0)
            alert('No Messages Selected');
        else
            deleteMessages();
    }
    
    var theChecks = "";
    function deleteMessages(fromWindowFlag)
    {
        try
        {
            if(RPC_Initialized == false || RPC_Busy == true)
                return;

            //theChecks
            var answer = "";
            
            if(theChecks == "")
            {
                alert('No Messages Checked');
                return;
            }
            
            if(theChecks.indexOf(",") > -1)
                answer = confirm("Are you sure you want to delete the selected messages?");
            else
            {
                if(fromWindowFlag == true)
                    answer = confirm("Are you sure you want to delete the message?");
                else
                    answer = confirm("Are you sure you want to delete the selected message?");
            }
                        
            if(answer == false)
                return;
                           
            var sXml = "<Contents>";
            sXml = sXml + "<MailIDs>" + theChecks + "</MailIDs>";
            sXml = sXml + "</Contents>";
            
            //hideMeMail();
		    var ret = callRPC('DeleteMail.aspx',sXml);
			if(ret.error != "")
			{
                alert(ret.error);
            }
            else
            {
                if(theChecks.indexOf(",") > -1)
                    alert('Messages Deleted');
                else
                    alert('Message Deleted');
                
                //RE-LOAD MailBox
                window.location.href = window.location.href;
            }
        }
        catch(ex)
        {
            alert("Error in : deleteMessage() - " + ex.message);
        }            
    }
    
    function checkHandler(theCheckID)
    {
        if(document.getElementById('chkMail' + theCheckID).checked == true)
        {
            if(theChecks == "")
                theChecks = theCheckID;
            else
                theChecks = theChecks + "," + theCheckID;
        }
        else
        {
            if(theChecks == theCheckID)
                theChecks = "";
            else if(theChecks.indexOf(',' + theCheckID, 0) > -1)
                theChecks = theChecks.replace(',' + theCheckID, '');
            else
                theChecks = theChecks.replace(theCheckID + ',', '');
        }
        
    }
    
    var mailSelectFlag = true;
    function selectAllMail()
    {
        try
        {
            var theIDs = document.getElementById('hndMailIDs').value;
            var splitIDs = theIDs.split(",");
            
            for(var d=0;d<splitIDs.length;d++)
            {
                document.getElementById('chkMail' + splitIDs[d]).checked = mailSelectFlag;
            }
            
            if(mailSelectFlag == true)
            {
                theChecks = theIDs;
            }
            else
            {
                theChecks = "";
            }
                   
            mailSelectFlag = !mailSelectFlag;
        }
        catch(ex)  {}
    }
    
    function InitPopups()
    {
        popupLocked = false;
    }
    
    function ShowProfile(profileID)
    {
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;
        window.location.href = "viewprofilewg.aspx?ProfileID=" + profileID;
        //var newWindow = window.open('viewprofilewg.aspx?ProfileID=' + profileID,'Wicked_Garden_Profile','width=770,height=650,top=10,location=0,menubar=0,status=0,toolbar=0,directories=0,location=0,scrollbars=1',false);
        return;            
    }    
    
    function ShowEvent(eventID)
    {
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;
        window.location.href = "eventdetail.aspx?DivDisplay=DESC&EventID=" + eventID;
        return;            
    }     
    
    function ShowAddEvent()
    {
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;
        window.location.href = "eventadd.aspx";
        return;            
    }        
    

    function ShowUpdateEvent(EventID)
    {
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;
        window.location.href = "eventadd.aspx?EventID=" + EventID;
        return;            
    }        
        
    
    function ShowMail(toScreenName)
    {
        if (toScreenName == "ADMINISTRATOR")
        {
            var theAdminAlert = "This account no longer receives email.  Please contact one of the following accounts for help:\r\n\r\n";
            theAdminAlert = theAdminAlert + "For administrative issues, email the 'MEMBER CARE' account on Wicked Garden, or at membercare@wickedgarden.com\r\n\r\n";
            theAdminAlert = theAdminAlert + "For billing or techical issues, email the 'TECH SUPPORT' account on Wicked Garden, or at techsupport@wickedgarden.com\r\n\r\n";
            theAdminAlert = theAdminAlert + "For questions regarding promotions and/or events, email the 'PROMO & EVENTS' account on Wicked Garden, or at promoevents@wickedgarden.com\r\n\r\n";
            theAdminAlert = theAdminAlert + "Thank You\r\n";
            theAdminAlert = theAdminAlert + "WickedGarden.Com";
            alert(theAdminAlert);
            return;
        }
    
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;
        var theUrl = "mailsend.aspx?ToScreenName=" + toScreenName.replace("&", "%26");
        window.location.href = theUrl;
        return;            
    }       

    function ViewMail(mailID,markRead)
    {
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;
        var newWindow = window.location.href="mailview.aspx?MailID=" + mailID;
        
        var theFolder = document.getElementById('hdnFolder').value;
        if(markRead == true)
        {
            if(document.getElementById('mailListImage' + mailID).src.indexOf('text') == -1)
                document.getElementById('mailListImage' + mailID).src="images/mail_read.png";
            document.getElementById('mailListTR' + mailID).style.backgroundColor="DarkGray";
        }
        setTimeout('WickedPulse()', 3000);
        
        return;            
    }        
    
    function ShowForumReply(TopicID,ForumCode)
    {
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;
        if(TopicID == "")
            TopicID = "0";            
        var theUrl = "AddForumReply.aspx?TopicID=" + TopicID + "&ForumCode=" + ForumCode;
        var newWindow;
        if(TopicID == "0")
            newWindow = window.open(theUrl,'Wicked_Garden_ForumReply','width=750,height=680,top=0,location=0,menubar=0,status=0,toolbar=0,directories=0,location=0,scrollbars=1',false);
        else
            newWindow = window.open(theUrl,'Wicked_Garden_ForumReply','width=750,height=600,top=0,location=0,menubar=0,status=0,toolbar=0,directories=0,location=0,scrollbars=0',false);
        return;            
    }  
    
    function ShowForumUpdate(ReplyID)
    {
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;        
        var theUrl = "AddForumReply.aspx?TopicID=0&ForumCode=&ReplyID=" + ReplyID;
        var newWindow;
        newWindow = window.open(theUrl,'Wicked_Garden_ForumReply','width=750,height=475,top=0,location=0,menubar=0,status=0,toolbar=0,directories=0,location=0,scrollbars=0',false);
            
        return;            
    }            
    
    function ShowPopup(PageUrl)
    {
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;        
        var newWindow = window.open(PageUrl);
        return;            
    }           

    var smallEnabled = true;
    function ShowPopupSmall(PageUrl)
    {
        if(smallEnabled == false)
        {
            smallEnabled = true;
            return;
        }
    
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 400;
        }
        else
        {
            winW = (winW / 2) - 390;           
        }
    
        currentZIndex = currentZIndex + 1;
        var top = 10;        
        var newWindow = window.open(PageUrl,'Wicked_Garden_SmallPopup','width=450,height=300,top=10,location=0,menubar=0,status=0,toolbar=0,directories=0,location=0,scrollbars=1',false);
        return;            
    }               
    
    
    //Zip Code Finder Functions!!
    function ZipSearchDone(SearchBox)
    {
        document.getElementById('divZipCodeResults').innerHtml = "";
        var SearchTerm = document.getElementById(SearchBox).value;
        
        if(trim(SearchTerm).length > 3)
        {
            var sXml = "<Contents>";
            sXml = sXml + "<SearchTerm><![CDATA[" + trim(SearchTerm) + "]]></SearchTerm>";
            sXml = sXml + "</Contents>";

		    var ret = callRPC('ZipSearchRPC.aspx',sXml);
			if(ret.error != "")
			{
                alert(ret.error);
            }
            else
            {
                var splitZips = ret.ReturnMessage.split("~");                
                if(splitZips.length == 0 || ret.ReturnMessage.length == 0)
                {
                    document.getElementById('divZipCodeResults').innerHTML = "No Results Returned...";
                }
                else
                {
                    var x = 0;
                    var theZipDivData = "";
                    for(x=0;x<splitZips.length;x++)
                    {
                        var IndvZip = splitZips[x].split("||");
                        var theZipUrl = "<a href=\"javascript:ZipSearchSelect('" + IndvZip[2] + "');\" style=\"text-decoration: none; color: White;\">" + IndvZip[0] + ", " + IndvZip[1] + ". (" + IndvZip[2] + ")</a>";
                                            
                        if(theZipDivData.length > 0)
                            theZipDivData = theZipDivData + "<br/>" + theZipUrl;
                        else
                            theZipDivData = theZipUrl;
                    }
                    
                    document.getElementById('divZipCodeResults').innerHTML = theZipDivData;
                }
            }            
        }
        else
            alert('Search Term Must Be At Least 4 Characters Long');
    }
    
    function ZipSearchSelect(theZipCode)
    {        
        document.getElementById(theResultBox).value = theZipCode;
        if(ZipCallBack.length > 0)
            eval(ZipCallBack);
        CloseZipSearchBox();
    }    
    
    function CloseZipSearchBox()
    {
        document.getElementById('ZipCodeDiv').style.display="none";
    }    
    
    var theResultBox = "";
    var ZipCallBack = "";
    function OpenZipFinder(txtResultBox,txtBox,theCallBack)
    {
        if(theCallBack.length > 0)
            ZipCallBack = theCallBack;
        else
            ZipCallBack = "";
            
        theResultBox = txtResultBox;
        var winW = 0;
        if (parseInt(navigator.appVersion)>3) {
            if (navigator.appName=="Netscape") {
                winW = window.innerWidth;
            }
            if (navigator.appName.indexOf("Microsoft")!=-1) {
                winW = document.body.offsetWidth;
            }
        }
        
        if (navigator.appName.indexOf("Microsoft") > -1) // Explorer 6 Strict
        {
            winW = (winW / 2) - 450;
        }
        else
        {
            winW = (winW / 2) - 440;
        }
    
        currentZIndex = currentZIndex + 1;
        var top = getYOffset() + 70;
        var left = getXOffset() + 180;
        document.getElementById(txtBox).value = "";
        document.getElementById('ZipCodeDiv').style.top=top+"px";
        document.getElementById('ZipCodeDiv').style.left=left+"px";
        document.getElementById('ZipCodeDiv').style.zIndex=currentZIndex;
        document.getElementById('divZipCodeResults').innerHTML = "Type City Name Above....";
        document.getElementById('ZipCodeDiv').style.display="";        
        document.getElementById(txtBox).focus();
    }


