var RADIO_OFFERS = {
	'lp+digital' : {aId:785,cId:10060387,persist:true},
	'lp+digital+shirt' : {aId:785,cId:10060394,persist:true},
	'cd+digital' : {aId:785,cId:10060397,persist:true},
	'cd+digital+shirt' : {aId:785,cId:10060398,persist:true},
	'digital' : {aId:785,cId:10062016,persist:true},
	'digital+shirt' : {aId:785,cId:10060384,persist:true},
	'deluxe+laminate' : {aId:785,cId:10060407,persist:true},
	'deluxe+laminate+shirt' : {aId:785,cId:10060410,persist:true},
	'deluxe' : {aId:785,cId:10060403,persist:true},
	'deluxe+shirt' : {aId:785,cId:10060404,persist:true},
	'shirt' : {aId:785,cId:10060227,persist:true}
};

function radioValue (radioGroup) {
    if (radioGroup)
    {
        for (var i = 0; i < radioGroup.length; i++)
        {
            if (radioGroup[i].checked)
            {
                var retVal = radioGroup[i].value;
                radioGroup = null;
                return retVal;
            }
        }
    }
    return null;
};

function radioSelect (formRef) {
    var radios = formRef;
    var value = radioValue(radios);
    if (value === null) {
        alert("Please select a package.");
    }
    var initHash = RADIO_OFFERS[value];
    if (initHash) {
        TSPurchase.load(initHash);
    }
};

/* This function will perform an awe.sm-powered share to Twitter, 
 * Facebook, MySpace, Google Buzz, LinkedIn, or email (via mailto)
 * using values you specify.
 * 
 * Here's how to use it on your site:
 * 1) Specify your awe.sm API Key on the line below defining var awesm_api_key
 *
 * 2) Upload this file to a public directory on your server
 *
 * 3) Add the following code to any pages in which you want to use the 
 *    function (before the lines on which you want to use it):
 *    	<script src="{URL of this file on your server}"></script>
 *
 * 4) Call the function via the onclick tag, as such:
 *    	<a href="javascript:void(0);" onclick="awesm_share('twitter',
 *	'Page URL', 'Page Title', 'Tweet Content (<120 chars)');">Share 
 *    	on Twitter</a>  
 *
 * A recognized channel ('twitter', 'facebook', 'myspace', 'gbuzz', 'linkedin',
 * or 'email') is required, the other variables (url, title, content) are optional.
 * 
 * If you want to include single quotes (') or backslashes (\) in the title
 * or content fields, you must escape them with \ (e.g. 'Men\'s Pants'). [You
 * can use addslashes() in PHP - http://php.net/manual/en/function.addslashes.php]
 *
 * If you want to include double quotes (") in the title or content fields,
 * you must use &quot; instead (e.g. 'He said &quot;That/'s nuts!&quot;').
 * [If you use PHP addslashes(), be sure to escape the double quotes first]
 */

function awesm_share(channel, url, title, content) {
						
	/* You must specify a valid awe.sm API Key */
	var awesm_api_key = 'ab530b750235fc75fc84d71726592f7614b052664b8ffccefb6d988ab45b75de'; /* Dev API Key */

	/* You can optionally specify a 'Source' value for LinkedIn (e.g.
         * the name of your site). If left blank, it will be user-defined.
	 */
	var linkedin_source = '';
			
	/* This value corresponds to Tool/create_type on awe.sm. You can
	 * optionally change it to something more specific to your site.
	 * However, please use the recommended construction of {site}-{tool}.
	 */
	var awesm_tool = 'awesm-share-js'
			
	/* This function is used to search for awe.sm Parent parameters in the
	 * current page URL. You must have this feature enabled in your awe.sm
	 * Account Settings for the awe.sm Parent parameters to be present.
	 */
	var getUrlVars = function() {
  		var vars = [], hash;
  		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
 		for(var i = 0; i < hashes.length; i++) {
	    		hash = hashes[i].split('=');
	    		vars.push(hash[0]);
	    		vars[hash[0]] = hash[1];
	  	}
	  	return vars;
	}
			
	/* If no URL is specified, use the current page address */
	if (typeof(url) == 'undefined' || url == '') {
		url = encodeURIComponent(location.href);
	} else {
		url = encodeURIComponent(url);
	}
		
	/* If no title is specified, use the current page title */
	if (typeof(title) == 'undefined' || title == '') {
		title = encodeURIComponent(document.title);
	} else {
		title = encodeURIComponent(title);
	}
			
	/* If no content is specified, use title */
	if (typeof(content) == 'undefined' || content == '') {
		content = title;
	} else {
		content = encodeURIComponent(content);
	}			
		
	/* Configure the channel-specific information */
	switch (channel) {
		case 'twitter':
  			var awesm_channel = 'twitter';
			/* Make sure the content is <120 characters so there's room for the URL */
			if (decodeURIComponent(content).length > '120') {
				content = decodeURIComponent(content).substring(0,117) + '...'; 
				content = encodeURIComponent(content);
			}
			var awesm_destination = 'http://twitter.com/home?status=' + content + '+AWESM_TARGET';
			var window_specs = '';
  			break;
		case 'facebook':
  			var awesm_channel = 'facebook-share';
			var awesm_destination = 'http://www.facebook.com/sharer.php?u=AWESM_TARGET&t=' + title;
			var window_specs = 'toolbar=0, status=0, width=626, height=436';
  			break;
		case 'gbuzz':
			var awesm_channel = 'googlebuzz';
			var awesm_destination = 'http://www.google.com/buzz/post?url=AWESM_TARGET&message=' + content;
			var window_specs = 'resizable=0, scrollbars=0, width=690, height=415';
  			break;
		case 'myspace':
			var awesm_channel = 'myspace';
			var awesm_destination = 'http://www.myspace.com/index.cfm?fuseaction=postto&u=AWESM_TARGET&t=' + title + '&c=' + content;
			var window_specs = 'toolbar=0, status=0, width=825, height=725';
  			break;
		case 'linkedin':
			var awesm_channel = 'linkedin';
			var awesm_destination = 'http://www.linkedin.com/shareArticle?mini=true&url=AWESM_TARGET&title=' + title + '&summary=' + content;
			if (linkedin_source != '') {
				awesm_destination += '&source=' + encodeURIComponent(linkedin_source);
			}
			var window_specs = 'toolbar=0, status=0, width=550, height=400';
  			break;
		case 'email':
			var awesm_channel = 'mailto';
			var awesm_destination = 'mailto:?subject=' + title + '&body=' + content + '%20AWESM_TARGET';
			var window_specs = 'toolbar=0, status=0, width=300, height=200';
  			break;
	}
			
	/* Construct the URL for the awe.sm Share API (see http://developers.awe.sm) */
	var awesmShareIt = 'http://create.awe.sm/url/share?version=1&api_key=' + awesm_api_key +
			    '&target=' + url + 
			    '&share_type=' + awesm_channel + 
			    '&create_type=' + awesm_tool + 
			    '&destination=' + encodeURIComponent(awesm_destination); 
			
	/* Check for an awe.sm Parent parameter in the current page URL, and
	 * add it to the awe.sm Share API URL if present. You must have this
	 * feature enabled in your awe.sm Account Settings for the awe.sm
	 * Parent parameter to be present.
	 */
	var pageParams = getUrlVars();
	if ( pageParams['awesm'] ) {
		awesmShareIt += '&awesm_parent=' + pageParams['awesm'];
	}

	/* If the page specifies a notes value as a global variable (like the
	 *  visitor's cookie GUID), add it to the awe.sm Share API URL. 
	 */
	if (typeof(awesm_notes) != 'undefined' && awesm_notes != null) {
		awesmShareIt += '&notes=' + awesm_notes;
	}
			
	/* Launch the share UI in a new window of the correct size */
	switch (channel) {
		case 'email':
			/* If the channel is Email, close the new window after redirection (3 seconds) */
			var newWin = window.open(awesmShareIt, '_blank', window_specs);
			setTimeout(function() {
				newWin.close();
			}, 3000)
 
			break;
		default:
			window.open(awesmShareIt, '_blank', window_specs);
	}
        
}

