<style type="text/css">
body, #social-post input {

}
#social-post input[type=text] {
	margin-bottom: 5px;
	width: 400px;
}
#social-post .label { 
	float: left;
	width: 120px;
}
#social-post .hide-text { 
	display: none;
}

#social-post .header {
	font-weight: bolder;
	font-size: 14px;
	width: 140px;
}
#social-post .hint {
	font-size: 9px;
}
</style> 

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
</head>


<body>
<div id="social-post">

<!--<input type="text" id="api_key" value="6fd1b6ecee2f4aa198fd05ca239f6ebc"/>
<input type="text" id="access_token" value="a4ba3b27528c417389fc65319e5f5ef5" />
<input type="text" id="base_url" value="http://www.fantools.net" />
<input type="text" id="fb_id" value="164157603666312"/>
<input type="text" id="org_id" value="431"/> 
<input type="text" id="methods" value="save_deal"/>-->

<?php
if($showfantools==1){
	$type="text";
	$type2="checkbox";
	$label="label";
	//$publish_value=' checked="checked"';
	$br="<br/>";
}else{
	$type="hidden";
	//$type2="hidden";
	$type2="checkbox";
	$label="hide-text";
	//$publish_value=' checked="checked"';
	$br="";
}
?>
	<br><span class="<?php echo $label;?>">Name:</span><input type="<?php echo $type;?>" id="deal_name" value="<?php echo $title;?>"/><?php echo $br;?>
	<input type="hidden" id="deal_type" value="Coupon"/>
	<span class="<?php echo $label;?>">Facebook Pages:</span><input type="<?php echo $type;?>" id="deal_fb" value="<?php echo $fbpage;?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Twitter Accounts:</span><input type="<?php echo $type;?>" id="deal_tw" value="<?php echo $twitterid;?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Headline:</span><input type="<?php echo $type;?>" id="deal_headline"  value="<?php echo $title;?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Short Description:</span><input type="<?php echo $type;?>" id="deal_short"  value="<?php echo substr($description,0,60);?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Description:</span><input type="<?php echo $type;?>" id="deal_description"  value="<?php echo $description;?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Coupon Code:</span><input type="<?php echo $type;?>" id="deal_coupon"  value="<?php echo $code;?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Url:</span><input type="<?php echo $type;?>" id="deal_url"  value="
<?php
		if(!empty($buttonURL)){
			echo $buttonURL;
		} else{
			echo $_SERVER['HTTP_HOST']."/order.php?coupon=" . $code;
		}
?>
	"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Price:</span><input type="<?php echo $type;?>" id="deal_price"  value="
	<?php if($couponprice>0){echo $couponprice;}?>
	"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Publish Date:</span><input type="<?php echo $type;?>" id="deal_publishdate"  value="<?php echo $currentdate;?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Start Date:</span><input type="<?php echo $type;?>" id="deal_startdate"  value="<?php echo $currentdate;?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">End Date:</span><input type="<?php echo $type;?>" id="deal_enddate"  value="<?php echo $expiration;?>"/><?php echo $br;?>
	<span class="<?php echo $label;?>">Expiration Date:</span><input type="<?php echo $type;?>" id="deal_expdate"  value="<?php echo $expiration;?>"/><?php echo $br;?>
	<span class="label"></span><div align="center"><b>Add To Facebook Wall</b><i> (in addition to deal page)</i>:<input type="<?php echo $type2;?>" id="deal_wallpublish" checked="checked"/></div><br><?php echo $br;?>
	<!--<span class="<?php //echo $label;?>">Publish To Wall:</span><input type="<?php //echo $type2;?>" id="deal_wallpublish"<?php //echo $publish_value;?>/><?php //echo $br;?>-->
	<span class="<?php echo $label;?>">Wall Post Message:</span><input type="<?php echo $type;?>" id="deal_wallmessage" /><?php echo $br;?>
	<span class="<?php echo $label;?>">Tweet:</span><input type="<?php echo $type;?>" id="deal_tweet" /><?php echo $br;?>
	<span class="<?php echo $label;?>">Email Subject:</span><input type="<?php echo $type;?>" id="deal_emailsubject" /><?php echo $br;?>
	<span class="<?php echo $label;?>">Email Body:</span><input type="<?php echo $type;?>" id="deal_emailbody" /><?php echo $br;?>
	<span class="<?php echo $label;?>">SMS Message:</span><input type="<?php echo $type;?>" id="deal_sms" /><?php echo $br;?>

<div align="center"><input type="button" id="btn_run" value="Publish to Facebook and/or Twitter" /></div><br>

<div id="output" style="padding-left: 5px; float: left; width: 60%; background-color: lightblue;"></div>

</div><!-- end social-post div -->

<script>
var ajax_call = function(url) {
	$.ajax({
		type: 'POST',
		url: $('#base_url').val() + url
	});
}

var deal_data = function() {
	return {
		Name: $('#deal_name').val(),
		Type: $('#deal_type').val(),
		FacebookPages: $('#deal_fb').val(),
		TwitterAccounts: $('#deal_tw').val(),
		Locations: $('#deal_location').val(),
		Headline: $('#deal_headline').val(),
		ShortDescription: $('#deal_short').val(),
		Description: $('#deal_description').val(),
		Restrictions: $('#deal_restrictions').val(),
		CouponCode: $('#deal_coupon').val(),
		Url: $('#deal_url').val(),
		MinUnits: $('#deal_minunits').val(),
		MaxUnits: $('#deal_maxunits').val(),
		MaxIndividualUnits: $('#deal_maxindunits').val(),
		Price: $('#deal_price').val(),
		Value: $('#deal_value').val(),
		PublishDate: $('#deal_publishdate').val(),
		StartDate: $('#deal_startdate').val(),
		EndDate: $('#deal_enddate').val(),
		Name: $('#deal_name').val(),
		ExpirationDate: $('#deal_expdate').val(),
		DesktopLayout: escape($('#deal_desktoplayout').val()),
		MobileLayout: escape($('#deal_mobilelayout').val()),
		PublishToWall: $('#deal_wallpublish').attr('checked'),
		WallPostMessage: $('#deal_wallmessage').val(),
		Tweet: $('#deal_tweet').val(),
		EmailSubject: $('#deal_emailsubject').val(),
		EmailBody: $('#deal_emailbody').val(),
		SMSMessage: $('#deal_sms').val()
	}
};

var methods = {
	save_deal: {
		url: function() { return '/api/save/{orgid}/offer?access_token={token}'.replace('{orgid}', $('#org_id').val()).replace('{token}', $('#access_token').val()) },
		data: function() { return  new deal_data(); },
		fn: function(response) {
			if (response.success)
				//$('#output').html('').append(JSON.stringify(response.data));
				$('#output').html('').append(JSON.stringify("Posted successfully."));
				//<?php echo "Posted successfully."; ?>
			else
				$('#output').html('').append(response.message);
		}
	}
	
}

var ajax = function(method) {
	$.ajax({
		type: 'POST',
		url: $('#base_url').val() + method.url(),
		dataType: 'jsonp',
		data: method.data(),
		success: method.fn
	});
}

$('#btn_run').click(function() {
	ajax(methods[$('#methods').val()]);
});

</script>
