var userId,followerid,blogid,action,divid;
var serverURL	=	"http://www.pokertwitter.com/";
///-------------------------------------------------------------------------------
//callings for the users area

function getFollowDeleteConfirmUser(userId,followerid,action,divid)
{
	var result	=	confirm('Are you sure you want to quit following this user?');
	if (result)
	{
		followuser(0,followerid,2,divid);
	}
	
	
}
//callings for the users area
function updateAddFollowUserDiv(userId,followerid,action,divid)
{
	if (action	==	1)//means added
	{
		document.getElementById("div"+divid).innerHTML =	'<a href="javascript:void(null);" onclick="getFollowDeleteConfirmUser(0,'+followerid+',1,'+divid+');" onmouseover="document.follow_usr_button.src=\'images/Remove_b.png\'" onmouseout="document.follow_usr_button.src=\'images/Remove_a.png\'" title="Remove"><img src="images/Remove_a.png" name="follow_usr_button" border="0" /></a>';							
	}
	else
	{
//		document.getElementById("div"+divid).innerHTML ='<input type="image" src="images/folllow.png" name="Submit" value="Follow" onclick="followuser(0,'+followerid+',1,'+divid+');" />';
		document.getElementById("div"+divid).innerHTML ='<a href="javascript:void(null);" onclick="followuser(0,'+followerid+',1,'+divid+');" onmouseover="document.follow_usr_button.src=\'images/folllow_b.png\'" onmouseout="document.follow_usr_button.src=\'images/folllow_a.png\'" title="Follow"><img src="images/folllow_a.png" name="follow_usr_button" border="0" /></a>';
	}
}

///-------------------------------------------------------------------------------
///-------------------------------------------------------------------------------
//callings for the blogs area
function getFollowDeleteConfirm(userId,followerid,action,divid)
{
	var result	=	confirm('Are you sure you want to quit following this user?');
	if (result)
	{
		followuserfromblog(0,followerid,2,divid);
	}
	
}
//callings for the blogs area
function updateAddFollowDiv(divid,userId,followerid,action)
{
	if (action	==	1)//means added
	{
		document.getElementById("div"+divid).innerHTML ='<a href="javascript:void(null);" class="style6" onclick="getFollowDeleteConfirm(0,'+followerid+',1,'+divid+');" title="Unfollow"><img src="images/followuser_active.png" alt="Follow" border="0"></a>';
	}
	else
	{
		document.getElementById("div"+divid).innerHTML ='<a href="javascript:void(null);" class="style6" onclick="followuserfromblog(0,'+followerid+',1,'+divid+');" title="Follow"><img src="images/followuser.png" alt="Follow" border="0"></a>';
	}
}

function GetXmlHttpObject_Rem()
{
   var xmlHttp_Rem = null;
   try
   {
      // Firefox, Opera 8.0+, Safari
      xmlHttp_Rem = new XMLHttpRequest();
   }
   catch (e)
   {
      //Internet Explorer
      try
      {
          xmlHttp_Rem = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
         xmlHttp_Rem = new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   
   return xmlHttp_Rem;
}
//--------------update online record---------
function getRegions(ncountryname)
{ 
	document.getElementById("divcity").innerHTML =	'<select name="city1" id="city1" class="input"><option value="">Select City</option></select>';
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceWorld.php";
   //url = url + "?q=" + s_id;
   url = url + "?sid="+Math.random()+"&action=1&countryname="+ncountryname;
   
   xmlHttp_Rem.onreadystatechange = stateRegionGenerate; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
}
function getRegionsAdmin(ncountryname)
{ 
	document.getElementById("divcity").innerHTML =	'<select name="city1" id="city1" class="input"><option value="">Select City</option></select>';
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "../../service/serviceWorld.php";
   //url = url + "?q=" + s_id;
   url = url + "?sid="+Math.random()+"&action=3&countryname="+ncountryname;
   
   xmlHttp_Rem.onreadystatechange = stateRegionGenerate; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
}

function stateRegionGenerate() 
{ 
   if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
	   var strOutput=String(xmlHttp_Rem.responseText);
		document.getElementById("divregion").innerHTML=strOutput;
   } 
   else
   {
		document.getElementById("divregion").innerHTML = "<img src='images/loader.gif'/>";
	}

}
//--------------update online record---------
function getCities(ncountryname,nregionid)
{ 
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceWorld.php";
   //url = url + "?q=" + s_id;
   url = url + "?sid="+Math.random()+"&action=2&countryname="+ncountryname+"&regionid="+nregionid;
   
   xmlHttp_Rem.onreadystatechange = stateCityGenerate; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
}
function getCitiesAdmin(ncountryname,nregionid)
{ 
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "../../service/serviceWorld.php";
   //url = url + "?q=" + s_id;
   url = url + "?sid="+Math.random()+"&action=2&countryname="+ncountryname+"&regionid="+nregionid;
   
   xmlHttp_Rem.onreadystatechange = stateCityGenerate; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
}

function stateCityGenerate() 
{ 
   if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
	   var strOutput=String(xmlHttp_Rem.responseText);
		document.getElementById("divcity").innerHTML=strOutput;
   } 
   else
   {
		document.getElementById("divcity").innerHTML = "<img src='images/loader.gif'/>";
	}

}

//--------------update online record---------
function updateOnlineRecord()
{ 
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceAjaxUpdate.php";
   //url = url + "?q=" + s_id;
   url = url + "?sid=" + Math.random();
   
   xmlHttp_Rem.onreadystatechange = stateChanged_Rem; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
   
   setTimeout('updateOnlineRecord()', 30000);
}

function stateChanged_Rem() 
{ 
	   var strOutput;
	   var splitArray;
	   var blogsfollowcount;
	   var blogsfollowbycount;
	   var followuseronline;
	   var followbyuseronline;
	   var blogcountfollow;
	   var blogcountfollowby;
	   var adminmessage;
	   var myblogs;
	   var myreplies;


	if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
   	if (xmlHttp_Rem.status == 200)
	{
	 strOutput=String(xmlHttp_Rem.responseText);
	 splitArray=strOutput.split("-");
	 try{
	 blogsfollowcount=splitArray[0];
	 }
	 catch(e){
		 alert ('exception');
		 }
	 blogsfollowbycount=splitArray[1];
	 followuseronline=splitArray[2];
	 followbyuseronline=splitArray[3];
	 blogcountfollow=splitArray[4];
	 blogcountfollowby=splitArray[5];
	 adminmessage=splitArray[6];
	 myblogs=splitArray[7];
	 myreplies=splitArray[8];
	   if(blogsfollowcount=="")
	   	blogsfollowcount=0;
	   if(blogsfollowbycount=="")
	   	blogsfollowbycount=0;
	   if(followuseronline=="")
	   	followuseronline=0;
	   if(followbyuseronline=="")
	   	followbyuseronline=0;
	   if(blogcountfollow=="")
	   	blogcountfollow=0;
	   if(blogcountfollowby=="")
	   	blogcountfollowby=0;
	   if(adminmessage=="")
	   	adminmessage=0;
	   if(myblogs=="")
	   	myblogs=0;
	   if(myreplies=="")
	   	myreplies=0;

	   try{
	   document.getElementById("blogsfollowcount").innerHTML=blogsfollowcount;
	   }catch(e){document.getElementById("blogsfollowcount").innerHTML="";}
	   try{
	   document.getElementById("blogsfollowbycount").innerHTML=blogsfollowbycount;
	   }catch(e){document.getElementById("blogsfollowbycount").innerHTML="";}
	   try{
	   document.getElementById("followuseronline").innerHTML=followuseronline;
	   }catch(e){document.getElementById("followuseronline").innerHTML="";}
	   try{
   	   document.getElementById("followbyuseronline").innerHTML=followbyuseronline;
	   }catch(e){document.getElementById("followbyuseronline").innerHTML="";}
	   try{
	   document.getElementById("blogcountfollow").innerHTML=blogcountfollow;
	   }catch(e){document.getElementById("blogcountfollow").innerHTML="";}
	   try{
	   document.getElementById("blogcountfollowby").innerHTML=blogcountfollowby;
	   }catch(e){document.getElementById("blogcountfollowby").innerHTML="";}
	   try{
	   document.getElementById("adminmessage").innerHTML=adminmessage;
	   }catch(e){document.getElementById("adminmessage").innerHTML="";}
	   
	   	if (adminmessage	!=	"0")
		{
			document.getElementById("EmailImage").src	=	serverURL+"images/adminemail.jpg";
			document.getElementById("EmailImage").alt	=	"Admin Messages";
			document.getElementById("EmailImageLink").href	=	serverURL+"?filename=adminmessages.php";
		}
		else
		{
//			alert (document.getElementById("EmailImage").src);	
			document.getElementById("EmailImage").src	=	serverURL+"images/email.jpg";
			document.getElementById("EmailImage").alt	=	"User Emails";
			document.getElementById("EmailImageLink").href	=	serverURL+"?blogtype=mine";
			
		}
	   document.getElementById("myblogs").innerHTML=myblogs;
	   document.getElementById("myreplies").innerHTML=myreplies;
	}
   } 
}

//-------------remove entry------------------
function removeEntry()
{ 

   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceRemoveEntry.php";
   //url = url + "?q=" + s_id;
   url = url + "?sid=" + Math.random();
   
   xmlHttp_Rem.onreadystatechange = stateChanged_Remove; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
   

}
function stateChanged_Remove() 
{ 
   if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
	   //alert(xmlHttp_Rem.responseText);
   } 
}


//--------------------------follow user-----------------------
function followuser(nUserId,nFollowerId,strAction,strDivid)
{ 
	
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceFollowUsers.php";
   url = url + "?userid=" + nUserId;
   url = url + "&followerid=" + nFollowerId;
   url = url + "&action=" + strAction;
   url = url + "&sid=" + Math.random();
   
	userId	=	nUserId;
	followerid=	nFollowerId;
	action	=	strAction;
	divid	=	strDivid;
	xmlHttp_Rem.onreadystatechange = callBackFollowUser; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
   
}

function callBackFollowUser() 
{ 
   if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
	   //alert(xmlHttp_Rem.responseText);
	   if (xmlHttp_Rem.responseText	==	"Added.")
	   {
	   	   document.getElementById("div"+divid).innerHTML ="<span class='cssSuccess'>"+xmlHttp_Rem.responseText+"</span>";
	    setTimeout('updateAddFollowUserDiv("'+userId+'","'+followerid+'","'+action+'","'+divid+'")', 3000);
	   }
	   else if (xmlHttp_Rem.responseText	==	"Please log in first")
	   {
		   document.getElementById("div"+divid).innerHTML ="<span class='cssNotSuccess'>"+xmlHttp_Rem.responseText+"</span>";
		}
	   else
	   	{
		   document.getElementById("div"+divid).innerHTML ="<span class='cssSuccess'>"+xmlHttp_Rem.responseText+"</span>";
	    setTimeout('updateAddFollowUserDiv("'+userId+'","'+followerid+'","'+action+'","'+divid+'")', 3000);
		}
	   
   } 
   else
   {
	   document.getElementById("div"+divid).innerHTML = "<img src='images/loader.gif'/>";
	}
}
//--------------------------follow user from blog area-----------------------
function followuserfromblog(nUserId,nFollowerId,strAction,nBlogId)
{ 
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceFollowUsers.php";
   url = url + "?userid=" + nUserId;
   url = url + "&followerid=" + nFollowerId;
   url = url + "&action=" + strAction;
   url = url + "&sid=" + Math.random();
   
	blogid	=	nBlogId;
	userId	=	nUserId;
	followerid=	nFollowerId;
	action	=	strAction;

	xmlHttp_Rem.onreadystatechange = callBackFollowUserFromBlog; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
   
}

function callBackFollowUserFromBlog() 
{ 
   if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
	   //alert(xmlHttp_Rem.responseText);
	   if (xmlHttp_Rem.responseText	==	"Added.")
	   {
	   	   document.getElementById("div"+blogid).innerHTML ="<span class='cssSuccess'>"+xmlHttp_Rem.responseText+"</span>";
			
			//alert (userId);
		    setTimeout('updateAddFollowDiv("'+blogid+'","'+userId+'","'+followerid+'","'+action+'")', 3000);
	   }
	   else if (xmlHttp_Rem.responseText	==	"Please log in first")
	   {
	   	   document.getElementById("div"+blogid).innerHTML ="<span class='cssNotSuccess'>"+xmlHttp_Rem.responseText+"</span>";
	   }
	   else
	   	{
		   document.getElementById("div"+blogid).innerHTML ="<span class='cssSuccess'>"+xmlHttp_Rem.responseText+"</span>";
		    setTimeout('updateAddFollowDiv("'+blogid+'","'+userId+'","'+followerid+'","'+action+'")', 3000);
		}
	   
   } 
   else
   {
	   document.getElementById("div"+blogid).innerHTML = "<img src='images/loader.gif'/>";
	}
}



//--------------------------performUserAdminMessage-----------------------
function performUserAdminMessage(messageid,userid,action)
{ 
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceAdminMessages.php";
   url = url + "?userid=" + userid;
   url = url + "&messageid=" + messageid;
   url = url + "&action=" + action;
   url = url + "&sid=" + Math.random();
   
	userId	=	messageid;

	xmlHttp_Rem.onreadystatechange = callBackPerformUserAdminMessage; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
   
}

function callBackPerformUserAdminMessage() 
{ 
   if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
	   //alert(xmlHttp_Rem.responseText);
	   if (xmlHttp_Rem.responseText	==	"Added.")
	   {
	   	   document.getElementById("div"+userId).innerHTML ="<span class='cssSuccess'>"+xmlHttp_Rem.responseText+"</span>";
	   }
	   else
	   	{
		   document.getElementById("div"+userId).innerHTML ="<span class='cssNotSuccess'>"+xmlHttp_Rem.responseText+"</span>";
		}
	   
   } 
   else
   {
	   document.getElementById("div"+userId).innerHTML = "<img src='images/loader.gif'/>";
	}
}
///////////////////////////////////-------
/////Update Status Message
//--------------update online record---------
function updateOnlineStatus()
{ 
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceStatusUpdate.php";
   url = url + "?q=" + document.getElementById("txtStatus").value;
   url = url + "&sid=" + Math.random();
   
   xmlHttp_Rem.onreadystatechange = stateChanged_Status; 

   xmlHttp_Rem.open("GET", url, true);
   xmlHttp_Rem.send(null);
}
function updateStatusDiv()
{
	document.getElementById("img").innerHTML = "";
}
function stateChanged_Status() 
{ 
   if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
	  document.getElementById("txtStatus").value=xmlHttp_Rem.responseText;	  
	  document.getElementById("img").innerHTML = "Updated!";
	  setTimeout('updateStatusDiv()', 3000);	
   }else{
	   document.getElementById("img").innerHTML = "<img src='images/loader.gif'/>";
   } 
}
function setImage(imgData,serverpath)
{
	//alert (imgData.src);	
	imgData.src	=	serverpath+"images/user.jpg";
}
function RemoveErrorMsg()
{
	document.getElementById("errMsgDiv").innerHTML = "&nbsp;";
}
function RemoveError()
{
	setTimeout('RemoveErrorMsg()', 3000);	
}
//
function registerSessionOnTopMsgClose()
{ 
  xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceTopMsg.php";
   
	//xmlHttp_Rem.onreadystatechange = 0; 
	
	xmlHttp_Rem.open("GET", url, true);
	xmlHttp_Rem.send(null);
   
}

//--------------------------validate pin code-----------------------
function validatePinCode()
{ 
	strPinCode	=	document.getElementById("pinCode").value;
   xmlHttp_Rem = GetXmlHttpObject_Rem();
   
   var url = "service/serviceUser.php";
   url = url + "?pinCode=" + strPinCode;
   url = url + "&sid=" + Math.random();
   
	xmlHttp_Rem.onreadystatechange = callBackValidatedPinCode; 
	
	xmlHttp_Rem.open("GET", url, true);
	xmlHttp_Rem.send(null);
   
}

function callBackValidatedPinCode() 
{ 
   if(xmlHttp_Rem.readyState == 4 || xmlHttp_Rem.readyState == "complete")
   { 
	   //alert(xmlHttp_Rem.responseText);
	   if (xmlHttp_Rem.responseText	==	"Verified")
	   {
		   document.getElementById("ispingenerated").style.display = "block";
		   document.getElementById("loaderispingenerated").style.display = "none";
		   document.getElementById("wrongispingenerated").style.display = "none";
		   document.getElementById("ispingenerated").innerHTML = "<font color='red'>Successfully! registered with phone.</font>";
		   alert (document.getElementById("cellphone").readOnly);
		   document.getElementById("cellphone").readOnly	=	true;
		   document.getElementById("country_code").readOnly	=	true;
		   
		   
		   
//			document.getElementById("div"+blogid).innerHTML ="<span class='cssSuccess'>"+xmlHttp_Rem.responseText+"</span>";
			
			//alert (userId);
//		    setTimeout('updateAddFollowDiv("'+blogid+'","'+userId+'","'+followerid+'","'+action+'")', 3000);
	   }
	   else if (xmlHttp_Rem.responseText	==	"Not Verified")
	   {
		   document.getElementById("ispingenerated").style.display = "block";
		   document.getElementById("loaderispingenerated").style.display = "none";
		   document.getElementById("wrongispingenerated").style.display = "block";
		   
	   }
/*	   else
	   	{
		   document.getElementById("div"+blogid).innerHTML ="<span class='cssSuccess'>"+xmlHttp_Rem.responseText+"</span>";
		    setTimeout('updateAddFollowDiv("'+blogid+'","'+userId+'","'+followerid+'","'+action+'")', 3000);
		}
*/		
	   
   } 
   else
   {
	   document.getElementById("loaderispingenerated").style.display = "block";
	   document.getElementById("wrongispingenerated").style.display = "none";
	   document.getElementById("ispingenerated").style.display = "none";
	   
	}
}

function submitPinPopup()
{
	try{
	document.getElementById("").value	=	'Yes';
	}
	catch (e){
		}
	document.getElementById("edit").submit();
}
function resetPinCode()
{
	if (document.getElementById("pinCode").value	==	"enter PIN")
	{
		document.getElementById("pinCode").value	=	"";
	}
		
}

function openValidateWindow(validateWindow)
{
	if (validateWindow	==	undefined)
	{
		if (!isValidInt(document.add.cellphone.value))
		{
			if (document.add.cellphone.value	!=	"")
			{
				//alert("Please provide correct cell phone.");
				document.add.cellphone.focus();
				return;
			}
		}
		
		url	=	'popup.php?country_code='+document.getElementById('country_code').value+'&cellphone='+document.getElementById('cellphone').value;
	}
	else if (validateWindow	==	"newNumber")
	{
		url	=	'popup.php?newnumber=yes';
	}
	else
	{
		url	=	'popup.php';
	}
	
	window.open(url, 'popup', 'width=525, height=400, scrollbars=no, resizable=no, toolbar=no, directories=no, location=no, menubar=no, status=no, left=0, top=0');
}
function openInfoWindow(validateWindow)
{
	if(validateWindow=="fb")
	{
		url	=	'popupinfo.php?info=fb';
	}
	else if (validateWindow	==	"iphone")
	{
		url	=	'popupinfo.php?info=iphone';
	}
	else if (validateWindow	==	"widget")
	{
		url	=	'popupinfo.php?info=widget';
	}
	
	window.open(url, 'popup', 'width=525, height=400, scrollbars=no, resizable=no, toolbar=no, directories=no, location=no, menubar=no, status=no, left=0, top=0');
}

function showPopupDisplay(divid,type)
{
	var popupType	;
	if (type	==	0)
	{
	popupType	=	"usertweet"+divid;
	}
	else if (type==1)//following
	popupType	=	"following"+divid;
	else if (type==2)//followers
	popupType	=	"followers"+divid;
	else if (type==3)//following on user page
	popupType	=	"followinguser"+divid;
	else if (type==4)//follower on user page
	popupType	=	"followersuser"+divid;
	
	
	var posY	=	findPosY(document.getElementById("imgfollow_"+popupType))-160;
	document.getElementById("popup_"+popupType).style.top	=	posY+"px"
	
	var posX	=	findPosX(document.getElementById("imgfollow_"+popupType))-27;
	document.getElementById("popup_"+popupType).style.left	=	posX+"px";	
	document.getElementById("popup_"+popupType).style.display	=	"block";
	
}
function hidePopupDisplay(divid, type)
{
	var popupType;
	if (type	==	0)
	{
	popupType	=	"usertweet"+divid;
	}
	else if (type==1)//following
	popupType	=	"following"+divid;
	else if (type==2)//followers
	popupType	=	"followers"+divid;
	else if (type==3)//following on user page
	popupType	=	"followinguser"+divid;
	else if (type==4)//follower on user page
	popupType	=	"followersuser"+divid;
//	alert (popupType);
	document.getElementById("popup_"+popupType).style.display	=	"none";	
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
function swapFollowButton(strMode, strname)
{
	if (strMode	==	1)
	{
			
		document.getElementById("follow_"+strname).src	=	"images/followuser_hover.png";
	}
	else if (strMode	==	2)
	{
		document.getElementById("follow_"+strname).src	=	"images/followuser.png";
	}
}
function swapUnFollowButton(strMode, strname)
{
	if (strMode	==	1)
	{
			
		document.getElementById("follow_"+strname).src	=	"images/followuser_active_hover.png";
	}
	else if (strMode	==	2)
	{
		document.getElementById("follow_"+strname).src	=	"images/followuser_active.png";
	}
}


///////////////////////////////////-------
