divid=0;
expdiv="";
which_div = "";
var sugg_popup="";
var exp_popup="";
//These variables  are to tell if any popup is opened or not...
var variable_for_sliding_up = "";
var div_name = "";
var div_number = 0;



//This function is used to close the popup boxes 
//On click of anywhere except in the popup box the popup's will be closed
function enb(e)
{		
	var e=e || window.event	
	   if (e.button != 2){
    		if(document.getElementById('app'))
    		{	
    			Effect.Fade('app',{duration:0.1});
    		}
		
		if (divid!='wn2')
		{	if(document.getElementById('wn2'))
			{
				Effect.Fade('wn2',{duration:0.1});
			}
		}

		if (divid!='tag_form')

		{	if(document.getElementById('tag_form'))
			{
				Effect.Fade('tag_form',{duration:0.1});
			}
		}

		if (divid!='detail_bio')
		{ 	if(document.getElementById('detail_bio'))
			{
				Effect.Fade('detail_bio',{duration:0.1});
			}
		}

		if (divid!='delete_sugg_expert')
		{	
			if(document.getElementById('delete_sugg_expert'))
			{
				Effect.Fade('delete_sugg_expert',{duration:0.1});
			}
		}
		if (divid!='story_form')
		{	

			if(document.getElementById('story_form'))
			{
				Effect.Fade('story_form',{duration:0.1});
			}
		}


		if (divid!='terms_popup')
		{	
			if(document.getElementById('terms_popup'))
			{
		
				Effect.Fade('terms_popup',{duration:0.0});
			}
		}
		
    	//	if (divid!='tagresult')
		//{	
	   //		if(document.getElementById('tagresult'))
	   //		{
		
    	//			Effect.Fade('tagresult',{duration:0.2});
        //			}
        //		}
		
		if (divid == 'menu' )
		{ 
			if(divid != 'experts_category_popup' && divid != 'menu')
			{	
				Effect.Fade('experts_category_popup',{duration:0.1});
			}
		}
		if (divid == 0 )
		{	
		if(document.getElementById('experts_category_popup')){
			Effect.Fade('experts_category_popup',{duration:0.1});
			document.getElementById('experts_category_popup').innerHTML="";
			document.getElementById('experts_category_popup').style.display="block";
			Effect.Appear('experts_category_popup',{duration:0.1});
			}
			arlength=document.getElementsByClassName('myart_popup');

for(i=0;i<arlength.length;i++){
if(document.getElementById(arlength[i].id))
 Effect.Fade(arlength[i].id,{duration:0.0});
 }
		}
		
		var div =expdiv.substring(0,4);
		if (div != 'menu')
		{
			clear();
			clear_menu();
		}
		divid=0;
		expdiv="";
		
		clear_reason_more();
		
		clear_all_popups();
		
	}
		
		if (hidemenu_onclick=="yes")
			hidemenu;
            
            //This function just Slides up all the open popup tags
//    		click_anywhere();
            
            //slide_up_all();
		
		
}

//On click of anywhere in the page this function will be called
document.onclick=enb;

//Get the div id and assign to the variable
function getId(id)
{	

    divid=id;	
	expdiv=id;


	return true;
}


//This function get the click coordinates and aligns the popup accordinglly
 function calljsc(e,layer,y,x)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
		
	}
	else{ if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	
		
	}
	}
	
	document.getElementById(layer).style.top=posy-y+"px";
	document.getElementById(layer).style.left=posx+x+"px";

}

//This function get the click coordinates and aligns the popup accordinglly. This is used for experts category popup 
function calljsc2(e,layer,div,num)
{
	
	var div_name=div+num;
	var elm = document.getElementById(div_name);
	if (elm)
	{
	x=elm.offsetLeft;
	y=elm.offsetTop;
	
	}

	document.getElementById(layer).style.top=y-120+"px";
	document.getElementById(layer).style.left=x+"px";

}

function callalign(e,layer,y,x)
{

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else{ if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	
		
	}
	}
	
document.getElementById(layer).style.top=posy-y+"px";
document.getElementById(layer).style.left=posx-x+"px";

}

function menu(eve)
 {
 
 var a = eve.clientX;
  var b = eve.clientY;
	setTimeout("calljscmenu("+a+","+b+",\'app\',120,10)",3000); 
 }

 function showad(){

 Effect.Appear('advertise',{duration:0.1});
 }
 
 //To focus the cursor to the first field of the login form
 function login()
 {
 document.getElementById('ttt').focus();
 }
 
//To focus the cursor to the first field of the login form
 
 //To focus the cursor to the first field of the Search in Wizard
// function search_expert_in_wizard()
// {
// document.getElementById('search_expert').focus();
// }
 
 
  //To focus the cursor to the first field of the registration form
 function register()
 {
 document.getElementById('first_name').focus();
 }
 
 //To focus the cursor to the first field of the rnewsletter form
 function newsletter()
 {
 document.getElementById('new_name').focus();
 }
 
//This function is used to align the height of the div's in the index page 
//Maximum div height is given to all three div (latest experts , latest suggestions and latest from blog) 
 function index_height()
  {	
  if (document.getElementById("feed"))
  var feed_hei = document.getElementById("feed").offsetHeight;
  else
  var feed_hei=0;
  var sugg_hei = document.getElementById("sugg").offsetHeight;
  var exp_hei = document.getElementById("expert").offsetHeight;
  
  var myArray = new Array(feed_hei,sugg_hei,exp_hei);
  for (var i=0; i<(myArray.length-1); i++)
        for (var j=i+1; j<myArray.length; j++)
            if (myArray[j] < myArray[i]) {
                var dummy = myArray[i];
                myArray[i] = myArray[j];
                myArray[j] = dummy;
            }
             if (document.getElementById("feed"))
    document.getElementById("feed").height=myArray[2];
    document.getElementById("sugg").height=myArray[2];
    document.getElementById("expert").height=myArray[2];
    
  }
 
//This function is used to align the height of the div's in the index page 
//Maximum div height is given to all three div (suggestica insight and featured expert) 
  function insight_height()
  {   var fea_hei = document.getElementById("featured_exp").offsetHeight;
	  var insight_hei = document.getElementById("insight").offsetHeight;
	
	  var myArray = new Array(fea_hei,insight_hei);
	  for (var i=0; i<(myArray.length-1); i++)
	        for (var j=i+1; j<myArray.length; j++)
	            if (myArray[j] < myArray[i]) {
	                var dummy = myArray[i];
	                myArray[i] = myArray[j];
	                myArray[j] = dummy;
	            }
	    document.getElementById("featured_exp").height=myArray[1];
	    document.getElementById("insight").height=myArray[1];
	     	
  }
 
    function clear_all_popups()
    {
        if(which_div == "tagresult")
        {
            if(document.getElementById('sort_type'))
            {
                document.getElementById('sort_type').style.display = "none";
                which_div = "";
    //            Effect.SlideUp('sort_type');
            }
        }

        if(which_div == "sort_type")
        {
            if(document.getElementById('tagresult'))
            {
                document.getElementById('tagresult').style.display = "none";
                which_div = "";
    //            Effect.SlideUp('tagresult');
            }
        }
    
    }

//    var set_this_when_clicked_inside_popup = 1;
    
    //This function just retains the div called "tagresult"
    function retain_this_tags()
    {
//        document.getElementById('tagresult').style.display = "";
//        which_div = "tagresult";
    }
    
    //This function just retains the div called "sort_type"
    function retain_this_sort()
    {
        document.getElementById('sort_type').style.display = "";
        which_div = "sort_type";
    }    
    


    //These functions just close all the popups when clicked on the document or any other popup.
    
    //Click anywhere outside
    function click_anywhere()
    {


/*
        if(variable_for_sliding_up != "")
        {
            Effect.SlideUp(variable_for_sliding_up);
        }
        
        if(div_name != "")
        {
            div_to_slideup = div_name+div_number;
            Effect.SlideUp(div_to_slideup);
        }
*/
    }
    
    function assign_null_to_variable_for_sliding_up()
    {
        variable_for_sliding_up = "";
        div_name = "";
    }
    
    //This function just SlidesDown and SlidesUp the popups.
    function slide_down_effect(show_this,hide_this)
    {

        if(variable_for_sliding_up == show_this)
        {
            Effect.SlideUp(show_this);
            variable_for_sliding_up = "";
        }
        else
        {

            Effect.SlideDown(show_this);

            if(variable_for_sliding_up != "" && document.getElementById(hide_this))
            {
                Effect.SlideUp(hide_this);
//              display_none(hide_this);
            }
            variable_for_sliding_up = show_this
        }


        if(div_name != "")
        {
            div_to_slideup = div_name+div_number;
            Effect.SlideUp(div_to_slideup);
            div_name = "";
        }
        inactive_image(123,'arrow_down','arrow_up');
        inactive_image(123,'arrow_down2','arrow_up2');
        //document.getElementById(showsort).style.display = 'block';
    }

    //This method is to make the style.display as none.
    function display_none(hide_this)
    {
        if(hide_this == "tagresult")
        {
           hide_tags(); 
        }
        
        if(hide_this == "sort_type")
        {
           hide_sort(); 
        }
    }

    function hide_tags()
    {
        document.getElementById('tagresult').style.display = "none";
    }

    function hide_sort()
    {
        document.getElementById('sort_type').style.display = "none";
    }
    
    //This function just Slides up all the Popups..
    function slide_up_all()
    {

        if(variable_for_sliding_up == "tagresult")
        {
           Effect.SlideUp('tagresult'); 
           variable_for_sliding_up = "";
        }
        
        if(variable_for_sliding_up == "sort_type")
        {
           Effect.SlideUp('sort_type'); 
           variable_for_sliding_up = "";
        }
        
        if(div_name != "")
        {
            div_to_slideup = div_name+div_number;
            Effect.SlideUp(div_to_slideup);
        }
        
    }
    
    //This function is to SlideUp tags, sort and other divs when a delete is clicked.
    function slide_up_others(name_of_div,number_of_div)
    {

        
        if(variable_for_sliding_up == "tagresult")
        {
           Effect.SlideUp('tagresult'); 
           variable_for_sliding_up = "";
           inactive_image(123,'arrow_down','arrow_up');
        }
        
        if(variable_for_sliding_up == "sort_type")
        {
           Effect.SlideUp('sort_type'); 
           variable_for_sliding_up = "";
           inactive_image(123,'arrow_down2','arrow_up2');
        }
        
        if(div_name != "")
        {
            if(div_name+div_number != name_of_div+number_of_div)
            {
                div_to_slideup = div_name+div_number;
                Effect.SlideUp(div_to_slideup);
                Effect.SlideDown(name_of_div+number_of_div);
                div_number = number_of_div;
            }
            
        }
        else
        {
            Effect.SlideDown(name_of_div+number_of_div);
            div_name = name_of_div;
            div_number = number_of_div;
        }
        


        
    }
    
    //This is to SlideUp the Popups.
    function slide_up(name,number)
    {
        Effect.SlideUp(name+number);
    }
           
 
    function check(number)
    {
//        alert(number);
    }
 
    function hide_1(w_id)
    {

     if(exp_popup){
     Effect.Fade("ap_"+exp_popup,{duration:0.1});
     exp_popup="";
     }
    
    if(sugg_popup){

     Effect.Fade("pp_"+sugg_popup,{duration:0.1});
     sugg_popup="";
     }

     sugg_popup=w_id;
     Effect.Appear('pp_'+sugg_popup);   
    }
    
    function hide_2(e_id)
    {

    if(sugg_popup){
     Effect.Fade("pp_"+sugg_popup,{duration:0.1});
     sugg_popup="";

     }

     
    if(exp_popup){
     if(exp_popup!=e_id)       {
     Effect.Fade("ap_"+exp_popup,{duration:0.1});
     exp_popup="";
          }
     }
    
     exp_popup=e_id;
     Effect.Appear('ap_'+exp_popup);   
    }
    
    