var xmlhttp_seeds;
var xmlhttp_referral_code;

function removereferralcodebox() {
	if (document.getElementById("country").value == 'United States') {
		document.getElementById("referral_code").disabled = false;
		document.getElementById("referral_code").value = '';
		document.getElementById("referral_code_result").innerHTML = '';
	}
	else {
		document.getElementById("referral_code").disabled = true;
		document.getElementById("referral_code").value = 'NOT AVAILABLE';
		document.getElementById("referral_code_result").innerHTML = '<font color=red face="arial">NOT AVAILABLE</font>';
	}
}

function GetXmlHttpObjectreferral_code() {
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
function checkforvalidreferralcode() {
	if (document.getElementById("referral_code").value.length > 0) {
		document.body.style.cursor = "wait";
		xmlhttp_referral_code=GetXmlHttpObjectreferral_code();
		if (xmlhttp_referral_code==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="checkreferralcode.php";
		url=url+"?referral_code="+document.getElementById("referral_code").value;
		xmlhttp_referral_code.onreadystatechange=updatereferral_code;
		xmlhttp_referral_code.open("GET",url,true);
		xmlhttp_referral_code.send(null);
	}
	else {
		alert("Please enter a referral code to check");
	}
}
function updatereferral_code() {
	if (xmlhttp_referral_code.readyState==4) {
		document.getElementById("referral_code_result").innerHTML=xmlhttp_referral_code.responseText;
		document.body.style.cursor = "default";
	}
}

function GetXmlHttpObject_seeds() {
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function update_seeds() {
	if (xmlhttp_seeds.readyState==4) {
		//document.getElementById("content").innerHTML=xmlhttp_seeds.responseText;
		document.frmpaypalseeds.submit();
		document.body.style.cursor = "default";
	}
}

function subscribe() {
	//validate the form
	if (document.getElementById('billing_name').value.length>0 && document.getElementById('billing_address_line_1').value.length>0 && document.getElementById('billing_city').value.length>0 && document.getElementById('billing_zip_code').value.length>0) {
		if (document.getElementById('credit_card_number').value.length>0) {
			if (document.getElementById('ship_to_name').value.length>0) {
				if (document.getElementById('ship_to_address_line_1').value.length>0) {
					if (document.getElementById('ship_to_city').value.length>0) {
						if (document.getElementById('ship_to_state').value.length>0) {
							if (document.getElementById('ship_to_zip_code').value.length>0) {
								if (document.getElementById('email_address').value.length>0) {
									if (document.getElementById('email_address').value.indexOf("@") > 0 && document.getElementById('email_address').value.indexOf(".") > 0) {					
										if (document.getElementById('how_did_you_hear_about_us').value.length>0) {
											if (document.getElementById('how_did_you_hear_about_us').value == 'Groupon') {
												if (document.getElementById('referral_code').value.length>0) {												
													frminfo.submit();
												}
												else {
													alert('You must enter in a valid Groupon barcode or promotional number');
												}
											}
											else {
												frminfo.submit();
											}
										}
										else {
											alert('You must enter in how you heard about our Seeds of the Month club');
										}
									}
									else {
										alert('You must enter in a valid email address');
									}
								}
								else {
									alert('You must enter in an email address');
								}
							}
							else {
								alert('You must enter in a zip code');
							}
						}
						else {
							alert('You must enter in a state name');
						}
					}
					else {
						alert('You must enter in a city name');
					}
				}
				else {
					alert('You must enter an address on line 1');
				}
			}
			else {
				alert('You must enter your name');
			}
		}
		else {	
			alert('You must enter in a valid credit card');
		}
	}
	else {
			alert('You must completely fill out the BILLING information');
	}
}

/*
function subscribe_to_monthly_seeds() {
	//validate the form
	if (document.getElementById('ship_to_name').value.length>0) {
		if (document.getElementById('ship_to_address_line_1').value.length>0) {
			if (document.getElementById('ship_to_city').value.length>0) {
				if (document.getElementById('ship_to_state').value.length>0) {
					if (document.getElementById('ship_to_zip_code').value.length>0) {
						if (document.getElementById('email_address').value.length>0) {
							if (document.getElementById('how_did_you_hear_about_us').value.length>0) {
								document.body.style.cursor = "wait";
								xmlhttp_seeds=GetXmlHttpObject_seeds();
								if (xmlhttp_seeds==null)
								{
									alert ("Browser does not support HTTP Request");
									return;
								}

								var url="seed_subscription.php";
								url=url+"?a="+document.getElementById("ship_to_name").value;
								url=url+"&b="+document.getElementById("ship_to_address_line_1").value;
								url=url+"&c="+document.getElementById("ship_to_address_line_2").value;
								url=url+"&d="+document.getElementById("ship_to_city").value;
								url=url+"&e="+document.getElementById("ship_to_state").value;
								url=url+"&f="+document.getElementById("ship_to_zip_code").value;
								url=url+"&g="+document.getElementById("ship_to_zip_code_plus_4").value;
								url=url+"&h="+document.getElementById("email_address").value;
								url=url+"&i="+document.getElementById("newsletter").checked;

								//url=url+"&k="+document.getElementById("subscribed_via").value;
								url=url+"&l="+document.getElementById("international_shipment").value;
								url=url+"&m="+document.getElementById("how_did_you_hear_about_us").value;
								url=url+"&n="+document.getElementById("subscription_length").value;
								url=url+"&o="+document.getElementById("affiliate_index").value;
								url=url+"&p="+document.getElementById("affiliate_number").value;
								url=url+"&sid="+Math.random();
								xmlhttp_seeds.onreadystatechange=update_seeds;
								xmlhttp_seeds.open("GET",url,true);
								xmlhttp_seeds.send(null);
							}
							else {
								alert('You must enter in how you heard about our Seeds of the Month club');
							}
						}
						else {
							alert('You must enter in a valid email address');
						}
					}
					else {
						alert('You must enter in a zip code');
					}
				}
				else {
					alert('You must enter in a state name');
				}
			}
			else {
				alert('You must enter in a city name');
			}
		}
		else {
			alert('You must enter an address on line 1');
		}
	}
	else {
		alert('You must enter your name');
	}
}
*/

function change_pick_your_plan(id) {
	txt='';
	
	removereferralcodebox();

	switch(id) {
		case "":
			alert("Pick a country!");
			break;
		case "United States":
			txt='<table width=100% border=0 class="maintableborder" cellspacing=1 cellpadding=1><tr><td><input type="hidden" name="plan_choice" id="plan_choice" value="4"></td></tr></table>';
			change_paypal_subscription_form(1);
/*
			txt='							<table width=100% border=0 class="maintableborder" cellspacing=1 cellpadding=1>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left colspan=2>';
			txt+='										<span class="websiteheadersectionfont">Pick your plan (United States)</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left colspan=2>';
			txt+='										<span class="websiteheadersectionfont">Your first month is FREE</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left>';
			txt+='										<input type="radio" name="plan_choice" id="plan_choice" value="4" onClick="change_paypal_subscription_form(4);">';
			txt+='									</td>';
			txt+='									<td valign=top align=left>';
			txt+='										<span class="seed_subscription_not_required">Pay as you Go: $1.69 per month cancel at anytime</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left>';
			txt+='										<input type="radio" name="plan_choice" id="plan_choice" value="1" onClick="change_paypal_subscription_form(1);">';
			txt+='									</td>';
			txt+='									<td valign=top align=left>';
			txt+='										<span class="seed_subscription_not_required">Good deal: $1.67 per month for 12 months</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left>';
			txt+='										<input type="radio" name="plan_choice" id="plan_choice" value="2" onClick="change_paypal_subscription_form(2);">';
			txt+='									</td>';
			txt+='									<td valign=top align=left>';
			txt+='										<span class="seed_subscription_not_required">Better deal: $1.50 per month for 24 months</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left>';
			txt+='										<input type="radio" name="plan_choice" id="plan_choice" value="3" onClick="change_paypal_subscription_form(3);">';
			txt+='									</td>';
			txt+='									<td valign=top align=left>';
			txt+='										<span class="seed_subscription_not_required"><font color="green">BEST deal: $1.33 per month for 36 months</font></span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='							</table>';
*/
			break;
		default:
			txt='<table width=100% border=0 class="maintableborder" cellspacing=1 cellpadding=1><tr><td><input type="hidden" name="plan_choice" id="plan_choice" value="5"></td></tr></table>';
			change_paypal_subscription_form(6);
/*
			txt='							<table width=100% border=0 class="maintableborder" cellspacing=1 cellpadding=1>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left colspan=2>';
			txt+='										<span class="websiteheadersectionfont">Pick your plan ('+id+')</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left colspan=2>';
			txt+='										<span class="websiteheadersectionfont">Your first month is FREE</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left>';
			txt+='										<input type="radio" name="plan_choice" id="plan_choice" value="5" onClick="change_paypal_subscription_form(5);">';
			txt+='									</td>';
			txt+='									<td valign=top align=left>';
			txt+='										<span class="seed_subscription_not_required">Pay as you Go: $3.69 per month cancel at anytime</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left>';
			txt+='										<input type="radio" name="plan_choice" id="plan_choice" value="6" onClick="change_paypal_subscription_form(6);">';
			txt+='									</td>';
			txt+='									<td valign=top align=left>';
			txt+='										<span class="seed_subscription_not_required">Good deal: $3.67 per month for 12 months</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left>';
			txt+='										<input type="radio" name="plan_choice" id="plan_choice" value="7" onClick="change_paypal_subscription_form(7);">';
			txt+='									</td>';
			txt+='									<td valign=top align=left>';
			txt+='										<span class="seed_subscription_not_required">Better deal: $3.50 per month for 24 months</span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='								<tr>';
			txt+='									<td valign=top align=left>';
			txt+='										<input type="radio" name="plan_choice" id="plan_choice" value="8" onClick="change_paypal_subscription_form(8);">';
			txt+='									</td>';
			txt+='									<td valign=top align=left>';
			txt+='										<span class="seed_subscription_not_required"><font color="green">BEST deal: $3.33 per month for 36 months</font></span>';
			txt+='									</td>';
			txt+='								</tr>';
			txt+='							</table>';
*/
			break;
	}
//	document.getElementById('pick_your_plan').innerHTML=txt;
}

function change_paypal_subscription_form(id) {
	var international_shipment;
	txt='';
	var subscription_length=0;

	switch (id) {
		case 1:	// 12 month subscription - US
			//txt='RZKWCVGKF67S6';	//one month free

			txt='T6QDQFCTQ8JWA';	//three months free

			international_shipment=0;
			subscription_length=1;
			break;
		case 2:	// 24 month subscription - US
			//txt='9136914';	// original
			txt='10351139';	//one month free
			international_shipment=0;
			subscription_length=2;
			break;
		case 3: // 36 month subscription - US
			//txt='9137018';
			txt='10351155';	//one month free
			international_shipment=0;
			subscription_length=3;
			break;
		case 4:	// pay as you go - US
			//txt='9439668'; // originial pay per month basis
			txt='10333778';	//one month free
			international_shipment=0;
			subscription_length=0;
			break;
		case 5:	// pay as you go international
			//txt='9772556'; // originial
			txt='10351288';	//one month free
			international_shipment=1;
			subscription_length=0;
			break;
		case 6: // 12 months international
			// txt='9772597'; // original
			txt='4TMUHCPTXRB76';	//three months free
			international_shipment=1;
			subscription_length=1;
			break;
		case 7: // 24 months international
			// txt='9772624'; // original
			txt='10801376';	//one month free
			international_shipment=1;
			subscription_length=2;
			break;
		case 8: // 36 months international
			// txt='9772646'; // original
			txt='10801298';	//one month free
			international_shipment=1;
			subscription_length=3;
			break;
		case 9: // LIFETIME BUTTON - LIMITED AVAILABILITY ONLY IN THE USA
			txt='10718811';	
			international_shipment=0;
			subscription_length=4;
			break;
		default:
			txt='9772556';	//default pay as you go international without free month
			international_shipment=1;
	}
	document.getElementById('hosted_button_id').value=txt;
	document.getElementById('international_shipment').value=international_shipment;
	document.getElementById('subscription_length').value=subscription_length;
}

function closing_window() {
	var txt='';

	txt="<head><title>Leaving Mike the Gardener Enterprises, LLC so soon?</title></head><body bgcolor='white' text=black>";
	txt+="<img src='veggies2.jpg' border='0' alt='Mike the Gardener Enterprises, LLC'>";
	txt+="<table cellpadding=3 cellspacing=3 border=0>";
	txt+='<tr><td valign=top align=left colspan=2><font face="arial" color="#003399" size="4">Don`t forget to visit our website, follow us on Twitter and join our Vegetable Gardening Facebook Fan Page.</font></td></tr>';
	txt+="</table>";
	txt+="<table cellpadding=3 cellspacing=3 border=0>";
	txt+='<tr><td valign=top align=left></td><td valign=top align=left><font face="arial" size="2"><a href="http://www.averagepersongardening.com" target=new>Mike the Gardener Enterprises, LLC</a></font></td></tr>';
	txt+='<tr><td valign=top align=left><img src="article_twitter_icon.png" border="0" align="left"></td><td valign=top align=left><font face="arial" size="2"><a href="http://www.twitter.com/mikethegardener" target=new>Twitter</a></font></td></tr>';
	txt+='<tr><td valign=top align=left><img src="article_facebook_icon.png" border="0" align="left"></td><td valign=top align=left><font face="arial" size="2"><a href="http://www.facebook.com/pages/Vegetable-Gardening/88717240962" target=new>Facebook</a></font></td></tr>';
	txt+='</table>';

	windowLeaving=window.open("",'Leaving','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=1,width=640,height=420');
	windowLeaving.document.writeln(txt); 
}

function change_show_video(id) {
	var txt='';
		
	switch (id) {
		case 1:	// ABC
			txt='<object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/v/9XwxPWz3EbM?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/9XwxPWz3EbM?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>';
			break;
		case 2:	// NBC
			txt='<object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/v/mj41jR3N-Ag?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="autoplay" value="true"><embed src="http://www.youtube.com/v/mj41jR3N-Ag?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390" autostart="true" loop="false"></object>';
			break;
		default:		
			txt='<object style="height: 390px; width: 640px"><param name="movie" value="https://www.averagepersongardening.com/seeds_of_the_month_club.mp4"><param name="autoplay" value="true"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="https://www.averagepersongardening.com/seeds_of_the_month_club.mp4" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390" autostart="true" loop="false"></object>';
	}

	document.getElementById('show_video').innerHTML=txt;
}
