function memberLogin()
{
    if($('txtUsername').value=='')
    {
        alert(RES['L1']);
        $('txtUsername').focus();
    }
    else if($('txtPassword').value=='')
    {
        alert(RES['L2']);
        $('txtPassword').focus();
    }
    else
    {
        $('lbnLogin').innerHTML='Loading...';
        
        var xmlHttp=createXmlHttp();
	
	    xmlHttp.open("Get","AJAX/MemberLogin.ashx?U="+escape($('txtUsername').value)+"&P="+escape($('txtPassword').value),true);
    	
	    xmlHttp.onreadystatechange=function()
	    {
		    if(xmlHttp.readyState==4)
		    {
			    var temp=xmlHttp.responseText;
			    
			    if(temp=="L3")
			    {
			        alert(RES['L3']);
			        $('lbnLogin').innerHTML='Submit';
                    $('txtUsername').focus();
			    }
			    else if(temp=="L4")
			    {
			        alert(RES['L4']);
			        $('lbnLogin').innerHTML='Submit';
                    $('txtUsername').focus();
			    }
			    else if(isInt(temp))
			    {
			        location.href='Profile.aspx?id='+temp;
			    }
		    }
	    }
    	
	    xmlHttp.send(null);
    }
}

function focusTxt(el,txt)
{
	if(el.value==txt)
		el.value='';
}
function blurTxt(el,txt)
{
	if(el.value=='')
		el.value=txt;
}

function selectSingle(el,els)
{
    for(i=0;i<els.length;i++)
    {
        els[i].checked=false;
    }
    el.checked=true;
}

function changeVerifyImg()
{
    $('VerifyImg').src='VerifyCode.aspx?T='+(new Date()).getTime();
}

function isInt(s)
{
	if(s.search(/^[0-9]+$/)!=-1)
		return true;
	else
		return false;
}

function handerAllCheck(name,f)
{
    var frm=document.forms[0];
    for(i=0;i<frm.length;i++)
    {
        e=frm.elements[i];
        if(e.type=='checkbox'&&e.name.indexOf(name)!=-1)
        {
            e.checked=f;
        }
    }
}

function updateOnline()
{
    runAJAX('AJAX/MemberUpdateOnline.ashx',null);
    setTimeout('updateOnline()',5000);
}

function getOnline()
{
    runAJAX('AJAX/MemberOnline.ashx',$('OnlineMembers'));
    setTimeout('getOnline()',5000);
}

function listenChat(sender)
{
    
    if(sender=='')
        return;
    else
    {
        $('ChatLinkList').innerHTML="";
        
        var xmlHttp=createXmlHttp();
        
        xmlHttp.open("Get","AJAX/HandleChat.ashx?O=LISTEN&Sender="+sender+'&Temp='+(new Date()).getTime(),true);
    	
        xmlHttp.onreadystatechange=function()
        {
	        if(xmlHttp.readyState==4)
	        {
		        var temp=xmlHttp.responseText;
		        if(temp!="")
		        {
		            var members=temp.split(',');
			        
		            for(i=0;i<members.length;i++)
		            {
			            $('ChatLinkList').innerHTML+="<a href=\"Chat.aspx?r="+members[i]+"\" onclick=\"return hs.htmlExpand(this, { contentId: 'popup-chat', outlineType: 'rounded-skin1', objectType: 'iframe', align: 'center',cacheAjax:true,preserveContent:false} );\"></a>";
		            }
		            
		            for(i=0;i<$('ChatLinkList').getElementsByTagName('A').length;i++)
		            {
		                $('ChatLinkList').getElementsByTagName('A')[i].onclick();
		            }
		        }
	        }
        }
        xmlHttp.send(null);
    }
}

function getHomeBulletin()
{
    runAJAX('AJAX/HomeBulletin.aspx',$('home-bulletin-box'));
    setTimeout('getHomeBulletin()',8000);
}

function searchProfile()
{
    var t=$('t').value;
    var q=escape($('q').value);
    
    location.href='Profiles.aspx?t='+t+'&q='+q;
}

function searchFriend()
{
    var t=$('t').value;
    var q=escape($('q').value);
    
    location.href='Friends.aspx?t='+t+'&q='+q;
}

function searchBlog()
{
    var t=$('t').value;
    var q=escape($('q').value);
    
    location.href='Blogs.aspx?t='+t+'&q='+q;
}

function searchNews()
{
    var t=$('t').value;
    var q=escape($('q').value);
    
    location.href='News.aspx?t='+t+'&q='+q;
}

function searchPodcast()
{
    var t=$('t').value;
    var q=escape($('q').value);
    
    location.href='Podcasts.aspx?t='+t+'&q='+q;
}

function handleReply(e)
{
    $('Reply').style.display=(e=='show')?'':'none';
}

function chatUser(viewId,ownerId)
{
    var xmlHttp=createXmlHttp();
        
    xmlHttp.open("Get","AJAX/GetOnlineUserName.ashx?MemberId="+ownerId+'&Temp='+(new Date()).getTime(),true);
	
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
	        var temp=xmlHttp.responseText;
	        if(temp!=""&&temp.length<20)
	        {
	            $('ChatHolder').innerHTML+="<a href=\"Chat.aspx?r="+temp+"\" onclick=\"return hs.htmlExpand(this, { contentId: 'popup-chat', outlineType: 'rounded-skin1', objectType: 'iframe', align: 'center',cacheAjax:true,preserveContent:false} );\"></a>";
                $('ChatHolder').getElementsByTagName('A')[0].onclick();
	        }
	        else
	        {
	            alert('this member is offline.');
	        }
        }
    }
    xmlHttp.send(null);
}

function blockUser(viewerId,ownerId)
{
    runAJAX('AJAX/BlockUser.ashx?ViewerId='+viewerId+'&OwnerId='+ownerId,null);
    alert('success.');
}


function maxLength(t,n)
{            
    var i=t.value.length;
    //var l=n-i;    
    if(i>=n)
    {
        t.value=t.value.substring(0,n);
        //i=n;
        //l=0;
    }
}

function AddView(objectId, objectType)
{
    runAJAX('AJAX/AddViewCount.ashx?id=' + objectId + '&type=' + objectType, null);
}

function reportAbuse(objectType,objectId,memberId)
{
    if(memberId==0)
        alert('please login.');
    else
    {
        runAJAX('AJAX/ReportAbuse.ashx?ObjectType=' + objectType + '&ObjectId=' + objectId+'&MemberId='+memberId+'&U='+escape(location.href), null);
        $(objectType+objectId).innerHTML='Marked as abuse';
        alert('Thanks, your report has been send.');
    }
}
