﻿    function PostForm(url) {
        with (document.forms[0]) {
		    //action = '<%=Http.Host%>' + url;
			action = 'http://' + document.location.host + url;
			
            submit();
        } 
    }

	//CLICK HANDLER SO HYPERLINKS WILL ACT AS BUTTONS
    document.onclick = clickHandler;

    function clickHandler(evt) {
        var obj = window.event ? window.event.srcElement : evt.target;

        if (obj.tagName == 'A') {
            if (obj.href.indexOf('lwflowers') > -1 || obj.href.indexOf('localhost') > -1) {
                if (obj.target != '_blank') {
                    with (document.getElementById('aspnetForm')) {
                        action = obj.href; submit();
                    }
                    return false;
                }
                return true;
            }
            if (obj.href.indexOf('javascript') == -1) obj.target = '_blank';
        }
        return true;
    }

    function checkEmail() {
        var email = document.getElementById('<%=txtEmail.ClientID%>');
        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

        if (!filter.test(email.value)) {
            alert('Please provide a valid email address');
            email.focus
            return false;
        }
    }

    function bookmarksite(title, url) {
        if (document.all)
            window.external.AddFavorite('<%=RequestUrl%>', document.title);
        else if (window.sidebar)
            window.sidebar.addPanel(document.title, '<%=RequestUrl%>', "")
    }

    function EmailToAFriend() {
        window.open('/email-to-a-friend.aspx')
    }

    function ShowTopMenu(What, MenuID) {

        HideTopMenus()

        var mnu = document.getElementById(MenuID);
        mnu.style.display = 'block';
        mnu.style.position = 'absolute';
        mnu.style.top = findPosY(What) + 'px';
        mnu.style.left = (findPosX(What) + 5) + 'px';
    }

    function HideTopMenus() {
        document.getElementById('menuCutFlowers').style.display = 'none';
        document.getElementById('menuFillers').style.display = 'none';
        document.getElementById('menuGreens').style.display = 'none';
        document.getElementById('menuTropical').style.display = 'none';
        document.getElementById('menuGrowersWholesalers').style.display = 'none';
    }

    function findPosY(obj) {
        var curtop = 0;
        if (obj.offsetParent)
            while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
        else if (obj.y)
            curtop += obj.y;
        return curtop;
    }

    function findPosX(obj) {
        var curleft = 0;
        if (obj.offsetParent)
            while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
        else if (obj.x)
            curleft += obj.x;
        return curleft;
    }

    function ClearMessageText(EmailBox) {
        if (EmailBox.value == ' -- Enter Email Address --')
            EmailBox.value = '';
    }

    function AddMessageText(EmailBox) {
        if (EmailBox.value.length == 0)
            EmailBox.value = ' -- Enter Email Address --';
    }

    function ClearZipCodeSearchText(txtbox) {
        //CLEAR THE BOX FOR THE USER ONFOCUS
        if (txtbox.value == 'Zip Code')
            txtbox.value = '';
    }

    function CheckZipCodeSearchText(txtbox) {
        //ONBLUR IF THERE IS NO VALUE ADDING ZIP CODE
        if (txtbox.value.length == 0)
            txtbox.value = 'Zip Code';
    }

    function ZipcodeInput(evnt) {
        var key = evnt.keyCode ? evnt.keyCode : evnt.charCode
        //DELETE = 46
        //BACKSPACE = 8
        //LEFT ARROW = 37
        //RIGHT ARROW = 39
        //ZERO = 48; 9 = 57 KEYBOARD KEYS
        //ZERO = 96; 9 = 105 NUMBER PAD KEYS
        if ((key > 95 && key < 106) || (key > 47 && key < 58) || key == 8 || key == 46 || key == 37 || key == 39) 
            return true;
        
        return false
    }

    function ZipSearchButtonFocus(what) {
        if (what.value.length == 5)
            document.getElementById('<%=btnZipcodeSearch.ClientID%>').focus();
    }
