divid=0;
expdiv="";
viewexpdiv="";
//This variable is used to close add/remove user popus on click of document
removediv="";
ansdiv="";
answerdiv="";
descdiv="";
dropdiv="";
flag=0;
ans = 0;
flagdiv=0;
flag_remove=0;

//onclick of login in layout clear neccessary data and focus the cursor to username
//Owner:Hareesh kumar (09-April-2007)
function user_login()
{
	Element.toggle('loginbox');
	Effect.Appear('loginbox',{duration:0.0});
	document.getElementById('results').innerHTML='';
	document.getElementById('username').value='';
	document.getElementById('pass').value='';
	setTimeout("focus_login_username('username')",100);
	
}

function user_login_qa()
{
	Element.toggle('loginbox');
	Effect.Appear('loginbox',{duration:0.0});
	document.getElementById('results').innerHTML='';
	document.getElementById('username').value='';
	document.getElementById('pass').value='';	
	setTimeout("focus_login_username('username')",100);
}

//Given id focus the cursor to field corresponding to that id
//Owner:Hareesh kumar (09-April-2007)
function focus_login_username(id){
    if(document.getElementById('username')){
    document.getElementById(id).focus();}
}

//This method is to called when user clicks on the popups
//Owner:Hareesh kumar (09-April-2007)
function getId(id)
{	
    divid=id;        
    expdiv="more_tags"+id;
    viewexpdiv="view_more_tags"+id;
	removediv="remove_user"+id;	
	descdiv="description"+id;
	return true;
}

function answerId(id)
{
    ansdiv="answerfield"+id;
}

function getAnswerId(id)
{
    answerdiv=id;
}

function getdropId(id)
{    
    dropdiv=id;
    flagdiv=1;   
    for(i=1;i<=10;i++)
    {		//Page_tag is the id of the div that gets populated in moretags popup
   			var dyn_id='dropdown'+i;
  			if((dropdiv != dyn_id))
  			{
  				//If the id exists then fade it
	  			if(document.getElementById(dyn_id))
	            {
	            	Effect.Fade(dyn_id,{duration:0.0});
	            } 
            }
   }
   $(id).style.display = 'block'; 	
}
//function getdrop(id)
//{    
    //dropdiv=id;
   // flagdiv=0;   
   // for(i=1;i<=10;i++)
  //  {		//Page_tag is the id of the div that gets populated in moretags popup
   			//var dyn_id='dropdown'+i;
  			//if(dropdiv == dyn_id)
  			//{
  				//If the id exists then fade it
	  			//if(document.getElementById(dyn_id))
	           // {
	            //	Effect.Fade(dyn_id,{duration:0.0});
	           // } 
           // }
  // }
   //$(id).style.display = 'none'; 	
//}

function flag_popup(id)
{
    flag_remove = 1;   
}
function get_popupid(id)
{
    descdiv="description"+id;
            
    flag=1;
	if ($('description'+id))
	{   
	   $('description'+id).style.visibility='hidden';
	   var id1 = id+1;
	   var id2 = id+2;	   
	   if($('description'+id1))
	   {
	       $('description'+id1).style.visibility='hidden';
	   }
	   if($('description'+id2))
	   {
	       $('description'+id2).style.visibility='hidden';
	   }
	}
	var id1 = id+1;
	var id2 = id+2;	
	   if($('description'+id1))
	   {
	       $('description'+id1).style.visibility='hidden';
	   }
	   if($('description'+id2))
	   {
	       $('description'+id2).style.visibility='hidden';
	   }
	
}

//Call the function onclicking anywhere on the website
document.onclick=enb;

//Close appropriate popups on clicking anywhere on the website
//Hareesh Kumar
function enb(e)
{
    if (!e) var e = window.event;
   
 	//This variable 20 has to be changes according to the number of records per page
    
    for(i=0;i<30;i++)
    {		//Page_tag is the id of the div that gets populated in moretags popup
   			var dyn_id='more_tags'+i;
  			if( (expdiv != dyn_id) && ((e.which == 1) || (e.button == 0)) )
  			{
  				//If the id exists then fade it
	  			if(document.getElementById(dyn_id))
	            {
	            	Effect.Fade(dyn_id,{duration:0.0});
	            } 
            }
 	} 
 	
 	 	//This variable 20 has to be changes according to the number of records per page
    
    for(i=0;i<30;i++)
    {		//Page_tag is the id of the div that gets populated in moretags popup
   			var dyn_id='view_more_tags'+i;
  			if( (viewexpdiv != dyn_id) && ((e.which == 1) || (e.button == 0)) )
  			{
  				//If the id exists then fade it
	  			if(document.getElementById(dyn_id))
	            {
	            	Effect.Fade(dyn_id,{duration:0.0});
	            } 
            }
 	} 
 	
 	for(i=1;i<=10;i++)
    {		//Page_tag is the id of the div that gets populated in moretags popup
   			var dyn_id='answerfield'+i;
  	      //  alert('inside');
  			if((ansdiv != dyn_id) && ((e.which == 1) || (e.button == 0)) )
  		{  		    
  				//If the id exists then fade it
	  		if(document.getElementById(dyn_id))
	           {
	          //   alert('others'); 
	          	Effect.Fade(dyn_id,{duration:0.0});
	          } 
           }
 	}
 	
 	ansdiv="";
 	
 		var dyn_id='answerfield';
  		if((answerdiv != dyn_id) && ((e.which == 1) || (e.button == 0)) )
  		{
  			//If the id exists then fade it
	  		if(document.getElementById(dyn_id))
	           {
	            	Effect.Fade(dyn_id,{duration:0.0});
	           } 
        }
       answerdiv="";    
 	 
 	for(i=0;i<30;i++)
    {		
   			var dyn_id='addtodirectory'+i;
  			if((divid != dyn_id) && ((e.which == 1) || (e.button == 0)) )
  			{	  			
  				//If the id exists then fade it
	  			if(document.getElementById(dyn_id))
	            {
	            	document.getElementById(dyn_id).innerHTML="";	              
	            } 
            }
 	}
 	  
	if(divid!='loginbox')
	{	if(document.getElementById('loginbox'))
		{
			document.getElementById('loginbox').style.display="none";
		}
	}
 	
	if(divid!='web20_results')
	{	if(document.getElementById('web20_results'))
		{
			document.getElementById('web20_results').style.display="none";
            if(document.getElementById('flash_cont')){
    			document.getElementById('homepage_image').style.display="none";
    			document.getElementById('flash_cont').style.display="";		
    		}
		}
	}

	//This variable 20 has to be changes according to the number of records per page
	//Close of popups corresponding to add/remove user
    for(i=0;i<20;i++)
    {		
   			var dyn_id='remove_user'+i;
  			if((removediv != dyn_id)  && ((e.which == 1) || (e.button == 0)) )
  			{	
  				//If the id exists then fade it
	  			if(document.getElementById(dyn_id))
	            {	document.getElementById(dyn_id).innerHTML="";
	            	//Effect.Fade(dyn_id,{duration:0.0});
	            } 
            }
 	}
 	 	
		
	if ((flag != 1) && ((e.which == 1) || (e.button == 0)) )
	{
     	for(i=0;i<20;i++)
        {		//Description notes // description is the id of the div that gets populated in notes
       			var dyn_id='description'+i;
       			if(document.getElementById(dyn_id))
    	        {
       			if(descdiv == dyn_id)
       			{   			  
       			  if( divid != dyn_id )
       			  {    	  			
    	            	$(dyn_id).style.visibility='visible';
    	            	var sec = i+1;
    	            	var third = i+2;
    	            	var dyn_id2='description'+sec;
    	            	var dyn_id3='description'+third;
    	            	if($(dyn_id2)){    	            	
    	            	$(dyn_id2).style.visibility='visible';}
    	            	if($(dyn_id3)){    	            	
    	            	$(dyn_id3).style.visibility='visible';}    	           
        	            var sec = i+1;
    	            	var third = i+2;
    	            	var dyn_id2='description'+sec;
    	            	var dyn_id3='description'+third;
    	            	if($(dyn_id2)){
    	            	$(dyn_id2).style.visibility='visible';}
    	            	if($(dyn_id3)){    	            	
    	            	$(dyn_id3).style.visibility='visible';}
    	          }
    	        }
    	        }
    	               var sec = i+1;
    	            	var third = i+2;
    	            	var dyn_id2='description'+sec;
    	            	var dyn_id3='description'+third;
    	            	if($(dyn_id2)){    	            	
    	            	$(dyn_id2).style.visibility='visible';}
    	            	if($(dyn_id3)){    	            	
    	            	$(dyn_id3).style.visibility='visible';}    	           
        	            var sec = i+1;
    	            	var third = i+2;
    	            	var dyn_id2='description'+sec;
    	            	var dyn_id3='description'+third;
    	            	if($(dyn_id2)){
    	            	$(dyn_id2).style.visibility='visible';}
    	            	if($(dyn_id3)){    	            	
    	            	$(dyn_id3).style.visibility='visible';}
     	}
     
 	}
 	// flagdiv=0;
          // dropdown id is the id of the more actions popup in QnA module        
         // if(flagdiv == 0)
          //{
          for(i=1;i<=10;i++)
            {	
                //Page_tag is the id of the div that gets populated in moretags popup
                var dyn_id = 'dropdown'+i;
                if((dropdiv != dyn_id))
                {
                        //If the id exists then fade it
                        if(document.getElementById(dyn_id))
                        {                            
                           Effect.Fade(dyn_id,{duration:0.0});
                        } 
                }
           }                          
        //  }
        // end of dropdown id more actions popup
                  
        if (flag_remove != 1)
 	{
 	  if($('removerow'))
 	  {
 	    if ( $('removerow').style.display == 'block' )
    	{   
    	       $('removerow').style.display='none';	  
    	}
      }
 	}
 	 if($('error_note'))
 	  {
 	    if ( $('error_note').style.display == 'block' )
    	{   
    	       $('error_note').style.display='none';	  
    	}
      }
      
      if($('vote_err'))
      {
       if ( $('vote_err').style.display == 'block' )
    	{   
        $("vote_err").style.display="none";
        }
      }
      
 	divid=0;
 	expdiv="";
 	viewexpdiv="";
 	removediv="";
 	dropdiv="";
 	flag=0;
 	ans = 0;
        flagdiv = 0; 
 	flag_remove=0;
 	//descdiv="";
 }
 

//Most browsers provide both pageX/Y and clientX/Y. 
//Internet Explorer is the only current browser that provides clentX/Y, but not pageX/Y.
//If pageX/Y is supplied, pageX/Y is relative to the whole page, and is completely reliable.
//If clientX/Y is supplied, clientX/Y should be relative to displayed portion of page (DOM compatible)
//Owner:Hareesh Kumar (13-Apr-2007)

var IE = document.all

function alertCoord(e) {
  if( !e ) {
    if( window.event ) {
      //Internet Explorer
      
      e = window.event;
    } else {
      //total failure, we have no way of referencing the event
     
      return;
    }
  }
  if( typeof( e.pageX ) == 'number' ) {
    //most browsers
    var xcoord = e.pageX;
    var ycoord = e.pageY;
  } else if( typeof( e.clientX ) == 'number' ) {
    //Internet Explorer and older browsers
    //other browsers provide this, but follow the pageX/Y branch
    var xcoord = e.clientX;
    var ycoord = e.clientY;
    var badOldBrowser = ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
     ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
     ( navigator.vendor == 'KDE' )
    if( !badOldBrowser ) {
      if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //IE 4, 5 & 6 (in non-standards compliant mode)
        xcoord += document.body.scrollLeft;
        ycoord += document.body.scrollTop;
        return [xcoord, ycoord];
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE 6 (in standards compliant mode)
        xcoord += document.documentElement.scrollLeft;
        ycoord += document.documentElement.scrollTop;
       // alert(xcoord);
        //alert(ycoord);
        return [xcoord, ycoord];
      }
    }
  } else {
    //total failure, we have no way of obtaining the mouse coordinates
    return;
  }
 
 	//This is if the scroll is touch the top
  	var xcoord = e.clientX;
    var ycoord = e.clientY;
        
    return [xcoord, ycoord];
  //window.alert('Mouse coordinates are ('+xcoord+','+ycoord+')');
}
 
//This function get the click coordinates and aligns the popup accordinglly
//Owner:Hareesh Kumar (13-Apr-2007)
function event_coordinates(eve,layer,x,y)
{

	//Check for the browser
	if(IE){	
			//var posx=eve.clientX;
			//var posy = eve.clientY;
			
			//For IE getting the pageX,PageY
			var pos = alertCoord();
			var posx=pos[0];
			var posy = pos[1];
		  }
	else {	
			var posx=eve.pageX;
			var posy = eve.pageY;
		 }	

	document.getElementById(layer).style.top=posy+y+"px";
	document.getElementById(layer).style.left=posx-145+"px";

}

function call_script(url,user){

  new Ajax.Updater('errors', '/admin/delete_rss?url='+url+'&user='+user, {asynchronous:true});


}
function call_update(url,user,val){

    new Ajax.Updater('errors', '/admin/update_rss?url='+url+'&user='+user+'&value='+val, {asynchronous:true});
    
}
function trim(str,ids) {
	  var whitespace = new String("\t\n\r");
      var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
          var j=0, i = s.length;
          while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
             j++;
             s = s.substring(j, i);
      }
    document.getElementById(ids).value = s;
}
