﻿//Author: adeel

var KeywordManager = Class.create({   initialize: 
    function() {    
    this.keywordText = '';
    this.isParital = '0';   
    this.nextKeywordseparator = '';//'-/.o834!' 
    } 
 }); 
 
 
 KeywordManager.addMethods({   addKeyword : function() {  
    if($('TextBoxAddKeyword').value.blank())
        return; 
    if($('RadioButtonPartialMatch').checked == true)
        this.isPartial = '1';        
    else 
        this.isPartial = '0';
         
    //$('keywordList').innerHTML +=  '<li><span>'+$('TextBoxAddKeyword').value+'</span> <a href="#"  onclick="objKeywordManager.removeKeyword(\''+$('TextBoxAddKeyword').value+'\',\''+this.isPartial+'\'); return false;">Remove</a></li>';    
    $('keywordList').style.display = 'block';
    $('keywordList').innerHTML +=  '<div class="expertise"><span>'+$('TextBoxAddKeyword').value+'</span> <a href="#"  onclick="objKeywordManager.removeKeyword(\''+$('TextBoxAddKeyword').value+'\',\''+this.isPartial+'\'); return false;">Remove</a><div style="clear:both"></div></div>';    
        
    $('keywordsTB').value += $('TextBoxAddKeyword').value+ "-"+this.isPartial + this.nextKeywordseparator;
    $('TextBoxAddKeyword').value = '';
}
});

KeywordManager.addMethods({   restoreKeywords : function() {        
    var str = $('keywordsTB').value;    
    if(str.length > 0){
        var arr = str.split(this.nextKeywordseparator);
        $('keywordList').innerHTML = '';
        $('keywordList').show();
        for(var i=0;i<arr.length;i++){
                if(arr[i].blank() == false){
                    var p = arr[i].lastIndexOf("-");
                    var kw = arr[i].substring(0,p);
                    var ispartial = arr[i].substring(p+1,arr[i].length);                    
                    $('keywordList').innerHTML +=  '<div class="expertise"><span>'+kw+'</span> <a href="#" onclick="objKeywordManager.removeKeyword(\''+kw+'\',\''+ispartial+'\'); return false;">Remove</a><div style="clear:both"></div></div>';                        
            }
        }        
    }
    else{
        $('keywordList').innerHTML = '';
        $('keywordList').style.display='none';
    }
}
});


 KeywordManager.addMethods({   removeKeyword : function(keyword,ispartial) { 
    $('keywordsTB').value = $('keywordsTB').value.replace(keyword+'-'+ispartial+this.nextKeywordseparator,'');    
    this.restoreKeywords();
}
});

