
// Script Name: /tag_content_ajax.js

var OneUGCTagCollection={_modules:new Array(),_currentID:0,_currentUID:0,_nodeID:0,toggleUGCTagFormView:function(id){if(id in this._modules){this._modules[id].toggleUGCTagFormView();}else{this._modules[id]=new OneUGCTag(id);this._modules[id].toggleUGCTagFormView();}},toggleUGCTagViewAll:function(id){if(id in this._modules){this._modules[id].toggleUGCTagViewAll();}else{this._modules[id]=new OneUGCTag(id);this._modules[id].toggleUGCTagViewAll();}},clearFieldValue:function(id){if(id in this._modules){this._modules[id].clearFieldValue();}else{this._modules[id]=new OneUGCTag(id);this._modules[id].clearFieldValue();}},deleteTag:function(id,tid,uid){this._currentID=id;this._currentUID=uid;if(id in this._modules){this._modules[id].deleteTag(uid,tid);}else{this._modules[id]=new OneUGCTag(id);this._modules[id].deleteTag(uid,tid);}},addTag:function(id,tag,uid,node_id){this._currentID=id;this._currentUID=uid;this._nodeID=node_id;tag=tag.replace("&","%26");if(id in this._modules){this._modules[id].addTag(uid,tag);}else{this._modules[id]=new OneUGCTag(id);this._modules[id].addTag(uid,tag);}},loadTagListing:function(svcResponse){id=svcResponse[0]['content_id'];if(id in OneUGCTagCollection._modules){OneUGCTagCollection._modules[id].hideTagForm();}else{OneUGCTagCollection._modules[id]=new OneUGCTag(id);OneUGCTagCollection._modules[id].hideTagForm();}
if(svcResponse['faultcode']==undefined){var more_tags_link_el=document.getElementById('more_tags_link'+id);if(svcResponse['total']>5&&more_tags_link_el){more_tags_link_el.innerHTML='<a href="javascript:OneUGCTagCollection.toggleUGCTagViewAll('+id+');">View More</a>';}else if(more_tags_link_el){more_tags_link_el.innerHTML='';}
document.getElementById(id).innerHTML='';response_string='';view_all_hidden=0;for(var i=0;i<svcResponse.length;i++){if(svcResponse[i]['tag']){if(i>svcResponse[0]['default_view']&&view_all_hidden==0){response_string+='<span id="view_all_tags_span'+id+'" class="view_all_tags_span">';view_all_hidden=1;}
response_string+=' <span class="normal_tag_style"><a href="'+svcResponse[i]['tag_link']+'">'+svcResponse[i]['tag']+'</a></span>';if(OneUGCTagCollection._currentUID==svcResponse[i]['owner_id']){response_string+=' <span class="tag_span_style">[<a href="javascript:OneUGCTagCollection.deleteTag('+id+','+svcResponse[i]['tag_id']+','+OneUGCTagCollection._currentUID+');">x</a>]</span> ';}else{if((i+1)<svcResponse.length){response_string+=',';}}}}
if(view_all_hidden==1){response_string+='</span>';document.getElementById(id).innerHTML=response_string;OneUGCTagCollection._modules[id].showViewAll();}else{document.getElementById(id).innerHTML=response_string;}}else{alert("Errors occurred loading the updated tag listing.");}}}
function OneUGCTag(id){this._id=id;this._formState='collapsed';this._viewAllState='collapsed';this._formDiv=document.getElementById('manage_tags_div'+this._id);this._formField=document.getElementById('txtTag'+this._id);}
OneUGCTag.prototype.toggleUGCTagFormView=function(){switch(this._formState){case'expanded':this.hideTagForm();break;case'collapsed':this.showTagForm();break;}}
OneUGCTag.prototype.showTagForm=function(){this._formDiv.style.display='block';this._formState='expanded';}
OneUGCTag.prototype.hideTagForm=function(){this._formField.value='Use commas to separate tags';this._formField.style.textAlign='center';this._formField.style.color='#696969';this._formDiv.style.display='none';this._formState='collapsed';}
OneUGCTag.prototype.toggleUGCTagViewAll=function(){switch(this._viewAllState){case'expanded':this.hideViewAll();break;case'collapsed':this.showViewAll();break;}}
OneUGCTag.prototype.showViewAll=function(){document.getElementById('view_all_tags_span'+this._id).style.display='inline';document.getElementById('more_tags_link'+this._id).innerHTML='<a href="javascript:OneUGCTagCollection.toggleUGCTagViewAll('+this._id+');">Hide More</a>';this._viewAllState='expanded';}
OneUGCTag.prototype.hideViewAll=function(){document.getElementById('view_all_tags_span'+this._id).style.display='none';document.getElementById('more_tags_link'+this._id).innerHTML='<a href="javascript:OneUGCTagCollection.toggleUGCTagViewAll('+this._id+');">View More</a>';this._viewAllState='collapsed';}
OneUGCTag.prototype.clearFieldValue=function(){if(this._formField.value!='Use commas to separate tags'){return;}
this._formField.value='';this._formField.style.textAlign='left';this._formField.style.color='#000000';}
OneUGCTag.prototype.deleteTag=function(uid,tid){var params=new Array();params['responseFunction']=this.tagServiceResponseHandler;params['action']='removeTagFromContent';params['responseFormat']='json';params['responseType']='JSON';params['handlerName']='svcTag';params['requestType']='service';params['contentID']=this._id;params['tagID']=tid;params['userID']=uid;OneAjax.request(params);}
OneUGCTag.prototype.addTag=function(uid,tag){var params=new Array();params['responseFunction']=this.tagServiceResponseHandler;params['action']='addTag';params['responseFormat']='json';params['responseType']='JSON';params['handlerName']='svcTag';params['requestType']='service';params['contentID']=this._id;params['tag']=tag;params['userID']=uid;params['nodeID']=OneUGCTagCollection._nodeID;OneAjax.request(params);}
OneUGCTag.prototype.tagServiceResponseHandler=function(svcResponse)
{if(svcResponse['faultcode']==undefined){var params=new Array();params['responseFunction']=OneUGCTagCollection.loadTagListing;params['action']='getTagsForContent';params['handlerName']='svcTag';params['requestType']='service';params['contentID']=OneUGCTagCollection._currentID;params['perPage']=100;params['responseFormat']='json';OneAjax.request(params);}else{alert("Errors occurred processing your request.  Please try again.");}}
function enterPressed(e,content_id,tag,uid,node_id)
{var keycode;if(window.event)keycode=window.event.keyCode;else if(e)keycode=e.which;else return true;if(keycode==13){OneUGCTagCollection.addTag(content_id,tag,uid,node_id);return false;}}

// Script Name: /ajax_wrapper.js

var OneAjax={_ajaxPath:'/resources/ajax/_router.one',_method:'POST',_requestType:'service',_handlerName:null,_responseFunction:null,_action:null,_responseType:'XML',_params:null,_varString:null,_isValid:true,_extraVars:null,request:function(params){if(('responseFunction'in params)&&('action'in params)&&('handlerName'in params)){this._responseFunction=params['responseFunction'];this._action=params['action'];this._handlerName=params['handlerName'];delete params['responseFunction'];delete params['action'];delete params['handlerName'];}
else{return;}
this._params=params;this._setOptionalVars();switch(this._responseType){case'XML':var handlerFunction=this.parseXmlResponse;break;case'JSON':var handlerFunction=this.parseJsonResponse;break;case'text':var handlerFunction=this.parseTextResponse;break;default:var handlerFunction=this.parseXmlResponse;break;}
this._generateVarString();if(this._isValid===false){return;}
var passArgument=new Array();passArgument['responseFunction']=this._responseFunction;passArgument['extraVars']=this._extraVars;var request=YAHOO.util.Connect.asyncRequest(this._method,this._ajaxPath,{success:handlerFunction,failure:this._genericFail,argument:passArgument},this._varString);},_setOptionalVars:function(){if('ajaxPath'in this._params){this._path=this._params['ajaxPath'];delete params['ajaxPath'];}
if('responseType'in this._params){this._responseType=this._params['responseType'];delete this._params['responseType'];}
if('requestType'in this._params){this._requestType=this._params['requestType'];delete this._params['requestType'];}
if('extraVars'in this._params){this._extraVars=this._params['extraVars'];delete this._params['extraVars'];}
return;},_generateVarString:function(){this._varString='action='+this._action;this._varString+='&requestType='+this._requestType;this._varString+='&handlerName='+this._handlerName;for(key in this._params){var valType=typeof this._params[key];if(valType!=='function'){this._varString+='&'+key+'='+this._params[key];}}
return;},parseXmlResponse:function(o){var params=o.argument;responseFunc=params['responseFunction'];extra=params['extraVars'];responseFunc(o.responseXml,extra);},parseJsonResponse:function(o){try{var resultArray=eval('('+o.responseText+')');}
catch(e){return;}
var params=o.argument;responseFunc=params['responseFunction'];extra=params['extraVars'];responseFunc(resultArray,extra);},parseTextResponse:function(o){var params=o.argument;responseFunc=params['responseFunction'];extra=params['extraVars'];responseFunc(o.responseText,extra);},_gerericFail:function(o){return;}};
