<script>
$(document).ready(function(){
	$('#updateBtn').click(function() { 
		var update = $('#update').val();
		var foruser_id = $('#foruser_id').val();
        var dataString = 'msg='+ update + '&foruser_id=' + foruser_id;
		
		$.ajax({
			type: 'POST',
			url: "<?=base_url()?>welcome/sendprivatemsg/",
			data: dataString,
			dataType: 'html',
			beforeSend: function() {
				$('#result').html('<img src="<?=base_url()?>cdn/images/ajax-loader.gif"/>Loading...');
				if(!update[0]) {
					$('#result').html('You did not write anything !');   	
					return false;
				} 	
			},
			success: function(response) 
			{
			    getsendsmscount();
				$('#result').html(response);
				document.getElementById('update').value = '';
				$('#updatelimitinfo').html(''); 
			}
 
		});
	});
});

function limitChars(textid, limit, infodiv)
{
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit)
	{
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else
	{
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}
 
$(function(){
 	$('#update').keyup(function(){
 		limitChars('update', 120, 'updatelimitinfo');
 	})
});
 

function getsendsmscount()
{
    $('#sendsmscnt').load('<?=base_url();?>welcome/getsendsmscount/').fadeIn(1000);
}
</script> 
<!-- start page -->
<div id="page">
	<!-- start sidebar -->
  
   <div id="leftside" style="float: left;margin-right: 15px;text-align: center;">
   <?php
     $userID = $this->session->userdata('id');
     $sqlConf = mysql_query("SELECT * FROM usertype_config WHERE id IN (SELECT membertype FROM users WHERE id='$userID')") or die(mysql_error());
	 $aConf=mysql_fetch_array($sqlConf,MYSQL_ASSOC);
	 
	 $sqlConf = mysql_query("SELECT count(*) as cnt FROM users WHERE membertype=1 AND aff_by='$userID'") or die(mysql_error());
	 $aFreeCount=mysql_fetch_array($sqlConf,MYSQL_ASSOC);
    
	 $sqlConf = mysql_query("SELECT count(*) as cnt FROM users WHERE membertype!=1 AND aff_by='$userID'") or die(mysql_error());
	 $aPaidCount=mysql_fetch_array($sqlConf,MYSQL_ASSOC);

	 $d=01;
     $mnth = date('m');
     $yr = date('Y');
     $dt = strtotime($d.'-'.$mnth.'-'.$yr);
     //die("SELECT count(*) as cnt FROM messages WHERE time_stamp>$dt AND member_uid='$userID'");
     $sqlConf = mysql_query("SELECT count(*) as cnt FROM messages WHERE for_user_id!=0 AND time_stamp>$dt AND member_uid='$userID'") or die(mysql_error());
	 $aSMSCount=mysql_fetch_array($sqlConf,MYSQL_ASSOC);
   ?>
   
  
       <div style="border:1px solid gray;border-radius:10px;padding: 5px; text-align: center;background-color: #E2E2E2;" >
        <h2>Today's Stat</h2>
            <div style="float:left;border-bottom:1px solid gray;border-right:1px solid gray;padding: 5px;width: 75px;">
                <h3>
                    Text's sent this month
                    <br/>
                    <span id="sendsmscnt"><?= $aSMSCount['cnt']?></span>/<font color="Blue"><?= $aConf['sms_limits'] ?></font>
                </h3>
            </div>
            <div style="float:left;border-bottom:1px solid gray;padding: 5px;width: 75px;">
                <h3>
                    <font color="Green">Paid</font>/<font color="Red">Free</font> Referrals
                    <br>
                    <font color="Green"><?= $aPaidCount['cnt']?></font>/<font color="Red"><?= $aFreeCount['cnt']?></font>
                </h3>
            </div>
            <div style="clear:both;"></div>
            <div style="float:left;border-right:1px solid gray;padding: 5px;width: 75px;">
                <h3>
                    Earnings this month
                    <br>
                    <font color="Green">$50</font>
                </h3>
            </div>
            <div style="float:left;padding:5px;width: 75px;">
                <h3>
                    Referral ID <a onclick='showHelp("This is then ID that you want share with people to use during then sign up. This ID will allow the system to keep track who are you reffering.");'>?</a>
                    <br>
                    <b><?= $userID ?></b>
                 </h3>
            </div>
            <div style="clear:both;"></div>
       </div>
       <br/>
       <h2>Referall URL <a onclick='showHelp("Copy the bellow URL and paste it wherever you want to share it. Share by email, on your blog, or other social networks. If a user signs up  under this link  will become a referall.");'>?</a></h2> <br/>
       <input type="text" value="<?=base_url();?>/welcome/newuser/<?= $userID ?>" size="26">
       <br/>
       <br/>
       <h2>Share On</h2> <br/>
       <a onclick="window.open('http://www.facebook.com/sharer.php?u=<?=base_url();?>/welcome/newuser/<?= $userID ?>','mywindow','width=750,height=650');" href="javascript:void(0);">
            <img width="60" height="60"  src="<?=base_url();?>images/fbicon.png">
       </a>
       <a href="http://twitter.com?status=<?=base_url();?>/welcome/newuser/<?= $userID ?>" target="_blank">
            <img width="60" height="60"  src="<?=base_url();?>images/twicon.png">
       </a>
       <br/>
       When people sign up under<br/>
       you share link you get a <br/>
       finders fee for the life<br/>
       of the account
       
    </div> 
    
	<!-- start content -->
	<div id="content" style="float:left;margin:0px;border: 1px solid gray;width: 600px;">
		<div class="post">
		  <div class="title">
            <div style="padding:20px 30px 0;">
         		    <h3>Plan: <?= $aConf['title'] ?> = <?= $aConf['sms_limits'] ?> text's month</h3>
            </div>

				<div style="padding:20px 30px 0;">Write your message! </div>
				<p>&nbsp;</p>
				<p>
				   <textarea name="update" cols="60" rows="5" id="update"  ></textarea>
				</p>
		
		    <input type="hidden" name="foruser_id" value="<?=$foruser_id?>"  id="foruser_id" />
			<p><font size="+2" style="font-weight:bold;" color="#FF0000"><span id="updatelimitinfo"></span></font></p>
			<p>&nbsp;</p>
			
			 <p><font size="+2" style="font-weight:bold;" color="#000000"><span id="result"></span></font></p>
		   <p>&nbsp;</p>
                <p>
                <input type="submit" name="updateBtn" id="updateBtn" class="button_base" value="Post It !" align="right" />
                </p>
	   
	      </div>
		      <div id="shoutbox">
		           <div style="padding:30px;">
         		        <h2>Message history</h2>
                   </div>
    			   <?php foreach ($aMessHistory as $mess) { ?>
                      <div style="padding:0px 30px 0;width:75%;"><?=$mess['txt']?><br/>
                   			<div class="bubble" id="<?=$mess['id'];?>" style="width:100%; overflow:hidden;border-bottom: 1px solid gray;" >
                                <?=$this->Message->Timesince($mess['time_stamp']);?>  <?php echo "ago"; ?>
                    	    </div>
        		      </div>
		           <?php } ?>
		      </div>
			<p class="links">&nbsp;</p>
	  </div>
  </div>
	<!-- end content -->
	<br style="clear: both;" />
</div>
<!-- end page -->