var className;
var isIE=document.all;
if (isIE){
	className = "className";
}
else{
	className = "class";
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
 * Highlight a specific row in the table, setting other rows to either 
 * a default style or the styles supplied.
 *
 * Paramaters:
 *    tableName			Name of table to update.
 *	  rowNum			Number of row to highlight (0 = first row)
 *    existingClass		Style to apply to non-selected rows (default '')
 *    alternatingClass	Style to apply to alternate rows (default = existingClass)
 */
function tableSelectRow(tableName, rowNum, existingClass, alternatingClass) 
{
	var myTable = document.getElementById(tableName);
	
	var arrRows = myTable.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
	

	
	for (var i=0; i<arrRows.length; i++)
	 {
		
			if (i == rowNum) 
			 {
			 
			         if (arrRows[i].className =="notselected")
			         {
			         
			         arrRows[i].className = "selected";
			         
			         }
			          
		 
			         
			             for(var k=i-1; k>=0 ; k--)
			                 {
			                 
			                    if(arrRows[k].className == "selected")
	                                 arrRows[k].className = "notselected";
				             }
			             for(var l=i+1; l<arrRows.length ; l++)
			                 {
			                
			                    if(arrRows[l].className == "selected")
	            	            arrRows[l].className = "notselected";
				            
			                 }
			        
		
			         
			 } 
			 
			
	} 
		
			
}


function tableSelectRow1(tableName, rowNum, existingClass, alternatingClass) 
{
	var myTable = document.getElementById(tableName);
	
	var arrRows = myTable.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
	

	
	for (var i=0; i<arrRows.length; i++)
	 {
		
			if (i == rowNum) 
			 {
			
			         if (arrRows[i].className =="msg-unread" || arrRows[i].className =="")
			         {
			         
			         arrRows[i].className = "msg-selected";
			         
			         }
			          
		 
			         
			             for(var k=i-1; k>=0 ; k--)
			                 {
			                 
			                    if(arrRows[k].className == "msg-selected")
	                                 arrRows[k].className = "";
				             }
			             for(var l=i+1; l<arrRows.length ; l++)
			                 {
			                
			                    if(arrRows[l].className == "msg-selected")
	            	            arrRows[l].className = "";
				            
			                 }
			        
		
			         
			 } 
			 
			
	} 
		
			
}
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/*
 * Tests if cookies are enabled.
 *
 * Paramaters: None
 * Returns: True if they are enabled, false otherwise
 */
function Test_Cookies() {
	Set_Cookie( 'test', 'none', '', '/', '', '' );
	var ret = Get_Cookie( 'test' );
	if (ret) {
		Delete_Cookie('test', '/', '');
		return true;
	}
	return false;
}

/*-----------------------------------------------------------------+ 
| This function is used in partial of bos i.e. backpage_reply_form |
| Created on 2007-06-13 by Kishore.                                |
+------------------------------------------------------------------*/
function trim(str)
{
     return str.replace(/^\s*|\s*$/g,"");
}
    
function setData()
{  
   var form0=document.forms[0];
   form0.replyer_Forwarding_Email_Id.value=form0.replyer_Identity.options[form0.replyer_Identity.selectedIndex].id
   form0.reply_Subject.value=form0.reply_Subject.value
   form0.reply_Data.value=form0.message.value
   if(trim(form0.reply_Subject.value) == "")
   {
     alert("Please enter a subject for your reply");
     return false;
   }
   if(trim(form0.reply_Data.value) == "")
   {
     alert("Please enter a message");
     return false;
   }
   return true;
}
    
function sendReply()
{
    if(setData())
        document.forms[0].submit();
}

/*---------------------------------------------+ 
| This function is used in bos/showLogin.rhtml |
| Created on 2007-06-13 by Kishore.            |
+----------------------------------------------*/
//function to clear text from login and password textbox
//Added on 17-04-2007
function clicktextclear(id)
{
    var selectedtextarea;
    selectedtextarea = 0;
    if (!selectedtextarea) 
        {
		  var objrep = document.getElementById(id);
		  var text=objrep.value;		  
		  if(objrep.value=='TrustPlus ID')
		  {
            objrep.value = '';            
          }
  		  else if(objrep.value=='Password')
		  {
            objrep.value = '';
          }
            selectedtextarea=1;
		}	   
}

/*---------------------------------------------+ 
| This function is used in bos/showPopUp.rhtml |
| Created on 2007-06-13 by Kishore.            |
+----------------------------------------------*/
function showActiveCross(crossImage)
{
    crossImage.src="/images/cross_active.gif";
}

function showInactiveCross(crossImage)
{
    crossImage.src="/images/cross_blue.gif";
}

function login()
{  
    //RIGHT NOW WE ARE NOT HAVING ANY GUI, TO SHOW TO USER
    //THAT HE/SHE HAS AUTOMATICALLY LOGGED IN.
    //THIS CODE IS WORKING FINE.
    new Ajax.Updater('login_div', '/user/loginFromBOS', {asynchronous:true, evalScripts:true});
    return false;
}

/*-----------------------------------------------+ 
| This function is used in bos/showReplyTo.rhtml |
| Created on 2007-06-13 by Kishore.              |
+------------------------------------------------*/
function submitFormReply()
{
    var form0=document.forms[0];
    form0.replyer_Forwarding_Email_Id.value=form0.replyer_Identity.options[form0.replyer_Identity.selectedIndex].id
    form0.submit();
}



function tableSelectedRow(tableName, rowNum, existingClass, alternatingClass) 
{
   var myTable = document.getElementById(tableName);	
   var arrRows = myTable.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
	if (!existingClass) {
		existingClass = '';
	}
	if (!alternatingClass) {
		alternatingClass = existingClass;
	}

	for (var i=0; i<arrRows.length; i++) 
	{	
		if (arrRows[i].className == 'rowSeperator' )
			continue;
		if (arrRows[i].className != 'expandableRow' ) 
		{
			if (i == rowNum) 
			{
			    
			    //Selected row for first column
			    if(tableName == "reputationTable")
			         document.getElementById("rating" + i + ".1").className = 'midRowLeftBgBlue';
				arrRows[i].className = 'tabhead';
			} 
			else 
			{
			    if(tableName == "reputationTable")
			         document.getElementById("rating" + i + ".1").className = 'midRowLeftBg';
				arrRows[i].className = (i%2 == 0) ? existingClass : alternatingClass;
			}
		} 
	} 		
}

function tableSelect_postRow(tableName, rowNum, total_num_row, existingClass, alternatingClass) 
{

	var myTable = document.getElementById(tableName).innerHTML;

    for(var myrow=0;myrow<total_num_row;myrow++) 
       {
       for(var select_j=0; select_j < 4; (select_j)++)
        {
            postTd = document.getElementById("post" + myrow + "." + select_j);
    		postTd.setAttribute(className,"");
        }    
      }
   for(var select_i=0; select_i < 4; (select_i)++)
    {
           postTd = document.getElementById("post" + rowNum + "." + select_i);	    
    	   postTd.setAttribute(className,"lightBlueBg");
    }    


	if (!existingClass) {
		existingClass = '';
	}
	if (!alternatingClass) {
		alternatingClass = existingClass;
	}

	
}

function tableSelect_replyRow(tableName, rowNum, total_num_row, reply_row_id) 
{ //  alert(reply_row_id) ;
     //var myTable = document.getElementById(tableName);
     var repliesTD = document.getElementsByTagName("td");
  //   alert(repliesTD[2].innerHTML);
    for(var i=0;i<repliesTD.length;i++) 
    {  
        if (repliesTD[i].getAttribute(className) == "lightGreenBg")
        {
            repliesTD[i].setAttribute(className,"lightwhiteBg_reply");
        }   
    }
        
        
        /*for(var select_i=0; select_i < 3; (select_i)++)
        {           
           if (replyTd = repliesTD[i].getElementById("reply" + rowNum + "." + select_i ))
           {
                replyTd.setAttribute(className,"lightGreenBg");
           }
           else
           {
            replyTd.className = "lightwhiteBg_reply";
           }
	   	   
        }*/
  
   for(var select_i=0; select_i < 3; (select_i)++)
    {     
           replyTd = document.getElementById("reply" + reply_row_id + "." + select_i );
          // alert(replyTd.innerHTML)
           replyTd.setAttribute(className,"lightGreenBg");
          // alert(replyTd.className)
	   	   
    }
}
/* Function for showing and hiding the reply section upon selecting a particular post
*/

function hide_and_show_reply(repliesDiv,rownum,total_num_row){

  for(var selectedrow=0; selectedrow<total_num_row; selectedrow++)
    {
    if (selectedrow == rownum){
        document.getElementById('repliesDiv' + rownum).style.visibility = 'visible';
          document.getElementById('repliesDiv' + rownum).style.display = '';}
        
    else{
        document.getElementById('repliesDiv' + selectedrow).style.visibility = 'hidden';
        document.getElementById('repliesDiv' + selectedrow).style.display = 'none';
        }
    }
  /*document.getElementById('repliesDiv' + prevSelected).style.visibility = 'hidden';
  document.getElementById('repliesDiv' + prevSelected).style.display = 'none';
  document.getElementById('repliesDiv' + rownum).style.visibility = 'visible';
  document.getElementById('repliesDiv' + rownum).style.display = '';
  prevSelected = rownum;
  return(prevSelected);*/
}

/* General function for validation of email format   */
function email_format_validation(str) 
{
    var email_pattern=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (!email_pattern.test(str))
    { 
        alert("Please enter a valid email address.")
        return false;    
    }   
    return true; 
}	
/* function to get the selected file extension */
function checkFileFormat(){		 
		var obj = document.getElementById("contacts");
		if (obj) {
			var filename = obj.value;
			if (filename.length == 0) 
				return "";
			var dot = filename.lastIndexOf(".");
			if (dot == -1) 
				return "";
			var extension = filename.substr(dot, filename.length);			
			if (extension.toLowerCase() == '.csv')
			return true;			
		}
		alert("Please select valid File format.");
		return false		
	}
/* This is used to restrict the user to enter only limited no. of characters in comment textbox area.
   It will strip off the exceeding no. of characters along with an alert message of overflow. */
function is_maxlength(obj)
{
	var max_length = 500;
	var commented_length = obj.value.length;
	if( commented_length  > max_length)
	{
		alert("You cannot enter more than " + max_length + " characters!");
		obj.value = obj.value.substring(0,500);
	}
}