var TWEETATWEET = {};
var TTapiKeySamp;
if (!TWEETATWEET.dynData) {
    TWEETATWEET.dynData = {
        "site_vars": {
            "canvas_client_compute_content_size_method": 1

        },
        "resources": {
			"base_url_format": "http://www.tweetatweet.com/",
            //"base_url_format": "http://beta.cenango.com/social_feedback/",
			//"base_url_format": "http://tat.local/",
			 "prompt_twitter_feed_url": "prompt_twitter_feed.php",
			 "prompt_twitter_feedback_url": "prompt_twitter_feedback_url.php",
			 "twitter_rpc_feedback_url" : "rpc.php?action=feedback"

        }
    };
}

if (!TWEETATWEET.locale) {
    TWEETATWEET.locale = "en_US";
}
if (!TWEETATWEET.localeIsRTL) {
    TWEETATWEET.localeIsRTL = false;
}
if (!window.TWEETATWEET) TWEETATWEET = {};
if (!TWEETATWEET.Monitor) TWEETATWEET.Monitor = {
    wrapObject: function(a) {
		TWEETATWEET.Monitor.cssInclude(TWEETATWEET.dynData.resources.base_url_format+"tw/css/feedback.css");
		TTapiKeySamp = a.api_key;
		TWEETATWEET.Monitor.createCommentBox(a);
    },setUser: function(q){
		TTapiKeySamp = q.api_key;
		TWEETATWEET.Monitor.cssInclude(TWEETATWEET.dynData.resources.base_url_format+"tw/css/feedback.css");
		TWEETATWEET.Monitor.createMain(q);
		TWEETATWEET.Monitor.getJsonData(q.api_key);
		
	},
	createCommentBox:function(q){
		tifInnerHtml = '<a class="TT_FeedBackOr_samp" style = "position:fixed;top:50%;  z-index:1000; right:0; _float:right; _position:absolute;" onclick="ShwTweetaTweetCommBOX('+"'"+q.api_key+"'"+')">Feedback</a>';
		TWEETATWEET.Monitor.ContainerOut(tifInnerHtml);
		},ContainerOut:function(H){
		document.write(H);
	},
	createMain:function(q){
		
		var mainDiv = '<div style="border: 1px solid #DADADA; border-bottom:none; padding:0; margin-bottom:10px; font-family:Helvetica,Arial,sans-serif; text-align: center; -webkit-border-radius: 8px 8px 0px 0px; -moz-border-radius: 8px 8px 0px 0px; border-radius: 8px; background: #F9F9F9; behavior:url(PIE.htc);width:'+q.width+';height:'+q.height+';"><h1 style="margin:10px 0 0 15px; padding:0; font-size:18px; color:#1D1D1D; text-align:left;">User Feedback</h1><div style="border: 1px solid #DADADA; padding: 0 0; margin:10px; text-align: center; -webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px; background: #fff; behavior:url(PIE.htc);"><ul style="list-style:none; margin:0; padding:0;" id ="tweetU"><img src="'+TWEETATWEET.dynData.resources.base_url_format+'images/ajax-loader.gif" alt="Loading..." /></ul></div><div style="border: 1px solid #DADADA; height:30px; padding:2px 5px; text-align: center; -webkit-border-radius: 0px 0px 8px 8px; -moz-border-radius: 0px 0px 8px 8px; border-radius: 0px 0px 8px 8px; -webkit-box-shadow: #666 0px 3px 4px; -moz-box-shadow: #666 0px 3px 4px; box-shadow: #666 0px 3px 4px; background: #9FD3F5; background: -webkit-gradient(linear, 0 0, 0 bottom, from(#BBE5FD), to(#82C0EE)); background: -moz-linear-gradient(#BBE5FD, #82C0EE); background: linear-gradient(#BBE5FD, #82C0EE); -pie-background: linear-gradient(#BBE5FD, #82C0EE); behavior:url(PIE.htc);"><a href="'+TWEETATWEET.dynData.resources.base_url_format+'" target="_blank" class="TT_logo_samp"><span style="display:none;">Tweet a Tweet</span></a><a href="javascript:void(0)" onclick="ShwTweetaTweetCommBOX('+"'"+q.api_key+"'"+')" class="btn_feedback_samp">Leave Feedback</a></div></div>';
		document.write(mainDiv);
		

		},
	getJsonData:function(TTapi_keySamp){		
      var TTurl_REQsamp = TWEETATWEET.dynData.resources.base_url_format+'tw/'+TWEETATWEET.dynData.resources.twitter_rpc_feedback_url+'&mode=check_api_key&api_key='+TTapi_keySamp+'&callback=TTprocessREQJSONsamp';        
	  var TTheadIDREQsamp = document.getElementsByTagName("head")[0];         
	  var TTnewScriptREQsamp = document.createElement('script');
	  TTnewScriptREQsamp.type = 'text/javascript';
	  TTnewScriptREQsamp.src = TTurl_REQsamp;
	  TTheadIDREQsamp.appendChild(TTnewScriptREQsamp);
	
/*	
	$(function(){
			  
		    $.getJSON(TWEETATWEET.dynData.resources.base_url_format+'tw/'+TWEETATWEET.dynData.resources.twitter_rpc_feedback_url+'&mode=check_api_key&api_key='+api_key+'&callback=?', function (data) {
       $("#tweetU").html('');
        $.each(data, function (i, item) {
			
            $("#tweetU").append('<li style ="border-bottom:1px dashed #CCC; padding:5px 0;word-wrap: break-word;">' + item.tweet + '<p style="font-size:10px; color:#FF9900;">'+item.add_time+'</p></li>');

        });
    });
    $("#tweetU").fadeIn(2000);
	});
*/	
	
	},
	jsInclude:function(jsFile) {
                 document.write('<' + 'script');
                 document.write(' language="JavaScript"');
                 document.write(' type="text/javascript"');
                 document.write(' src="' + jsFile + '">');
                 document.write('</' + 'script' + '>');
         },
	cssInclude:function(cssFile) {
                 document.write('<' + 'link');
                 document.write(' rel="stylesheet"');
				 document.write(' media="all"');
                 document.write(' type="text/css"');
                 document.write(' href="' + cssFile + '"/>');
         }
	

};
		 TWEETATWEET.Monitor.ContainerOut('<div id="TT_blockUI_samp" style="display: none; background-color: black; width: 100%; height: 100px; position: absolute; left: 0px; top: 0px; z-index: 50000; -moz-opacity: .5; opacity: .5; filter: alpha(opacity=50);" onclick="return false" onmousedown="return false" onmousemove="return false" onmouseup="return false" ondblclick="return false">&nbsp;</div><div id="TT_comm_box_samp" style="display:none; text-align:left;"><a href="javascript:void(0)" onClick="TT_BlockUI_samp.TT_hide_samp();" class="TT_close_samp"></a><b class="TT_title_samp" style="font-size:13px; color:#000000;">Leave Feedback</b><span id ="TT_status_msg_samp" class="TT_status_msg_samp"></span><span class="TT_title_samp" style="margin-top:7px;">Name :</span><input class="TT_name_samp" name="TT_name_text_samp" id="TT_name_text_samp" type="text" /><span class="TT_title_samp" style="margin-top:15px;">Email :</span><input class="TT_name_samp" id="TT_email_text_samp" name="TT_email_text_samp" type="text" /><span class="TT_title_samp" style="margin-top:15px;">Comment :</span><textarea class="TT_name_samp" id="TT_comment_samp" name="TT_comment_samp" cols="" rows="5"></textarea><input type="hidden" name="TT_api_key_samp" id="TT_api_key_samp" value="'+TTapiKeySamp+'" /><div class="TT_powered_samp">powered by <a href="http://www.tweetatweet.com" target="_blank"><img src="http://www.tweetatweet.com/tw/images/wiget_logo.gif" border="0" alt="tweet a tweet" /></a></div><input class="TT_button_samp" id="TT_post_samp" name="TT_post_samp" type="button" value="Post" onclick="TT_validate_form_samp()" /></div>'); 

function ShwTweetaTweetCommBOX(TTApiKeySamp){
	document.getElementById('TT_api_key_samp').value = TTApiKeySamp;
	TT_BlockUI_samp.TT_show_samp();
	var tt_popup_samp = document.getElementById('TT_comm_box_samp');
	if( null == tt_popup_samp ) alert('Popup is not loaded!');
	else tt_popup_samp.style.display = 'block';
	} 
	
	var TT_BlockUI_samp = {
		TT_show_samp : function()
		{
			var tt_block_samp = document.getElementById("TT_blockUI_samp");
			tt_block_samp.style.display = "block";
			tt_block_samp.style.height = document.body.offsetHeight + "px";
		},
		TT_hide_samp : function()
		{
			closeCommentBoxSamp();
			
		}
	};
	
	
function TT_validate_form_samp(){
	var  TT_post_samp_val	=	document.getElementById("TT_comment_samp").value;
	var  TT_api_key_samp_cal	=	document.getElementById("TT_api_key_samp").value;
	var  TT_email_text_samp_val	=	document.getElementById("TT_email_text_samp").value;
	var  TT_name_text_samp_val	=	document.getElementById("TT_name_text_samp").value;

if(TT_post_samp_val == ""){
		document.getElementById('TT_status_msg_samp').innerHTML = "Enter Comments";
		}
	else{
		
		TTmakeJsonRequestSamp(TT_post_samp_val,TT_api_key_samp_cal,TT_email_text_samp_val,TT_name_text_samp_val);
}
	//alert(escape(TT_post_samp_val));alert(unescape(escape(TT_post_samp_val)));
	}
	
	

        function TTmakeJsonRequestSamp(TT_post_samp_val,TT_api_key_samp_cal,TT_email_text_samp_val,TT_name_text_samp_val)
        {
        var TTurl_samp = TWEETATWEET.dynData.resources.base_url_format+'tw/rpc.php?action=feedback&mode=add_comment&api_key='+TT_api_key_samp_cal+'&name='+TTURLEncodesamp(TT_name_text_samp_val)+'&email='+TTURLEncodesamp(TT_email_text_samp_val)+'&comments='+TTURLEncodesamp(TT_post_samp_val)+'&callback=TTprocessJSONsamp';        
			 var TTheadIDsamp = document.getElementsByTagName("head")[0];         
			  var TTnewScriptsamp = document.createElement('script');
				  TTnewScriptsamp.type = 'text/javascript';
				  TTnewScriptsamp.src = TTurl_samp;
			  TTheadIDsamp.appendChild(TTnewScriptsamp);
			  setTimeout("closeCommentBoxSamp()",3000);

        }
function closeCommentBoxSamp(){
			document.getElementById("TT_blockUI_samp").style.display = "none";
			document.getElementById("TT_comm_box_samp").style.display = "none";
			document.getElementById("TT_comment_samp").value = "";
			document.getElementById("TT_email_text_samp").value = "";
			document.getElementById("TT_name_text_samp").value = "";

			document.getElementById('TT_status_msg_samp').innerHTML = "";
	
	}
function TTprocessJSONsamp(TTfeedSamp){
  document.getElementById('TT_status_msg_samp').innerHTML = TTfeedSamp.error_msg;
 }
 
function TTprocessREQJSONsamp(TTReqSamp){
	document.getElementById('tweetU').innerHTML = "";
	for(var i =0 ;i<TTReqSamp.length;i++){
		//alert(TTReqSamp[i].tweet);
		document.getElementById('tweetU').innerHTML += '<li style="border-bottom: 1px dashed #CCCCCC; word-wrap: break-word; text-align:left; padding:5px 0px 7px 0px; margin:0 10px 5px 10px;"><p style="font-size: 11px; color:#0C77CF; margin:0; padding:0 0 5px 0;">'+TTReqSamp[i].add_time+'</p><p style="padding:0; margin:0; color:#333; font-size:14px">'+TTReqSamp[i].tweet+'</p><p style="text-align:right;color:#00528F; margin:0; padding:0;font-size:12px;"><span style="font-size:14px;">'+TTReqSamp[i].add_user_name+'</span></p></li>';
		}

          //  $("#tweetU").append('<li style ="border-bottom:1px dashed #CCC; padding:5px 0;word-wrap: break-word;">' + item.tweet + '<p style="font-size:10px; color:#FF9900;">'+item.add_time+'</p></li>');

	}
function TTURLEncodesamp(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;}
	
function TTURLDecode(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
