function do_login()
{

        if (document.frmlogin.username.value == "" )
        {
	        alert("Enter your emailid to login");
	        return false;
        }
        if (document.frmlogin.password.value == "" )
        {
	        alert("Provide the password to login");
	        return false;
        }
        document.frmlogin.submit;
        return true;

}

function go_to_archive_folder(session,username)
{
        var foldername = document.getElementById('ARCHIVEFOLDERID').value;     
        var sid = session;
        var popusername = username; 
        if(document.getElementById('ARCHIVEFOLDERID').selectedIndex == 0)
        {
                alert("Please select the folder");
                return false;
        }
        else
        {
                location.href = 'archive.cgi?session='+sid+'&username='+popusername+'&FOLDER='+foldername;
        }       
}

function go_to_folder(session,username)
{
	var foldername = document.getElementById('FOLDERID').value;	
	var sid = session;
	var popusername = username; 
	if(document.getElementById('FOLDERID').selectedIndex == 0)
	{
		alert("Please select the folder");
		return false;
	}
	else
	{					
		location.href = 'checkmail.cgi?session='+sid+'&username='+popusername+'&FOLDER='+foldername;
	}	
}

function go_to_page(session,username,foldername,archive)
{
    	var page_no = document.getElementById('PAGEID').value;	
	var sid = session;
	var popusername = username;	
	if(document.getElementById('PAGEID').selectedIndex == 0)
	{
		alert("Please select the page number");
		return false;
	}
	else
	{
		if(archive == "yes")
		{								
			location.href = 'archive.cgi?session='+sid+'&username='+popusername+'&FOLDER='+foldername+"&pg="+page_no;
		}
		else
		{
			location.href = 'checkmail.cgi?session='+sid+'&username='+popusername+'&FOLDER='+foldername+"&pg="+page_no;
		}		
		
	
	}	
}

function select_all()
{
	
	
	var re = new RegExp(/^new/);
	if(document.frmMails.selectall.checked)
	{
		if(document.frmMails.MESSAGES)
		{		
		        if(document.frmMails.MESSAGES.length)
		        {
		                for(i=0; i<document.frmMails.MESSAGES.length; i++)
		                {
					var msgrow = 'row' + (i + 1);
		                        document.frmMails.MESSAGES[i].checked = true;
					document.getElementById(msgrow).style.backgroundColor= '#f6f6f6';
		                }
		        }
		        else
		        {
		               document.frmMails.MESSAGES.checked = true;
				 document.getElementById('row1').style.backgroundColor= '#f6f6f6';
		        }
		        document.frmMails.hidDelAll.value = "yes";
		 }       
	}
	else
	{
		if(document.frmMails.MESSAGES)
		{
			document.frmMails.hidDelAll.value = ""; 
		        if(document.frmMails.MESSAGES.length)
		        {
		                for(i=0; i<document.frmMails.MESSAGES.length; i++)
		                {
					var msgrow = 'row' + (i + 1);
		                        document.frmMails.MESSAGES[i].checked = false;
					if(document.frmMails.MESSAGES[i].value.match(re))
					{
						document.getElementById(msgrow).style.backgroundColor= '#e4e4e4';
					}
					else
					{
						document.getElementById(msgrow).style.backgroundColor= '#FFFFFF';
					}	
		                }
		                return false;
		
		        }
		        else
		        {
		                document.frmMails.MESSAGES.checked = false;
				if(document.frmMails.MESSAGES.value.match(re))
				{
					 document.getElementById('row1').style.backgroundColor= '#e4e4e4';
				}
				else
				{
					 document.getElementById('row1').style.backgroundColor= '#FFFFFF';
				}
		        }
		        
		        return false;
		}        
	}

}


function check_message()
{	
	if(document.frmMails.num_messages.value == 0)
	{
		alert("No messages are available");
		return false;		
	}
	
}

function key_check()

{
       var re = new RegExp(/^\s+$/);
       if(!((document.sForm.from_date.selectedIndex == 0) && (document.sForm.from_month.selectedIndex == 0) && (document.sForm.from_year.selectedIndex == 0)
		   && (document.sForm.to_date.selectedIndex == 0) && (document.sForm.to_month.selectedIndex == 0) && (document.sForm.to_year.selectedIndex == 0)))
       {
       		if((document.sForm.from_date.selectedIndex != 0) && (document.sForm.from_month.selectedIndex != 0) && (document.sForm.from_year.selectedIndex != 0)
		   && (document.sForm.to_date.selectedIndex != 0) && (document.sForm.to_month.selectedIndex != 0) && (document.sForm.to_year.selectedIndex != 0))
		   {
		   	document.sForm.date_is_selected.value = "yes";     	   	
		   }
		   else
		   {
		   	alert("You must select the valid 'From date' or 'To date' for datewise searching");
		   	return false;
		   }     	
       
       }
       else if((document.sForm.k.value == "" || document.sForm.k.value.match(re)) && ((document.sForm.from_date.selectedIndex == 0) && (document.sForm.from_month.selectedIndex == 0) && (document.sForm.from_year.selectedIndex == 0)
		   && (document.sForm.to_date.selectedIndex == 0) && (document.sForm.to_month.selectedIndex == 0) && (document.sForm.to_year.selectedIndex == 0)))
       {
       		alert("Please enter some criteria for search");
       		return false ;	
       	
       }	   
       else 
       {
       		document.sForm.date_is_selected.value = "no";
       }
       document.sForm.submit();  

}

function folder_empty()
{
	 var re = new RegExp(/^\s+$/);	 
	 
	 if(document.frmFolder.nfolder.value == "" || document.frmFolder.nfolder.value.match(re))
	 {
	 	alert("Please enter the folder name");
	 	return false;	
	 }		
	
}

function confirm_emp (name)
{
	if ( confirm('This will delete all your mails from folder ' + '['+name+']' + '. Are you sure ?'))
 		return true
	else
		return false
}
function confirm_del (name)
{
	if ( confirm('This will remove the folder '+ '['+name+']' +' completely. Are you sure ?'))
 		return true
	else
		return false
}

 function validateName()
{
        var strName = document.userfrm.fullname.value;
        var newStrName = trimstr(strName);

        if(newStrName == "")
        {
                alert("Please enter your Full Name.");
                return false;
        }
        else if (strName.indexOf("@") > -1)
        {
                alert("Please do not include '@' char. in your name.");
                return false;
        }
        else
        {
                return true;
        }
}

function trimstr(str)
{
  return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}

function open_add(toccbcc,scope)
{
	var session = document.Compose.session.value;
	var username = document.Compose.username.value;
	document.Compose.toccbcc.value = toccbcc;
        var url = "/cgi-bin/Planner/addbk.cgi?v=" + toccbcc +"&sp=" + scope +"&frm=ctSrtView&"+"username="+username+"&session="+session+"&lfrom=TO";
        if ((toccbcc == 'all') || (toccbcc == 'too'))
                url += escape (document.Compose.TO.value);
        if ((toccbcc == 'all') || (toccbcc == 'ccc'))
                url += escape (document.Compose.CC.value);
        if ((toccbcc == 'all') || (toccbcc == 'bcc'))
                url += escape (document.Compose.BCC.value);
        window.open(url,"addressbook","width=450,height=325,resizable=yes,scrollbars=yes");
}

function AddSign() {
			
        var sign = document.Compose.mySign.value;

        if ( sign  == "no_sign" )
        {
            alert('Please go to Options to add signature.');
            document.Compose.addsign.checked = false;
            return false;
        }
        else
        {
        					
              if (document.Compose.addsign.checked)
              {              	
              
	              	if(document.Compose.ReplyUncheck.value == "true")  
	              	{              		
	              		document.Compose.body.value = "\n\n\n\n" + sign + "\n\n" + document.Compose.body.value; 
	              	}
	              	else
	              	{             		                       		
	                 	document.Compose.body.value += "\n\n" + sign; 
	                }                  
                 	document.Compose.addsign.disabled = true;                
              }
                         
              
        }
}

function SendText()
{
    if(document.Compose.readfromdraft.value == "true")
    {
    	return true;
    	
    }    	
    if (document.Compose.TO.value == "" )
    {
        alert("Please type email ids in 'TO:' or pickup from the address book");
        return false;
    }

    if (document.Compose.SUBJECT.value == "" )
    {
        if ( confirm("send with no subject. Are you sure. ?") )
        {
                document.Compose.SUBJECT.value = 'no subject given';
        }
        else
        {
                document.Compose.SUBJECT.focus();
                return false;
        }

	document.Compose.SUBJECT.focus();
    }
   	document.Compose.submit();
}

function SwitchHtml()
{				
	var session = document.Compose.session.value;
	var username = document.Compose.username.value;
					
	if(document.Compose.addsign.checked == true)
		document.Compose.SignAdded.value = "yes";				
							
        document.Compose.action = "send.cgi?session="+session+"&username="+username;
        document.Compose.send_as_html.value="yes";
        document.Compose.hidSwitch.value="yes";		//-------------- Added by Ritesh Dobhal on 13/07/07 ------------------
        document.Compose.submit();
}
function openPopWindow(url)
{		
	window.open(url,"cpanel","width=400,height=200,resizable=yes,scrollbars=yes");	
}

function readFromDraft()
{
        document.Compose.action = "checkmail.cgi";
        document.Compose.FOLDER.value = "drafts";
        document.Compose.readfromdraft.value = "true";
        document.Compose.submit();
        return true;
}


 function SwitchText()
{ 
	var session =  document.Compose.session.value;     
        var username =  document.Compose.username.value;
        if(edit.document.body.innerHTML!="")    
        {
        	var conf = confirm("This will convert your message into plain text. All formatting will be lost. Continue?");
            if (!conf) {
                return;
            }                
        }
        if(document.Compose.addsign.checked == true)
		document.Compose.SignAdded.value = "yes"; 							
        
        var strHTML = /<strong[^>]*>|<\/strong>|<em[^>]*>|<\/em>|<span[^>]*>|<\/span>|<font[^>]*|<\/font>|<p[^>]*>|<\/p>|<h1[^>]*>|<\/h1>|<h2[^>]*>|<\/h2>|<h3[^>]*|<\/h3>|<h4[^>]*>|<\/h4>|<h5[^>]*>|<\/h5>|<h6[^>]*>|<\/h6>|<address[^>]*|<\/address>|<pre[^>]*>|<\/pre>|<ol[^>]*>|<\/ol>|<li[^>]*>|<\/li>|<ul[^>]*>|<\/ul>|<u[^>]*>|<\/u>|<div[^>]*>|<\/div>/gi;                          
			
	var strStripHtml= edit.document.body.innerHTML.replace(strHTML,"");
	var strReplaceBR = /<br[^>]*>/gi;  					
			  
	if(navigator.userAgent.match('Gecko'))
	{       				  	     				  	
		strStripHtml = strStripHtml.replace(strReplaceBR,"");
	}
	else
	{
		strStripHtml = strStripHtml.replace(strReplaceBR,"\n");
	}	
  	strStripHtml = strStripHtml.replace(/>/,"");      					       					
	
	document.Compose.body.value = strStripHtml;			
        document.Compose.action = "send.cgi?session="+session+"&username="+username+"&format=plain";
        document.Compose.send_as_html.value="";
        document.Compose.submit();
}

function SetHtml()
{
       
	var msgBody = document.Compose.PlainMsg.value.replace(/\n/g,"<br>");    						
	document.Compose.PlainMsg.value = msgBody;											
        editor.SetHTML(document.Compose.PlainMsg.value);
}
function SetSign()
{   

	document.Compose.mySign.value = document.Compose.mySign.value.replace(/\n/g,"<br>");				   
	if(document.Compose.ReplyUncheck.value == "true")
      	{              		
      		edit.document.body.innerHTML = "<BR><BR>" + document.Compose.mySign.value + "<BR><BR>" + edit.document.body.innerHTML;  
      	   		
      	}
      	else
      	{
      		edit.document.body.innerHTML = edit.document.body.innerHTML + "<BR><BR>" + document.Compose.mySign.value;                          		
         
        }                  
        document.Compose.addsign.disabled = true;                   
                
} 

function AddSign_HTML()
{        
        var sign = document.Compose.mySign.value;        
        if ( sign  == "no_sign" )
        {
                alert('Please click on Options to add signature.');
                document.Compose.addsign.checked = false;
                return false;
        }        
        else
        {        		
        			
                if (document.Compose.addsign.checked)
                {                           			
                    SetSign();                   
                    document.Compose.addsign.disabled = true; 
                }       			
              
        }
}
function SendHtml()
{	
				
        if (document.Compose.TO.value == "" ) {
                alert("Please type email ids in 'TO:' or pickup from the contacts");
                return false;
        }
        if (document.Compose.TO.value == "" ) {
                if ( confirm("send with no subject. Are you sure. ?") ) {
                        document.Compose.SUBJECT.value = 'no subject given';
                } else {
                        document.Compose.SUBJECT.focus();
                        return false;
                }
                document.Compose.SUBJECT.focus();
        }
        document.Compose.body.value=edit.document.body.innerHTML;
    	document.Compose.submit();
        
}
function select_address()
{
	var flag = 0;
	if(document.addQuickContact.quickEmailID.length)
	{
		for(var i=0; i < document.addQuickContact.quickEmailID.length ;i++)
		{
			if(document.addQuickContact.quickEmailID[i].checked == true)
			{
				flag = 1;
				break;	
			}		
		}
		if(flag == 0)
		{
			alert("Please select emailId(s)");
			return false;	
		}			
		
	}
	else
	{
		if(document.addQuickContact.quickEmailID.checked == false)
		{
			alert("Please select the emailId");
			return false;			
		}							
	}
}
function quick_add_validate()
{
	var errorMsg = "";

	for(i=1; i<=document.ctAddrFrm.fieldCount.value; i++)
	{

		var firstName = eval("document.ctAddrFrm.firstName"+i);
		var lastName = eval("document.ctAddrFrm.lastName"+i);
		var email = eval("document.ctAddrFrm.email"+i);
		if(trimstr(firstName.value) == "")
		{
			alert("Please enter first name for Contact "+i);
			return false;
		}
				
	}
	return true;
}
function trimstr(str)
{
	return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') );
}
function confirm_spam (name)
{

 	if ( confirm('This action will report to our Spam Analysist to treat this type of message as spam at the same time this message will be deleted. Are you sure?'))
 		return true
	else
   		return false
}
function move_folder_up()
{	
	
	if(document.getElementById('MOVEFOLDERID1').selectedIndex == 0)
	{
		alert("Please select the folder");
		return false;	
	} 
        else
       	{
       		document.getElementById('MOVEFOLDERID2').disabled = true;
       		document.frmMoveMails.submit();
       		
       	}			
	
}
function move_folder_down()
{	
	
	if(document.getElementById('MOVEFOLDERID2').selectedIndex == 0)
	{
		alert("Please select the folder");
		return false;	
	} 
        else
       	{
       		document.getElementById('MOVEFOLDERID1').disabled = true;
       		document.frmMoveMails.submit();
       		
       	}			
	
}
function load_text()
{
	
      if(document.Compose.SignAdded.value == "yes" )
      {        
      	document.Compose.addsign.checked = true;
      	document.Compose.addsign.disabled = true;
      }
      /*--------------------------------- Added by ritesh dobhal on 16/06/06-------------------------------------------*/
      if(document.Compose.SGN_CHK.value == "checked" )
      {
      	document.Compose.addsign.disabled = true;
      }
      /*----------------------------------- End of code ---------------------------------------------------------------*/      
   
     document.Compose.body.value = "\n\n" + document.Compose.body.value;	
	
}
function load_html()
{	
	
	
	if(document.Compose.SignAdded.value == "yes")
       	{       	  
       		document.Compose.addsign.checked = true;
       		document.Compose.addsign.disabled = true;     		 
       	}
  	if(document.Compose.SGN_CHK.value == "checked" )
      	{
      		document.Compose.addsign.disabled = true;
      	}	     
       
       	var richTextFrame = document.getElementById('edit');      		
       
        doc = richTextFrame.contentWindow.document;        
        doc.open();
        if(document.Compose.hidSwitch.value == "yes")
        {
        	doc.write("<br>"+document.Compose.PlainMsg.value.replace(/\n/g, "<br>"));
        }
        else
        {	
        	doc.write("<br>"+document.Compose.PlainMsg.value);
        }	
        //doc.write(document.Compose.PlainMsg.value.replace(/\n/g, "<br>"));
        doc.close(); 	
       	
        /*if(document.Compose.ReplyUncheck.value == "true")
	{
	      	alert("If you want to add the signature to the reply message, Please add the signature before writing the message");
	      	return false;      
	}*/		
	
}

function ValidateOrder(form)
{

  if (form.FIRST_NAME.value == "")
  {
  	 alert("Please include Your First name ");
  	 form.FIRST_NAME.focus();
  	 return false;
  }
  if (form.LAST_NAME.value == "")
  {
  	 alert("Please include Last Name ");
  	 form.LAST_NAME.focus();
  	 return false;
  }
  if(form.dd.value!="")
  {
  	if(isNaN(form.dd.value))
  	{
     		alert("Please enter the 'date' as number");
    		form.dd.focus();
    		return false;	
	}
 	else
 	{
    		 if(form.dd.value < 1 || form.dd.value > 31 )
    		 { 	
     			 alert("Date is not valid");
     			 form.dd.focus();
     			 return false;
    		 }
 	 }
  }
  if(form.mm.value!="")
  {
  	
  	if(isNaN(form.mm.value))
  	{
     		alert("Please enter the 'month' as number");
    		form.mm.focus();
    		return false;
 	}
 	else
  	{
     		if(form.mm.value < 1 || form.mm.value > 12 )
     		{
      			alert("Month is not valid");
      			form.mm.focus();
      			return false;
     		}

	}
  }
  if(form.yy.value!="")
  {

 	 if(isNaN(form.yy.value))
  	 {
     		alert("Please enter the 'year' as number");
     		form.yy.focus();
     		return false;
  	 }
  	 else
  	 { 
     		if(form.yy.value < 1900 || form.yy.value > 2000 )
     		{
      			alert("Year is not valid");
      			form.yy.focus();
     			return false;
    		}
  	 }
  }
  
  if(form.WORKPHONE.value!="")
  {
	var re = RegExp(/^[0-9+ -]+$/);
        if(!re.test(form.WORKPHONE.value))
	{
		alert("Phone No. should be valid");
		form.WORKPHONE.focus();
		return false;	
	} 


  }
  if(form.EMAIL_ID.value!="")
  {
	var re = new RegExp(/\s/);	
  	if(form.EMAIL_ID.value.match(re))
  	{
        	 alert("Email should not contain spaces");
         	 return false;
 	}
	else
  	{

                var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
                if (! form.EMAIL_ID.value.match(re))
                {
            		alert("Invalid email address");
            		form.EMAIL_ID.focus();
                 	return false;
                }
                else if(form.EMAIL_ID.value.length > 50)
                {
                        alert("The length of the Email Id should not be more than 50 characters");
                        form.EMAIL_ID.focus();
            		return false;
                }
        }

  }
  form.submit();
}

function change_password_validate()
{

	if(document.frmChangePassword.opass.value == "")
 	{
	  alert("Enter the old password");
	  document.frmChangePassword.opass.focus();
	  return false;
	}
	else if(document.frmChangePassword.npass.value == "")
	{
		alert("Enter the new password");
		document.frmChangePassword.npass.focus();
		return false;
	}
	else if(document.frmChangePassword.rpass.value == "")
	{
		alert("Re-Enter the new password");
		document.frmChangePassword.rpass.focus();
		return false;	
	}
	else if(document.frmChangePassword.rpass.value!="" && document.frmChangePassword.npass.value!="")
	{
		if(document.frmChangePassword.rpass.value!=document.frmChangePassword.npass.value)
		{		
			alert("The 'new password' and the 're-enter' password must be same");
			return false;
		}
	} 
	return true;
	
}
function valid_emailId()
{
        var strName = document.mailForward.beid.value;
        var newStrName = trimstr(strName);
         
        if(newStrName == "")
        {
                alert("Please enter email address(s) you want to forward mails.");
                return false;
        }
        else
        {
        	newArrayId = newStrName.split(",");
        	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
               	for(var i = 0 ; i < newArrayId.length ; i++)
        	{  
        	
        		if(newArrayId[i] == "")
        		{
        			alert("Please enter the email id in between 'commas'");
        			return false;        			
        		}
        		else
        		{    
        			var emailId = newArrayId[i];
        			if(! emailId.match(re))
        			{
        				alert("Please enter the valid email id");
        				return false;
        			
        			}
        		}			
        			
                }                
                return true;
        }
}

function validateEmail(str)
{

	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	if (! str.match(re))
	{
	    alert("Invalid email address");
	    document.frmFilter.dt_id.focus();
	    document.frmFilter.dt_id.select();
	    return false;
	}
	return true;
}
function checkValidPhrase()
{	
	if(document.frmFilter.phrase.value == "")
	{
		alert("Please enter some phrase");
		document.frmFilter.phrase.focus();
		return false;
	}
	else
	{	
		var regExp = new RegExp(/[a-z0-9\ \@\\\-\_\.]/i);	
		if(!regExp.test(document.frmFilter.phrase.value))
		{
			alert("Enter the valid phrase");
			document.frmFilter.phrase.focus();
			document.frmFilter.phrase.select();
			return false;
		}
	}
	if(document.frmFilter.m_action[2].checked == true)
	{
		if(document.frmFilter.dt_id.value == "")
		{
			alert("Enter the email address");
			document.frmFilter.dt_id.focus();
			return false;
		}
		else
		{
		  return validateEmail(document.frmFilter.dt_id.value);		
		}
	}
}
function refreshWindow()
{
	window.refresh();
}
function displayTextBox()
{	
	if(document.frmFilter.m_action[2].checked == true)
  		document.frmFilter.dt_id.style.visibility = "visible";
  	else if(document.frmFilter.m_action[2].checked == false)
  		document.frmFilter.dt_id.style.visibility = "hidden";  	
 
}
function populateForm(filter_no,counter,header,condition)
{		
	document.getElementById('filter_no').value = filter_no;
	document.getElementById('action').value = "Edit";
	
	var headerOptionsArr = new Array("Subject","From","Body","To","Cc");
	var conditionOptionsArr = new Array("contains","does not contain","end","does not end","begins","does not begin");
	
	var j=1;	
	for(var i=0;i<document.getElementById('head1').options.length;i++)
	{		  
		if(headerOptionsArr[i] == header)
		{	  	
		  document.getElementById('head1').selectedIndex = i;
		  break;
		}
	  	j++;	
	}
	j=1;	
	for(var i=0;i<document.getElementById('cond').options.length;i++)
	{		
	  
		if(conditionOptionsArr[i] == condition)
		{	  	
			 document.getElementById('cond').selectedIndex = i;
			 break;
		}
	  	j++;	
	}
	
	/*--------------------------------------- code for phrase control ------------------------------------------------ */
	var phraseHid = 'phrase' + counter;	
	document.getElementById('phrase').value = document.getElementById(phraseHid).value;
	
	/* ---------------------------------------- code for checkbox control ----------------------------------------------------- */
	var mcaseHid = 'mcase' + counter;
	
	if(document.getElementById(mcaseHid).value == "YES")
	{
		document.getElementById('mc').value = document.getElementById(mcaseHid).value;
		document.getElementById('mc').checked = true;
	}
	else
	{
		document.getElementById('mc').checked = false;
	}	
	
	/* --------------------------------------- code for radio control ---------------------------------------------------*/
	var actionHid = 'action' + counter;	
	for(i=0;i < document.frmFilter.m_action.length;i++)
	{					
		if(document.frmFilter.m_action[i].value == document.getElementById(actionHid).value)
		{	
							
			document.frmFilter.m_action[i].checked = true;
			if(document.frmFilter.m_action[2].checked == true)
			{					
				document.getElementById('dt_id').style.visibility = "visible";
				document.getElementById('dt_id').value = document.getElementById(actionHid).value;
			}
		}
	}		
	if(document.getElementById(actionHid).value!="Block" && document.getElementById(actionHid).value!="Return")
	{	  				
		document.frmFilter.m_action[2].checked = true;
		document.getElementById('dt_id').style.visibility = "visible";
		document.getElementById('dt_id').value = document.getElementById(actionHid).value;	
	}	
	
	if(document.frmFilter.m_action[2].checked == true)
  		document.getElementById('dt_id').style.visibility = "visible";
  	else if(document.frmFilter.m_action[2].checked == false)
  		document.getElementById('dt_id').style.visibility = "hidden";	
}

function validate_email()
{	
  var re = new RegExp(/\s/);   
	if(document.bform.beid.value.match(re) || document.bform.beid.value=="")
	{
		alert("Field value should not contain spaces or left blank");
		return false;
	}
	else
	{
	
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
		if (! document.bform.beid.value.match(re))
		{
		    alert("Invalid email address");
		    document.bform.beid.focus();
		    document.bform.beid.select();
		    return false;
		}
		else if(document.bform.beid.value.length > 50)
		{
			alert("The length of the Email Id should not be more than 50 characters");
			document.bform.beid.focus();
			document.bform.beid.select();
			return false;		
		}
	}
}
function select_block_id()
{	
	var flag = 0;
	if(document.frmBlockId.MESSAGES.length)
	{
		for(var i=0; i < document.frmBlockId.MESSAGES.length ;i++)
		{
			if(document.frmBlockId.MESSAGES[i].checked == true)
			{
				flag = 1;
				break;	
			}		
		}
		if(flag == 0)
		{
			alert("Please select emailId(s)");
			return false;	
		}			
		
	}
	else
	{
		if(document.frmBlockId.MESSAGES.checked == false)
		{
			alert("Please select the emailId");
			return false;			
		}							
	}
}
function select_one_from_list()
{
	
	if(document.bform.block_list.selectedIndex == "-1")
	{		
		if(document.bform.block_list.options.length == 0)		
			alert("White list is empty");		
		else
			alert("Select atleast one from the list");
		
		return false;	
	}
	else
	{
		j = 0;
		for(var i = 0 ; i <	document.bform.block_list.options.length ; i++)
		{			
			if(document.bform.block_list.options[i].selected == true)
			{
				j++;
			}
		}
		if(j > 1)
		{
			alert("Select only one value at a time to remove");
			return false;			
		}
	}
		
}

function alert_message()
{
	alert("Restore the mail to 'Inbox' to use this feature");
	return false;

}
function CheckAll(checked)
{
	
        len = document.addressBkFrm.elements.length;        
        var i = 0;
        for (i = 0; i < len; i++)
        {
                if (document.addressBkFrm.elements[i].name == 'addBkID')
                {
                        document.addressBkFrm.elements[i].checked=checked;
                }
        }
}
function checkAllInGroup(gid)
{
	
        len = document.addressBkFrm.addBkID.length;     
           
        var i = 0;
        for (i = 0; i < len; i++)
        {
        	if(document.addressBkFrm.hidaddBkID[i].value == gid)
        	{
        		if(document.addressBkFrm.addBkID[i].checked == false)
        		{
        			document.addressBkFrm.addBkID[i].checked = true;
        		}
        		else
        		{
        			document.addressBkFrm.addBkID[i].checked = false;	
        		}	
        					
        	}
        }
}
function sendMailAddfrm()
{  
	var session = document.addressBkFrm.session.value;
	var username = document.addressBkFrm.username.value;
		      				
			if(document.addressBkFrm.addBkID)
			{	    				      				
				if(document.addressBkFrm.addBkID.length)
        {                
        	j = 1;
					for (i = 0; i < document.addressBkFrm.addBkID.length; i++)
          {		                  	
          	if(document.addressBkFrm.addBkID[i].checked==true)
          	{
          		var emailId = 'email' + i;                 			                  		
          		if(j == 1)
          		{
          		emailIdStr = document.addressBkFrm.hidEmail[i].value;	
//			emailIdStr = document.getElementById(emailId).innerHTML;                  			                 			
          		}
          		else
          		{
          			emailIdStr+= ",";		                  		
			emailIdStr+=  document.addressBkFrm.hidEmail[i].value;  
        		 // emailIdStr+= document.getElementById(emailId).innerHTML;
          		}
          		j++;
									}
								}
								if(j == 1)
								{
									alert("Select the addresses to send mails");
									return false;									
								}			                  
          
        }
        else if(document.addressBkFrm.addBkID.length==undefined)
        {	                	 
        
        	if(document.addressBkFrm.addBkID.checked==true)
        	
		{
		
			var emailIdStr = document.addressBkFrm.hidEmail.value;	
//        	   var emailIdStr = document.getElementById('email0').innerHTML;           	  	                			
		}
        	else
        	{
        		alert("Select the address to send mail");
        		return false;
        	}
        }	
        document.addressBkFrm.TO.value = emailIdStr; 


	document.addressBkFrm.action="../webmail/send.cgi?session="+session+"&username="+username;               
        document.addressBkFrm.submit;
     }
     else
     {
     		alert("Sorry!! No Addresses available");
     		return false;		             
     }   
	
}
function deleteContacts()
{
	if(document.addressBkFrm.addBkID)
	{				   	
		if(document.addressBkFrm.addBkID.length)
        	{		                  
        		j = 1;
	        	for (i = 0; i < document.addressBkFrm.addBkID.length; i++)
	                {		                  	
	                  	if(document.addressBkFrm.addBkID[i].checked==true)
	                  	{
	                  		j++;
				}
			}
			if( j == 1)
			{
				alert("Select the addresses to delete");
        	  		return false;											
			}			                  
          
        	}
                else if(document.addressBkFrm.addBkID.length==undefined)
                { 
                	if(document.addressBkFrm.addBkID.checked == false)
                	{              	
                	 	alert("Select the address to delete");
                	 	return false;
                	} 	                	
                }
           			
     }
     else
     {
     		alert("Sorry!! No Addresses available");
     		return false;		             
     }
     if(confirm("Are you sure you want to delete"))
     {
               document.addressBkFrm.act.value="delCt";
               document.addressBkFrm.frm.value="";
               return true;
     }
     else
     {
     		return false;
     }		  
}
function moveContacts()
{
	if(document.addressBkFrm.addBkID)
	{				   	
		if(document.addressBkFrm.addBkID.length)
        	{		                  
        		j = 1;
	        	for (i = 0; i < document.addressBkFrm.addBkID.length; i++)
	                {		                  	
	                  	if(document.addressBkFrm.addBkID[i].checked==true)
	                  	{
	                  		j++;
				}
			}
			if( j == 1)
			{
				alert("Select the addresses to move");
        	  		return false;											
			}			                  
          
        	}
                else if(document.addressBkFrm.addBkID.length==undefined)
                { 
                	if(document.addressBkFrm.addBkID.checked == false)
                	{              	
                	 	alert("Select the address to move");
                	 	return false;
                	} 	                	
                }
           			
     }
     else
     {
     		alert("Sorry!! No Addresses available");
     		return false;		             
     }
     document.addressBkFrm.act.value="moveCt";
     document.addressBkFrm.frm.value="";
     return true;
       
}
function sortList(s1,s2,s3)
{
	var sortStr;
	if(s1=="all" && s2=="all" && s3=="all")
	{
		 sortStr = "all";
	}
	else if(s3 == "z")
	{
		sortStr = s1 + "," + s2;	
	}
	else
	{
		sortStr = s1 + "," + s2 + "," + s3;	
	}
	document.frmSort.ch.value = sortStr;
	document.frmSort.submit();
}
function editContact(contactId,groupId)
{
	document.frmEdit.addBkID.value = contactId;
	document.frmEdit.gID.value = groupId;
	document.frmEdit.submit();
}
function deleteContact(contactId)
{
	if(confirm("Are you sure you want to delete"))
	{	
		document.frmDelete.addBkID.value = contactId;
		document.frmDelete.submit();
	}
	else
	{
		return false;
	}		
}
function showAddCtfrm()
{ 
	var session = document.addressBkFrm.session.value;
	var username = document.addressBkFrm.username.value;
	//var memberId = document.addressBkFrm.memberID.value;                       
        document.addressBkFrm.act.value="";
        document.addressBkFrm.frm.value="disAddCtFrm";
        document.addressBkFrm.action="/cgi-bin/Planner/addbk.cgi?frm=disAddCtFrm&session"+session+"&username="+username+"&action=gpdisp&memberID="+memberId;               
        document.addressBkFrm.submit();
}
function validate_contact()
{
	var regExp = new RegExp(/^[0-9\-]+$/);
	if(document.ctAddrFrm.txtHomePhone.value!="")
	{	
		if(!regExp.test(document.ctAddrFrm.txtHomePhone.value))
		{
			alert("Please Enter the Valid Home Phone");
			document.ctAddrFrm.txtHomePhone.focus();
			document.ctAddrFrm.txtHomePhone.select();
			return false;
		}
	}
	if(document.ctAddrFrm.txtWorkPhone.value!="")
	{		
		if(!regExp.test(document.ctAddrFrm.txtWorkPhone.value))
		{
			alert("Please Enter the Valid Work Phone");
			document.ctAddrFrm.txtWorkPhone.focus();
			document.ctAddrFrm.txtWorkPhone.select();
			return false;
		}
	}
	if(document.ctAddrFrm.txtCell.value!="")
	{	
		if(!regExp.test(document.ctAddrFrm.txtCell.value))
		{
			alert("Please Enter the Mobile Number");
			document.ctAddrFrm.txtCell.focus();
			return false;
		}
	}			 
}
function checkActOnDelete()
{
 	document.ctAddrFrm.act.value = 'delCt'; 			 
}
function newWin(cID)
{
	 var session = document.addressBkFrm.session.value;
        var username = document.addressBkFrm.username.value;
        url = "/cgi-bin/Planner/addbk.cgi?frm=viewCts&cID="+cID+"&session="+session+"&username="+username;
        window.open(url, "cDetails", "location=no, menubars=no, scrollbars=yes, resizable=yes, width=600, height=625");
}

function AddMailID()
{
	len = document.addressBkFrm.elements.length;
	
	var i = 0;
	var arg;
	var flagBrieCas = 0;	
	
	if(window.opener.document.formRightBottomFrame)
	{
		if(window.opener.document.formRightBottomFrame.brieCas.value)
		{
			arg=window.opener.document.formRightBottomFrame.toccbcc.value;
			var flagBrieCas = 1; 
		}
	}	
	else
	{
		
		arg=window.opener.document.Compose.toccbcc.value; 
	}
	    
	switch(arg)
	{
		
		case "too":				
			for(i=0;i<len;i=i+1)
			{
			  
				if(flagBrieCas == 0)
				{
				
					if(document.addressBkFrm.elements[i].checked && opener.document.Compose.TO.value != "")
					{	
						
						opener.document.Compose.TO.value+=", "+document.addressBkFrm.elements[i].value;							
					}
					if(document.addressBkFrm.elements[i].checked && opener.document.Compose.TO.value == "")
					{						
						
						opener.document.Compose.TO.value+=document.addressBkFrm.elements[i].value;							
							
					}
				}
				else if(flagBrieCas == 1)
				{									  
					if(document.addressBkFrm.elements[i].checked && opener.document.formRightBottomFrame.emailAddress.value != "")
					{								
						opener.document.formRightBottomFrame.emailAddress.value+=", "+document.addressBkFrm.elements[i].value;
							
					}
					if(document.addressBkFrm.elements[i].checked && opener.document.formRightBottomFrame.emailAddress.value == "")
					{							
						opener.document.formRightBottomFrame.emailAddress.value+=document.addressBkFrm.elements[i].value;
													
					}
				
				
				}	
			}
			break;
		case "ccc":
			for(i=0;i<len;i=i+1)
			{
				if(document.addressBkFrm.elements[i].checked && opener.document.Compose.CC.value != "")
				{
					opener.document.Compose.CC.value+=", "+document.addressBkFrm.elements[i].value;
				}
				if(document.addressBkFrm.elements[i].checked && opener.document.Compose.CC.value == "")
				{
					opener.document.Compose.CC.value+=document.addressBkFrm.elements[i].value;
				}
			}
			break;
		case "bcc":
			for(i=0;i<len;i=i+1)
			{
				if(document.addressBkFrm.elements[i].checked && opener.document.Compose.BCC.value != "")
				{
					opener.document.Compose.BCC.value+=", "+document.addressBkFrm.elements[i].value;
				}
				if(document.addressBkFrm.elements[i].checked && opener.document.Compose.BCC.value == "")
				{
					opener.document.Compose.BCC.value+=document.addressBkFrm.elements[i].value;
				}
			}
			break;

		case "fmm":
			for(i=0;i<len;i=i+1)
			{
				if(document.addressBkFrm.elements[i].checked && opener.document.formRightBottomFrame.emailAddress.value != "")
				{
					opener.document.formRightBottomFrame.emailAddress.value+=", "+document.addressBkFrm.elements[i].value;
				}
				if(document.addressBkFrm.elements[i].checked && opener.document.formRightBottomFrame.emailAddress.value == "")
				{
					opener.document.formRightBottomFrame.emailAddress.value+=document.addressBkFrm.elements[i].value;
				}
			}
			break;

		default:
			for(i=0;i<len;i=i+1)
			{
				if(document.addressBkFrm.elements[i].checked && opener.document.frmAddEvents.txaInvitation.value != "")
				{
					opener.document.frmAddEvents.txaInvitation.value+=", "+document.addressBkFrm.elements[i].value;
				}
				if(document.addressBkFrm.elements[i].checked && opener.document.frmAddEvents.txaInvitation.value == "")
				{
					opener.document.frmAddEvents.txaInvitation.value+=document.addressBkFrm.elements[i].value;
				}
			}
			break;
	}
	window.close();
}
function openFolderWindow(url)
{		
	window.open(url,"cpanel","width=450,height=150,resizable=yes,scrollbars=yes");	
}

function submitSearch()
{	
	var re = new RegExp(/^\s+$/);
	var RE = new RegExp(/\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\~|\`|\:|\;|\"|\'|\<|\,|\>|\.|\?|\/|\{|\}|\[|\]/);
	
	
	if(document.getElementById('kw').value=="" || document.getElementById('kw').value.match(re))
	{
		alert("Please enter the keyword for search");
		return false;
	}
	else if(document.getElementById('kw').value.match(RE))
	{
		alert("Please enter the valid keyword");
		return false;	
	}	
	else
	{
		document.frmSearch.k.value = document.getElementById('kw').value;
		document.frmSearch.submit();	
	}	
}

function check_alert()
{
	if(document.frmSpamControl.AC.checked == true)
	{
		document.frmSpamControl.C2.disabled = false;
				
	}
	else
	{
		document.frmSpamControl.C2.checked = false;
		document.frmSpamControl.C2.disabled = true;	
		
	}	
		
	
}
function change_row_color(row_pointer)
{
	var re = new RegExp(/^new/);
	if(document.frmMails.MESSAGES)
        {
                       if(document.frmMails.MESSAGES.length)
                        {
                                for(i=0; i<document.frmMails.MESSAGES.length; i++)
                                {
					if((i+1) == row_pointer)
					{
					
					 	var msgrow = 'row' + row_pointer;	
						if(document.frmMails.MESSAGES[i].checked == true)
						{
							document.getElementById(msgrow).style.backgroundColor= '#f6f6f6';
						}
						else
						{
							if(document.frmMails.MESSAGES[i].value.match(re))
							{
								document.getElementById(msgrow).style.backgroundColor= '#e4e4e4';
							}
							else
							{
								document.getElementById(msgrow).style.backgroundColor= '#FFFFFF';
							}
						}	
					
                               		 }
				}

                        }
                        else
                        {
				if(document.frmMails.MESSAGES.checked == true)
				{
                               		document.getElementById('row1').style.backgroundColor ='#f6f6f6';
				}
				else
                                {
                                	document.getElementById('row1').style.backgroundColor= '#FFFFFF';
                                }

                        }
         }


}
function quota_exceded_message(status)
{
        if(status=="yes")
        {
                alert("Your mailbox is running out of allocated space quota. Please delete some mails now to release some free space and continue.");
        return false;


        }
}
function open_http_page(url)

{

alert("Your are visiting a site which is outside of webmail. you must close the browser to logout completely");

window.open(url);

//window.open(url,"mywebmail","width=600,height=605,resizable=yes,scrollbars=yes,tile=yes") ;

}

				
