// JavaScript Document
function printForm() {
	//preload alt form
	var pic1= new Image(250,700); 
	pic1.src="/images/form_new.png"; 
	
	var form = "<div id='colForm' style='background-image: url(/images/form_new_short.png); height: 549px; background-position: top right;'> \
            <div id='form'> \
                <form id='sideForm' method='post' action='http://www.aweber.com/scripts/addlead.pl' onsubmit='return textCheck();'> \
                <input type='hidden' name='meta_web_form_id' value='1214064524'> \
                <input type='hidden' name='meta_split_id' value=''> \
                <input type='hidden' name='unit' value='rsi-request1'> \
                <input type='hidden' name='redirect' value='http://www.refrigerationschool.com/thankyou.htm'> \
                <input type='hidden' name='meta_adtracking' value=''> \
                <input type='hidden' name='meta_message' value='1'> \
                <input type='hidden' name='meta_required' value='from,custom Phone,name,custom Custom,custom Address,custom City,custom State,custom Zip,custom How did you hear about RSI'> \
                <input type='hidden' name='meta_forward_vars' value='0'> \
                <div class='notSelect'><input name='name' type='text' id='name'></div> \
                <div style='margin-top: 3px;' class='notSelect'><input name='custom Custom' type='text' id='custom Custom'></div> \
                <div style='margin-top: 3px;' class='notSelect'><input name='custom Phone' type='text' id='custom Phone'></div> \
                <div style='margin-top: 3px;' class='notSelect'><input name='from' type='text' id='from'></div> \
                <div style='margin-top: 3px;' class='notSelect'><input name='custom Address' type='text' id='custom Address'></div> \
                <div style='margin-top: 3px;' class='notSelect'><input name='custom City' type='text' id='custom City'></div> \
                <div id='stateDiv' style='height: 15px;'> \
                    <div class='notSelect' style=' float: right; height: auto; margin-right: 2px;'> \
					<input name='custom State' id='custom State' type='text' style='border: 1px solid; margin-top: 1px; width: 55px; margin-right: 22px;' > \
                    <input name='custom Zip' id='custom Zip' type='text' style='width: 55px;' id='custom Zip'> \
                  </div> \
                    <div style='clear: both;'></div> \
                </div> \
                <div id='tourDiv' style='height: 15px; margin-top: 3px;'> \
                	<select name='custom Tour' id='custom Tour' class='autocomplete'> \
                    	<option value='yes'>Yes</option> \
                        <option value='no'>No</option> \
                    </select> \
                    <div style='clear: both;'></div> \
                </div> \
                <div style='margin-top: 30px; height: 15px;'> \
                	<select name='custom How did you hear about RSI' id='hear' style='width: 208px;' class='autocomplete'> \
                    	<option value='internet_search'>Internet Search</option> \
                    	<option value='tv'>TV Commercial</option> \
                    	<option value='radio'>Radio</option> \
                    	<option value='friend'>Friend</option> \
                    	<option value='yellow_pages'>Yellow Pages</option> \
                    	<option value='referral'>Referral</option> \
                    	<option value='none'>None of the Above</option> \
                    </select> \
                    <div style='clear: both;'></div> \
                </div> \
                <div style='margin: 30px 0px 0px 0px; height: auto; padding: 0px; clear:both;' class='notSelect'><textarea name='custom Comments' cols='' rows='' style='width: 207px; height: 54px; border: 1px solid #000;' id='custom Comments'></textarea></div> \
				<div style='text-align: left; margin: 10px 0px 0px 180px;'><input type='checkbox' id='optin_cb' onclick='tgltxt();'></div>\
				<div id='optin' style='display: none;'>\
					<div class='notSelect' style='margin: 6px 0px 0px 0px;'><input type='text' id='txt_cell'></div>\
					<div style='margin: 25px 0px 0px 0px;'><select id='txt_op' class='autocomplete'><option value=''></option><option value='Alltel'>Alltel</option><option value='AT&T'>AT&T</option><option value='Boost'>Boost</option><option value='Cincinnati Bell'>Cincinnati Bell</option><option value='Dobson'>Dobson/Cellular One</option><option value='Nextel'>Nextel</option><option value='Sprint'>Sprint</option><option value='T-Mobile'>T-Mobile</option><option value='US Cellular'>US Cellular</option><option value='Verizon'>Verizon</option><option value='Virgin Mobile'>Virgin Mobile</option></select></div>\
				</div>\
				<div><input type='image' src='/images/submit-button.jpg' value='Submit' alt='Submit' style='width: 60px; height: 19px; margin-top: 5px;'></div> \
                </form> \
            </div> \
	<script type='text/javascript'> \
		if (!jQuery.browser.msie) new Autocompleter.SelectBox('custom Tour', {css : 'combo1'}); \
	</script> \
	<script type='text/javascript'> \
		if (!jQuery.browser.msie) new Autocompleter.SelectBox('hear', {css : 'combo3'}); \
	</script> \
	<script type='text/javascript'> \
		if (!jQuery.browser.msie) new Autocompleter.SelectBox('txt_op', {css : 'combo3'}); \
	</script> \
          </div>"
	document.write(form); 
}

function textCheck()
{
	if(jQuery("#optin_cb:checked").length != 1) return true;
		
	//Scrub the cell field
	jQuery("#txt_cell").val( jQuery("#txt_cell").val().replace(/\D/g, '') );
	jQuery("#txt_cell").val( jQuery("#txt_cell").val().replace(/^1/g, '') );
		
	//Quick validate
	if(jQuery("[id=name]").val() == "")
	{
		alert('Please enter a first name.');
		return false;
	}
	
	if(jQuery("[id=custom Custom]").val() == "")
	{
		alert('Please enter a last name.');
		return false;
	}
	
	if(jQuery("[id=custom Phone]").val() == "")
	{
		alert('Please enter a phone number.');
		return false;
	}
	
	if(jQuery("[id=from]").val() == "")
	{
		alert('Please enter an email address.');
		return false;
	}
	
	if(jQuery("[id=custom Address]").val() == "")
	{
		alert('Please enter an address.');
		return false;
	}
	
	if(jQuery("[id=custom City]").val() == "")
	{
		alert('Please enter a city');
		return false;
	}
	
	if(jQuery("[id=custom State]").val() == "")
	{
		alert('Please enter a state.');
		return false;
	}
	
	if(jQuery("[id=custom Zip]").val() == "")
	{
		alert('Please enter a zip code.');
		return false;
	}
	
	
	if(jQuery("#txt_op").val() == "")
	{
		alert('Please select an operator.');
		return false;
	}
		
	if(jQuery("#txt_cell").val().length != 10)
	{
		alert('Please enter a valid cell phone number.');
		return false;
	}
		
	//Ajax the opt-in call
	var d = {};
	d.cell_phone = jQuery("#txt_cell").val();
	d.operator = jQuery("#txt_op").val();
	if(jQuery("form#sideForm input[name='name']").val() != "") d.first_name = jQuery("form#sideForm input[name='name']").val();
	if(jQuery("form#sideForm input[name='custom Custom']").val() != "") d.last_name = jQuery("form#sideForm input[name='custom Custom']").val();
	if(jQuery("form#sideForm input[name='from']").val() != "") d.email = jQuery("form#sideForm input[name='from']").val();
	if(jQuery("form#sideForm input[name='custom Address']").val() != "") d.street1 = jQuery("form#sideForm input[name='custom Address']").val();
	if(jQuery("form#sideForm input[name='custom Zip']").val() != "") d.zip = jQuery("form#sideForm input[name='custom Zip']").val();
	//jQuery.post("/txt.php", d);
	jQuery.ajax({
		type: 'POST',
		url: "/txt.php",
		data: d,
		async: false
	});

		
	return true;
}

		function tgltxt()
		{
				if(jQuery("#optin_cb:checked").length == 1)
				{
					jQuery("#optin").show();
					document.getElementById('colForm').style.backgroundImage = 'url(/images/form_new.png)';
					document.getElementById('colForm').style.height = '700px';
				}
				else
				{
					jQuery("#optin").hide();
					document.getElementById('colForm').style.backgroundImage = 'url(/images/form_new_short.png)';
					document.getElementById('colForm').style.height = '549px';
				}
		}