
function CustomDataGrid()
{this.create=CustomDataGrid_create;this.update=CustomDataGrid_update;this.copyClipboard=CustomDataGrid_copyClipboard;this.copyButtonMouseover=CustomDataGrid_copyButtonMouseover;this.copyButtonMouseout=CustomDataGrid_copyButtonMouseout;this.divIdToWord={};this.currentStemData={};this.clear=CustomDataGrid_clear;this.gridRollover=CustomDataGrid_gridRollover;this.gridRollout=CustomDataGrid_gridRollout;this.gridClickNeg=CustomDataGrid_gridClickNeg;this.updateStemData=CustomDataGrid_updateStemData;this.prompt=CustomDataGrid_prompt;this.shownPrompt=false;}
function CustomDataGrid_update(query_data,negativesObj,headerColumns,data,supress_warning)
{var hi_cap=65535;var prevScore=0;var incFactor=0;for(var i=data.length-1;i>=0;i--)
{data[i][3]=parseInt(data[i][2]);if(data[i][3]<prevScore)
{incFactor=prevScore;}
data[i][3]+=incFactor;prevScore=data[i][3];hi_cap=data[i][3];}
var lo_cap=5;var euler=2.71828182845904523536;var max=Math.log(hi_cap)/Math.log(euler);if(max==0)max=1;var fullText='Keyword Suggestions Provided by WordStream Free Keyword Tool: http://www.wordstream.com/keywords\n\n';var oldScroll=$("#gridBody").attr("scrollTop");var reducedCount=0;var reducedVisits=0;var limit=100;var added_words=0;var total_words=data.length;var query_phrases=query_data.split('\n');var query_words={};var browser=navigator.appName;var version=getIEVersionNumber();table_width='width="100%"';if(browser=="Microsoft Internet Explorer"&&version<8)
{table_width='style="width:'+parseInt(this.width)-20+'px;"';}
var html=['<table id="'+this.divId+'_mainTable'+'" class="cellStyle" '+table_width+'>'];for(var i=0;i<query_phrases.length;i++)
{var query_text=query_phrases[i].split(' ');for(var j=0;j<query_text.length;j++)
{query_words[query_text[j]]=query_text[j];}}
var i=0;var j=0;this.headerColumns=headerColumns;this.queryData=query_data;this.data=data;for(var i=0;i<this.data.length;i++)
{var words=this.data[i][1].split(' ');var found=false;for(var index=0;index<words.length;index++)
{if(words[index]in negativesObj)
{found=true;reducedCount++;reducedVisits+=parseInt(this.data[2]);break;}}
if(found==false)
{added_words++;fullText+=added_words+'\t'+data[i][1]+'\t'+data[i][2]+'\n';if(((added_words)%2)==0)
{filler=' bgcolor="#F7F7F7" ';}
else
{filler=' bgcolor="#FFFFFF" ';}
html.push('<tr>');for(var j=0;j<this.data[i].length;j++)
{this.data[i][0]=added_words;if(j==0)
{var cell_width=headerColumns[j][1];html.push('<td id="cell_'+added_words+'_'+j+'"'+filler+' width="'+cell_width+'">');html.push(this.data[i][j]);html.push('</td>');}
else if(j==1)
{var cell_width=headerColumns[j][1];html.push('<td id="cell_'+added_words+'_'+j+'"'+filler+' width="'+cell_width+'">');for(var index=0;index<words.length;index++)
{var divId='div'+added_words+'_'+j+'_'+index;this.divIdToWord[divId]=words[index];html.push('<span id="'+divId+'_span" class="word_container" onmouseover="');html.push(this.divId+".gridRollover('"+divId+"');");html.push('" onmouseout="');html.push(this.divId+".gridRollout('"+divId+"');"+'" onclick="');html.push(this.divId+".gridClickNeg('"+divId+"');");html.push('">');if(index>0)
{html.push('&nbsp;');}
html.push(words[index]);html.push('<span style="padding-left: 2px; display: none; vertical-align: middle;" id="'+divId+'">');html.push('<img src="'+suggest_server+'/themes/wordstream/images/negatives.png"/>');html.push('</span>');html.push('</span>');}
html.push('</td>');}
else if(j==2)
{var cell_width=headerColumns[j][1];html.push('<td id="cell_'+added_words+'_'+j+'"'+filler+' width="'+cell_width+'">');html.push('<div class="bar_chart">');var orig=parseFloat(this.data[i][3]);if(orig>hi_cap)orig=hi_cap;var scaled=(Math.log(orig)/max)*100;var final=parseInt(scaled);if(final<lo_cap)final=lo_cap;html.push('<div class="bar_chart_inner" style="width: '+final+'%;">');html.push('</div>');html.push('</div>');html.push('</td>');}}
html.push("</tr>");if(added_words==limit)break;}}
html.push('</table>');$('#gridBody').html(html.join(''));$("#gridBody").attr({scrollTop:oldScroll});if(added_words<limit&&total_words>=limit)
{getKeywords('pattern');return 0;}
var total=0;if(added_words>0)
{}
$('#gridBody').width(this.width);$('#gridBody').height(parseInt(this.height)-$('#headerBar').height()-$('#footerBar').height());maxScroll=$("#gridBody").attr("scrollHeight")-$("gridBody").height();if(oldScroll>maxScroll)
{oldScroll=maxScroll;}
$("#gridBody").attr({scrollTop:oldScroll});$('#'+this.divId+'_busy').hide();fullText+="\nWant access to thousands of relevant keywords? Set up a FREE Keyword Tool Account today!\n"+suggest_server+"/signup\n";self.ZeroClipboard_clip.setText(fullText);if(self.ZeroClipboard_clip.glued==false)
{self.ZeroClipboard_clip.glued=true;}
var newCount=currentCount-reducedCount;newCountStr=commaFormat(newCount);var newVisits=currentVisits-reducedVisits;newVisitsStr=commaFormat(newVisits);var newAddedKeywords=commaFormat(added_words);if(added_words==0)
{newCountStr='0';newVisitsStr='0';}
var str='&nbsp;Results: Top '+added_words+' of an estimated <span style="color: #0000FE; text-decoration: underline;">'+newCountStr+' keywords</span>';$('#result').html(str);if(currentCount>50000&&query_phrases.length==1&&supress_warning==false)
{this.prompt('Your keyword search returned a very high number of keywords! We recommend that you:<br/><ul><li>Filter your results by hovering over unwanted words, then clicking the filter button</li><li>Use more specific keywords in your keyword list and then re-executing your search</li></ul>');}
return[reducedCount,reducedVisits];}
function CustomDataGrid_create(containerId,query_data,negativesObj,headerColumns,data,width,height)
{var oldScroll=$("#gridBody").attr("scrollTop");var reducedCount=0;var reducedVisits=0;var limit=100;var added_words=0;var total_words=data.length;var query_phrases=query_data.split('\n');var query_words={};for(var i=0;i<query_phrases.length;i++)
{var query_text=query_phrases[i].split(' ');for(var j=0;j<query_text.length;j++)
{query_words[query_text[j]]=query_text[j];}}
var i=0;var j=0;this.divId=containerId;this.headerColumns=headerColumns;this.queryData=query_data;this.data=data;this.width=width;this.height=height;var html=[];html.push('<div id="'+this.divId+'_busy" class="datagrid_busy" style="width: '+this.width+'; height: '+this.height+';">');html.push('<table width="100%" height="100%"><tr><td width="100%" height="'+this.height+'" align="center" valign="center">');html.push('<br><br><img src="'+suggest_server+'/themes/wordstream/images/loader.gif"/><br><font color="#FFFFFF">Getting keyword results</font>');html.push('</td></tr></table>');html.push('</div>');html.push('<div id="'+this.divId+'_prompt" class="prompt">');html.push('</div>');html.push('<div id="gridBody" class="gridBody">');html.push('</div>');var myDiv=document.getElementById(this.divId).innerHTML=html.join('');var total=0;$('#gridBody').width(width);$('#gridBody').height(parseInt(height)-$('#headerBar').height()-$('#footerBar').height());var newCount=currentCount-reducedCount;newCountStr=commaFormat(newCount);var newVisits=currentVisits-reducedVisits;newVisitsStr=commaFormat(newVisits);var newAddedKeywords=commaFormat(added_words);return[reducedCount,reducedVisits];}
function CustomDataGrid_prompt(text)
{if(this.shownPrompt==false)
{this.shownPrompt=true;var promptId='#'+this.divId+'_prompt';var myDivId='#'+this.divId;$(promptId).html(text);$(promptId).fadeTo(0,0.0);$(promptId).show();var pos=$(myDivId).position();var top=parseInt(pos.top);var width=parseInt($(myDivId).width());var promptWidth=parseInt($(promptId).width());var left=(parseInt(pos.left+width-promptWidth)-37)+'px';var height=parseInt($(myDivId).height());var promptHeight=parseInt($(promptId).height());var newTop=(height-20-promptHeight+top)+'px';var par=this;$(promptId).css({left:left,top:newTop});$(promptId).fadeTo(2000,1.0);$(promptId).fadeTo(15000,1.0);$(promptId).fadeTo(2000,0.0,function()
{$(promptId).hide();par.shownPrompt=false;});}}
function CustomDataGrid_gridRollover(id)
{if(idHash(this.divIdToWord[id])in this.currentStemData)
{return;}
var word=this.divIdToWord[id];$('#'+id+'_span').attr('title','Filter all keywords containing '+"'"+word+"' from my results");$('#'+id+'_span').addClass('word_container_selected');$('#'+id+'_span').removeClass('word_container');$('#'+id).show();}
function CustomDataGrid_gridRollout(id)
{if(idHash(this.divIdToWord[id])in this.currentStemData)
{return;}
$('#'+id+'_span').attr('title','');$('#'+id+'_span').addClass('word_container');$('#'+id+'_span').removeClass('word_container_selected');$('#'+id).hide();}
function CustomDataGrid_gridClickNeg(id)
{if(idHash(this.divIdToWord[id])in this.currentStemData)
{return;}
var word=this.divIdToWord[id];negativesContainer.add(word);var headerData=[['#','4%'],['Keyword','76%'],['Relative Volume','20%']];var reduceResult=dataGrid.update(currentQuery,negativesContainer.getNegativesDict(),headerData,currentData,true);}
function CustomDataGrid_updateStemData(inStemData)
{this.currentStemData={};var stemList=inStemData.split('\n');for(var i=0;i<stemList.length;i++)
{this.currentStemData[idHash(stemList[i])]=true;}}
function CustomDataGrid_clear()
{this.currentStemData={};this.divIdToWord={};}
function CustomDataGrid_copyClipboard()
{}
function CustomDataGrid_copyButtonMouseover()
{$('#'+this.divId+'_copyButton').attr('class','dataGrid_buttonSelected');}
function CustomDataGrid_copyButtonMouseout()
{$('#'+this.divId+'_copyButton').attr('class','dataGrid_button');}
function changePattern(source)
{this.source=source;clearTimeout(self.synonym_timer);self.synonym_timer=setTimeout("getSynonyms(source)",1000);}
function SynonymsContainer()
{this.rootLookup={};this.acceptedSynonyms={};this.rejectedSynonyms={};this.allSynonyms={};this.skippedTerms={};this.pendingRejectedSynonymCount=0
this.create=SynonymsContainer_create;this.refreshSynonyms=SynonymsContainer_refreshSynonyms;this.updateSynonyms=SynonymsContainer_updateSynonyms;this.getAcceptedSynonyms=SynonymsContainer_getAcceptedSynonyms;this.getRejectedSynonyms=SynonymsContainer_getRejectedSynonyms;this.clear=SynonymsContainer_clear;this.acceptRollover=SynonymsContainer_acceptRollover;this.acceptRollout=SynonymsContainer_acceptRollout;this.acceptClick=SynonymsContainer_acceptClick;this.removeRollover=SynonymsContainer_removeRollover;this.removeRollout=SynonymsContainer_removeRollout;this.removeClick=SynonymsContainer_removeClick;this.editTerm=SynonymsContainer_editTerm;this.synRollover=SynonymsContainer_synRollover;this.synRollout=SynonymsContainer_synRollout;this.pruneSynonyms=SynonymsContainer_pruneSynonyms;this.getKeywordWithSubstitutedSynonym=SynonymsContainer_getKeywordWithSubstitutedSynonym;}
function SynonymsContainer_create(containerId,width,height)
{this.key='';this.containerId=containerId;var str='';this.width=width;this.height=height;var html=[]
var par_width=$('#'+containerId).width();html.push('<div id="'+this.containerId+'_busy" class="busy" style="height: '+this.height+'; width: '+par_width+'px;">');html.push('<div style="height: 15px;"></div>');html.push('<center>');html.push('<img src="'+suggest_server+'/themes/wordstream/images/loader.gif"/><br><font color="#FFFFFF">Getting related terms</font>');html.push('</center>');html.push('</div>');html.push('<div id="'+containerId+'_inner" class="scroll_area"></div>');$('#'+containerId).html(html.join(''))
$('#'+containerId).height(height);$('#'+containerId+'_inner').width(width);$('#'+containerId+'_inner').height(height);}
function SynonymsContainer_editTerm(key)
{$('#pattern').val($('#pattern').val()+'\n'+this.getKeywordWithSubstitutedSynonym($('#pattern').val(),this.allSynonyms[key]));changePattern('pattern');this.skippedTerms[key]=this.allSynonyms[key];if(key in this.acceptedSynonyms)
{delete this.acceptedSynonyms[key];}
this.updateSynonyms(this.synonymResponse,this.key);}
function SynonymsContainer_refreshSynonyms()
{var synonymList=this.pruneSynonyms($('#pattern').val(),this.synonymResponse);var browser=navigator.appName;var version=getIEVersionNumber();table_width='width="100%"';if(browser=="Microsoft Internet Explorer"&&version<8)
{table_width='style="width:'+parseInt(this.width)-20+'px;"';}
html=['<table border="0" '+table_width+'>'];for(var i=0;i<synonymList.length;i++)
{if(!(this.containerId+"_"+idHash(synonymList[i])in this.skippedTerms))
{this.allSynonyms[this.containerId+"_"+idHash(synonymList[i])]=synonymList[i];html.push('<tr><td width="100%">');html.push('<input type="hidden" value="'+synonymList[i]+'">');html.push('<span id="'+this.containerId+"_"+idHash(synonymList[i])+'_syn'+'"class="syn_container">');html.push(synonymList[i]);html.push('<span style="padding-left: 2px; display: none; vertical-align: middle;" id="'+this.containerId+"_"+idHash(synonymList[i])+'_img">');html.push('<img src="'+suggest_server+'/themes/wordstream/images/edit.png"/>');html.push('</span>');html.push('</span>');html.push('</td>');html.push('<td width="1%">');var acceptSrc='';if(this.containerId+"_"+idHash(synonymList[i])in this.acceptedSynonyms)
{acceptSrc=suggest_server+'/themes/wordstream/images/accept.png';}
else
{acceptSrc=suggest_server+'/themes/wordstream/images/accept_desat.png';}
html.push('<img id="'+this.containerId+"_"+idHash(synonymList[i])+'_accept'+'" src="'+acceptSrc+'"  title="'+"Check to include the term '"+synonymList[i]+"' in the query"+'" ');html.push('onmouseover="');html.push(this.containerId+".acceptRollover('"+this.containerId+"_"+idHash(synonymList[i])+"')");html.push('" ');html.push('onmouseout="');html.push(this.containerId+".acceptRollout('"+this.containerId+"_"+idHash(synonymList[i])+"')");html.push('" ');html.push('onclick="'+this.containerId+".editTerm('"+this.containerId+'_'+idHash(synonymList[i])+"')"+'"');html.push('" ');html.push('/>');html.push('</td>');html.push('</tr>');}}
html.push('</table>');$('#'+this.containerId+'_inner').html(html.join(''));}
function SynonymsContainer_updateSynonyms(synonymResponse,key)
{this.pendingRejectedSynonymCount=0;this.synonymResponse=synonymResponse;this.key=key;this.refreshSynonyms();}
function SynonymsContainer_getAcceptedSynonyms()
{var str='';for(key in this.acceptedSynonyms)
{str+=this.acceptedSynonyms[key]+'\n';}
return str;}
function SynonymsContainer_getRejectedSynonyms()
{var str='';for(key in this.rejectedSynonyms)
{str+=this.rejectedSynonyms[key]+'\n';}
return str;}
function SynonymsContainer_clear()
{this.acceptedSynonyms={};this.rejectedSynonyms={};this.allSynonyms={};this.skippedTerms={};this.rootLookup={};this.pendingRejectedSynonymCount=0
$('#'+this.containerId+'_inner').html('');this.key='';}
function SynonymsContainer_acceptRollover(id)
{$('#'+id+'_accept').attr('src',suggest_server+'/themes/wordstream/images/accept.png');}
function SynonymsContainer_acceptRollout(id)
{if(!(id in this.acceptedSynonyms))
{$('#'+id+'_accept').attr('src',suggest_server+'/themes/wordstream/images/accept_desat.png');}}
function SynonymsContainer_acceptClick(id)
{if(id in this.acceptedSynonyms)
{delete this.acceptedSynonyms[id];$('#'+id+'_accept').attr('src',suggest_server+'/themes/wordstream/images/accept_desat.png');}
else
{this.acceptedSynonyms[id]=this.allSynonyms[id];$('#'+id+'_accept').attr('src',suggest_server+'/themes/wordstream/images/accept.png');}}
function SynonymsContainer_removeRollover(id)
{$('#'+id+'_remove').attr('src',suggest_server+'/themes/wordstream/images/remove.png');}
function SynonymsContainer_removeRollout(id)
{$('#'+id+'_remove').attr('src',suggest_server+'/themes/wordstream/images/remove_desat.png');}
function SynonymsContainer_removeClick(id)
{this.rejectedSynonyms[id]=this.allSynonyms[id];if(id in this.acceptedSynonyms)
{delete this.acceptedSynonyms[id];}
delete this.allSynonyms[id];this.pendingRejectedSynonymCount+=1;this.refreshSynonyms();if(this.pendingRejectedSynonymCount>5)
{getSynonyms('pattern');}
else
{clearTimeout(self.synonym_timer);self.synonym_timer=setTimeout("getSynonyms('pattern')",6000);}}
function SynonymsContainer_synRollover(id)
{$('#'+id+'_syn').attr('class','syn_container_selected');$('#'+id+'_img').show();}
function SynonymsContainer_synRollout(id)
{$('#'+id+'_syn').attr('class','syn_container');$('#'+id+'_img').hide();}
function SynonymsContainer_getKeywordWithSubstitutedSynonym(pattern,synonym)
{var result='';var rootWord='';for(root in this.rootLookup)
{for(var synonym_key in this.rootLookup[root])
{if(synonym_key in this.allSynonyms)
{var synonym_test=this.allSynonyms[synonym_key];if(synonym_test==synonym)
{rootWord=root;break;}}}}
var lineList=pattern.split('\n');for(var i=0;i<lineList.length;i++)
{var newWordList=[];var wordList=lineList[i].split(' ');for(var j=0;j<wordList.length;j++)
{if(wordList[j]!='')
{newWordList.push(wordList[j]);}}
var searchableLine=newWordList.join(' ');if(searchableLine.indexOf(rootWord)!=-1)
{result=searchableLine.replace(rootWord,synonym)
break;}}
return result;}
function SynonymsContainer_pruneSynonyms(text,synonymResponse)
{var synList=[];var synonymList=synonymResponse.split('\n');for(var i=0;i<synonymList.length;i++)
{var synList2=synonymList[i].split('\t');if(!(synList2[0]in this.rootLookup))
{this.rootLookup[synList2[0]]={};}
for(var j=1;j<synList2.length;j+=2)
{var key=this.containerId+'_'+idHash(synList2[j]);this.rootLookup[synList2[0]][key]=[decodeURIComponent(escape(synList2[j])),decodeURIComponent(escape(synList2[j+1]))];}}
var wordLookup={};var lineList=text.split('\n');var searchableText='';for(var i=0;i<lineList.length;i++)
{var found=false;var wordList=lineList[i].split(' ');for(var j=0;j<wordList.length;j++)
{if(wordList[j]!='')
{found=true;wordLookup[wordList[j]]=wordList[j];searchableText+=wordList[j]+' ';}}
if(found==true)
{searchableText+='\n';}}
deleteList=[];for(var root in this.rootLookup)
{var rootWords=root.split(' ');var removeRoot=false;if(rootWords.length==1)
{if(!(root in wordLookup))
{removeRoot=true;}}
else
{if(searchableText.indexOf(root)==-1)
{removeRoot=true;}}
if(removeRoot==true)
{for(var synonym in this.rootLookup[root])
{var key=this.containerId+'_'+idHash(this.rootLookup[root][synonym][0]);if(key in this.allSynonyms)
{delete this.allSynonyms[key];}
if(key in this.acceptedSynonyms)
{delete this.acceptedSynonyms[key];}
if(key in this.rejectedSynonyms)
{delete this.rejectedSynonyms[key];}
if(key in this.skippedTerms)
{delete this.skippedTerms[key];}}
deleteList.push(root);}}
for(var i=0;i<deleteList.length;i++)
{delete this.rootLookup[deleteList[i]];}
var kvSynList=[];for(var root in this.rootLookup)
{for(var synonym in this.rootLookup[root])
{var key=this.containerId+'_'+idHash(this.rootLookup[root][synonym][0]);if((!(key in this.rejectedSynonyms)))
{kvSynList.push({Key:this.rootLookup[root][synonym][1],Value:this.rootLookup[root][synonym][0]});}}}
kvSynList.sort(sortByKey);var sortedSynList=[];for(var i=0;i<kvSynList.length;i++)
{sortedSynList.push(kvSynList[i].Value);}
return sortedSynList;}
function sortByKey(a,b)
{var x=a.Key;var y=b.Key;return((x>y)?-1:((x<y)?1:0));}
function NegativesContainer()
{this.add=NegativesContainer_add;this.getNegatives=NegativesContainer_getNegatives;this.remove=NegativesContainer_remove;this.getNegativesDict=NegativesContainer_getNegativesDict;this.count=NegativesContainer_count;this.clear=NegativesContainer_clear;this.negatives=[];this.negativeLookup={};}
function NegativesContainer_count()
{return this.negatives.length;}
function NegativesContainer_getNegativesDict()
{var retObj={};for(var i=0;i<this.negatives.length;i++)
{retObj[this.negatives[i]]=this.negatives[i];}
return retObj;}
function NegativesContainer_add(negative_keyword)
{if(idHash(negative_keyword)in this.negativeLookup)
{return;}
this.negativeLookup[idHash(negative_keyword)]=negative_keyword;this.negatives.push(negative_keyword);}
function NegativesContainer_remove(negative_keyword_id)
{var new_negatives=[];for(var i=0;i<this.negatives.length;i++)
{if(this.negatives[i]!=this.negativeLookup[negative_keyword_id])
{new_negatives.push(this.negatives[i]);}}
this.negatives=new_negatives;delete this.negativeLookup[negative_keyword_id];getKeywords('pattern');}
function NegativesContainer_clear()
{this.negatives=[];this.negativeLookup={};}
function NegativesContainer_getNegatives()
{return this.negatives.join('\n');}
function getKeywords(source)
{if($('#'+source).val().length==0)return;$('#pri_keyword_input').hide();$('#tool_control_center').show();$('#tool_control_center').css('visibility','visible');if($('#'+source).val()=='')return;$('#dataGrid_busy').show();$('#statusBar').hide();var pattern=document.getElementById(source).value;var synonyms_accepted=self.synonymsContainer.getAcceptedSynonyms();var negatives=negativesContainer.getNegatives();var recaptcha_challenge_field="";var recaptcha_response_field="";if($('#captcha').is(':visible'))
{recaptcha_challenge_field=Recaptcha.get_challenge();recaptcha_response_field=Recaptcha.get_response();}
$.getJSON(suggest_server+'/keywords?callback=?',{'pattern':pattern,'synonyms_key':self.synonymsContainer.key,'negatives':negatives,'block_adult':'true','recaptcha_challenge_field':recaptcha_challenge_field,'recaptcha_response_field':recaptcha_response_field},gotKeywords);var navp=$.cookie('navp');if(!navp)
{navp='';}
navp+='kwtool:'+pattern.replace(/[\r\n]/g,'|')+' > '
$.cookie('navp',navp,{path:'/',domain:'.wordstream.com'})}
function gotKeywords(data)
{self.xmlHttpReqKeywords=false;var bodyData=[];var headerData=[['#','4%'],['Keyword','76%'],['Relative Volume','20%']];var keywordResponse=data.split('|');if(keywordResponse[0]=="ERROR")
{$('#statusBar').html(keywordResponse[1]);$('#statusBar').show();}
else if(keywordResponse[0]=="CAPTCHA")
{$('#statusBar').html(keywordResponse[1]);$('#statusBar').show();currentQuery=$('#pattern').val();currentData=bodyData;currentCount=0;currentVisits=0;Recaptcha.create(keywordResponse[2],"captchaCode",{theme:"white",callback:Recaptcha.focus_response_field});showCaptcha();dataGrid.update($('#pattern').val(),negativesContainer.getNegativesDict(),headerData,bodyData,false);}
else
{$('#statusBar').hide();currentQuery=$('#pattern').val();currentData=bodyData;currentCount=parseInt(keywordResponse[0]);currentVisits=parseInt(keywordResponse[1]);var keywords=unescape(keywordResponse[2]).split('\n');for(var i=0;i<keywords.length-1;i++)
{var keyword_data=keywords[i].split('\t');bodyData.push([i+1,decodeURIComponent(escape(keyword_data[0])),keyword_data[1],keyword_data[2]]);}
dataGrid.update($('#pattern').val(),negativesContainer.getNegativesDict(),headerData,bodyData,false);}}
function getSynonyms(source)
{$('#synonymsContainer_busy').width($('#synonymsContainer').width());$('#synonymsContainer_busy').show();var pattern=document.getElementById(source).value;$.getJSON(suggest_server+'/synonyms?callback=?',{'pattern':pattern,'key':self.synonymsContainer.key,'rejected':'','accepted':'','block_adult':'true'},gotSynonyms);}
function gotSynonyms(data)
{self.xmlHttpReqSynonyms=false;var synonymResponse=data.split("|");if(synonymResponse[0]=="WAIT")
{clearTimeout(self.synonym_timer);self.synonym_timer=setTimeout("getSynonyms('pattern')",parseInt(synonymResponse[1]));}
else
{var inSynKey=synonymResponse[0];var inSynList=unescape(synonymResponse[1]);var inStemData=unescape(synonymResponse[2]);dataGrid.updateStemData(inStemData)
synonymsContainer.updateSynonyms(inSynList,inSynKey);$('#synonymsContainer_busy').hide();}}
function sendEmail()
{if(this.shownEmailPrompt==true)return;$('#mailKeywordsCallout').html('<b>Sending e-mail...</b>')
showEmailPrompt();$('#statusBar').hide();var pattern=document.getElementById('pattern').value;var synonyms_accepted=self.synonymsContainer.getAcceptedSynonyms();var negatives=negativesContainer.getNegatives();var email=$('#email').val();$.getJSON(suggest_server+'/email?callback=?',{'pattern':pattern,'email':email,'synonyms_accepted':'','negatives':negatives,'block_adult':'true'},sentEmail);}
function sentEmail(data)
{self.xmlHttpReqEmail=false;var emailResponse=data.split("|");if(emailResponse[0]=="ERROR")
{$('#mailKeywordsCallout').html("<b>"+emailResponse[1]+"</b>");}
else
{$('#mailKeywordsCallout').html("<b>Your keywords will be delivered shortly</b>");}
hideEmailPrompt();}
function showCaptcha()
{$('#dimmer').show();$('#captcha').center();$('#captcha').show();}
function hideCaptcha()
{$('#captcha').hide();$('#dimmer').hide();}
function showEmailPrompt()
{if(this.shownEmailPrompt==false)
{this.shownEmailPrompt=true;var promptId='#mailKeywords';var myDivId='#'+this.divId;var par=this;$(promptId).fadeTo(0,0.0);$(promptId).show();$(promptId).fadeTo(250,1.0);}}
function hideEmailPrompt()
{if(this.shownEmailPrompt==true)
{var promptId='#mailKeywords';var myDivId='#'+this.divId;var par=this;$(promptId).fadeTo(10000,1.0);$(promptId).fadeTo(2000,0.0,function()
{$(promptId).hide();par.shownEmailPrompt=false;});}}
function doLogin()
{var username=$('#username').val();var password=$('#password').val();$.getJSON(suggest_server+'/login?callback=?',{'username':username,'password':password},doneLogin);}
function doneLogin(data)
{var responseCode=data.split('|');if(responseCode[0]=='0')
{$('#login').css('visibility','hidden');$('#logout').css('visibility','visible');$('#email').val(responseCode[2]);$('#signup_message').css('visibility','hidden');$('#welcome').html('Welcome '+responseCode[2])}
else
{$('#username').val('');$('#password').val('');$('#username_div').show();$('#password_div').show();msgBox(responseCode[1],'Login Error');}}
function doLogout()
{$.getJSON(suggest_server+'/logout?callback=?',{},doneLogout);}
function doneLogout(data)
{$('#login').css('visibility','visible');$('#logout').css('visibility','hidden');$('#signup_message').css('visibility','visible');$('#email').val('');$('#username').val('');$('#password').val('');$('#username_div').show();$('#password_div').show();}
function autoLogin()
{$.getJSON(suggest_server+'/auto_login?callback=?',{},doneAutoLogin);}
function doneAutoLogin(data)
{var responseCode=data.split('|');if(responseCode[0]=='0')
{$('#login').css('visibility','hidden');$('#logout').css('visibility','visible');$('#email').val(responseCode[2]);$('#signup_message').css('visibility','hidden');$('#welcome').html('Welcome '+responseCode[2])}
else
{$('#login').css('visibility','visible');$('#logout').css('visibility','hidden');$('#signup_message').css('visibility','visible');$('#email').val('');}}
function onCopyKwdsMouseOver(id)
{$('#'+id).css('background','#BABFC3');}
function onCopyKwdsMouseOut(id)
{$('#'+id).css('background','#EAEFF3');}
function onCopyKwdsMouseDown(id)
{$('#'+id).css('background','#9A9FA3');}
function onCopyKwdsMouseUp(id)
{$('#'+id).css('background','#BABFC3');}
function checkEnter(event)
{var k=event.keyCode;if(k==13)
{getKeywords('primary_keyword_input');$('#pattern').val($('#primary_keyword_input').val());}}
function msgBox_close()
{$('#msgBox').fadeTo(300,0.0);$('#msgBox').hide();$('#overlay').css('visibility','hidden');}
function msgBox(bodyText,titleText)
{if(titleText==undefined)titleText='Free Keyword Tool';var ttext='<table border="0"><tr><td valign="middle"><img src="'+suggest_server+'/themes/wordstream/images/wordstream.png"/></td><td valign="middle"><b>'+titleText+'</b></td></tr></table>'
$('#titleText').html(ttext);$('#bodyText').html(bodyText);$('#msgBox').center();$('#msgBox').fadeTo(0,0.0);$('#overlay').css('visibility','visible');$('#msgBox').show();$('#msgBox').fadeTo(300,1.0);}
function suggestStartup()
{this.shownEmailPrompt=false;jQuery.fn.center=function()
{this.css("position","absolute");this.css("top",($(window).height()-this.height())/2+$(window).scrollTop()+"px");this.css("left",($(window).width()-this.width())/2+$(window).scrollLeft()+"px");return this;}
image_url=new Array();image_url[0]=suggest_server+"/themes/wordstream/images/remove_desat.png";image_url[1]=suggest_server+"/themes/wordstream/images/remove.png";image_url[2]=suggest_server+"/themes/wordstream/images/accept_desat.png";image_url[3]=suggest_server+"/themes/wordstream/images/accept.png";image_url[4]=suggest_server+"/themes/wordstream/images/edit.png";image_url[5]=suggest_server+"/themes/wordstream/images/negatives.png";image_url[6]=suggest_server+"/themes/wordstream/images/copy_desat.png";image_url[7]=suggest_server+"/themes/wordstream/images/copy.png";for(var i=0;i<=7;i++)
{preloadedImages=new Image();preloadedImages.src=image_url[i];}
$(document).ready(function()
{self.synonymsContainer=new SynonymsContainer();self.dataGrid=new CustomDataGrid();self.negativesContainer=new NegativesContainer();self.currentQuery=$('#pattern').val();self.currentData=[];self.currentCount=0;self.currentVisits=0;self.totalQueries=0;var headerData=[['#','4%'],['Keyword','76%'],['Relative Volume','20%']];var bodyData=[];synonymsContainer.create('synonymsContainer','100%','80px');dataGrid.create('dataGrid',$('#pattern').val(),self.negativesContainer.getNegativesDict(),headerData,bodyData,'760px','242px');if($('#pattern').val()!=''&&$('#pattern').val()!=undefined)
{changePattern('primary_keyword_input');}
params=getURLParams();var referrer=document.referrer;if(!referrer)
referrer='ws local';if(document.referrer.search('wordstream.com')==-1)
{var nextc=1;var limit=10;for(i=1;i<limit;++i)
{if($.cookie('myref_'+i))
{nextc=i+1;}}
var cmp='none';var src='none';if('cmp'in params)
cmp=params['cmp'];if('src'in params)
src=params['src'];var today=new Date();today.setTime(today.getTime());var exp_date=new Date(today.getTime()+(60*60*24*29.5*12*24));$.cookie('myref_'+nextc,referrer,{'path':'/','domain':'.wordstream.com','expires':exp_date});$.cookie('mycmp',cmp,{'path':'/','domain':'.wordstream.com','expires':exp_date});$.cookie('mysrc',src,{'path':'/','domain':'.wordstream.com','expires':exp_date});}
if(params['pattern'])
{$('#primary_keyword_input').val(params['pattern']);$('#pattern').val(params['pattern']);getSynonyms('pattern');getKeywords('pattern');}
$('#username').val('');$('#password').val('');$('#username_div').show();$('#password_div').show();autoLogin();});}
function getURLParams()
{var gp=new Array();var loc=location.search;if(loc)
{loc=loc.substring(1);var parms=loc.split('&amp;');for(var i=0;i<parms.length;i++)
{nameValue=parms[i].split('=');var val=nameValue[1].replace(/\+/g,' ')
gp[nameValue[0]]=decodeURIComponent(val);}}
return gp;}
function idHash(str)
{var outStr='id';for(var i=0;i<str.length;i++)
{outStr+=str.charCodeAt(i);}
return outStr;}
function getIEVersionNumber()
{var ua=navigator.userAgent;var MSIEOffset=ua.indexOf("MSIE ");if(MSIEOffset==-1){return 0;}else{return parseFloat(ua.substring(MSIEOffset+5,ua.indexOf(";",MSIEOffset)));}}
function commaFormat(num)
{var numStr=''+num;var commaStr='';for(var i=numStr.length-1;i>=0;i--)
{if((((numStr.length-i-1)%3)==0)&&(i!=(numStr.length-1)))
{commaStr=','+commaStr;}
commaStr=numStr.charAt(i)+commaStr;}
return commaStr;}
function hideItAndFocus(id,focus)
{$('#'+id).hide();$('#'+focus).focus();}
function showItIfEmpty(id,text)
{if($('#'+text).val().length==0)
{$('#'+id).show();}}
function resetPassword()
{if($('#username').val().length==0)
{msgBox('You must enter your E-mail address in the E-mail field','Reset Password');}
else
{location.href=suggest_server+"/reset?username="+encodeURIComponent($('#username').val());}}
suggestStartup();