﻿function inscaps()
{ 
  var c;
  c=window.event.keyCode;
      if(c>=97 && c<=121)
      {
        window.event.keyCode=window.event.keyCode-32;
      }
 }

function insnums(evt)
{
 var charCode=(evt.which) ? evt.which : event.keyCode;
 
 if(charCode > 31 && (charCode < 48 || charCode > 57 ))
    {
        return false;
    }
    return true;
}

function inswords()
{
    var c;
    c = window.event.keyCode;
    if(c==32)
    return;
    if(c==8)
    return;
    if(c<65 || c>122 ||c==96)
    window.event.keyCode=0;
}

function deleterec()
 {  var ok ;
    ok=confirm("Are You sure to delete Record...?");
    if (ok==true)
    {   return true;
      }
      else
      { return false;
      }
   }

function chk(id) 
 { 
    if(id.checked == true)
	    {
			    for(i=0; i<document.aspnetForm.elements.length; i++)
			    {
					    if(document.aspnetForm.elements[i].type=="checkbox")
					    {
					        document.aspnetForm.elements[i].checked=true;
					    }
			    }               
	    }
	    else
	    {
			    for(i=0; i<document.aspnetForm.elements.length; i++)
			    {
					    if(document.aspnetForm.elements[i].type=="checkbox")
					    {
					    document.aspnetForm.elements[i].checked=false;
					    }
			    } 
	    }
	}

function open_new_window(id)
{
        window.open("openwindow.aspx?id=" + id,"mywindow","width=400,heigth=400,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no");
  }	

function open_blank_window(id,datablock)
{
    window.open("collectdatadisplay.aspx?id=" + id + "&datablock=" + datablock ,"mywindow1","width=400,height=200,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no");
}

function open_url_window(url)
{
        window.open(url);
}   

function phone()
{
 var p;
  p=window.event.keyCode;
  if(p==40 || p==41 || p==43 || p==45 || p==32)
  { 
    return ;
   }
  if(p<48 ||p>57)
  {
    window.event.keyCode=0;
  }
}


//Forum Scripts

//Thread List
function blockvisible(no)
{
    if(document.getElementById('thread'+no).style.display=='')
    {
        document.getElementById('thread'+no).style.display='none';
    }
    else
    {
        document.getElementById('thread'+no).style.display='';
    }
}

function changeuserstatus(id,name)
{
    window.location.href('Add-Approve-User.aspx?id='+id+'&name='+name);
}

//Public Thread(s)
function getid()
{
    var cids = '';
    var uids = '';
    var id = new Array();
    
    for(i=0; i<document.aspnetForm.elements.length; i++)
    {
        if(document.aspnetForm.elements[i].type=="checkbox" && document.aspnetForm.elements[i].name.substring(0,4)=='chk-')
        {
            if(document.aspnetForm.elements[i].checked == true)
            {
                id = document.aspnetForm.elements[i].name.split('-');
                cids += id[1]+',';
            }
            else
            {
                id = document.aspnetForm.elements[i].name.split('-');
                uids += id[1]+',';
            }
        }
    }  

    cids = cids.substring(0,cids.length - 1);
    uids = uids.substring(0 ,uids.length - 1);

    if(cids == '' && uids == '')
    {
        alert("First Select Thread");
        return;
    }

    if(cids == '')
    {
        cids = '0';
    }
    if(uids == '')
    {
        uids = '0';
    }    
    ForumMethods.Update( cids+':'+uids, call_backupdate);
}

//Private Thread(s)
function getprivateid()
{
    var cids = '';
    var uids = '';
    var id = new Array();
    
    for(i=0; i<document.aspnetForm.elements.length; i++)
    {
        if(document.aspnetForm.elements[i].type=="checkbox" && document.aspnetForm.elements[i].name.substring(0,5)=='chk1-')
        {
            if(document.aspnetForm.elements[i].checked == true)
            {
                id = document.aspnetForm.elements[i].name.split('-');
                cids += id[1]+',';
            }
            else
            {
                id = document.aspnetForm.elements[i].name.split('-');
                uids += id[1]+',';
            }
        }
    }
      
    cids = cids.substring(0,cids.length - 1);
    uids = uids.substring(0 ,uids.length - 1);

    if(cids == '' && uids == '')
    {
        alert("First Select Thread");
        return;
    }

    if(cids == '')
    {
        cids = '0';
    }
    
    if(uids == '')
    {
        uids = '0';
    }
    
    ForumMethods.UpdateForPrivate( cids+':'+uids, call_backupdate);
}

//Protected Thread(s)
function getprotectedid(loginid)
{ 
    if(loginid == '')
        return;
        
    var cids = '';
    var uids = '';
    var id = new Array();

    for(i=0; i<document.aspnetForm.elements.length; i++)
    {
        if(document.aspnetForm.elements[i].type=="checkbox" && document.aspnetForm.elements[i].name.substring(0,5)=='chk3-')
        {
            if(document.aspnetForm.elements[i].checked == true)
            {
                id = document.aspnetForm.elements[i].name.split('-');
                cids += id[1]+',';
            }
        }
    }  

    cids = cids.substring(0,cids.length - 1);

    if(cids == '')
    {
        alert("First Select Thread");
        return;
    }
 
    ForumMethods.InsertProtectedRequest(cids, loginid, Call_Back);
}

function Call_Back(res)
{
    if(res.value !='' && res.value != null)
    {
        alert("Request Send Successfully");
    }
}

//Own Protected Thread(s)
function getprotid()
{
    var cids = '';
    var uids = '';
    var id = new Array();
    
    for(i=0; i<document.aspnetForm.elements.length; i++)
    {
        if(document.aspnetForm.elements[i].type=="checkbox" && document.aspnetForm.elements[i].name.substring(0,5)=='chk2-')
        {
            if(document.aspnetForm.elements[i].checked == true)
            {
                id = document.aspnetForm.elements[i].name.split('-');
                cids += id[1]+',';
            }
            else
            {
                id = document.aspnetForm.elements[i].name.split('-');
                uids += id[1]+',';
            }
        }
    }  
    
    //cids = cids.substring(0, cids.length - 1);
    //uids = uids.substring(0, uids.length - 1);

    if(cids == '' && uids == '')
    {
        alert("First Select Thread");
        return;
    }
    
    if(cids == '')
    {
        cids = '0';
    }
    
    if(uids == '')
    {
        uids = '0';
    }
    
    ForumMethods.UpdateForProtected( cids+':'+uids, call_backupdate);
}

function call_backupdate(res)
{
    if(res.value == '')
    {
      alert("Operation Successfully completed.");
    }
    else
    {
        alert(res.value);
    }
}

//Thread Reply
function threadreply(rid)
{
    if(document.getElementById('tr-'+rid).style.display == '')
        document.getElementById('tr-'+rid).style.display = 'none';
    else
        document.getElementById('tr-'+rid).style.display = ''
}

function savereply(replyparentid, threadid)
{
   // alert (replyparentid + " &nbsp;"+ threadid);
    comments = document.getElementById('txtreplycomments-'+replyparentid).value;

    if(comments == '')
    {
        alert('Fill Comments');
        return;
    }
    
    replyby = document.getElementById('txtreplyby-'+replyparentid).value;

    if(replyby == '')
    {
        alert('Fill reply by');
        return;
    }
    
    email = document.getElementById('txtemail-'+replyparentid).value;

//    if(email != '')
//    {
//        var exp = '\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*';
//       // var exp = '/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/';
//        result = email.match( exp );
//        
//        if ( ! result ) 
//        {
//            alert('Invalid email address');
//            return;
//        }
//    }
    
    path = window.location.toString();
    var url = new Array();
    url = path.split('/');
    
    var pagename = url[url.length-1];
    var queryelements = new Array();
    queryelements = pagename.split('&');

    //moderator
    var mode = new Array();
    mode = queryelements[0].split('=');                
    var mod = mode[1];
    
    //alert(document.getElementById('ctl00_ContentPlaceHolder1_h1').value.trim());
    if(mod == "True")
        ForumMethods.SaveThreadReply(comments, replyby, email, replyparentid, threadid,'0', callback_reply);
    else if(mod == "False")
        ForumMethods.SaveThreadReply(comments, replyby, email, replyparentid, threadid,'1', callback_reply);
}


function callback_reply(res)
{
    document.getElementById('txtreplycomments-'+res.value).value = '';
    document.getElementById('txtreplyby-'+res.value).value = '';
    document.getElementById('txtemail-'+res.value).value = '';

    threadreply(res.value);

    __doPostBack('ctl00$ContentPlaceHolder1$FillCL','');
}

function getid()
{
    var cids = '';
    var uids = '';
    var id = new Array();
    
    for(i=0; i<document.aspnetForm.elements.length; i++)
    {
        if(document.aspnetForm.elements[i].type=="checkbox")
        {
            if(document.aspnetForm.elements[i].checked == true)
            {
                id = document.aspnetForm.elements[i].name.split('-');
                cids += id[1]+',';
            }
            else
            {
                id = document.aspnetForm.elements[i].name.split('-');
                uids += id[1]+',';
            }
        }
    }  

    cids = cids.substring(0,cids.length - 1);
    uids = uids.substring(0 ,uids.length - 1);

    if(cids == '')
    {
        cids = '0';
    }
    
    if(uids == '')
    {
        uids = '0';
    }

    var msg = ForumMethods.UpdateForReply( cids+':'+uids);
    if(msg.value == '')
    {
        alert("Operation Successfully completed.");
    }
    else
    {
        alert('Sorry we are experiencing technical problems.');
    }
}

//Change Moderator
function checkonlyone(id)
{
    for(i=0; i<document.aspnetForm.elements.length; i++)
    {
        if(document.aspnetForm.elements[i].type=="checkbox" && document.aspnetForm.elements[i].name.substring(0,8)=="Manage2:")
        {
            if(id !=document.aspnetForm.elements[i].id)
            {
                document.aspnetForm.elements[i].checked = false;
            }
        }
    }
}


//function deletereply(replyid)
//{  
//    try
//    {
//       alert(replyid); 
//       ForumMethods.deletethreadreply(replyid);
//     }
//    catch(Err)
//    {
//        alert("Error: " + Err.description);
//    }                     
//}
