// --------------------------------------------
// ---- CHECK IF MAC OR PC --------------------
// --------------------------------------------
function Mac_or_PC() 
{
	detect = navigator.userAgent.toLowerCase();
	
	isMac = detect.indexOf('mac') + 1;
	
	if( isMac )
	{
		menu = document.getElementById('menu_items');
		menuLinks = menu.getElementsByTagName("a");
		for(i = 0; i < menuLinks.length; i++){	
			menuLinks[i].style.padding = "1px 15px 3px 15px";
		}
	}
}

// ----------------------------------------------------------------------------------
// ---- CREATE ACCOUNT VALIDATION FORM ----------------------------------------------
// ----------------------------------------------------------------------------------

function ValidateTrialForm()
{
	if( validateForm1() )
	{
		
		frm = document.free_trial_form;
		
				
		// THIS IS THE "ORDER-NOW" PAYMENT PAGE
		if (document.getElementById('return'))
		{
			// --- Set pass-on variables in "return" field
			return_var = "http://www.sparkio.com/members/pdt_confirm.php";
			//return_var = document.getElementById('return').value; // May get messed up if reset too often?
			occupation_var = frm.occupation.value;
			referral_val = frm.referral.value;
			set_referral = return_var + '?occupation=' + occupation_var + '&referral=' + referral_val;
			document.getElementById('return').value = set_referral;
		
		
			// --- SET RECURRING VALUES, ETC (so that it will be correct each time...  // This implies checking to make sure amount is correct at the end...
			
			

			// --- If in Canada / Quebec
			if ( frm.address_country.value == 'canada' )
			{
				// Set currency to Canadian Dollar
				document.getElementById('currency_code').value = 'CAD';
				
				// Payment (calculate taxes)
				totalpayment = eval(frm.a3.value);
				totalpayment = Math.round(totalpayment*100)/100;
				
				gstvalue = eval(totalpayment*7/100);
				gstvalue = Math.round(gstvalue*100)/100;
				gstvalue1 = gstvalue.toFixed(2);
				
				qstvalue = eval((totalpayment+gstvalue)*7.5/100);
				qstvalue = Math.round(qstvalue*100)/100;
				qstvalue1 = qstvalue.toFixed(2);
				
				
					
				// Set Canadian Taxes
				if ( frm.address_state.value == 'quebec' )
				{
					document.getElementById('on0').value = "GST included in price";
					document.getElementById('os0').value = "$" + gstvalue1;
					document.getElementById('on1').value = "QST included in price";
					document.getElementById('os1').value = "$" + qstvalue1;
					thepayment = eval(totalpayment+gstvalue+qstvalue);
					document.getElementById('a3').value = Math.round(thepayment*100)/100;
					
				} else {
					
					document.getElementById('on0').value = "GST included in price";
					document.getElementById('os0').value = "$" + gstvalue1;
					thepayment = eval(totalpayment+gstvalue);
					document.getElementById('a3').value = Math.round(thepayment*100)/100;
					
				} // Fi Set Canadian Taxes
				
				alert("the payment value is (a3): " + document.getElementById('a3').value + "\n The 'totalpayment' variable is " + totalpayment +  "\n and the on0/os0 twins are:\n "+ document.getElementById('on0').value + ' => ' + document.getElementById('os0').value + "\n and the on1/os1 twins are:\n "+ document.getElementById('on1').value + ' => ' + document.getElementById('os1').value );
		
			}// Fi In Canada / Quebec
			
		} // FI this is "order-now" payment page
		
		
		
		return true;
		
	} else {
		alert('YOU MUST CORRECT THE FOLLOWING FORM FIELDS:\n '+message);
		return false;
	}
	
	// Check that Username and Portfolio Web Address are not already taken (php) !!!!!!!!!
	
}

function validateForm1()
{

	// Initiate variables
	frm = document.free_trial_form;
	message = '';
	
	// List of fields
	var trial_fields = new Array();
	trial_fields['first_name'] = 		"First Name";
	trial_fields['last_name'] = 		"Last Name";
	trial_fields['custom'] = 			"Portfolio Web Address";
	trial_fields['payer_email'] = 		"Email";
	trial_fields['address_street'] = 	"Address Street";
	trial_fields['address_city'] = 		"Address City";
	trial_fields['address_state'] = 	"Address State / Province";
	trial_fields['address_zip'] = 		"Address Zip / Postcode";
	trial_fields['occupation'] = 		"Occupation";
	trial_fields['referral'] = 			"How you heard about us";
	
	// Go through all form fields
	for(i=0; i < frm.length; i++) {
	
		// Check that fields are not blank
		if(frm[i].value == '') 
		{
			thisField = frm[i].name;
			if( thisField !== "referral" && thisField !== 'item_name' && thisField !== 'on0' && thisField !== 'os0' && thisField !== 'on1' && thisField !== 'os1' ) 
			{
				message += '\n"'+trial_fields[thisField]+'" can not be left blank.';
			}
		}
		// Check that "email" is a email address
		else if( frm[i].name == 'payer_email' ) 
		{
			email_address = frm[i].value;
			validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
			
			// search email text for regular exp matches
			if (email_address.search(validRegExp) == -1) 
			{
				message += '\n Your email address is INVALID.';
			} 
		}
		// Make sure they agree to terms of service
		else if ( frm[i].name == 'terms_of_use' && !frm[i].checked)
		{
				message += '\n You must agree to the Terms Of Use if you want to use Sparkio.';
		}
		
	} // End foreach
	
	// If there is an error, do not send and pop-up appropriate message
	if (message.length == 0) 
	{
		return true;
	}
	else
	{
		return false;
	}

} // End function ValidateForm1()


// ----------------------------------------------------------------------------------
// ---- Questions & Info pop-ups ----------------------------------------------------
// ----------------------------------------------------------------------------------
function info_popup(content) 
{
	// Popup content
	var popup_content = new Array();
	popup_content["Unique Website URL"] = 	"Your portfolio's website URL is the suffix you wish to add to \"sparkio.com/\" from which your can link to it. <br /><br /> For example, if you choose \"yourPortfolio\", then your website's URL will be \"<strong>www.sparkio.com/yourPortfolio</strong>\".<br /><br /><strong>NOTE 1:</strong> You can only use alphanumeric characters (letters A to Z and numbers 0 to 9)<br /><br /><strong>NOTE 2:</strong> Maximum length of 25 characters";
	
	
	// Popup function
	info_popup=window.open('','info','width=350,height=230,left=100,top=100,resizable=no,scrollbars=auto,toolbar=no,status=no,location=no');
	
	var tmp = info_popup.document;
	tmp.write('<html><head><title>'+content+'</title>');
	tmp.write('<link rel="stylesheet" href="/css/sparkio_css.css">');
	tmp.write('</head><body><div style="padding:5px 10px;">');
	tmp.write('<h3><strong>'+content+'</strong></h3>');
	tmp.write('<p><br />'+popup_content[content]+'</p><p style="text-align:right;"><a href="javascript:window.close()">Close</a></p>');
	tmp.write('</div></body></html>');
	tmp.close();
	
	// Focus on opened popup
	if (window.focus) {info_popup.focus()}	
}


// -----------------------------------------------------------------------------------
// -------- VIEW TERMS OF USE IN POPUP -----------------------------------------------
// -----------------------------------------------------------------------------------
function popup_terms_of_use(url)
{
	help_window = window.open(url,'terms_of_use','width=500,height=550,left=20,top=20,resizable=1,scrollbars=1,toolbar=0,status=0,location=0');
	//help_window.location.href = url;
	
	if (window.focus) 
	{
		help_window.focus();
	}
}

// -----------------------------------------------------------------------------------
// -------- VIEW PRODUCT INFO POPUPS -----------------------------------------------
// -----------------------------------------------------------------------------------
function popup_product_info(info_id)
{
	url = '/product_info_popup.php?prod_info_id=' + info_id;
	popup_window = window.open(url,'Product_Info','width=300,height=250,left=40,top=40,resizable=1,scrollbars=1,toolbar=0,status=0,location=0');
	
	if (window.focus) 
	{
		popup_window.focus();
	}
}

