// JavaScript Document
$(document).ready(function() {						   
	$(document).layout();
	var legalHtml = getLegal();	
	var calcBox = $('#calcBox').clone();
	$('#calcBox').remove();
	var legal;
	var formId;
	$("input[type=radio]").click(function(){
		formId = $(this).val();		
//		var performSubmit = function(form){
//			var formContact = $(form).getContactForm();	
//			if(formId == "pdf") {	
//				formContact.From = 'guide@netsize.com';	
//				formContact.LinkItemId =  4;
//				formContact.BodySource = 'mail_NetsizeGuide2010Pdf.html';	
//				formContact.Subject =  'Download your free copy of The Netsize Guide 2010';	
//				sendMail(formContact);
//			}
//			else if(formId == "hard") {
//				$("#calcBox").total(); 
//				var quantity = parseInt($("#quantity").val());		
//				var shipping = (quantity > 3) ? 0 : parseFloat($("#shipping").text());
//				var url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9VJSG5PKAYQMQ" +
//					"&quantity=" + quantity + "&shipping=" + shipping +	"&first_name=" + formContact.FirstName + 
//					"&last_name=" + formContact.LastName + "&email=" + formContact.Email;
//					
//				$("#retURL").val(url);
//			}
//			
//			form.submit();
//		}
		
		var option = new Object();		
		if(formId == "pdf") {
			option.fields = new Array("salutation", "firstname", "lastname", "email", "title", "company", "market", "country", "phone", "mobile", "newsletterBox", "agree");
			option.salesforceId = "70120000000Q8JX";
		}
		else if(formId == "hard") {
			option.fields = new Array("salutation", "firstname", "lastname", "email", "title", "company", "market", "country", "phone", "mobile", "comments", "newsletterBox", "agree");
			option.salesforceId = "70120000000Q8Jc";			
		}
		
		var initForm = function(){
			option.isPartner = false;
			$("#signupForm").loadFields(option);
			legal = (legal == undefined) ? $(legalHtml) : $("#legal");
			$("#signupForm").after(legal);
			$("#signupForm").validate();
			
			$("#signupForm").submit(function(){
				if($(this).valid() == false)
								return false;
				
				var formContact = $(this).getContactForm();	
					if(formId == "pdf") {	
						formContact.From = 'guide@netsize.com';	
						formContact.LinkItemId =  4;
						formContact.BodySource = 'mail_NetsizeGuide2010Pdf.html';	
						formContact.Subject =  'Download your free copy of The Netsize Guide 2010';	
						sendMail(formContact);
					}
					else if(formId == "hard") {
						$("#calcBox").total(); 
						var quantity = parseInt($("#quantity").val());		
						var shipping = (quantity > 3) ? 0 : parseFloat($("#shipping").text());
						var url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9VJSG5PKAYQMQ" +
							"&quantity=" + quantity + "&shipping=" + shipping +	"&first_name=" + formContact.FirstName + 
							"&last_name=" + formContact.LastName + "&email=" + formContact.Email;
							
						$("#retURL").val(url);
					}
				
				return true;
			});

			
			
			
			if(formId == "hard") {				
				$("#newsletterBox").before(calcBox.show());
				$("#update").click(function(){ $("#calcBox").total(); });
			}
		}			
		
		if(option.fields != undefined)
			$("label[for="+formId+"]").after($("#signupForm").load("../template/formular/form.html", initForm).show());
		else $("#signupForm").hide();
		
	});	
		
});


