
	/*************ajax function for counting clicks of facebook Like/unlike button ****************/ 
	var objXmlHttp  //a globle variable

	//initiate a xmlhttprequest object
	function GetHttpObject(){
		var objReq;
		try {
			 objReq = new XMLHttpRequest();
		}
		catch (error){
			try {
				objReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (error){  
				try {    
				    objReq = new ActiveXObject("Msxml2.XMLHTTP");  
				}
					catch (error){
						alert("Your browser does not support AJAX. Please upgrade it to a newer version.");
						return false;
					}
			}
		}
		objReq.onreadystatechange=function(){
			if (objReq.readyState==4 || objReq.readyState=="complete"){
				if (objReq.status==200){ 
					//DO NOTHING;
					//document.getElementById('testFB').innerHTML=objReq.responseText
				}
				else{ 
					//document.getElementById('testFB').innerHTML="There was a problem while using XMLHTTP:\n" + objReq.statusText; //just for debug use. delete this line after finish
					alert("There was a problem while using XMLHTTP:\n" + objReq.statusText);
				}		
			}
		}
		return objReq;
	}
	
	/*****************call from counting the facebook Like button  *********************/
	function fbLikeCounter(str,type) //argument str is the URL where Like is cliked
	{
		var qStr=str;
		//alert(qStr);
		objXmlHttp=GetHttpObject();
		//alert(svrName);
		objXmlHttp.open("GET", "http://"+svrName+"/fbLikeCounter.cfm?href="+qStr+"&type=" +type + "&dummy=" + new Date().getTime(), true); //the dummy parameter is to avoid using cache data
		objXmlHttp.send(null);
	}
						
/*********counting click of facebook Like button*******************/				
window.fbAsyncInit = function() {
	 FB.init({appId: '118647714913665', status: true, cookie: true, xfbml: true}); //this is for production site
	 //FB.init({appId: '127947150632108', status: true, cookie: true, xfbml: true}); //this is for dev site
	 
	 //clicked like
	 FB.Event.subscribe('edge.create', function(href) {
		 // Do something, e.g. track the click on the "Like" button here
		 //alert('You just liked '+href);
		 fbLikeCounter(href, 'like');
	 });
	 
	 //clicked dislike
	 FB.Event.subscribe('edge.remove', function(href) {
		 // Do something, e.g. track the click on the "Like" button here
		 //alert('You just disliked '+href);
		 fbLikeCounter(href,'unlike');
	 });			 
};

(function() {
 var e = document.createElement('script');
 e.type = 'text/javascript';
 e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
 e.async = true;
 document.getElementById('fb-root').appendChild(e);
 }());

