var under_this_tag  =   "";
var radio_size    =   "";
var root_tag    ="";
var root_tags    ="";
var rename_tag_root ="";
var rename_tothis_tag = "";
var rename_id = "";
var disp_id = "";
var from_here ="";
var checked_id ="";
function check_selected_expert(){
cnt = document.getElementById('count_page');
		protocol=window.location.protocol+"//"+window.location.hostname+":"+window.location.port;	
		count_per_page = cnt.options[cnt.selectedIndex].text;
		window.location.href = protocol+'';
		window.load();
}

 function change_pointer(id_name)
    {        
        document.getElementById(id_name).style.cursor = "pointer";
    }

// This function defined to close the taggit popup
function close_tagit(closeid)	    {
        document.getElementById(closeid).style.display="none";
}
// This function defined to show that page is loading
function showBusy(){
    document.getElementById('busy').style.display='block';
}
// This function defined to hide the page loading image
function hideBusy(){
    document.getElementById('busy').style.display='none';
}

//This function is called while removing a contact from watchlist
//Hareesh Kumar
    function close_div(id)
    {	
    	document.getElementById(id).innerHTML="";
    }

// This function is called from both layouts, on entering search words.   Search scope is Web2.0
	 function auto_complete(se_te,here,e){
	       
            se_te = se_te.replace(/%/g, '%20' );        
            se_te = se_te.replace(/{/g, '%20' );                    
            se_te = se_te.replace(/}/g, '%20' );                    
            se_te = se_te.replace(/>/g, '%20' );                              
            se_te = se_te.replace(/</g, '%20' );                                  
            se_te = se_te.replace(/:/g, '%20' );            
            se_te = se_te.replace(/;/g, '%20' );                    
            se_te = se_te.replace(/~/g, '%20' );                              
            se_te = se_te.replace(/./g, '%20' );
            se_te = se_te.replace(/`/g, '%20' ); 
            se_te = se_te.replace(/#/g, '%20' ); 
            se_te = se_te.replace(/\^/g, '%20' ); 
            se_te = se_te.replace(/!/g, '%20' ); 
            se_te = se_te.replace(/@/g, '%20' ); 
            se_te = se_te.replace(/\(/g, '%20' ); 
            se_te = se_te.replace(/\)/g, '%20' ); 
            se_te = se_te.replace(/\-/g, '%20' );
//            se_te = se_te.replace(/\</g, '%20' );
//            se_te = se_te.replace(/\"/g, '%20' );
//            se_te = se_te.replace(/\>/g, '%20' );
            //se_te = se_te.replace(/ /g, '%20');          
           
    	        document.getElementById('web20_results').style.display="";        	
                new Ajax.Updater('auto', '/home/suggest_search?sug_search='+se_te+'&here='+here, {asynchronous:true, evalScripts:true,
                onLoading:function(request){Element.hide('flash_cont'),Element.show('homepage_image')},
                onComplete:function(request){}});            
         
	 }   

// This function is called from both layouts, on entering search words.   Search scope is My Directory
	 function auto_directory(se_te,e){
	       if(e.keyCode!=13) 
            {
                
                document.getElementById('web20_results').style.display="block";	 
    	       new Ajax.Updater('auto', '/home/suggest_search?sug_search='+se_te); return false;
    	    }   	       
	 }   

// This function is called from both layouts, on entering search words.   Search scope is My Watchlist
	 function auto_watchlist(se_te,e)
	 {
	        
    	    if(e.keyCode!=13) 
            {                
	           document.getElementById('web20_results').style.display="block"; 
    	       new Ajax.Updater('auto', '/home/suggest_search?sug_search='+se_te); return false;
    	    }
	 }   


// This function places the suggested search word in the search box
    function show_a(take){
        search_word = take;
        document.getElementById('suggested_words').value=search_word; 
        document.getElementById('web20_results').style.display="none";
        if(document.getElementById('flash_cont'))    
        {
        document.getElementById('flash_cont').style.display="block";
        document.getElementById('homepage_image').style.display="none";
        }
    }
 //To focus the cursor to the first field of the login form
 function focus_here(focus_field)
 {
 document.getElementById(focus_field).focus();
 }

// This function is called to generate RSS.   Search scope is My Watchlist
	 function gen_rss(){
	         rss = document.getElementById('suggested_words').value; 
	         scope='rss'
	         document.getElementById('web20_results').style.display="block"; 
    	    new Ajax.Updater('rssauto', '/home/rss?q='+rss+'&scope='+scope); return false;
	 }   
// This function is called from both layouts, on entering search words.   Search scope is Web2.0
	 function auto_tagit(se_te,here,e){
	   
        var c2=new Array();
        c2 = se_te.split(',');
        var len=c2.length;
        var subc = c2[len-1];
        
        if(e.keyCode!=13) 
         {
            se_te = se_te.replace(/%/g, '%25' );        
            se_te = se_te.replace(/{/g, '%7B' );                    
            se_te = se_te.replace(/}/g, '%7D' );                    
            se_te = se_te.replace(/>/g, '%3E' );                              
            se_te = se_te.replace(/</g, '%3C' );                                  
            se_te = se_te.replace(/:/g, '%3A' );            
            se_te = se_te.replace(/;/g, '%3B' );                    
            se_te = se_te.replace(/~/g, '%7E' );                              
            se_te = se_te.replace(/`/g, '%60' );
            se_te = se_te.replace(/./g, '%20' );            

  	        document.getElementById('web20_results').style.display="";  
            new Ajax.Updater('auto', '/home/suggest_search?sug_search='+subc+'&here='+here, {asynchronous:true, evalScripts:true,onComplete:function(request){}});            
       }     
	 }   
// This function places the suggested search word in the Tags field of tagit popup extension & search fields of site.
// Modified     : 26-Apr-2007
// Modification : To allow multiple word selection both for tags and search
    function show_b(take){
                search_word = take;
                var c1 = document.getElementById('suggested_words').value;
                c2 = c1.lastIndexOf(',');
                var subc = (c1.substring(0,c2));    
                if (subc != ""){          
                    document.getElementById('suggested_words').value = subc +','+search_word
                }
                else{
                    document.getElementById('suggested_words').value = search_word
                }    
        document.getElementById('web20_results').style.display="none";
        document.getElementById('suggested_words').focus();
        if(document.getElementById('flash_cont'))    
        {
        document.getElementById('flash_cont').style.display="block";
        document.getElementById('homepage_image').style.display="none";
        }
    }
	 
 
// This function related to tag hierarchy
// created  : 03 - May - 2007
function cancel_newtag(tagslot,tag1){
    document.getElementById(tagslot).style.display  = "none";
    document.getElementById(tag1).value="";
}

// Displays the message that tag is successfully added
function success_msg_old(disp_msg){

    msg = disp_msg.substring(6);
    for(i=0;i<6;i++)
    {
           msg1 = "su_msg"+i 
           if(msg1 == disp_msg){
               if(document.getElementById(msg1)){ 
                   document.getElementById(msg1).style.display  = "block";
               }
           }
           else{
               if(document.getElementById(msg1)){ 
                   document.getElementById(msg1).style.display  = "none";           
               }
           }
    }
}

function success_msg(disp_msg){
var closemessage='close_msg("inner_msg");'
var refresh     ='reload();'

    document.getElementById("inner_msg").style.display = "block";
    if(disp_msg == "su_msg0"){
        document.getElementById("inner_msg").innerHTML= '<div>You have successfully renamed the tag.&nbsp;&nbsp;&nbsp;<font onClick='+closemessage+' style="padding-left:100px;cursor:pointer;cursor:hand;">x</font></div>'
    }
    if(disp_msg == "su_msg1"){
        document.getElementById("inner_msg").innerHTML= '<div>You have successfully added the tag.&nbsp;&nbsp;&nbsp;<font onClick='+closemessage+' style="padding-left:100px;cursor:pointer;cursor:hand;">x</font></div>'
    }
    if(disp_msg == "su_msg2"){    
        document.getElementById("inner_msg").innerHTML= '<div>You have successfully deleted the tag(s).&nbsp;&nbsp;&nbsp;<font onClick='+closemessage+refresh+' style="padding-left:100px;cursor:pointer;cursor:hand;" OnClick="javascript:window.refresh();">x</font></div>'  
    }
    if(disp_msg == "su_msg3"){    
        document.getElementById("inner_msg").innerHTML= '<div>You have successfully pasted the tag(s) from clipboard.&nbsp;&nbsp;&nbsp;<font onClick='+closemessage+refresh+' style="padding-left:100px;cursor:pointer;cursor:hand;">x</font></div>'  
    }
    if(disp_msg == "su_msg4"){    
        document.getElementById("inner_msg").innerHTML= '<div>You have successfully copied the tag(s) to clipboard.&nbsp;&nbsp;&nbsp;<font onClick='+closemessage+' style="padding-left:100px;cursor:pointer;cursor:hand;">x</font></div>'  
    }
    if(disp_msg == "su_msg5"){    
        document.getElementById("inner_msg").innerHTML= '<div>You have successfully cut the tag(s) to clipboard.&nbsp;&nbsp;&nbsp;<font onClick='+closemessage+' style="padding-left:100px;cursor:pointer;cursor:hand;">x</font></div>'  
    }

}

// Refreshes the pages
function reload(){
    location.reload(true);
}


// Close the message
function close_msg(msg){
    document.getElementById(msg).style.display  = "none";
}

// Displays the fields to store the tags
function show_slot(){
    document.getElementById('enter_tag1').value  = "";
    document.getElementById('enter_tag').style.display  = "block";
}

function show_txt_field(){
    document.getElementById('tag1').value  = "";
    document.getElementById('tag_slot').style.display  = "block";
}


function close_message(){
    document.getElementById('tag_added').style.display  = "none";
}

// This function is not been used; but based on this logic show_chidld2() is written
function show_child(ch){
    ch_name = ch.className;
    ch= ch.id;
    ch1=ch+1;
    ch2=ch+2;    
    ch3=ch+3;
    ch4=ch+4;    
    minusicon ="minus"+ch;
    plusicon = "plus"+ch;
if(document.getElementById(ch1)){
    if(document.getElementById(ch1).style.display=="none"){
    
        document.getElementById(ch1).style.display="";
            if(document.getElementById(plusicon).style.display=="block"){
            document.getElementById(plusicon).style.display="none";    
            document.getElementById(minusicon).style.display="block";    
            }    
           
    
    }    
    else{
    document.getElementById(ch1).style.display="none";
    if(document.getElementById(plusicon).style.display){
    document.getElementById(plusicon).style.display="block";    
    document.getElementById(minusicon).style.display="none";          
    }
    }    
}    

    if(document.getElementById(ch2)){
        document.getElementById(ch2).style.display="";
        if(document.getElementById(plusicon).style.display=="block"){
        document.getElementById(plusicon).style.display="none";    
        document.getElementById(minusicon).style.display="block";    
        }   
        else{
        document.getElementById(plusicon).style.display="block";    
        document.getElementById(minusicon).style.display="none";          
        }
         
    }

    if(document.getElementById(ch3)){

    document.getElementById(ch3).style.display="";
        if(document.getElementById(plusicon).style.display=="block"){
        document.getElementById(plusicon).style.display="none";    
        document.getElementById(minusicon).style.display="block";    
        }    
        else{
        document.getElementById(plusicon).style.display="block";    
        document.getElementById(minusicon).style.display="none";          
        }
        
    }
    
    if(document.getElementById(ch4)){
    document.getElementById(ch4).style.display="";
        if(document.getElementById(plusicon).style.display=="block"){
        document.getElementById(plusicon).style.display="none";    
        document.getElementById(minusicon).style.display="block";    
        }    
        else{
        document.getElementById(plusicon).style.display="block";    
        document.getElementById(minusicon).style.display="none";          
        }
   
    }    
}

// This function does show/hide of the child tags (if present)
function show_child2(ch){
    var radio_length = document.getElementsByClassName("tag_radio").length;
// loop over the length of the tag levels starting for radio button sake
var rl;
var ul;
    for(rl=0;rl<radio_length;rl++){
        var rad = "radio"+ch;
    }
// loop over the length of the tag levels ending for radio button sake

   var unique_length = document.getElementsByClassName("unique").length;
// loop over the length of the tag levels starting

    for(ul=0;ul<unique_length;ul++){
        var minusicon ="minus"+ch;    
        var plusicon = "plus"+ch;
        if(document.getElementById(ch+ul)){
            if(document.getElementById(ch+ul).style.display=="none"){
                document.getElementById(ch+ul).style.display="";
                    if(document.getElementById(plusicon).style.display=="block"){
                    document.getElementById(plusicon).style.display="none";    
                    document.getElementById(minusicon).style.display="block";    
                    }    
                   
            
            }    
            else{

            document.getElementById(ch+ul).style.display="none";
	    if(document.getElementById(plusicon)){	
	            if(document.getElementById(plusicon).style.display=="none"){
		            document.getElementById(plusicon).style.display="block";    
		            document.getElementById(minusicon).style.display="none";          
	            }
	    }	
            }    
        }    
        
        
        
    }
// loop over the length of tag levels is ending    
  
}

// This function is called in click of new tag
function new_tag(){
$('delete_tag').style.display = "none";
$('add_tag').style.display = "none";
$('empty_tag').style.display = "none";
$('ren_tag').style.display = "none";
$('copy_tag').style.display = "none";
$('cut_tag').style.display = "none";
$('pas_tag').style.display = "none";
    document.getElementById("inner_msg").style.display = "none";  
    radio_length = document.getElementsByClassName("tag_radio").length;
    radio_elements = document.getElementsByClassName("tag_radio");    
    var cancel_tag_box = 'cancel_newtag("tag_slot");'

// This displays the new tag field opotion when user creating the hierarchy for the first time.
 if(document.getElementById("my_tags").checked){

        document.getElementById("tag_slot").style.display="block";                    			     
//        document.getElementById("tag_slot").innerHTML ='<table width="100%" border="0" align="right" cellpadding="0" cellspacing="4"><tr><td align="right" valign="middle" width="98%" ><input type="text" id="tag1" class="htagsfields" align="left" valign="middle"/></td><td align="right" valign="middle" width="1%" ><input name="imageField2" type="image" src="/images/button_save_01.gif" align="middle" /></td>                                                <td align="right" valign="middle" width="1%" ><input name="imageField3" type="image" onClick='+cancel_tag_box+' src="/images/button_cancel_01.gif" align="middle" /></td></tr></table> ';
                                                  
 }

    for(rl=0;rl<radio_length;rl++){
			if(radio_elements[rl].checked==true){
			    radio_id = radio_elements[rl].id;
			    checked_id= radio_id.substring(5);
			    radio_size = radio_id.length;
			    radio_loop  =  radio_size-5;
			    root_tag ='';
                        for(i=0;i<radio_loop;i++){
                            under_this_tag  = document.getElementById(radio_id).value;                  
                            radio_id        = radio_id.substring(0,radio_size-1);
            			    radio_size      = radio_id.length;                    
                            root_tag        = under_this_tag+'>'+root_tag;   
                            if(root_tag.charAt(0)==">"){            
                                root_tag    = root_tag.substring(1,root_tag.length)
                            }  
                        }
                          document.getElementById("tag_slot").style.display="block";                    			     
//                       document.getElementById("tag_slot").innerHTML ='<table width="100%" border="0" align="right" cellpadding="0" cellspacing="4"><tr><td align="right" valign="middle" width="98%" ><input type="text" id="tag1" class="htagsfields" align="left" valign="middle"/></td><td align="right" valign="middle" width="1%" ><input name="imageField2" type="image" src="/images/button_save_01.gif" align="middle" /></td>                                                <td align="right" valign="middle" width="1%" ><input name="imageField3" type="image" onClick='+cancel_tag_box+' src="/images/button_cancel_01.gif" align="middle" /></td></tr></table> ';
    }

    }
    
}

// This function sets the user entered tag in the hierarchy.  The slected radio option will be taken as parent.
function set_tag(uname1,pwd1){

         uname = document.getElementById(uname1).value;
         pwd   = document.getElementById(pwd1).value;
        var newtag     = document.getElementById('tag1').value;
        var iChars = "!@#$%^&*()+=[]\\\';,/{}|\":<>?";
        var count=0;
  for (var i = 0; i < newtag.length; i++) {
  	if (iChars.indexOf(newtag.charAt(i)) != -1) {
  	count=count+1;
  	Effect.Appear("error_tag");
    msg = setTimeout('Effect.Fade("error_tag")',10000);
  	}
  }
    if (count==0){ 
        if(newtag!='')
        {
            // This to called when the request is from new tags
        
    		 if(document.getElementById("my_tags").checked)
    		 {
                     newtag     = newtag.replace(/>/g, '%3E' );   
                     newtag = newtag.replace(/{/g, '%7B' );                    
			         newtag = newtag.replace(/}/g, '%7D' );                    
			         newtag = newtag.replace(/>/g, '%3E' );                              
			         newtag = newtag.replace(/</g, '%3C' );                                  
			         newtag = newtag.replace(/:/g, '%3A' );            
			         newtag = newtag.replace(/;/g, '%3B' );                    
			         newtag = newtag.replace(/~/g, '%7E' );                              
			         newtag = newtag.replace(/`/g, '%60' );      
			         //alert(newtag);                       
    		  	 new Ajax.Updater('update_tag_hierarchy', '/user_account/set_tag_hierarchy?username='+uname+'&password='+pwd+'&action1=new&newtag='+newtag, {asynchronous:true, evalScripts:true,onComplete:function(request){add_tag();}});           
								 				 
             }        
    
            // This to called when the request is for new sub tags
            else
            {
             root_tag   = root_tag.replace(/>/g, '%3E' );   
             newtag     = newtag.replace(/>/g, '%3E' );    
             newtag = newtag.replace(/{/g, '%7B' );                    
			         newtag = newtag.replace(/}/g, '%7D' );                    
			         newtag = newtag.replace(/>/g, '%3E' );                              
			         newtag = newtag.replace(/</g, '%3C' );                                  
			         newtag = newtag.replace(/:/g, '%3A' );            
			         newtag = newtag.replace(/;/g, '%3B' );                    
			         newtag = newtag.replace(/~/g, '%7E' );                              
			         newtag = newtag.replace(/`/g, '%60' );      
			         //alert(newtag);     
                                
             new Ajax.Updater('update_tag_hierarchy', '/user_account/set_tag_hierarchy?username='+uname+'&password='+pwd+'&action1=new&tags='+root_tag+'&newtag='+newtag, {asynchronous:true, evalScripts:true,onComplete:function(request){add_tag();}});
			 //alert("You have successfully added the tag."); 
            }
            
        }else{
            //alert("New Tag can not be empty.");
            empty_tag();
        }   
       }  
}

function empty_tag()
{
$('delete_tag').style.display = "none";
$('add_tag').style.display = "none";
//$('empty_tag').style.display = "none";
$('ren_tag').style.display = "none";
$('copy_tag').style.display = "none";
$('cut_tag').style.display = "none";
$('pas_tag').style.display = "none";
document.getElementById('tag1').value  = "";
document.getElementById('tag_slot').style.display  = "none";
Effect.Appear("empty_tag");
msg = setTimeout('Effect.Fade("empty_tag")',10000);

}

function add_tag()
{
$('delete_tag').style.display = "none";
//$('add_tag').style.display = "none";
$('empty_tag').style.display = "none";
$('ren_tag').style.display = "none";
$('copy_tag').style.display = "none";
$('cut_tag').style.display = "none";
$('pas_tag').style.display = "none";
document.getElementById('tag1').value  = "";
document.getElementById('tag_slot').style.display  = "none";
Effect.Appear("add_tag");
msg = setTimeout('Effect.Fade("add_tag")',10000);

}

// This function is called in click of delete tag
function delete_tag(){

    radio_length = document.getElementsByClassName("tag_radio").length;
    radio_elements = document.getElementsByClassName("tag_radio");
    //alert(radio_length);
    for(rl=0;rl<radio_length;rl++){//alert(radio_elements);
                        if(radio_elements[rl].checked==true){//alert(radio_elements[rl].id+"radio_elements");
                            radio_id = radio_elements[rl].id;
                            radio_size = radio_id.length;//alert(radio_size+"size");
                            radio_loop  =  radio_size-5;//alert(radio_loop+"loop");
                            root_tag = '';
                            under_this_tag='';
                            
                        for(i=0;i<radio_loop;i++){//alert(radio_id,);
                            under_this_tag  = document.getElementById(radio_id).value;
                            //alert(under_this_tag+"under_this_tag");
                            radio_id        = radio_id.substring(0,radio_size-1);
                            //alert(radio_id,+"radio_id");
                                    radio_size      = radio_id.length;
                                    //alert(radio_size+"radio_size");
                                    
                            root_tag        = under_this_tag+'>'+root_tag;
                           //alert(root_tag,+"root_tag2");
                            if(root_tag.charAt(0)==">"){
                                root_tag    = root_tag.substring(1,root_tag.length)

                            }


                        }
                        //alert(root_tag);
         root_tag = root_tag.replace(/>/g, '%3E' ); 
                                        
         uname = document.getElementById("sth_username").value;
         pwd   = document.getElementById("sth_password").value;
         //alert(root_tag);
         new Ajax.Updater('update_tag_hierarchy', '/user_account/set_tag_hierarchy?username='+uname+'&password='+pwd+'&action1=delete&tags='+root_tag, {asynchronous:true, evalScripts:true,onComplete:function(request){del_tag();}});
         root_tag=" "
                        }
    }
}
function del_tag()
{
//$('delete_tag').style.display = "none";
$('add_tag').style.display = "none";
$('empty_tag').style.display = "none";
$('ren_tag').style.display = "none";
$('copy_tag').style.display = "none";
$('cut_tag').style.display = "none";
$('pas_tag').style.display = "none";
Effect.Appear("delete_tag");
msg = setTimeout('Effect.Fade("delete_tag")',10000);

}

// This function is called in click of rename tag
function rename_tag(){
 root_tag ="";
    radio_length = document.getElementsByClassName("tag_radio").length;
    radio_elements = document.getElementsByClassName("tag_radio");    

    for(rl=0;rl<radio_length;rl++){
    
    			if(radio_elements[rl].checked==true){//alert(radio_elements[rl].id);
			    radio_id1 = radio_elements[rl].id;
			    radio_id  = radio_elements[rl].id;
			    radio_size = radio_id1.length;
			    radio_loop  =  radio_size-5;

                        for(i=0;i<radio_loop;i++){
                            under_this_tag  = document.getElementById(radio_id).value;                  
                            radio_id        = radio_id.substring(0,radio_size-1);
            			    radio_size      = radio_id.length;                    
                            root_tag        = under_this_tag+'>'+root_tag;   
                            if(root_tag.charAt(0)==">"){            
                                root_tag    = root_tag.substring(1,root_tag.length-2)
                            }    
                        }
                //rename_id is the global variable and used in rename_the_tag() function                        
                rename_id  = "rename"+radio_id1.substring(5); 
                disp_id    = "disp"+radio_id1.substring(5);  
                if(document.getElementById(rename_id)){
                     document.getElementById("tag_slot").style.display="none"; 
                     document.getElementById(disp_id).style.display="none";
                                      
                     document.getElementById(rename_id).style.display="block";
                } 
                for(i=0;i<20;i++)
                {		//Page_tag is the id of the div that gets populated in tag hierarchy
               			var tb='re_name'+i;              			
              				//If the id exists then focus it
            	  			if(document.getElementById(tb))
            	            {
            	              //  alert(tb);
            	            //	document.getElementById('rename1').focus();
            	            }                         
             	}                
			}               
    }
}


// This function sets the user entered tag in the hierarchy.  The slected radio option will be taken as parent.
function rename_the_tag(e_id){
         renaming_id = "re_name"+e_id
         rename_tothis_tag = document.getElementById(renaming_id).value;

         if(rename_tothis_tag!=''){
             uname = document.getElementById("sth_username").value;
             pwd   = document.getElementById("sth_password").value;
         root_tag           = root_tag.replace(/>/g, '%3E' );  
         
         rename_tothis_tag  = rename_tothis_tag.replace(/>/g, '%3E' );     
                   
               new Ajax.Updater('update_tag_hierarchy','/user_account/set_tag_hierarchy?username='+uname+'&password='+pwd+'&action1=rename&tags='+root_tag+'&newtag='+rename_tothis_tag, {asynchronous:true, evalScripts:true,onComplete:function(request){cancel_rename_tag();ren_tag();}});            
	     //alert("You have successfully renamed the tag.");
         }else{
             //alert("Tag name can not be empty!");
             empty_tag();
         }
}

function ren_tag()
{
$('delete_tag').style.display = "none";
$('add_tag').style.display = "none";
$('empty_tag').style.display = "none";
//$('ren_tag').style.display = "none";
$('copy_tag').style.display = "none";
$('cut_tag').style.display = "none";
$('pas_tag').style.display = "none";
Effect.Appear("ren_tag");
msg = setTimeout('Effect.Fade("ren_tag")',10000);
}

function cancel_rename_tagfields(){

                 document.getElementById(disp_id).style.display="block";                    
                 document.getElementById(rename_id).style.display="none";

}

function cancel_rename_tag(){

                 document.getElementById(disp_id).style.display="block";                    
                 document.getElementById(rename_id).style.display="none";

}


// Following are functions related to clipboard:


function Clipboard()
{  
	this.clear = function()
	{

		this.content = null;

	};
	
	// init
	this.clear();
	this.setContent = function(objContent)
	{
        //alert(objContent+"objContent12323");
		this.content = objContent;

	};
	this.isContentAvailable = function()
	{
		return this.content != null;
	};
	this.getContentType = function()
	{
		return this.contentType;
	};
	this.getContent = function()
	{
		return this.content;
	};
	this.isCut = function()
	{
		return this.cut;
	};
}
clip = new Clipboard();

	function paste()
	{
		
   
		var nodeToCopy = clip.getContent();
		
		return nodeToCopy;
	}

// This function copies the selected root tag content to clipboard
function copy_2_clipboard(){

    from_here ="copying";
    radio_length = document.getElementsByClassName("tag_radio").length;
    radio_elements = document.getElementsByClassName("tag_radio");
    root_tag="";
    for(rl=0;rl<radio_length;rl++){

                        if(radio_elements[rl].checked==true){//alert(radio_elements[rl].id+"id232");
                            radio_id1 = radio_elements[rl].id;
                            radio_id  = radio_elements[rl].id;
                            radio_size = radio_id1.length;
                            radio_loop  =  radio_size-5;

                        for(i=0;i<radio_loop;i++){
                            under_this_tag  = document.getElementById(radio_id).value;
                            
                            radio_id        = radio_id.substring(0,radio_size-1);
                                    radio_size      = radio_id.length;
                            root_tag        = under_this_tag+'>'+root_tag;
                            if(root_tag.charAt(0)==">"){
                                root_tag    = root_tag.substring(1,root_tag.length-2)

                            }
                        }
                        
                clip.setContent(root_tag);
                //success_msg('su_msg4');
                msg_copy();
                        }
    }

}

function msg_copy()
{
$('delete_tag').style.display = "none";
$('add_tag').style.display = "none";
$('empty_tag').style.display = "none";
$('ren_tag').style.display = "none";
//$('copy_tag').style.display = "none";
$('cut_tag').style.display = "none";
$('pas_tag').style.display = "none";
Effect.Appear("copy_tag");
msg = setTimeout('Effect.Fade("copy_tag")',10000);
}


// This function cuts the selected root tag content 
function cut_tags(){
    from_here ="cutting";
    radio_length = document.getElementsByClassName("tag_radio").length;
    radio_elements = document.getElementsByClassName("tag_radio");
    for(rl=0;rl<radio_length;rl++){

                        if(radio_elements[rl].checked==true){
                            radio_id1 = radio_elements[rl].id;
                            radio_id  = radio_elements[rl].id;
                            radio_size = radio_id1.length;
                            radio_loop  =  radio_size-5;
root_tag="";
                        for(i=0;i<radio_loop;i++){
                            under_this_tag  = document.getElementById(radio_id).value;
                            radio_id        = radio_id.substring(0,radio_size-1);
                                    radio_size      = radio_id.length;
                            root_tag        = under_this_tag+'>'+root_tag;
                            if(root_tag.charAt(0)==">"){
                                root_tag    = root_tag.substring(1,root_tag.length-2)

                            }
                        }
                clip.setContent(root_tag);
                //success_msg('su_msg5');
                cut_msg();
                        }
    }

}
function cut_msg()
{
Effect.Appear("cut_tag");
msg = setTimeout('Effect.Fade("cut_tag")',10000);
}


// This function copies the selected root tag content from clipboard
function paste_from_clipboard(){

    radio_length = document.getElementsByClassName("tag_radio").length;
    radio_elements = document.getElementsByClassName("tag_radio");    
    for(rl=0;rl<radio_length;rl++){
    
    			if(radio_elements[rl].checked==true){
			    radio_id1 = radio_elements[rl].id;
			    radio_id  = radio_elements[rl].id;
			    radio_size = radio_id1.length;
			    radio_loop  =  radio_size-5;
                            root_tag = '';
                        for(i=0;i<radio_loop;i++){
                            under_this_tag  = document.getElementById(radio_id).value;  
                            radio_id        = radio_id.substring(0,radio_size-1);
            			    radio_size      = radio_id.length;                    
                            root_tag        = under_this_tag+'>'+root_tag;   
                            
                            if(root_tag.charAt(0)==">"){            
                                root_tag    = root_tag.substring(1,root_tag.length-2)
                            }    
                            if(root_tag.charAt(root_tag.length-1)==">"){            
                                root_tag    = root_tag.substring(0,root_tag.length-1)
                            }    
                            
                        }
                 }                 
     }                   
    
	var paste_this = paste();
    if(paste_this != null){
        if(paste_this.charAt(paste_this.length-1)==">"){            
                paste_this    = paste_this.substring(0,paste_this.length-1);
        }    
    }
    else
    {
        document.getElementById("inner_msg").style.display = "block";
        document.getElementById("inner_msg").innerHTML= '<div>Sorry, you have not copied any tag(s) to clipboard.&nbsp;&nbsp;&nbsp;<font onClick=close_msg("inner_msg"); style="padding-left:10px;cursor:pointer;cursor:hand;">x</font></div>'   
    }    
        
    uname = document.getElementById("sth_username").value;
    pwd   = document.getElementById("sth_password").value;
    var closemessage='close_msg("inner_msg");'    
     root_tag   = root_tag.replace(/>/g, '%3E' );                
    if(paste_this == null){
        document.getElementById("inner_msg").style.display = "block";
        document.getElementById("inner_msg").innerHTML= '<div>Sorry, you have not copied any tag(s) to clipboard.&nbsp;&nbsp;&nbsp;<font onClick='+closemessage+' style="padding-left:10px;cursor:pointer;cursor:hand;">x</font></div>'        
    }
    else{
        paste_this = paste_this.replace(/>/g, '%3E' );  
        if(from_here == "copying"){
            new Ajax.Updater('update_tag_hierarchy', '/user_account/set_tag_hierarchy?username='+uname+'&password='+pwd+'&action1=copy&clipboardtags='+paste_this+'&tags='+root_tag, {asynchronous:true, evalScripts:true,onComplete:function(request){paste_tag();}});            
        }
        else{
            new Ajax.Updater('update_tag_hierarchy', '/user_account/set_tag_hierarchy?username='+uname+'&password='+pwd+'&action1=cut&clipboardtags='+paste_this+'&tags='+root_tag, {asynchronous:true, evalScripts:true,onComplete:function(request){paste_tag();}});                    
        }            
    }
}

function paste_tag()
{
$('delete_tag').style.display = "none";
$('add_tag').style.display = "none";
$('empty_tag').style.display = "none";
$('ren_tag').style.display = "none";
$('copy_tag').style.display = "none";
$('cut_tag').style.display = "none";
$('pas_tag').style.display = "none";
Effect.Appear("pas_tag");
msg = setTimeout('Effect.Fade("pas_tag")',10000);
}

function tag_pref(tag){

    if(document.getElementById(tag).checked){

        new Ajax.Updater('tag_added', '/user_account/set_tag_pref?action1=settaghierarchy&set=true', {asynchronous:true, evalScripts:true,onComplete:function(request){}});                            
    }else{

        new Ajax.Updater('tag_added', '/user_account/set_tag_pref?action1=settaghierarchy&set=false', {asynchronous:true, evalScripts:true,onComplete:function(request){}});                            
    }
}

// This function is called from both layouts, on entering tags.   
	 function auto_tags(se_te){
         document.getElementById('web20_results').style.display="block";	 
    	    new Ajax.Updater('tags_auto', '/home/suggest_tags?sug_tags='+se_te); return false;
	 }   
	 
function tag_results(req){
    alert(req);
}	 
function textbx(present)
{   //alert(present);
$(present).style.width='370px';
	$(present).style.border='1px gray solid';
	$(present).style.background='#dddddd';
	
}
function textout(present)
{  
	$(present).style.border='';
	$(present).style.background='';
	
}
function textbx_search(present)
{
	present.style.cursor='text';
	present.style.width='420px'; 
	present.style.height='15px'; 
	present.style.background='#bde2ff';
	//present.style.border='1px gray outset';
	
}
function textout_search(present)
{
	present.style.background='';
	present.style.border='';
	present.style.width='';
	
}
function removeuser(blog)
{                            
            $('removerow').style.display="block";                    
            $('blog').value=blog;                                                                                                             
}

function editblog(blog,user)
{
            $('editrow').style.display="block";                    
            $('blog').value=blog;
            $('uname').value=user;
}

function saveblog()
{      
          var url=$('blog').value;
          var uname=$('uname').value;
          var desc=$('description').value;          
          new Ajax.Updater('save_blog', '/admin_channel/update_rss?url='+url+'&user='+uname+'&value='+desc, {asynchronous:true, evalScripts:true,onComplete:function(request){}});           
          
          $('editrow').style.display="none";
          $('message').style.display="block";
}

function delete_rss(blog)
{
                    $('removeblog').style.display="block";                    
                    $('blog').value=blog;
}

function removedblog()
{          
          var url=$('blog').value;
          var uname=$('uname').value;                    
          new Ajax.Updater('save_blog', '/admin_channel/delete_rss?url='+url+'&user='+uname, {asynchronous:true, evalScripts:true,onComplete:function(request){check_blog(request);}});
          $('removeblog').style.display="none";
}

function check_blog(request)
{
    $('msg').style.display="block";
    window.reload();
}

function canceledit()
{
     $('editrow').style.display="none";
   //  window.reload();              						
}

function cancel()
{
     $('removerow').style.display="none";
  //   window.reload();              						
}

function notremovedblog()
{
    $('removeblog').style.display="none";
  //  window.reload(); 
}

function settop_tag()
{
            se_te=$('toptag').value;
            
            se_te = se_te.replace(/%/g, '%25' );        
            se_te = se_te.replace(/{/g, '%7B' );                    
            se_te = se_te.replace(/}/g, '%7D' );                    
            se_te = se_te.replace(/>/g, '%3E' );                              
            se_te = se_te.replace(/</g, '%3C' );                                  
            se_te = se_te.replace(/:/g, '%3A' );            
            se_te = se_te.replace(/;/g, '%3B' );                    
            se_te = se_te.replace(/~/g, '%7E' );                              
            se_te = se_te.replace(/`/g, '%60' );            
            se_te = se_te.replace(/\\/g, '%5B' );  
  	        
            new Ajax.Updater('topped', '/channel/sub_top_tag?toptag='+se_te, {asynchronous:true, evalScripts:true,onComplete:function(request){check_toptag(request);}});
}

function check_toptag(request)
{
    var instruction = request.getResponseHeader('X-Instruction');
    
	if(instruction == "OK") 
	{	   
	   Effect.Appear("top_tag");
       msg = setTimeout('Effect.Fade("top_tag")',10000);   
	}
	else
	{
	   $('top_tag').value="Failed on adding as a top tag";
	}
}
function taghierarchy_popup(e)
{
	
 
	new Ajax.Updater('popup', '/user_account/tag_hierarchy_help', {asynchronous:true, evalScripts:true,onComplete:function(request){new Effect.Appear('popup',{duration:0.1})}}); 
		
	var w = screen.width; // Get the width of the screen
	var h = screen.height; // Get the height of the screen
	// The size of the Window
	var win_width = w - 350;
	var win_height = h - 250;
	// Where to place the Window
	var left = (w - win_width)/2;
	var top = (h - win_height)/2;
 
	 if(w == 1024)
	{
	$('popup').style.left = left+50+ "px";	
	$('popup').style.top = top +135+ "px"; 
	}
	else if(w == 1280)
	{
	$('popup').style.left = left+240+ "px";	
	$('popup').style.top = top +135+ "px"; 
	}
	else if(w == 1400)
	{
	$('popup').style.left = left+290+ "px";	
	$('popup').style.top = top +135+ "px"; 
	}
	else
	{
	$('popup').style.left = left+240+ "px";	
	$('popup').style.top = top +135+ "px"; 
	}
	$('popup').style.zindex = 5;
	
}

function help_popup(e)
{	 
	// new Ajax.Updater('popup_window', '/user_account/tag_hierarchy_help', {asynchronous:true, evalScripts:true,onComplete:function(request){new Effect.Appear('popup',{duration:0.1})}}); 
	$('popup_window').style.display = "block";	
	var w = screen.width; // Get the width of the screen
	var h = screen.height; // Get the height of the screen
	// The size of the Window
	var win_width = w - 350;
	var win_height = h - 250;
	// Where to place the Window
	var left = (w - win_width)/2;
	var top = (h - win_height)/2;
 
	 if(w == 1024)
	{
	$('popup_window').style.left = left+50+ "px";	
	$('popup_window').style.top = top +135+ "px"; 
	}
	else if(w == 1280)
	{
	$('popup_window').style.left = left+240+ "px";	
	$('popup_window').style.top = top +135+ "px"; 
	}
	else if(w == 1400)
	{
	$('popup_window').style.left = left+290+ "px";	
	$('popup_window').style.top = top +135+ "px"; 
	}
	else
	{
	$('popup_window').style.left = left+240+ "px";	
	$('popup_window').style.top = top +135+ "px"; 
	}
	$('popup_window').style.zindex = 5;
	
}

function help_popup_blog(e)
{	 
	// new Ajax.Updater('popup_window', '/user_account/tag_hierarchy_help', {asynchronous:true, evalScripts:true,onComplete:function(request){new Effect.Appear('popup',{duration:0.1})}}); 
	$('popup_window').style.display = "block";	
	var w = screen.width; // Get the width of the screen
	var h = screen.height; // Get the height of the screen
	// The size of the Window
	var win_width = w - 350;
	var win_height = h - 250;
	// Where to place the Window
	var left = (w - win_width)/2;
	var top = (h - win_height)/2;
    
	 if(w == 1024)
	{
	$('popup_window').style.left = left+50+ "px";	
	$('popup_window').style.top = top +135+ "px"; 
	}
	else if(w == 1280)
	{
	$('popup_window').style.left = left+540+ "px";	
	$('popup_window').style.top = top +635+ "px"; 
	}
	else if(w == 1400)
	{
	$('popup_window').style.left = left+290+ "px";	
	$('popup_window').style.top = top +135+ "px"; 
	}
	else
	{
	$('popup_window').style.left = left+240+ "px";	
	$('popup_window').style.top = top +135+ "px"; 
	}
	$('popup_window').style.zindex = 5;
	
}

function preview_popup(e)
{    
	new Ajax.Updater('popup1', '/qa/preview', {asynchronous:true, evalScripts:true, onLoading:function(request){}, onComplete:function(request){new Effect.Appear('popup1',{duration:0.1})}}); 
		
	var w = screen.width; // Get the width of the screen
	var h = screen.height; // Get the height of the screen
	// The size of the Window
	var win_width = w - 350;
	var win_height = h - 250;
	// Where to place the Window
	var left = (w - win_width)/2;
	var top = (h - win_height)/2;
 
	 if(w == 1024)
	{
	$('popup1').style.left = left+50+ "px";	
	$('popup1').style.top = top +100+ "px"; 
	}
	else if(w == 1280)
	{
	$('popup1').style.left = left+240+ "px";	
	$('popup1').style.top = top +100+ "px"; 
	}
	else if(w == 1400)
	{
	$('popup1').style.left = left+290+ "px";	
	$('popup1').style.top = top +100+ "px"; 
	}
	else
	{
	$('popup1').style.left = left+240+ "px";	
	$('popup1').style.top = top +100+ "px"; 
	}
	$('popup1').style.zindex = 5;
	
}

function display(request)
{
    alert("dsfsadfasd");
}
function closediv(id)
{
$(id).style.display="none";
}