///////////////////////
//Make selection of tabs in setting page
//Author = Alpesh Modi
//10 Mar,2008
///////////////////////

var new_sources_counter = 0;
//This counter is used to put sources list in sample extended user details. Also to put comma between sources.
var total_sources_counter = 0;
//this counter used to put user get me links in sample box.This will set from '_about_user.rhtml' file.
var dynamic_service_fields_counter = 0;

var toggleSetting = function (settingPage){
	switch(settingPage)
		{
		case 'settings':
			//change tab class
			$('tab_settings').className = "setting_active";
			$('tab_about_me').className = "setting_inactive";
			$('tab_picture').className = "setting_inactive";
			$('tab_emails').className = "setting_inactive";
			$('tab_notification').className = "setting_inactive";
			$('tab_alert').className = "setting_inactive";
			$('tab_tools').className = "setting_inactive";
			//show/hide div's
			$('about_me').style.display = 'none';
			$('settings_container').style.display = 'block';
			$('news_alert_div').style.display = 'none';
			$('notification_div').style.display = 'none';
			$('change_picture_div').style.display = 'none';
			$('set_emails_div').style.display = 'none';
			$('sm_tools_div').style.display = 'none';
			return true;
		case 'picture':
			//change tab class
			$('tab_about_me').className = "setting_inactive";
			$('tab_settings').className = "setting_inactive";
			$('tab_picture').className = "setting_active";
			$('tab_emails').className = "setting_inactive";
			$('tab_notification').className = "setting_inactive";
			$('tab_alert').className = "setting_inactive";
			$('tab_tools').className = "setting_inactive";
			//show/hide div's
			$('about_me').style.display = 'none';
			$('settings_container').style.display = 'none';
			$('news_alert_div').style.display = 'none';
			$('notification_div').style.display = 'none';
			$('change_picture_div').style.display = 'block';
			$('set_emails_div').style.display = 'none';
			$('sm_tools_div').style.display = 'none';
			return true;
		case 'emails':
			//change tab class
			$('tab_about_me').className = "setting_inactive";
			$('tab_settings').className = "setting_inactive";
			$('tab_picture').className = "setting_inactive";
			$('tab_emails').className = "setting_active";
			$('tab_notification').className = "setting_inactive";
			$('tab_alert').className = "setting_inactive";
			$('tab_tools').className = "setting_inactive";
			//show/hide div's
			$('about_me').style.display = 'none';
			$('settings_container').style.display = 'none';
			$('news_alert_div').style.display = 'none';
			$('notification_div').style.display = 'none';
			$('change_picture_div').style.display = 'none';
			$('set_emails_div').style.display = 'block';
			$('sm_tools_div').style.display = 'none';
			return true;
		case 'notification':
			//change tab class
			$('tab_about_me').className = "setting_inactive";
			$('tab_settings').className = "setting_inactive";
			$('tab_notification').className = "setting_active";
			$('tab_picture').className = "setting_inactive";
			$('tab_emails').className = "setting_inactive";
			$('tab_alert').className = "setting_inactive";
			$('tab_tools').className = "setting_inactive";
			//show/hide div's
			$('about_me').style.display = 'none';
			$('settings_container').style.display = 'none';
			$('notification_div').style.display = 'block';
			$('news_alert_div').style.display = 'none';
			$('change_picture_div').style.display = 'none';
			$('set_emails_div').style.display = 'none';
			$('sm_tools_div').style.display = 'none';
			return true;
		case 'alert':
			//change tab class
			$('tab_about_me').className = "setting_inactive";
			$('tab_settings').className = "setting_inactive";
			$('tab_picture').className = "setting_inactive";
			$('tab_emails').className = "setting_inactive";
			$('tab_notification').className = "setting_inactive";
			$('tab_alert').className = "setting_active";
			$('tab_tools').className = "setting_inactive";
			//show/hide div's
			$('about_me').style.display = 'none';
			$('settings_container').style.display = 'none';
			$('news_alert_div').style.display = 'block';
			$('notification_div').style.display = 'none';
			$('change_picture_div').style.display = 'none';
			$('set_emails_div').style.display = 'none';
			$('sm_tools_div').style.display = 'none';
			return true;
		case 'password':
			//change tab class
			$('tab_about_me').className = "setting_inactive";
			$('tab_password').className = "setting_active";
			$('tab_email').className = "setting_inactive";
			$('tab_picture').className = "setting_inactive";
			$('tab_emails').className = "setting_inactive";
			$('tab_notification').className = "setting_inactive";
			$('tab_alert').className = "setting_inactive";
			$('tab_tools').className = "setting_inactive";
			//show/hide div's
			$('about_me').style.display = 'none';
	  		$('change_password_div').style.display = 'block';
			$('change_email_div').style.display = 'none';
			$('news_alert_div').style.display = 'none';
			$('notification_div').style.display = 'none';
			$('change_picture_div').style.display = 'none';
			$('set_emails_div').style.display = 'none';
			$('sm_tools_div').style.display = 'none';
			return true;
		case 'popular':
			//change tab class
			$('tab_popular').className = "setting_active";
			$('tab_recent').className = "setting_inactive";
			$('tab_rising_fast').className = "setting_inactive";
			$('tab_abc_xyz').className = "setting_inactive";
			//show/hide div's
			$('tag_cloud_popular').style.display = 'block';
			return true;
		case 'recent':
		    //change tab class
			$('tab_popular').className = "setting_inactive";
			$('tab_recent').className = "setting_active";
			$('tab_rising_fast').className = "setting_inactive";
			$('tab_abc_xyz').className = "setting_inactive";
			//show/hide div's
			$('tag_cloud_recent').style.display = 'block';
			return true;
		case 'rising_fast':
			//change tab class
			$('tab_popular').className = "setting_inactive";
			$('tab_recent').className = "setting_inactive";
			$('tab_rising_fast').className = "setting_active";
			$('tab_abc_xyz').className = "setting_inactive";
			//show/hide div's
			$('tag_cloud_rising_fast').style.display = 'block';
			return true;
		case 'topics':
			//change tab class
			$('tab_popular').className = "setting_inactive";
			$('tab_recent').className = "setting_inactive";
			$('tab_rising_fast').className = "setting_inactive";
			$('tab_abc_xyz').className = "setting_active";
			//show/hide div's
			$('tag_cloud_abc_xyz').style.display = 'block';
			return true;
		default:
			//change tab class
			$('tab_about_me').className = "setting_active";
			$('tab_settings').className = "setting_inactive";
			$('tab_picture').className = "setting_inactive";
			$('tab_notification').className = "setting_inactive";
			$('tab_alert').className = "setting_inactive";
			$('tab_tools').className = "setting_inactive";
			//show/hide div's
			$('about_me').style.display = 'block';
			$('settings_container').style.display = 'none';
			$('news_alert_div').style.display = 'none';
			$('settings_container').style.display = 'none';
			$('change_picture_div').style.display = 'none';
			$('sm_tools_div').style.display = 'none';
			return true;
		case 'tools':
			//change tab class
			$('tab_about_me').className = "setting_inactive";
			$('tab_settings').className = "setting_inactive";
			$('tab_notification').className = "setting_inactive";
			$('tab_picture').className = "setting_inactive";
			$('tab_emails').className = "setting_inactive";
			$('tab_alert').className = "setting_inactive";
			$('tab_tools').className = "setting_active";
			//show/hide div's
			$('about_me').style.display = 'none';
			$('settings_container').style.display = 'none';
			$('notification_div').style.display = 'none';
			$('news_alert_div').style.display = 'none';
			$('change_picture_div').style.display = 'none';
			$('set_emails_div').style.display = 'none';
			$('sm_tools_div').style.display = 'block';
			return true;
		}
}

var expandUserInfoOnMyPage = function (link){
	if(link.innerHTML == "more"){
		$('more_profile').style.display = 'block';
		link.innerHTML = "less";
	}
	else{
		$('more_profile').style.display = 'none';
		link.innerHTML = "more";
	}
}

// Check user's added source existency and then add it.
var checkUserFavoriteSource = function (){
	var urlValidation = /(http|https):\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
	if($('user_favorite_source_txt').value == ''){
		alert("Please enter the full URL Eg. http://www.socialmedian.com");
	}else if(!urlValidation.test($('user_favorite_source_txt').value)){
		alert("Please enter the full URL Eg. http://www.socialmedian.com");
	}else{
		$('add_loading').style.display = 'block';
		var postParameters = "source_url=" + $('user_favorite_source_txt').value;
		var ajaxRequestOptions = {
			// Use POST
			method: 'post',
			// Send this lovely data
			postBody: postParameters,
			// Handle successful response
			onSuccess: checkUserFavoriteSourceCallback,
			// Handle 404
			on404: checkUserFavoriteSource404Callback,
			// Handle other errors
			onFailure: checkUserFavoriteSourceFailureCallback
		}
		new Ajax.Request('/check_url', ajaxRequestOptions);
	}
}
var checkUserFavoriteSourceCallback = function (response){
	//eval the json object
	var response_data = response.responseText.evalJSON();
	if(response_data.ok == true)
	{
		if(response_data.source_id != null){
			$('add_loading').style.display = 'none';
			//Call to function which will add source name above add source text.
			addUserFavoriteSource(response_data.source_name, response_data.source_id);
		}
		else{
			$('add_loading').style.display = 'none';
			alert("You have already entered this source.");
		}
		new_sources_counter ++;
	}
	else{
		$('add_loading').style.display = 'none';
		alert("Please check URL.");
	}
}
/**
 * userUpdate failure callback function
 */
var checkUserFavoriteSourceFailureCallback = function (){
	$('add_loading').style.display = 'none';
	alert("Please check URL....");
}
/**
 * userUpdate 404 callback function
 */
var checkUserFavoriteSource404Callback = function (){
	alert("Error page is not found");
}

// Remove user source.
var removeUserFavoriteSource = function (user_source_id){
	$('remove_loading_'+user_source_id).style.display = 'block';
	var postParameters = "source_id=" + user_source_id;
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: removeUserFavoriteSourceCallback,
		// Handle 404
		on404: removeUserFavoriteSource404Callback,
		// Handle other errors
		onFailure: removeUserFavoriteSourceFailureCallback
	}
	new Ajax.Request('/remove-source', ajaxRequestOptions);
}
var removeUserFavoriteSourceCallback = function (response){
	//eval the json object
	var response_data = response.responseText.evalJSON();
	if(response_data.ok == true)
	{
		//remove whole div containing this source.
		$(response_data.source_id).parentNode.parentNode.removeChild($(response_data.source_id).parentNode);
		//remove appropriate span in sample extended user details (ui).
		$('user_ext_source_'+response_data.source_id+'_div').parentNode.removeChild($('user_ext_source_'+response_data.source_id+'_div'));
		total_sources_counter--;
		//remove whole my source div in sample extended user details (ui).
		if(total_sources_counter <= 0) $('source_list_container_div').style.display = 'none';
	}
	else{
		alert("Sorry its not removed.");
		return false;
	}
}
/**
 * removeUserFavoriteSource failure callback function
 */
var removeUserFavoriteSourceFailureCallback = function (){
		alert("Sorry its not removed.");
}
/**
 * removeUserFavoriteSource 404 callback function
 */
var removeUserFavoriteSource404Callback = function (){
	alert("Error page is not found");
}
var addUserFavoriteSource = function (source_name, source_id){
		if($('user_favorite_source_txt').value!=''){
				$('user_favorite_sources_list_div').innerHTML = $('user_favorite_sources_list_div').innerHTML
																+ '<div style="width:100%;" >'
																+ '	<div style="float:left;width:230px;overflow:hidden"> '
																+ ' <a href="'+ $('user_favorite_source_txt').value +'" title="'+ $('user_favorite_source_txt').value +'">'
																+ ' <span style="width:210px;">'
																+ 		source_name
																+ ' </span></a>'
																+ '</div> '
																+ '	<div id="'+ source_id + '" style="float:right;width:60px;padding:3px 0px 0px 0px;font-family:arial;color:#000000;font-size:11px;font-style:arial;" >'
																+ ' 	<div style="float:left;padding:0px;cursor:pointer;" onclick="removeUserFavoriteSource(' + source_id + ');">'
																+ '			Delete'
																+ '		</div>'
																+ '		<div id="remove_loading_'+source_id+'" style="display:none;float:left;padding:0px 0px 0px 5px;">'
																+ '			<img src="'+ S3_STATIC_ASSETS_PATH + '/images/loader.gif">'
																+ '		</div>'
																+ '		<br clear="all">'
																+ '	</div>'
																+ '</div>';
		}
		$('user_favorite_source_txt').value = '';
		total_sources_counter++;
		setUserSourcesInSample(source_name, source_id);
}
var divValuesToHiddenField = function (){
//	addUserFavoriteSource();
	var favourite_sources = new Array();
	$$('#user_favorite_sources_list_div a').each(
												function(child){
													var pass_value = child.getElementsBySelector("span").first().innerHTML + '==' + child.href;
													favourite_sources.push(pass_value);
												}
											  );
	$('user_favorite_sources').value = favourite_sources.join('<<>>')
//	$('user_favorite_sources').value = favourite_sources
	new_sources_counter = 0;
	return true;
}

var saveNotificationChanges = function (){
	$('notification_success_message').style.display = 'block';
	var postParameters = Form.serialize("email_notification_frm");
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: saveNotificationChangesCallback,
		// Handle 404
		on404: saveNotificationChanges404Callback,
		// Handle other errors
		onFailure: saveNotificationChangesFailureCallback
	}
	new Ajax.Request('/change-notification', ajaxRequestOptions);
}
var saveNotificationChangesCallback = function (response){
	//eval the json object
	var response_data = response.responseText.evalJSON();
	if(response_data.ok == true){
		$('notification_success_message').style.color = '#008000';
		$('notification_success_message').innerHTML = "Information saved successfully!!.";
		$('notification_status_span').innerHTML = ' On';
		$('notification_status_span').style.color = '#008000';
		$('start_stop_notifications_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: stopAllNotifications();">Click <font style="color:#2A2AFF;">here</font> to turn off your Notifications.</a><br />'
													 + '<span style="font-size:11px;">(<b>Warning:</b> Not recommended. You will not be notified when other users are attempting to communicate with you.)</span>';
		$('global_mails_status_span').innerHTML = ' On';
		$('global_mails_status_span').style.color = '#008000';
		$('global_on_off_div').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: globalMailsOff();">Click <font style="color:#2A2AFF;">here</font> to turn off all emails from socialmedian.  </a><br />'
										   +'<span style="font-size:12px;font-weight: normal;">(<b>Warning:</b> This will turn off all socialmedian emails, including when other users are trying to communicate with you.)</span>';
	}
	else{
		$('notification_success_message').style.display = 'none';
		$('notification_success_message').style.color = '#FF0000';
		$('notification_success_message').innerHTML = "Sorry, its system problem.";
	}
}
/**
 * saveNotificationChanges failure callback function
 */
var saveNotificationChangesFailureCallback = function (){
	$('save_username_notice_div').style.display = 'none';
	$('notification_success_message').style.color = '#FF0000';
	$('notification_success_message').innerHTML = "Sorry, its system problem.";
}
/**
 * saveNotificationChanges 404 callback function
 */
var saveNotificationChanges404Callback = function (){
	$('save_username_notice_div').style.display = 'none';
	$('notification_success_message').style.color = '#FF0000';
	$('notification_success_message').innerHTML = "Sorry, its system problem.";
}



var saveUserName = function (){
	$('save_username_notice_div').style.display = 'block';
	var postParameters = 'username=' + $('socialmedian_url').value;
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: saveUserNameCallback,
		// Handle 404
		on404: saveUserName404Callback,
		// Handle other errors
		onFailure: saveUserNameFailureCallback
	}
	new Ajax.Request('/save-user-name', ajaxRequestOptions);
}
var saveUserNameCallback = function (response){
	//eval the json object
	var response_data = response.responseText.evalJSON();
	if(response_data.ok == true){
		$('save_username_notice_div').style.color = '#008000';
		$('save_username_notice_div').innerHTML = 'Information saved successfully';

	}
	else{
		$('save_username_notice_div').style.display = 'none';
		alert("Sorry, its system problem.");
	}
}
/**
 * removeUserFavoriteSource failure callback function
 */
var saveUserNameFailureCallback = function (){
	$('save_username_notice_div').style.display = 'none';
	alert("Sorry, its system problem.");
}
/**
 * removeUserFavoriteSource 404 callback function
 */
var saveUserName404Callback = function (){
	$('save_username_notice_div').style.display = 'none';
	alert("Error page is not found");
}


var saveUsrMiniProfile = function (){
	$('mini_profile_notice_div').style.display = 'block';
	//Reset field values to nil if required.
	if($('user[f_name]').value == 'First Name') $('user[f_name]').value = '';
	if($('user[l_name]').value == 'Last Name') $('user[l_name]').value = '';
	if($('user[city]').value == 'City') $('user[city]').value = '';
	if($('user[state]').value == 'State') $('user[state]').value = '';
	if($('user[country]').value == 'Country') $('user[country]').value = '';
	if($('user[company]').value == 'Company') $('user[company]').value = '';
	if($('user[job_title]').value == 'Job Title') $('user[job_title]').value = '';
	if($('user[industry]').value == 'Industry') $('user[industry]').value = '';

	var postParameters = Form.serialize("user_mini_profile_frm");
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: saveUsrMiniProfileCallback,
		// Handle 404
		on404: saveUsrMiniProfile404Callback,
		// Handle other errors
		onFailure: saveUsrMiniProfileFailureCallback
	}
	new Ajax.Request('/user-mini-profile', ajaxRequestOptions);
}
var saveUsrMiniProfileCallback = function (response){
	//eval the json object
	var response_data = response.responseText.evalJSON();
	if(response_data.ok == true){
		$('mini_profile_notice_div').style.color = 'green';
		$('mini_profile_notice_div').innerHTML = 'Information saved successfully';

	}
	else{
		$('mini_profile_notice_div').style.display = 'none';
		alert("Sorry, its system problem.");
	}
	//Reset field values to nil if required.
	if($('user[f_name]').value == '') $('user[f_name]').value = 'First Name';
	if($('user[l_name]').value == '') $('user[l_name]').value = 'Last Name';
	if($('user[city]').value == '') $('user[city]').value = 'City';
	if($('user[state]').value == '') $('user[state]').value = 'State';
	if($('user[country]').value == '') $('user[country]').value = 'Country';
	if($('user[company]').value == '') $('user[company]').value = 'Company';
	if($('user[job_title]').value == '') $('user[job_title]').value = 'Job Title';
	if($('user[industry]').value == '') $('user[industry]').value = 'Industry';

}
/**
 * removeUserFavoriteSource failure callback function
 */
var saveUsrMiniProfileFailureCallback = function (){
	$('mini_profile_notice_div').style.display = 'none';
	alert("Sorry, its system problem.");
}
/**
 * removeUserFavoriteSource 404 callback function
 */
var saveUsrMiniProfile404Callback = function (){
	$('mini_profile_notice_div').style.display = 'none';
	alert("Error page is not found");
}

function validateSpecialCharacter(val) {
	if (val.match(/[^a-zA-z0-9_\-]/)!=null) {
		return true;
	} else {
		return false;
	}
}

var saveUsrExtProfile = function (){
	if($('user_favorite_source_txt').value != ''){
		var urlValidation = /(http|https):\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
		if(!urlValidation.test($('user_favorite_source_txt').value)){
			alert("Please, either keep blank or enter the full URL Eg. http://www.socialmedian.com  in Favorite News Sources");
			return false;
		}
	}
	$('ext_profile_notice_div').style.display = 'block';
	$('user[hero_fname]').value = $('user[hero_fname]').value=='First Name' ? '' : $('user[hero_fname]').value;
	$('user[hero_lname]').value = $('user[hero_lname]').value=='Last Name' ? '' : $('user[hero_lname]').value;
	var postParameters = Form.serialize("user_ext_profile_frm");
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: saveUsrExtProfileCallback,
		// Handle 404
		on404: saveUsrExtProfile404Callback,
		// Handle other errors
		onFailure: saveUsrExtProfileFailureCallback
	}
	new Ajax.Request('/about_user', ajaxRequestOptions);
}
var saveUsrExtProfileCallback = function (response){
	//eval the json object
	var response_data = response.responseText.evalJSON();
	if(response_data.ok == true){
		$('ext_profile_notice_div').innerHTML = 'Information saved successfully';
		if($('user[hero_fname]').value == '') $('user[hero_fname]').value = 'First Name';
		if($('user[hero_lname]').value == '') $('user[hero_lname]').value = 'Last Name';
		//alert(response_data.service_notice);
		if(response_data.service_notice != []){
			$('error_container').style.display = 'block';
			$('error_container').innerHTML = response_data.service_notice.join('<br>');
		}else{
			$('error_container').style.display = 'none';
		}
	}
	else{
		$('ext_profile_notice_div').style.display = 'none';
		$('error_container').style.display = 'none';
		alert("Sorry, its system problem.");
	}
}
/**
 * removeUserFavoriteSource failure callback function
 */
var saveUsrExtProfileFailureCallback = function (){
		$('ext_profile_notice_div').style.display = 'none';
		$('error_container').style.display = 'none';
		alert("Sorry, its system problem.");
}
/**
 * removeUserFavoriteSource 404 callback function
 */
var saveUsrExtProfile404Callback = function (){
	$('ext_profile_notice_div').style.display = 'none';
	alert("Error page is not found");
}

var toggleServiceButtonLook = function (icon){
	$('twitter_icon').style.border = '2px solid #FFFFFF';
	$('friendfeed_icon').style.border = '2px solid #FFFFFF';
	$('facebook_icon').style.border = '2px solid #FFFFFF';
	$('linkedin_icon').style.border = '2px solid #FFFFFF';
	$('flickr_icon').style.border = '2px solid #FFFFFF';
	$('myblog_icon').style.border = '2px solid #FFFFFF';
	$('myspace_icon').style.border = '2px solid #FFFFFF';
	$('googlereader_icon').style.border = '2px solid #FFFFFF';
	$('youtube_icon').style.border = '2px solid #FFFFFF';
	$('digg_icon').style.border = '2px solid #FFFFFF';
	$('delicious_icon').style.border = '2px solid #FFFFFF';
	$('other_icon').style.border = '2px solid #FFFFFF';

	$(icon+'_icon').style.border = '2px solid #000000';
	$(icon+'_option').selected = 'selected';
}
var createOtherLinkBox = function (service){
	$('service_update_box_div').innerHTML = '<div align="left" style="">'
										  + '  	<form id="'+service+'_frm" name="'+service+'_frm">'
										  + '		<div style="padding:0px;margin:0px;">'
										  + '			<input type="text" id="service_name" name="service_name" style="width:200px;"> <br>'
										  + ' 			Site Name '
										  + '			<input type="hidden" id="service_catagory" name="service_catagory" value="other">'
									 	  + '		</div>'
										  + '		<div style="padding:7px 0px 0px 0px;margin:0px;">'
										  + '			<input type="text" id="service_value_txt" name="service_value_txt" style="width:200px;" onkeypress="Javascript: if(event.keyCode == 13){if(this.value!=\'\'){saveUserLink(\''+service+'\'); return false;}}"> &nbsp;'
										  + '			<a style="text-decoration:underline;cursor:pointer;" onclick="Javascript: saveUserLink(\''+service+'\');"> Add </a> <br>'
										  + ' 			Profile URL '
									 	  + '		</div>'
										  + ' 	</form>'
										  + '</div>'
}

var createMylinkUpdateBox = function (service_display_name, service, eg_url){
	var value = '';
	try{
		value = $(service +'_value_div').innerHTML.strip();
	}catch (e) {}
	$('service_update_box_div').innerHTML = '<div align="left" style="">'
										  + '  	<form id="'+service+'_frm" name="'+service+'_frm">'
										  + '		<div style="padding:0px;margin:0px;">'
										  + '			<input type="text" id="service_value_txt" name="service_value_txt" value="'+value+'" style="width:200px;" onkeypress="Javascript: if(event.keyCode == 13){if(this.value!=\'\'){saveUserLink(\''+service+'\'); return false;}}">'
										  + '			<input type="hidden" id="service_name" name="service_name" value="'+service+'"> &nbsp;'
										  + '			<a style="text-decoration:underline;cursor:pointer;" onclick="Javascript: saveUserLink(\''+service+'\');"> Add </a>'
										  + ' 		</div>'
										  + '		<div style="padding:0px;margin:0px;">'
										  + '			Add your ' + service_display_name
									 	  + '		</div>'
										  + ' 		<div style="padding:0px;color:rgb(255,102,0);font-size:11px;font-family:arial;">'
										  + 	 		eg_url
										  + ' 		</div>'
										  + ' 	</form>'
										  + '</div>';
}

var saveUserLink = function (service){
	var err_msg = "";
	if(service == 'myblog' && ($('service_value_txt').value.strip() == "" || $('service_value_txt').value.strip().indexOf("http://") != 0)) {
		err_msg = "Invalid Blog url!";
	} else if(service == 'twitter' && ($('service_value_txt').value.strip() == '' || validateSpecialCharacter($('service_value_txt').value.strip()))) {
		err_msg = "Invalid Twitter user name!";
	} else if(service == 'facebook' && ($('service_value_txt').value.strip() == '' || $('service_value_txt').value.strip().indexOf("http://www.facebook.com/") != 0)) {
		err_msg = "Invalid Facebook url!";
	} else if(service == 'myspace' && ($('service_value_txt').value.strip() == "" || validateSpecialCharacter($('service_value_txt').value.strip()))) {
		err_msg = "Invalid MySpace user name!";
	} else if(service == 'linkedin' && ($('service_value_txt').value.strip() == "" || $('service_value_txt').value.strip().indexOf("http://www.linkedin.com") != 0)) {
		err_msg = "Invalid LinkedIn url!";
	} else if(service == 'flickr' && ($('service_value_txt').value.strip() == "" || validateSpecialCharacter($('service_value_txt').value.strip()))) {
		err_msg = "Invalid Flickr user name!";
	} else if(service == 'youtube' && ($('service_value_txt').value.strip() == "" || validateSpecialCharacter($('service_value_txt').value.strip()))) {
		err_msg = "Invalid YouTube user name!";
	} else if(service == 'googlereader' && ($('service_value_txt').value.strip() == "" || $('service_value_txt').value.strip().indexOf("http://www.google.com/reader/shared/") != 0)) {
		err_msg = "Invalid Google Reader url!";
	} else if(service == 'delicious' && ($('service_value_txt').value.strip() == "" || validateSpecialCharacter($('service_value_txt').value.strip()))) {
		err_msg = "Invalid del.icio.us user name!";
	} else if(service == 'digg' && ($('service_value_txt').value.strip() == "" || validateSpecialCharacter($('service_value_txt').value.strip()))) {
		err_msg = "Invalid Digg user name!";
	} else if(service == 'friendfeed' && ($('service_value_txt').value.strip() == "" || validateSpecialCharacter($('service_value_txt').value.strip()))) {
		err_msg = "Invalid Friend Feed user name!";
	} else if(service == 'other') {
		if($('service_name').value.strip() == "")
			err_msg = "Site Name can't be blank!";
		else if($('service_value_txt').value.strip() == "" || $('service_value_txt').value.strip().indexOf("http://") != 0)
			err_msg = "Invalid profile URL!";
	}
	if(err_msg != "") {
		alert(err_msg);
		return false;
	}
	$('add_link_to_list_loading_div').style.display = 'block';
	var postParameters = Form.serialize(service+'_frm');
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: saveUserLinkCallback,
		// Handle 404
		on404: saveUserLink404Callback,
		// Handle other errors
		onFailure: saveUserLinkFailureCallback
	}
	new Ajax.Request('/save-user-links', ajaxRequestOptions);
}
var saveSuggestedUserLink = function (connection_id, service, service_value){
	$('remove_suggested_link_loading_span_'+connection_id).innerHTML = '<img src="'+S3_STATIC_ASSETS_PATH+'/images/loader.gif" /> Saving your url..'
	var postParameters = "connection_id="+connection_id+'&service_name='+service+'&service_value_txt='+service_value;
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: saveUserLinkCallback,
		// Handle 404
		on404: saveUserLink404Callback,
		// Handle other errors
		onFailure: saveUserLinkFailureCallback
	}
	new Ajax.Request('/save-user-links', ajaxRequestOptions);
}
/**
 * userUpdate success callback function
 */
var saveUserLinkCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok == true ) {
		//Call the function to display service url in list field and in sample preview window also.
		showSavedUserServiceUrl(response_data.saved_service);
		response_data.non_actioned_connections.length > 0 ? fillIsThisYouBox(response_data.non_actioned_connections) : $('is_this_you_div').style.display = 'none';

		$('add_link_to_list_loading_div').style.display = 'none';
		try{$('mylink_none_div').innerHTML = '';}catch (e){}
		//Fill one dummy div which will help to show service value into fields filled.
		$(response_data.saved_service.service_name +'_value_div').innerHTML = response_data.saved_service.show_service_url;
	}
}
/**
 * userUpdate failure callback function
 */
var saveUserLinkFailureCallback = function (){
	alert("Error on page");
	$('add_link_to_list_loading_div').style.display = 'none';
}
/**
 * userUpdate 404 callback function
 */
var saveUserLink404Callback= function (){
	alert("Error page is not found");
	$('add_link_to_list_loading_div').style.display = 'none';
}

var fillIsThisYouBox = function (connections){
	var contents = '';
	for(var i = 0; i<connections.length; i++)
	{
		contents = contents
				 + '<div style="width:100%;padding:5px 0px 5px 0px;margin:0px;border-top:1px solid #AFAFAF;">'
				 + '	<span style="float:left;width:60%;overflow:hidden;">'
				 + ' 		<a href="'+connections[i].user_profile_url+'" title="'+connections[i].user_profile_url+'" style="text-decoration:none;cursor:pointer;color:#000;overflow:hidden;">'
				 + 				connections[i].display_profile.truncate(26,'...')
				 + '		</a>'
				 + '	</span>'
				 + '	<span style="float:left;width:35%;overflow:hidden;padding:0px 0px 0px 10px;">';
		if(connections[i].service_name != 'other'){
			contents = contents
				 + '		<div style="width:20px;float:left;">'
				 + ' 			<img height="16px" weidth="16px" src="'+S3_STATIC_ASSETS_PATH+'/images/'+ connections[i].service_name +'_icon.gif" />'
				 + '		</div>'
				 + '		<div style="float:left;" title="'+connections[i].service_name+'">'
				 + 				connections[i].service_name
				 + '		</div>';
		}else{
			contents = contents
				 + '		<span style="width:20px;">'
				 + ' 			<img height="16px" weidth="16px" src="'+S3_STATIC_ASSETS_PATH+'/images/myblog_icon.gif" />'
				 + '		</span>';
		}
		contents = contents
				 + '	</span>'
				 + '	<br clear="all">'
				 + '	<span style="float:left;width:30%;">'
				 + '		<a style="text-decoration:underline;cursor:pointer;" onclick="saveSuggestedUserLink('+connections[i].id+', \''+connections[i].service_name+'\',\''+connections[i].user_profile_url+'\')"> Yes </a>&nbsp;&nbsp;'
				 + '		<a style="text-decoration:underline;cursor:pointer;" onclick="rejectConnectionUrl('+connections[i].id+')"> No </a>'
				 + '	</span>'
				 + '	<span id="remove_suggested_link_loading_span_'+connections[i].id+'" style="float:left;width:60%;">'
				 + '	</span>'
				 + '	<br clear="all">'
				 + '</div>';
	}
	$('is_this_you_div').style.display = 'block';
	$('is_this_you_container_div').innerHTML = contents;
}

var rejectConnectionUrl = function (connection_id){
	$('remove_suggested_link_loading_span_'+connection_id).innerHTML = '<img src="'+S3_STATIC_ASSETS_PATH+'/images/loader.gif" /> Removing url..'
	var postParameters = "connection_id="+connection_id;
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: rejectConnectionUrlCallback,
		// Handle 404
		on404: rejectConnectionUrl404Callback,
		// Handle other errors
		onFailure: rejectConnectionUrlFailureCallback
	}
	new Ajax.Request('/reject-suggested-connection', ajaxRequestOptions);

}
/**
 * rejectConnectionUrl success callback function
 */
var rejectConnectionUrlCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	((response_data.ok == true ) && (response_data.non_actioned_connections.length > 0)) ? fillIsThisYouBox(response_data.non_actioned_connections) : $('is_this_you_div').style.display = 'none';;
}
/**
 * rejectConnectionUrl failure callback function
 */
var rejectConnectionUrlFailureCallback = function (){
	alert("Error on page");
}
/**
 * rejectConnectionUrl 404 callback function
 */
var rejectConnectionUrl404Callback= function (){
	alert("Error page is not found");
}

var showSavedUserServiceUrl = function (saved_service){
	//Remove service from the service list, if previously displayed .
	try{
		$('service_'+saved_service.id).parentNode.parentNode.removeChild($('service_'+saved_service.id).parentNode);
	}catch (e) {}
	try{
		$('user_ext_service_'+ saved_service.id+'_div').parentNode.removeChild($('user_ext_service_'+ saved_service.id +'_div'));
	}catch (e) {}
	//Add saved service in the list.
	user_service_url_list = '';
	user_service_url_list = user_service_url_list
						 + '<div style="padding: 0px 0px 8px 0px;width:100%;font-family:arial;color:#000000;font-size:12px;font-style:arial;">'
						 + '	<div style="width:10%;float:left;">'
						 + '		<a class="snap_noshots" href="'+ saved_service.service_url+'" title="'+ saved_service.service_url+'" style="text-decoration:none;cursor:pointer;">';
	if(saved_service.service_name != 'other' && saved_service.service_catagory != 'other'){
		user_service_url_list = user_service_url_list
						 + ' 			<img height="16px" weidth="16px" src="'+S3_STATIC_ASSETS_PATH+'/images/'+ saved_service.service_name +'_icon.gif" />&nbsp;';
	}else{
		user_service_url_list = user_service_url_list
						 + ' 			<img height="16px" weidth="16px" src="'+S3_STATIC_ASSETS_PATH+'/images/myblog_icon.gif" />&nbsp;';
	}
	user_service_url_list = user_service_url_list
						 + '		</a>'
						 + '	</div>'
						 + '	<div style="width:65%;float:left;overflow:hidden;">'
						 + '		<a class="snap_noshots" href="'+ saved_service.service_url+'" title="'+ saved_service.service_url+'" style="text-decoration:none;cursor:pointer;">'
						 +  		 	saved_service.show_service_url.truncate(29,'...')
						 + '		</a>'
						 + ' 	</div>'
						 + ' 	<div id="'+ saved_service.service_name +'_value_div" align="left" style="display:none;">'
						 + 			saved_service.show_service_url
						 + '	</div>'
						 + ' 	<div id="service_'+ saved_service.id +'" style="float:right;width:16%;padding:0px;color:#000000;" onclick="removeUserServiceUrl('+ saved_service.id +');">'
						 + ' 		<div style="float:left;padding:0px;cursor:pointer;">'
						 + ' 			<img src="'+S3_STATIC_ASSETS_PATH+'/images/editdelete.png" />'
						 + ' 		</div>'
						 + ' 		<div id="remove_loading_url_'+ saved_service.id +'" style="display:none;float:right;padding:0px;">'
						 + ' 			&nbsp;<img src="'+S3_STATIC_ASSETS_PATH+'/images/loader.gif">'
						 + ' 		</div>'
						 + ' 		<br clear="all">'
						 + ' 	</div>'
						 + '	<br clear="all">'
						 + '</div>';

	$('user_service_url_list').innerHTML = $('user_service_url_list').innerHTML + user_service_url_list;
	$('join_me_container_div').style.display = 'block';
	$('join_me_div').innerHTML = $('join_me_div').innerHTML
							   + '<span id="user_ext_service_'+ saved_service.id+'_div" title="'+saved_service.service_url+'">';
	if(saved_service.service_name != 'other' && saved_service.service_catagory != 'other'){
		$('join_me_div').innerHTML = $('join_me_div').innerHTML
								   + '<img height="16px" width="16px" src="'+S3_STATIC_ASSETS_PATH+'/images/'+ saved_service.service_name+'_icon.gif" />&nbsp;';
	}else{
		$('join_me_div').innerHTML = $('join_me_div').innerHTML
								   + '<img height="16px" width="16px" src="'+S3_STATIC_ASSETS_PATH+'/images/myblog_icon.gif" />&nbsp;';
	}
	$('join_me_div').innerHTML = $('join_me_div').innerHTML
								+' </span>';
}

var removeUserServiceUrl = function (service_id){
	var postParameters = "service_id="+service_id;
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: removeUserServiceUrlCallback,
		// Handle 404
		on404: removeUserServiceUrl404Callback,
		// Handle other errors
		onFailure: removeUserServiceUrlFailureCallback
	}
	new Ajax.Request('/remove-user-links', ajaxRequestOptions);
}
/**
 * removeUserServiceUrl success callback function
 */
var removeUserServiceUrlCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok == true ) {
		//remove whole div containing this service from service list.
		$('service_'+response_data.service_id).parentNode.parentNode.removeChild($('service_'+response_data.service_id).parentNode);
		if(response_data.user_services.length == 0) {
			$('user_service_url_list').innerHTML = '<div id="mylink_none_div" style="padding: 0px 0px 8px 10px;width:100%;">	None</div>'
		}
		//remove appropriate span in sample extended user details (ui).
		$('user_ext_service_'+response_data.service_id+'_div').parentNode.removeChild($('user_ext_service_'+response_data.service_id+'_div'));
		if($('join_me_div').innerHTML.strip() == '') $('join_me_container_div').style.display = 'none';
	}
}
/**
 * removeUserServiceUrl failure callback function
 */
var removeUserServiceUrlFailureCallback = function (){
	alert("Error on page");
}
/**
 * removeUserServiceUrl 404 callback function
 */
var removeUserServiceUrl404Callback= function (){
	alert("Error page is not found");
}


var createDynamicServiceField = function (){
	var dynamic_service_fields_container_div = $('dynamic_service_fields_container_div');
	var dynamic_service_field_div = document.createElement('div');
	//increment counter first.
	dynamic_service_fields_counter++;
	dynamic_service_field_div.innerHTML = ' <div style="padding:0px;float:left;width:145px;"> '
										+ '		<input type="text" id="service_name_'+ dynamic_service_fields_counter +'" name="service_name[]" value="Service name" onfocus="javascript: if(this.value==\'Service name\'){this.value=\'\'; this.style.color=\'black\';} this.style.textAlign=\'left\';" onblur="Javascript: this.style.textAlign=\'right\';" onkeyup="javascript: setUserLinksInSample();" onkeydown="javascript: setUserLinksInSample();" style="width:85px;color:#7F7F7F;font-family:arial;"> : '
										+ ' </div> '
										+ ' <div style="padding:0px 0px 13px 5px;float:left;"> '
										+ ' 	<input type="text" id="service_url_'+ dynamic_service_fields_counter +'" name="service_url[]" value="Service URL" onfocus="javascript: if(this.value==\'Service URL\'){this.value=\'\'; this.style.color=\'black\';}" onkeyup="javascript: setUserLinksInSample();" onkeydown="javascript: setUserLinksInSample();" style="width:200px;color:#7F7F7F;font-family:arial;"> '
										+ ' </div> '
										+ '	<br clear="all">'
	dynamic_service_fields_container_div.appendChild(dynamic_service_field_div);
}

var clearDefaultValuesAndSubmit = function (){
	if($('user[hero_fname]').value == 'Louis'){
		$('user[hero_fname]').value = '';
	}
	if($('user[hero_lname]').value == 'Armstrong'){
		$('user[hero_lname]').value = '';
	}
	document.about_user.submit()
}

var setHiroFnameValueFoc = function (){
	if($('user[hero_fname]').value == 'Louis'){
		$('user[hero_fname]').value = '';
		$('user[hero_fname]').style.color = 'black';
	}
}

var setHiroFnameValueBlur = function (){
	if($('user[hero_fname]').value == ''){
		$('user[hero_fname]').value = 'Louis';
		$('user[hero_fname]').style.color = 'gray';
	}
}

var setHiroLnameValueFoc = function (){
	if($('user[hero_lname]').value == 'Armstrong'){
		$('user[hero_lname]').value = '';
		$('user[hero_lname]').style.color = 'black';
	}
}

var setHiroLnameValueBlur = function (){
	if($('user[hero_lname]').value == ''){
		$('user[hero_lname]').value = 'Armstrong';
		$('user[hero_lname]').style.color = 'gray';
	}
}

var setUserNameInSample = function (){
	var user_name;
	var first_name = (($('user[f_name]').value != '') && ($('user[f_name]').value != 'First Name')) ? $('user[f_name]').value : '';
	var last_name = (($('user[l_name]').value != '') && ($('user[l_name]').value != 'Last Name')) ? $('user[l_name]').value : '';
	if((first_name != '') || (last_name != '')){
		user_name = first_name + ' ' + last_name;
	}else{
		user_name = $('socialmedian_url').value;
	}
//	alert(user_name);
	//$('username_div').innerHTML = user_name;
	$('username_ext_div').innerHTML = user_name;
}
var setUserLocationInSample = function (){
	var user_location = [];
	if(($('user[city]').value != '') && ($('user[city]').value != 'City')) user_location.push($('user[city]').value);
	if(($('user[state]').value != '') && ($('user[state]').value != 'State')) user_location.push($('user[state]').value);
	if(($('user[country]').value != '') && ($('user[country]').value != 'Country')) user_location.push($('user[country]').value);

	//Hide for mini profile sample changes.
	//$('user_location_div').innerHTML = user_location.join(', ');
	$('user_location_ext_div').innerHTML = user_location.join(', ');
}
var setUserCompanyInSample = function (){
	if(($('user[company]').value != '') && ($('user[company]').value != 'Company')) {
		//$('company_name_div').style.display = 'block';
		//$('company_name_div').innerHTML = 'Company - '+$('user[company]').value;
		$('company_name_ext_div').style.display = 'block';
		$('company_name_ext_div').innerHTML = 'Company - '+$('user[company]').value;
	}else {
		//$('company_name_div').style.display = 'none';
		$('company_name_ext_div').style.display = 'none';
	}
}

var setUserJobTitleInSample = function (){
	if(($('user[job_title]').value != '') && ($('user[job_title]').value != 'Job Title')) {
		//$('job_title_div').style.display = 'block';
		//$('job_title_div').innerHTML = 'Job title - '+$('user[job_title]').value;
		$('job_title_ext_div').style.display = 'block';
		$('job_title_ext_div').innerHTML = 'Job title - '+$('user[job_title]').value;
	}else {
		//$('job_title_div').style.display = 'none';
		$('job_title_ext_div').style.display = 'none';
	}
}

var setUserIndustryInSample = function (){
	if(($('user[industry]').value != '') && ($('user[industry]').value != 'Industry')) {
		//$('industry_div').style.display = 'block';
		//$('industry_div').innerHTML = 'Industry - '+$('user[industry]').value;
		$('industry_ext_div').style.display = 'block';
		$('industry_ext_div').innerHTML = 'Industry - '+$('user[industry]').value;
	}else {
		//$('industry_div').style.display = 'none';
		$('industry_ext_div').style.display = 'none';
	}
}

var setUserNEThingInSample = function (){
	try{
		if($('user[n_e_thing]').value.length <= 0){
			$('n_e_thing_container_div').style.display='none';
			//$('n_e_thing_info_container_div').style.display='none';
		}else if($('user[n_e_thing]').value.length > 150){
			$('n_e_thing_container_div').style.display='block';
			//$('n_e_thing_info_container_div').style.display='block';
			//$('n_e_thing_info_span').innerHTML = $('user[n_e_thing]').value.truncate(150,' ...')
			//								   +'<a style="text-decoration:underline;color:#7F7F7F;">'
			//						 		   +'	more'
			//						 		   +'</a> ';
			$('n_e_thing_span').innerHTML = $('user[n_e_thing]').value;
		}else{
			$('n_e_thing_container_div').style.display='block';
			//$('n_e_thing_info_container_div').style.display='block';
			//$('n_e_thing_info_span').innerHTML = $('user[n_e_thing]').value;
			$('n_e_thing_span').innerHTML = $('user[n_e_thing]').value;
		}
	}catch(e){ alert(e) }
}

var setUserHeroInSample = function (){
//	alert($('user[hero_fname]').value);
	var user_hero = '';
	var hero_first_name = (($('user[hero_fname]').value != '') && ($('user[hero_fname]').value != 'First Name')) ? $('user[hero_fname]').value : '';
	var hero_last_name = (($('user[hero_lname]').value != '') && ($('user[hero_lname]').value != 'Last Name')) ? $('user[hero_lname]').value : '';

	if((hero_first_name != '') || (hero_last_name != '')){
		$('hero_name_container_div').style.display = 'block';
		user_hero = hero_first_name + ' ' + hero_last_name;
	}else{
		$('hero_name_container_div').style.display = 'none';
	}
	$('hero_name_div').innerHTML = user_hero;
}

var setUserTopicsInSample = function (){
	if($('user_favorite_topics').value != ''){
		$('topic_list_container_div').style.display = 'block';
		$('topic_list_div').innerHTML = $('user_favorite_topics').value;
	}else{
		$('topic_list_container_div').style.display = 'none';
	}
}

var setUserLinksInSample = function (){
	var user_links = '';
	if($('user[link_to_myblog]').value != '') user_links = user_links + 'My Blog <br>';
	if($('user[link_to_twitter]').value != '') user_links = user_links + 'Twitter <br>';
	if($('user[link_to_facebook]').value != '') user_links = user_links + 'Facebook <br>';
	if($('user[link_to_myspace]').value != '') user_links = user_links + 'My Space <br>';
	if($('user[link_to_linkedin]').value != '') user_links = user_links + 'Linkedin <br>';
	if($('user[link_to_flickr]').value != '') user_links = user_links + 'Flickr <br>';
	if($('user[link_to_youtube]').value != '') user_links = user_links + 'You Tube <br>';
	if($('user[link_to_googlereader]').value != '') user_links = user_links + 'Google Reader <br>';
	if($('user[link_to_delicious]').value != '') user_links = user_links + 'del.icio.us <br>';
	if($('user[link_to_digg]').value != '') user_links = user_links + 'Digg <br>';
	if($('user[link_to_friendfeed]').value != '') user_links = user_links + 'Friend Feed <br>';
	for(var i=1; i<=dynamic_service_fields_counter; i++)
	{
		if($('service_name_'+ i).value != '' && $('service_name_'+ i).value != 'Service name') user_links = user_links + $('service_name_'+ i).value +'<br>';
	}

	if(user_links != ''){
		$('join_me_container_div').style.display = 'block';
		$('join_me_div').innerHTML = user_links;
	}else{
		$('join_me_container_div').style.display = 'none';
	}
}

var setUserSourcesInSample = function (source_name, source_id){
	if(total_sources_counter > 0){
		$('source_list_container_div').style.display = 'block';
		if(total_sources_counter == 1){
			$('source_list_container_div').innerHTML = '<div align="right" style="width:108px;float:left;padding:5px 0px 0px 0px;margin:0px;font-family:arial;font-weight:bold;color:#8D8D8D;font-size:12px;">'
													+'		My sources : '
													+'	</div>'
													+'	<div align="left" id="source_list_div" style="width:153px;float:left;padding:5px 0px 0px 7px;margin:0px;font-family:arial;color:#02488E;font-size:12px;overflow:hidden;">'
													+'		<span id="user_ext_source_'+source_id+'_div">'
													+			source_name
													+'		</span>'
													+'  </div>'
													+'  <br clear="all">';

		}
		else{
			$('source_list_div').innerHTML = $('source_list_div').innerHTML
											+'<span id="user_ext_source_'+source_id+'_div">'
											+'	, '+ source_name
											+'</span>' ;
		}
	}else{
		$('source_list_container_div').style.display = 'none';
	}
}

var testSocialGraph = function (){
	alert("Come here..");
	var postParameters = 'q=friendfeed.com/sunilkhedar';
	var ajaxRequestOptions = {
		// Use POST
		method: 'get',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: testSocialGraphCallback,
		// Handle 404
		on404: testSocialGraph404Callback,
		// Handle other errors
		onFailure: testSocialGraphFailureCallback
	}
	new Ajax.Request('http://socialgraph.apis.google.com/lookup', ajaxRequestOptions);
	alert("Come here..1111");
}
/**
 * userUpdate success callback function
 */
var testSocialGraphCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	alert(response_data);
}
/**
 * userUpdate failure callback function
 */
var testSocialGraphFailureCallback = function (){
	alert("Error on page");
}
/**
 * userUpdate 404 callback function
 */
var testSocialGraph404Callback= function (){
	alert("Error page is not found");
}

var updateUserInfo = function (){
	var error_message = '';
	// If error_message contains error message, means invalidate, display it.
	if(error_message != '')
	{
		//Alert By filling error div.
		$('email_error_div').innerHTML = '';
		$('email_error_div').innerHTML = error_message;
		return false;
	}

	var postParameters = Form.serialize("user_update");
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: userUpdateForFeedCallback,
		// Handle 404
		on404: userUpdateForFeed404Callback,
		// Handle other errors
		onFailure: userUpdateForFeedFailureCallback
	}
	new Ajax.Request('/Show_userinfo_on_mypage', ajaxRequestOptions);
}
/**
 * userUpdate success callback function
 */
var userUpdateForFeedCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.error == 1) {
		$('error_message_div').style.display = 'block';
		$('error_message_div').innerHTML = response_data.message;
	}
	else{
		$('success_message_div').style.display = 'block';
		$('success_message_div').innerHTML = response_data.message;
		$('user_info_fname').innerHTML = response_data.user_info.f_name + '&nbsp;';
		$('user_info_lname').innerHTML = response_data.user_info.l_name;
		$('user_info_city').innerHTML = response_data.user_info.city + ',&nbsp;';
		$('user_info_state').innerHTML = response_data.user_info.state + ',&nbsp;';
		$('user_info_country').innerHTML = response_data.user_info.country;
		$('user_info_company').innerHTML = response_data.user_info.company;
	}
}
/**
 * userUpdate failure callback function
 */
var userUpdateForFeedFailureCallback = function (){
	alert("Error on page");
}
/**
 * userUpdate 404 callback function
 */
var userUpdateForFeed404Callback= function (){
	alert("Error page is not found");
}

function removePreviousMessages(){
//	$$(".action_status_message").each(function(element){element.toggle();});
}


/**
 * stopAllNotifications globaly in one click.
 */
var stopAllNotifications = function (){
	$('start_stop_notifications_loading').style.display = 'block';
	var postParameters = '';
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: stopAllNotificationsCallback,
		// Handle 404
		on404: stopAllNotifications404Callback,
		// Handle other errors
		onFailure: stopAllNotificationsFailureCallback
	}
	new Ajax.Request('/stop-all-notifications', ajaxRequestOptions);
}

/**
 *stopAllNotifications globaly in one click success callback
 */
var stopAllNotificationsCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok){
		$('start_stop_notifications_loading').style.display = 'none';
		$('notification_status_span').innerHTML = ' Off';
		$('notification_status_span').style.color = '#FF0000';
		$('start_stop_notifications_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: startAllNotifications();">Click <font style="color:#2A2AFF;">here</font> to turn on your Notifications.</a>';

		//Uncheck all option setting for notification
		var notification_on_buttons = document.getElementsByClassName('on');
		for(i=0; i<notification_on_buttons.length; i++){
			notification_on_buttons[i].checked = false;
		}
		var notification_off_buttons = document.getElementsByClassName('off');
		for(i=0; i<notification_off_buttons.length; i++){
			notification_off_buttons[i].checked = true;
		}
	}
}
/**
 * stopAllNotifications globaly in one click. failure callback function
 */
var stopAllNotificationsFailureCallback = function (){
	alert("Error on page");
}
/**
 * stopAllNotifications globaly in one click 404 callback function
 */
var stopAllNotifications404Callback= function (){
	alert("Error page is not found");
}
/**
 * startAllNotifications globaly in one click.
 */
var startAllNotifications = function (){
	$('start_stop_notifications_loading').style.display = 'block';
	var postParameters = '';
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: startAllNotificationsCallback,
		// Handle 404
		on404: startAllNotifications404Callback,
		// Handle other errors
		onFailure: startAllNotificationsFailureCallback
	}
	new Ajax.Request('/start-all-notifications', ajaxRequestOptions);
}

/**
 *startAllNotifications globaly in one click success callback
 */
var startAllNotificationsCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok){
		$('start_stop_notifications_loading').style.display = 'none';
		$('notification_status_span').innerHTML = ' On';
		$('notification_status_span').style.color = '#008000';
		$('start_stop_notifications_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: stopAllNotifications();">Click <font style="color:#2A2AFF;">here</font> to turn off your Notifications.</a><br />'
													 + '<span style="font-size:11px;">(<b>Warning:</b> Not recommended. You will not be notified when other users are attempting to communicate with you.)</span>';

		//Uncheck all option setting for notification
		var notification_on_buttons = document.getElementsByClassName('on');
		for(i=0; i<notification_on_buttons.length; i++){
			notification_on_buttons[i].checked = true;
		}
		var notification_off_buttons = document.getElementsByClassName('off');
		for(i=0; i<notification_off_buttons.length; i++){
			notification_off_buttons[i].checked = false;
		}
		//Start global mails also
		$('global_mails_status_span').innerHTML = ' On';
		$('global_mails_status_span').style.color = '#008000';
		$('global_on_off_div').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: globalMailsOff();">Click <font style="color:#2A2AFF;">here</font> to turn off all emails from socialmedian.  </a><br />'
										   +'<span style="font-size:12px;font-weight: normal;">(<b>Warning:</b> This will turn off all socialmedian emails, including when other users are trying to communicate with you.)</span>';
	}
}
/**
 * startAllNotifications globaly in one click. failure callback function
 */
var startAllNotificationsFailureCallback = function (){
	alert("Error on page");
}
/**
 * startAllNotifications globaly in one click 404 callback function
 */
var startAllNotifications404Callback= function (){
	alert("Error page is not found");
}


/**
 * stopAlerts globaly in one click.
 */
var stopAlerts = function (){
	$('start_stop_alert_loading').style.display = 'block';
	var postParameters = '';
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: stopAlertsCallback,
		// Handle 404
		on404: stopAlerts404Callback,
		// Handle other errors
		onFailure: stopAlertsFailureCallback
	}
	new Ajax.Request('/stop-alerts', ajaxRequestOptions);
}

/**
 *stopAlerts globaly in one click success callback
 */
var stopAlertsCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok){
		$('start_stop_alert_loading').style.display = 'none';
		$('alert_status_span').innerHTML = ' Off';
		$('alert_status_span').style.color = '#FF0000';
		$('start_stop_alert_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: startAlerts();">Click <font style="color:#2A2AFF;">here</font> to turn on your News Alerts.</a>';
		//Uncheck all alert buttons and in last check "0 alerts per day"
		for(i=0; i<=4; i++){
			$(i+'_alerts').checked = false;
		}
		$('0_alerts').checked = true;
	}
}
/**
 * stopAlerts globaly in one click. failure callback function
 */
var stopAlertsFailureCallback = function (){
	alert("Error on page");
}
/**
 * stopAlerts globaly in one click 404 callback function
 */
var stopAlerts404Callback= function (){
	alert("Error page is not found");
}


/**
 * startAlerts globaly in one click.
 */
var startAlerts = function (){
	$('start_stop_alert_loading').style.display = 'block';
	var postParameters = '';
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: startAlertsCallback,
		// Handle 404
		on404: startAlerts404Callback,
		// Handle other errors
		onFailure: startAlertsFailureCallback
	}
	new Ajax.Request('/start-alerts', ajaxRequestOptions);
}

/**
 *startAlerts globaly in one click success callback
 */
var startAlertsCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok){
		$('start_stop_alert_loading').style.display = 'none';
		$('alert_status_span').innerHTML = ' On';
		$('alert_status_span').style.color = '#008000';
		$('start_stop_alert_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: stopAlerts();">Click <font style="color:#2A2AFF;">here</font> to turn off your News Alerts.</a>';
		//Uncheck all alert buttons and in last check "0 alerts per day"
		for(i=0; i<=4; i++){
			$(i+'_alerts').checked = false;
		}
		$('1_alerts').checked = true;

		//Start global mails also
		$('global_mails_status_span').innerHTML = ' On';
		$('global_mails_status_span').style.color = '#008000';
		$('global_on_off_div').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: globalMailsOff();">Click <font style="color:#2A2AFF;">here</font> to turn off all emails from socialmedian.  </a><br />'
										   +'<span style="font-size:12px;font-weight: normal;">(<b>Warning:</b> This will turn off all socialmedian emails, including when other users are trying to communicate with you.)</span>';
	}
}
/**
 * startAlerts globaly in one click. failure callback function
 */
var startAlertsFailureCallback = function (){
	alert("Error on page");
}
/**
 * startAlerts globaly in one click 404 callback function
 */
var startAlerts404Callback= function (){
	alert("Error page is not found");
}


/**
 * globalMailsOff in one click.
 */
var globalMailsOff = function (){
	$('global_on_off_loading').style.display = 'block';
	var postParameters = '';
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: globalMailsOffCallback,
		// Handle 404
		on404: globalMailsOff404Callback,
		// Handle other errors
		onFailure: globalMailsOffFailureCallback
	}
	new Ajax.Request('/off-all-mails-globaly', ajaxRequestOptions);
}

/**
 *globalMailsOff in one click success callback
 */
var globalMailsOffCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok){
		$('global_on_off_loading').style.display = 'none';
		$('global_mails_status_span').innerHTML = ' Off';
		$('global_mails_status_span').style.color = '#FF0000';
		$('global_on_off_div').innerHTML = ' <a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: globalMailsOn();">Click <font style="color:#2A2AFF;">here</font> to turn on all emails from socialmedian.  </a>';
		/*
		* Turn off all alerts
		*/
		$('alert_status_span').innerHTML = ' Off';
		$('alert_status_span').style.color = '#FF0000';
		$('start_stop_alert_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: startAlerts();">Click <font style="color:#2A2AFF;">here</font> to turn on your News Alerts.</a>';
		//Uncheck all alert buttons and in last check "0 alerts per day"
		for(i=0; i<=4; i++){
			$(i+'_alerts').checked = false;
		}
		$('0_alerts').checked = true;

		/*
		* Turn off all notifications.
		*/
		$('notification_status_span').innerHTML = ' Off';
		$('notification_status_span').style.color = '#FF0000';
		$('start_stop_notifications_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: startAllNotifications();">Click <font style="color:#2A2AFF;">here</font> to turn on your Notifications.</a>';

		//Uncheck all option setting for notification
		var notification_on_buttons = document.getElementsByClassName('on');
		for(i=0; i<notification_on_buttons.length; i++){
			notification_on_buttons[i].checked = false;
		}
		var notification_off_buttons = document.getElementsByClassName('off');
		for(i=0; i<notification_off_buttons.length; i++){
			notification_off_buttons[i].checked = true;
		}
	}
}
/**
 * globalMailsOff in one click. failure callback function
 */
var globalMailsOffFailureCallback = function (){
	alert("Error on page");
}
/**
 * globalMailsOff in one click 404 callback function
 */
var globalMailsOff404Callback= function (){
	alert("Error page is not found");
}


/**
 * globalMailsOn in one click.
 */
var globalMailsOn = function (){
	$('global_on_off_loading').style.display = 'block';
	var postParameters = '';
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: globalMailsOnCallback,
		// Handle 404
		on404: globalMailsOn404Callback,
		// Handle other errors
		onFailure: globalMailsOnFailureCallback
	}
	new Ajax.Request('/on-all-mails-globaly', ajaxRequestOptions);
}

/**
 *globalMailsOn in one click success callback
 */
var globalMailsOnCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok){
		$('global_on_off_loading').style.display = 'none';
		$('global_mails_status_span').innerHTML = ' On';
		$('global_mails_status_span').style.color = '#008000';
		$('global_on_off_div').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: globalMailsOff();">Click <font style="color:#2A2AFF;">here</font> to turn off all emails from socialmedian.  </a><br />'
										   +'<span style="font-size:12px;font-weight: normal;">(<b>Warning:</b> This will turn off all socialmedian emails, including when other users are trying to communicate with you.)</span>';

		/*
		* Turn On all alerts to default setting
		*/
		$('alert_status_span').innerHTML = ' On';
		$('alert_status_span').style.color = '#008000';
		$('start_stop_alert_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: stopAlerts();">Click <font style="color:#2A2AFF;">here</font> to turn off your News Alerts.</a>';
		//Uncheck all alert buttons and in last check "1 alerts per day", which is default
		for(i=0; i<=4; i++){
			$(i+'_alerts').checked = false;
		}
		$('1_alerts').checked = true;

		/*
		* Turn On all notifications to default setting.
		*/
		$('notification_status_span').innerHTML = ' On';
		$('notification_status_span').style.color = '#008000';
		$('start_stop_notifications_span').innerHTML = '<a style="cursor:pointer;color:#7F7F7F;" onclick="Javascript: stopAllNotifications();">Click <font style="color:#2A2AFF;">here</font> to turn off your Notifications.</a><br />'
													 + '<span style="font-size:11px;">(<b>Warning:</b> Not recommended. You will not be notified when other users are attempting to communicate with you.)</span>';

		//Uncheck all option setting for notification
		var notification_on_buttons = document.getElementsByClassName('on');
		for(i=0; i<notification_on_buttons.length; i++){
			notification_on_buttons[i].checked = true;
		}
		var notification_off_buttons = document.getElementsByClassName('off');
		for(i=0; i<notification_off_buttons.length; i++){
			notification_off_buttons[i].checked = false;
		}
	}
}
/**
 * globalMailsOn in one click. failure callback function
 */
var globalMailsOnFailureCallback = function (){
	alert("Error on page");
}
/**
 * globalMailsOn in one click 404 callback function
 */
var globalMailsOn404Callback= function (){
	alert("Error page is not found");
}

