var rxEmail = /^\w[\w#$\%^&*'\/=?_`{|}~+-]*(\.[\w#$\%^&*'\/=?_`{|}~+-]+)*@(\w[\w-]*\.)+[a-z]{2,4}$/i; // email regexp
var rxWebsite = /^(https?:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/i; // website regexp
var rxFeed = /^((https?|feed):\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/i; // website regexp
var refresh_time_in_milliseconds = 60000;

/*	Yehuda: This function trim a string from both sides. */
String.prototype.trim = function() { 	return this.replace(/^\s+|\s+$/g,"");	};
String.prototype.indexOfIgnoreCase = function(str) { return this.toLowerCase().indexOf(str.toLowerCase()); }
String.prototype.lastIndexOfIgnoreCase = function(str) { return this.toLowerCase().lastIndexOf(str.toLowerCase()); }
String.prototype.toRx = function(str) { return this.replace(/(\(|\)|\{|\}|\[|\]|\:|\^|\$|\!|\=|\+|\*|\/|\,|\-|\||\?|\.)/g,"\\$1"); }
String.prototype.rjust = function(n, c) { var result=this; while(result.length<n) { result=c+result; }; return result; }

var refreshed_ads_slots = ['HomePage_728x90_leaderboard','HomePage_160x600','HomePage_300x250_top','QuotePage_300x250_top','QuotePage_728x90_leaderboard','ETFs_Quotepage_728x90_leaderboard','ETFs_QuotePage_728x90_leaderboard','ETFs_QuotePage_300x250_top','Common_300x250_top','Common_160x600','Common_728x90_leaderboard','Shp_ETFs_728x90_leaderboard','MacroViewDashboard_728x90_leaderboard','StocksSectorsDashboard_728x90_leaderboard','GlobalMarketsDashboard_728x90_leaderboard','ETFsDashboard_728x90_leaderboard','InvestingIdeasDashboard_728x90_leaderboard'];


var bInProcees=false;
var gTimeout;
var oRefresher=null;
var atleast = false;
var jspellRealtime=false;
var jspellAutoAttach=false;
var jspellShowOptionsMenu=false;
var jspellIgnoreUpper=false;
var user_watchlist_authors_from_cookie = readCookie('user_watchlist_authors');
var user_watchlist_slugs_from_cookie = readCookie('user_watchlist_slugs');
var wl_icon_html = "<img src='http://static.seekingalpha.com/images/WL-Icon.gif?2' onmouseover='wl_icon_mouseover(this)' onmouseout='wl_icon_mouseout(this)' onclick='wl_icon_onclick(this)' class='wl_icon' title='This article is in your Watchlist'/>"
var isRefresh = /source\=refreshed/i.test(top.location.href);
var comment_edit_time = 20; // in minutes;

function PageRefresher(Url, Interval) {
	this.Url=Url;
	this.Interval=Interval;

	this.Timeout=setTimeout(
		function () {
			top.location.href=this.Url;
		}.bind(this),
		this.Interval
	);

	this.Clear=function () {
		clearTimeout(this.Timeout);
	}

	this.Activate=function () {
		this.Timeout=setTimeout(
			function () {
				top.location.href=this.Url;
			}.bind(this),
			this.Interval
		);
	}
}

/* 	the line: setSelRange(document.getElementsByClassName('have_your_say_textarea')[0], 0, 0); 
	will place the cursor in the first place of the textarea. */
function setSelRange(inputEl, selStart, selEnd) {
  if (inputEl.setSelectionRange) {
    inputEl.focus();
    inputEl.setSelectionRange(selStart, selEnd);
  } else if (inputEl.createTextRange) {
    var range = inputEl.createTextRange();
    range.collapse(true);
    range.moveEnd('character', selEnd);
    range.moveStart('character', selStart);
    range.select();
  }
}

function scroll_top() {
	window.scrollTo(0,0);
	document.body.scrollTop=0;
}

function article_page_kind() {
  if ($('breadcrumbs')) return (($('breadcrumbs').innerHTML.toLowerCase()).indexOf('>transcripts<') > -1 ? "transcript" : "article");
  else return "";
}

function getDomain() {
  /https?:\/\/(.+?)(?:\/|\?|$)/.test(location.href);
  return RegExp.$1;
}

function do_nothing_at_all() {
  void(0);
}

function user_picture(id,picture_size) {
  string_id = id.rjust(9,"0");
  return "http://staticorigin.seekingalpha.com/images/users_profile/" + string_id.substr(0,3)+"/"+string_id.substr(3,3)+"/"+string_id.substr(6,3) + "/" + picture_size + "_pic.png?rand=" + rand(10000)
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
    var aQueryString = strQueryString.split(/&|#/);
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (new RegExp("^"+strParamName+"=").test(aQueryString[iParam])){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function jump_to_html_anchor_by_param() {
  jump_to_anchor(getURLParam('html_anchor'));
}

function rand(n) {// return integer between 1 to n
  return (Math.floor( Math.random( )* n + 1 ));
}

function change_wrapper_to_promote_image(path,promote_page) {
  var img_width = (promote_page == 'book' ? 100 : 145)
  $('img_wrapper').innerHTML = "";
  image = document.createElement('img');
  image.style.cssText="visibility:hidden;";
  image.setAttribute('image_width',img_width);
  image.onload = function () { if (this.width > img_width) {this.style.cssText='display:block;width:'+this.getAttribute('image_width')+'px;visibility:visible;'} else {this.style.cssText='visibility:visible;'} }
  image.src = path;
  $('img_wrapper').appendChild(image);
  $('has_logo_remove_button').style.display = 'block';
  $('need_to_remove_image').value = 'no'  

  if ($('upload_msg')) $('upload_msg').style.display='none';
  if ($('save_button')) {
	$('save_button').disabled=false;
	$('save_button').className='submit';
  }
}  

function delete_promote_image(oBtn, UserId, PageName) {
  $('need_to_remove_image').value = 'yes';
  $('has_logo_remove_button').style.display = 'none';

  oDiv = document.createElement('div');
  oDiv.className = "no_img";
  oDiv.innerHTML = "You haven't uploaded a book image yet"
  $('img_wrapper').innerHTML = "";
  $('img_wrapper').appendChild(oDiv);
}

function note_promote_afer_published(){
	$('promote_confirmation').style.display='block';
	$("promote_section_name").innerHTML="";
	if ($("description_intersts_trading")) $("description_intersts_trading").innerHTML="";
	scroll_top();
}

function notice_to_element(address,howto) {
  if (readCookie('notice_'+address)!=null) {
    switch(howto) {
    case 'update':
      $('notice_'+address).update(readCookie('notice_'+address));
      break;
    case 'innerhtml':
      $('notice_'+address).innerHTML = readCookie('notice_'+address);
      break;
    case 'value':
      $('notice_'+address).value = readCookie('notice_'+address);
      break;
    default:
      $('notice_'+address).update(readCookie('notice_'+address));
    }
    eraseCookie('notice_'+address);
  }
}

function comments_forgot_password_switcher(title,val) {
  $('forgot_password_form_name').value = val;
	if ($('popup_forgot_password').style.display!='block') {
    	$('forgot_password_title').innerHTML = title;
		$('popup_forgot_password').style.display='block';
		$('popup_login_or_register').style.display='none';	
		$('forgot_password_user_email').value = $('login_user_email').value;
		$('notice_forgot_password').innerHTML='';
		$('notice_never_chose_password').innerHTML='';
	} else {
		$('popup_forgot_password').style.display='none';
		$('popup_login_or_register').style.display='block';
		$('login_user_email').value = $('forgot_password_user_email').value;
	}
}

function forgot_password_switcher() {
	if ($('orthodox_forgot_password').style.display!='block') {
		$('orthodox_forgot_password').style.display='block';
		$('orthodox_login_and_registration').style.display='none';
		$('forgot_password_user_email').value = $('login_user_email').value;
	} else {
		$('orthodox_forgot_password').style.display='none';
		$('orthodox_login_and_registration').style.display='block';
		$('login_user_email').value = $('forgot_password_user_email').value;
	}
}

function handleInput(obj,action) {
	switch (action) {
		case 'focus':

			if (obj.title==obj.value) obj.value="";

			break;

		case 'blur':

			if (obj.value=="") obj.value=obj.title;

			break;
	}
}

function link_over(e, clr) {
	$(e).setStyle({ cursor:'pointer', textDecoration:'underline', color:clr || 'red' });
}

function link_out(e, clr) {
	$(e).setStyle({ textDecoration:'none', color:clr || 'blue' });
}

function password_type_change_to_text(passwprd_id){
	var temp=$(passwprd_id).value;
	$('password_wrapper').innerHTML="<input type='text' name='user[password]' id='"+passwprd_id+"' value='"+temp+"' />";
  $('hide_wrapper').innerHTML='<span class="hidee" onclick="password_type_change_to_password(\''+passwprd_id+'\')" onmouseover="link_over(this,\'#024999\')" onmouseout="link_out(this,\'#024999\')">Hide</span>';
	$(passwprd_id).focus();

}
function password_type_change_to_password(passwprd_id){
	var temp=$(passwprd_id).value;
	$('password_wrapper').innerHTML="<input type='password' name='user[password]' id='"+passwprd_id+"' value='"+temp+"' />";
  $('hide_wrapper').innerHTML='<span onclick="password_type_change_to_text(\''+passwprd_id+'\')" class="hidee" onmouseover="link_over(this,\'#024999\')" onmouseout="link_out(this,\'#024999\')">Show</span>'
	$(passwprd_id).focus();
}
/* naomi: this two functions are same as the two above but with tabidex */
function password_type_change_to_text_watchlist(passwprd_id){
	var temp=$(passwprd_id).value;
	$('password_wrapper').innerHTML="<input type='text' name='user[password]' id='"+passwprd_id+"' value='"+temp+"' tabindex='2' />";
  $('hide_wrapper').innerHTML='<span class="hidee" onclick="password_type_change_to_password_watchlist(\''+passwprd_id+'\')" onmouseover="link_over(this,\'#024999\')" onmouseout="link_out(this,\'#024999\')">Hide</span>';
	$(passwprd_id).focus();
}
function password_type_change_to_password_watchlist(passwprd_id){
	var temp=$(passwprd_id).value;
	$('password_wrapper').innerHTML="<input type='password' name='user[password]' id='"+passwprd_id+"' value='"+temp+"' tabindex='2' />";
  $('hide_wrapper').innerHTML='<span onclick="password_type_change_to_text_watchlist(\''+passwprd_id+'\')" class="hidee" onmouseover="link_over(this,\'#024999\')" onmouseout="link_out(this,\'#024999\')">Show</span>';
	$(passwprd_id).focus();
}

/*

 */

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length)).gsub(/\+/,' ');
	}

	if (user_cookie[name]) return ''+user_cookie[name];

	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function flush_cookies_by_prefix(prefix) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(prefix) == 0) {
			eraseCookie(c.substring(0,c.indexOf('=')));
		}
	}
}
function flush_all_notice_cookies() {
  flush_cookies_by_prefix("notice_");
	return null;
//	document.cookie = document.cookie.gsub(/notice_.*(;|$)/,'');
}

function flush_all_user_cookies() {
  flush_cookies_by_prefix("notice_");
  flush_cookies_by_prefix("user_");
  eraseCookie("watchlist_refresh_choose_password_after_authentication");
  eraseCookie('comments_rating');
  eraseCookie('author_slug');
  eraseCookie('last_comment');
  eraseCookie('last_comment_date');
  return null;
}


function logout() {
  (new GigyaSA()).logout();
}

function logout_completly() {
	//kof: this will be executed by the gigya.logout() callback.
	flush_all_user_cookies();
   if (/\/account\//.test(top.location.href)) {
     top.location.href = '/';
   } else {
     window.location.href = window.location.href;
   }
 }


function is_users_cookie_exists() {
	return (readCookie('user_id')!=null && readCookie('user_id')!='');
}

function unless_cookie_exists_update_element(id,content) {
  if (!is_users_cookie_exists()) {
	$(id).update(content);
	$(id).style.display='block';
  }	
}

function if_cookie_exists_update_element(id,content) {
  if (is_users_cookie_exists()) {
	$(id).update(content);
	$(id).style.display='block';
  }	
}

function set_login_and_registration_header() {
  if (is_users_cookie_exists()) {
    $('header').className='';
  }	
}

function set_login_and_registration_top_header(){
	$('floating_logged_in').style.display='none';
	$('floating_logged_out').style.display='none';
	
	if (is_users_cookie_exists()) {
		$('floating_logged_in').style.display='block';
		var user_id = readCookie('user_id');
		var user_nick = readCookie('user_nick');
		if (user_nick == null || user_nick == "") {
		  user_nick = "User " + user_id;
		}
		tmp_text=[];
		tmp_text.push('<div class="left_corner"></div><div class="right_corner"></div><ul>');
 		if (readCookie('author_slug')==null || readCookie('author_slug')=='') tmp_text.push('<li class="the_user_name"><a href="/user/'+user_id +'/profile">'+user_nick+'</a></li>');
		else tmp_text.push('<li class="the_user_name"><a href="/author/'+readCookie('author_slug') +'">'+user_nick+'</a></li>');
    tmp_text.push('<li><a href="/account/portfolio">Portfolio</a></li>');
		if (readCookie('author_slug')==null || readCookie('author_slug')=='') tmp_text.push('<li><a href="/user/'+user_id +'/stocktalk">StockTalk</a></li>');
		else tmp_text.push('<li><a href="/author/'+readCookie('author_slug') +'/stocktalk">StockTalk</a></li>');
		if (readCookie('author_slug')==null || readCookie('author_slug')=='') tmp_text.push('<li><a href="/user/'+user_id +'/instablog">Instablog</a></li>');
		else tmp_text.push('<li><a href="/author/'+readCookie('author_slug') +'/instablog">Instablog</a></li>');
		// tmp_text.push('<li><a href="#">Bookmarks</a></li>');
		tmp_text.push('<li><a href="/account/email_preferences" class="pad">Settings</a></li>');
		tmp_text.push('<li class="last">&nbsp;</li>');
                
    tmp_text.push('<li class="floating_sa_logo_li"><a class="floating_sa_logo_a" href="http://www.seekingalpha.com"></a></li>');
    tmp_text.push('<li class="logout_link_li"><span class="logout_link" onclick="logout()">Logout</span></li>');
    tmp_text.push('<li class="border_li">&nbsp;</li>');
                tmp_text.push('</ul>');
		$('floating_logged_in').innerHTML = tmp_text.join("");
	}
	else{
		$('floating_logged_out').style.display='block';
	}
}

function update_user_nick(id) {
  if (readCookie('user_nick')!=null) {
    $(id).value = readCookie('user_nick');
  }
}

function submit_account_preferences(obj) {
  if ($('current_email_fieldset2').style.display == 'block') {
    if (!validate_email('new_email','notice_account_preferences') == true) return false;
  }
  
  if ($('new_password_information').style.display == 'block') {
    if (!validate_password('old_password','notice_account_preferences','Please enter your current password for verification.',1,80) == true) return false;
    if (!validate_password('new_password','notice_account_preferences','Please enter a password with 4 to 40 characters.',4,40) == true) return false;
    if (!validate_password_confirmation("new_password","new_password_confirmation","notice_account_preferences") == true) return false;
  }  
  $('account_preferences').submit();
}

function nick_was_taken_alert() {
  if (confirm('The name/pseudonym you chose had already been taken.\nDo you want to go to your account preferences to choose a different name/pseudonym?')) {
    location.href = '/account/edit_bio'
  } else {
    return false;
  }
}

function nick_was_taken_alert_by_querystring() {
  if (getURLParam('nick_was_taken')=='true') { nick_was_taken_alert(); }  
}

function jump_to_anchor(anchor_name) {
  window.location.hash = anchor_name; 
}

function application_init(){
  /* ARIK CC */
  //initialize_tabs(); // << WHAT IT IS GOOD FOR?
  /* ARIK CC */
  //initialize_search_and_email_focus();
  nick_was_taken_alert_by_querystring();
  flush_all_notice_cookies();
}

function page_load() {
	SeekingAlpha.Initializer.RunAfterLoad.call(SeekingAlpha.Initializer);
}

function initialize_search_and_email_focus_per_element(id) {
  e = $(id);
  if (e.value == ''){    
    e.value = e.title; 
  }
  e.observe('focus', function(event){ if (e.value == e.title){ e.value = ''; }});
  e.observe('blur',  function(event){ if (e.value == '')     {	e.value = e.title; }});    
	
}

function change_location(href) {
  location.href = href;
}

function submit_form_if_has_proper_value(oForm,field) {
	if (field.value == "" || field.value == field.title) return false;  // if the value of _field_ is not blank and is not field.title
	oForm.submit();
}

function validate_and_refresh_cookie() {
	new Ajax.Request('/account/validate_and_refresh_cookie/', { method: 'get' });
}

function change_user(){
	$('user_email').style.width='285px';
	//$('user_email').disabled=false;
	$('user_email').style.color='black';
	$('user_email').style.borderWidth='1px';
  $('user_email').style.borderStyle='solid';
  $('user_email').style.borderColor='#999999 #d3d3d3 #d3d3d3 #999999';
  $('user_email').style.marginLeft='12px';
	$('change_user_email').style.display='none';
	$('current_email_fieldset2').style.display='block';
	$('email_change_warning').style.display='block';		
}

function account_preferences_change_password(){
	$('old_password_stars').style.display = 'none';
	$('new_password_information').style.display = 'block';
}

function init_unsubscribe_page() {
	if (is_users_cookie_exists()==true) {
		$("text_for_unlogged_user").style.display = 'none';
		$("text_for_logged_user").style.display = 'block';
    $("login_user_email").value = readCookie("user_email");
    $("login_user_email").readOnly = true;
	}
}

function validate_interests_section_in_promote_page() {
  var oObj,
    iInp,
    bCol1,bCol2,bCol3;
  for (iInp=0;oObj=document.forms["promote_form"]["vocation"][iInp];iInp++) {
    if (oObj.checked) bCol1 = true;
  }

  for (iInp=0;oObj=document.forms["promote_form"]["user_interests[]"][iInp];iInp++) {
    if (oObj.checked) bCol2 = true;
  }

  for (iInp=0;oObj=document.forms["promote_form"]["user_trading_frequence_tag_id"][iInp];iInp++) {
    if (oObj.checked) bCol3 = true;
  }

  if (bCol1 && bCol2 && bCol3)
    return "";
  else
    return "Please complete this section";
}

function ajax_submit_form(obj, location) {
  submit_button = obj.getElementsByClassName('submit')[0];
  loader_button = obj.getElementsByClassName('loader')[0];
  new Ajax.Request(location, {
    asynchronous:true,
    evalScripts:true, 
    parameters:Form.serialize(obj),
    onLoading: function(transport) {
      if (submit_button) { submit_button.disabled = true };
      if (loader_button) { loader_button.style.display = 'inline' };
    },
    onComplete: function(transport) {
      if (loader_button) { loader_button.style.display = 'none' };
      if (submit_button) { submit_button.disabled = false };
    }
  });
  return false;
}

function check_length(str,min,max) {
  return ((str.length>= min) && (str.length<= max));
}

function validate_field_confirmation(field_name,snd_field_name,notice_name,msg) {
  field = $(field_name);
  snd_field = $(snd_field_name);
  notice = $(notice_name);
  if (field.value != snd_field.value)  {
    notice.innerHTML = msg;
    snd_field.focus();
    return false;
  } else {
    return true;
  }
} 

function validate_password_confirmation(field_name,snd_field_name,notice_name) {
  return validate_field_confirmation(field_name,snd_field_name,notice_name,"Password does not match confirmation.")
}

function validate_email_confirmation(field_name,snd_field_name,notice_name) {
  return validate_field_confirmation(field_name,snd_field_name,notice_name,"Email does not match confirmation.")
}

function validate_email(field_name,notice_name) {
  field = $(field_name);
  notice = $(notice_name);
  if ((field.value.gsub(' ','') == '') || !rxEmail.test(field.value)) {
    notice.innerHTML = '<span class="\inner_notice\">Please enter a valid email address.</span>';
    field.focus();
    return false;
  } else {
    return true;
  }  
}

function validate_password(field_name,notice_name,notice_message,min,max) {
  field = $(field_name);
  notice = $(notice_name);
  if (!check_length(field.value.gsub(' ',''),min,max)) {
    notice.innerHTML = notice_message;
    field.focus();
    return false;
  } else {
    return true;
  }
}

function validate_title(field_name,notice_name,notice_message,min,max) {
  field = $(field_name);
  notice = $(notice_name);
  notice.innerHTML = '';
  if (!check_length(field.value.gsub(' ',''),min,max) || field.value == 'Enter your title here.') {
    notice.innerHTML = notice_message;
    field.focus();
    return false;
  } else {
    return true;
  }
}

function validate_nick(field_name,notice_name,notice_message) {
	if ($(field_name).value.trim()=='') {
		$(notice_name).innerHTML=notice_message;
		$(field_name).focus();
		return false;
	}

	return true;
}

function submit_choose_password_form(obj) {
  if ($('password').value!='') {
    if  ($('password').value==$('password_confirmation').value) {
	  obj.disabled=true;

      $('choose_password_form').submit();
    } else {
      $('notice_choose_password').innerHTML = 'Please use identical password for confirmation';
    }
  } else {
    $('password').focus();
  }
}

function submit_orthodox_registration_form(obj) {
  //$('notice_registration').innerHTML = "";
  if ($("I_agree_to_Terms").checked == false) {
    $('notice_registration').innerHTML = "Terms must be agreed in order to confirm registration";
    $('I_agree_to_Terms').focus();
    return false;
  } 

  if (!validate_email('register_user_email','notice_registration') == true) return false;
  if (!validate_password('register_user_password','notice_registration','Please enter a password with 4 to 40 characters.',4,40) == true) return false;

  if (!validate_password_confirmation("register_user_password","register_user_password_confirmation","notice_registration") == true) return false;

  if (obj) obj.disabled=true;
	if ($('slugs_input_reg').checked == true) {
		$('slugs_input_reg_pass').value = $('slugs_input_reg_pass').value + "," + $('slugs_input_reg').value;
	}
  $('orthodox_registration').submit();
}

function submit_orthodox_login_form() {
  //$('notice_login').innerHTML = '';

  if (!validate_email('login_user_email','notice_login') == true) return false;
  if (!validate_password('login_user_password','notice_login','Please enter your password.',1,80) == true) return false;
  
  $('orthodox_login').submit();
}

function submit_orthodox_login_form_ajax() {
  if (!validate_email('login_user_email_pop','notice_login_pop') == true) return false;
  if (!validate_password('login_user_password_pop','notice_login_pop','<span class=\"inner_notice\">Please enter your password.</span>',1,80) == true) return false;
  
  bInProcees=true;
  
  new Ajax.Request('/account/ajax_popup_login', {
    asynchronous:true,
    evalScripts:true,
    parameters:Form.serialize($('orthodox_login_pop')),
    onLoading: function(transport) {
		if ($('login_generic_loader')) $('login_generic_loader').style.display='';
	},
    onComplete: function(transport) {
      if (transport.responseText == 'success') {
        if (/\//.test(top.location.href.replace(/http:\/\/(?:.*?)\//,""))) window.location.href = window.location.href;
        else top.location.href = '/account/stocktalk';
      } else {
        $("notice_login_pop").innerHTML="<span class=\"inner_notice\">Username and password don't match, please try again!</span>";
		if ($('login_generic_loader')) $('login_generic_loader').style.display='none';
      }
      bInProcees=false;
    }
  });
}

function submit_orthodox_forgot_password() {
  if (!validate_email('user_email','notice_forgot_password') == true) return false;
  $('submit_btn_id').disabled = true;
  $('orthodox_forgot_password').submit();
}

function submit_orthodox_never_chose_password() {
  if (!validate_email('user_email','notice_never_chose_password') == true) return false;
  $('submit_btn_id').disabled = true;
  $('orthodox_never_chose_password').submit();
}

function ajax_submit_comment_register() {
  if ($("I_agree_to_Terms").checked == false) {
    $('notice_registration').innerHTML = "Terms must be agreed in order to confirm registration";
    $('I_agree_to_Terms').focus();
    return false;
  } 

  if ($('register_user_nick').value.trim()=='') {
	$('notice_registration').innerHTML="Please enter a name/pseudonym.";
	$('notice_registration').style.display='';
	return false;
  }
  if ((!validate_password('register_user_nick','notice_registration','Please enter a longer name/pseudonym.',2,80) == true)) return false;
  if (!validate_email('register_user_email','notice_registration') == true) return false;
  if (!validate_password('register_user_password','notice_registration','Please enter a password with 4 to 40 characters.',4,40) == true) return false;

  if (!validate_password_confirmation("register_user_password","register_user_password_confirmation","notice_registration") == true) return false;

  ajax_submit_form($('comment_registration'),'/account/submit_comment');
}

function ajax_submit_comment_login() {
  //$('notice_login').innerHTML = '';

  if (!validate_email('login_user_email','notice_login') == true) return false;
  if (!validate_password('login_user_password','notice_login','Please enter your password.',1,80) == true) return false;
  submit_btn = $('comment_login').getElementsByClassName('submit')[0]
  
  if (!submit_btn.disabled) {
    submit_btn.disabled = true;
    ajax_submit_form($('comment_login'),'/account/submit_comment');
  }
}

function ajax_submit_comment_forgot_password() {
  //$('notice_forgot_password').innerHTML = '';
  //$('notice_never_chose_password').innerHTML = '';
  if (!validate_email('forgot_password_user_email','notice_forgot_password') == true) return false;
  return ajax_submit_form($('comment_forgot_password'),'/account/submit_comment');
}

/* Article Toolbar - start */

var Article_Last_Size="small";

function setArticleFont(sSize) {
	var oArticle=$("article_body"),
		oLink=$("article-size-"+sSize)
		oCurrLink=$("article-size-"+Article_Last_Size);

	oCurrLink.className=Article_Last_Size;

	oArticle.className=sSize+"_font_size";
	oLink.className=sSize+"_selected";

	Article_Last_Size=sSize;

	createCookie("__article_last_size",sSize,30);
}

function load_article_toolbar() {
	var sSize=readCookie("__article_last_size");

	if (sSize!=null) setArticleFont(sSize);
}

/* Article Toolbar - end */


/* Seeking Google - start */

function addSeekingAlphaToolBar() {

 try{
  window.external.AddSearchProvider("http://"+document.domain+"/javascripts/seeking.xml?e=1");
 }

 catch(eX){
  if (70 == (eX.number & 0xFFFF))alert("For security reasons, you must use the mouse\n(or the Enter key) to click the Install button.");
  else alert("Unable to add search provider. The Create Your\nOwn tool requires Internet Explorer.   [" + (eX.number & 0xFFFF) + "]");
 }

}

/* Seeking Google - end */

/* Check if enter key was pressed, if so, submit form */
function KEY_FORM_PRESS(event,f) {
	var key = event.which || event.keyCode;

	if (key==13) f();
}

/* analytics set vocation */

function analytics_user_tracker() {
	var vocation = readCookie('user_vocation');
	switch(vocation)
	{
		case "": 
			var set_vocation ="Vocation Not Selected";
		    break;    
	    case "1":
			var set_vocation ="Vocation Not Selected";
	        break;    
	    case "2":
			var set_vocation ="Buy side (fund manager or analyst)";
		    break;    
	    case "3":
			var set_vocation ="Sell side (analyst, sales person or trader)";
		    break;    
	    case "4":
			var set_vocation ="Financial advisor or broker";
	        break;    
	    case "5":
			var set_vocation ="Investment banker";
		    break;    
	    case "6":
			var set_vocation ="Company executive or other industry expert";
		    break;    
	    case "7":
			var set_vocation ="Stock market blogger";
		    break;    
	    case "8":
			var set_vocation ="Individual investor";
		    break;    
	    case "9":
			var set_vocation ="Venture capitalist";
		    break;    
	    case "10":
	 	    var set_vocation =	"Investor relations";
		    break;    
	    case "11":
	 		var set_vocation ="Other Vocation";
			break;    
		default:
		  	var set_vocation ="Not Logged In";
			}
	__utmSetVar(set_vocation.gsub(' ','_'));
}


/* analytics set vocation */

function kknd_user(user_id) {
	if (confirm("Are you sure you want to delete this user and all the associated content? This CANNOT BE UNDONE.")) {
    new Ajax.Request('/moderator/ajax_kknd_user', {
      asynchronous:true,
      evalScripts:true,
      parameters:"user_id="+user_id,
      onComplete: function(transport) {
        if (transport.status == 200 && transport.responseText != "failed") {
          alert('Data for this user were fully removed.')
        }
      }
    });
	}
}

/* sa source */
function InitSASource() {
	var Links=$$('a'),
	  oLink,
	  iLink,
	  bUserLogin=is_users_cookie_exists();
	
  for (iLink=0;oLink=Links[iLink];iLink++) {
	  if (oLink.getAttribute("sasource") && oLink.href.indexOf("source=")==-1) {
		  oLink.href=oLink.href.indexOf("?")==-1 ? oLink.href+"?source="+oLink.getAttribute("sasource") : oLink.href+"&source="+oLink.getAttribute("sasource");
		  if (oLink.href.indexOf("#")!=-1) oLink.href=oLink.href.replace(/(\#(?:.*?))(\?|\&)/,"$2")+RegExp.$1;
	  }
  }
}

function remove_unneeded_article_from_most_popular_box(id) {
  if(obj = ($('most_popular_article_'+id) || $$('li.last_most_popular_article')[0])) {
    obj.style.display = 'none';
  }
}

function remove_unneeded_article_from_article_more_box(id) {
  if(obj = ($('recent_article_'+id) || $$('li.last_recent_article')[0])) {
    obj.style.display = 'none';
  }
}

function init_link_mafne_on_array(source, a_array) {
  a_array.each( function(e) { 
    e.onclick = function() {
      if (e.href.indexOf('mafne.html')==-1) {
        var anew_li = e
        while (!anew_li.id.match('anew_')) { anew_li = anew_li.parentNode } // to succeed even when the links are nested <li id="anew_xxx"><koko><a></a></koko></li>
        e.href = "/mafne.html?source=" + source + anew_li.id.gsub('anew_','&anew_id=') + "&url=" + escape(e.href);
      }
    }
  } )
}

function FindSymbol(oForm, bFromBtn) {
  var oAC=AutoCompleteSAConfig.Packages.transcript_symbol;

  if (bFromBtn && oAC.State=='open') oAC.AutoInsert();
  
  if (oForm.symbol.value.trim()=="" || oForm.symbol.value==oForm.symbol.title) {
    alert("Please enter a symbol");
    return false;
  }
  if (symbols.indexOf("<"+oForm.symbol.value.toUpperCase()+">")==-1) {
    alert("This symbol does not exist");
    return false;
  }
  urchinTracker('event/transcripts_center/search_box/symbol_transcript');
  location.href="/symbol/"+oForm.symbol.value.toLowerCase()+"/transcripts";
  return false;
}

function FindTermInAllTranscripts(oForm, page_name) {
  if (oForm.term.value.trim()=="" || oForm.term.value=='e.g. "recession"') {
    return false;
  }
  urchinTracker('event/' + page_name + '/search_box/search_all_transcripts');
  if(page_name == 'business_intelligence') {
    location.href="/searches/business_intelligence?term="+encodeURIComponent(oForm.term.value);
  } else {
    order_param = ((location.href.indexOf("order_by=relevance") > -1) ? "&order_by=relevance" : "");
    location.href = "/search/transcripts?term="+encodeURIComponent(oForm.term.value) + order_param;
  }
  return false;
}

function FindTermInSymbolTranscripts(oForm, page_name) {
	if (oForm.term.value.trim()=="") {
    return false;
  }
  urchinTracker('event/' + page_name + '/search_box/search_symbol_transcripts');
	location.href="/search/transcripts?symbol=" + oForm.symbol.value + "&term=" + encodeURIComponent(oForm.term.value);
  return false;	
}

// TODO: YEHUDA: I need to complete it.
function ajax_subscribe_to_transcripts() {
  if (bInProcees) return;
  if (is_users_cookie_exists() || rxEmail.test($("your_email_for_transcripts_list").value)==true) {
	  bInProcees=true;
	  new Ajax.Request('/account/subscribe_to_transcripts', {
	    asynchronous:true,
	    evalScripts:true,
	    parameters:"url_source="+escape(top.location.href)+"&user_email="+$('your_email_for_transcripts_list').value,
	    onLoading: function(transport) {
	    },
	    onComplete: function(transport) {
			bInProcees=false;
		}
	  });
  } else {
    display_error_message_in_daily_registration();
  }
}

function display_error_message_in_daily_registration() {
  $("error_message").style.display = "block";
}

function remove_error_message_in_daily_registration() {
  $("error_message").style.display = "none";
}

function display_get_daily_transcripts_list() {
  if (readCookie('user_non_watchlist_slugs') && readCookie('user_non_watchlist_slugs').split(",").indexOf('transcripts') > -1) {
    return false;
  }
  var tmp_text = [];
  
  
  tmp_text.push("<h5 class=\"transcript_alerts\">Transcript Alerts</h5>");
  tmp_text.push("<div><div class=\"get_alerts\">Get a daily email alert of new Transcripts - </div>");
  tmp_text.push("    <div class='sample' style='display:inline; zoom:1;'><span class='text' style='cursor:default; color:#024999;'  onmouseout='footer_advertbox_sample_out(\"new_transcripts_popup\");' onmouseover='footer_advertbox_sample_over(\"new_transcripts_popup\");'>Sample</span>");
  tmp_text.push("    <span class='hide_popup' id='new_transcripts_popup'>");
  tmp_text.push("    <div class='sample_bubble_left'>");
  tmp_text.push("      <div class='bubble_content_papa'><div class='bubble_content'>");
  tmp_text.push("        <div class='bb_14px_bold'>Seeking Alpha - Today's Transcripts</div>");
  tmp_text.push("				<ul>");
  tmp_text.push("          <li><span class='link'>Sangamo Biosciences Inc. Q3 2008 Earnings Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>The Spectranetics Corporation, Q3 2008 Earnings Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>ViroPharma Incorporated Q3 2008 Earnings Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>Berry Petroleum Co. Q3 2008 Earnings Conference Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>Encore Acquisition Company, Q3 2008 Earnings Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>First Solar, Inc. Q3 2008 Earnings Conference Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>Ameriprise Financial, Inc. Q3 2008 Earnings Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>Arthur J. Gallagher & Co. Q3 2008 Earnings Conference Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>Cincinnati Financial Corporation Q3 2008 Earnings Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>Corning, Inc. Q3 2008 (Quarter End 9/30/08) Earnings Call Transcript</span></li>");
  tmp_text.push("          <li><span class='link'>Harman International Industries Inc. F1Q09 (Qtr End 9/30/08) Earnings Call Transcript</span></li>");
  tmp_text.push("				</ul>");
  tmp_text.push("        <span class='email_continues'>Email continues...</span>");
  tmp_text.push("      </div>");
  tmp_text.push("      </div><div class='bubble_start_left'></div>");
  tmp_text.push("    </div>");
  tmp_text.push("    </span><!--end hide_popup--></div>");
  tmp_text.push("</div>");
  tmp_text.push("<div style='margin:10px 0 3px 0;'>");


  if (is_users_cookie_exists()) {
    tmp_text.push("<input type=\"text\" name=\"phrase\" class=\"signup\" id=\"your_email_for_transcripts_list\" style=\"display:none\" />");
  } else {
    tmp_text.push("<input type=\"text\" name=\"phrase\" class=\"signup\" value='Enter email address' title='Enter email address' id=\"your_email_for_transcripts_list\" onfocus=\"this.style.color='#000000';handleInput(this,'focus');\" onblur=\"this.style.color=this.value=='' ? '#BCBCBC' : '#000000';handleInput(this,'blur');\" onkeypress=\"if (event.keyCode==13) { ajax_subscribe_to_transcripts(); }\" />");
  }
  tmp_text.push("<input type=\"button\" class=\"submit\" value=\"Sign up\" onclick=\"ajax_subscribe_to_transcripts()\"/>");
  tmp_text.push('</div>');
  tmp_text.push('<span class="error_message" id="error_message" style="display:none">Please enter a valid email address</span>');
  //tmp_text.push("<div class=\"note\">We don't spam</div>");
  $('get_daily_transcripts_list').innerHTML = tmp_text.join("");
  initialize_search_and_email_focus_per_element('your_email_for_transcripts_list');
}

function create_footer_rss_advert_box() {
	var oCont=$('newsletters');
	
	oCont.innerHTML='<span class="seperator"></span><dd style="color:#000">Live Feeds</dd><dt><a href="/page/feeds" class="rss_option"><div class="rss_icon"></div>Stay up to date with<br />Seeking Alpha\'s <strong>live feeds</strong></a></dt>';

}

function new_advert_box_focus(o) {
	handleInput(o,'focus');

	o.style.color='#000000';
}

function new_advert_box_blur(o) {
	if (o.value=='') o.style.color='#959595';
	
	handleInput(o,'blur');
}

function footer_advertbox_sample_over(id) {
  var obj = $(id);
  $$('.show_popup').each( function(e) {
    if (obj != e) { e.className = 'hide_popup' }  
  } );
  
  obj.setAttribute('state','opened');
  if (obj.innerHTML != '') {
  	obj.className="show_popup";
  } else {
    new Ajax.Request("/footer_samples/"+id+".html", {
      asynchronous:true,
      method: 'get',
      onComplete: function(transport) {
        obj.innerHTML = transport.responseText;
      	obj.className="show_popup";
      }
    });
  }
}

function footer_advertbox_sample_out(id) {
  var obj = $(id);
  obj.setAttribute('state','closing');
  setTimeout(
    function(){
      if (obj.getAttribute('state') == 'closing') {
        obj.className="hide_popup";
      }
    },
    1000
  );
}

/* FOOTER ADVERT BOX - END */

function add_wl_icon_to_link(element) {
  var oLink;
  //alert(element.innerHTML)
  element.innerHTML = wl_icon_html + element.innerHTML;

  oLink=element.getElementsByTagName('A')[0];

  // oLink.href = add_wl_icon_source(oLink.href); // Yehuda: I removed the source from the wl icons
  wl_icon_articles.push(element)
}

var wl_icon_articles = [];
var non_wl_icon_articles = [];

function adding_wl_icon_for_watchlist_link(article_id, article_author, article_slugs) {
  var element = $("article_"+article_id),
	    symbols = $("article_symbols_"+article_id),
	    wl_icon_granted = false,
	    aSymbols;

  if (is_this_article_authors_in_my_watchlist(article_author)) {
    wl_icon_granted = true;
    
	$('article_author_'+article_id).addClassName('author_in_portfolio');
  }
  
  if (aSymbols = is_this_article_symbols_in_my_watchlist(article_slugs)) {
    // this return an array of slugs
    if (aSymbols.length) { // if there is no WL slug.. array will return empty
      wl_icon_granted = true;

	  if (symbols) symbols.innerHTML = aSymbols.join(", ");
    }
  }

  if (!wl_icon_granted) {
    non_wl_icon_articles.push(element)
  }
}

function add_stats_to_wl_icons() {
  if (wl_icon_articles.length > 0) {
    wl_icon_articles.each (function(e) {
      e.onclick = function() {
        var aImgs=e.getElementsByTagName('img');
        if (aImgs.length==2)
          urchinTracker('event/'+getWLIconPageName()+'/wl_and_editors_icons/clicked');
        else
          urchinTracker('event/'+getWLIconPageName()+'/wl_icon/clicked');
      }
    })
    non_wl_icon_articles.each (function(e) {
      e.onclick = function() {
		    var aImgs=e.getElementsByTagName('img');
		    if (aImgs.length==1)
		      urchinTracker('event/'+getWLIconPageName()+'/editors_icon/clicked');
		    else
		      urchinTracker('event/'+getWLIconPageName()+'/no_icon/clicked');
		  }
    })
  }
}

function getWLIconPageName() {
  if (top.location.href.indexOf("/author/") > -1) {
    return 'author_page';
  } else if (top.location.href.indexOf("/dashboard/") > -1) {
    return 'dashboard_page';
  } else {
    return 'sector_page'
  }
}

function wl_icon_mouseover(img) {
	var oLink=img.parentNode.getElementsByTagName('A')[0];

	oLink.className="wl_hover_link";
}

function wl_icon_mouseout(img) {
	var oLink=img.parentNode.getElementsByTagName('A')[0];

	oLink.className="dashboard_article_link";
}

function wl_icon_onclick(img) {
	var oLink=img.parentNode.getElementsByTagName('A')[0];
  if (oLink.click) oLink.click();
	else top.location.href=oLink.href;
}

// check if the author of the article in the user's watchlist (the function get only 1 author)
function is_this_article_authors_in_my_watchlist(author) {
  if (user_watchlist_authors_from_cookie && author) {
    return (("," + user_watchlist_authors_from_cookie + ",").indexOf(","+author+",") > -1);
  }
}

function send_me_watchlist_headline(obj) {
  loader = $('email_loader');
  // btn_submit = actual_form.getElementsByClassName("btn_submit")[0];   // submit button ...

  new Ajax.Request('/account/send_me_watchlist_headline', {
    asynchronous:true,
    parameters:"user_email_watchlist=" + (obj.checked ? '1' : '0'),
    onLoading: function(transport) {
      obj.style.display = 'none';
      loader.style.display = 'inline';        // whirling circle goes wild
    },
    onComplete: function(transport) {
      if (200 != transport.status) {
        alert("An error has occurred.");      // server communication lost
      }
      loader.style.display = 'none';        // whirling circle goes hidden
      obj.style.display = 'inline';
    }
  });
}

// check if the symbols of the article in the user's watchlist
function is_this_article_symbols_in_my_watchlist(slugs) {
  var articles_symbols_array = slugs,
	  aSymbolsWL = [],
	  aSymbols = [],
	  sSlug;
  if (user_watchlist_slugs_from_cookie && slugs.length) {
    for (var i=0;sSlug=articles_symbols_array[i];i++) {
  	  if (("," + user_watchlist_slugs_from_cookie + ",").indexOf(","+sSlug+",") > -1) {
  	    aSymbolsWL.push('<a href="/symbol/' + sSlug + '" class="symbol_in_portfolio">' + sSlug.toUpperCase() + '</a>');
  	  } else {
  	    aSymbols.push('<a href="/symbol/' + sSlug + '" class="dashboard_article_link">' + sSlug.toUpperCase() + '</a>');
      }
  	  if (aSymbolsWL.length == 3) return aSymbolsWL;
    }

    if (aSymbolsWL.length) aSymbolsWL = aSymbolsWL.concat(aSymbols.slice(0,3-aSymbolsWL.length));

    return aSymbolsWL;
  }
  return false;
}

function add_wl_icon_source(link) {
  if (/(?:\?|\&)source\=/i.test(link)) {
    return link.replace(/(\?|\&)source\=(.*?)(\&|$)/i,"$1source=wl_icon$2");
  } else {
    return link=link+(link.indexOf("?")==-1 ? "?" : "&")+"source=wl_icon";
  }
}

function display_results_order_by(order_by) {
  if (order_by == "") {
    location.href = location.href.gsub(/&order_by=.*(\?|\&|$)/i,"");
  } else if (location.href.indexOf('order_by') == -1) {
    add_this = "&order_by="+order_by;
    location.href = location.href + add_this;
  }
}

function display_all_results() {
  location.href = location.href.gsub("&last_quarters=true","");
}

function adslot_refreshination(slot) { 
  if ((slot == "ETFs_Quotepage_728x90_leaderboard") && isRefresh) {
    slot = "ETFs_QuotePage_728x90_leaderboard"
  };
  return (isRefresh && (refreshed_ads_slots.indexOf(slot) != -1) ) ? slot + '_refreshed' : slot;
}

function GA_googleFillSlot_sa(slot) { 
  GA_googleFillSlot(adslot_refreshination(slot));
}

function GA_googleAddSlot_sa(slot) { 
  GA_googleAddSlot("ca-pub-1420150919334552", adslot_refreshination(slot));
}

function isRefresh() {
   return /source\=refreshed/i.test(top.location.href);
}

function print_article(type) {
  if (type=='no_comments') $('comments').className=$('comments').className.replace(' print_comments','');
  else if (type=='with_comments') $('comments').className=$('comments').className+' print_comments';
  urchinTracker('event/'+article_page_kind()+'_page/click_print/print_'+type);
  print();
}

function GetArticleId() {
  var rx=/\/article\/(\d+?)\-/;

  rx.test(top.location.href);

  return RegExp.$1;
}

function initialize_search_and_email_focus_per_element(id) {
  e = $(id);
  if (e.value == ''){    
    e.value = e.title; 
  }
  e.observe('focus', function(event){ if (e.value == e.title){ e.value = ''; }});
  e.observe('blur',  function(event){ if (e.value == '')     {	e.value = e.title; }});
}

function ajax_dashboard_subscription_widget(dashboard_slug) {
  new Ajax.Request("/account/ajax_dashboard_subscription_widget", {
    asynchronous:true,
    evalScripts:true, 
    parameters:"dashboard_slug="+dashboard_slug,
    onComplete: function(transport) {
      if (transport.responseText == 'success') {
        $('dashboard_advert_box').innerHTML = '<div style="font-size: 13px; margin-top: 14px">You have successfully signed-up for this email!</div>';
      } else if (transport.responseText == 'unlogged') {
        top.location.href = '/account/login?slugs='+dashboard_slug;
      }
    }
  });
}

function is_subscribed_to_dashboard(dashboard_slug) {
  return (readCookie('user_non_watchlist_slugs') && readCookie('user_non_watchlist_slugs').split(",").indexOf(dashboard_slug) > -1);
}
function init_dashboard_subscription_widget(dashboard_slug) {
  if (is_users_cookie_exists()) {
    if (is_subscribed_to_dashboard(dashboard_slug)) return false;
    $$('.get_btn_c')[0].onclick = function() { ajax_dashboard_subscription_widget(dashboard_slug) }
    $('dashboard_advert_box_container').style.display = 'inline';
  } else {
    $$('.get_btn_c')[0].onclick = function() { top.location.href = '/account/login?slugs='+dashboard_slug }
    $('dashboard_advert_box_container').style.display = 'inline';
  } 
}

// Yehuda: this st input box is w/o jspell
function display_logged_in_stocktalks_input_box() {
  var form = [];
  form.push("<div class='note' style='display: none;' id='stocktalk_form_alert_add_stocktalk'></div>");
  form.push("<form method='post' id='stock_talk_form' class='stock_talk_form' style='position:relative;float:left'>");
    form.push("<div class='question_and_spellcheck'>");
      form.push("<p>How are you investing and why?</p>");
    form.push("</div>");
    form.push("<textarea onkeyup='return charCounter(this);' onkeydown='return charCounter(this);' onpaste='setTimeout(function () { charCounter(this); }.bind(this),10)' tabindex='99' id='stock_talk_textarea' name='stock_talk[content]'></textarea>");
    form.push("<div class='char_counter_with_settings'>");
      form.push("<div class='char_counter' id='char_counter'>140 characters left</div>");
      form.push("<span style='display: none;' id='gigya_settings_stock_talk'> | <a target='_blank' href='/account/twitter_and_facebook_settings'>Settings</a></span>");
    form.push("</div>");
    form.push("<input type='button' onclick='doneChecking();ajax_submit_stock_talk(this,false, false)' class='submit' tabindex='100' id='stocktalk_submit_button' value='Submit'/>");
  form.push("</form>");
  form.push("<div id='gigya_unit' class='gigya_unit'></div>");

  return form.join('');
}

function display_logged_out_stocktalks_input_box() {
  var form = [];
  form.push("<div class='question_and_spellcheck'>");
    form.push("<p>How are you investing and why?</p>");
  form.push("</div>");
  form.push("<textarea onkeypress='return false;' onkeydown='return false;' onclick='open_header_log_in_popup_lightbox(\"stocktalk\",\"post a stocktalk\")'></textarea>");
  form.push("<div class='char_counter_with_settings'>");
    form.push("<div class='char_counter'>140 characters left</div>");
  form.push("</div>")
  form.push("<input type='button' class='submit' value='Submit' onclick='open_header_log_in_popup_lightbox(\"stocktalk\",\"post a stocktalk\")' />");

  return form.join('');
}

function checkSpelling(Suffix)
{
	var Sffix=Suffix || '';

	if (!window.jspellIsAttached) return;
	if(!jspellIsAttached()) {
		$('jSpellReCheck'+Sffix).style.display='';
		$('jSpellDone'+Sffix).style.display='';
		$('jSpellCheck'+Sffix).style.display='none';
	}
		
	jspellOnDemandCheck();
}

function doneChecking(Suffix) {  
  var Sffix=Suffix || '';
  
  if (!window.jspellIsAttached) return;
  if(jspellIsAttached()) {
	  $('jSpellReCheck'+Sffix).style.display='none';
	  $('jSpellDone'+Sffix).style.display='none';
	  $('jSpellCheck'+Sffix).style.display='';
	  jspellDetach();

	  $('dmv').style.display='none';
	  $('snv').style.display='none';
	  $('dnv').style.display='none';
  }
}

function jspellPostInit() {
	$('jSpellCheck').style.display='block';
};

Event.observe(window, 'load', function() { page_load(); });
