/**
 * Global array for url and username sites.
 * list of sites currently not supported for promte sites
 * these site take username/urls
 */
OTHER_SITES = eval({'myspace':{'type':'usernameSites','hint':''},'linkedin':{'type':'urlSites','hint':'Eg: http://www.linkedin.com/in/(user name)'}});
/**
 *	Global array for service url site
 *	list of sites supported for promote site
 */
SERVICE_URL_SITES = ['twitter','googlereader','digg','blog','delicious','facebook','youtube','flickr','friendfeed','linkedin','nowPublic','myspace','mixx', 'qik', 'seesmic'];
/**
 *	Contains all the supported service urls
 *	list of sites whose templates are available
 */
SUPPORTED_SERVICE_URL_CLOSE = ['twitter','googlereader','digg','blog','delicious','facebook','youtube','flickr','friendfeed','linkedin','myspace', 'nowPublic','mixx', 'qik','seesmic','sites', 'othersites', 'usernameSites', 'urlSites'];
SUPPORTED_SERVICE_URL = ['twitter','googlereader','digg','blog','delicious','facebook','youtube','flickr','friendfeed','linkedin','nowPublic','myspace','mixx', 'qik','seesmic'];
/**
 *	Global array for user added service urls
 *	contain list of sites already added by user.
 */
var USER_SERVICE_URL = new Array();
/**
 *	Coantain service tags added by user.
 */
var USER_SERVICES_TAGS = new Array();
/**
 *	Check the previously open service type template
 */
var PREVIOUSLY_OPEN_SERVICE_TYPE = '';
/**
 *	contain the site name for url and username sites
 *	First element contain urlsites info and second element contain username info.
 */
var PREVIOUSLY_OPEN_SERVICE_NAME = new Array();
/**
 *	global array for suggesting service url to user
 */
var SUGGESTED_SERVICE_URL = new Array();
var PREVIOUSLY_ADDED_SERVICE = 0;
// store the currently edited service url id
var CURRENTLY_EDITED_SERVICE_URL_ID = 0;
// check whether the request for user service url is sent or not
var IS_SERIVCE_REQUEST_SEND = 0;
/**
 *	Rounded corner for Add something widget
 */
addSomethingSettings = {
    tl: { radius: 5 },
    tr: { radius: 5 },
    bl: { radius: 5 },
    br: { radius: 5 },
    antiAlias: true,
    autoPad: false,
    validTags: ["div"]
}
var addSomethingBoxObject = new curvyCorners(addSomethingSettings, 'addSomethingWidget');
addSomethingBoxObject.applyCornersToAll();

addSomethingBodySettings = {
    tl: { radius: 1 },
    tr: { radius: 1 },
    bl: { radius: 5 },
    br: { radius: 5 },
    antiAlias: true,
    autoPad: false,
    validTags: ["div"]
}
var addSomethingBodyBoxObject = new curvyCorners(addSomethingBodySettings, 'addSomethingWidgetBody');
addSomethingBodyBoxObject.applyCornersToAll();

/**
 *	Rounded corner for site menu
 */
addSiteMenuSettings = {
    tl: { radius: 5 },
    tr: { radius: 5 },
    bl: { radius: 5 },
    br: { radius: 5 },
    antiAlias: true,
    autoPad: false,
    validTags: ["div"]
}
var addSiteMenuBoxObject = new curvyCorners(addSiteMenuSettings, 'addSiteMenuBoxCorner');
addSiteMenuBoxObject.applyCornersToAll();

/**
 *	Function related with Add Something widget
 */
// perform action on widget
function showSnipBox(obj) {
	obj.className = "widgetTabSnipOver";
	obj.style.borderBottom = "1px solid #FFFFFF";

	$('widgetTab2').className = "widgetTabNews";
	$('widgetTab3').className = "widgetTabSite";

	$('widgetTab2').style.borderBottom = "1px solid #9FBAD7";

	$('news_content_box').style.display = "none";
	$('snip_content_box').style.display = "block";

	$('add_something_box_min').style.display = "block";
}

/**
 * @author AA
 * Display the content on add something widget(right side panel) by selecting tab
 * @param {Integer} boxId: id of the opened tab box (possible value 1,2,3)
 * @param {Object} obj: object of tab
 */
function showAddSomeThingBox(boxId, obj) {
	obj.style.borderBottom = "1px solid #FFFFFF";
	switch(boxId){
		case 1:
			obj.className = "widgetTabSnipOver";
			$('widgetTab2').className = "widgetTabNews";
			$('widgetTab2').style.borderBottom = "1px solid #9FBAD7";
			$('widgetTab3').className = "widgetTabSite";
			$('widgetTab3').style.borderBottom = "1px solid #9FBAD7";
			$('snip_content_box').style.display = "block";
			$('news_content_box').style.display = "none";
			$('site_content_box').style.display = "none";
			break;
		case 2:
			obj.className = "widgetTabNewsOver";
			$('widgetTab1').className = "widgetTabSnip";
			$('widgetTab1').style.borderBottom = "1px solid #9FBAD7";
			$('widgetTab3').className = "widgetTabSite";
			$('widgetTab3').style.borderBottom = "1px solid #9FBAD7";
			$('snip_content_box').style.display = "none";
			$('news_content_box').style.display = "block";
			$('site_content_box').style.display = "none";
			break;
		case 3:
			/*
			 * Add logged in check
			 * @author Ajay
			 * @date 10/12/2008
			 */
			if(IS_SERIVCE_REQUEST_SEND == 0 && globalUserId != null && globalUserId != 0){
				searchUserAddedServiceUrl();
			}
			obj.className = "widgetTabSiteOver";
			$('widgetTab1').className = "widgetTabSnip";
			$('widgetTab1').style.borderBottom = "1px solid #9FBAD7";
			$('widgetTab2').className = "widgetTabNews";
			$('widgetTab2').style.borderBottom = "1px solid #9FBAD7";
			$('snip_content_box').style.display = "none";
			$('news_content_box').style.display = "none";
			$('site_content_box').style.display = "block";
			break;
	}
	$('add_something_box_min').style.display = "block";
}
/**
 * Minimize the add something widget box on right panel
 */
function minimizeAddSomethingBox() {
	$('add_something_box_min').style.display = 'none';
	$('news_content_box').style.display = 'none';
	$('snip_content_box').style.display = 'none';
	$('site_content_box').style.display = 'none';
	$('widgetTab1').className = "widgetTabSnip";
	$('widgetTab2').className = "widgetTabNews";
	$('widgetTab3').className = "widgetTabSite";
}

/**
 * @author AA
 * Open the site template box on left side and changed the boder color of site icons on left side
 * @param {Object} obj: object of currently selected site icon
 * @param {String} name: service type
 * @param {Integer} edit: if template is called in edited mode then 1 else 0
 * @param {Integer} serviceId: if opened in edited mode then contain user service url id else 0
 * @param {String} categoryId: category of user service url (possible value 'other')
 */
function toggleSiteUrlButton(obj, name, edit, serviceId, categoryId){
	/**
	 *	Closed the getting stated box for promotional news network
	 */
	try{
		$('promoteNetworkGettingStarted').style.display = 'none';
	}catch(e){}
	if(edit == 1){
		getUserServiceTemplate(name, edit, serviceId, categoryId);
		return false;
	}
	getUserServiceTemplate(name, 0, serviceId, categoryId);
	$('twitter_icon').style.border = '1px solid #FFF';
	$('friendfeed_icon').style.border = '1px solid #FFF';
	$('facebook_icon').style.border = '1px solid #FFF';
	$('linkedin_icon').style.border = '1px solid #FFF';
	$('flickr_icon').style.border = '1px solid #FFF';
	$('blog_icon').style.border = '1px solid #FFF';
	$('myspace_icon').style.border = '1px solid #FFF';
	$('googlereader_icon').style.border = '1px solid #FFF';
	$('youtube_icon').style.border = '1px solid #FFF';
	obj.style.border = '1px solid #7F7F7F';
}

/**
 *	Searches the user service template
 */
var getUserServiceTemplate = function (service_type, edit, serviceId, categoryId){
	if(categoryId == 'other'){
		service_type = 'othersites';
	}
	// if there is getting started messages, then hide those messages
    try {
        $('gettingStartedStepInfo').style.display = "none";
    } catch(e){}
    if(edit == 1){
		CURRENTLY_EDITED_SERVICE_URL_ID = serviceId;
	}
	for(i=0;i<SUPPORTED_SERVICE_URL_CLOSE.length;i++){
		try{
			$(SUPPORTED_SERVICE_URL_CLOSE[i]+'Menu').style.display = 'none';
		}catch(e){}
	}
	// catch the error when service type is not found in OTHER_SITES array
	try{
		// for other services define in OTHER_SITES global array
		var contentDivType = OTHER_SITES[service_type]['type'];
		if($(contentDivType+'Menu') != null){
			var contentInnerHtml = $(contentDivType+'Menu').innerHTML;
			eval('contentInnerHtml = contentInnerHtml.replace(/'+(contentDivType == 'urlSites' ? PREVIOUSLY_OPEN_SERVICE_NAME[0] : PREVIOUSLY_OPEN_SERVICE_NAME[1])+'/g, "'+service_type+'");');
			$(contentDivType+'Menu').innerHTML = contentInnerHtml;
			$('addSiteMenuOuterDiv').style.display = 'block';
			$(contentDivType+'SiteName').innerHTML = service_type;
			$(contentDivType+'Icon').className = service_type+'-link-icon';
			$(contentDivType+'Hint').innerHTML = OTHER_SITES[service_type]['hint'];
			if(PREVIOUSLY_OPEN_SERVICE_TYPE != ''){
				//$(PREVIOUSLY_OPEN_SERVICE_TYPE+'Menu').style.display = 'none';
				PREVIOUSLY_OPEN_SERVICE_TYPE = contentDivType;
				if(PREVIOUSLY_OPEN_SERVICE_TYPE == 'urlSites'){
					PREVIOUSLY_OPEN_SERVICE_NAME[0] = service_type;
				}else{
					PREVIOUSLY_OPEN_SERVICE_NAME[1] = service_type;
				}
			}
			$(''+contentDivType+'Menu').style.display = 'block';
			// fill the template for edit
			if(edit == 1){
				try{
					fillAllTheFields(service_type);
				}catch(e){}
			}else{
				setDefaultField(service_type);
			}
			return false;
		}
	}catch(e){}
	// for special services like googlereader, delicious, digg, twitter, blog
	if($(''+service_type+'Menu') != null){
		$('addSiteMenuOuterDiv').style.display = 'block';
		if(PREVIOUSLY_OPEN_SERVICE_TYPE != ''){
			//$(PREVIOUSLY_OPEN_SERVICE_TYPE+'Menu').style.display = 'none';
			PREVIOUSLY_OPEN_SERVICE_TYPE = service_type;
		}
		$(service_type+'Menu').style.display = 'block';
		// fill the template for edit
		try{
			if(edit == 1){
				fillAllTheFields(service_type);
			}else{
				setDefaultField(service_type);
			}
		}catch(e){}
		if(service_type == 'sites'){
			displayAddEditServiceUrl();
		}
		if(service_type == 'blog'){
			$('userServiceUrlOuterDiv').style.display = 'block';
			$('promoteYourselfDiv').style.display = 'none';
		}
		if(service_type == 'facebook') {
			if(FB_STATUS_UPDATE_OPTIONAL == 1) {
				$('fb_status_update_optional').checked = true;
			} else {
				$('fb_status_update_optional').checked = false;
			}
		}
		return false;
	}
	if(OTHER_SITES[service_type] != null){
		var postParameters = "service_type="+OTHER_SITES[service_type]['type']+"&service_name="+service_type;
	} else if (categoryId == "other") {
		var postParameters = "service_type=othersites";
	} else{
		var postParameters = "service_type="+service_type;
	}
	$('addEditUserServiceUrlLoadingIcon').style.display = 'block';
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: function (response){getUserServiceTemplateCallback(response, service_type, edit, categoryId);},
		// Handle 404
		on404: getUserServiceTemplate404Callback,
		// Handle other errors
		onFailure: getUserServiceTemplateFailureCallback
	}
	new Ajax.Request('/service-url-template', ajaxRequestOptions);
}
/**
 * Service template callback function
 */
var getUserServiceTemplateCallback = function (response, service_type, service_edit, categoryId){
	for(i=0;i<SUPPORTED_SERVICE_URL_CLOSE.length;i++){
		try{
			$(SUPPORTED_SERVICE_URL_CLOSE[i]+'Menu').style.display = 'none';
		}catch(e){}
	}
	// hide loading icon
	$('addEditUserServiceUrlLoadingIcon').style.display = 'none';
	new Insertion.Bottom('addSiteMenuBox',response.responseText);
	$('addSiteMenuOuterDiv').style.display = 'block';
	if(OTHER_SITES[service_type] == null){
		/*if(PREVIOUSLY_OPEN_SERVICE_TYPE != ''){
			$(PREVIOUSLY_OPEN_SERVICE_TYPE+'Menu').style.display = 'none';
		}*/
		PREVIOUSLY_OPEN_SERVICE_TYPE = service_type;
	}else{
		try{
			$(OTHER_SITES[service_type]['type']+'SiteName').innerHTML = service_type;
			$(OTHER_SITES[service_type]['type']+'Icon').className = service_type+'-link-icon';
			$(OTHER_SITES[service_type]['type']+'Hint').innerHTML = OTHER_SITES[service_type]['hint'];
			$(''+OTHER_SITES[service_type]['type']+'Menu').style.display = 'block';
			/*if(PREVIOUSLY_OPEN_SERVICE_TYPE != ''){
				$(PREVIOUSLY_OPEN_SERVICE_TYPE+'Menu').style.display = 'none';
			}*/
			PREVIOUSLY_OPEN_SERVICE_TYPE = OTHER_SITES[service_type]['type'];
			if(PREVIOUSLY_OPEN_SERVICE_TYPE == 'urlSites'){
				PREVIOUSLY_OPEN_SERVICE_NAME[0] = service_type;
			}else{
				PREVIOUSLY_OPEN_SERVICE_NAME[1] = service_type;
			}
		}catch(e){}
	}
	if(service_edit == 1){
		try{
			fillAllTheFields(service_type);
		}catch(e){}
	}
	if(service_type == 'sites'){
		displayAddEditServiceUrl();
	}
	if(service_type == 'twitter' && service_edit != 1){
		setDefaultField('twitter');
	}
}

/**
 * Service template failure callback function
 */
var getUserServiceTemplateFailureCallback = function (){
	alert("Error on page");
	// hide loading icon
	$('addEditUserServiceUrlLoadingIcon').style.display = 'none';
}
/**
 * Service template 404 callback function
 */
var getUserServiceTemplate404Callback= function (){
	// hide loading icon
	$('addEditUserServiceUrlLoadingIcon').style.display = 'none';
	alert("Error page is not found");
}

/**
 *	Search the user added service urls
 */
var searchUserAddedServiceUrl = function(reload){
	IS_SERIVCE_REQUEST_SEND = 1;
	if(USER_SERVICE_URL.size() > 0 && reload != 1){
		showUserServiceUrl();
		return false;
	}
	var postParameters = "";
	if(reload != 1){
		$('siteLoadingIcon').style.display = 'block';
	}
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: function(response){searchUserAddedServiceUrlCallback(response, reload);},
		// Handle 404
		on404: searchUserAddedServiceUrl404Callback,
		// Handle other errors
		onFailure: searchUserAddedServiceUrlFailureCallback
	}
	new Ajax.Request('/user-service-url', ajaxRequestOptions);
}

var searchUserAddedServiceUrlCallback = function (response, reload){
	$('siteLoadingIcon').style.display = 'none';
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	//check if there is an error
	if (response_data.error == 1) {
		//alert the error
		alert(response_data.message);
	} else {
		var userServiceUrl = response_data.url_info;
		var suggestedServiceUrl = response_data.non_actioned_connections;
		var userServiceUrlTags = (response_data.tags != null ? response_data.tags : "");
		if(userServiceUrl.length > 0){
			PREVIOUSLY_ADDED_SERVICE = 1;
		}
		SUGGESTED_SERVICE_URL = new Array();
		USER_SERVICES_TAGS = new Array();
		USER_SERVICE_URL = new Array();
		for(i=0;i<userServiceUrl.length;i++){
			USER_SERVICE_URL[userServiceUrl[i]['id']] = new Array();
			USER_SERVICE_URL[userServiceUrl[i]['id']] = userServiceUrl[i];
		}
		for(j=0;j<suggestedServiceUrl.length;j++){
			SUGGESTED_SERVICE_URL[j] = suggestedServiceUrl[j];
		}
		try{
			for(k=0;k<userServiceUrlTags.length;k++){
				USER_SERVICES_TAGS[userServiceUrlTags[k]['user_service_url_id']] = new Array();
				USER_SERVICES_TAGS[userServiceUrlTags[k]['user_service_url_id']] = userServiceUrlTags[k];
			}
		}catch(e){}
		showUserServiceUrl();
	}
	if(reload == 1){
		getUserServiceTemplate('sites', 0, 0, '');
	}
}
/**
 * Service template failure callback function
 */
var searchUserAddedServiceUrlFailureCallback = function (){
	alert("Error on page");
	$('siteLoadingIcon').style.display = 'none';
}
/**
 * Service template 404 callback function
 */
var searchUserAddedServiceUrl404Callback= function (){
	alert("Error page is not found");
	$('siteLoadingIcon').style.display = 'none';
}
/**
 *	Display the service url
 */
function showUserServiceUrl(){
	$('serviceUrlSiteIconDiv').innerHTML = '';
	if(PREVIOUSLY_ADDED_SERVICE == 1){
		$('addUserServiceSiteHeading').innerHTML = 'Your sites';
		$('addSiteLink').innerHTML = '<a href="" class="editsites-button" onclick="javascript:getUserServiceTemplate(\'sites\', 0, 0, \'\');return false;"></a>';
		var count = 0;
		for (key in USER_SERVICE_URL) {
			var serviceName = USER_SERVICE_URL[key]['service_name'];
			if(serviceName != undefined && serviceName != ''){
				if(serviceName != 'blog' && SERVICE_URL_SITES.indexOf(serviceName) != -1 && USER_SERVICE_URL[key]['service_catagory'] != 'other'){
					SERVICE_URL_SITES.splice(SERVICE_URL_SITES.indexOf(serviceName),1);
				}
				new Insertion.Bottom('serviceUrlSiteIconDiv',getUserServiceIconDiv(serviceName, 1, USER_SERVICE_URL[key]['id'], USER_SERVICE_URL[key]['service_catagory']));
				if(count != 0 && (count % 9) == 0){
					new Insertion.Bottom('serviceUrlSiteIconDiv', '<br clear="all"/>');
				}
				count++;
			}
		}
		showSuggestedServiceUrl('Right');
	}else{
		$('addUserServiceSiteHeading').innerHTML = 'Add links and feeds from your site';
		$('addSiteLink').innerHTML = '<a href="" class="addsites-button" onclick="javascript: getUserServiceTemplate(\'sites\', 0, 0, \'\');return false;"></a>';
		for(i=0;i<SERVICE_URL_SITES.length;i++){
			new Insertion.Bottom('serviceUrlSiteIconDiv',getUserServiceIconDiv(SERVICE_URL_SITES[i], 0, 0, ''));
			if(i != 0 && (i % 9) == 0){
				new Insertion.Bottom('serviceUrlSiteIconDiv', '<br clear="all"/>');
			}
		}
	}
	new Insertion.Bottom('serviceUrlSiteIconDiv',"<br clear='all'/>");
}

// check weather optional field is set or not for facebook status update
var FB_STATUS_UPDATE_OPTIONAL = 1;
var saveUserServiceUrlLink = function (service){
	var err_msg = "";
	var service_catagory = "";
	eval('var frmObj = document.'+service+'_frm;');
	if(service == 'blog' && (frmObj.service_id.value.strip() == "" || frmObj.service_id.value.strip().indexOf("http://") != 0)) {
		err_msg = "Invalid Blog url!";
	} else if(service == 'twitter' && (frmObj.service_id.value.strip() == '' || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid Twitter user name!";
	} else if(service == 'myspace' && (frmObj.service_id.value.strip() == "" || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid MySpace user name!";
	} else if(service == 'linkedin' && (frmObj.service_id.value.strip() == "" || frmObj.service_id.value.strip().indexOf("http://www.linkedin.com") != 0)) {
		err_msg = "Invalid LinkedIn url!";
	} else if(service == 'flickr' && (frmObj.service_id.value.strip() == "" || (frmObj.service_id.value.strip().match(/[^a-zA-z0-9_\- .@]/) != null))) {
		/**
		 * @author AA
		 *
		 * Added @ for adding NSID
		 */
		err_msg = "Invalid Flickr user name!";
	} else if(service == 'youtube' && (frmObj.service_id.value.strip() == "" || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid YouTube user name!";
	} else if(service == 'googlereader' && (frmObj.service_id.value.strip() == "" || frmObj.service_id.value.strip().indexOf("http://www.google.com/reader/shared/") != 0)) {
		err_msg = "Invalid Google Reader url!";
	} else if(service == 'delicious' && (frmObj.service_id.value.strip() == "" || (frmObj.service_id.value.strip().match(/[^a-zA-z0-9_\-.]/)!= null))) {
		/**
		 * @author KD
		 * @date 03/12/08
		 * Added . for adding delicious username with .
		 */
		err_msg = "Invalid del.icio.us user name!";
	} else if(service == 'digg' && (frmObj.service_id.value.strip() == "" || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid Digg user name!";
	} else if(service == 'friendfeed' && (frmObj.service_id.value.strip() == "" || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid Friend Feed user name!";
	} else if(service == 'nowPublic' && (frmObj.service_id.value.strip() == "" || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid nowPublic user name!";
	} else if(service == 'mixx' && (frmObj.service_id.value.strip() == "" || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid mixx user name!";
	} else if(service == 'qik' && (frmObj.service_id.value.strip() == "" || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid Qik user name!";
	} else if(service == 'seesmic' && (frmObj.service_id.value.strip() == "" || validateSpecialCharacter(frmObj.service_id.value.strip()))) {
		err_msg = "Invalid seesmic user name!";
	} else if(service == 'othersites') {
		if(frmObj.service_type.value.strip() == "")
			err_msg = "Site Name can't be blank!";
		else if(frmObj.service_id.value.strip() == "" || frmObj.service_id.value.strip().indexOf("http://") != 0)
			err_msg = "Invalid profile URL!";
		service_catagory = "&service_catagory=other";
	}
	if(err_msg != "") {
		alert(err_msg);
		return false;
	}
	$(service+'UserServiceUrlLoadingIcon').style.display = 'block';
	try {
		var form = $(service+'Frm');
		var input = form['service_keywords'];
		if ($(input).getValue() == TWEET_KEYWORD_HELP) {
			$(input).clear();
		}
	} catch (e) {}
	if (service != 'othersites') {
		var postParameters = Form.serialize(service+'Frm')+"&service_type="+service+"&service_url_id="+CURRENTLY_EDITED_SERVICE_URL_ID;
	} else {
		var postParameters = Form.serialize(service+'Frm')+service_catagory+"&service_url_id="+CURRENTLY_EDITED_SERVICE_URL_ID;
	}
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: function (response){saveUserServiceUrlLinkCallback(response,service);},
		// Handle 404
		on404: function (){saveUserServiceUrlLink404Callback(service);},
		// Handle other errors
		onFailure: function (){saveUserServiceUrlLinkFailureCallback(service);}
	}
	new Ajax.Request('/save-user-links', ajaxRequestOptions);
}

/**
 * userUpdate success callback function
 */
var saveUserServiceUrlLinkCallback = function (response,service){
	$(service+'UserServiceUrlLoadingIcon').style.display = 'none';
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok == true ) {
		// setting for facebook status update.
		if(service == "facebook") {
			FB_STATUS_UPDATE_OPTIONAL = response_data.status_update_for_comment;
		}
		SERVICE_URL_SITES = ['twitter','googlereader','digg','blog','delicious','facebook','youtube','flickr','friendfeed','linkedin','myspace','mixx','nowPublic', 'qik','seesmic'];
		searchUserAddedServiceUrl(1);
	}else{
		errorMessage = response_data.message.replace(/SITENAME/, service);
		alert(errorMessage);
	}
}
/**
 * userUpdate failure callback function
 */
var saveUserServiceUrlLinkFailureCallback = function (service){
	alert("Error on page");
	$(service+'UserServiceUrlLoadingIcon').style.display = 'none';
}
/**
 * userUpdate 404 callback function
 */
var saveUserServiceUrlLink404Callback= function (service){
	alert("Error page is not found");
	$(service+'UserServiceUrlLoadingIcon').style.display = 'none';
}

/**
 *	Validate the user service url name
 */
function validateSpecialCharacter(val) {
	if (val.match(/[^a-zA-z0-9_\-]/)!=null) {
		return true;
	} else {
		return false;
	}
}
/**
 *	Enable or disable the checkbox for import
 */
function enableDisableCheckBox(serviceType, blockId){
	if(blockId == 1){
		try{
			$(serviceType+'SocialmedianKeywordsText').style.color = '#959595';
			$(serviceType+'SocialmedianKeywords').checked = false;
		}catch(e){}
		$(serviceType+'KeywordsOptionText').style.color = '#959595';
		$(serviceType+'KeywordsOption').checked = false;
		$(serviceType+'ImportAllText').style.color = '#000';
	}else{
		$(serviceType+'ImportAllText').style.color = '#959595';
		$(serviceType+'ImportAll').checked = false;
		try{
			$(serviceType+'SocialmedianKeywordsText').style.color = '#000';
		}catch(e){}
		$(serviceType+'KeywordsOptionText').style.color = '#000';
	}
}

/**
 *	Display the user Added services and other services on left side
 */
function displayAddEditServiceUrl(){
	var serviceUrlSiteInnerHtml = '';
	$('userAddedServices').innerHTML = '';
	$('addEditUserServiceIcons').innerHTML = '';
	$('yourSitesBox').style.display = 'none';
	if(PREVIOUSLY_ADDED_SERVICE != 0){
		var userAddedServiceIcons = '';
		var serviceName = '';
		var serviceCategory = '';
		var classIconName = '';
		for(key in USER_SERVICE_URL){
			if(USER_SERVICE_URL[key]['id'] == '' || USER_SERVICE_URL[key]['id'] == undefined){
				continue;
			}
			serviceName = USER_SERVICE_URL[key]['service_name'];
			serviceCategory = USER_SERVICE_URL[key]['service_catagory'];
			classIconName = (serviceCategory == 'other' ? 'blog' : serviceName);
			if(serviceName != undefined && serviceName != ''){
				var displayLinkedIcon = 'inactive';
				var displayConnectedIcon = 'inactive';
				var displayConnectedTitle = 'Not Connected';
				var displayLinkedTitle = 'Not Linked';
				if(USER_SERVICE_URL[key]['crawl_service_url'] == 'y'){
					displayConnectedIcon = 'active';
					displayConnectedTitle = '"Feed Connected';
				}
				if(USER_SERVICE_URL[key]['public_display'] == 'y'){
					displayLinkedIcon = 'active';
					displayLinkedTitle = 'Linked from Profile';
				}
				userAddedServiceIcons += "<div style='padding:5px 0px 0px 0px;margin:0px;'>"
											+"<div style='padding:0px 5px 0px 0px;margin:0px;float:left;'>"
												+"<a href='javascript:void(0)' style='text-decoration:none;cursor:default;' title='"+displayConnectedTitle+"' class='import-feed-"+displayConnectedIcon+"'></a>"
											+"</div>"
											+"<div style='padding:5px 5px 0px 0px;margin:0px;float:left;'>"
												+"<a href='javascript:void(0)' style='text-decoration:none;cursor:default;' title='"+displayLinkedTitle+"' class='profile-link-"+displayLinkedIcon+"'></a>"
											+"</div>"
											+"<div style='padding:0px 5px 0px 0px;margin:0px;float:left;'>"
												+"<a href='' title='"+serviceName+"'  onclick='javascript: getUserServiceTemplate(\""+serviceName+"\", 1, "+USER_SERVICE_URL[key]['id']+", \""+USER_SERVICE_URL[key]['service_catagory']+"\");return false;' class='"+classIconName+"-link-icon'></a>"
											 +"</div>"
											 +"<div align='left' class='f_normal_11' style='padding:0px 0px 0px 0px;margin:0px;float:left;'>"
											 	+"<a href='' title='"+USER_SERVICE_URL[key]['service_url']+"' onclick='javascript: getUserServiceTemplate(\""+serviceName+"\", 1, "+USER_SERVICE_URL[key]['id']+", \""+USER_SERVICE_URL[key]['service_catagory']+"\");return false;' style='text-decoration:underline;color:#333'>"+USER_SERVICE_URL[key]['show_service_url'].truncate()+"</a>"
											+"</div>"
											+"<br clear='all'/>"
										 +"</div>";
			}
		}
		if(userAddedServiceIcons != ''){
			new Insertion.Bottom('userAddedServices', userAddedServiceIcons);
			$('yourSitesBox').style.display = 'block';
		}
	}
	var userServiceUrlIcons = '';
	for(i=0;i<SERVICE_URL_SITES.length;i++){
		userServiceUrlIcons += getUserServiceIconDiv(SERVICE_URL_SITES[i], 0, 0, '');
	}
	new Insertion.Top('addEditUserServiceIcons',userServiceUrlIcons);
	showSuggestedServiceUrl('Left');
}
/**
 *	generate the user service Icon div
 */
function getUserServiceIconDiv(serviceName, edit, serviceId, categoryId){
	var userServiceIconsInnerHTML = '';
	userServiceIconsInnerHTML += "<div style='padding:5px 0px 0px 0px;margin:0px;float:left;width:25px;'>"
									+"<a href='' title='"+serviceName+"' onclick='javascript: toggleSiteUrlButton(this,\""+serviceName+"\", "+edit+", "+serviceId+", \""+categoryId+"\"); return false;' style='border: 1px solid rgb(255, 255, 255);' class='"+(categoryId != 'other' ? serviceName : 'blog')+"-link-icon' id='"+(categoryId != 'other' ? serviceName : serviceId)+"_icon'></a>"
								+"</div>";
	return userServiceIconsInnerHTML;
}

/**
 *	Display the suggested service url to user left/right panel
 */
function showSuggestedServiceUrl(displayPanel){
	var addLineBreak = "";
	var rightSideBottomPad = "5px";
	var serviceNameWidth = "36%";
	if(displayPanel == "Right"){
		addLineBreak = "<br clear='all'/>";
		rightSideBottomPad = "10px";
		serviceNameWidth = "52%";
	}
	var contentDivId = "suggestedServiceUrl"+displayPanel+"Panel";
	$(contentDivId).innerHTML = '';
	if(SUGGESTED_SERVICE_URL.length < 1){
		$(contentDivId).style.display = 'none';
	}
	$('isThisYou'+displayPanel+'PanelOuterBox').style.display = 'none';
	var serviceUrlSuggestion = '';
	for(i=0;i<SUGGESTED_SERVICE_URL.length;i++){
		serviceUrlSuggestion += "<div style='padding:"+rightSideBottomPad+" 0px 0px 0px;margin:0px;width:100%;'>"
									+"<div align='left' style='padding:0px;margin:0px;float:left;width:44%;'>"
										+"<a title='"+SUGGESTED_SERVICE_URL[i]['display_profile']+"' href='"+SUGGESTED_SERVICE_URL[i]['user_profile_url']+"' style='text-decoration:none;color:#333;' target='_blank'>"+SUGGESTED_SERVICE_URL[i]['display_profile'].truncate(20, '...')+"</a>"
									+"</div>"
									+"<div class='f_normal_12' style='padding:0px;margin:0px;float:left;width:"+serviceNameWidth+"'>"
										+"<div style='float:left;padding:0px 0px 0px 5px'>on</div>"
										+"<div style='float:left;padding:0px 0px 0px 5px'><span class='"+(SUGGESTED_SERVICE_URL[i]['service_name'] == 'other' ? 'blog' : SUGGESTED_SERVICE_URL[i]['service_name'])+"-link-icon'></span></div>"
										+"<div style='float:left;padding:0px 0px 0px 5px'>"+SUGGESTED_SERVICE_URL[i]['service_name']+"</div>"
										+"<br clear='all'/>"
									+"</div>"
									+addLineBreak
									+"<div style='padding:0px;margin:0px;float:left;'><a href='' onclick='javascript: populateSuggestedServiceUrlMenu("+i+");return false;'>Yes</a></div>"
									+"<div style='padding:0px 0px 0px 10px;margin:0px;float:left;'><a href='' onclick='javascript: rejectConnectionUrl("+SUGGESTED_SERVICE_URL[i]['id']+");return false;'>No</a></div>"
									+"<br clear='all'/>"
								+"</div>";
	}
	if(serviceUrlSuggestion != ''){
		serviceUrlSuggestion += (displayPanel == "Right" ? "<br clear='all'/>" : "");
		new Insertion.Top(contentDivId, serviceUrlSuggestion);
		$('isThisYou'+displayPanel+'PanelOuterBox').style.display = 'block';
		$(contentDivId).style.display = 'block';
		refreshSnapshots();
	}
}
/**
 * function to show/hide blog stories
 */
var BLOG_POPULAR_STORY_REQ_SENT = false;
function getBlogStories(feed_id, story_id, type) {
	if(type == "recent") {
		// change tab actions
		$('reverseBlogPopularStoriesHolderTab').className = "shareTabInactive";
		$('reverseBlogRecentStoriesHolderTab').className = "shareTabActive";

		$('reverseBlogPopularStoriesBoxHolder').style.display = "none";
		$('reverseBlogRecentStoriesBoxHolder').style.display = "block";
	} else if(type == "popular") {
		// change tab actions
		$('reverseBlogRecentStoriesHolderTab').className = "shareTabInactive";
		$('reverseBlogPopularStoriesHolderTab').className = "shareTabActive";

		// send request only once
		if(BLOG_POPULAR_STORY_REQ_SENT == false) {
			getOtherStoriesFromFeed(feed_id, story_id, type);
		} else {
			$('reverseBlogRecentStoriesBoxHolder').style.display = "none";
			$('reverseBlogPopularStoriesBoxHolder').style.display = "block";
		}
	}
}
/**
 *	Reject the suggested service url connection
 */
var rejectConnectionUrl = function (connection_id){
	$('addEditUserServiceUrlLoadingIcon').style.display = 'block';
	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){
	$('addEditUserServiceUrlLoadingIcon').style.display = 'none';
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	var suggestedServiceUrl = response_data.non_actioned_connections;
	SUGGESTED_SERVICE_URL = new Array();
	for(j=0;j<suggestedServiceUrl.length;j++){
		SUGGESTED_SERVICE_URL[j] = suggestedServiceUrl[j];
	}
	if(suggestedServiceUrl.length < 1){
		$('isThisYouRightPanelOuterBox').style.display = 'none';
		try{
			$('isThisYouLeftPanelOuterBox').style.display = 'none';
		}catch(e){}
	}else{
		showSuggestedServiceUrl('Right');
		try{
			showSuggestedServiceUrl('Left');
		}catch(e){}
	}
}
/**
 * rejectConnectionUrl failure callback function
 */
var rejectConnectionUrlFailureCallback = function (){
	$('addEditUserServiceUrlLoadingIcon').style.display = 'none';
	alert("Error on page");
}
/**
 * rejectConnectionUrl 404 callback function
 */
var rejectConnectionUrl404Callback= function (){
	$('addEditUserServiceUrlLoadingIcon').style.display = 'none';
	alert("Error page is not found");
}

/**
 *	Remove the user added service url from the database
 */
var removeUserServiceUrl = function (service_id, service_type){
	var postParameters = "service_id="+service_id;
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: function(response){removeUserServiceUrlCallback(response, service_type)},
		// Handle 404
		on404: removeUserServiceUrl404Callback,
		// Handle other errors
		onFailure: removeUserServiceUrlFailureCallback
	}
	new Ajax.Request('/remove-user-links', ajaxRequestOptions);
}
/**
 * removeUserServiceUrl success callback function
 */
var removeUserServiceUrlCallback = function (response, service_type){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	if(response_data.ok == true) {
		//USER_SERVICE_URL.splice(CURRENTLY_EDITED_SERVICE_URL_ID, 1);
		/*USER_SERVICE_URL.unset(CURRENTLY_EDITED_SERVICE_URL_ID);
		SERVICE_URL_SITES.push(service_type);*/
		SERVICE_URL_SITES = ['twitter','googlereader','digg','blog','delicious','facebook','youtube','flickr','friendfeed','linkedin','myspace','mixx','nowPublic', 'qik','seesmic'];
		searchUserAddedServiceUrl(1);
		//getUserServiceTemplate('sites', 0, 0, '');
	}
}
/**
 * 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 TEMPLATE_LOADED_INTERVAL = '';
/**
 * diplay the correct template for the service type (as selected by user), fill the user values
 */
function populateSuggestedServiceUrlMenu(index){
	var serviceType = SUGGESTED_SERVICE_URL[index]['service_name'];
	if(serviceType == 'other'){
		serviceType = 'othersites';
	}
	 /**
	  * AA 17/11/08:
	  *
	  * change the logic for comparing the SUPPORTED_SERVICE_URL with service types
	  */

	if(SUPPORTED_SERVICE_URL.indexOf(serviceType) < 0){
		serviceType = 'othersites';
	}
	getUserServiceTemplate(serviceType, 0, 0, '');
	TEMPLATE_LOADED_INTERVAL = setInterval('displaySuggestedField('+index+',"'+serviceType+'")', '100');
}

/**
 * @author ajay agrawal
 * Fill the template with previously enter data (call when someone edit its site profile)
 * @params service_type: string (contain the service type to be edited)
 */
function fillAllTheFields(service_type){
	eval('var formObj = document.'+service_type+'_frm');
	$(service_type+'SaveUserChangesButton').style.display = "none";
	$(service_type+'EditServiceUrlOuterDiv').style.display = "block";
	$(service_type+'RemoveLink').innerHTML = "<a href='' onclick='javascript: removeUserServiceUrl("+USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['id']+");return false;' style='text-decoration:underline;color:#959595;'>Remove this site</a>";
	formObj.service_id.value = USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['show_service_url'];
	formObj.display_service_link.checked = (USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['public_display'] == 'y' ? true : false);
	try {
		formObj.service_keywords.value = USER_SERVICES_TAGS[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['tag_name'];
		enableDisableCheckBox(service_type, 2);
	}catch(e){}
	var userImportAll = false;
	var importSelected = false;
	var twitterTags = false;
	if(USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['crawl_service_url'] == 'y'){
		userImportAll = (USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['total_tag'] == '0' ? true : false);
		twitterTags = (USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['twitter_tags'] == 'y' ? true : false);
		if(twitterTags && USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['total_tag'] > 2){
			importSelected = true;
		}else if(twitterTags == false && USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['total_tag'] > 0){
			importSelected = true;
		}
	}
	try{
		formObj.service_type.value = USER_SERVICE_URL[''+CURRENTLY_EDITED_SERVICE_URL_ID+'']['service_name'];
	}catch(e){}
	//formObj.user_service_id.value = CURRENTLY_EDITED_SERVICE_URL_ID;
	formObj.service_import_all.checked = userImportAll;
	formObj.service_extra_tags.checked = twitterTags;
	formObj.service_keywords_option.checked = importSelected;
}

/**
 * @author AA
 * Fill the template when called from suggested user services
 * @params index: INTEGER (contain index of the SUGGESTED_SERVICE_URL array)
 * @params serviceType: STRING (contain service type to be modified)
 */
function displaySuggestedField(index, serviceType){
	try{
		eval('var formObj = document.'+serviceType+'_frm');
		/**
	 	 * AA 17/11/08
	 	 *
	 	 * genrate the correct service url for user (Add http if not in user_profile_url)
	 	 */
		if(serviceType == "googlereader" || serviceType == "linkedin"){
			// check whether display url contain "http" or not (http is required for google reader)
			var containHttp = SUGGESTED_SERVICE_URL[index]['display_profile'].indexOf("http://");
			if(containHttp < 0){
				SUGGESTED_SERVICE_URL[index]['display_profile'] = "http://www."+SUGGESTED_SERVICE_URL[index]['display_profile'];
			}
		}else if(serviceType == "facebook"){
			var containHttp = SUGGESTED_SERVICE_URL[index]['display_profile'].indexOf("http://");
			if(containHttp < 0){
				SUGGESTED_SERVICE_URL[index]['display_profile'] = "http://www.new."+SUGGESTED_SERVICE_URL[index]['display_profile'];
			}
		}
		/**
	 	 * AA 17/11/08
	 	 *
		 * populate the field with default values
		 */
		formObj.service_id.value = SUGGESTED_SERVICE_URL[index]['display_profile'];
		if(serviceType == 'twitter'){
			$('twitterKeywordsOptionText').color = "#000";
			$('twitterSocialmedianKeywordsText').color = "#000";
			$('twitterImportAllText').color = "#959595";
			formObj.service_import_all.checked = false;
			formObj.service_extra_tags.checked = true;
			formObj.service_keywords_option.checked = true;
			formObj.service_keywords.value = (window.location.href.indexOf('mmf.') >=0 ? 'mmf, monacomediaforum, mmf2008, mmf08' : '');
		}else{
			formObj.service_import_all.checked = true;
			formObj.service_extra_tags.checked = false;
			formObj.service_keywords_option.checked = false;
		}
		if(serviceType == 'othersites'){
			formObj.service_type.value = serviceType;
		}
		clearInterval(TEMPLATE_LOADED_INTERVAL);
	}catch(e){}
}

/**
 * @author AA
 * Fill the template with default values
 * @params service_type: STRING (contain the service type name to be modified)
 */
function setDefaultField(service_type){
	eval('var formObj = document.'+service_type+'_frm');
	$(service_type+'SaveUserChangesButton').style.display = "block";
	$(service_type+'EditServiceUrlOuterDiv').style.display = "none";
	formObj.service_id.value = "";
	formObj.display_service_link.checked = true;
	formObj.service_keywords.value = '';
	if(service_type == 'twitter'){
		$('twitterKeywordsOptionText').color = "#000";
		$('twitterSocialmedianKeywordsText').color = "#000";
		$('twitterImportAllText').color = "#959595";
		formObj.service_import_all.checked = false;
		formObj.service_extra_tags.checked = true;
		formObj.service_keywords_option.checked = true;
		formObj.service_keywords.value = (window.location.href.indexOf('mmf.') >=0 ? 'mmf, monacomediaforum, mmf2008, mmf08' : '');
	}else{
		formObj.service_import_all.checked = true;
		formObj.service_extra_tags.checked = false;
		formObj.service_keywords_option.checked = false;
	}
}

/**
 * function to show/hide blog stories
 */
var BLOG_STORY_REQ_STATUS = new Hash();
function getBlogStories(feed_id, story_id, type) {
	if(type == "recent") {
		// change tab actions
		$('reverseBlogPopularStoriesHolderTab').className = "shareTabInactive";
		$('reverseBlogRecentStoriesHolderTab').className = "shareTabActive";
		var selectedTabBody = $('reverseBlogRecentStoriesBoxHolder');
	} else if(type == "popular") {
		// change tab actions
		$('reverseBlogRecentStoriesHolderTab').className = "shareTabInactive";
		$('reverseBlogPopularStoriesHolderTab').className = "shareTabActive";
		var selectedTabBody = $('reverseBlogPopularStoriesBoxHolder');
	}
	// send request only once
	if(BLOG_STORY_REQ_STATUS.get(type)) {
		showActiveTabBody([$('reverseBlogRecentStoriesBoxHolder'),$('reverseBlogPopularStoriesBoxHolder')], selectedTabBody);
	} else {
		getOtherStoriesFromFeed(feed_id, story_id, type);
	}
}

/**
 * function to get other stories from the feed
 */
var getOtherStoriesFromFeed = function (feed_id, story_id, type){
	// show loading image
	$('feedStoryLoader').style.display = "block";
	var postParameters = "feed_id="+feed_id+"&story_id="+story_id+"&type="+type;
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: function(response){getOtherStoriesFromFeedCallback(response, type, story_id)},
		// Handle 404
		on404: getOtherStoriesFromFeed404Callback,
		// Handle other errors
		onFailure: getOtherStoriesFromFeedFailureCallback
	}
	new Ajax.Request('/get-other-stories-from-feed', ajaxRequestOptions);
}
/**
 * function to get other stories from the feed callback function
 */
var getOtherStoriesFromFeedCallback = function (response, type, story_id){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	// hide loading image
	$('feedStoryLoader').style.display = "none";
	if(response_data.error == 0) {
		BLOG_STORY_REQ_STATUS.set(type, 1);
		var htmlHolder = "";
		for(i=0;i<response_data.story_info.length;i++) {
			var story = response_data.story_info[i];
			if(story.id != story_id) {
				if(response_data.story_clip_info[story.id] != undefined) {
					eval('user_clipped_story'+story.id+' = 1');
				} else {
					eval('user_clipped_story'+story.id+' = 0');
				}
				htmlHolder += '<div align="left" style="margin:0px;padding:5px 0px 0px 10px;">'+
					'<div align="left" style="margin:0px;padding:0px 0px 0px 4px;width:50px;float:left;">';
						if(globalUserId != 0) {
							if(response_data.story_clip_info[story.id] != undefined) {
								htmlHolder += '<div id="clipUnclipStory_hotlist_'+story.id+'" class="clippedStoryPin" title="Remove this Clip" onClick="javascript: showCommentBox('+story.id+','+eval('user_clipped_story'+story.id)+','+story.id+'); return false;">';
							} else {
								htmlHolder += '<div id="clipUnclipStory_hotlist_'+story.id+'" class="unclippedStoryPin" title="Add to my Clips" onClick="javascript: showCommentBox('+story.id+','+eval('user_clipped_story'+story.id)+','+story.id+'); return false;">';
							}
								htmlHolder += '<div align="center" class="clipCountHolder">'+story.total_clip+'</div>'+
								'<div align="center" class="clipText">'+((story.total_clip == 0 || story.total_clip > 1) ? "Clips" : "Clip")+'</div>'+
							'</div>';
						} else {
							htmlHolder += '<div id="clipUnclipStory_'+story.id+'" class="unclippedStoryPin">'+
								'<div align="center" class="clipCountHolder">'+story.total_clip+'</div>'+
								'<div align="center" class="clipText">'+((story.total_clip == 0 || story.total_clip > 1) ? "Clips" : "Clip")+'</div>'+
							'</div>';
						}
					var date_str = story.added_on.split(" ");
					htmlHolder += '</div>'+
					'<div align="left" style="margin:0px;padding:6px 0px 0px 2px;width:215px;float:left;">'+
						'<div style="padding:0px;margin:0px;font-family:Arial;font-weight:bold;font-size:12px;color:#295EAE">'+
							'<a href="/story/'+story.id+'/'+story.story_permalink+'" style="color:#2262A9;text-decoration:none;">'+story.title+'</a>'+
						'</div>'+
						'<div style="padding:0px;margin:0px;font-family:Arial;font-weight:normal;font-size:11px;color:#7E7C6F">'+
							'Posted: '+months.get(date_str[0].split("/")[1])+' '+date_str[0].split("/")[2]+', '+date_str[0].split("/")[0]+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#636363">(<a href="'+story.link+'" style="text-decoration:none;color:#1D4A8E;" onmouseover="this.style.color=\'#2974DF\'" onmouseout="this.style.color=\'#1D4A8E\'">Permalink</a>)</span>'+
						'</div>'+
						'<div style="padding:0px;margin:0px;font-family:Arial;font-weight:bold;font-size:10px;color:#7E7C6F;">';
							if(story.total_comment > 1) {
								htmlHolder += '<a class="commentStoryInactive" href="/story/'+story.id+'/'+story.story_permalink+'">'+story.total_comment+' Comments</a>';
							} else if(story.total_comment == 1) {
								htmlHolder += '<a class="commentStoryInactive" href="/story/'+story.id+'/'+story.story_permalink+'">'+story.total_comment+' Comment</a>';
							} else {
								htmlHolder += '<a class="commentStoryInactive" href="/story/'+story.id+'/'+story.story_permalink+'" style="width:105px;">Add Comment</a>';
							}
						htmlHolder += '</div>'+
					'</div>'+
					'<br clear="all"/>'+
				'</div>';
			}
		}
		if(type == "recent") {
			var selectedTabBody = $('reverseBlogRecentStoriesBoxHolder');
		} else if(type == "popular") {
			var selectedTabBody = $('reverseBlogPopularStoriesBoxHolder');
		}
		selectedTabBody.innerHTML = htmlHolder;
		showActiveTabBody([$('reverseBlogRecentStoriesBoxHolder'),$('reverseBlogPopularStoriesBoxHolder')], selectedTabBody);
		refreshSnapshots();
		// check whether to show widget or not
		if(response_data.story_info.length > 1) {
			$('reverseBlogWidgetOuterBox').style.display = "block";
		}
	}
}
/**
 * function to get other stories from the feed failure callback function
 */
var getOtherStoriesFromFeedFailureCallback = function (){
	alert("Error on page");
	// hide loading image
	$('feedStoryLoader').style.display = "none";
}
/**
 * function to get other stories from the feed 404 callback function
 */
var getOtherStoriesFromFeed404Callback= function (){
	alert("Error page is not found");
	// hide loading image
	$('feedStoryLoader').style.display = "none";
}