function VPForm(action) {
	if(action == 'show') {
		var winHeight = document.viewport.getHeight();
        var winWidth = document.viewport.getWidth();
        var mainDimensions = $('voicepad').getDimensions();
        var winScrollOS = document.viewport.getScrollOffsets();

        /*if((winHeight/2)-(mainDimensions.height/2) < 0) {
            var ostop = 300;
        } else {
            var ostop = (winHeight/2)-(mainDimensions.height/2) + winScrollOS.top;
        }*/
        var ostop = (winHeight/2)-(mainDimensions.height/2) + winScrollOS.top;
        
        if((winWidth/2)-(mainDimensions.width/2) < 0) {
            var osleft = 1;
        } else {   
            var osleft = (winWidth/2)-(mainDimensions.width/2) + winScrollOS.left;
        }
        
        $('voicepad').setStyle({
            position: 'absolute',
            top: ostop+'px',
            left: osleft+'px'
        });

		Element.show('voicepad');
	}else {
		 Element.hide('voicepad');
	}

}

function validateVoicePad() {
	var name = $('voicepad_name').value;
	var mobile = $('voicepad_mobile').value;
	var email = $('voicepad_email').value;
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

    if(name == "") {
	    alert("Please fill in your name.  Thank you.");
	    return false;
    } else if (mobile == "") {
	    alert("Please fill in your telephone number.  Thank you.");
	    return false;
    } else if (email == "") {
	    alert("Please fill in your email address.  Thank you.");
	    return false;
    } else if (mobile.length != 10 || (/^\d+$/.test(mobile) == false)) {
        alert("For the phone number, you must enter a 10 digit number with no dashes (-) or parentheses (()). Thank you.");
        return false;
    } else if (name.length > 50) {
        alert("The name you enter cannot exceed 50 characters.  Please correct this.  Thank you.");
        return false;
    } else if (email.length > 100) {
	    alert("The email you enter cannot exceed 100 characters.  Please correct this.  Thank you.");
	    return false;
    } else if (pattern.test(email) == false) {
	    alert("Please enter a valid email address.  Thank you.");
	    return false;
    }

    var url = '/voicepad/voicepad.php?f_name='+name+'&f_phone='+mobile+'&f_email='+email+'&f_customerid=524';
    var returning;
    
    //all validation passed so lets make the request to VoicePad
    new Ajax.Request(url, {
        method: 'post',
        asynchronous: false,
        onSuccess: function(transport) {
            if (transport.responseText != "1")
            {//this is an error
            	Element.update('signup', "<p class='userMessage'>There was an error sending your info to Cutler Mobile MLS.  Please try again later, if the problem persists please contact <a href='mailto: support@deltagroup.com'>support@deltagroup.com</a>.  Thank you.</p>");
                returning = false;
            }
            else
            {//success
            	Element.update('signup', "<p class='userMessage'>Your information has been successfully sent to Cutler Mobile MLS.  Please check your email to see if you have received further instructions from Cutler Mobile MLS.  Thank you.<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='+4'>1-800-465-4556</font></p>");
                returning = true;
            }
        },
        onFailure: 
        function(transport) {
        	Element.update('signup', "<p class='userMessage'>There was an error sending your info to Cutler Mobile MLS.  Please try again later, if the problem persists please contact <a href='mailto: support@deltagroup.com'>support@deltagroup.com</a>.  Thank you.</p>");
            returning = false;
        }
    });

    return returning;
}