function VPForm(action) {
	var voicepad_brand = $('voicepad_brand').value;//this is the name used in the verbiage

	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 = 1;
        } else {
            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(number, specialVars) {
	var name = $('voicepad_name').value;
	var mobile = $('voicepad_mobile').value;
	var email = $('voicepad_email').value;
	var customer_id = $('f_customerid').value;
	var voicepad_brand = $('voicepad_brand').value;//this is the name used in the verbiage
	
	if(specialVars == 1) {
		//this was added for crye-leike
		var vp_mls = $('VP_MLS').value;
		var vp_agentid = $('VP_AgentID').value;
	} else if(specialVars == 2) {//this was added for re/max integrity
		var vp_mls, vp_agentid;
		
		if($('f_county_lane').checked == true) {
			vp_mls = 'RMLS';
			vp_agentid = 'DEFAULT_121692801';
		} else if($('f_county_linn').checked == true) {
			vp_mls = 'WVMLS';
			vp_agentid = 'DEFAULT_122178180';
		} else {
			alert("Please select an area before activating (Lane Co. or Linn/Benton Co.).  Thank you.")
			return false;
		}
	}
	
	//this was put in place specifically for Equity Group becaue they have 3 phone numbers
	var updateDIV = (number == 'useDIV') ? 1 : 0;
		
	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 = '/shared/jsscripts/voicepad/voicepad.php?f_name='+name+'&f_phone='+mobile+'&f_email='+email+'&f_customerid='+customer_id;
    
    if(specialVars == 1 || specialVars == 2) {//this is specifically for cid 317 and remax integrity
    	url += '&vp_mls='+vp_mls+'&vp_agentid='+vp_agentid;
    }
 
    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 the " + voicepad_brand + ".  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
            	if(updateDIV == 1) {
            		Element.hide('signup');
            		Element.show('submitDIV');
            	} else {
            		Element.update('signup', "<p class='userMessage'>Your information has been successfully sent to " + voicepad_brand + ".  Please check your email to see if you have received further instructions from " + voicepad_brand + ".  Thank you.<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='+4'>"+number+"</font></p></p>");
            	}
                returning = true;
            }
        },
        onFailure: 
        function(transport) {
        	Element.update('signup', "<p class='userMessage'>There was an error sending your info to " + voicepad_brand + ".  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;
}
