/***********************************************************************
FileName        :jchangestatus.js
Description     :Changestatus Javascript
Created By      :EMP-077
Created Date    :13-06-2007
***********************************************************************/

function change_status()
{
/*	if(document.getElementById('status_1'))
	{*/
		var url = SITE_AJAX_URL+"change_status.php";
		//alert(url);
		var isWorking = false;
		if (!isWorking)
		{ 
				isWorking = true;		
				if (window.XMLHttpRequest)
			  	{
			  		http_change_status=new XMLHttpRequest()
			  		http_change_status.open("GET",url, true);
				  	http_change_status.onreadystatechange=handleHttpResponseChangeStatus
				  	http_change_status.send(null)
			  	}
				// code for IE
				else if (window.ActiveXObject)
			  	{
			  		http_change_status=new ActiveXObject("Microsoft.XMLHTTP")
			    	if (http_change_status)
			    	{
			    		http_change_status.open("GET",url, true);
			    		http_change_status.onreadystatechange=handleHttpResponseChangeStatus
			    		http_change_status.send();
			    	}
			  	}
	  	}//end if(!working))
		//if(!displayPopup)	closeLoadingWindow(winObj);
	//}
}
function handleHttpResponseChangeStatus()
{
		var temp;
		temp="";
		var temp1;
		temp1="";
		var iid;
		var tmp_color;//alert(http_state_Member.readyState);
		if (http_change_status.readyState == 4)
		{
			//alert(http_change_status.responseText);return false;
			var xmlDocument = http_change_status.responseXML;
			var no = xmlDocument.getElementsByTagName('count').item(0).firstChild.data;
			var p_site_images = xmlDocument.getElementsByTagName('siteimages').item(0).firstChild.data;
			var p_site_url = xmlDocument.getElementsByTagName('siteurl').item(0).firstChild.data;
			var p_sess_memberid = xmlDocument.getElementsByTagName('sessmemberid').item(0).firstChild.data;
			var p_index = xmlDocument.getElementsByTagName('index').item(0).firstChild.data;
			var p_tokenbal = xmlDocument.getElementsByTagName('tokenbal').item(0).firstChild.data;
			for(j=0;j<document.getElementsByTagName('div').length;j++)
			{
				div=document.getElementsByTagName('div').item(j).id;
				div=div.split("_"); 
				if(div[0]=="status" || div[0]=="communication")
				{
					for(i=0;i<no;i++)
					{					
						var p_iMemberId=xmlDocument.getElementsByTagName('imemberid').item(i).firstChild.data;
						var p_online=xmlDocument.getElementsByTagName('eonline').item(i).firstChild.data;
						var p_onlinestatus=xmlDocument.getElementsByTagName('eonlinestatus').item(i).firstChild.data;
						var p_iMemProfileId=xmlDocument.getElementsByTagName('memberprofileid').item(i).firstChild.data;
						var p_spanId=document.getElementsByTagName('div').item(j).id;
						//alert(p_sess_memberid);
						if(document.getElementById('communication_'+p_iMemberId) && div[0]=="communication")
						{
							var p_video=xmlDocument.getElementsByTagName('video').item(i).firstChild.data;
							var p_text=xmlDocument.getElementsByTagName('text').item(i).firstChild.data;
							var p_voice=xmlDocument.getElementsByTagName('voice').item(i).firstChild.data;
						}
						if("communication_"+p_iMemberId==p_spanId && div[0]=="communication" && p_onlinestatus=="Online" && p_online== "1")
						{
								if (p_text=="1")
										temp1+="<img align='absmiddle' src='"+p_site_images+"chat-icon.gif' border='0' />Text&nbsp;|&nbsp;";
								if(p_voice=="1")
						  			temp1+="<img align='absmiddle' border='0' src='"+p_site_images+"audio-icon.gif' />Voice&nbsp;|&nbsp;";
						  		if(p_video=="1")
									temp1+="<img align='absmiddle' border='0' src='"+p_site_images+"video-icon.gif' />Video";
						}
						if("status_"+p_iMemberId==p_spanId)
						{
							if(p_online=="1" || p_onlinestatus != 'Offline')
							{
									temp="<img align='absmiddle' src='"+p_site_images+"Online-icon.gif'/>";
									if(p_sess_memberid != "0")
									{
										if(p_sess_memberid != p_iMemberId)
										{
											if(p_onlinestatus != 'Offline')
											{
												temp+="<a href='javascript://' class='greenmatterbig' 	onclick=\"window.open('"+p_site_url+"gcChatApp.php?iMemProfileId="+p_iMemProfileId+"&iExpertId="+p_iMemberId+"','customerChatApp','toolbar=no,resizable=no,scrollbars=No,width=800, height=550,left=200,top=80'); return false;\">Chat Now</a>";
											}
											else
											{
												temp+="<a title='Online, (but not available to chat).'> Online</a>";
											}
										}
										else
										{
													temp+="<a title='Online, (but not available to chat).'> Its you.</a>";
										}
									}
									else
									{
											if (p_onlinestatus != 'Offline')
											{
												temp+="<a href='"+p_site_url+p_index+"?file=c-signin'> Chat Now</a>";
											}
											else
											{
												temp+="<a title='Online, (but not available to chat).'> Online</a>";
											}
									}
							}
							else
							{
									temp+="<img align='absmiddle' src='"+p_site_images+"Offline-icon.gif'/>";
									temp+="<span> Offline</span>";
							}
							iid='status_'+p_iMemberId;
							document.getElementById(iid).innerHTML="";
							document.getElementById(iid).innerHTML=temp;
							if(document.getElementById('tokenbal'))
								document.getElementById('tokenbal').innerHTML=p_tokenbal;
							temp="";
							
						}
						if(document.getElementById('communication_'+p_iMemberId)  && div[0]=="communication" && p_onlinestatus=="Online" && p_online=="1")
						{
							if("communication_"+p_iMemberId==p_spanId)
							{
								//alert(temp1);
								iid1='communication_'+p_iMemberId
								document.getElementById(iid1).innerHTML="";
								document.getElementById(iid1).innerHTML=temp1;
								temp1="";
							}
						}						
					}
				}
			}
		}
}


function funchngpword()
{	
	if(!checkValidNull(document.getElementById('vCurrentPassword'),"Please Enter  Current Password"))
       return false;

	if(!checkValidNull(document.getElementById('vNewPassword'),"Please Enter  New Password"))
       return false;
	if(!checkValidLength(document.getElementById('vNewPassword'),4,"Please Enter New Password Length Should be greaterthan 4 characters"))
			return false;  
	if(!checkValidNull(document.getElementById('vRetypePassword'),"Please Enter Retype Password"))
       return false;
   	
	if(document.getElementById('vNewPassword').value!=document.getElementById('vRetypePassword').value)
	{
				  alert("New Password & Retype Password Must Be Same ");
				  document.getElementById('vRetypePassword').focus();
			   	  return false;
	}
}
   	/*
	if(document.getElementById('vCurrentPassword').value!=document.getElementById('current_password').value)
	{
	   alert("Please Enter Correct Curent Password");
	   document.getElementById('vCurrentPassword').focus();
	   return false;
	}
	*/
	
	/* AJAX Script */
		/*
		var url=AJAX_URL+"/ajaxfiles/userValidation.php?";
		url+="way=changepassword&formcurrentpassword="+document.getElementById('vCurrentPassword').value;
		alert(url);
		if(window.XMLHttpRequest)
		{
			http_validate=new XMLHttpRequest()
		  	http_validate.open("GET",url, true)
			http_validate.onreadystatechange=handleHttpResponse_validate;
			http_validate.send(null)
		}
		// code for IE
		else if (window.ActiveXObject)
		{
			http_validate=new ActiveXObject("Microsoft.XMLHTTP")
			if (http_validate)
			{
				http_validate.open("GET",url, true);
				http_validate.onreadystatechange=handleHttpResponse_validate;
				http_validate.send()
			}
		}
	*/
		
 /* End AJAX Script */	

//end function 	


/*
function handleHttpResponse_validate()
{
	//alert(http_validate.readyState);
	if (http_validate.readyState == 4)
	{
		isWorking = false;
		//alert(http_validate.responseText);
		if (http_validate.responseText.indexOf('invalid') == -1)
		{
			var xmlDocument = http_validate.responseXML;
			//alert(xmlDocument); 
			var currentpwordstatus=xmlDocument.getElementsByTagName('currentpwordstatus').item(0).firstChild.data;
			if(currentpwordstatus=="0")
			{
			  	   alert("Please Enter Correct Curent Password");
				   document.getElementById('vCurrentPassword').focus();
				   return false;
			}
		}//end if responsetext
	}//end if state==4
}//end function	
*/
