// Global Functions for all Spikr apps

	// Validates Gigya API
	var conf=
		{
			APIKey: '2_5OoiPtjkdFYjhVVKbqR0_Ig66zv50BzjWvIO9D7-z__hnmjDXFewKzr--C-qbk20'
			,enabledProviders: 'facebook,twitter,google,myspace,yahoo,linkedin,aol'
		};
//	var conf = 
//        {
//            APIKey: '2_F2ggHoyTmJunPvHMIVB6G0dlPzDeSQXzEz14uRqLdXYHWyeu0w-XAN3Ey2Zwol3m',
//            enabledProviders:'facebook,myspace,twitter,google,yahoo,aol'
//        };
        function onLoad()
        {
            // show connect UI in "divConnect"
			gigya.services.socialize.showConnectUI(conf,connect_params,{containerID:"divConnect",useFacebookConnect : true});
			// get user info
            gigya.services.socialize.getUserInfo(conf,{callback:renderUI});	    
            // register for connect status changes
            gigya.services.socialize.addEventHandlers(conf, { onConnect:renderUI, onDisconnect:renderUI }   ); 
        }

	// Retrieve elements from social feeds and renders UI
		function renderUI(res)
		{
                 if (res.user!=null && res.user.isConnected)  
                 {  
				  document.getElementById("name").innerHTML = res.user.nickname;  
                  document.getElementById("photo").src = res.user.thumbnailURL;  
                  document.getElementById("profile").style.display="block";
				  document.getElementById("loginFirstAlert").style.display="none";
				  document.getElementById("btnUpdateStatus").className="updateButton";
				  document.getElementById("btnUpdateStatus").disabled=false;
                 } else{  
                        document.getElementById("profile").style.display="none";  
                 }
				 //	to disable or do anything with the update button if user is not connected
				 if (res.user==null || !res.user.isConnected)
				 {
				   document.getElementById("btnUpdateStatus").className="updateButtonDisabled";
				   document.getElementById("btnUpdateStatus").disabled=true;
				   document.getElementById("loginFirstAlert").style.display="block";
                 }
			 
		}
		// Updates user status
		
         function setStatus() 
         {
			 var params =   
             {  
                 status: document.getElementById("gigya-socialize-update-text").value,  
                 callback:setStatus_momo,  
                 useFacebookConnect : true  
             };    
             gigya.services.socialize.setStatus(conf, params);  
         }  
   
         // Display a status message according to the response from reportAction.  
         function setStatus_momo(response)
		 {
   			// alert("i'm inside the callback");
			 switch (response.status)  
             {  
				 case 'OK':   
                     document.getElementById('status').innerHTML = '<span style="color:green;">New Status updated:</span><br><span style="color:#666666; font-size:9px;">' + document.getElementById("gigya-socialize-update-text").value; + '</span>'
					 document.getElementById("gigya-socialize-update-text").style.color = "red";
                     document.getElementById("gigya-socialize-update-text").value = "What are you doing right now?";  
                     break;  
                 default:  
                     document.getElementById('status').style.color = "red";  
                     document.getElementById('status').innerHTML = "Oy Vey! Something went caput here! Please try again. Disconnecting or reconnecting one or all social networks may do the trick.<br>If not, please <a href='/contact'>let us know!</a> so that we can fix it. Sorry! Error code:" + response.status;  
             }  
        } 
		
	// Prevents conflicts of different types of jQuery and AJAX scripts to prioritize on Gigya services 
		if( typeof( jQuery ) != 'undefined' && typeof( gigya ) != 'undefined' ) {
			jQuery(document).ready(function() { jQuery('#gigya-socialize-widget-content').show(); });
		}
		
	// Counts characters on typing
		<!--
		maxKeys = 140;
            var IE = (document.all) ? 1 : 0;
            var DOM = 0; 
            if (parseInt(navigator.appVersion) >=5) {DOM=1};
        function txtshow( txt2show ) {
            // Detect Browser
            if (DOM) {
		var viewer = document.getElementById("counter");
                viewer.innerHTML=txt2show;
            }
            else if(IE) {
                document.all["counter"].innerHTML=txt2show;
            }
        }
		function messageCounter(what) 
		{
		  var str = new String(what.value);
		  var len = str.length;
		  // Writes into the 'counter' span
		  var showstr = + len ;
		  // Produces a warning if user goes over 140 characters
		  if (len > maxKeys) showstr += '<div class="counterWarning">Twitter and SMS on some mobile devices limit messages to 140 Characters. Consider editing and URL shortning</div>';
		  txtshow( showstr );
		}
		//-->