if( typeof(SNI)=='undefined' ){
		SNI = {};
}
if( typeof(SNI.Community)=='undefined' ){
		SNI.Community = {};
}
if( typeof(SNI.Community.Toolbox)=='undefined' ){
		SNI.Community.Toolbox = {};
}

if( typeof(SNI.Community.Widgets) == 'undefined' )
{
   SNI.Community.Widgets = {};
}

SNI.Community.Widgets.isPVProject = false;
if(document.getElementById("ispv")){
	SNI.Community.Widgets.isPVProject = true;
}

SNI.Community.Widgets.imageUrl="";
SNI.Community.Widgets.fbPVObjectId = 0;
SNI.Community.Widgets.fbPVWidgetId = 0;
SNI.Community.Widgets.fbPVCategory = "";

SNI.Community.Widgets.flagCacheKeys = "";
SNI.Community.Widgets.flagChannelId = "";
SNI.Community.Widgets.flagRequestFrom = "";
SNI.Community.Widgets.flagInAppCid = "";
SNI.Community.Widgets.flagInAppOid = "";
SNI.Community.Widgets.flagUploadBy = "";
SNI.Community.Widgets.flagUploadByUrl = "";
SNI.Community.Widgets.flagDescription = "";
SNI.Community.Widgets.flagUserId = "";
SNI.Community.Widgets.flagSiteId = "";

SNI.Community.Widgets.descReadMoreEnabled = false;
SNI.Community.Widgets.interstitialAdEnabled = false;
SNI.Community.Widgets.isFirstItemLoad = true;
SNI.Community.Widgets.isTopLayout = false;

SNI.Community.Widgets.validationCheck = 0;
SNI.Community.Widgets.crosstimeframecheck = 0;

SNI.Community.Widgets.mainContentHTML = "";
SNI.Community.Widgets.topClickSortModifier = false;

// Shell page script codes
//function showHideDiv()  SNI.Community.Widgets.Carousel = function(ele, config)
SNI.Community.Widgets.showHideDiv = function()
{	
	for(var i=0;i<SNI.Community.Widgets.objHideIds.length;i++){
		try{
			if(document.getElementById(SNI.Community.Widgets.objHideIds[i]))
				document.getElementById(SNI.Community.Widgets.objHideIds[i]).style.display="none";
		}catch(e){}
	}
	
	for(var j=0;j<SNI.Community.Widgets.objShowIds.length;j++){
		try{
			if(document.getElementById(SNI.Community.Widgets.objShowIds[j]))
				document.getElementById(SNI.Community.Widgets.objShowIds[j]).style.display="block";
		}catch(e){}
	}
}

//function visibleHiddenDiv()
SNI.Community.Widgets.visibleHiddenDiv = function()
{	
	for(var i=0;i<SNI.Community.Widgets.objHiddenIds.length;i++){
		try{
			if(document.getElementById(SNI.Community.Widgets.objHiddenIds[i]))
				document.getElementById(SNI.Community.Widgets.objHiddenIds[i]).style.visibility="hidden";
		}catch(e){}
	}
	
	for(var j=0;j<SNI.Community.Widgets.objVisibleIds.length;j++){
		try{
			if(document.getElementById(SNI.Community.Widgets.objVisibleIds[j]))
				document.getElementById(SNI.Community.Widgets.objVisibleIds[j]).style.visibility="visible";
		}catch(e){}
	}
}

//function signIn(val,lip,app_name){
SNI.Community.Widgets.signIn = function(val,lip,app_name){
	var logUrl = document.getElementById("gLoginUrl").value;
	
	app_name = escape(app_name);
	
	if(val!="")
		document.location = logUrl+"?DEST_URL="+val+"&lip="+lip+"&APP_NAME="+app_name;
	else	
		document.location = logUrl+"?DEST_URL="+document.location+"&lip="+lip+"&APP_NAME="+app_name;
		
	return false;
}

//function signUp(){
SNI.Community.Widgets.signUp = function(){
	//JEE Commenting out as John wants this to be full registration not task based.
	//document.location = "<%=svo.getRegistrationProjectUrl()%>?DEST_URL="+escape(document.location);
	document.location = document.getElementById("gRegistrationUrl").value;
}

//function signOut(){
SNI.Community.Widgets.signOut = function(){
	var baseDomainOfLoginProject = document.getElementById("gBaseDomainUrl").value;
	document.location = baseDomainOfLoginProject+"/redirectors/logout_redirector.jsp?DEST_URL="+document.location;
}

//function channelStats(parentObjectId){
SNI.Community.Widgets.channelStats = function(parentObjectId){
	var baseUrl = document.getElementById("gAjaxUrl").value+"/";
	var previewMode = document.getElementById("gPreviewMode").value;
	
	if(previewMode=='null' || previewMode==''){
		var ie=document.all;
		var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
		var a;
		try
		{
			a = document.getElementById('mainPageURL').href;
			a = a.split("/");
		}
		catch(err)
		{}
		var statsBaseUrl = base_Url+"/";
		try{
			statsBaseUrl = baseUrl;
		}catch(e){}
		var currentTxtRec = 0;
		var parObjId = '0';
		var objId = document.getElementById("gChannelId").value;
		var widId = 0;
		var fromUrl = "";
		var country = "";
		var fromIp = document.getElementById("gIpAddress").value;
		var fuserid = document.getElementById("gUserId").value;;
		var entType = '9';
		var hitFromType = '1';
		var widVal = document.getElementById("gWid").value;
		var refVal =  document.getElementById("gReferer").value;
		
		if(parentObjectId!="") parObjId=parentObjectId;
		
		if(widVal!="null" && widVal!="" && widVal.length>0){
			widId = widVal;
		}
	
		if(refVal!="" && refVal!="null"){
				fromUrl = refVal;
		}
		
		var url=statsBaseUrl+"pickleStats.do?pid="+parObjId+"&oid="+escape(objId)+"&wid="+escape(widId)+"&furl="+escape(fromUrl);
		url += "&ctry="+escape(country)+"&ip="+escape(fromIp)+"&fuid="+escape(fuserid)+"&et="+escape(entType)+"&hft="+escape(hitFromType);
		
		request.onreadystatechange=function()
		{
			if(request.readyState==4)
			{
				if(request.status==200)
				{
					 //alert('request.responseText :'+request.responseText);
				}
			}
		}
		request.open("POST",url,true);
		request.setRequestHeader("content-type","application/x-www-form-urlencoded");
		request.send('');
	}			
}

//function searchStats(searchType,searchWords,searchIp,searchUserId){
SNI.Community.Widgets.searchStats = function(searchType,searchWords,searchIp,searchUserId){
//try{

	var searchWords =  document.getElementById('pickle_search_box').value;
	var filterTermSearch = document.getElementById('gFilterTermsSearch').value;
	defaultSearchText = filterTermSearch;
	if(SNI.Community.Widgets.trim(searchWords)==defaultSearchText) searchWords="";
	var previewMode = document.getElementById('gPreviewMode').value;

	if((previewMode=='null' || previewMode=='')
			&& SNI.Community.Widgets.trim(searchWords)!=''){
			var a = document.getElementById('mainPageURL').href;
			a = a.split("/");
			var statsBaseUrl = "/";
			var loc_temp = document.location+"";
			if(loc_temp.indexOf("localhost")!=-1)
				statsBaseUrl += "PickleWeb/";
			var currentTxtRec = 0;
								
				var ie=document.all;
				var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
				var url=statsBaseUrl+"pickleSearchStats.do?stype="+searchType+"&swords="+escape(searchWords)+"&ip="+escape(searchIp)+"&uid="+escape(searchUserId);
				request.onreadystatechange=function()
				{
					if(request.readyState==4)
					{
						if(request.status==200)
						{
							//alert('request.responseText :'+request.responseText);
							SNI.Community.Widgets.pickleGlobalSearch();
						}
					}
				}
				request.open("POST",url,true);
				request.setRequestHeader("content-type","application/x-www-form-urlencoded");
				request.send('');
				}
		else
		{
		//$('#cgp-search').removeClass('hd_search clrfix').addClass('search_b_shadow');
		$('#pickle_search_box').focus();
		}	
//}catch(e){}	
}

//function removeCategorytag(inputStr)
SNI.Community.Widgets.removeCategorytag = function(inputStr)
{
	 //alert("inside remove :"+inputStr);
	var tmpRet = "";
	if(inputStr!=undefined){
		inputStr =  inputStr.replace(/[^a-zA-Z 0-9]+/g,'');
		inputStr = inputStr.replace(/ /g,"-");
		tmpRet = inputStr;
	}
	 //alert(tmpRet);
	return tmpRet;
}

//function removeUnwatned(input)
SNI.Community.Widgets.removeUnwatned = function(input)
{
	var temp = "";
	for(i=0;i<input.length;i++)
	{
		if(input[i] != "$" && input[i] != "%" && input[i] != "\"")
			temp += input[i];
	}
	return temp;
}

//function replaceUnwatned(inputText){
SNI.Community.Widgets.replaceUnwatned = function(inputText){
	var tmpText = escape(inputText);
	if(inputText!=""){
		//tmpText = tmpText.replace(/$/g,"");
		tmpText = tmpText.replace(/%24/g,"");
		//tmpText = tmpText.replace(/%/g,"");
		tmpText = tmpText.replace(/%25/g,"");
		//tmpText = tmpText.replace(/\"/g,"");
		tmpText = tmpText.replace(/%22/g,"");
	}
	return unescape(tmpText);
}

//function pickleGlobalSearch()
SNI.Community.Widgets.pickleGlobalSearch = function()
{
	var surl = SNI.Community.Widgets.searchUrlTemplate;

	/*var bUrl = document.getElementById("gBaseUrl").value;
	var defaultSearchText = "";
	var loc = document.location+"";
	if (loc.indexOf("&loc=")!=-1) loc = loc.substring(0,loc.indexOf("&loc="));
	*/
	var defaultSearchText = "";
	var filterTermSearch = SNI.Community.Widgets.trim( document.getElementById('gFilterTermsSearch').value );
	defaultSearchText = filterTermSearch;
	var categoryTag = "";
	if(document.getElementById('thisfilter')){
		categoryTag = document.getElementById('thisfilter').value;
	}
	 //alert(categoryTag);
	if(categoryTag=="All"){
		categoryTag = "";
	}else
	{
		 //alert("eles :"+categoryTag);
		categoryTag=SNI.Community.Widgets.removeCategorytag(categoryTag);
	}
	
	var user_search_term = document.getElementById('pickle_search_box').value;
	var catSearch = "";
	if(user_search_term=="Search")
		user_search_term = "";
	if(SNI.Community.Widgets.trim(user_search_term)==defaultSearchText) user_search_term="";

	// Calling SNI.Community.Widgets.trim(user_search_term) to to remove leading, trailing spaces from user_search_term
	
	user_search_term=SNI.Community.Widgets.trim(user_search_term)

	user_search_term = SNI.Community.Widgets.cleanSearchQuery(user_search_term);
	
    if(SNI.Community.Widgets.trim(user_search_term) !=''){
	if(categoryTag != "")
	{
		categoryTag = categoryTag+"/"+user_search_term;
	}
	else
	{
		categoryTag = user_search_term;
	}

	surl = surl.replace('_SEARCH_', categoryTag);
	
	document.location = surl;
    }
    else
    	{
    	//$('#cgp-search').removeClass('hd_search clrfix').addClass('search_b_shadow');
    	$('#pickle_search_box').focus();
    	}
}

SNI.Community.Widgets.cleanSearchQuery = function(input)
{
	var temp = input;

	temp = temp.replace(/[^a-zA-Z 0-9&']+/g,"-");
	//temp = temp.replace(/&/g,"(amp)"); 

	
	temp = temp.replace(/%/g," "); //no percentage
	temp = temp.replace(/~/g," "); //no percentage
	temp = temp.replace(/#/g," "); //no percentage
	//temp = temp.replace(/&/g," "); //no ampersand
	temp = temp.replace(/\?/g," "); //no question mark
	temp = temp.replace(/\$/g," "); //no pounds either
	temp = temp.replace(/  /g," "); //trim spaces
	temp = temp.replace(/  /g," "); //trim spaces
	temp = temp.replace(/--/g,"-"); //trim dashes
	temp = temp.replace(/-/g,"--"); //user dashes are doubled for recognition
	temp = temp.replace(/ /g,"-"); //user spaces replaced with - for recognition
	//temp = temp.replace(/[^a-zA-Z 0-9]+/g,'-');
	temp = escape(temp);

	return temp;
}

//function trim(str){
SNI.Community.Widgets.trim = function(str){
	if(str!=null && str!=undefined && str!="undefined"){ 
		return str.replace(/^\s*|\s*$/g,'')
	}else{
		return str;
	}
}

//function highlightText(obj){
SNI.Community.Widgets.highlightText = function(obj){
	var defaultSearchText = "";
	defaultSearchText = SNI.Community.Widgets.trim( document.getElementById('gFilterTermsSearch').value );


	if(SNI.Community.Widgets.trim(obj.value)==defaultSearchText){
	 obj.value=""; 
	}else if(SNI.Community.Widgets.trim(obj.value)=="Your E-mail"){
		obj.value=""; 
	}else if(SNI.Community.Widgets.trim(obj.value)=="Your Friends' E-mail Addresses"){
		obj.value=""; 
	}else if(SNI.Community.Widgets.trim(obj.value)=="Subject"){
		obj.value=""; 
	}else if(SNI.Community.Widgets.trim(obj.value)=="Your Name"){
		obj.value=""; 
	}
	obj.focus();
	 //obj.select();
}

//function checkText(obj,fromText){
SNI.Community.Widgets.checkText = function(obj,fromText){
	var defaultSearchText = "";
	defaultSearchText = document.getElementById('gFilterTermsSearch').value;

	if(SNI.Community.Widgets.trim(obj.value)=="") {
		obj.value =  defaultSearchText;
		//$('#cgp-search').removeClass('hd_search clrfix').addClass('search_b_shadow');
		//$('#pickle_search_box').focus();
	}
	else
		{
		//$('#cgp-search').removeClass('search_b_shadow').addClass('hd_search clrfix');
		}
}

//function secureUpload(){
SNI.Community.Widgets.secureUpload = function(){
	secureComponent("postSecure()","Sign In");
}
//function postSecure(){
SNI.Community.Widgets.postSecure = function(){
	document.location = document.getElementById('upload_link').href;
}
		
//function Set_Cookie( name, value, expires, path, domain, secure ){
SNI.Community.Widgets.Set_Cookie = function( name, value, expires, path, domain, secure ){
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires == 30000)
	{
		expires = 1 * expires;
	} else {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


//function Get_Cookie( name ) {
SNI.Community.Widgets.Get_Cookie = function( name ) {
	var start = document.cookie.indexOf( name + "=" );
	
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

//function Delete_Cookie( name, path, domain ) {
SNI.Community.Widgets.Delete_Cookie = function( name, path, domain ) {
	if ( SNI.Community.Widgets.Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//function setPickleCookie(type,itemid){
SNI.Community.Widgets.setPickleCookie = function(type,itemid){
	var currval = SNI.Community.Widgets.Get_Cookie(type);	
	if(currval){
	 SNI.Community.Widgets.Delete_Cookie(type, '/', '');
	 currval = currval + ',' + itemid ;
	}
	else{
	 currval = itemid;
	}
	SNI.Community.Widgets.Set_Cookie( type,currval, '365', '/', '', '' );
}

//function changeCategory(curObj,changeUrl,taxCategory,reqStatus){
SNI.Community.Widgets.changeCategory = function(curObj,changeUrl,taxCategory,reqStatus){
	SNI.Community.Widgets.Delete_Cookie('pickle_taxanomy_category','/','');
	SNI.Community.Widgets.setPickleCookie("pickle_taxanomy_category",taxCategory);
	if(reqStatus && curObj)
		curObj.href = changeUrl;
}

//function submitenter(searchType,searchWords,searchIp,searchUserId,e)
SNI.Community.Widgets.submitenter = function(searchType,searchWords,searchIp,searchUserId,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if (keycode == 13)
	{
		SNI.Community.Widgets.searchStats(searchType,searchWords,searchIp,searchUserId);
	}
}


//function displayOn(objId){
SNI.Community.Widgets.displayOn = function(objId){
	if(document.getElementById(objId)){
		document.getElementById(objId).style.display = "block";
	}	
}
//function displayOff(objId){
SNI.Community.Widgets.displayOff = function(objId){
	if(document.getElementById(objId)){
		document.getElementById(objId).style.display = "none";
	}	
}

//function clearTxtArea(objId){
SNI.Community.Widgets.clearTxtArea = function(objId){
	if(document.getElementById(objId)){
		document.getElementById(objId).value = "";
	}	
}

//function replaceAll(OldString,FindString,ReplaceString){
SNI.Community.Widgets.replaceAll = function(OldString,FindString,ReplaceString){
	var SearchIndex = 0;
	var NewString = ""; 
	while (OldString.indexOf(FindString,SearchIndex) != -1)  
	  {
		NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));
		NewString += ReplaceString;
		SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length);         
		}
	NewString += OldString.substring(SearchIndex,OldString.length);
	return NewString;
}

//function setfilter(inFilter){
SNI.Community.Widgets.setfilter = function(inFilter){
	inFilter=SNI.Community.Widgets.replaceAll(inFilter,"|","'");
	document.getElementById('thisfilter').value=inFilter;
}

// End shell page script codes

//Detail Page code start

//function isRatingCookieFound(itemid){
SNI.Community.Widgets.isRatingCookieFound = function(itemid){
	var search_key = itemid;
	if(SNI.Community.Widgets.getratingscookie()){
		if(SNI.Community.Widgets.getratingscookie().search(search_key)==-1){
			SNI.Community.Widgets.layerOn('rate');
		}
		else{
			SNI.Community.Widgets.layerOff('rate');
			alert('You already rated this!');
		}
	}
	else{
		SNI.Community.Widgets.layerOn('rate');
	}
}

SNI.Community.Widgets.initVoting = function(itemid,userid,isUr){
	var voteCookie = "";
	var search_key = itemid;
	var ur = "true";
	if( isUr == undefined ){
		if( document.getElementById("gUrNonur") ){
			ur = SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
		}
	}else{
		ur = isUr;	
	}
	
	if(ur=="true"){
		voteCookie = "pickle_votings"+itemid+userid;
	}else{
		voteCookie = "pickle_votings"+itemid+"";	
	}

	//if(parseInt(userid) != -1 && SNI.Community.Widgets.Get_Cookie( SNI.Community.Widgets.trim(voteCookie) )){
	if( SNI.Community.Widgets.Get_Cookie( SNI.Community.Widgets.trim(voteCookie) ) ){
		SNI.Community.Widgets.displayOn('vote_done');
		SNI.Community.Widgets.displayOff('vote_init');
		SNI.Community.Widgets.displayOn("vr");
		SNI.Community.Widgets.displayOff('vote_loading');
		SNI.Community.Widgets.displayOff("vote_error");
		SNI.Community.Widgets.displayOff('vr-loading');
	}
	else{
		SNI.Community.Widgets.displayOff('vote_done');
		SNI.Community.Widgets.displayOn('vote_init');
		SNI.Community.Widgets.displayOff('vote_loading');
		SNI.Community.Widgets.displayOff("vote_error");
		SNI.Community.Widgets.displayOff('vr-loading');
		SNI.Community.Widgets.displayOn("vr");
	}
}

SNI.Community.Widgets.secureVote = function(){
	var ur = SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	if(ur=="true"){
		secureComponent("SNI.Community.Widgets.doVote()","You Need To Be Signed In To Do That.","voteforit",3);
	}else{
		SNI.Community.Widgets.doVote()
	}
}

SNI.Community.Widgets.createVotingsCookie = function(request,itemid,userid){
	SNI.Community.Widgets.Set_Cookie('pickle_votings'+itemid+userid,request.responseXML.getElementsByTagName('nofvotes').item(0).firstChild.nodeValue, '365', '/', '', '' );
	SNI.Community.Widgets.initVote(itemid,userid);
}
SNI.Community.Widgets.doVote = function(){
	var origProjectId = document.getElementById("gOrigProjectId").value;
	var logUserId = document.getElementById("gUserId").value;
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	
	SNI.Community.Widgets.displayOff('vote_done');
	SNI.Community.Widgets.displayOff('vote_init');
	SNI.Community.Widgets.displayOn('vote_loading');
	SNI.Community.Widgets.displayOn('vr-loading');
	SNI.Community.Widgets.displayOff("vote_error");
	SNI.Community.Widgets.displayOff("vr");
	
	var url = "";
		
	var ur = SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	if(ur=="true"){
		url = gAjaxUrl+'/voteobject.do?objId='+document.getElementById("gObjId").value+'&wpid='+origProjectId+'&userid='+logUserId+"&d2curl="+escape(window.location)+"&nameused="+escape(SNI.Community.Toolbox.cWidgetNameUsedInApp);
	}else{
		url = gAjaxUrl+'/nourvoteobject.do?objId='+document.getElementById("gObjId").value+'&wpid='+origProjectId+'&userid='+logUserId+"&d2curl="+escape(window.location)+"&nameused="+escape(SNI.Community.Toolbox.cWidgetNameUsedInApp);
	}		
	
	
	///
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	
	SNI.Community.Widgets.displayOff('rating-stars-content');
	SNI.Community.Widgets.displayOn('rating-stars-loading-content');
	
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200)
			{
			//	SNI.Community.Widgets.createVotings(request,document.getElementById("gObjId").value,logUserId);
				var totVotes = parseInt(request.responseXML.getElementsByTagName('nofvotes').item(0).firstChild.nodeValue)-1;
				if(ur=="true"){
					SNI.Community.Widgets.Set_Cookie( SNI.Community.Widgets.trim('pickle_votings'+document.getElementById("gObjId").value+logUserId),totVotes, '365', '/', '', '' );
				}else{
					SNI.Community.Widgets.Set_Cookie( SNI.Community.Widgets.trim('pickle_votings'+document.getElementById("gObjId").value+''),totVotes, '365', '/', '', '' );
				}
				document.getElementById('vote_total').innerHTML = totVotes;
				SNI.Community.Widgets.initVoting(document.getElementById("gObjId").value,logUserId,ur);
			}
		}
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send('');
	
	//simplePost(url,"SNI.Community.Widgets.createVotings(request,'"+document.getElementById("gObjId").value+"','"+logUserId+"')");
}

//function closeratinglayer(){
SNI.Community.Widgets.closeratinglayer = function(){
	if(document.getElementById('rate').style.visibility == 'visible'){
		SNI.Community.Widgets.layerOff('rate');
	}
}
//function layerOn(objId){
SNI.Community.Widgets.layerOn = function(objId){
	if(document.getElementById(objId))
		document.getElementById(objId).style.visibility = "visible";
}

//function layerOff(objId){
SNI.Community.Widgets.layerOff = function(objId){
	if(document.getElementById(objId))
		document.getElementById(objId).style.visibility = "hidden";
}

//function setratingscookie(itemid)
SNI.Community.Widgets.setratingscookie = function(itemid)
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	var currval = SNI.Community.Widgets.getratingscookie();	
	if(currval){
	 SNI.Community.Widgets.Delete_Cookie('pickle_ratings'+gObjId, '/', '');
	 currval = currval + ',' + itemid ;
	}
	else{
	 currval = itemid;
	}
	SNI.Community.Widgets.Set_Cookie( 'pickle_ratings'+gObjId,currval, '365', '/', '', '' );
}

//function setvotescookie(itemid)
SNI.Community.Widgets.setvotescookie = function(itemid)
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	var currval = SNI.Community.Widgets.getvotescookie();	
	if(currval){
	 SNI.Community.Widgets.Delete_Cookie('pickle_votings'+gObjId, '/', '');
	 currval = currval + ',' + itemid ;
	}
	else{
	 currval = itemid;
	}
	SNI.Community.Widgets.Set_Cookie( 'pickle_votings'+gObjId,currval, '365', '/', '', '' );
}

//function getratingscookie(val)
SNI.Community.Widgets.getratingscookie = function(val)
{			
	try{
		var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
		var temp = SNI.Community.Widgets.Get_Cookie('pickle_ratings'+gObjId);
		
		if(temp && temp.indexOf("///")!=-1&&val==1){
			return temp.substring(temp.indexOf("///")+3,temp.length);
		}	
		else if(temp && temp.indexOf("///")!=-1){
			return temp.substring(0,temp.indexOf("///"));
		}	
		else{
			return temp;
		}
	}catch(e){}		
}

//function getvotescookie()
SNI.Community.Widgets.getvotescookie = function()
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	return SNI.Community.Widgets.Get_Cookie('pickle_votes'+gObjId);
}

//function rateLayerOnOff(param)
SNI.Community.Widgets.rateLayerOnOff = function(param)
{
	if(param=='off'){
		SNI.Community.Widgets.displayOff('top-info-right-a');
		SNI.Community.Widgets.displayOff('top-info-right-b');
		document.getElementById('cgp-id-page-top-info-right').className = "";
	}
	else
	{
		SNI.Community.Widgets.displayOn('top-info-right-a');
		SNI.Community.Widgets.displayOn('top-info-right-b');
		document.getElementById('cgp-id-page-top-info-right').className = "cgp-id-page-top-info-right";
	}
}

//function formatStringSpecialChars(str)
SNI.Community.Widgets.formatStringSpecialChars = function(str)
{
	if(str.length>0)
	{
		str=SNI.Community.Widgets.ConvertSpecialChars(str);
		str=SNI.Community.Widgets.ConvertLatin2ToAsciiChars(str);
	}
	return str;
}

//function ConvertSpecialChars(str) 
SNI.Community.Widgets.ConvertSpecialChars = function(str)
{
	if(str.length > 0){   
		str = str.replace(new RegExp(String.fromCharCode(8216),"g"),"'");
		str = str.replace(new RegExp(String.fromCharCode(8217),"g"),"'");
		str = str.replace(new RegExp(String.fromCharCode(8220),"g"),"\"");
		str = str.replace(new RegExp(String.fromCharCode(8221),"g"),"\"");
		return str;   
	}
}

//function ConvertLatin2ToAsciiChars(str) 
SNI.Community.Widgets.ConvertLatin2ToAsciiChars = function(str)
{ 
	str = str.replace(/\r\n/g,"\n");
	var utftext = "";
	
	for (var n = 0; n < str.length; n++) 
	{
	
		var c = str.charCodeAt(n);
		
		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return str;
}

//function formatString2(str)
SNI.Community.Widgets.formatString2 = function(str)
{
	str = str.replace(/&lt;/g,"<");
	str = str.replace(/&gt;/g,">");
	str = str.replace(/&amp;/g,"&");
	str = str.replace(/&apos;/g,"'");
	str = str.replace(/&quot;/g,"\"");
	return str;
}

//function formatString(str)
SNI.Community.Widgets.formatString = function(str)
{
	str = str.replace(/%0A/g, "<br>");
	
	str = unescape(str);
	
	return str;
}			

//function submitPrint(curObj){
SNI.Community.Widgets.submitPrint = function(curObj){
	var printUrl = document.getElementById("gPrintUrl").value;
	document.location = printUrl+escape(document.location);
	//document.location = "<%=ajaxUrl%>/collectionsprint.do?<%=Pickle2WebHttpRequestConstants.URL_OBJECT_ID%>=<%=CVO.getObjectId()%>&wid=<%=wid%>&loc="+escape(document.location);
}  

//function closeErrorMsg(){
SNI.Community.Widgets.closeErrorMsg = function(){
	document.getElementById('cgp-id-page-itemsaved-d2c').style.display = "none";
}

//function closeErrorMsgSingleUp(){
SNI.Community.Widgets.closeErrorMsgSingleUp = function(){
	document.getElementById('cgp-id-page-itemsaved').style.display = "none";
}

//function getElementsByClassName(className, tag, elm){
SNI.Community.Widgets.getElementsByClassName = function(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

//function handleRated(val)
SNI.Community.Widgets.handleRated = function(val)
{
	
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
		
	if(userLogin=="" || userLogin=="false"){
			var a = SNI.Community.Widgets.getElementsByClassName("cgp-ratestar-on", "div",document);
			for(i=0;i<a.length;i++)
				a[i].className = "cgp-ratestar-rated";
				
			a = SNI.Community.Widgets.getElementsByClassName("cgp-ratestar", "div",document);
			for(i=0;i<a.length;i++)
				a[i].className = "cgp-ratestar-rated-logout";
	}else{
		var class_name = "cgp-ratestar-rated";
		if(SNI.Community.Widgets.getratingscookie()){
		
		 if(SNI.Community.Widgets.getratingscookie().search(gObjId)!=-1 )
			{
				var a = SNI.Community.Widgets.getElementsByClassName("cgp-ratestar-on", "div",document);
				for(i=0;i<a.length;i++)
					a[i].className = "cgp-ratestar-rated";
					
				a = SNI.Community.Widgets.getElementsByClassName("cgp-ratestar", "div",document);
				for(i=0;i<a.length;i++)
					a[i].className = "cgp-ratestar-rated-logout";
				
			}
		}
	}
}

SNI.Community.Widgets.bol = false;
//function mouse_in()
SNI.Community.Widgets.mouse_in = function()
{
	SNI.Community.Widgets.bol = true;
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	if(userLogin=="false" && ur=="true"){
			
			document.getElementById("cgp-ratings-notloggedin").style.display = "block";
			document.getElementById("cgp-ratings-message").style.display = "none";
			//document.getElementById("cgp-ratings-message").innerHTML = "<a onmouseover=\"SNI.Community.Widgets.mouse_in()\" href=\"javascript:SNI.Community.Widgets.secureRating('<%=CVO.getObjectId()%>',1);\"><b>Please sign in to rate</b></a>"
	}else{
		SNI.Community.Widgets.select_star_css(parseInt(SNI.Community.Widgets.getratingscookie(1)));
	}
}

SNI.Community.Widgets.temp_obj = 0;
SNI.Community.Widgets.prev_val = "";

//function rateTypes(inDiv, inRateType,curId,val)
SNI.Community.Widgets.rateTypes = function(inDiv, inRateType,curId,val)
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	
	if(SNI.Community.Widgets.getratingscookie()){
		if(SNI.Community.Widgets.getratingscookie().search(gObjId)!=-1)
			return;
	}
	var tmpInRateType = inRateType;
	
	if(inRateType=="rating_val"){
		inRateType = document.getElementById('cgp-ratings-message-hidden').value;
	}

	if(userLogin=="true" || ur=="false"){
			SNI.Community.Widgets.temp_obj = val;
			if(tmpInRateType!="rating_val")
			{
				SNI.Community.Widgets.select_star_css(val);
			}
			else
			{						
				//SNI.Community.Widgets.select_star_css(0);
			}
	}
	//document.getElementById(inDiv).innerHTML = inRateType;
}

//function reset_stars()
SNI.Community.Widgets.reset_stars = function()
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	if(SNI.Community.Widgets.getratingscookie()){
		if(SNI.Community.Widgets.getratingscookie().search(gObjId)!=-1)
			return;
		}
	SNI.Community.Widgets.select_star_css(SNI.Community.Widgets.temp_obj);
}

//function reset_stars_restore()
SNI.Community.Widgets.reset_stars_restore = function()
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	if(SNI.Community.Widgets.bol)
	{
		SNI.Community.Widgets.bol = false;
		false;
	}
	if(SNI.Community.Widgets.getratingscookie()){ 
		if(SNI.Community.Widgets.getratingscookie().search(gObjId)!=-1)
			return;
		}
	
	SNI.Community.Widgets.select_star_css(0);
	//document.getElementById("cgp-ratings-message").innerHTML = "Ratings: <%--=CVO.getNumOfRatings()--%>" ;
	document.getElementById("cgp-ratings-notloggedin").style.display = "none";
	document.getElementById("cgp-ratings-message").style.display = "block";
	//SNI.Community.Widgets.prev_val = "";
}



//function getlogin(inDiv)
SNI.Community.Widgets.getlogin = function(inDiv)
{
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);

	if(ur=="true"){
		if(userLogin=="false"){
			document.getElementById(inDiv).innerHTML = "<a href='#'>Please sign in to rate</a>"
		}else{
			document.getElementById(inDiv).innerHTML = document.getElementById('cgp-ratings-message-hidden').value;
		}
	}else{
		document.getElementById(inDiv).innerHTML = document.getElementById('cgp-ratings-message-hidden').value;
	}
}

//function securefavorite(val)
SNI.Community.Widgets.securefavorite = function(val)
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	secureComponent("SNI.Community.Widgets.submitvotes('"+gObjId+"','"+val+"')","You Need To Be Signed In To Do That.",'cgp-id-page-title-area',4);
}

SNI.Community.Widgets.TopNavSecureFavoriteOverlay = function(val)
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	secureComponent("SNI.Community.Widgets.submitvotes('"+gObjId+"','"+val+"')","You Need To Be Signed In To Do That.",'rmrfavoriteDiv',4);
}


SNI.Community.Widgets.secureFlagForPortfolioGallery = function(objId){
	secureComponent("SNI.Community.Widgets.showConfirmMultigallery('flag_"+objId+"')","You Need To Be Signed In To Do That.",'flaglink_'+objId,6);
}

SNI.Community.Widgets.secureFlagForMultiGallery = function(objId){
	if(document.getElementById('isUr').value == "true"){
		secureComponent("SNI.Community.Widgets.showConfirmMultigallery('flag_"+objId+"')","You Need To Be Signed In To Do That.",'flaglink_'+objId,6);
	}else{
		SNI.Community.Widgets.showConfirmMultigallery('flag_'+objId);
	}
}

SNI.Community.Widgets.postFlagGallery = function(objId){
	if( document.getElementById('chId_'+objId) ){
		SNI.Community.Widgets.flagChannelId = document.getElementById('chId_'+objId).value;
	}
	if( document.getElementById('objDesc_'+objId) ){
		SNI.Community.Widgets.flagDescription = document.getElementById('objDesc_'+objId).innerHTML;
	}
	
	if( document.getElementById("objUploadBy_"+objId) ){
		SNI.Community.Widgets.flagUploadBy = document.getElementById("objUploadBy_"+objId).value;
	}
	
	if( document.getElementById("flagUserId_"+objId) ){
		SNI.Community.Widgets.flagUserId = document.getElementById("flagUserId_"+objId).value;
	}
	
	if( document.getElementById("projectSiteId") ){ // Is gallery pages
		SNI.Community.Widgets.flagSiteId = document.getElementById("projectSiteId").value; 
	}
	else if( document.getElementById("flagSiteId_"+objId) ){
		SNI.Community.Widgets.flagSiteId = document.getElementById("flagSiteId_"+objId).value;
	}
	
	//PICKLE-960
	if( document.getElementById("gProjectType") && document.getElementById("gProjectType").value=="5" ){ 
		SNI.Community.Widgets.flagRequestFrom = "homepage";
	}
	
	
		
	SNI.Community.Widgets.flagAsInappropriateGallery(objId,'items','flaglink_'+objId,'null');
}

SNI.Community.Widgets.postFlagPortfolioGallery = function(objId){
	SNI.Community.Toolbox.cAssetId = objId;	
	SNI.Community.Toolbox.cSelectedId = objId;
	SNI.Community.Widgets.flagCacheKeys = document.getElementById("globalPageCacheKeys").value;
	SNI.Community.Widgets.flagChannelId = document.getElementById('chId_'+objId).value;
	SNI.Community.Widgets.flagRequestFrom = "portfolio";
	SNI.Community.Widgets.flagInAppCid = "";
	SNI.Community.Widgets.flagInAppOid = "";
	if( document.getElementById("disp_name_id") ){
		SNI.Community.Widgets.flagUploadBy = document.getElementById("disp_name_id").innerHTML;
	}
	
	if( document.getElementById("userProfileURL_href_Id") ){
		SNI.Community.Widgets.flagUploadByUrl = document.getElementById("userProfileURL_href_Id").href; 
	}
	
	if( document.getElementById('objDesc_'+objId) ){
		SNI.Community.Widgets.flagDescription = document.getElementById('objDesc_'+objId).innerHTML;
	}
	
	if( document.getElementById("flagUserId_"+objId) ){
		SNI.Community.Widgets.flagUserId = document.getElementById("flagUserId_"+objId).value;
	}

	if( document.getElementById("flagSiteId_"+objId) ){
		SNI.Community.Widgets.flagSiteId = document.getElementById("flagSiteId_"+objId).value;
	}
			
	SNI.Community.Widgets.flagAsInappropriateGallery(objId,'items','flaglink_'+objId,'null');
}

SNI.Community.Widgets.flagAsInappropriateGallery = function(id,flagType,obj,commentsId)
{
	SNI.Community.Toolbox.ie=document.all;
	var request=SNI.Community.Toolbox.ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	var comments = "";
	var caption = "";
	var uploadBy = "";
	var description = "";
	var uploadbyurl = "";
	var modId = id;
	var d2cLink = window.location.href;
	d2cLink = d2cLink.replace(/#/g, "");
	var flagReason = "";
	var gOridWPID = '';
	if( document.getElementById("gOrigProjectId") )
		gOridWPID = trim(document.getElementById("gOrigProjectId").value);
	
	if(document.getElementById("item_flag_reason_"+id)){
		flagReason = trim( document.getElementById("item_flag_reason_"+id).value );
	}
	
	if(trim(flagReason) == ""){
		SNI.Community.Widgets.displayOn("item_flag_reason_error_"+id);
		document.getElementById("item_flag_reason_error_"+id).innerHTML = "You must provide a reason for flagging this item.";
		return;
	}else{
		if( SNI.Community.Widgets.flagRequestFrom == "portfolio" ){
			SNI.Community.Widgets.displayOff('flag_'+id);
		}else{
			SNI.Community.Widgets.closeFlagPopup(id)
		}
	}
	
	
	var sendalertemailValue=document.getElementById("sendalertemailextCommentValue").value;
	var deactivateItemValue=document.getElementById("deactivateextCommentValue").value;
	var sendalertemailthreshold=document.getElementById("sendalertemailextCommentthreshold").value;
	var deactivateItemthreshold=document.getElementById("deactivateextCommentthreshold").value;
	
	
	//d2cLink += "&cObjId="+SNI.Community.Toolbox.cSelectedId;

	if(commentsId!='null'){
		comments = document.getElementById(commentsId).innerHTML;
		comments = comments.replace('<div>','');
		comments = comments.replace('</div>','');
	}
	
	SNI.Community.Widgets.flagInAppOid = id;
	if ( SNI.Community.Widgets.trim(SNI.Community.Widgets.flagInAppCid) == ""){
		SNI.Community.Widgets.flagInAppCid = id;
	} 	

	if ( SNI.Community.Widgets.trim(SNI.Community.Widgets.flagChannelId) == ""){
		SNI.Community.Widgets.flagChannelId = id;
	} 	
		
	var a1aUrl = escape( SNI.Community.Toolbox.cAdminRootUrl+"/a1adirect.do?pId="+SNI.Community.Widgets.flagChannelId+"&collectionId="+SNI.Community.Widgets.flagInAppOid+"&listIndex=0&channelPno=1" );
	var url= SNI.Community.Toolbox.subPath + "/flagasinappropriate.do";
	
	var ur = "";
	if( document.getElementById("gUrNonur")){
		ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);

		if(ur=="false"){
			url= SNI.Community.Toolbox.subPath+"/flagasinappropriatenonur.do";
		}
		
	}	
	
	var params = "collectionId="+id+"&obj_type="+escape(flagType);
	params += "&d2c_link="+escape(d2cLink);
	params += "&moderationurl="+escape(""+SNI.Community.Toolbox.cAdminRootUrl+"/moderation.do?oid="+id+"&statusId=1&objectType=pva&flag="+flagType+"&pid="+id+"&ht="+id);
	//params += "&inappropriateurl="+escape(SNI.Community.Toolbox.cAdminRootUrl+"/loadCMS.do?cmsId="+SNI.Community.Toolbox.cSelectedId+"&assetid="+SNI.Community.Toolbox.cAssetId);
	params += "&inappropriateurl="+a1aUrl;
	params += "&comments="+escape(comments)+"&caption="+escape(document.getElementById('cap_'+id).value);
	params += "&sendalertemailValue="+escape(sendalertemailValue);
	params += "&deactivateItemValue="+escape(deactivateItemValue);
	params += "&sendalertemailthreshold="+escape(sendalertemailthreshold);
	params += "&deactivateItemthreshold="+escape(deactivateItemthreshold);	
	params += "&wpid="+gOridWPID;
	params += "&reason="+escape(flagReason);
	params += "&rf="+escape(SNI.Community.Widgets.flagRequestFrom);
	params += "&cks="+escape(SNI.Community.Widgets.flagCacheKeys);
	params += "&cid="+SNI.Community.Widgets.flagChannelId;
	params += "&uploadBy="+escape(SNI.Community.Widgets.flagUploadBy);
	params += "&userprofilelink="+escape(trim(SNI.Community.Widgets.flagUploadByUrl));
	params += "&description="+escape(trim(SNI.Community.Widgets.flagDescription));
	if( SNI.Community.Widgets.flagSiteId ){
		params += "&siteId="+SNI.Community.Widgets.flagSiteId;
	}
	
	if( SNI.Community.Widgets.flagUserId ){
		params += "&userid="+SNI.Community.Widgets.flagUserId;
	}		
				
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200 ||request.status==12152)
			{
				obj = document.getElementById(obj);
				if( ur=="false" ){
					SNI.Community.Widgets.setPickleCookie("pickle_item_inapp_"+id,id);
				}else{
					SNI.Community.Widgets.setPickleCookie("pickle_item_inapp_"+id+"_"+document.getElementById('loggedInUserId').value,id);
				}

				if( SNI.Community.Widgets.flagRequestFrom == "portfolio" ){
					SNI.Community.Widgets.displayOff('flag_'+id);
				}else{
					SNI.Community.Widgets.closeFlagPopup(id)
				}

				obj.parentNode.innerHTML = " Flagged";				
			}
			else if(request.status==500){
				alert("You found an opportunity for improvement! Please try again later");
			}	
			else{
				alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
			}	
		}
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.send(params);
}

SNI.Community.Widgets.closeFlagPopup = function (objId){

	if( document.getElementById('flag_'+objId) ){
		SNI.Community.Widgets.displayOff('flag_'+objId);
	}

	for(i=0;i<20;i++){
		try{
			if( document.getElementById('flag_'+objId+'_'+i) ){
				SNI.Community.Widgets.displayOff('flag_'+objId+'_'+i);
			}
		}catch(e){}
	}
}


//function showConfirm(){
SNI.Community.Widgets.showConfirmMultigallery = function(obj_id){
	SNI.Community.Widgets.displayOn(obj_id);
	//var obj = document.getElementById(obj_id);
	//SNI.Community.Widgets.displayOnWithAlignCenter(obj,obj_id)
}


//function secureFlag(){
SNI.Community.Widgets.secureFlag = function(){
	secureComponent("SNI.Community.Widgets.showConfirm()","You Need To Be Signed In To Do That.",'cgp-id-page-title-area',6);
}

//function postsecureFlag(){
SNI.Community.Widgets.postsecureFlag = function(){
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	flagAsInappropriate(gObjId,'items','flag_link','null');
}

SNI.Community.Widgets.postsecureFlagTop = function(){
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	flagAsInappropriate(gObjId,'items','rmr_flag','null');
}

//function showConfirm(){
SNI.Community.Widgets.showConfirm = function(){
	SNI.Community.Widgets.displayOn('cgp-flyout-flag');
	document.getElementById("item_flag_reason_error").innerHTML = "";
	SNI.Community.Widgets.displayOff("item_flag_reason_error");
}

//function secureComments(id,flagType,obj,commentsId){
SNI.Community.Widgets.secureComments = function(id,flagType,obj,commentsId){
	secureComponent("SNI.Community.Widgets.postsecureComments('"+id+"','"+flagType+"','"+obj+"','"+commentsId+"')","YOU NEED TO BE SIGNED IN TO DO THAT.",obj,5);
	SNI.Community.Widgets.displayOff('cgp-flyout-flag');
} 

//function postsecureComments(id,flagType,obj,commentsId){
SNI.Community.Widgets.postsecureComments = function(id,flagType,obj,commentsId){
	flagAsInappropriate(id,flagType,obj,commentsId);
}

//function secureRating(id,retVal){
SNI.Community.Widgets.secureRating = function(id,retVal){
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id

	if(userLogin=="true"){
		if(SNI.Community.Widgets.getratingscookie()&&SNI.Community.Widgets.getratingscookie().search(gObjId)!=-1)
				return ;
	}
	
	secureComponent("SNI.Community.Widgets.postsecureRating('"+id+"','"+retVal+"')","YOU NEED TO BE SIGNED IN TO DO THAT.","cgp-id-page-title-area",3);
} 

SNI.Community.Widgets.secureRating = function(id,retVal){
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id

	if(userLogin=="true"){
		if(SNI.Community.Widgets.getratingscookie()&&SNI.Community.Widgets.getratingscookie().search(gObjId)!=-1)
				return ;
	}
	
	secureComponent("SNI.Community.Widgets.postsecureRating('"+id+"','"+retVal+"')","YOU NEED TO BE SIGNED IN TO DO THAT.","cgp-id-page-title-area",3);
} 


SNI.Community.Widgets.securechat = function(val){
	secureComponent("SNI.Community.Widgets.submitvotes('0','yes')","YOU NEED TO BE SIGNED IN TO DO THAT.");
}

SNI.Community.Widgets.postsecureRating = function(id,retVal){
	SNI.Community.Widgets.submitrating(id,retVal);
}

//Carousel related code start

SNI.Community.Widgets.paginationLen = 5;
SNI.Community.Widgets.resultText = "";
SNI.Community.Widgets.objType = "";
SNI.Community.Widgets.objHeight = "0";
SNI.Community.Widgets.objWidth = "0";
SNI.Community.Widgets.selectedId = 0;
SNI.Community.Widgets.count =0 ;
SNI.Community.Widgets.inAppItemId = 0; 

SNI.Community.Widgets.restAll = function(){
	for(i=0;i<objIdArr.length;i++){
	try{
		document.getElementById('carousel_'+objIdArr[i]).className='thumb-nav-thumb';
		}catch(e){}
	}
}

SNI.Community.Widgets.fireEvent = function(element,event) {
   if (document.createEventObject) {
       // dispatch for IE
       var evt = document.createEventObject();
       return element.fireEvent('on'+event,evt)
   } else {
       // dispatch for firefox + others
       var evt = document.createEvent("HTMLEvents");
       evt.initEvent(event, true, true ); // event type,bubbling,cancelable
       return !element.dispatchEvent(evt);
   }
}

SNI.Community.Widgets.posI;
SNI.Community.Widgets.ovPos=0;
SNI.Community.Widgets.currentTxtRec = 0;
SNI.Community.Widgets.isOverlayAvailable = false;
SNI.Community.Widgets.pageLoadFlag = true;

SNI.Community.Widgets.moveOn = function(val,curObjSNI)
{
	
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	var itemListCount = document.getElementById("gItemListCount").value;
	var overLay = SNI.Community.Widgets.trim(document.getElementById("gOverlay").value);
	var defaultWidth = SNI.Community.Widgets.trim(document.getElementById("gDefaultWidth").value);
	var defaultHeight = SNI.Community.Widgets.trim(document.getElementById("gDefaultHeight").value);

	
	// Calling Nielsen Tracing Web Analytics
	
	SNI.Community.Widgets.callNielsenTracking();
	
	$('.img_pre').removeClass('moveOut');
	$('.img_next').removeClass('moveOut');

	if(SNI.Community.Widgets.currentTxtRec < (parseInt(itemListCount)-1))
		SNI.Community.Widgets.ovPos=SNI.Community.Widgets.currentTxtRec;

	if( SNI.Community.Widgets.pageLoadFlag ){
		if(SNI.Community.Widgets.posI == (parseInt(itemListCount)-1))
			SNI.Community.Widgets.ovPos=SNI.Community.Widgets.posI;
	}
	SNI.Community.Widgets.pageLoadFlag = false;
	
	//Added IF conditon for Pickle 2313 issue
	if((document.getElementById("laytype").value == "top")){
		//SNI.Community.Widgets.displayOff('moreCont_bg');
		//SNI.Community.Widgets.displayOff('moreCont');
		SNI.Community.Widgets.closeTophatOtherSpaces();
	}	
	if(val=="incre"){
		if((document.getElementById("laytype").value == "top")){
			var prevLink = document.getElementById("prevLink");
			prevLink.style.display = "block";		
		}		
		SNI.Community.Widgets.posI++;
		SNI.Community.Widgets.ovPos++;
	}	
	else{		
		SNI.Community.Widgets.posI--;
	}	

	
	//if( SNI.Community.Widgets.posI >= ( parseInt(itemListCount)-1 ) )
	if( SNI.Community.Widgets.posI > ( parseInt(itemListCount)-1 ) )
		SNI.Community.Widgets.posI = 0;
	else if(SNI.Community.Widgets.posI<0)
		SNI.Community.Widgets.posI = parseInt(itemListCount)-1;
		
	// Code to Display Overlay Popup on clicking next button

	var ovlyCnt=itemListCount;	
	SNI.Community.Widgets.isOverlayAvailable = false;

	if(overLay=="true"){ 	
		
		if(SNI.Community.Widgets.ovPos==ovlyCnt){
				//SNI.Community.Widgets.showOtherSpaces('<%=strContainerIds%>','<%=CVO.getObjectId()%>','1','<%=vwvo.getWidgetProjectId()%>','<%=systemTagList.SNI.Community.Widgets.replaceAll("'","\\\\'")%>','all','<%=CVO.getUserId()%>');
				if((document.getElementById("laytype").value == "top")) {  //if( document.getElementById('projectSiteId').value == 14 )
					SNI.Community.Widgets.topLayoutD2COverlay();
					SNI.Community.Widgets.isOverlayAvailable = true;
				}else{
					SNI.Community.Widgets.testOverlay();
					SNI.Community.Widgets.isOverlayAvailable = true;
				}
				SNI.Community.Widgets.ovPos=-1;
				SNI.Community.Widgets.posI = parseInt(itemListCount)-1;									
			}
		else{
		try{
			 SNI.Community.Widgets.closeOtherSpaces();
			}catch(e){}
		}
		var itemCnt=SNI.Community.Widgets.currentTxtRec;
	}
	
	var sObjType = "";	
	if(document.getElementById('sObjType'+SNI.Community.Widgets.posI)){
		sObjType = document.getElementById('sObjType'+SNI.Community.Widgets.posI).value;
	}	
	
	//PICKLE-3052
	SNI.Community.Widgets.alignButtons();
	
	SNI.Community.Widgets.showThis(SNI.Community.Widgets.posI,sObjType,defaultWidth,defaultHeight,true,curObjSNI,true);	
	//SNI.Community.Widgets.showThis(SNI.Community.Widgets.posI,'<%//=defaultObjectType%>','<%//=defaultWidth%>','<%//=defaultHeight%>',false,curObjSNI);
		
	if(overLay=="true"){ 	
		if(SNI.Community.Widgets.ovPos==ovlyCnt){
			// hiding the overlay ads
			SNI.Community.Widgets.closeInterstitialAdDiv();
		}
	}
	
	if( SNI.Community.Widgets.isOverlayAvailable ){
		SNI.Community.Widgets.removeMainContent();		
	}
}

SNI.Community.Widgets.renderHidenIframe = function(){
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	if(document.getElementById('hidfrme'))
	{
		document.getElementById('hidfrme').src = gAjaxUrl+"/jsp_p2/widget/fixHits.html";
	}else{
		var a = document.createElement('iframe');
		a.id = "hidfrme";
		a.src = gAjaxUrl+"/jsp_p2/widget/fixHits.html";
		a.style.visibility = "hidden";
		a.style.position = "absolute";
		document.getElementsByTagName('head')[0].appendChild(a);
	}
}

SNI.Community.Widgets.overallCount = 0;

SNI.Community.Widgets.hideOverlayDivs = function(){
	try{
		
		// SNI.Community.Widgets.ovPos = 0;
		var itemListCount = document.getElementById("gItemListCount").value;
		if(SNI.Community.Widgets.currentTxtRec < (parseInt(itemListCount)-1))
			SNI.Community.Widgets.ovPos=SNI.Community.Widgets.currentTxtRec;
		
		if((document.getElementById("laytype").value == "top")){
			SNI.Community.Widgets.closeTophatOtherSpaces();	
		}else{
		   	SNI.Community.Widgets.closeOtherSpaces();	
		}
	}
	catch(e){}
}

SNI.Community.Widgets.showThis = function(in_pos,in_obj_type,in_width,in_height,statsStatus,curObjSNI,moveOnClicked )
{
	if (typeof console === "object" ) { console.log("Inside SNI.Community.Widgets.showThis") }
	// PICKLE-2765 - starts
	if( moveOnClicked == undefined || !SNI.Community.Widgets.isOverlayAvailable ){
		SNI.Community.Widgets.hideOverlayDivs();
	}
	// PICKLE-2765 - end
	
	
	//var p = prompt("Test","Pos :"+in_pos+", objTYpe :"+in_obj_type+", width :"+in_width+", Height :"+in_height+", status :"+statsStatus+", curObj"+curObjSNI );
	var adDelay = SNI.Community.Widgets.trim(document.getElementById("gAdDelay").value);
	var userTagDisplay = SNI.Community.Widgets.trim(document.getElementById("gUserTagDisplay").value);
	SNI.Community.Widgets.renderHidenIframe();
	SNI.Community.Widgets.posI = in_pos;
	var newCaption='';
	var newText='';
	var newTags = '';
	var newProducer = '';
	var myObjColl = SNI.Community.Widgets.getElementsByClassName('jcarousel-pageimg');
	
    SNI.Community.Widgets.restAll();
    		
	var carouselMaxRec = document.getElementById("txtCarouselMaxRec").value;
	
	try{	
	SNI.Community.Widgets.fireEvent(myObjColl[0].childNodes[Math.floor( parseInt(in_pos)/parseInt(carouselMaxRec) )],'click');
	}catch(e){}
	
	SNI.Community.Widgets.count++;
	if(SNI.Community.Widgets.count==parseInt(adDelay))
	{
		SNI.Community.Widgets.count = 0;
		var randomnumber=Math.floor(Math.random()*100000)
		if(SNI.Community.Widgets.overallCount!=0)
		{
			try{
					var url =  "";
					var isBigBoxReq = true;
					
					if( SNI.Community.Widgets.isFirstItemLoad ){
						isBigBoxReq = true;
					}else if( SNI.Community.Widgets.interstitialAdEnabled 
						 		&& typeof(SNI.DynamicAds) != 'undefined' ){
						 isBigBoxReq = false;
					}
					
					
					/*
					*  Big Box Ad setting
					*/
					if( isBigBoxReq ){
						url = VideoPlayerAd("BIGBOX", "", 5);
						if(url.indexOf("ORD=")!=-1)
						{
						   var part1 = url.substring(0,url.indexOf("ORD="));
						   var part2 = url.substring(url.indexOf("ORD="),url.length);
						   part2 = part2.substring(part2.indexOf("&")+1,part2.length);
						   url = part1+part2;
						}
						url += "&ord=" + randomnumber;
						try{
							setDartEnterpriseBanner("BIGBOX", url);
						}catch(e){
						    document.getElementById('bigbox').innerHTML = "<iframe border=0 style='overflow-x:hidden;overflow-y:hidden;overflow:-moz-scrollbars-none;x-hidden; padding: 0px; margin: 0px;' height='260px' width='310px' frameborder='0' ALLOWTRANSPARENCY='true' src='"+url+"'>";
						}

					}
					   
					   
					/*
					* Leader Board ad setting
					*/
					
					randomnumber=Math.floor(Math.random()*100000);
					url = VideoPlayerAd("LEADERBOARD", "", 1);
					if(url.indexOf("ORD=")!=-1)
					{
					   var part1 = url.substring(0,url.indexOf("ORD="));
					   var part2 = url.substring(url.indexOf("ORD="),url.length);
					   part2 = part2.substring(part2.indexOf("&")+1,part2.length);
					   url = part1+part2;
					}
					url += "&ord=" + randomnumber;
					try{
						setDartEnterpriseBanner("LEADERBOARD", url);
					}catch(e){
						document.getElementById('cgp-lb-ad').innerHTML = "<iframe border=0 style='overflow-x:hidden;overflow-y:hidden;overflow:-moz-scrollbars-none;x-hidden; padding: 0px; margin: 0px;' height='90px' width='728px' frameborder='0' ALLOWTRANSPARENCY='true' src='"+url+"'>";
					}
					
				}catch(e){}
		}
		
	}
	
	in_width = in_width!=''?in_width:'0';
	in_height = in_height!=''?in_height:'0';
	//alert('Val '+in_width+' ,Index :'+in_width.indexOf('.')+' , New Str');
	if(in_width.indexOf('.')!=-1){
		in_width = in_width.substring(0,in_width.indexOf('.')); 
	}
	
	if(in_height.indexOf('.')!=-1){
		in_height = in_height.substring(0,in_height.indexOf('.'));
	}
	
	SNI.Community.Widgets.selectedId = objIdArr[in_pos];
	SNI.Community.Toolbox.cSelectedId = SNI.Community.Widgets.selectedId;
	//Pickle 2313---Changes starts here
	//alert("test"+document.getElementById("laytype").value);
	if((document.getElementById("laytype").value == "top") && (in_pos == 0)){
		var prevLink = document.getElementById("prevLink");
		prevLink.style.display = "none";
	}
	///Fix End here
	var commPageNumber = "1";
	if(document.getElementById("gCommentsPageNumber")){
		commPageNumber = document.getElementById("gCommentsPageNumber").value;	
		if( isNaN(commPageNumber) ){
			commPageNumber = 1;
		}else if( parseInt(commPageNumber)<0 ){
			commPageNumber = 1;
		}
	}
	
	//PICKLE-427 - commented out below two line
	//Fix starts here
	var commentPagenoParameter = SNI.Community.Widgets.getParameter("cpageno");

	if( isNaN(commentPagenoParameter) || (commentPagenoParameter==null) || (commentPagenoParameter=="null") || (commentPagenoParameter=="") ){
		commPageNumber = 1;	
	} else if(  parseInt(commentPagenoParameter)<0 ){
		commPageNumber = 1;
	}else{
		commPageNumber = parseInt(commentPagenoParameter);
	}
	// Fix ends here
					
	SNI.Community.Widgets.objType = in_obj_type;
	SNI.Community.Widgets.objWidth = in_width;
	SNI.Community.Widgets.objHeight = in_height;
	 document.getElementById('carousel_'+SNI.Community.Widgets.selectedId).className='thumb-nav-thumb-on';
	 //Pickle 2313---Changes starts here
	 if((document.getElementById("laytype").value == "top") && (in_pos == 0)){
		var prevLink = document.getElementById("prevLink");
		prevLink.style.display = "none";
	}else {
		var prevLink = document.getElementById("prevLink");
		prevLink.style.display = "block";
	}
	
	$("#cgp-id-page-image-image").fadeOut(250, function(){
	
	//Pickle 2313---Changes Ends here

	//try{
	if(in_obj_type != "VIDEO"){
		if($("#laytype").val() == "top" && $("#topHor").val()=="true")
		{
			if(unescape(objArr[in_pos]).indexOf("_topmed1_vert")!=-1){
				if( moveOnClicked == undefined || !SNI.Community.Widgets.isOverlayAvailable ) {
					$("#cgp-id-page-image-image").html("<div style=\"width=:"+objWidthArr[in_pos]+"px; height:"+objHeightArr[in_pos]+"px;display:none;\" class=\"endFrameImageOverlay\"></div><div class=\"expanImage\"><span>Enlarge Photo</span></div>"+unescape(objArr[in_pos]));				
				} else {
					$("#cgp-id-page-image-image").html("<div style=\"width=:"+objWidthArr[in_pos]+"px; height:"+objHeightArr[in_pos]+"px;display:block;\" class=\"endFrameImageOverlay\"></div><div class=\"expanImage\"><span>Enlarge Photo</span></div>"+unescape(objArr[in_pos]));				
				}
			}else{
				if( moveOnClicked == undefined || !SNI.Community.Widgets.isOverlayAvailable ) {
					$("#cgp-id-page-image-image").html("<div style=\"width:"+objWidthArr[in_pos]+"px; height:"+objHeightArr[in_pos]+"px;display:none;\" class=\"endFrameImageOverlay\"></div>"+unescape(objArr[in_pos]));
				} else {
					$("#cgp-id-page-image-image").html("<div style=\"width:"+objWidthArr[in_pos]+"px; height:"+objHeightArr[in_pos]+"px;display:block;\" class=\"endFrameImageOverlay\"></div>"+unescape(objArr[in_pos]));
				}
			}		
			$(".expanImage").unbind("click");
			$(".expanImage").bind("click", SNI.Community.Widgets.expandImg);
		}else{
		try{			
				if( $("#laytype").val() == "top" && parseInt(objWidthArr[in_pos]) > 588 || parseInt(objHeightArr[in_pos]) > 441 && in_obj_type != "VIDEO" ){
					var rto = (300*objAspectRatio[SNI.Community.Widgets.posI]);
					objArr[in_pos] = objArr[in_pos].replace(/VAL/g,"width:300px;height:"+rto+"px;");
					$("#cgp-id-page-image-image").html("<div style=\"width:300px; height:"+rto+":px;display:none;\" class=\"endFrameImageOverlay\"></div><div class=\"expanImage\"><span>Enlarge Photo</span></div>"+unescape(objArr[in_pos]));					
					$(".expanImage").unbind("click");
					$(".expanImage").bind("click", SNI.Community.Widgets.actImg);			
				}else{
					objArr[in_pos] = objArr[in_pos].replace(/VAL/g,"");
					document.getElementById('cgp-id-page-image-image').innerHTML = unescape(objArr[in_pos]);
				}
			}catch(e){
				objArr[in_pos] = objArr[in_pos].replace(/VAL/g,"");
					document.getElementById('cgp-id-page-image-image').innerHTML = unescape(objArr[in_pos]);
			}
		}
		try{			
			$("#imgTop"+SNI.Community.Widgets.posI).unbind("load");
			$("#imgTop"+SNI.Community.Widgets.posI).bind("load", function () { SNI.Community.Widgets.alignButtons(); });
		}catch(e){}
	}else{
		$("#cgp-id-page-image-image").removeAttr('style')
		$("#cgp-id-page-image-image").html(unescape(objArr[in_pos]));
	}
	});
	$("#cgp-id-page-image-image").fadeIn(250);
		try{
		//document.title = SNI.Community.pageTitle;
		}catch(e){}
		var imgTxt = unescape(objTextArr[in_pos]);
		newCaption = unescape(objCaptionArr[in_pos]);
		newText = unescape(objTextArr[in_pos]);
		newTags = unescape(objTagArr[in_pos]);
		newProducer = unescape(objProducerArr[in_pos]);
		SNI.Community.Widgets.currentTxtRec = in_pos;
		if (typeof console === "object" ) { console.log(" itemListCount "+document.getElementById("gItemListCount").value) }
		// PICKLE-2437
		var itemListCount = document.getElementById("gItemListCount").value;
		if( parseInt(in_pos) == (parseInt(itemListCount)-1)  && SNI.Community.Widgets.ovPos != -1 ) {
			SNI.Community.Widgets.ovPos = parseInt(itemListCount)-1;
		}
		//Changes Ends here
	
		/*
		if(navigator.appName.indexOf('Microsoft')!=-1){
			imgTxt=SNI.Community.Widgets.replaceAll(imgTxt,"&apos;","'")
		}
		*/
		
		if( SNI.Community.Widgets.trim( navigator.appName ) != 'Netscape' ){
			imgTxt=SNI.Community.Widgets.replaceAll(imgTxt,"\\n","<br>");		
		}
		
		imgTxt=SNI.Community.Widgets.replaceAll(imgTxt,"&apos;","'");		
		
		imgTxt=SNI.Community.Widgets.replaceAll(imgTxt,"&lt;","<");
		imgTxt=SNI.Community.Widgets.replaceAll(imgTxt,"&gt;",">");
		//document.getElementById('cgp-id-page-image-text').innerHTML = "<p>"+unescape(objTextArr[in_pos])+"</p>";
		
//Pickle -2304 changes starts here		
		if( SNI.Community.Widgets.isTopLayout )
		{			
			var headerIdText = $("#collection_description").html();   // Code Added for  Pickle-3013 issue
			if ( headerIdText == 'null' || headerIdText == "" || headerIdText == null) {
				$("#headerId").hide();
			} else {
				$("#headerId").show();
			}
			if ( itemListCount <= 5){	//Code added for Pickle-2716 issue			
				$('div.jcarousel-prev').hide();
				$('div.jcarousel-next').hide();
			}
			
			/*
			
			Changed display settings to be hidden by default in detailpage.jsp
			
			Now checking itemListCount for 2 items or above and displaying 
			carousel to prevent carousel from displaying and then disapearing when there is only one item.

			Tyler: PICKLE-2828 / PICKLE-3454			
			
			*/
			
			// Below code creates flashes when hiding, so handled in the JSP code itself
			/*if ( parseInt(itemListCount) == 1){			
				$('#photo-carousel').hide();				
			}*/
			
			/*var carouselObj = document.getElementById('rootUl');			
			if (typeof console === "object" ) { console.log(" carouselObj "+carouselObj) }
			if(carouselObj && itemListCount == 1){			 	
				carouselObj.style.display='none';
			}*/
			
			if((imgTxt == "" || imgTxt == 'null') && ($("#overSizeNoteId") || $("#noteId"))){			
				$("#overSizeNoteId").css('display', 'none');
				$("#noteId").css('display', 'none');
			}
			else{
				25182583
				$("#cgp-id-page-image-text").html("<p>"+imgTxt+"</p>");
				$("#cgp-id-page-image-text-ext").html("<p>"+imgTxt+"</p>");
				
				var photoNoteObj = document.getElementById('photoNoteTxtFlag');
				if(photoNoteObj){	
					photoNoteObj.value="YES";
				}
				setTimeout("SNI.Community.Widgets.setPhotoNotes()",1000);
				
		    }

		}else{
			
			if((imgTxt == "" || imgTxt == 'null') && $("#noteTitleId"))
			{			
				$("#noteTitleId").css('display', 'none'); 
				
			}else{
				$("#cgp-id-page-image-text").html("<p>"+imgTxt+"</p>");
				
				if($("#noteTitleId")){
					$("#noteTitleId").css('display', 'block');
				}
				$("#cgp-id-page-image-text").html("<p>"+imgTxt+"</p>");
		    }
		}
		
		//document.title = SNI.Community.pageTitle;


	    ///Changes Ends here
	    if(SNI.Community.Widgets.trim(imgTxt)!="null" && SNI.Community.Widgets.trim(imgTxt)!=""){
	    	//temp coment need to discuss with tyler
	    	if(document.getElementById('cgp-id-page-image'))
	    		document.getElementById('cgp-id-page-image').className = "cgp-id-page-image";
	    	SNI.Community.Widgets.displayOn('cgp-id-page-image-text');
	    }else{
	    	//temp coment need to discuss with tyler
	    	if(document.getElementById('cgp-id-page-image')) 
	    		document.getElementById('cgp-id-page-image').className = "cgp-id-page-image-wbg";
	    	SNI.Community.Widgets.displayOff('cgp-id-page-image-text');
	    }
		var colPhotoTag = "";
		var spanData = unescape(objTagArr[in_pos]);
		var colSpanData = document.getElementById('txtColTagSpan').value;
	
		//colSpanData=SNI.Community.Widgets.replaceAll(colSpanData,"\n","<br>")
		//imgTxt=SNI.Community.Widgets.replaceAll(imgTxt,"&apos;","'")'
		if(SNI.Community.Widgets.trim(colSpanData)=="null") colSpanData="";							
		if(SNI.Community.Widgets.trim(spanData)=="null" || SNI.Community.Widgets.trim(spanData)=="") spanData = "";
		colPhotoTag = colSpanData+spanData;
		
		if(navigator.appName.indexOf('Microsoft')!=-1){
		colSpanData=SNI.Community.Widgets.replaceAll(colSpanData,"&apos;","'");
		spanData=SNI.Community.Widgets.replaceAll(spanData,"&apos;","'")
		}
		/*
		if(document.getElementById('tagSpan')){
			if(SNI.Community.Widgets.trim(colSpanData)!=""){ 
				if(SNI.Community.Widgets.trim(spanData)=="")
					document.getElementById('tagSpan').innerHTML = colSpanData;
				else
					document.getElementById('tagSpan').innerHTML = colSpanData+",&nbsp;"+spanData;
			}	
			else{
				document.getElementById('tagSpan').innerHTML = spanData;
			}	
		}
		*/
		var totTagSize= document.getElementById('tagsLen').value;
		
		for(var t=0;t<totTagSize;t++){
			if(document.getElementById('tagSpan_'+t)){
				document.getElementById('tagSpan_'+t).style.display="none";
			}
		}
		if(document.getElementById('tagSpan_'+in_pos)){
			document.getElementById('tagSpan_'+in_pos).style.display="block";
		}
				
		if(userTagDisplay=="true"){
			if(document.getElementById('collPhotoTag')){
				if(SNI.Community.Widgets.trim(colPhotoTag)==""){
					document.getElementById('collPhotoTag').style.display='none';
				}else{
					document.getElementById('collPhotoTag').style.display='block';
				}
			}	
		}
		
		try{
			for(var t=0;t<totTagSize;t++){
					if($("#u_tag_"+t)){
						$("#u_tag_"+t).hide();
					}
				}
			$("#u_tag_"+in_pos).show();	
			//Pickle -2281 issue
			if(document.getElementById('collPhotoTag')){			
				if(SNI.Community.Widgets.trim(colPhotoTag)==""){
					document.getElementById('collPhotoTag').style.display='none';
				}else{
					document.getElementById('collPhotoTag').style.display='block';
				}
			}	
		//Changes End here		 
		}catch(e){}
		
		document.getElementById('counterCurrentTxt').vaue = in_pos;
		var maxRecVal = document.getElementById('counterMaxTxt').value;
		//Code Move to cp_commenting.js
		if(document.getElementById('counth2') && SNI.Community.Toolbox.cIsCommentEnabled != true )
			document.getElementById('counth2').innerHTML = (parseInt(in_pos)+1)+" of "+maxRecVal;
			
		counterText = ( parseInt(in_pos)+1 )+" of "+maxRecVal;
		
		SNI.Community.Toolbox.cGlobalCounterText = counterText;
		
		if(SNI.Community.Toolbox.cIsCommentEnabled)
			SNI.Community.Widgets.moveToPageInternal(commPageNumber); //Load comments
		
		//document.getElementById('count-container').style.display='block';	
		//setTimeout("document.getElementById('count-container').style.display='none'",5000);
		try{
			//JEE - Adding - this was not getting reached in RMS
			SNI.Community.Widgets.imageUrl = document.getElementById('imgTop'+in_pos).src;
		}catch(e){}
		
		
		var sObjectId = document.getElementById('sObjectId'+in_pos).value;
			
		SNI.Community.Widgets.inAppItemId = sObjectId;
	
		SNI.Community.Widgets.checkItemFlag($('#gObjId').val()); // PICKLE-3002 -  Old Parameter SNI.Community.Widgets.inAppItemId
		
		if(statsStatus==true){
			var sCollectionId = document.getElementById('sCollectionId'+in_pos).value;					
			var sWId = document.getElementById('sWId'+in_pos).value;
			var sFromUrl = document.getElementById('sFromUrl'+in_pos).value;
			var sIpAddress = document.getElementById('sIpAddress'+in_pos).value;
			var sObjType = document.getElementById('sObjType'+in_pos).value;
			
			SNI.Community.Widgets.stats(sCollectionId,sObjectId,sWId,sFromUrl,'',sIpAddress,'0','2','1',sObjType);
		}
	//alert('before track');	
	if(SNI.Community.Widgets.overallCount != 0){
		try{
			//alert('inside track');
			SNI.Community.Widgets.doDynOmni(sObjectId); // To Track the Click Event As per Leo's requirement
			}catch(e){SNI.Community.Widgets.globalErr = e.message;}
	}
	try{	
		SNI.Community.childObjectCaption =newCaption;
	    SNI.Community.childObjectId=SNI.Community.Widgets.selectedId;
	    SNI.Community.childObjectType=SNI.Community.Widgets.objType;
	    SNI.Community.childObjectProducer=newProducer;
	    SNI.Community.childObjectTags=newTags;
	    SNI.Community.childObjectDescription=newText;
	    
	    if(curObjSNI==undefined){
	    	curObjSNI = document.getElementById('carousel_'+SNI.Community.Widgets.selectedId)
	    }
	    
		//SNI.Community.t.ActionTrack(curObjSNI,'SLIDESHOWCLICK_WITHAD',SNI.Community.childObjectCaption);
		
	    //alert("SNI.Community.childObjectCaption :"+SNI.Community.childObjectCaption+",SNI.Community.childObjectId :"+SNI.Community.childObjectId+",SNI.Community.childObjectType :"+SNI.Community.childObjectType);
	    //alert("SNI.Community.childObjectProducer :"+SNI.Community.childObjectProducer+",SNI.Community.childObjectTags :"+SNI.Community.childObjectTags+",SNI.Community.childObjectDescription :"+SNI.Community.childObjectDescription);				
		
	}catch(e){}
	
	SNI.Community.Widgets.overallCount++;
	
	SNI.Community.Widgets.descRedaMore('cgp-id-page-image-text',imgTxt,456);
	
	if (typeof console === "object" ) { console.log("SNI.Community.Widgets.interstitialAdEnabled :"+SNI.Community.Widgets.interstitialAdEnabled+" , SNI.Community.Widgets.isFirstItemLoad :"+SNI.Community.Widgets.isFirstItemLoad+" , SNI.Community.Widgets.isOverlayAvailable :"+SNI.Community.Widgets.isOverlayAvailable) }
		
	if( SNI.Community.Widgets.interstitialAdEnabled ){
		if( typeof(SNI.DynamicAds) != 'undefined' 
			&& !SNI.Community.Widgets.isFirstItemLoad 
			&& !SNI.Community.Widgets.isOverlayAvailable){
								
				var returnvalads = SNI.DynamicAds.refresh(inter_wrap);	
				//If the call to "refresh" returns true, an interstitial ad is about to be shown
				//alert( returnvalads );
				if(returnvalads)
				{
					
					if (typeof console === "object" ) { console.log("returnvalads is true") }
					
					//Push left and right buttons used to paginate through the photos out to the side
					//<IMPLEMENT BUTTON CSS CHANGE HERE TO PUSH BUTTONS OUT >
					setTimeout("SNI.Community.Widgets.placeNextPrevButtonCSS()",1500);
					
				}
				
		}
		
	}
	
	
	SNI.Community.Widgets.isFirstItemLoad = false;
	SNI.Community.Widgets.mainContentHTML = $("#cgp-id-page-image-image").html();
}

SNI.Community.Widgets.placeNextPrevButtonCSS = function(){

		if( $(".interWrapParent").find( '.close' ).html() != null ) {
			$('.img_pre').addClass('moveOut');
			$('.img_next').addClass('moveOut');
		}
		
		//Attach an event to the mousedown of the "Continue to Next Photo" link
		//We can't attach to the click event or that would override the interstitial ads code.
		$(".interWrapParent").find( '.close' ).live("mousedown", function(event) {
			if (typeof console === "object" ) { console.log("attaching mousedown event to continue link") }
			//Pull left and right buttons used to paginate through the photos in from the side
			//<IMPLEMENT BUTTON CSS CHANGE HERE TO PULL BUTTONS IN >
			$('.img_pre').removeClass('moveOut');
			$('.img_next').removeClass('moveOut');
		});

}

SNI.Community.Widgets.globalErr;

SNI.Community.Widgets.doDynOmni= function(itemId){	
			if (mdManager.getParameterString("oUrl") == "") {
				mdManager.setParameter("oUrl", mdManager.getParameterString("Url"))
			}
			mdManager.setParameter("Url", mdManager.getParameter("oUrl")+"&ht=" + parseInt(itemId));
			mdManager.setParameter("UniqueId", mdManager.getParameterString("UniqueId").replace(/(.*?)-([0-9]{1,2})$/, "$1-"+itemId));
//			alert('doDynOmni track');
			//alert(typeof s);
			if (typeof s == "object") { s.t();}
			return;
		}

//Carousel related code end

SNI.Community.Widgets.checkItemFlag = function(itemId){
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;

	var a = null;
	
	if( ur=="true" ){
		a = ""+SNI.Community.Widgets.Get_Cookie('pickle_item_inapp_'+itemId+"_"+document.getElementById('loggedInUserId').value);
	}else{
		a = ""+SNI.Community.Widgets.Get_Cookie('pickle_item_inapp_'+itemId);
	}
	
	/*
	if(userLogin=="true" && ur=="true"){
		a = ""+SNI.Community.Widgets.Get_Cookie('pickle_collection_inapp');
	}else{
		a = ""+SNI.Community.Widgets.Get_Cookie('pickle_collection_inapp');
	}
	*/
		
	//if( a!=null && SNI.Community.Widgets.trim(a)!= "null" && SNI.Community.Widgets.trim(a).search(itemId)!=-1)
	if(a!=null && SNI.Community.Widgets.trim(a)!= "null")
	{
		if(document.getElementById('flag_link')){
			var obj = document.getElementById('flag_link');
			obj.parentNode.innerHTML = "<img src='"+gAjaxUrl+"/skins/main/images/dot.gif' border='0' id='tbflag-on'> <span  class='flaggedThis'>Flagged</span>";
		}	
	
	}else{
		obj = document.getElementById('objFlag');
		if(obj){
			if(ur=="true"){
				obj.innerHTML = "<a id='flag_link' href=\"javascript:SNI.Community.Widgets.secureFlag();\"><img src=\""+gAjaxUrl+"/skins/main/images/dot.gif\" border=\"0\" id=\"tbflag-off\"/></a> <a id='flag_href' href=\"javascript:SNI.Community.Widgets.secureFlag();\">Flag</a>";
			}else{
				obj.innerHTML = "<a id='flag_link' href=\"javascript:SNI.Community.Widgets.showConfirm();\"><img src=\""+gAjaxUrl+"/skins/main/images/dot.gif\" border=\"0\" id=\"tbflag-off\"/></a> <a id='flag_href' href=\"javascript:SNI.Community.Widgets.showConfirm();\">Flag</a>";
			}
		}
	}
}

SNI.Community.Widgets.ismaxlength = function(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength){
	obj.value=obj.value.substring(0,mlength)
		obj.scrollLeft = obj.scrollWidth;
		obj.scrollTop = obj.scrollHeight;
	}
}

SNI.Community.Widgets.numberFormat = function(nStr,prefix){
	var prefix = prefix || '';
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1))
	 			x1 = x1.replace(rgx, '$1' + ',' + '$2');
	
	return prefix + x1 + x2;
}

SNI.Community.Widgets.temp1;

SNI.Community.Widgets.secureCommentFlag = function(objId){
	SNI.Community.Widgets.temp1 = objId;
	secureComponent("SNI.Community.Widgets.flagComments()","YOU NEED TO BE SIGNED IN TO DO THAT.","cmt_usr_img_"+objId,7);
}

SNI.Community.Widgets.flagComments = function(){
	SNI.Community.Widgets.displayOn('cgp-flyout-'+SNI.Community.Widgets.temp1);
	document.getElementById("comment_flag_reason_error_"+SNI.Community.Widgets.temp1).innerHTML = "";
	SNI.Community.Widgets.displayOff("comment_flag_reason_error_"+SNI.Community.Widgets.temp1);
}

SNI.Community.Widgets.flagComment = function(){
	SNI.Community.Widgets.displayOn('cgp-flyout-'+SNI.Community.Widgets.temp1);
	document.getElementById("comment_flag_reason_error_"+SNI.Community.Widgets.temp1).innerHTML = "";
	SNI.Community.Widgets.displayOff("comment_flag_reason_error_"+SNI.Community.Widgets.temp1);
}

SNI.Community.Widgets.removeSpecials = function(inputStr){
	var tmpRet = "";
	if(inputStr!=undefined){
		var pattern = "[^0-9 ^A-Z^a-z]";
		inputStr = inputStr.replace(pattern, "");
		inputStr = inputStr.replace(/ /g,"-");
		tmpRet = inputStr;
		tmpRet =  tmpRet.replace(/[^a-zA-Z 0-9]+/g,'');
		
		//tmpRet = escape(tmpRet);
	}
	return tmpRet;
}

SNI.Community.Widgets.replaceGtLt = function(symbol){
	symbol =symbol.replace(/>/g,'&gt;');                                           
       symbol =symbol.replace(/</g,'&lt;');
       return symbol;
}


SNI.Community.Widgets.stripHTML = function(testString){ 	
	testString=testString.replace("&lt;b&gt;","<b>");
	testString=testString.replace("&lt;/b&gt;","</b>");
	testString=testString.replace("&lt;i&gt;","<i>");
	testString=testString.replace("&lt;/i&gt;","</i>");
	testString=testString.replace("&lt;u&gt;","<u>");
	testString=testString.replace("&lt;/u&gt;","</u>");
	testString=testString.replace("&lt;a href=","<a href=");
	testString=testString.replace("\"&gt;",">");
	testString=testString.replace("&lt;/a&gt;","</a>");
	testString=testString.replace("&lt;br&gt;","<br>");
	testString=testString.replace("&lt;p&gt;","<p>");

	return testString;  
} 

SNI.Community.Widgets.ie=document.all
SNI.Community.Widgets.ns6=document.getElementById&&!document.all

SNI.Community.Widgets.total = 0;;
if(document.getElementById("gItemListCount")){
	SNI.Community.Widgets.total = parseInt( document.getElementById("gItemListCount").value ) +1 ;
} 
SNI.Community.Widgets.nowat = 0;

SNI.Community.Widgets.switchToThis = function(nowat){
	SNI.Community.Widgets.hideAll();
	document.getElementById('main_img'+nowat).style.display = "block";
	document.getElementById('main_img_text'+nowat).style.display = "block";
	document.getElementById('countstatus').innerHTML = (nowat+1) +" of "+ SNI.Community.Widgets.total;
	
	if(nowat==0)
		document.getElementById('prev_txt').innerHTML = "&nbsp;";
	else
		document.getElementById('prev_txt').innerHTML = "<a href='javascript:SNI.Community.Widgets.switchToThis("+(nowat-1)+")'>&laquo; Previous</a>";
	
	if(nowat<(SNI.Community.Widgets.total-1))
		document.getElementById('nxt_txt').innerHTML = "<a href='javascript:SNI.Community.Widgets.switchToThis("+(nowat+1)+")'>Next &raquo;</a>";
	else
		document.getElementById('nxt_txt').innerHTML = "&nbsp;";
		
}

SNI.Community.Widgets.hideAll = function(){
	for(i=0;i<SNI.Community.Widgets.total;i++){
		document.getElementById('main_img'+i).style.display = "none";
		document.getElementById('main_img_text'+i).style.display = "none";
	}
}

SNI.Community.Widgets.counterMove = function(from,fromStatus){
	var maxCount = 4;
	var curRec = document.getElementById('counterCurrentTxt').value;
	var maxRec = document.getElementById('counterMaxTxt').value;
	var tmpCurRec = parseInt(curRec)>0?curRec-1:0;
	var tmpMaxRec = parseInt(maxRec)>0?parseInt(maxRec):0;
	maxRec = parseInt(maxRec)>0?parseInt(maxRec)-1:0;
	var loopMaxCount = 0;

	if(fromStatus){	
		if(from=="next"){
			if(curRec>=maxRec){
				curRec = 0;
				loopMaxCount =curRec>0?Math.round( (curRec-1)/maxCount ):0;
			}else{
				loopMaxCount =curRec>0?Math.round( (curRec-1)/maxCount ):0;
				curRec = parseInt(curRec)+1;
			}
		}	
		else{
			if(curRec==0){
				curRec = maxRec;
				loopMaxCount =curRec>0?Math.round( (curRec+1)/maxCount ):0;
				//loopMaxCount =curRec>0? ((curRec+1)%maxCount ):0;
				loopMaxCount = loopMaxCount>0?loopMaxCount-1:loopMaxCount;
			}else{						
				curRec = (parseInt(curRec)>0?(parseInt(curRec)-1):0);
				loopMaxCount =curRec>0?Math.round( (curRec+1)/maxCount ):0;
				//loopMaxCount =curRec>0? ((curRec+1)%maxCount ):0;
				loopMaxCount = loopMaxCount>0?loopMaxCount-1:loopMaxCount;
			}	
		}	
		
		if(curRec>=0 && curRec<=maxRec){
			SNI.Community.Widgets.showThis(curRec,'',0,0,true);
			document.getElementById('counterCurrentTxt').value = curRec;
		}
	}	

	//SNI.Community.Widgets.switchToThis_New(loopMaxCount);
	//switchToThis_Carousel(parseInt(loopMaxCount)+1);
	//globalPrevNextPos = parseInt(loopMaxCount)+1;
	//prevNextStatus(from);
	return curRec;
}

SNI.Community.Widgets.findPosX = function(obj){
	 var curleft = 0
	 if (obj.offsetParent){
		  while (obj.offsetParent){
			   curleft += obj.offsetLeft
			   obj = obj.offsetParent
		  }
	 }
	 else if (obj.x)
	 	 curleft += obj.x
	 return curleft
}

SNI.Community.Widgets.findPosY = function(obj)
{
	 var curtop = 0
	 if (obj.offsetParent){
		  while (obj.offsetParent){
			   curtop += obj.offsetTop
			   obj = obj.offsetParent
		  }
	 }
	 else if (obj.y)
	  	curtop += obj.y
	 return curtop
}

SNI.Community.Widgets.switchToThis_New = function(nowat){
	var loopMaxCount = document.getElementById("gLoopMaxCount").value;
	var max = loopMaxCount;
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	try{
		for(i=0;i<=parseInt(max);i++){
			document.getElementById('pip_'+i).src = gAjaxUrl+"/skins/main/images/spaces/pipoff.gif";
		}
		document.getElementById('pip_'+nowat).src = gAjaxUrl+"/skins/main/images/spaces/pipon.gif";
	}catch(e){}
	SNI.Community.Widgets.currentTxtRec = document.getElementById('counterCurrentTxt').vaue;
	//document.getElementById('counterCurrentTxt').vaue="0";
	SNI.Community.Widgets.hideAll_New();
	var maxCount = 4;
	var tmpCount=0;
	var tmpnowat = nowat*maxCount;
	//alert('SNI.Community.Widgets.total :'+SNI.Community.Widgets.total+' ,tmpnowat '+tmpnowat);
	var pgNum = Math.ceil((SNI.Community.Widgets.total-1)/maxCount);
	for(var i=tmpnowat;i<=(SNI.Community.Widgets.total-1);i++){
		if(tmpCount<maxCount){
			try{
				document.getElementById('thumb-nav-thumb'+i).style.display = "block";
			}catch(e){}	
			tmpCount++;
		}	
		if(tmpCount==maxCount)
			break;
	}
	
	if(nowat==0){
		document.getElementById('img-thumb-nav-left').src = gAjaxUrl+"/skins/main/images/spaces/left.gif";
		document.getElementById('img-thumb-nav-left').onclick="";
		document.getElementById('img-thumb-nav-left').style.cursor = "";
	}	
	else{
		document.getElementById('img-thumb-nav-left').src = gAjaxUrl+"/skins/main/images/spaces/pink_left.gif";
		document.getElementById('img-thumb-nav-left').style.cursor = "pointer";
		document.getElementById('img-thumb-nav-left').onclick=new Function("SNI.Community.Widgets.switchToThis_New("+(nowat-1)+");");
	}	
	
	if(nowat<(pgNum-1)){
		document.getElementById('img-thumb-nav-right').src = gAjaxUrl+"/skins/main/images/spaces/right.gif";
		document.getElementById('img-thumb-nav-right').style.cursor = "pointer";
		document.getElementById('img-thumb-nav-right').onclick=new Function("SNI.Community.Widgets.switchToThis_New("+(nowat+1)+");");
	}	
	else{
		document.getElementById('img-thumb-nav-right').src = gAjaxUrl+"/skins/main/images/spaces/white_right.gif";
		document.getElementById('img-thumb-nav-right').onclick="";
		document.getElementById('img-thumb-nav-right').style.cursor = "";
	}	
}

SNI.Community.Widgets.hideAll_New = function(){
	for(var i=0;i<=SNI.Community.Widgets.total;i++){
		try{
		document.getElementById('thumb-nav-thumb'+i).style.display = "none";
		}catch(e){}
	}
}

SNI.Community.Widgets.select_star = function(obj){
	var len = parseInt(obj.id);
	//alert('len :'+len)
	var rating=len;
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	
	document.getElementById('rating_text_container').innerHTML = obj.title;
	for(i=1;i<=parseInt(len);i++){
		document.getElementById(''+i).src =  gAjaxUrl+"/skins/main/images/spaces/blip-on.gif";
	}
	for(i=parseInt(len)+1;i<=5;i++){
		document.getElementById(''+i).src =  gAjaxUrl+"/skins/main/images/spaces/blip-off.gif";
	}	
}

SNI.Community.Widgets.select_star_css = function(curId){
	var len = parseInt(curId);
	var rating=len;
	//document.getElementById('rating_text_container').innerHTML = obj.title;
	for(i=1;i<=parseInt(len);i++){
		if(document.getElementById('ratingstar_'+i))
			document.getElementById('ratingstar_'+i).className = "cgp-ratestar-rated";
	}
	for(i=parseInt(len)+1;i<=5;i++){
		if(document.getElementById('ratingstar_'+i))
			document.getElementById('ratingstar_'+i).className = "cgp-ratestar-rated-logout";
	}	
}

SNI.Community.Widgets.show = function(objId){
	if(document.getElementById(objId)){ 
		document.getElementById(objId).style.visibility = "visible";
	}
}

SNI.Community.Widgets.hide = function(objId){
	if(document.getElementById(objId)){ 
		document.getElementById(objId).style.visibility = "hidden";
	}	
}

SNI.Community.Widgets.ratingUnderProcess = false;

SNI.Community.Widgets.userRateStatus = false;

SNI.Community.Widgets.submitrating = function(itemid,rating_val) {

	var ratingText1 = ""; 
	if(document.getElementById("gRatingText1"))
		ratingText1 = document.getElementById("gRatingText1").value;
	
	var ratingText2 = ""; 
	if(document.getElementById("gRatingText2"))
		ratingText2 = document.getElementById("gRatingText2").value;
		
	var ratingText3 = "";
	if(document.getElementById("gRatingText3")) 
		ratingText3 = document.getElementById("gRatingText3").value;
		
	var ratingText4 = ""; 
	if(document.getElementById("gRatingText4"))
		ratingText4 = document.getElementById("gRatingText4").value;
	var ratingText5 = "";
	if(document.getElementById("gRatingText5")) 
		ratingText5 = document.getElementById("gRatingText5").value;
		

	if(document.getElementById("ispv")){
		SNI.Community.Widgets.isPVProject = true;
	} 

	var pv = SNI.Community.Widgets.isPVProject;
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	var origProjectId = SNI.Community.Widgets.trim( document.getElementById("gOrigProjectId").value );
	var logUserId = document.getElementById("gUserId").value;
	var userRateStatusText = SNI.Community.Widgets.trim( document.getElementById("gRateStatus").value );
	if(userRateStatusText!="" && userRateStatusText=="true"){
		SNI.Community.Widgets.userRateStatus = true;
	}else{
		SNI.Community.Widgets.userRateStatus = false;
	}
	
	if(SNI.Community.Widgets.ratingUnderProcess)
		return;
	else
		SNI.Community.Widgets.ratingUnderProcess = true;
	
	var exRated = document.getElementById('rateHead').innerHTML;
	
	if(SNI.Community.Widgets.userRateStatus){
		return;
	}	

	var sURL = unescape(window.location);
	
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	var url= "";
	if(ur=="true"){
		/* JAMES TO FIX - NEEDS TO ADD IN USER_ID PARAM IF loggedUserVO IS NOT NULL */	
		if( userLogin!="" && userLogin=="true" ){
			//url=baseUrl+'rateobject.do?objId='+itemid+'&rating='+rating_val+'&userid='+logUserId+'&d2curl='+escape(window.location)+"&wpid="+origProjectId+"&pv="+pv+"&nameused="+SNI.Community.Toolbox.cWidgetNameUsedInApp+"&wid="+SNI.Community.Toolbox.cWidgetId+"&oc="+escape(document.getElementById("objCaption_h1").innerHTML);
			url=baseUrl+'rateobject.do?objId='+itemid+'&rating='+rating_val+'&d2curl='+escape(window.location)+"&wpid="+origProjectId+"&pv="+pv+"&nameused="+SNI.Community.Toolbox.cWidgetNameUsedInApp+"&wid="+SNI.Community.Toolbox.cWidgetId+"&oc="+escape(document.getElementById("objCaption_h1").innerHTML);
		}else{
			url=baseUrl+'rateobject.do?objId='+itemid+'&rating='+rating_val+"&pv="+pv+"&nameused="+SNI.Community.Toolbox.cWidgetNameUsedInApp+"&wid="+SNI.Community.Toolbox.cWidgetId;
		}
	}else{
		url=baseUrl+'rateobjectnonur.do?objId='+itemid+'&rating='+rating_val+'&d2curl='+escape(window.location)+"&pv="+pv+"&nameused="+SNI.Community.Toolbox.cWidgetNameUsedInApp+"&wid="+SNI.Community.Toolbox.cWidgetId;
	}
	
	SNI.Community.Widgets.displayOff('rating-stars-content');
	SNI.Community.Widgets.displayOn('rating-stars-loading-content');
	
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200)
			{
				SNI.Community.Widgets.displayOn('rating-stars-content');
				SNI.Community.Widgets.displayOff('rating-stars-loading-content');
			
				//SNI.Community.Widgets.displayOff('rate');
				//SNI.Community.Widgets.rateLayerOnOff('on');
				var no_of_rating = request.responseXML.getElementsByTagName('nofratings');
				var cumulative = request.responseXML.getElementsByTagName('ratingscumulative');
				var final_rating1 = request.responseXML.getElementsByTagName('showrate');
				//var final_rating = parseInt(cumulative.item(0).firstChild.nodeValue)/parseInt(no_of_rating.item(0).firstChild.nodeValue);
				var innerhtml = "";
				var final_rating = Math.round( parseFloat(final_rating1.item(0).firstChild.nodeValue) );
				var ratingClass = "top-info-right-a-rating0";
				for(i=1;i<6;i++)
				{
					if(final_rating>=i)
					{
						ratingClass = "top-info-right-a-rating"+i;
						
						//if(document.getElementById('unrated'))
							//document.getElementById('unrated').innerHTML="";
						
						if(document.getElementById('unrated')){
							
							if(final_rating<2){
								
								document.getElementById('unrated').innerHTML=ratingText1;
							}
							else if(final_rating<3){
								
								document.getElementById('unrated').innerHTML=ratingText2;
							}
							else if(final_rating<4){
								
								document.getElementById('unrated').innerHTML=ratingText3;
							}
							else if(final_rating<5){
								
								document.getElementById('unrated').innerHTML=ratingText4;
							}
							else if(final_rating<6){
									
								document.getElementById('unrated').innerHTML=ratingText5;
							}
						}							
											
						if(userLogin=="" && userLogin=="false" && ur=="true"){
							document.location = document.location+"";
						}			
					}
				}
				
				document.getElementById('rateHead').innerHTML = "YOU RATED:";
				SNI.Community.Widgets.userRateStatus = true;
				document.getElementById('cgp-ratings-message').innerHTML = "Ratings: "+no_of_rating.item(0).firstChild.nodeValue;
				document.getElementById('cgp-ratings-message-hidden').value = "Ratings: "+no_of_rating.item(0).firstChild.nodeValue;
				
				document.getElementById('avg_rating').innerHTML = SNI.Community.Widgets.roundNumber( parseFloat(final_rating1.item(0).firstChild.nodeValue),1);//Math.round(final_rating*10)/10;
				SNI.Community.Widgets.handleRated();		
				SNI.Community.Widgets.setratingscookie(itemid+"///"+rating_val);
				SNI.Community.Widgets.select_star_css(parseInt(rating_val));						
				//window.location.href = sURL;
			}
			else if(request.status==500){
				SNI.Community.Widgets.displayOn('rating-stars-content');
				SNI.Community.Widgets.displayOff('rating-stars-loading-content');
				alert("You found an opportunity for improvement! Please try again later");
			}	
			else{
				SNI.Community.Widgets.displayOn('rating-stars-content');
				SNI.Community.Widgets.displayOff('rating-stars-loading-content');
				alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
			}	
		}
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send('');
}

SNI.Community.Widgets.gotoEdit = function(){
	
	var ratingText1 = ""; 
	if(document.getElementById("gRatingText1"))
		ratingText1 = document.getElementById("gRatingText1").value;
	
	var ratingText2 = ""; 
	if(document.getElementById("gRatingText2"))
		ratingText2 = document.getElementById("gRatingText2").value;
		
	var ratingText3 = "";
	if(document.getElementById("gRatingText3")) 
		ratingText3 = document.getElementById("gRatingText3").value;
		
	var ratingText4 = ""; 
	if(document.getElementById("gRatingText4"))
		ratingText4 = document.getElementById("gRatingText4").value;
	var ratingText5 = "";
	if(document.getElementById("gRatingText5")) 
		ratingText5 = document.getElementById("gRatingText5").value;
	
	//var rateval=document.getElementById('ratingText').innerHTML;
	var rateval=document.getElementById("gRatingToShow").value;
	var rating = document.getElementById("gRating").value;
	var idParam = document.getElementById("gIdParam").value;
	var editUrl = document.getElementById("gEditUrl").value; 
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	
	var rate="";
	if(rateval!=''){
		rate=rateval;
	}
	else{
	
		if(rating<2.0){
			rate=ratingText1 ;
		} 
		else if(rating<3.0) {
			rate=ratingText2 ;
		}
		else if(rating<4.0) {
			rate=ratingText3 ;
		} 
		else if(rating<5.0) {
			rate=ratingText4;
		}
		else if(rating<6.0) {			
			rate=ratingText5 ;
		} 
	}
	
	location.href=editUrl+"?goto=editcollection&"+idParam+"="+gObjId+"&rate="+rate;
}

SNI.Community.Widgets.submitvotes = function(itemid,favStatus) {

	if(document.getElementById("ispv")){
		SNI.Community.Widgets.isPVProject = true;
	} 

	var pv = SNI.Community.Widgets.isPVProject;

	var obj = document.getElementById('vote_link');
	//var objOvly = document.getElementById('vote_link_ovly');
	var objOvly = document.getElementById('fav_link_ovly');
	var ie=document.all;
	var userId;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var origProjectId = document.getElementById("gOrigProjectId").value;
	var logUserId = document.getElementById("gUserId").value;
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	
	try{
		if(userLogin!="" && userLogin=="true"){
			//var url= baseUrl+'voteobject.do?objId='+itemid+'&favstatus='+favStatus+'&wpid='+origProjectId+'&userid='+logUserId+'&d2curl='+escape(window.location)+"&oc="+document.getElementById("objCaption_h1").innerHTML+"&pv="+pv+"&wid="+SNI.Community.Toolbox.cWidgetId;
			var url= baseUrl+'voteobject.do?objId='+itemid+'&favstatus='+favStatus+'&wpid='+origProjectId+'&d2curl='+escape(window.location)+"&oc="+document.getElementById("objCaption_h1").innerHTML+"&pv="+pv+"&wid="+SNI.Community.Toolbox.cWidgetId;
		}else{
			if(SNI.Community.Widgets.Get_Cookie('AJAX_LOGIN_RESPONSE'))
				{
				   userId = SNI.Community.Widgets.Get_Cookie('AJAX_LOGIN_RESPONSE').split("||")[0];
				}else{
					userId = SNI.Community.Widgets.Get_Cookie('picklecookie').split(",")[0];
				}
			//var url= baseUrl+'voteobject.do?objId='+itemid+'&favstatus='+favStatus+'&wpid='+origProjectId+'&userid='+userId+'&d2curl='+escape(window.location)+"&pv="+pv+"&wid="+SNI.Community.Toolbox.cWidgetId;
			var url= baseUrl+'voteobject.do?objId='+itemid+'&favstatus='+favStatus+'&wpid='+origProjectId+'&d2curl='+escape(window.location)+"&pv="+pv+"&wid="+SNI.Community.Toolbox.cWidgetId;
		}
	}catch(e){}
	
	SNI.Community.Widgets.toolsLoading('vote_link');	
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200)
			{
				//alert('res :'+request.responseText);
				var no_of_votes = request.responseXML.getElementsByTagName('nofvotes');			
				if(favStatus=="removefav"){

					SNI.Community.Widgets.Delete_Cookie('pickle_votes', '/', '');
					obj.parentNode.innerHTML ="<a id='vote_link' href=\"#\" onclick=\"SNI.Community.Widgets.securefavorite('addfav');SNI.Community.t.ActionTrack(this,'FAVORITE');return false;\"><img src=\""+gAjaxUrl+"/skins/main/images/dot.gif\" border=\"0\" id=\"tbf-off\"/></a> <a href=\"#\" id=\"fav_link\" onclick=\"SNI.Community.Widgets.securefavorite('addfav');SNI.Community.t.ActionTrack(this,'FAVORITE');return false;\">Favorite</a>";
					//$("#vote_link").removeClass("fa spinner");				
					//var unfav = document.getElementById('vote_link').className = "fa active";					
					if(objOvly)
						objOvly.parentNode.innerHTML =" <a href=\"#\" id=\"fav_link_ovly\" onclick=\"SNI.Community.Widgets.securefavorite('addfav');SNI.Community.t.ActionTrack(this,'FAVORITE');SNI.Community.Widgets.closeOtherSpaces();return false;\">Favorite</a>";								
				}else{

					SNI.Community.Widgets.setvotescookie(itemid);
					obj.parentNode.innerHTML ="<a id='vote_link' href=\"#\" onclick=\"SNI.Community.Widgets.securefavorite('removefav');return false;\"><img src=\""+gAjaxUrl+"/skins/main/images/dot.gif\" border=\"0\" id=\"tbf-on\"/></a> <a href=\"#\" id=\"fav_link\" onclick=\"SNI.Community.Widgets.securefavorite('removefav');return false;\">Unfavorite</a>";								
					//obj.parentNode.innerHTML ="<a href=\"#\" id=\"fav_link\" onclick=\"SNI.Community.Widgets.securefavorite('removefav');return false;\">Unfavorite</a>";
					if(objOvly)
						objOvly.parentNode.innerHTML ="<a href=\"#\" id=\"fav_link_ovly\" onclick=\"SNI.Community.Widgets.securefavorite('removefav');SNI.Community.Widgets.closeOtherSpaces();return false;\">Unfavorite</a>";
				}
				if(userLogin=="" && userLogin=="false"){
					document.location = document.location+"";
				}	
			}
			else if(request.status==500){
				if(SNI.Community.Widgets.idTextChange){
					SNI.Community.Widgets.displayOn('vote_link');
					document.getElementById(curId).innerHTML = SNI.Community.Widgets.existValue;
				}
			
				alert("You found an opportunity for improvement! Please try again later");
			}	
			else{
				if(SNI.Community.Widgets.idTextChange){
					if(curId=="fav_link"){
						SNI.Community.Widgets.displayOn('vote_link');
					}
					document.getElementById(curId).innerHTML = SNI.Community.Widgets.existValue;
				}
			
				alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
			}	
		}
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send('');
}

SNI.Community.Widgets.idTextChange = false;
SNI.Community.Widgets.existValue = "";

SNI.Community.Widgets.toolsLoading = function(curId){
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	
	if(curId!="" && curId!=undefined){
		SNI.Community.Widgets.idTextChange = true;
		SNI.Community.Widgets.existValue = document.getElementById(curId).innerHTML;
	} 
	
	if(SNI.Community.Widgets.idTextChange){
		//alert('pa :'+document.getElementById(curId).parentNode.id);
		//var parObj = document.getElementById(curId).parentNode.id;
	
		//alert('parObj Width:'+parObj.offsetWidth);
	
		if(curId=="fav_link"){
			SNI.Community.Widgets.displayOff('vote_link');
		}else if(curId=="flag_href"){
			SNI.Community.Widgets.displayOff('flag_link');
		}else if (curId=="ol_favorites") { //Added this if condition for Pickle 2744 issue
			document.getElementById(curId).innerHTML = "<img src='"+gAjaxUrl+"/skins/main/images/rmr/loader.gif'/>";  //"loading";
		}
		if(curId!="ol_favorites"){ //Added this if condition for Pickle 2744 issue
		document.getElementById(curId).innerHTML = "<img src='"+gAjaxUrl+"/skins/main/images/account/dot.gif' id='small_loading'/>";  //"loading";
		}
	}

}	

SNI.Community.Widgets.roundNumber = function(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	var tmpNum = num+"";
	if(tmpNum.indexOf(".")!=-1){
		if(tmpNum.indexOf(".0")!=-1){
			tmpNum = tmpNum.substring(0,tmpNum.indexOf(".0"));
			result = tmpNum+".0";
		}
	}else{
		result = tmpNum+".0";
	}
	return result;
}	

SNI.Community.Widgets.handleSpecialChars = function(input){
	input = input.replace(/%/g,"%25");
	//input = input.replace(/\$/gi,"%24");
	input = input.replace(/&/g,"%26");
	input = input.replace(/\?/gi,"%3F");
	input = input.replace(/`/gi,"%60");
	
	input = input.replace(/~/g,"%7E");
	input = input.replace(/!/g,"%21");
	input = input.replace(/#/g,"%23");
	
	input = input.replace(/\^/g,"%5E");
	input = input.replace(/\(/g,"%28");
	input = input.replace(/\)/g,"%29");
	return input;
}

/* Given code move to shell page
function flagAsInappropriate(id,flagType,obj,commentsId)
{
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	var gCurObjId = document.getElementById("gCurObjId").value;
	var channelId =  document.getElementById("gChannelId").value;
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	var idParam = document.getElementById("gIdParam").value;
	var parentIdParam = document.getElementById("gParentIdParam").value;
	var ajaxBaseAdmin =  document.getElementById("gAjaxBaseAdminUrl").value;
	var channelIdParam = document.getElementById("gChannelIdParam").value;
	var userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
			 
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	//obj = document.getElementById(obj);
	var comments = "";
	var caption = "";
	var uploadBy = "";
	var description = "";
	var uploadbyurl = "";
	var modId = id;
	var d2cLink = window.location.href;
	d2cLink = d2cLink.replace(/#/g, "");
	d2cLink += "&cObjId="+inAppItemId;
	
	
	if(commentsId!='null'){
		comments = document.getElementById(commentsId).innerHTML;
		comments = comments.replace('<div>','');
		comments = comments.replace('</div>','');
	}	

	caption = document.getElementById('objCaption_h1').innerHTML;
	uploadBy = document.getElementById('objHrefUploadBy').innerHTML;
	if(document.getElementById('pObjDescription')){
		description = document.getElementById('pObjDescription').innerHTML;
	}	
	uploadbyurl = document.getElementById('objHrefUploadBy').href;
	var inAppCid = gObjId;
	var inAppOid = gCurObjId; 
	var ipAppChannelId = channelId;
	
	if(flagType != "comments")
	{
		id = inAppItemId;
		inAppOid = inAppItemId;
	}			
	var url= baseUrl+"flagasinappropriate.do";
	
	var params = "id="+id+"&obj_type="+flagType;

	params += "&d2c_link="+escape(d2cLink);
	if(flagType != "comments")
		params += "&moderationurl="+escape(gAjaxUrl+"/moderation.do?"+idParam+"="+inAppCid+"&statusId=1&objectType=collection&flag="+flagType+"&"+parentIdParam+"="+inAppCid+"&ht="+SNI.Community.Widgets.selectedId+"&ajaxUrl="+baseUrl);				
	else	
		params += "&moderationurl="+escape(gAjaxUrl+"/moderation.do?"+idParam+"="+id+"&statusId=1&objectType=pva&flag="+flagType+"&"+parentIdParam+"="+inAppCid+"&ht="+SNI.Community.Widgets.selectedId+"&ajaxUrl="+baseUrl);
	params += "&inappropriateurl="+escape(ajaxBaseAdmin+"/loada3_p2.do?"+channelIdParam+"="+ipAppChannelId+"&"+parentIdParam+"="+inAppCid+"&objectid="+inAppOid);
	params += "&comments="+escape(comments)+"&caption="+escape(caption)+"&uploadBy="+escape(uploadBy)+"&description="+escape(description);
	params += "&imageUrl="+escape(imageUrl);
	params += "&userprofilelink="+escape(uploadbyurl);
	
	
	
	if(flagType=="comments"){
		
	}else{
		SNI.Community.Widgets.toolsLoading('flag_href');
	}
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200 ||request.status==12152)
			{
				if(flagType == "comments")
				{
					obj = document.getElementById(obj);
					SNI.Community.Widgets.setPickleCookie("pickle_comments_inapp",id);
					obj.parentNode.innerHTML = " Flagged";
				}
				else
				{
					SNI.Community.Widgets.setPickleCookie("pickle_collection_inapp",id);							
					obj = document.getElementById('flag_link'); 							
					obj.parentNode.innerHTML = "<img src=\""+gAjaxUrl+"/skins/main/images/dot.gif\" border=\"0\" id=\"tbflag-on\"/> <span>Flagged</span>";
					
					//document.getElementById('collection_inapp').innerHTML = "You Flagged this !!";
				}
				if(userLogin=="false" && ur=="true"){
					document.location = document.location+"";
				}	
				//obj.innerHTML = "You flagged this item as inappropriate"
				//obj.onclick = "";
			}
			else if(request.status==500){
				if(flagType != "comments")
					document.getElementById('flag_link').innerHTML = "Flag";
				alert("You found an opportunity for improvement! Please try again later");
			}	
			else{
				if(flagType != "comments")
					document.getElementById('flag_link').innerHTML = "Flag";
				alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
			}	
		}
	}
	
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.send(params);
}
*/

SNI.Community.Widgets.emfPosition = function(){
	 //var posLeft = SNI.Community.Widgets.findPosX(document.getElementById('pre-button-container'));
	 //document.getElementById('cgp-id-emf-window').style.left =posLeft+"px"; 
}
SNI.Community.Widgets.globalCountEMF = 0;
SNI.Community.Widgets.loadEMFContent = function(){
	 //SNI.Community.Widgets.emfPosition();
	 //cgp-pre-next-count
	 var captchaImageUrl = SNI.Community.Widgets.captchaUrl+Math.floor(Math.random()*999);
	 if(SNI.Community.Widgets.globalCountEMF==0){
		 try{	
		 		if( SNI.Community.Widgets.isCaptchaEnabled ){
			 		var captcha = "<div id='emf-content04' class='clrfix'>";
			 		captcha += "<div id='emf-label'><p><label id='captcha_lbl'>Enter the characters shown in the image to verify that you are, in fact, human.</label></p></div>";
			 		//captcha div started
			 		captcha += "<div id='up-ur-code-a'><div id='up-text-field'><div id='up-inner-text-field'>"; 
			 		captcha += "<input type='text' name='secretcode' id='up-create-captcha' class='up-create-email'>"
			 		captcha += "</div></div></div>";
			 		
			 		captcha += "<div id='up-ur-code-b'>";
			 		captcha += "<img id='captchaImg' src='' style='width: 91px; height:28px;'>";
			 		captcha += "</div>";
			 		
			 		//Captcha div ended   
			 		captcha += "</div>"; 
			 		
			 		captcha += "<div id='up-clear'></div>";
			 		
					$('#cgp-newedit-new-space-upload-button').before(captcha);
		 		
		 		}
				
				document.getElementById('txtEmfContent').value =escape(document.getElementById('cgp-id-emf-middle-container').innerHTML);
				document.getElementById('txtEmfTitleContent').value = escape("<div id='cgp-id-emf-title'>"+document.getElementById('cgp-id-emf-title').innerHTML+"</div>");
				document.getElementById('txtButtonContent').value = escape(document.getElementById('cgp-newedit-new-space-upload-button').innerHTML);
			}catch(e){}
	}
		
	SNI.Community.Widgets.globalCountEMF++;
	document.getElementById('cgp-id-emf-middle-container').innerHTML = "";
	//document.getElementById("emf-error-msg").innerHTML = "All fields are required.";
	//document.getElementById("emf-error-msg").className = "emf-req-information";
	document.getElementById('cgp-id-emf-middle-container').innerHTML = unescape(document.getElementById('txtEmfContent').value);
	 
	if( SNI.Community.Widgets.isCaptchaEnabled ){
		$('#captchaImg').attr('src', captchaImageUrl);
	}
}

SNI.Community.Widgets.emailToFriend = function(){
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	var fromEmail = document.getElementById('fromEmail_txt').value;	
	var fromName = document.getElementById('fromName_txt').value;
	var toEmail = document.getElementById('toEmail_txt').value;
	
	var emailSubject = document.getElementById('gEmailSubjectHeader').value;
	var footerText = document.getElementById('gFooterText').value;
	var gWid= document.getElementById("gWid").value;
	var emailAddressText = SNI.Community.Widgets.trim(document.getElementById("gEmailAddressText").value);
	var emailRecipientAddressText = SNI.Community.Widgets.trim( document.getElementById("gEmailRecipientAddressText").value );	
		
	var mailSubject = 'test';//document.getElementById('mailSubject').value;//document.getElementById('objCaption_h1').innerHTML;
	var mailMessage = document.getElementById('mailMessage_txta').value;
	var objCaption = "";
	try{
		objCaption = document.getElementById('objCaption_h1').innerHTML;
	}catch(e){objCaption = $('.title').html();}
	var widgeReferenceName = document.getElementById("gReferenceName").value;;
	var skinPath = document.getElementById("gAjaxUrl").value;
	var fromMailLabel = document.getElementById('emf-label-left').innerHTML;
	var emf_colId = document.getElementById('emf_colId').value;
	toEmail = toEmail.replace(/;/g,",");
	var fromAddressLabel = "";
	var d2cLink = window.location.href;
	//d2cLink = d2cLink.replace(/#/g, "");
	d2cLink = d2cLink.replace(/#/g, "%23");
	
	if(document.getElementById("ispv")){
		SNI.Community.Widgets.isPVProject = true;
	} 
	
	var pv = SNI.Community.Widgets.isPVProject;
		
	if(SNI.Community.Widgets.isPVProject){
		SNI.Community.Widgets.inAppItemId = document.getElementById("gObjId").value;
		SNI.Community.Widgets.imageUrl = document.getElementById('imgTop0').src; 
	}else{ 
		if(SNI.Community.Widgets.inAppItemId!=0)
			d2cLink += "&cObjId="+SNI.Community.Widgets.inAppItemId;
	}	
	
	document.getElementById('fromEmail_lbl').className = "";
	document.getElementById('fromName_lbl').className = "";
	document.getElementById('toEmail_lbl').className = "";
	document.getElementById('mailSubject_lbl').className = "";
	document.getElementById('mailMessage_lbl').className = "";
	
	document.getElementById("emf-error-msg").innerHTML = "";
	
	var emailCheck = SNI.Community.Widgets.isEmail(document.getElementById('fromEmail_txt'));
	var toEmailCheck = SNI.Community.Widgets.isEmailToken(document.getElementById('toEmail_txt'));
	
	if(SNI.Community.Widgets.trim(fromName)==''){
		document.getElementById("emf-error-msg").innerHTML = "Please enter your name in the "+document.getElementById('fromName_lbl').innerHTML+" field.";
		document.getElementById("emf-error-msg").className = "emf-error-information"; 
		document.getElementById('fromName_lbl').className = "error-field";
		return;
	}else if(SNI.Community.Widgets.trim(fromEmail)=='' || emailCheck==true){
		document.getElementById('fromEmail_lbl').className = "error-field";
		if(SNI.Community.Widgets.trim(fromMailLabel)=="Your email"){
			var tmpText = "Please enter a valid e-mail address in the ";
			if(emailAddressText==""){
				tmpText += "Your e-mail field.";
			}else{
				tmpText += emailAddressText+" field."
			}
			document.getElementById("emf-error-msg").innerHTML = tmpText;
			document.getElementById("emf-error-msg").className = "emf-error-information";
		}	
		else{
			var tmpText = "Please enter a valid e-mail address in the ";
			if(emailAddressText==""){
				tmpText += "Your E-mail Address field.";
			}else{
				tmpText += emailAddressText+" field."
			}
			
			document.getElementById("emf-error-msg").innerHTML = tmpText;
			document.getElementById("emf-error-msg").className = "emf-error-information";
		}		
		return;
	}
	else if(SNI.Community.Widgets.trim(toEmail)=='' || toEmailCheck==true){
		document.getElementById('toEmail_lbl').className = "error-field";
		document.getElementById("emf-error-msg").innerHTML = "Please enter a valid e-mail address in the "+emailRecipientAddressText+" field.";
		document.getElementById("emf-error-msg").className = "emf-error-information"; 
		return;
	}else if(SNI.Community.Widgets.trim(mailSubject)==''){
		document.getElementById('mailSubject_lbl').className = "error-field";
		document.getElementById("emf-error-msg").innerHTML = "Please enter a subject in the "+document.getElementById('mailSubject_lbl').innerHTML+" field.";
		document.getElementById("emf-error-msg").className = "emf-error-information"; 
		return;
	}else if(SNI.Community.Widgets.trim(mailMessage)==''){
		document.getElementById('mailMessage_lbl').className = "error-field";
		document.getElementById("emf-error-msg").innerHTML = "Please enter a message in the "+document.getElementById('mailMessage_lbl').innerHTML+" field.";
		document.getElementById("emf-error-msg").className = "emf-error-information"; 
		return;
	}
	
	mailSubject = escape(emailSubject);
	
	//mailMessage += footerText;
	
	//var url=baseUrl+"emailtofriend.do?cliptype="+escape(SNI.Community.Widgets.objType)+"&fromaddress="+escape(fromEmail);
	var url=baseUrl+"emailtofriend.do";
	
	var reqParameters = "cliptype="+escape(SNI.Community.Widgets.objType)+"&fromaddress="+escape(fromEmail);
	reqParameters += "&toaddress="+escape(toEmail)+"&emailsubject="+mailSubject+"&emailmessage="+escape(mailMessage)+"&imageurl="+escape(SNI.Community.Widgets.imageUrl);
	reqParameters += "&seturl="+escape(d2cLink)+"&imagewidth="+escape(SNI.Community.Widgets.objWidth)+"&imageheight="+escape(SNI.Community.Widgets.objHeight)+"&caption="+escape(objCaption);
	reqParameters += "&widrefname="+escape(widgeReferenceName)+"&skinpath="+escape(skinPath);
	reqParameters += "&wid="+gWid;
	reqParameters += "&sendername="+escape(fromName);
	reqParameters += "&colId="+emf_colId;
	reqParameters += "&photoId="+SNI.Community.Widgets.inAppItemId;
	reqParameters += "&pv="+pv;
	if( SNI.Community.Widgets.isCaptchaEnabled ){
		reqParameters += "&secretcode="+escape($("#up-create-captcha").val());
	}	

	SNI.Community.Widgets.displayOn('emf-loading');
	if (SNI.Community.Widgets.isIE6()){SNI.Community.Widgets.ie_heightfix('ieDiv5','220');}
	SNI.Community.Widgets.displayOff('emf-content');
	SNI.Community.Widgets.displayOff('emf-content01');
	//SNI.Community.Widgets.displayOff('emf-content02');
	SNI.Community.Widgets.displayOff('emf-content03');
	if( SNI.Community.Widgets.isCaptchaEnabled ){
		SNI.Community.Widgets.displayOff('emf-content04');
	}
	SNI.Community.Widgets.displayOff('cgp-newedit-new-space-upload-button');			
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200)
			{
				SNI.Community.Widgets.displayOff('emf-loading');
				if (SNI.Community.Widgets.isIE6()){SNI.Community.Widgets.ie_heightfix('ieDiv5','351');}
				SNI.Community.Widgets.displayOn('emf-content');
				SNI.Community.Widgets.displayOn('emf-content01');
				//SNI.Community.Widgets.displayOn('emf-content02');
				SNI.Community.Widgets.displayOn('emf-content03');
				if( SNI.Community.Widgets.isCaptchaEnabled ){
					SNI.Community.Widgets.displayOn('emf-content04');
				}
				SNI.Community.Widgets.displayOn('cgp-newedit-new-space-upload-button');
				var mailStatus = "";
				if(request.responseText!=""){
					mailStatus = request.responseXML.getElementsByTagName('mail_status');
				}
				if(mailStatus.length==0 || SNI.Community.Widgets.trim(mailStatus.item(0).firstChild.nodeValue)=="success" || SNI.Community.Widgets.trim(mailStatus)=="null"){
					document.getElementById('cgp-id-emf-middle-container').innerHTML = "";
					var titleContent = unescape(document.getElementById('txtEmfTitleContent').value);
					var bodyContent = "<div id='emf-content'>";
					bodyContent += "<div id=\"emf-messagesent-title\"><p>Success!</p></div>";
					bodyContent += "<div id=\"emf-messagesent-text\"><p>A link to <b>"+objCaption+"</b> has been sent.</p></div>";
					bodyContent += "<div style='clear: both;'></div>";
					bodyContent += "</div>";
					
					
					var buttonContent = '<div id="emf-close-cont">';
					buttonContent += '<span class="emf-close"><div id="cgp-nav">';
					buttonContent += '<ul id="widget-nav"><li id="widget-nav-item-off"/><a href="javascript:SNI.Community.Widgets.displayOff(\'cgp-id-emf-window\')"><em>Close</em></a></ul>';
					buttonContent += '</div></span><div style="clear: both;"></div>';
					buttonContent += '</div>';
					buttonContent += '<div style="clear: both;"></div>';
					 
					document.getElementById('cgp-id-emf-middle-container').innerHTML = titleContent+bodyContent+buttonContent;
					if (SNI.Community.Widgets.isIE6()){SNI.Community.Widgets.ie_heightfix('ieDiv5','124');}
				}
				else{
					SNI.Community.Widgets.displayOff('emf-loading');
					var statusResult = mailStatus.item(0).firstChild.nodeValue;
					if(statusResult.indexOf('from_field')!=-1){
						if(SNI.Community.Widgets.trim(fromMailLabel)=="Your email"){
							var tmpText = "Please enter a valid e-mail address in the ";
							if(emailAddressText==""){
								tmpText += "Your e-mail field.";
							}else{
								tmpText += emailAddressText+" field."
							}
							fromAddressLabel = tmpText;  
						}	
						else{
							var tmpText = "Please enter a valid e-mail address in the ";
							if(emailAddressText==""){
								tmpText += "Your E-mail Address field.";
							}else{
								tmpText += emailAddressText+" field."
							}
						
							fromAddressLabel =  tmpText;
						}		
						document.getElementById('fromEmail_lbl').className = "error-field";
						statusResult = fromAddressLabel;
					}else if( SNI.Community.Widgets.isCaptchaEnabled ){
						if(statusResult.indexOf('characters')!=-1){
							document.getElementById('captcha_lbl').className = "error-field";
							statusResult = "Please enter the characters shown in the image.";						
						}else if(statusResult.indexOf('timed out')!=-1){
							document.getElementById('captcha_lbl').className = "error-field";
							statusResult = "Your request has timed out. Please click <a href=\"javascript:void(0);\" onclick=\"SNI.Community.Widgets.loadEMFContent();\">here</a> to reload the captcha and try again.";					
						}
					}
					
					document.getElementById("emf-error-msg").innerHTML = unescape(statusResult);
					document.getElementById("emf-error-msg").className = "emf-error-information"; 
				}
			}
			else if(request.status==500){
				SNI.Community.Widgets.displayOn('emf-content');
				SNI.Community.Widgets.displayOn('emf-content01');
				//SNI.Community.Widgets.displayOn('emf-content02');
				SNI.Community.Widgets.displayOn('emf-content03');
				if( SNI.Community.Widgets.isCaptchaEnabled ){
					SNI.Community.Widgets.displayOn('emf-content04');
				}	
				SNI.Community.Widgets.displayOn('cgp-newedit-new-space-upload-button');
			
				SNI.Community.Widgets.displayOff('cgp-id-emf-window');
				SNI.Community.Widgets.displayOff('emf-loading');							
				//alert("You found an opportunity for improvement! Please try again later");
			}	
			else{
				SNI.Community.Widgets.displayOn('emf-content');
				SNI.Community.Widgets.displayOn('emf-content01');
				//SNI.Community.Widgets.displayOn('emf-content02');
				SNI.Community.Widgets.displayOn('emf-content03');
				if( SNI.Community.Widgets.isCaptchaEnabled ){
					SNI.Community.Widgets.displayOn('emf-content04');
				}
				SNI.Community.Widgets.displayOn('cgp-newedit-new-space-upload-button');
			
				SNI.Community.Widgets.displayOff('cgp-id-emf-window');			
				SNI.Community.Widgets.displayOff('emf-loading');				
				//alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
			}	
		}
	}	
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send(reqParameters);
}

SNI.Community.Widgets.isEmail = function(obj){
	var string = obj.value
	var emailerror=false;
	if (SNI.Community.Widgets.trim(string).search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
	{
		emailerror=false;
	}
	else
	{
		emailerror=true;
		//alert('Enter Valid User Name !!!');
		obj.focus();
		obj.select();
	}
	return emailerror;
}

SNI.Community.Widgets.isEmailToken = function(obj){
	var string = obj.value
	var emailerror=false;
	string = string.replace(/;/g,",");
	 //alert("string : "+string);
	var mailAddress = string.split(",");
	
	for(i=0;i<mailAddress.length;i++){
		if(SNI.Community.Widgets.trim(mailAddress[i])!=""){
			if (SNI.Community.Widgets.trim(mailAddress[i]).search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
			{
				emailerror=false;
			}
			else
			{
				emailerror=true;
				//alert('Enter Valid User Name !!!');
				obj.focus();
				obj.select();
				break;
			}
		}
	}			
	return emailerror;
}

SNI.Community.Widgets.stats = function(parObjId,objId,widId,fromUrl,country,fromIp,fuserid,entType,hitFromType,objFromType){
	//try{
		/*
		if(objFromType!="PHOTO"){
			if(entType=='2'){
				return;
			}
		}	
		*/
		var gAjaxUrl = document.getElementById("gAjaxUrl").value;
		var baseUrl = gAjaxUrl+"/";
		var previewMode = document.getElementById("gPreviewMode").value;		
		if(previewMode=='null' || previewMode==''){
			var ie=document.all;
			var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
			//var url=baseUrl+"pickleStats.do?pid="+parObjId+"&oid="+escape(objId)+"&wid="+escape(widId)+"&furl="+escape(fromUrl);
			var url=baseUrl+"pickleStats.do";
			var reqParameters = "pid="+parObjId+"&oid="+escape(objId)+"&wid="+escape(widId)+"&furl="+escape(fromUrl);
			reqParameters += "&ctry="+escape(country)+"&ip="+escape(fromIp)+"&fuid="+escape(fuserid)+"&et="+escape(entType)+"&hft="+escape(hitFromType);
			
			request.onreadystatechange=function()
			{
				if(request.readyState==4)
				{
					if(request.status==200)
					{
						 //alert('request.responseText :'+request.responseText);
					}
				}
			}
			request.open("POST",url,true);
			request.setRequestHeader("content-type","application/x-www-form-urlencoded");
			request.send(reqParameters);
		}	
	//}catch(e){}	
}

SNI.Community.Widgets.callBackSetLiWidth = function(){
	//var formObj = document.getElementById("ul");
	var nameArr = document.getElementsByTagName("li");
	for( var i=0;i<nameArr.length;i++){
		var obj = nameArr[i];
		var carClass = obj.className;
		if(carClass.indexOf("jcarousel-item")!=-1){
			obj.style.width = "83px";
			obj.style.height = "83px";
		}
	}
}	

SNI.Community.Widgets.ie_heightfix = function(inDiv, inState){document.getElementById(inDiv).style.height = inState+"px";}

SNI.Community.Widgets.isIE6 = function() {
	var appVer = navigator.appVersion;
	appVer = appVer.split(';');
	if(appVer[1] == ' MSIE 6.0') {
		return true;
	}				
}

//Overlay code start

SNI.Community.Widgets.testOverlay = function(){
	var containerIds = document.getElementById("gContainerIds").value;
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	var widgetProjectId = document.getElementById("gWidgetProjectId").value;
	var systemTagList = document.getElementById("gSystemTagListD2C").value;
	var ownerUserId = document.getElementById("gOwnerUserId").value;
	
	var rightPaneTpe = "usergallery";
	//var so = -1;
	//if(document.getElementById("rightPaneSO"))
		//so = document.getElementById("rightPaneSO").value;
	
	var so = 2;	

	// Get the pv_sort_ort cookie
	// if( SNI.Community.Widgets.Get_Cookie('pickle_pv_sort_order') != null ){
		// so = SNI.Community.Widgets.Get_Cookie('pickle_pv_sort_order');
	// }

	SNI.Community.Widgets.showOtherSpaces(containerIds,gObjId,'1',widgetProjectId,systemTagList,'catgallery',ownerUserId,so,'right');

	//if(document.getElementById("leftPaneSO"))
		//so = document.getElementById("leftPaneSO").value;
	if(document.getElementById("rightPaneShowType"))
		rightPaneTpe = document.getElementById("rightPaneShowType").value;
		
	//if(parseInt(so)!=-1)
		//ownerUserId = "-1";
	so = 2;		
	SNI.Community.Widgets.showOtherSpaces(containerIds,gObjId,'1',widgetProjectId,"",rightPaneTpe,ownerUserId,so,'left');

}

SNI.Community.Widgets.topLayoutD2COverlay = function(){

	/*
	var containerIds = document.getElementById("gContainerIds").value;
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	var widgetProjectId = document.getElementById("gWidgetProjectId").value;
	var systemTagList = document.getElementById("gSystemTagListD2C").value;
	var ownerUserId = document.getElementById("gOwnerUserId").value;
	var so = 2;
	var rightPaneTpe = "usergallery";
	
	document.getElementById("cContainer1").style.display = "none";
	document.getElementById("uContainer1").style.display = "none";
	
	SNI.Community.Widgets.displayOn('vr-loading_overlay');
	SNI.Community.Widgets.displayOn('vr-loading_overlay2');
		
	// Get the pv_sort_ort cookie
	// if( SNI.Community.Widgets.Get_Cookie('pickle_pv_sort_order') != null ){
		// so = SNI.Community.Widgets.Get_Cookie('pickle_pv_sort_order');
	// }
	
	SNI.Community.Widgets.showTophatOtherSpaces(containerIds,gObjId,'1',widgetProjectId,systemTagList,'catgallery',ownerUserId,so,'right');

	if(document.getElementById("rightPaneShowType"))
		rightPaneTpe = document.getElementById("rightPaneShowType").value;
	
	// Always most recents sort order ( PICKLE-2216 )
	so = 2;
	SNI.Community.Widgets.showTophatOtherSpaces(containerIds,gObjId,'1',widgetProjectId,"",rightPaneTpe,ownerUserId,so,'left');

	*/
	
	
	var containerIds = $("#gContainerIds").val();
	var gObjId = $("#gObjId").val();
	var widgetProjectId = $("#gWidgetProjectId").val();
	var systemTagList = $("#gSystemTagListD2C").val();
	var ownerUserId = $("#gOwnerUserId").val();
	
	var so = 2;
	var rightPaneTpe = "usergallery";
	
	$("#cContainer1").css('display', 'none');
	$("#uContainer1").css('display', 'none'); 
	
	$(".endFrameImageOverlay").css('display', 'block'); 
	SNI.Community.Widgets.displayOn('vr-loading_overlay');
	SNI.Community.Widgets.displayOn('vr-loading_overlay2');
	
	SNI.Community.Widgets.showTophatOtherSpaces(containerIds,gObjId,'1',widgetProjectId,systemTagList,'catgallery',ownerUserId,so,'right');

	if( document.getElementById("rightPaneShowType") )
		rightPaneTpe = document.getElementById("rightPaneShowType").value;

	so = 2;
	SNI.Community.Widgets.showTophatOtherSpaces(containerIds,gObjId,'1',widgetProjectId,"",rightPaneTpe,ownerUserId,so,'left');
}


SNI.Community.Widgets.overlayBacktoBegining = function(){
	SNI.Community.Widgets.closeOtherSpaces();

	var defaultWidth = SNI.Community.Widgets.trim(document.getElementById("gDefaultWidth").value);
	var defaultHeight = SNI.Community.Widgets.trim(document.getElementById("gDefaultHeight").value);

	var sObjType = "";	
		if(document.getElementById('sObjType'+SNI.Community.Widgets.posI)){
			sObjType = document.getElementById('sObjType'+SNI.Community.Widgets.posI).value;
		}	
	var curURL = document.location;	
	SNI.Community.Widgets.ovPos = 0;
	SNI.Community.Widgets.showThis(0,sObjType,defaultWidth,defaultHeight,true,curURL);
}

SNI.Community.Widgets.imgDivHeight = "0px";
SNI.Community.Widgets.closeOtherSpaces = function(){

	SNI.Community.Widgets.displayOff('cgp-d2c-over');
	SNI.Community.Widgets.displayOff('under-over');
	//document.getElementById('cgp-id-page-image-image').style.height = SNI.Community.Widgets.imgDivHeight+"px";
	document.getElementById('cgp-id-page-image-image').style.height ="auto";
	// cleaning the div on closing
	for (var i = 0 ; i < 2 ; i++) {
		var j=i+1;
		document.getElementById('userCapt'+j).innerHTML="";	
		document.getElementById('userView'+j).innerHTML="";
		document.getElementById('uImg'+j).innerHTML="";	
		document.getElementById('uRat'+j).innerHTML="";	
	}
	for (var i = 0 ; i < 2 ; i++) {
		var j=i+1;
		document.getElementById('catCap'+j).innerHTML="";	
		document.getElementById('catView'+j).innerHTML="";
		document.getElementById('cImg'+j).innerHTML="";	
		document.getElementById('cRat'+j).innerHTML="";	
	}	
	SNI.Community.Widgets.resetMainContent();
}

SNI.Community.Widgets.showOtherSpaces = function(channelId,objID,pageNo,wpId,categoryType,requestType,userId,so,type){

	//<![CDATA[
	var is_ie6 = (
		window.external &&
		typeof window.XMLHttpRequest == "undefined"
	);
	//]]>
	
   var gAjaxUrl = document.getElementById("gAjaxUrl").value;
   	
   SNI.Community.Widgets.imgDivHeight = document.getElementById('cgp-id-page-image-image').offsetHeight;
   //alert('SNI.Community.Widgets.imgDivHeight '+SNI.Community.Widgets.imgDivHeight);
  if( SNI.Community.Widgets.imgDivHeight < 335 )	{
    //alert('imgDivHeight1 '+SNI.Community.Widgets.imgDivHeight);
    document.getElementById('under-over').style.height = "335px";
   	document.getElementById('cgp-id-page-image-image').style.height = "335px";		 	 
   }
   else
   {
    //alert('imgDivHeight2 '+SNI.Community.Widgets.imgDivHeight);
   	document.getElementById('under-over').style.height = SNI.Community.Widgets.imgDivHeight+"px";
   }
   
   SNI.Community.Widgets.displayOn('cgp-d2c-over');
	SNI.Community.Widgets.displayOn('under-over');
    var pno=pageNo;
  
    if(requestType=="usergallery"){
  
	    if(pno<1){
	    pno=document.getElementById('utpno').value;
	    }
	    if(pno>document.getElementById('utpno').value){
	    pno=1;
	    }
    }
    if(requestType=="catgallery"){
   
	    if(pno<1){
	    pno=document.getElementById('gtpno').value;
	    }
	    if(pno>document.getElementById('gtpno').value){
	    pno=1;
	    }
    }
  	
    var rType=requestType;
    if(rType=="all"){

			for (var i = 0 ; i < 2 ; i++) {
				var j=i+1;
				document.getElementById('userCapt'+j).innerHTML="";	
				document.getElementById('userView'+j).innerHTML="";
				document.getElementById('uImg'+j).innerHTML="";	
				document.getElementById('uRat'+j).innerHTML="";	
			}
			
			for (var i = 0 ; i < 2 ; i++) {
			var j=i+1;
			document.getElementById('catCap'+j).innerHTML="";	
			document.getElementById('catView'+j).innerHTML="";
			document.getElementById('cImg'+j).innerHTML="";	
			document.getElementById('cRat'+j).innerHTML="";	
			}	
			
	document.getElementById('loadLeft').innerHTML="<div id=\"oct-loading-icon\"></div>";
	document.getElementById('loadRight').innerHTML="<div id=\"oct-loading-icon\"></div>";
	}
	// if(rType=="usergallery"){
	 if(type=="left"){
	 for (var i = 0 ; i < 2 ; i++) {
				var j=i+1;
				document.getElementById('userCapt'+j).innerHTML="";	
				document.getElementById('userView'+j).innerHTML="";
				document.getElementById('uImg'+j).innerHTML="";	
				document.getElementById('uRat'+j).innerHTML="";	
			}
	document.getElementById('loadLeft').innerHTML="<div id=\"oct-loading-icon\"></div>";
	}
	 //if(rType=="catgallery"){
	 if(type=="right"){
	for (var i = 0 ; i < 2 ; i++) {
			var j=i+1;
			document.getElementById('catCap'+j).innerHTML="";	
			document.getElementById('catView'+j).innerHTML="";
			document.getElementById('cImg'+j).innerHTML="";	
			document.getElementById('cRat'+j).innerHTML="";	
			}
	document.getElementById('loadRight').innerHTML="<div id=\"oct-loading-icon\"></div>";
	}
	
		var browL = document.location+"";
		
		
			if(browL.indexOf(":80/") == -1){
				gAjaxUrl = gAjaxUrl.replace(':80','');
			}
		
		
		var ie=document.all;
       	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
      	var url=gAjaxUrl+"/overlay.do?chl="+channelId+"&oid="+objID+"&pn="+pno+"&ct="+categoryType+"&wpid="+wpId+"&gt="+requestType+"&uid="+userId+"&so="+so+"&type="+type;
      //var t = prompt("test",url);
  		request.onreadystatechange=function()
		{
			if(request.readyState==4)
			{
				
				if(request.status==200)
				{
					 //if(rType=="usergallery")
					 if(type=="left")
					document.getElementById('loadLeft').innerHTML="";
					// if(rType=="catgallery")
					 if(type=="right")
					document.getElementById('loadRight').innerHTML="";
					SNI.Community.Widgets.resultText = ""+request.responseText;	
					
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"\n","")
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"\r","")	
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"&","&amp;")				
				    SNI.Community.Widgets.parseTextToXMLOverlay(SNI.Community.Widgets.resultText,"");
				    
				}
				else if(request.status==500){
					alert("You found an opportunity for improvement! Please try again later");
				}	
				else{
					alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
				}	
			}
		}

		request.open("POST",url,true);
		request.setRequestHeader("content-type","application/x-www-form-urlencoded");
		request.send('');
}

SNI.Community.Widgets.closeTophatOtherSpaces = function(){
	$(".endFrameImageOverlay").css('display', 'none'); 
	SNI.Community.Widgets.displayOff('moreCont_bg');
	SNI.Community.Widgets.displayOff('moreCont');
	SNI.Community.Widgets.resetMainContent();
}

SNI.Community.Widgets.toplayoutoverlayBacktoBegining = function(){
	SNI.Community.Widgets.closeTophatOtherSpaces();

	var defaultWidth = SNI.Community.Widgets.trim(document.getElementById("gDefaultWidth").value);
	var defaultHeight = SNI.Community.Widgets.trim(document.getElementById("gDefaultHeight").value);

	var sObjType = "";	
		if(document.getElementById('sObjType'+SNI.Community.Widgets.posI)){
			sObjType = document.getElementById('sObjType'+SNI.Community.Widgets.posI).value;
		}	
	var curURL = document.location;	
	SNI.Community.Widgets.ovPos = 0;
	SNI.Community.Widgets.showThis(0,sObjType,defaultWidth,defaultHeight,true,curURL);
}

SNI.Community.Widgets.showTophatOtherSpaces = function(channelId,objID,pageNo,wpId,categoryType,requestType,userId,so,type){
		
		SNI.Community.Widgets.displayOn('moreCont_bg');
		SNI.Community.Widgets.displayOn('moreCont');

		var pno=pageNo;
		var rType=requestType;
		var browL = document.location+"";
		var gAjaxUrl = document.getElementById("gAjaxUrl").value;

		if(browL.indexOf(":80/") != -1){
			gAjaxUrl = gAjaxUrl.replace(':80','');
		}
			
		var ie=document.all;
       	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
      	var url=gAjaxUrl+"/overlay.do?chl="+channelId+"&oid="+objID+"&pn="+pno+"&ct="+categoryType+"&wpid="+wpId+"&gt="+requestType+"&uid="+userId+"&so="+so+"&type="+type+"&lo=top";
      	
      	// var userSearchStr = SNI.Community.Widgets.Get_Cookie('pickle_pv_user_search');
      	var userSearchStr = '';
      	if( document.getElementById('gAjPVUsrSearchCookieValue') ){	
      		userSearchStr = document.getElementById('gAjPVUsrSearchCookieValue').value;
      	}
      	if( userSearchStr == 'null' || userSearchStr == null ){
			userSearchStr = '';
		} else {
			url += "&userSearchString="+userSearchStr;
		}			
      	
      	//var t = prompt("test",url);
  		request.onreadystatechange=function()
		{
			if(request.readyState==4)
			{
				
				if(request.status==200)
				{
					SNI.Community.Widgets.resultText = ""+request.responseText;	
					
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"\n","");
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"\r","");	
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"&","&amp;");
					if( requestType == 'catgallery' ) {
						SNI.Community.Widgets.displayOff('vr-loading_overlay');
					}
					if( requestType == 'usergallery' ){
						SNI.Community.Widgets.displayOff('vr-loading_overlay2');
					}
				    SNI.Community.Widgets.parseTextToXMLOverlayForTophat(SNI.Community.Widgets.resultText,"");
				    
				}
				else if(request.status==500){
					alert("You found an opportunity for improvement! Please try again later");
				}	
				else{
					// alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
				}	
			}
		}

		request.open("POST",url,true);
		request.setRequestHeader("content-type","application/x-www-form-urlencoded");
		request.send('');

}

SNI.Community.Widgets.removeMainContent = function(){
	if( document.getElementById("cgp-id-page-image-image") 
			&& SNI.Community.Widgets.objType.toUpperCase() == "VIDEO"){		
		$("#cgp-id-page-image-image").fadeOut(250, function(){
				$("#cgp-id-page-image-image").html("");
		});
	}
}

SNI.Community.Widgets.resetMainContent = function(){
	if( document.getElementById("cgp-id-page-image-image") 
			&& SNI.Community.Widgets.objType.toUpperCase() == "VIDEO"){
		$("#cgp-id-page-image-image").html(SNI.Community.Widgets.mainContentHTML);
		$("#cgp-id-page-image-image").fadeIn(250);
	}
}


SNI.Community.Widgets.uobjId; 
SNI.Community.Widgets.uimgURL; 
SNI.Community.Widgets.ucaption;
SNI.Community.Widgets.uratings;
SNI.Community.Widgets.uviews; 
SNI.Community.Widgets.ud2cUrl;
SNI.Community.Widgets.cobjId; 
SNI.Community.Widgets.cimgURL;
SNI.Community.Widgets.ccaption;
SNI.Community.Widgets.cratings;
SNI.Community.Widgets.cviews;
SNI.Community.Widgets.cd2cUrl;

SNI.Community.Widgets.parseTextToXMLOverlay = function(text,show){	
	
	var xmlDoc;
		if(SNI.Community.Widgets.ie){
	
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(text);
		}
		else if(SNI.Community.Widgets.ns6){
		    parser=new DOMParser();
		    xmlDoc=parser.parseFromString(text,"text/xml");
	    }

		var userGallery =xmlDoc.getElementsByTagName('usergallery')[0];
		var utype=xmlDoc.getElementsByTagName('type')[0].firstChild.nodeValue;
		var gAjaxUrl = document.getElementById("gAjaxUrl").value;
		var gBaseUrl = document.getElementById("gBaseUrl").value;
		
		//if(userGallery!=undefined){
		if(utype=="left"){
		
			var ucurPage = xmlDoc.getElementsByTagName('currentPage')[0].firstChild.nodeValue;
		
			document.getElementById('upno').value=ucurPage;
			var utotalPages = xmlDoc.getElementsByTagName('totalpages')[0].firstChild.nodeValue;
			document.getElementById('utpno').value=utotalPages;			
			var uitems = xmlDoc.getElementsByTagName("object");
			
			if((utotalPages==1)||(utotalPages<1)){
			
			document.getElementById('uPrevOff').style.display="block";
			document.getElementById('uNextOff').style.display="block";
			document.getElementById('uPrev').style.display="none";
			document.getElementById('uNext').style.display="none";
			}
			else{
			document.getElementById('uPrevOff').style.display="none";
			document.getElementById('uNextOff').style.display="none";
			document.getElementById('uPrev').style.display="block";
			document.getElementById('uNext').style.display="block";
			}
			
			if(ucurPage == utotalPages && utotalPages > 1 ){
				document.getElementById('uPrev').style.display="block";
				document.getElementById('uPrevOff').style.display="none";	
						
				document.getElementById('uNext').style.display="none";
				document.getElementById('uNextOff').style.display="block";
			}
			if( ucurPage == 1 && utotalPages > 1 ) {
				document.getElementById('uPrev').style.display="none";
				document.getElementById('uPrevOff').style.display="block";
				
				document.getElementById('uNext').style.display="block";
				document.getElementById('uNextOff').style.display="none";
			}
			
			SNI.Community.Widgets.uobjId = new Array();
			SNI.Community.Widgets.uimgURL  = new Array();
			SNI.Community.Widgets.ucaption  = new Array();
			SNI.Community.Widgets.uratings = new Array();
			SNI.Community.Widgets.uviews = new Array();
			SNI.Community.Widgets.ud2cUrl = new Array();
			
			for (var i = 0 ; i < uitems.length ; i++) {
			    var uitem = uitems[i];		
				SNI.Community.Widgets.uobjId[i] = uitem.getElementsByTagName("id")[0].firstChild.nodeValue;
				SNI.Community.Widgets.uimgURL[i] = uitem.getElementsByTagName("imgurl")[0].firstChild.nodeValue;
				SNI.Community.Widgets.ucaption[i] = uitem.getElementsByTagName("caption")[0].firstChild.nodeValue;
				SNI.Community.Widgets.uratings[i] = uitem.getElementsByTagName("rating")[0].firstChild.nodeValue;
				//Added SNI.Community.Widgets.numberWithCommas function for issue 2501
				SNI.Community.Widgets.uviews[i] = SNI.Community.Widgets.numberWithCommas(uitem.getElementsByTagName("views")[0].firstChild.nodeValue);
				//SNI.Community.Widgets.ud2cUrl[i] = uitem.getElementsByTagName("d2curl")[0].firstChild.nodeValue;
				SNI.Community.Widgets.ud2cUrl[i] = uitem.getElementsByTagName("taxonomy")[0].firstChild.nodeValue;
		   }
		  
		   for (var i = 0 ; i < 2 ; i++) {
				var j=i+1;
				document.getElementById('userCapt'+j).innerHTML="";	
				document.getElementById('userView'+j).innerHTML="";
				document.getElementById('uImg'+j).innerHTML="";	
				document.getElementById('uRat'+j).innerHTML="";	
			}

		if(utotalPages<1){
		document.getElementById('message').innerHTML="<p>This user hasn't uploaded anymore items yet.</p>";
		document.getElementById('message').style.display="block";
		}
		else{
		document.getElementById('message').innerHTML="";
		document.getElementById('message').style.display="none";
		}
		for (var i = 0 ; i < uitems.length ; i++) {
			
			
			var j=i+1;
			var uCapTxt = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.ucaption[i]," ","-");
			var usrDispTxt=SNI.Community.Widgets.ucaption[i];
			if(usrDispTxt.length>10){
			usrDispTxt=usrDispTxt.substring(0, 10);
			usrDispTxt=usrDispTxt+"...";
			}
			
			uCapTxt =  uCapTxt.replace(/[^a-zA-Z 0-9 \-]+/g,'');
			uCapTxt = uCapTxt.replace(/ /g,"-");
			
			//var uURL=gBaseUrl+"/"+SNI.Community.Widgets.ud2cUrl[i]+"/"+uCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.uobjId[i];
			var uURL = '';
			if(SNI.Community.Widgets.ud2cUrl[i]!='Other-Spaces')
				uURL=gBaseUrl+"/"+SNI.Community.Widgets.ud2cUrl[i]+"/"+uCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.uobjId[i];
			else
				uURL=gBaseUrl+"/"+uCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.uobjId[i];
				
			var uImgURL="";
			if(SNI.Community.Widgets.uimgURL[i].indexOf("http")==-1){
			uImgURL=gAjaxUrl+SNI.Community.Widgets.cimgURL[i];
			}
			else{

			uImgURL=SNI.Community.Widgets.uimgURL[i];
			}
						
			document.getElementById('userCapt'+j).innerHTML="<p><a href="+uURL+">"+usrDispTxt+"</a></p>";
			
			document.getElementById('userView'+j).innerHTML="<p>"+SNI.Community.Widgets.uviews[i]+" Views</p>";

			//document.getElementById('uImg'+j).innerHTML="<a href="+uURL+"><img  src="+SNI.Community.Widgets.uimgURL[i]+" border=\"0\"></a>";
			document.getElementById('uImg'+j).innerHTML="<a href="+uURL+"><img  src="+SNI.Community.Widgets.uimgURL[i]+" border=\"0\"></a>";
			var urate=SNI.Community.Widgets.uratings[i];
			
			var uStar="";
				for(var r=0;r<urate;r++){
					uStar+="<img src=\""+gAjaxUrl+"/skins/main/images/account/dot.gif\" width=\"11px\" height=\"10px\" id=\"star-on\">";
				}
			document.getElementById('uRat'+j).innerHTML=uStar;
		
		}		
		 
	}
	
	var catGallery=xmlDoc.getElementsByTagName('catgallery')[0];
	var ctype=xmlDoc.getElementsByTagName('type')[0].firstChild.nodeValue;
	//if(catGallery!=undefined){
	if(ctype=="right"){
		var gcurPage = catGallery.getElementsByTagName('currentPage')[0].firstChild.nodeValue;
		document.getElementById('gpno').value=gcurPage;
		var gtotalPages = catGallery.getElementsByTagName('totalpages')[0].firstChild.nodeValue;
		document.getElementById('gtpno').value=gtotalPages;
				
		if(gtotalPages==1){		
		document.getElementById('cPrevOff').style.display="block";
		document.getElementById('cNextOff').style.display="block";
		document.getElementById('cPrev').style.display="none";
		document.getElementById('cNext').style.display="none";
		}
		else{
		
		document.getElementById('cPrevOff').style.display="none";
		document.getElementById('cNextOff').style.display="none";
		document.getElementById('cPrev').style.display="block";
		document.getElementById('cNext').style.display="block";
		}
		
		if(gcurPage == gtotalPages && gtotalPages > 1 ){
			document.getElementById('cPrev').style.display="block";
			document.getElementById('cPrevOff').style.display="none";	
					
			document.getElementById('cNext').style.display="none";
			document.getElementById('cNextOff').style.display="block";
		}
		
		if( gcurPage == 1 && gtotalPages > 1  ) {
			document.getElementById('cPrev').style.display="none";
			document.getElementById('cPrevOff').style.display="block";
			
			document.getElementById('cNext').style.display="block";
			document.getElementById('cNextOff').style.display="none";
		}
		
		SNI.Community.Widgets.cobjId = new Array();
		SNI.Community.Widgets.cimgURL  = new Array();
		SNI.Community.Widgets.ccaption  = new Array();
		SNI.Community.Widgets.cratings = new Array();
		SNI.Community.Widgets.cviews = new Array();
		SNI.Community.Widgets.cd2cUrl = new Array();
		
			var citems = catGallery.getElementsByTagName("object");
			
			for (var i = 0 ; i < citems.length ; i++) {
		    var citem = citems[i];		
			SNI.Community.Widgets.cobjId[i] = citem.getElementsByTagName("id")[0].firstChild.nodeValue;
			SNI.Community.Widgets.cimgURL[i] = citem.getElementsByTagName("imgurl")[0].firstChild.nodeValue;
			SNI.Community.Widgets.ccaption[i] = citem.getElementsByTagName("caption")[0].firstChild.nodeValue;
			SNI.Community.Widgets.cratings[i] = citem.getElementsByTagName("rating")[0].firstChild.nodeValue;
			SNI.Community.Widgets.cviews[i] = citem.getElementsByTagName("views")[0].firstChild.nodeValue;
			SNI.Community.Widgets.cd2cUrl[i] = citem.getElementsByTagName("taxonomy")[0].firstChild.nodeValue;
		
		}
		for (var i = 0 ; i < 2 ; i++) {
			var j=i+1;
			document.getElementById('catCap'+j).innerHTML="";	
			document.getElementById('catView'+j).innerHTML="";
			document.getElementById('cImg'+j).innerHTML="";	
			document.getElementById('cRat'+j).innerHTML="";	
		}
		
		for (var i = 0 ; i < citems.length ; i++) {
			var j=i+1;
			
			var cCapTxt = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.ccaption[i]," ","-");
			
		
			var capDispTxt=SNI.Community.Widgets.ccaption[i];
			if(capDispTxt.length>10){
			capDispTxt=capDispTxt.substring(0, 10);
			capDispTxt=capDispTxt+"...";
			}
			
			cCapTxt =  cCapTxt.replace(/[^a-zA-Z 0-9 \-]+/g,'');
			cCapTxt =  cCapTxt.replace(/ /g,"-");
			
			//var cURL= gBaseUrl+"/"+SNI.Community.Widgets.cd2cUrl[i]+"/"+cCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.cobjId[i];
			var cURL = '';
			if(SNI.Community.Widgets.cd2cUrl[i]!='Other-Spaces')
				cURL=gBaseUrl+"/"+SNI.Community.Widgets.cd2cUrl[i]+"/"+cCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.cobjId[i];
			else
				cURL=gBaseUrl+"/"+cCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.cobjId[i];
				
				
			var cImgURL="";
			if(SNI.Community.Widgets.cimgURL[i].indexOf("http")==-1){
			cImgURL=gAjaxUrl+SNI.Community.Widgets.cimgURL[i];
			}
			else{
			cImgURL=SNI.Community.Widgets.cimgURL[i];
			}
			document.getElementById('catCap'+j).innerHTML="<p><a href="+cURL+">"+capDispTxt+"</a></p>";
			document.getElementById('catView'+j).innerHTML="<p>"+SNI.Community.Widgets.cviews[i]+" Views</p>";
			//document.getElementById('cImg'+j).innerHTML="<a href="+cURL+"><img  src="+SNI.Community.Widgets.cimgURL[i]+" border=\"0\"></a>";
			document.getElementById('cImg'+j).innerHTML="<a href="+cURL+"><img  src="+cImgURL+" border=\"0\"></a>";
			
			var crate=SNI.Community.Widgets.cratings[i];
			
			var cStar="";
				for(var r=0;r<crate;r++){
					cStar+="<img src=\""+gAjaxUrl+"/skins/main/images/account/dot.gif\" width=\"11px\" height=\"10px\" id=\"star-on\">";
				}
				
			document.getElementById('cRat'+j).innerHTML=cStar;		
		}	
	}				
}

//end overlay code


SNI.Community.Widgets.parseTextToXMLOverlayForTophat = function(text,show){	

	var xmlDoc;
		if(SNI.Community.Widgets.ie){
	
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(text);
		}
		else if(SNI.Community.Widgets.ns6){
		    parser=new DOMParser();
		    xmlDoc=parser.parseFromString(text,"text/xml");
	    }

		var userGallery =xmlDoc.getElementsByTagName('usergallery')[0];
		var utype=xmlDoc.getElementsByTagName('type')[0].firstChild.nodeValue;
		var gAjaxUrl = document.getElementById("gAjaxUrl").value;
		var gBaseUrl = document.getElementById("gBaseUrl").value;
		
		if(utype=="left"){
		
			var uitems = xmlDoc.getElementsByTagName("object");
			
			SNI.Community.Widgets.uobjId = new Array();
			SNI.Community.Widgets.uimgURL  = new Array();
			SNI.Community.Widgets.ucaption  = new Array();
			SNI.Community.Widgets.uratings = new Array();
			SNI.Community.Widgets.uviews = new Array();
			SNI.Community.Widgets.ud2cUrl = new Array();
			
			for (var i = 0 ; i < uitems.length ; i++) {
			    var uitem = uitems[i];		
				SNI.Community.Widgets.uobjId[i] = uitem.getElementsByTagName("id")[0].firstChild.nodeValue;
				SNI.Community.Widgets.uimgURL[i] = uitem.getElementsByTagName("imgurl")[0].firstChild.nodeValue;
				SNI.Community.Widgets.uimgURL[i] = SNI.Community.Widgets.uimgURL[i].replace("square", "medthumb_hor");
				SNI.Community.Widgets.ucaption[i] = uitem.getElementsByTagName("caption")[0].firstChild.nodeValue;
				SNI.Community.Widgets.uratings[i] = uitem.getElementsByTagName("rating")[0].firstChild.nodeValue;
				SNI.Community.Widgets.uviews[i] = SNI.Community.Widgets.numberWithCommas(uitem.getElementsByTagName("views")[0].firstChild.nodeValue);
				SNI.Community.Widgets.ud2cUrl[i] = uitem.getElementsByTagName("taxonomy")[0].firstChild.nodeValue;
		   }

		if( uitems.length == 0 ){
			document.getElementById('uContainer1').style.display="none";
			document.getElementById('uContainer1').innerHTML="This user hasn't uploaded anymore items yet.";
			document.getElementById('moreFromUserH').style.display="none";
		}else{
			document.getElementById('moreFromUserH').style.display="block";
		}
		var loopCount = uitems.length;
		if( uitems.length > 1 )
			loopCount = 1;

		for (var i = 0 ; i < loopCount ; i++) {
			
			var j=i+1;
			document.getElementById('uContainer'+j).style.display="block";
			var uCapTxt = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.ucaption[i]," ","-");
			var usrDispTxt=SNI.Community.Widgets.ucaption[i];
			if(usrDispTxt.length>32){
				usrDispTxt=usrDispTxt.substring(0, 32);
				usrDispTxt=usrDispTxt+"...";
			}
			
			uCapTxt =  uCapTxt.replace(/[^a-zA-Z 0-9 \-]+/g,'');
			uCapTxt = uCapTxt.replace(/ /g,"-");
			
			var uURL = '';
			if(SNI.Community.Widgets.ud2cUrl[i]!='Other-Spaces')
				uURL=gBaseUrl+"/"+SNI.Community.Widgets.ud2cUrl[i]+"/"+uCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.uobjId[i];
			else
				uURL=gBaseUrl+"/"+uCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.uobjId[i];
				
			var uImgURL="";
			if(SNI.Community.Widgets.uimgURL[i].indexOf("http")==-1){
				uImgURL=gAjaxUrl+SNI.Community.Widgets.cimgURL[i];
			}
			else{
				uImgURL=SNI.Community.Widgets.uimgURL[i];
			}
						
			document.getElementById('uLink'+j).innerHTML="<a href='javascript:void(0)' url=\""+uURL+"\">"+usrDispTxt+"</a>";
			document.getElementById('uPageview'+j).innerHTML=SNI.Community.Widgets.uviews[i]+" Views";
			document.getElementById('uImageLink'+j).innerHTML="<img src="+SNI.Community.Widgets.uimgURL[i]+" >";
			$('#uImageLink'+j).attr('href', "javascript:void(0)" );
			$('#uImageLink'+j).attr('url', uURL );
			$('#uImageLink'+j).attr('title', usrDispTxt );
			$("#uLink"+j+" a").bind("click", function () {
					orderByUserIdWithoutReload();
					document.location = $(this).attr('url');
			});
			$('#uImageLink'+j).bind("click", function () {
					orderByUserIdWithoutReload();
					document.location = $(this).attr('url');
			});
			
			var ratingPerc = SNI.Community.Widgets.uratings[j];
			if ( ratingPerc != '' && ratingPerc > 0){
				ratingPerc = parseInt(SNI.Community.Widgets.uratings[j])*20;
			}
			else{
				ratingPerc = 0;
			}
			$('#uRating'+j+' div span').width(''+ratingPerc+'%');
			
		}		
		 
	}
	
	var catGallery=xmlDoc.getElementsByTagName('catgallery')[0];
	var ctype=xmlDoc.getElementsByTagName('type')[0].firstChild.nodeValue;
	if(ctype=="right"){
		
		SNI.Community.Widgets.cobjId = new Array();
		SNI.Community.Widgets.cimgURL  = new Array();
		SNI.Community.Widgets.ccaption  = new Array();
		SNI.Community.Widgets.cratings = new Array();
		SNI.Community.Widgets.cviews = new Array();
		SNI.Community.Widgets.cd2cUrl = new Array();
		
			var citems = catGallery.getElementsByTagName("object");
			
			for (var i = 0 ; i < citems.length ; i++) {
		    var citem = citems[i];		
			SNI.Community.Widgets.cobjId[i] = citem.getElementsByTagName("id")[0].firstChild.nodeValue;
			SNI.Community.Widgets.cimgURL[i] = citem.getElementsByTagName("imgurl")[0].firstChild.nodeValue;
			SNI.Community.Widgets.cimgURL[i] = SNI.Community.Widgets.cimgURL[i].replace("square", "medthumb_hor");
			SNI.Community.Widgets.ccaption[i] = citem.getElementsByTagName("caption")[0].firstChild.nodeValue;
			SNI.Community.Widgets.cratings[i] = citem.getElementsByTagName("rating")[0].firstChild.nodeValue;
			//Added SNI.Community.Widgets.numberWithCommas function for issue 2501
			SNI.Community.Widgets.cviews[i] = SNI.Community.Widgets.numberWithCommas(citem.getElementsByTagName("views")[0].firstChild.nodeValue);
			SNI.Community.Widgets.cd2cUrl[i] = citem.getElementsByTagName("taxonomy")[0].firstChild.nodeValue;
		
		}
		
		loopCount = citems.length;
		
		if( citems.length == 0 ){
			document.getElementById('cContainer1').style.display="none";
			document.getElementById('moreFromCategoryH').style.display="none";
		}else{
			document.getElementById('moreFromCategoryH').style.display="block";
		}
		
		if( citems.length > 1 )
			loopCount = 1;
			
		for (var i = 0 ; i < loopCount ; i++) {

			var j=i+1;
			document.getElementById('cContainer'+j).style.display="block";			
			var cCapTxt = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.ccaption[i]," ","-");
			var capDispTxt=SNI.Community.Widgets.ccaption[i];
			if(capDispTxt.length>32){
				capDispTxt=capDispTxt.substring(0, 32);
				capDispTxt=capDispTxt+"...";
			}
			
			cCapTxt =  cCapTxt.replace(/[^a-zA-Z 0-9 \-]+/g,'');
			cCapTxt =  cCapTxt.replace(/ /g,"-");
			
			var cURL = '';
			if(SNI.Community.Widgets.cd2cUrl[i]!='Other-Spaces')
				cURL=gBaseUrl+"/"+SNI.Community.Widgets.cd2cUrl[i]+"/"+cCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.cobjId[i];
			else
				cURL=gBaseUrl+"/"+cCapTxt+"/detail.esi?oid="+SNI.Community.Widgets.cobjId[i];
				
			document.getElementById('cLink'+j).innerHTML="<a href='javascript:void(0);' cat=\""+SNI.Community.Widgets.cd2cUrl[i]+"\" url=\""+cURL+"\">"+capDispTxt+"</a>";
			document.getElementById('cPageview'+j).innerHTML=SNI.Community.Widgets.cviews[i]+" Views";
			document.getElementById('cImageLink'+j).innerHTML="<img src="+SNI.Community.Widgets.cimgURL[i]+" />";
			$('#cImageLink'+j).attr('href', cURL );
			$('#cImageLink'+j).attr('title', capDispTxt );
			$('#cImageLink'+j).attr('cat', SNI.Community.Widgets.cd2cUrl[i] );
			
			
			$("#cLink"+j+" a").bind("click", function () {
					SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_user_search', '/', '' );
					//SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_time_frame', '/', '' );
					SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_created_user_name', '/', '' );
					SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_created_user_id', '/', '' );
					//SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_time_frame', '/', '' );
					
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_sort_order','2', '1', '/', '', '' );
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_from_page','gallery', '1', '/', '', '' );
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_page','1', '1', '/', '', '' );
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_time_frame','0', '1', '/', '', '' );
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_category',$(this).attr('cat'), '1', '/', '', '' );
					document.location = $(this).attr('url');
			});
			
			$('#cImageLink'+j).bind("click", function () {
					SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_user_search', '/', '' );
					//SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_time_frame', '/', '' );
					SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_created_user_name', '/', '' );
					SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_created_user_id', '/', '' );
					
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_sort_order','2', '1', '/', '', '' );
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_from_page','gallery', '1', '/', '', '' );
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_page','1', '1', '/', '', '' );
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_time_frame','0', '1', '/', '', '' );
					SNI.Community.Widgets.Set_Cookie( 'pickle_pv_category',$(this).attr('cat'), '1', '/', '', '' );
					document.location = $(this).attr('url');
			});
			
			var ratingPerc = SNI.Community.Widgets.cratings[j];
			if ( ratingPerc != '' && ratingPerc > 0){
				ratingPerc = parseInt(SNI.Community.Widgets.cratings[j])*20;
			}
			else{
				ratingPerc = 0;
			}
			$('#cRating'+j+' div span').width(''+ratingPerc+'%');
			
		}	
	}				
	
}

//Check after this function closeErrorMsg
//Detail page code end

//Collections uplaod related code start

//Step1 code

SNI.Community.Widgets.mingleWithExisting = function(){
	if(document.getElementById('collectionId').value!=''){
		document.getElementById("myspace-label").className = ""; 
		document.getElementById("spaceTypeLabel").className = ""; 
		document.getElementById("capLabel").className = ""; 
		document.getElementById('returnurl').value = crossDomainURL;
		document.getElementById('spacetypelist').value = document.getElementById('tags').value;
		document.getElementById('isold').value = "1";
		//document.getElementById("goto").value = "renderpage";
		document.getElementById("goto").value = "";
		document.f1.submit();
	}
	else{
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		//document.getElementById('errorMessage').innerHTML="<ul><li><p id=\"errortext\">Please select a Space.</p></ul></li>";
		document.getElementById('errorMessage').innerHTML="<ul><li><p id=\"errortext\">Please make a selection.</p></ul></li>";
		document.getElementById("myspace-label").className = "error-field"; 
		
	document.getElementById("spaceTypeLabel").className = ""; 
	document.getElementById("capLabel").className = "";
	document.getElementById("descLabel").className = "";
	}
}

SNI.Community.Widgets.closeErrorMsgUpload = function(objId){
	if(document.getElementById(objId))
		document.getElementById(objId).style.display = "none";
}

SNI.Community.Widgets.createNew = function(){
	var spaceType=document.getElementById('spacetype').value;
	var caption=document.getElementById('caption').value;
	var desc=document.getElementById('desc').value;
	var tags=document.getElementById('tags').value;
	var taxMapSize = document.getElementById('taxMapSize').value;
	
	if(parseInt(taxMapSize) == 0){
		spaceType = "without taxonomy"; // Just for condition check
	}
	
	if(spaceType==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		document.getElementById("spaceTypeLabel").className = "error-field"; 
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
	}
	else if(spaceType!=''){
		document.getElementById('errorMessageNewSpaceType').innerHTML="";
		document.getElementById("spaceTypeLabel").className = "";
	}
	
	if(caption==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("capLabel").className = "error-field";
		document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
	}
	else if(caption!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("capLabel").className = "";
	}	
	
	var mandontarCheck=true;
	var mandontaryTemp2 = mandontary+'';
	var uploadDescription = '';
	if( document.getElementById("desc") )
		uploadDescription = document.getElementById("desc").value;
	if(mandontaryTemp2.indexOf("uploadDescription_txt")!=-1 && SNI.Community.Widgets.trim(uploadDescription)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("descLabel").className = "error-field";
		mandontarCheck=false;
		document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
	}
	else if(SNI.Community.Widgets.trim(uploadDescription)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("descLabel").className = "";		
	}
	if(!mandontarCheck){
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-middle-new");
	}
	
	if((caption!='')&&(spaceType!='') && mandontarCheck){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "none";
		document.getElementById('returnurl').value = crossDomainURL;
		document.f1.submit();	
	}
}
SNI.Community.Widgets.ScrollTo=function(ObjId){	
	var a = document.location+"";
	if(a.indexOf("#")==-1){
		document.location = a+"#"+ObjId;
	}else{
		a = a.substring(0,a.indexOf("#"));
		document.location = a+"#"+ObjId;
	}
}
SNI.Community.Widgets.setSelect = function(inObjId, inObjCap, inDiv, inDisplayDiv, inDataDiv,categoryTag){
	var inObjIdVal ='';
	inObjId=SNI.Community.Widgets.replaceAll(inObjId,"|","'");
	inObjCap=SNI.Community.Widgets.replaceAll(inObjCap,"|","'");
	document.getElementById(inDataDiv).value = inObjId;
	document.getElementById(inDisplayDiv).value = inObjCap;
	document.getElementById(inDiv).style.display = 'none';
	if(categoryTag!=undefined){
		if(document.getElementById('tags'))
		  document.getElementById('tags').value = categoryTag;
	}	  

	if(inDisplayDiv=="spacetypelist"){
		inObjId = SNI.Community.Widgets.replaceAll(inObjId,"|","'");
		document.getElementById('tags').value = inObjId;
		SNI.Community.Widgets.changeCategory('','',inObjId,false);
	}
}

/*Any issue refer here
SNI.Community.Widgets.setSelect = function(inObjId, inObjCap, inDiv, inDisplayDiv, inDataDiv){
	inObjId=SNI.Community.Widgets.replaceAll(inObjId,"|","'");
		inObjCap=SNI.Community.Widgets.replaceAll(inObjCap,"|","'");
	document.getElementById(inDataDiv).value = inObjId;
	document.getElementById(inDisplayDiv).value = inObjCap;
	document.getElementById(inDiv).style.display = 'none';
}
*/


SNI.Community.Widgets.createNewNonUr = function()
{
	//alert( mandontary );
	var spaceType=document.getElementById('spacetype').value;
	var caption=document.getElementById('caption').value;
	var desc=document.getElementById('desc').value;
	var tags=document.getElementById('tags').value;
	var taxMapSize = document.getElementById('taxMapSize').value;
	
	var mandontaryTemp = mandontary+'';
	
	if(parseInt(taxMapSize) == 0){
		spaceType = "without taxonomy"; // Just for condition check
	}	
	
	var userEmail = document.getElementById('userEmail_txt').value;
	var emailCheck = SNI.Community.Widgets.isEmail(document.getElementById('userEmail_txt'));
	if( mandontaryTemp.indexOf("userEmail_txt")!=-1 && ( SNI.Community.Widgets.trim(userEmail) =='' || emailCheck == true ) ){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("userEmail_Label").className = "error-field";
		document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please enter a valid e-mail address in the E-mail Address field.</p></li></ul>";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		return false;
	}
	else if(SNI.Community.Widgets.trim(userEmail)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("userEmail_Label").className = "";
	}
	
	var displayName = '';
	if( document.getElementById('displayName_txt') )
		displayName = document.getElementById('displayName_txt').value;
	
	if( mandontaryTemp.indexOf("displayName_txt")!=-1 && SNI.Community.Widgets.trim(displayName)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("displayName_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(displayName!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("displayName_Label").className = "";
	}
	
	var firstName = '';
	if( document.getElementById('firstName_txt') )
		firstName = document.getElementById('firstName_txt').value;
	
	if( mandontaryTemp.indexOf("firstName_txt")!=-1 && SNI.Community.Widgets.trim(firstName)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("firstName_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(firstName)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("firstName_Label").className = "";
	}
	
	var lastName = '';
	if( document.getElementById("lastName_txt") )
		lastName = document.getElementById("lastName_txt").value;
	
	if( mandontaryTemp.indexOf("lastName_txt")!=-1 && SNI.Community.Widgets.trim(lastName)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("lastName_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(lastName)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("lastName_Label").className = "";
	}
	
	var streetAddress = '';
	if( document.getElementById("streetAddress_txt") )
		streetAddress = document.getElementById("streetAddress_txt").value;
	if( mandontaryTemp.indexOf("streetAddress_txt")!=-1 && SNI.Community.Widgets.trim(streetAddress)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("streetAddress_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(streetAddress)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("streetAddress_Label").className = "";
	}
	
	var streetAddress2 = '';
	if( document.getElementById("streetAddress2_txt") )
		streetAddress2 = document.getElementById("streetAddress2_txt").value;
	if( mandontaryTemp.indexOf("streetAddress2_txt")!=-1 && SNI.Community.Widgets.trim(streetAddress2)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("streetAddress2_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(streetAddress2)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("streetAddress2_Label").className = "";
	}
	
	var state = '';
	if( document.getElementById("state_txt") )
		state = document.getElementById("state_txt").value;
	if(mandontaryTemp.indexOf("state_txt")!=-1 && SNI.Community.Widgets.trim(state)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("state_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(state)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("state_Label").className = "";		
	}	
	
	
	var city = '';
	if( document.getElementById("city_txt") )
		city = document.getElementById("city_txt").value;
	if(mandontaryTemp.indexOf("city_txt")!=-1 && SNI.Community.Widgets.trim(city)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("city_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(city)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("city_Label").className = "";		
	}	
	
	var postal = '';
	if( document.getElementById("zipCode_txt") )
		postal = document.getElementById("zipCode_txt").value;
	if(mandontaryTemp.indexOf("zipCode_txt")!=-1 && SNI.Community.Widgets.trim(postal)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("zipCode_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(postal)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("zipCode_Label").className = "";		
	}		
	
	var phone1 = '';
	if( document.getElementById("phone_txt") )
		phone1 = document.getElementById("phone_txt").value;
	if(mandontaryTemp.indexOf("phone_txt")!=-1 && SNI.Community.Widgets.trim(phone1)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("phone_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(phone1)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("phone_Label").className = "";		
	}
	
	var phone2 = '';
	if( document.getElementById("phone2_txt") )
		phone2 = document.getElementById("phone2_txt").value;
	if(mandontaryTemp.indexOf("phone2_txt")!=-1 && SNI.Community.Widgets.trim(phone2)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("phone2_Label").className = "error-field";
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(phone2)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("phone2_Label").className = "";		
	}
	
	var country = '';
	if( document.getElementById("country_txt") )
		country = document.getElementById("country_txt").value;
	if(mandontaryTemp.indexOf("country_txt")!=-1 && SNI.Community.Widgets.trim(country)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("country_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(country)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("country_Label").className = "";		
	}
	
	var gender = '';
	if( document.getElementById("gender_txt") )
		gender = document.getElementById("gender_txt").value;
	if(mandontaryTemp.indexOf("gender_txt")!=-1 && SNI.Community.Widgets.trim(gender)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("gender_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(gender)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("gender_Label").className = "";		
	}
	
	
	var aboutme = '';
	if( document.getElementById("aboutme_txt") )
		aboutme = document.getElementById("aboutme_txt").value;
	if(mandontaryTemp.indexOf("aboutme_txt")!=-1 && SNI.Community.Widgets.trim(aboutme)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("aboutme_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(aboutme)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("aboutme_Label").className = "";		
	}
	
	var custom1 = '';
	if( document.getElementById("custom_txt") )
		custom1 = document.getElementById("custom_txt").value;
	if(mandontaryTemp.indexOf("custom_txt")!=-1 && SNI.Community.Widgets.trim(custom1)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("custom_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(custom1)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("custom_Label").className = "";		
	}
	
	var custom2 = '';
	if( document.getElementById("custom2_txt") )
		custom2 = document.getElementById("custom2_txt").value;
	if(mandontaryTemp.indexOf("custom2_txt")!=-1 && SNI.Community.Widgets.trim(custom2)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("custom2_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(custom2)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("custom2_Label").className = "";		
	}
	
	var month = '';
	if( document.getElementById("month_txt") )
		month = document.getElementById("month_txt").value;
	if(mandontaryTemp.indexOf("month_txt")!=-1 && ( SNI.Community.Widgets.trim(month)=='MM' || SNI.Community.Widgets.trim(month)=='' )){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("dob_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(month)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("dob_Label").className = "";		
	}
	var year = '';
	if( document.getElementById("year_txt") )
		year = document.getElementById("year_txt").value;
	if(mandontaryTemp.indexOf("year_txt")!=-1 &&  ( SNI.Community.Widgets.trim(year)=='YYYY' || SNI.Community.Widgets.trim(year)=='' ) ){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("dob_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(year)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("dob_Label").className = "";		
	}
	
	var date = '';
	if( document.getElementById("date_txt") )
		date = document.getElementById("date_txt").value;
	if(mandontaryTemp.indexOf("date_txt")!=-1 &&  ( SNI.Community.Widgets.trim(date)=='DD' || SNI.Community.Widgets.trim(date)=='' ) ){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("dob_Label").className = "error-field";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
		//document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(date)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("dob_Label").className = "";		
	}
	
	if(SNI.Community.Widgets.trim(spaceType) ==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		document.getElementById("spaceTypeLabel").className = "error-field"; 
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
	}
	else if(SNI.Community.Widgets.trim(spaceType) !=''){
		document.getElementById('errorMessageNewSpaceType').innerHTML="";
		document.getElementById("spaceTypeLabel").className = "";
	}
	
	if(SNI.Community.Widgets.trim(caption) ==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("capLabel").className = "error-field";
		document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");
	}
	else if(SNI.Community.Widgets.trim(caption) !=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("capLabel").className = "";
	}
	
	var mandontarCheck=true;
	var uploadDescription = '';
	if( document.getElementById("desc") )
		uploadDescription = document.getElementById("desc").value;
	if(mandontaryTemp.indexOf("uploadDescription_txt")!=-1 && SNI.Community.Widgets.trim(uploadDescription)==''){
		document.getElementById('cgp-id-page-itemsaved-new').style.display = "block";
		document.getElementById("descLabel").className = "error-field";
		mandontarCheck=false;
		document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved-new");	
	}
	else if(SNI.Community.Widgets.trim(uploadDescription)!=''){
		document.getElementById('errorMessageNewCaption').innerHTML="";
		document.getElementById("descLabel").className = "";		
	}
	
	if((SNI.Community.Widgets.trim(caption)!='')&&(SNI.Community.Widgets.trim(spaceType)!='') && mandontarCheck){
		var mandFound=false;
		for( var i=0;i<mandontary.length;i++){
			var ibj = document.getElementById( mandontary[i] );
			if( ibj && SNI.Community.Widgets.trim( ibj.value) == ''){
				mandFound = true;				
				document.getElementById('errorMessageNewSpaceType').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
			}
		}
		if( !mandFound ){
			document.getElementById('cgp-id-page-itemsaved-new').style.display = "none";
			document.getElementById('returnurl').value = crossDomainURL;
			document.f1.submit();	
		}
	}
		
}

// End step 1 code

//Start step2 code

SNI.Community.Widgets.termsCheck = function(){
	if(document.getElementById('chkTerms').checked){
	 	SNI.Community.Widgets.setUploadCountValue();
	    var uplCountObj = document.getElementById("upload_file_count");
	    
	    if(parseInt(uplCountObj.value)==0){
	    	//alert("termsCheck")
		    document.getElementById('cgp-id-page-itemsaved').style.display = "block";		     
		    document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please Select a File.</p></ul></li>";
		    //document.getElementById('errMessageT').innerHTML="";
		    SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved");
	    } 
	    else{
			document.getElementById('cgp-id-page-itemsaved').style.display = "none";	
			SNI.Community.Widgets.startCallback();
			document.getElementById('sub').click();
			uploadCompleted(true,true);
	    } 				
	}
	else{
		
		if( document.getElementById('tcAlertText') ){
			document.getElementById('cgp-id-page-itemsaved').style.display = "block";
			document.getElementById('errMessageF').innerHTML="";
			document.getElementById('errMessageT').innerHTML="<ul><li><p id=\"errortext\">"+document.getElementById('tcAlertText').value+"</p></ul></li>";
			SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved");
		}
		else{
			document.getElementById('cgp-id-page-itemsaved').style.display = "block";
			document.getElementById('errMessageF').innerHTML="";
			document.getElementById('errMessageT').innerHTML="<ul><li><p id=\"errortext\">Please read and agree to the Privacy Policy, Infringement Policy and Terms of Use.</p></ul></li>";
			SNI.Community.Widgets.ScrollTo("cgp-id-page-itemsaved");
		}
	}		
}

SNI.Community.Widgets.setUploadCountValue = function(){
	var tmpUploadCount = 0;
	var formObj = document.getElementById("f1");
	var nameArr = formObj.getElementsByTagName("input");
	for( var i=0;i<nameArr.length;i++){
		var obj = nameArr[i];
		if( obj.type=="file" ){
			if(obj.value != ""){
				tmpUploadCount++;
			}
			//url += obj.name + "=" + escape(obj.value) + "&";
		}
	}

	var uplCountObj = document.getElementById("upload_file_count");
	if(uplCountObj) uplCountObj.value=tmpUploadCount;
}

SNI.Community.Widgets.startCallback = function() {
	var a = ""+SNI.Community.Widgets.files;
	if(a.indexOf('false')!=-1)
	{
		SNI.Community.Widgets.showAlert();
		return false;
	}
	//alert(SNI.Community.Widgets.myuploadcount);
	/*if(sniset == 0){
  			 for ( var z=0;z<SNI.Community.Widgets.myuploadcount.length;z++)
  			 {
  				if(SNI.Community.Widgets.myuploadcount[0] == "P"){
  					SNI.Community.objectType = "Photo" ;
  				}
  				else
  				{
  					SNI.Community.objectType = "Video" ;
  				}
  				SNI.Community.t.ActionTrack(this,'UPLOAD',SNI.Community.objectType);	   					
  			 }
  			 sniset = 1;
 			 }*/
	alignPageCenter('progressbarstatuscontrol');
	SNI.Community.Widgets.displayOn('grey_background');
	SNI.Community.Widgets.displayOn('progressbarstatuscontrol');
	SNI.Community.Widgets.displayOn('processingStatus');
	
	return true;
}

var a = true;
SNI.Community.Widgets.filesOk = true;
SNI.Community.Widgets.errMessage = "";
SNI.Community.Widgets.completeCallback = function(response) {
	// make something useful after (onComplete)
	if(a || isCancel==true){a=false;return;}
	uploadCompleted(true,true);
}

SNI.Community.Widgets.photosandvideos;
SNI.Community.Widgets.myuploadcount = new Array();
SNI.Community.Widgets.tmpUploadStatusCount = 0;

SNI.Community.Widgets.checkFileType = function(obj){
	var acceptedFiles = document.getElementById("cUpAcceptedFiles").value;
 	var uploadUrl = document.getElementById("cUpUploadUrl").value; 

	SNI.Community.Widgets.photosandvideos = new Array();
	var acceptFiles = acceptedFiles;
	var videos = ".avi, .mov, .mpg, .wmv, .mpeg, .3gp, .3g2, .flv, .mp4, .rm, or .qtl";
	var ext = obj.value;
	ext = ext.substring(ext.length-3,ext.length);
	ext = ext.toLowerCase();
	if(videos.indexOf(ext)!=-1){
		SNI.Community.Widgets.photosandvideos[SNI.Community.Widgets.photosandvideos.length] = "V";
		SNI.Community.Widgets.myuploadcount[SNI.Community.Widgets.myuploadcount.length] = "V";
	}
	else{
		SNI.Community.Widgets.photosandvideos[SNI.Community.Widgets.photosandvideos.length] = "P";
		SNI.Community.Widgets.myuploadcount[SNI.Community.Widgets.myuploadcount.length] = "P";
	}
 	
	if(acceptFiles.indexOf(ext)==-1) {
		SNI.Community.Widgets.errMessage = '<p><ul><li>Only the following file types are supported: '+acceptedFiles+'</ul></li></p>';
		SNI.Community.Widgets.files[parseInt(obj.id)] = false;
		
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById('errMessageF').innerHTML="<ul><li><p id=\"errortext\">This file type is not accepted. Please select another file and try again.</p></ul></li>";
		obj.value = "";
		if(SNI.Community.Widgets.tmpUploadStatusCount>0){
			SNI.Community.Widgets.tmpUploadStatusCount--;
		}
	}else{
		var textName = document.getElementsByName("up-search"+obj.id);
		textName[0].value = obj.value;
		SNI.Community.Widgets.files[parseInt(obj.id)] = true;
		SNI.Community.Widgets.tmpUploadStatusCount++;
	}
	SNI.Community.Widgets.setUploadCountValue();
	var uplCountObj = document.getElementById("upload_file_count");
	
	//Given code for single mode collection conditional check
	var projectType = document.getElementById("gProjectType").value;
	//alert("projectType :"+projectType);
	if(parseInt(projectType) != 8){
		document.f1.action = uploadUrl+uplCountObj.value;
	}
}

SNI.Community.Widgets.files = new Array(5);
SNI.Community.Widgets.showAlert = function(){
	//alert(SNI.Community.Widgets.errMessage);
	document.getElementById('cgp-id-page-itemsaved').style.display = "block";
	document.getElementById('errMessageF').innerHTML="<ul><li><p id=\"errortext\">This file type is not accepted. Please select another file and try again.</p></ul></li>";
	return false;
}

SNI.Community.Widgets.addOneMore = function(maxUpload)
{
	if(maxUpload>600) maxUpload = 10;
	if(uploadCount<maxUpload){
		uploadCount++;
		var a  = document.createElement('div');
		a.id = "cgp-newedit-upload-file01";
		//a.innerHTML = "<span class='labellayout'>File "+uploadCount+": </span><span class='entrylayout'><input name='file"+uploadCount+"' class='file' onchange='SNI.Community.Widgets.checkFileType(this)' id='"+uploadCount+"' value='' type='file'></span><div class='fakefile'"+uploadCount+"><div id='up-page-mypicture-upload-select'><div id='up-mypicture-field'><input type='text' id='up-search'  name='fileName'"+uploadCount+"></div></div><div id='up-accountpage-button'><ul id='widget-nav'><li id='widget-nav-item-off' /><a href='#'><em>Browse...</em></a></ul></div></div><div id=\"up-clear\"></div>";							
		var addHtml = "<div class='fileinputs'>"+
							"<div class='cgp-mypicture-upload-labellayout'><p>File "+uploadCount+": </p></div><div class='entrylayout'><input class='file' onchange='SNI.Community.Widgets.checkFileType(this)' name='file"+uploadCount+"' id='"+uploadCount+"' value='' type='file'></div>"+
							"<div class='fakefile'>"+
							"<div class='cgp-mypicture-upload-container'>"+			
								"<div id='cgp-mypicture-upload-select'>"+								
									"<div id='cgp-mypicture-field' ><input type='text' name='up-search"+uploadCount+"' id='up-search' readonly='readonly'></div><ul id='cgp-widget-nav-float'><li id='cgp-select-off' /><a href='#'><em>Browse...</em></a></ul>"+
								"</div>"+
							"</div>"+
							"</div>"+
							"<div id='up-clear'></div>"+								
					"</div>";
					
		a.innerHTML = addHtml;
		document.getElementById('cgp-newedit-upload-file').appendChild(a);
		
		if(uploadCount==maxUpload)
			SNI.Community.Widgets.layerOff('cgp-newedit-addmore-button')
	}
}

SNI.Community.Widgets.iframeSubmit = function(){
	SNI.Community.Widgets.setUploadCountValue();
	//return AIM.submit(this,'<%//=frId%>', {'onStart' : SNI.Community.Widgets.startCallback, 'onComplete' : SNI.Community.Widgets.completeCallback})
}

SNI.Community.Widgets.clearFileSelector = function(formId){
	var formObj = document.getElementById(formId);
	if(formObj){
		var nameArr = formObj.getElementsByTagName("input");
		for( var i=0;i<nameArr.length;i++){
			var obj = nameArr[i];
			if( obj.type=="file" ){
				obj.value = "";
				//url += obj.name + "=" + escape(obj.value) + "&";
			}
		}	
	}
}

//End step2 code

//Satrt step 3 code

SNI.Community.Widgets.show_hide_div = function(objToBeShown,objToBeHide){
	document.getElementById(objToBeShown).style.display="block";
	document.getElementById(objToBeHide).style.display="none";
} 

SNI.Community.Widgets.load_rico = function(){
	var pickleWebPath = document.getElementById("cUpPickleWebPath").value;
	//document.getElementById('changeOrderImage').style.visibility = "hidden";
	var rico_js = document.createElement('script');
	rico_js.type = "text/javascript";
	rico_js.src = pickleWebPath+"/skins/js/rico.js";
	document.getElementsByTagName('head')[0].appendChild(rico_js);
}

SNI.Community.Widgets.load_customrico_js = function(){
	var pickleWebPath = document.getElementById("cUpPickleWebPath").value;
	var customrico_js = document.createElement('script');
	customrico_js.type = "text/javascript";
	customrico_js.src = pickleWebPath+"/skins/js/customrico.js";
	document.getElementsByTagName('head')[0].appendChild(customrico_js);
}

SNI.Community.Widgets.init_CO = function(){
	//new getObj('setarrayid').value = setValue;	
	//new getObj('setobjectarrayid').value = setObjectValue;
	var images = getElementsByClass(document, "imageclass");
	for(b=0; b < images.length; b++) //return the first hotspot it finds that's been landed on
	{
		var imagedrop = new getObj(images[b].id);
		imagedropid = imagedrop.id;
		//alert('imagedropid :'+imagedropid);
		//imagetitle = imagedrop.title; 
		dragid = 'imagedrag'+ imagedropid.substring(9,200);
		//testcustomrico();
		dndMgr.registerDropZone( new CustomDropzone(imagedropid, setArray, setObjectArray));
		//alert('imageid :'+imageid);
		dndMgr.registerDraggable( new Rico.Draggable('rico draggable',dragid) );		
	}
	if(document.getElementById('toprevpage'))
		dndMgr.registerDropZone( new CustomDropzone('toprevpage', setArray, setObjectArray));
	if(document.getElementById('tonextpage'))
		dndMgr.registerDropZone( new CustomDropzone('tonextpage', setArray, setObjectArray));
}

SNI.Community.Widgets.submit_thiform = function(){
	/*
	var catCookie = ""+SNI.Community.Widgets.Get_Cookie('pickle_taxanomy_category'); 
	
	if(SNI.Community.Widgets.trim(catCookie)!=""){
		document.getElementById('categorySelected').value = catCookie;
	}
	*/
	
	// PICKLE-2935
	
	SNI.Community.Widgets.Delete_Cookie('pickle_pv_from_page','/','');
	SNI.Community.Widgets.Delete_Cookie('pickle_pv_time_frame','/','');
	SNI.Community.Widgets.Delete_Cookie('pickle_pv_created_user_id','/','');
	SNI.Community.Widgets.Delete_Cookie('pickle_pv_page_size','/','');
	SNI.Community.Widgets.Delete_Cookie('pickle_pv_category','/','');
	SNI.Community.Widgets.Delete_Cookie('pickle_pv_user_search','/','');
	
	
	SNI.Community.Widgets.displayOff("save_button");
	SNI.Community.Widgets.displayOff("cancel_button");
	SNI.Community.Widgets.displayOn("save_button_loading");
	try{
		document.getElementById('setarrayid').value = 	$('#sortable').sortable('toArray');
	}catch(e){alert("Unable to do CustomSort");}
	setTimeout('SNI.Community.Widgets.formSubmitStep3()', 1000); // 1 second wait			
	//document.f1.submit();
}

SNI.Community.Widgets.formSubmitStep3 = function(){
	document.f1.submit();
}	

SNI.Community.Widgets.deleteIds = new Array();
SNI.Community.Widgets.globalDeleteArrayId = new Array();
/* Any issue pls refer this code
SNI.Community.Widgets.deleteItems = function(obj){
	if(obj.checked == true)
	{
		SNI.Community.Widgets.deleteIds[SNI.Community.Widgets.deleteIds.length] = obj.value;
	}else{
		for(i=0;i<SNI.Community.Widgets.deleteIds.length;i++){
			if(parseInt(SNI.Community.Widgets.deleteIds[i])==parseInt(obj.value))
				SNI.Community.Widgets.deleteIds.splice(i,i+1);
		}
		
	}
	
	document.getElementById('cgp-id-page-itemdelete').style.display = "none";
	
	if(parseInt(deleteCountMax)==parseInt(SNI.Community.Widgets.deleteIds.length)){
		document.getElementById('cgp-newedit-new-space-save-button').style.display = "none";
		document.getElementById('cgp-id-page-itemdelete').style.display = "block";
	}else{
		document.getElementById('cgp-newedit-new-space-save-button').style.display = "block";
	}
	
	document.getElementById('deleteids').value = SNI.Community.Widgets.deleteIds;
}
*/
SNI.Community.Widgets.deleteItems = function(obj){
	if(obj.checked == true)
	{
		SNI.Community.Widgets.deleteIds[SNI.Community.Widgets.deleteIds.length] = obj.value;
	}else{
		for(i=0;i<SNI.Community.Widgets.deleteIds.length;i++)
		{
			if(parseInt(SNI.Community.Widgets.deleteIds[i])==parseInt(obj.value))
				SNI.Community.Widgets.deleteIds.splice(i,i+1);
		}
		
	}
	
	document.getElementById('deleteids').value = SNI.Community.Widgets.deleteIds;
	SNI.Community.Widgets.deleteAllDiv();
}

SNI.Community.Widgets.deleteAllDiv = function(){
	document.getElementById('cgp-id-page-itemdelete').style.display = "none";

	if(parseInt(deleteCountMax)==parseInt(SNI.Community.Widgets.deleteIds.length) && deleteCountMax>0){
		if(document.getElementById('cgp-newedit-new-space-create-button'))
			document.getElementById('cgp-newedit-new-space-create-button').style.display = "none";
		if(document.getElementById('cgp-newedit-new-space-save-button'))	
			document.getElementById('cgp-newedit-new-space-save-button').style.display = "none";
					
		document.getElementById('cgp-id-page-itemdelete').style.display = "block";
	}else{
		if(document.getElementById('cgp-newedit-new-space-create-button'))
			document.getElementById('cgp-newedit-new-space-create-button').style.display = "block";
		if(document.getElementById('cgp-newedit-new-space-save-button'))
			document.getElementById('cgp-newedit-new-space-save-button').style.display = "block";
	}
}
SNI.Community.Widgets.changeFeaturedItem = function(featItemVal){
	if(document.getElementById("featureitem_"+featItemVal)){
		var featChecked = document.getElementById("featureitem_"+featItemVal).checked;
		if(!featChecked){
			//document.getElementById("featureitem_"+featItemVal).checked = true;
			document.getElementById("featureitem_"+featItemVal).checked = "checked";
		}
	}
}

SNI.Community.Widgets.changeMode = function(){
	var where_to= confirm("Are you sure you want to delete?");
	if(where_to)
	{
		var locReturn = document.getElementById("cUpBaseUrl").value;
		var collId = document.getElementById('collectionid').value;
		var crossUrl = document.getElementById("cUpCrossDomainUrl").value;
		var url = crossUrl+'/collectionsedit.do?editmode=delete&cid='+collId+'&loc_return_con=true&del_returnurl='+escape(locReturn);
		document.location = url;
		//alert('url :'+url);
		//document.getElementById('editmode').value="delete";
		//document.f2.submit();
	}
}

SNI.Community.Widgets.deleteItemsBack = function(){
	var total_to_delete = document.getElementById('deleteids').value;
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	
	var cBaseUrl = document.getElementById("cUpBaseUrl").value;
	var crossUrl = document.getElementById("cUpCrossDomainUrl").value;
	var cParentId =  document.getElementById("cUpParentId").value;
	
	var locReturn = cBaseUrl;
	var collId = document.getElementById('collectionid').value;
	var pId = cParentId;
	var url = crossUrl+"/a1deleteobject_p2.do?odl="+total_to_delete+"&oType=pva&pId="+escape(pId)+"&collectionId="+collId;
	
	request.onreadystatechange=function()
	{
	 if(request.readyState==4)
	 {
	  if(request.status==200)
	  {
	  	window.history.go(-1);
	  	//document.getElementById('processing').innerHTML = "This item is now archived."; 
	  }
	  else if(request.status==500)
	   alert("You found an opportunity for improvement! Please try again later");
	  else
	   alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
	 }
	}	
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send(''); 
}	

SNI.Community.Widgets.deleteSpace = function(){  
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	
	var cAppUrl = document.getElementById("cUpAppUrl").value; 
	var cParentId =  document.getElementById("cUpParentId").value;
	var crossUrl = document.getElementById("cUpCrossDomainUrl").value;
	
	var locReturn = cAppUrl;
	var collId = document.getElementById('collectionid').value;
	var pId = cParentId;

	//var url="<%//=crossDomainUrl%>/changestatusaction.do?obid=0&obstatl=1&obtype=pva&collectionId="+collId;
	var url = crossUrl+"/a1deleteobject_p2.do?odl="+collId+"&oType=collection&pId="+escape(pId);
	
	if(document.getElementById('isUr') && document.getElementById('isUr').value == "false"){
		url = crossUrl+"/no_ur_a1deleteobject_p2.do?odl="+collId+"&oType=collection&pId="+escape(pId);
	}
	
	request.onreadystatechange=function()
	{
	 if(request.readyState==4)
	 {
	  if(request.status==200)
	  {
	  	document.location = locReturn;
	  }
	  else if(request.status==500)
	   alert("You found an opportunity for improvement! Please try again later");
	  else
	   alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
	 }
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send(''); 
}	

SNI.Community.Widgets.uncheckdelete = function(){
	for(var i=0;i<SNI.Community.Widgets.globalDeleteArrayId.length;i++)
	{
		var curObj = document.getElementById(SNI.Community.Widgets.globalDeleteArrayId[i]);
		if(curObj){
			curObj.checked = false;
		} 
	}	
}	

SNI.Community.Widgets.goBackPage = function(){
	//SNI.Community.Widgets.deleteItemsBack();
	var where_to= confirm("Are you sure you want to delete?");
	if(where_to)
	{
		SNI.Community.Widgets.deleteItemsBack();
	}
	//SNI.Community.Widgets.uncheckdelete();
	//window.history.go(-1);
}

SNI.Community.Widgets.changePhoto = function(photoId,collectionId){
	var url = base_Url+"/savechangefeaturephoto.do?sdl="+photoId+"&collectionid="+collectionId;
	simplePost(url,"SNI.Community.Widgets.changedSuccesfully()");
}

SNI.Community.Widgets.changePhoto = function(photoId,collectionId,isFeature){
	if(isFeature=="feature")
	{
		alert("This is already a Feature Item.");
		return;
	}
	var url = "/savechangefeaturephoto.do?sdl="+photoId+"&collectionid="+collectionId;
	simplePost(url,"SNI.Community.Widgets.changedSuccesfully()");
}
	
SNI.Community.Widgets.changedSuccesfully = function(){
	alert("The cover image has been changed successfully.");
}
//End step3 code

//End Collections uplaod related code

//Collections edit code start
SNI.Community.Widgets.mingleWithExistingEdit = function(){
	document.getElementById('isold').value = "1";
	document.f2.submit();
}

SNI.Community.Widgets.changeModeEdit = function(){
	//var where_to= confirm("Are you sure you want to delete?");
	//if(where_to)
	//{
		document.getElementById('editmode').value="delete";
		document.f2.submit();
	//}
}

SNI.Community.Widgets.goBackPageEdit = function(){
	selectedTab = 2;
	SNI.Community.Widgets.saveChanges();
}

SNI.Community.Widgets.setSortOrder = function(){
	SNI.Community.Widgets.setSortOrderValues();
	doSubmitUpload();
}

SNI.Community.Widgets.setSortOrderValues = function(){
	var result = $('#sortable').sortable('toArray');
	if(document.getElementById('setarrayid').value != result){
	 document.getElementById('cOrder').value = "true";
	}
	document.getElementById('setarrayid').value = result;
	document.getElementById('setobjectarrayid').value = result;
}


SNI.Community.Widgets.saveChanges = function(){
	var myspaceT=SNI.Community.Widgets.removeCategorytag(document.getElementById('myspaceT').value);
	//alert("myspace : "+myspaceT);
	if(SNI.Community.Widgets.trim(myspaceT)=='Select'||myspaceT=='--Select--'){
	myspaceT='default';
	}
	
	document.getElementById('returnurl').value = firstPart;
	//alert(document.getElementById('returnurl').value);
	//return;
	var spaceType=document.getElementById('myspaceT').value;
	var caption=document.getElementById('caption').value;
	var desc=document.getElementById('desc').value;
	page=document.getElementById('detail').value;
	SNI.Community.Widgets.setSortOrderValues();
	
	var taxMapSize = 0;
	
	if( document.getElementById('taxMapSize') ){
		taxMapSize = document.getElementById('taxMapSize').value;
	}
	
	if(parseInt(taxMapSize) == 0){
		spaceType = "without taxonomy"; // Just for condition check
	}	
	
	
	document.getElementById('errorMessage').innerHTML="";
	document.getElementById('errorMessage1').innerHTML="";
	
	if(parseInt(selectedTab)==2 && parseInt(deleteCountMax)==parseInt(SNI.Community.Widgets.deleteIds.length)){
		//SNI.Community.Widgets.uncheckdelete();
		var where_to= confirm("Are you sure you want to delete?");
		if(where_to)
		{
			var a = ""+window.location;
			a = a.replace(/#/g, "");
			a = a.replace(/&show_this=editdesc/g,"");
			a = a.replace(/&show_this=editdetails/g,"");
			a += "&show_this=upload"
			//document.getElementById('deleteids').value = "";
			document.getElementById('loc_return_con').value = "true";
			document.getElementById('del_returnurl').value = a;
			//document.location = a;
			document.f2.submit();
		}
		return;			
	}
	
	if(spaceType==''){
		if(page=="detailPage"){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById('errorMessage').innerHTML="<li><p id=\"errortext\">Please fill out all the required fields.</p></li>";
		document.getElementById("spaceLabel").className = "error-field"; 
		}
	}
	else if(spaceType!=''){
	if(page=="detailPage"){
		document.getElementById('errorMessage').innerHTML="";
		document.getElementById("spaceLabel").className = "";
		} 
	}

	if(caption==''){
	if(page=="detailPage"){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";		
		document.getElementById('errorMessage').innerHTML="<li><p id=\"errortext\">Please fill out all the required fields.</p></li>";
		document.getElementById("captionLabel").className = "error-field";
		} 
	}
	else if(caption!=''){
	if(page=="detailPage"){
		
	document.getElementById('errorMessage1').innerHTML="";
		document.getElementById("captionLabel").className = "";
	}
	}
	
	var mandantayCheck = true;
	var mandontaryTemp2 = '';
	if( page=="detailPage" )
		mandontaryTemp2 = mandontary+'';
	
	if(SNI.Community.Widgets.trim(desc)=='' && mandontaryTemp2.indexOf("uploadDescription_txt")!=-1 ){
		if(page=="detailPage"){
			mandantayCheck=false;
			document.getElementById('cgp-id-page-itemsaved').style.display = "block";		
			document.getElementById('errorMessage').innerHTML="<li><p id=\"errortext\">Please fill out all the required fields.</p></li>";
			document.getElementById("descLabel").className = "error-field";
		} 
	}
	else if(SNI.Community.Widgets.trim(desc)!=''){
		if(page=="detailPage"){
			document.getElementById('errorMessage1').innerHTML="";
			document.getElementById("descLabel").className = "";
		}
	}
	
	if(page=="detailPage"){
		if((caption!='')&&(spaceType!='') && mandantayCheck){
			document.getElementById('cgp-id-page-itemsaved').style.display = "none";
			SNI.Community.Widgets.saveButtonLoading();
			setTimeout('SNI.Community.Widgets.formSubmitEditUpload()', 1000); // 1 second wait
			//document.f2.submit();
		}
	}
	if(page=="descriptionPage"){
		SNI.Community.Widgets.saveButtonLoading();
		setTimeout('SNI.Community.Widgets.formSubmitEditUpload()', 1000); // 1 second wait
		//document.f2.submit();
	}
}

SNI.Community.Widgets.formSubmitEditUpload = function(){
	document.f2.submit();
}	

SNI.Community.Widgets.saveButtonLoading = function(){
	SNI.Community.Widgets.displayOff("com_save_cancel_button");
	SNI.Community.Widgets.displayOn("save_button_loading");	
}

SNI.Community.Widgets.saveButtonHideLoading = function(){
	SNI.Community.Widgets.displayOn("com_save_cancel_button");
	SNI.Community.Widgets.displayOff("save_button_loading");	
}


SNI.Community.Widgets.prevAction = "";
SNI.Community.Widgets.open_obj = function(val,obj)
{
	selectedTab=val;
	document.getElementById('cgp-newedit-new-space-upload-button').style.display = "none";
	
	if(document.getElementById('cgp-newedit-new-space-create-button'))
		document.getElementById('cgp-newedit-new-space-create-button').style.display = "none";

	if(document.getElementById('cgp-newedit-new-space-save-button'))
		document.getElementById('cgp-newedit-new-space-save-button').style.display = "none";
		
	if(document.getElementById('cgp-id-page-itemdelete'))
		document.getElementById('cgp-id-page-itemdelete').style.display = "none";
	
	document.getElementById('widnav-edit-info').className = "widget-nav-item-off";
	document.getElementById('widnav-edit-photo').className = "widget-nav-item-off";
	document.getElementById('widnav-add-more').className = "widget-nav-item-off";	
	
	obj.className = "widget-nav-item"; 
	
	//document.getElementById('widget-nav-item').id = "widget-nav-item-off";
	//obj.id = "widget-nav-item";

	//try{
		if(parseInt(val)==3){			
			document.getElementById('cgp-newedit-new-space-upload-button').style.display = "block";
			SNI.Community.Widgets.deleteAllDiv();
			if(document.getElementById('cgp-newedit-new-space-create-button'))
				document.getElementById('cgp-newedit-new-space-create-button').style.display = "none";
				
			if(document.getElementById('cgp-newedit-new-space-save-button'))
				document.getElementById('cgp-newedit-new-space-save-button').style.display = "none";
				
		}else{
			if( document.getElementById('cgp-newedit-new-space-create-button') )
				document.getElementById('cgp-newedit-new-space-create-button').style.display = "block";
				
			if( document.getElementById('cgp-newedit-new-space-save-button') )
				document.getElementById('cgp-newedit-new-space-save-button').style.display = "block";
				
		}	
		if(parseInt(val)==1){
			document.getElementById('detail').value="detailPage";
		}
		if(parseInt(val)==2){
			document.getElementById('detail').value="descriptionPage";
			//SNI.Community.Widgets.deleteAllDiv();
			if(parseInt(deleteCountMax)==0){
				document.getElementById('cgp-mewedit-edit-uploaded').style.display = "none";
				document.getElementById('capText').style.display = "none";
				if( document.getElementById('cgp-newedit-new-space-create-button') )
					document.getElementById('cgp-newedit-new-space-create-button').style.display = "none";
				if( document.getElementById('cgp-newedit-new-space-save-button') )
					document.getElementById('cgp-newedit-new-space-save-button').style.display = "none";					
				document.getElementById('capNoItemText').style.display = "block";
			}else{
				SNI.Community.Widgets.deleteAllDiv();
				document.getElementById('capNoItemText').style.display = "none";
				document.getElementById('capText').style.display = "block";				
				document.getElementById('cgp-mewedit-edit-uploaded').style.display = "block";				
				//document.getElementById('cgp-newedit-new-space-create-button').style.display = "block";
			}
		}
			
		document.getElementById('div_1').style.display = "none";
		document.getElementById('div_2').style.display = "none";
		document.getElementById('div_3').style.display = "none";
	//}catch(e){}
	document.getElementById('div_'+val).style.display = "block";
}

SNI.Community.Widgets.showContent = function(){
	if(document.getElementById('cgp-pc-rightrail-int'))
	{
		window.clearInterval(int_obj);
			 document.getElementById('cgp-pc-rightrail-int').style.display="block";	
	}
}

SNI.Community.Widgets.editCancel = function(curObj){
	var retUrl = "#";
	
	var cEdSourceUrl = document.getElementById("cEdSourceUrl").value;
	var cEdDetailPageUrl = document.getElementById("cEdDetailPageUrl").value;
	
	if(SNI.Community.Widgets.trim(cEdSourceUrl)!=""){
		retUrl = document.getElementById('mainPageURL').href.replace(/gallery.esi/g,"detail");
		retUrl = document.getElementById('returnurl').value.replace(/gallery/g,"detail");
		retUrl = document.getElementById('mainPageURL').href.replace(/multigallery.esi/g,"detail");
		retUrl = document.getElementById('returnurl').value.replace(/multigallery/g,"detail");
	}else{
		retUrl = cEdDetailPageUrl;
	}
	
	/*
	if(retUrl.indexOf("detail.esi") == -1){
		retUrl += "/detail.esi"; 
	}	
	*/
	
	var caption = document.getElementById("tmp_obj_caption").value; //'<%--=objCaption--%>';
	var objId =  document.getElementById("cEdObjId").value;  
	var cEdObjIdParam = document.getElementById("cEdObjIdParam").value;  
	
	if(retUrl.indexOf("EdgeTagGeneratorServlet")==-1){
		//retUrl += "?"+cEdObjIdParam+"="+objId;
	}	
	else{
		retUrl += "&"+cEdObjIdParam+"="+objId;
	}	
	
	document.location = retUrl;
	
	//curObj.href = retUrl;
	//alert('curObj. :'+curObj.href);
}

/*Edit details code start here*/

SNI.Community.Widgets.changeSpaceValue = function(curObj){
	document.getElementById('tags').value=curObj.value;		
	SNI.Community.Widgets.changeCategory('','',curObj.value,false);
}

/*End edit details code*/

//End collections edit code

SNI.Community.Widgets.deleteAllPVCookie = function(){
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ){
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );		
		
		// and SNI.Community.Widgets.trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		if( cookie_name.indexOf("pickle_pv_") != -1 ){
			SNI.Community.Widgets.Delete_Cookie(cookie_name, '/', '');
		}
	}	
}

//Single mode collection upload




SNI.Community.Widgets.termsCheckSingleMode = function(){

	SNI.Community.Widgets.validationCheck = 0;	
	if(document.getElementById('chkTerms').checked){
	 	SNI.Community.Widgets.setUploadCountValue();
	    var uplCountObj = document.getElementById("upload_file_count");
	 		    
	    if(parseInt(uplCountObj.value)==0){
		    document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		    document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		    document.getElementById('errMessageT').innerHTML="<ul><li><p id=\"errortext\">Please Select a File.</p></ul></li>";
		    //document.getElementById('errMessageT').innerHTML="";
		    validationCheck = 1;
	    } 
	    else{
			document.getElementById('cgp-id-page-itemsaved').style.display = "none";
			var urNonUr = document.getElementById("gUpUrNonUr").value;

			var p2CreateCollValidation = false;
			var p2CreateCollNonUrValidation = false;

			if(SNI.Community.Widgets.trim(urNonUr) == "true"){
				p2CreateCollValidation = SNI.Community.Widgets.p2CreateCollectionValidation();
					
				if(p2CreateCollValidation){
					SNI.Community.Widgets.p2CreateCollection();
				}
			}	
			else{
				p2CreateCollValidation = SNI.Community.Widgets.p2CreateCollectionValidation();
				p2CreateCollNonUrValidation = SNI.Community.Widgets.p2CreateCollectionNonUrValidation();
								
				if(p2CreateCollNonUrValidation && p2CreateCollValidation){	
					SNI.Community.Widgets.p2CreateCollectionNonUr();
				}
			
			}		
	    } 				
	}
	else{
	
		if( document.getElementById('tcAlertText') ){
			document.getElementById('cgp-id-page-itemsaved').style.display = "block";
			document.getElementById('errMessageF').innerHTML="";
			document.getElementById('errMessageT').innerHTML="<ul><li><p id=\"errortext\">"+document.getElementById('tcAlertText').value+"</p></ul></li>";
			document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		}
		else{
			document.getElementById('cgp-id-page-itemsaved').style.display = "block";
			document.getElementById('errMessageF').innerHTML="";
			document.getElementById('errMessageT').innerHTML="<ul><li><p id=\"errortext\">Please read and agree to the Privacy Policy, Infringement Policy and Terms of Use.</p></ul></li>";
		}
		
	}		
}

SNI.Community.Widgets.p2CreateCollectionValidation = function(){
	var validationStatus = false;
	var spaceType=document.getElementById('spacetype').value;
	var caption=document.getElementById('caption').value;
	var desc=document.getElementById('desc').value;
	var tags=document.getElementById('tags').value;
	var taxMapSize = document.getElementById('taxMapSize').value;
	if(parseInt(taxMapSize) == 0){
		spaceType = "without taxonomy"; // Just for condition check
	}
	
	if( document.getElementById('errMessageT') )
		document.getElementById('errMessageT').innerHTML="";
		
	
	if(spaceType==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		document.getElementById("spaceTypeLabel").className = "error-field";
		if(document.getElementById('errMessageF')){
			document.getElementById('errMessageF').innerHTML = "";
		}			 
		validationCheck = 1;
	}
	else if(spaceType!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("spaceTypeLabel").className = "";
	}
	
	if(caption==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("capLabel").className = "error-field";
		document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		if(document.getElementById('errMessageF')){
			document.getElementById('errMessageF').innerHTML = "";
		}			
		validationCheck = 1;
	}
	else if(caption!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("capLabel").className = "";
	}
	if((spaceType=='')||(caption=='')){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		if(document.getElementById('errMessageF')){
			document.getElementById('errMessageF').innerHTML = "";
		}			
		validationCheck = 1;
	}
	else{
		document.getElementById('errMessageN').innerHTML="";
	}
	
	//Pickle-333
	var mandontarCheck=true;
	
	var mandontaryTemp2 = mandontary+'';
	var uploadDescription = '';
	if( document.getElementById("desc") )
		uploadDescription = document.getElementById("desc").value;
	if(mandontaryTemp2.indexOf("uploadDescription_txt")!=-1 && SNI.Community.Widgets.trim(uploadDescription)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("descLabel").className = "error-field";
		mandontarCheck=false;
		document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		if(document.getElementById('errMessageF')){
			document.getElementById('errMessageF').innerHTML = "";
		}
		validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(uploadDescription)!=''){
		if( SNI.Community.Widgets.validationCheck = 0 ) {
			document.getElementById('errMessageN').innerHTML="";
		}
		document.getElementById("descLabel").className = "";		
	}
	if((caption!='')&&(spaceType!='') && mandontarCheck){
		validationStatus = true;
	}
	return validationStatus;
}

SNI.Community.Widgets.p2CreateCollectionNonUrValidation = function(){
	var validationStatus = false;

	var userEmail = document.getElementById('userEmail_txt').value;

	var emailCheck = SNI.Community.Widgets.isEmail(document.getElementById('userEmail_txt'));

		var caption=document.getElementById('caption').value;
		
	var mandontaryTemp = mandontary+'';
	
	if(document.getElementById('errMessageT')){
		document.getElementById('errMessageT').innerHTML = "";
	}
		
	if(document.getElementById('errMessageF')){
		document.getElementById('errMessageF').innerHTML = "";
	}
	
	if( mandontaryTemp.indexOf("userEmail_txt")!=-1 && ( SNI.Community.Widgets.trim(userEmail) =='' || emailCheck == true ) ){

		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("userEmail_Label").className = "error-field";
		document.getElementById('errMessageT').innerHTML="<ul><li><p id=\"errortext\">Please enter a valid e-mail address in the E-mail Address field.</p></li></ul>";
		mandFound = true;
		return false;
	}
	else if(SNI.Community.Widgets.trim(userEmail)!=''){
		if( SNI.Community.Widgets.validationCheck = 0 ) {
			document.getElementById('errMessageN').innerHTML="";
		}
		document.getElementById("userEmail_Label").className = "";
	}
	
	var displayName = '';
	
	if( document.getElementById('displayName_txt') )
		displayName = document.getElementById('displayName_txt').value;
	
	if( mandontaryTemp.indexOf("displayName_txt")!=-1 && SNI.Community.Widgets.trim(displayName)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("displayName_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		validationCheck = 1;
	}
	else if(displayName!=''){
		if( SNI.Community.Widgets.validationCheck = 0 ) {
			document.getElementById('errMessageN').innerHTML="";
		}
		document.getElementById("displayName_Label").className = "";
	}
	
	var firstName = '';
	if( document.getElementById('firstName_txt') )
		firstName = document.getElementById('firstName_txt').value;
	
	if( mandontaryTemp.indexOf("firstName_txt")!=-1 && SNI.Community.Widgets.trim(firstName)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("firstName_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(firstName)!=''){
		if( SNI.Community.Widgets.validationCheck = 0 ) {
			document.getElementById('errMessageN').innerHTML="";
		}
		document.getElementById("firstName_Label").className = "";
	}	
	var lastName = '';
	if( document.getElementById("lastName_txt") )
		lastName = document.getElementById("lastName_txt").value;
	
	if( mandontaryTemp.indexOf("lastName_txt")!=-1 && SNI.Community.Widgets.trim(lastName)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("lastName_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(lastName)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("lastName_Label").className = "";
	}
	
	var streetAddress = '';
	if( document.getElementById("streetAddress_txt") )
		streetAddress = document.getElementById("streetAddress_txt").value;
	if( mandontaryTemp.indexOf("streetAddress_txt")!=-1 && SNI.Community.Widgets.trim(streetAddress)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("streetAddress_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(streetAddress)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("streetAddress_Label").className = "";
	}
	
	var streetAddress2 = '';
	if( document.getElementById("streetAddress2_txt") )
		streetAddress2 = document.getElementById("streetAddress2_txt").value;
	if( mandontaryTemp.indexOf("streetAddress2_txt")!=-1 && SNI.Community.Widgets.trim(streetAddress2)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("streetAddress2_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(streetAddress2)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("streetAddress2_Label").className = "";
	}

	
	var state = '';
	if( document.getElementById("state_txt") )
		state = document.getElementById("state_txt").value;
	if(mandontaryTemp.indexOf("state_txt")!=-1 && SNI.Community.Widgets.trim(state)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("state_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(state)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("state_Label").className = "";		
	}	
	
	
	var city = '';
	if( document.getElementById("city_txt") )
		city = document.getElementById("city_txt").value;
	if(mandontaryTemp.indexOf("city_txt")!=-1 && SNI.Community.Widgets.trim(city)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("city_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(city)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("city_Label").className = "";		
	}	
	
	var postal = '';
	if( document.getElementById("zipCode_txt") )
		postal = document.getElementById("zipCode_txt").value;
	if(mandontaryTemp.indexOf("zipCode_txt")!=-1 && SNI.Community.Widgets.trim(postal)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("zipCode_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(postal)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("zipCode_Label").className = "";		
	}		
	
	var phone1 = '';
	if( document.getElementById("phone_txt") )
		phone1 = document.getElementById("phone_txt").value;
	if(mandontaryTemp.indexOf("phone_txt")!=-1 && SNI.Community.Widgets.trim(phone1)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("phone_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(phone1)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("phone_Label").className = "";		
	}
	
	var phone2 = '';
	if( document.getElementById("phone2_txt") )
		phone2 = document.getElementById("phone2_txt").value;
	if(mandontaryTemp.indexOf("phone2_txt")!=-1 && SNI.Community.Widgets.trim(phone2)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("phone2_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		SNI.Community.Widgets.validationCheck = 1;
	}
	else if(SNI.Community.Widgets.trim(phone2)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("phone2_Label").className = "";		
	}
	
	var country = '';
	if( document.getElementById("country_txt") )
		country = document.getElementById("country_txt").value;
	if(mandontaryTemp.indexOf("country_txt")!=-1 && SNI.Community.Widgets.trim(country)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("country_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(country)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("country_Label").className = "";		
	}
	
	
	var gender = '';
	if( document.getElementById("gender_txt") )
		gender = document.getElementById("gender_txt").value;
	if(mandontaryTemp.indexOf("gender_txt")!=-1 && SNI.Community.Widgets.trim(gender)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("gender_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(gender)!=''){
		if( SNI.Community.Widgets.validationCheck = 0 ) {
			document.getElementById('errMessageN').innerHTML="";
		}
		document.getElementById("gender_Label").className = "";		
	}
	
	var aboutme = '';
	if( document.getElementById("aboutme_txt") )
		aboutme = document.getElementById("aboutme_txt").value;
	if(mandontaryTemp.indexOf("aboutme_txt")!=-1 && SNI.Community.Widgets.trim(aboutme)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("aboutme_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(aboutme)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("aboutme_Label").className = "";		
	}
	
	
	var custom1 = '';
	if( document.getElementById("custom_txt") )
		custom1 = document.getElementById("custom_txt").value;
	if(mandontaryTemp.indexOf("custom_txt")!=-1 && SNI.Community.Widgets.trim(custom1)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("custom_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(custom1)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("custom_Label").className = "";		
	}
	
	var custom2 = '';
	if( document.getElementById("custom2_txt") )
		custom2 = document.getElementById("custom2_txt").value;
	if(mandontaryTemp.indexOf("custom2_txt")!=-1 && SNI.Community.Widgets.trim(custom2)==''){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("custom2_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(custom2)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("custom2_Label").className = "";		
	}
	
	var month = '';
	if( document.getElementById("month_txt") )
		month = document.getElementById("month_txt").value;
	if(mandontaryTemp.indexOf("month_txt")!=-1 && ( SNI.Community.Widgets.trim(month)=='MM' || SNI.Community.Widgets.trim(month)=='' )){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("dob_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(month)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("dob_Label").className = "";		
	}
	var year = '';
	if( document.getElementById("year_txt") )
		year = document.getElementById("year_txt").value;
	if(mandontaryTemp.indexOf("year_txt")!=-1 &&  ( SNI.Community.Widgets.trim(year)=='YYYY' || SNI.Community.Widgets.trim(year)=='' ) ){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("dob_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(year)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("dob_Label").className = "";		
	}
	
	var date = '';
	if( document.getElementById("date_txt") )
		date = document.getElementById("date_txt").value;
	if(mandontaryTemp.indexOf("date_txt")!=-1 &&  ( SNI.Community.Widgets.trim(date)=='DD' || SNI.Community.Widgets.trim(date)=='' ) ){
		document.getElementById('cgp-id-page-itemsaved').style.display = "block";
		document.getElementById("dob_Label").className = "error-field";
		//document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
	}
	else if(SNI.Community.Widgets.trim(date)!=''){
		document.getElementById('errMessageN').innerHTML="";
		document.getElementById("dob_Label").className = "";		
	}
	
	var mandFound=false;
	for( var i=0;i<mandontary.length;i++){
		var ibj = document.getElementById( mandontary[i] );
		if( ibj && SNI.Community.Widgets.trim( ibj.value) == ''){
			mandFound = true;
			document.getElementById('cgp-id-page-itemsaved').style.display = "block";
			document.getElementById('errMessageN').innerHTML="<ul><li><p id=\"errortext\">Please fill out all the required fields.</p></li></ul>";
		}
	}
	
	if( !mandFound ){
		validationStatus = true;
	}
	
	return validationStatus;
}	

SNI.Community.Widgets.p2CreateCollection = function(){
	var url = document.getElementById("gAjaxUrl").value;
	var reqParams = "";
	
	var userid = document.getElementById("gUserId").value;
	var urNonUr = document.getElementById("gUpUrNonUr").value;
	var siteId = document.getElementById("siteId").value;
	var wid = document.getElementById("gWid").value;
	var originalProjId = document.getElementById("gUpOrigProjId").value;
	var isold = document.getElementById("isold").value;
	var mediaPath = document.getElementById("gUpMediaPath").value;
	
	var caption = document.getElementById("caption").value;
	var tags = document.getElementById("tags").value;
	var publicTags = document.getElementById("public_tags").value; 
	var desc =  document.getElementById("desc").value; 
	var fromEmailAddress = document.getElementById("userEmail").value;  
	var userDisplayName = document.getElementById("userDisplayName").value;
	var parentObjectId = document.getElementById("parentId").value;  
	var objectStatus = document.getElementById("objectStatus").value; 
	var category = document.getElementById("spacetypelist").value; 	
	
	var containerIds = document.getElementById("gLContainerId").value;
	var widProjId = document.getElementById("gLWidPid").value;
	
	url += "/p2_createcollection.do";
	
	reqParams = "ajax=true&showstep=step2&ur="+urNonUr+"&userid="+userid;
	reqParams += "&caption="+escape(caption)+"&tags="+escape(tags)+"&public_tags="+escape(publicTags);
	reqParams += "&desc="+escape(desc)+"&userEmail="+escape(fromEmailAddress)+"&parentId="+parentObjectId;
	reqParams += "&userDisplayName="+escape(userDisplayName);
	reqParams += "&objectStatus="+objectStatus+"&spacetypelist="+escape(category);
	reqParams += "&wid="+wid+"&isold="+isold+"&siteId="+siteId+"&originalProjId="+originalProjId;
	reqParams += "&containerIds="+containerIds+"&widProjId="+widProjId;
	reqParams += "&mediaPath="+mediaPath;
	
	SNI.Community.Widgets.p2CreateCollectionAJAX(url,reqParams);
	//postWithParam(url,"SNI.Community.Widgets.afterP2CreateCollection()", reqParams)
}

SNI.Community.Widgets.p2CreateCollectionNonUr = function()
{
	//alert("here");
	
	var url = document.getElementById("gAjaxUrl").value;
	var reqParams = "";
	
	var emailAddress = "";
	var DisplayName = "";
	var FirstName="";
	var LastName = "";
	var StreetAddress1 = "";
	var StreetAddress2 = "";
	var City = "";
	var State = "";
	var Country = "";
	var ZipCode = "";
	var Phone1 = "";
	var Phone2 = "";
	var month = "";
	var date = "";
	var year = "";
	var Gender = "";
	var AboutMe = "";
	var Customtxt1="";
	var Customtxt2="";
	var  urlst="";
	var optCount=0;
	var pvuid="";
	var originalprojectId="";
	var userid="";
	/*var userInfoArray=new Array('userEmail_txt','displayName_txt','firstName_txt','lastName_txt','streetAddress_txt','streetAddress2_txt','city_txt','state_txt','country_txt','zipCode_txt');
	var urlst=""
	
	
	for(i=0;i<userInfoArray.length;i++)
	{
		var userInfoArray[i]="";
		if(document.getElementById(userInfoArray[i])){
			userInfoArray[i] = document.getElementById(userInfoArray[i]).value;
		alert(userInfoArray[i]);
		}
		urlst+=userInfoArray[i]=escape(userInfoArray[i]);
	}*/
	
	if(document.getElementById("userEmail_txt")){
		emailAddress = document.getElementById("userEmail_txt").value;
		urlst="userEmail_txt="+escape(emailAddress);
		//alert("emailAddress :"+emailAddress);
	}
	
	if(document.getElementById("displayName_txt")){
		DisplayName = document.getElementById("displayName_txt").value; 
		urlst+="&displayName_txt="+escape(DisplayName);
		//alert("DisplayName :"+DisplayName);
	}
	
	if(document.getElementById("firstName_txt")){
		FirstName = document.getElementById("firstName_txt").value;
		urlst+="&firstName_txt="+escape(FirstName);
		//alert("FirstName :"+FirstName);
	}
	
	if(document.getElementById("lastName_txt")){
		LastName = document.getElementById("lastName_txt").value;
		urlst+="&lastName_txt="+escape(LastName);
		//alert("LastName :"+LastName);
	}
	
	if(document.getElementById("streetAddress_txt")){
		StreetAddress1 = document.getElementById("streetAddress_txt").value;
		urlst+="&streetAddress_txt="+escape(StreetAddress1);
		//alert("StreetAddress1 :"+StreetAddress1);
	}	
	
	if(document.getElementById("streetAddress2_txt")){
		StreetAddress2 = document.getElementById("streetAddress2_txt").value;
		urlst+="&streetAddress2_txt="+escape(StreetAddress2);
			//alert("StreetAddress2 :"+StreetAddress2);
	}	
	
	if(document.getElementById("city_txt")){
		City = document.getElementById("city_txt").value;
		urlst+="&city_txt="+escape(City);
			//alert("City :"+City);
	}	
	
	if(document.getElementById("state_txt")){
		State = document.getElementById("state_txt").value;
		urlst+="&state_txt="+escape(State);
			//alert("State :"+State);
	}	
	
	if(document.getElementById("country_txt")){
		Country = document.getElementById("country_txt").value;
		urlst+="&country_txt="+escape(Country);
		//alert("Country :"+Country);
	}	
	
	if(document.getElementById("zipCode_txt")){
		ZipCode = document.getElementById("zipCode_txt").value;
		urlst+="&zipCode_txt="+escape(ZipCode);
		//alert("ZipCode :"+ZipCode);
	}	
	
	if(document.getElementById("phone_txt")){
		Phone1 = document.getElementById("phone_txt").value;
		urlst+="&phone_txt="+escape(Phone1);
		//alert("Phone1 :"+Phone1);
	}	
	
	if(document.getElementById("phone2_txt")){
		Phone2 = document.getElementById("phone2_txt").value;
		urlst+="&phone2_txt="+escape(Phone2);
		//alert("Phone2 :"+Phone2);
	}	
	
	if(document.getElementById("month_txt")){
		month = document.getElementById("month_txt").value;
		urlst+="&month_txt="+escape(month);
		//alert("month :"+month);
	}	
	
	if(document.getElementById("date_txt")){
		date = document.getElementById("date_txt").value;
		urlst+="&date_txt="+escape(date);
		//alert("date :"+date);
	}	
	
	if(document.getElementById("year_txt")){
		year = document.getElementById("year_txt").value;
		urlst+="&year_txt="+escape(year);
		//alert("year :"+year);
	}	
	
	if(document.getElementById("gender_txt")){
		Gender = document.getElementById("gender_txt").value;
		urlst+="&gender_txt="+escape(Gender);
		//alert("Gender :"+Gender);
	}	
	
	if(document.getElementById("aboutme_txt")){
		AboutMe = document.getElementById("aboutme_txt").value;
		urlst+="&aboutme_txt="+escape(AboutMe);
		//alert("AboutMe :"+AboutMe);
	}	
	if(document.getElementById("custom_txt")){
		Customtxt1 = document.getElementById("custom_txt").value;
		urlst+="&custom_txt="+escape(Customtxt1);
		//alert("Customtxt1 :"+Customtxt1);
	}	
	
	if(document.getElementById("custom2_txt")){
		Customtxt2 = document.getElementById("custom2_txt").value;
		urlst+="&custom2_txt="+escape(Customtxt2);
		//alert("Customtxt2 :"+Customtxt2);
	}
	
	if(document.getElementById("optCount")){
		optCount = document.getElementById("optCount").value;
		urlst+="&optCount="+escape(optCount);
		//alert("optCount :"+optCount);
	}
	
	for(i=0;i<optCount;i++)
	{
		try{
		  urlst+="&identifier"+i+"="+escape(document.getElementById("identifier"+i).value);
		  urlst+="&attrid"+i+"="+escape(document.getElementById("attrid"+i).value);
		  urlst+="&optcheck"+i+"="+escape(document.getElementById("optcheck"+i).checked);
		}catch(e){}
	}
	
	if(document.getElementById("pvuid")){
		pvuid = document.getElementById("pvuid").value;
		urlst+="&pvuid="+escape(pvuid);
		//alert("pvuid :"+pvuid);
	}
	
	if(document.getElementById("gUserId")){
		userid = document.getElementById("gUserId").value;
		urlst+="&userid="+escape(userid);
		//alert("userid :"+userid);
	}
	
	if(document.getElementById("originalprojectId")){
		originalprojectId = document.getElementById("originalprojectId").value;
		urlst+="&originalprojectId="+escape(originalprojectId);
		//alert("originalprojectId :"+originalprojectId);
	}
	
	
	//var userid = document.getElementById("gUserId").value;
	var urNonUr = document.getElementById("gUpUrNonUr").value;
	var siteId = document.getElementById("siteId").value;
	var wid = document.getElementById("gWid").value;
	var originalProjId = document.getElementById("gUpOrigProjId").value;
	var isold = document.getElementById("isold").value;
	var mediaPath = document.getElementById("gUpMediaPath").value;
	
	var caption = document.getElementById("caption").value;
	var tags = document.getElementById("tags").value;
	var publicTags = document.getElementById("public_tags").value; 
	var desc =  document.getElementById("desc").value; 
	var fromEmailAddress = document.getElementById("userEmail").value;  
	var userDisplayName = document.getElementById("userDisplayName").value;
	var parentObjectId = document.getElementById("parentId").value;  
	var objectStatus = document.getElementById("objectStatus").value; 
	var category = document.getElementById("spacetypelist").value; 	
	
	var containerIds = document.getElementById("gLContainerId").value;
	var widProjId = document.getElementById("gLWidPid").value;
	
	url += "/p2_createcollection.do";
	
	reqParams = "ajax=true&showstep=step2&ur="+urNonUr+"&userid="+userid;
	reqParams += "&caption="+escape(caption)+"&tags="+escape(tags)+"&public_tags="+escape(publicTags);
	reqParams += "&desc="+escape(desc)+"&userEmail="+escape(fromEmailAddress)+"&parentId="+parentObjectId;
	reqParams += "&userDisplayName="+escape(userDisplayName);
	reqParams += "&objectStatus="+objectStatus+"&spacetypelist="+escape(category);
	reqParams += "&wid="+wid+"&isold="+isold+"&siteId="+siteId+"&originalProjId="+originalProjId;
	reqParams += "&containerIds="+containerIds+"&widProjId="+widProjId;
	reqParams += "&mediaPath="+mediaPath;
	
	reqParams += "&"+urlst
	
	SNI.Community.Widgets.p2CreateCollectionAJAX(url,reqParams);
}

SNI.Community.Widgets.p2CreateCollectionAJAX = function(url,reqParams){
	
	var browLoca = document.location+"";
	
	if(browLoca.indexOf(":80/") == -1){
		url = url.replace(":80/","/");
	}	
	
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();

	//Initiate Uplaod progress bar
	
	alignPageCenter('progressbarstatuscontrol');
	SNI.Community.Widgets.displayOn('grey_background');
	SNI.Community.Widgets.displayOn('progressbarstatuscontrol');
	SNI.Community.Widgets.displayOn('processingStatus');
	
	request.onreadystatechange=function()
	{
		if(request.readyState==4){
 			if(request.status==200){
 				//alert("request :"+request.responseText);
 				var uploadUrl = document.getElementById("cUpUploadUrl").value;
 				var uplCountObj = document.getElementById("upload_file_count");
 				document.getElementById("parentid").value = request.responseText; 
				if(uploadUrl.indexOf("parentid=")==-1){
					uploadUrl += uplCountObj.value;
					uploadUrl += "&parentid="+request.responseText;  
					document.f1.action = uploadUrl;
				}

				var projectUrl = document.getElementById("projetcURL").value;
				
				var categoryTag = ""; 
				var titleText = "";
				
				if( document.getElementById("spacetypelist") ){
					categoryTag = document.getElementById("spacetypelist").value;
				}				

				if( document.getElementById("caption") ){
					titleText = document.getElementById("caption").value;
				}								
				var d2cUrl = SNI.Community.Widgets.generateD2CUrl(projectUrl,categoryTag,titleText,SNI.Community.Widgets.trim(request.responseText));
				SNI.Community.Widgets.fbPVObjectId = SNI.Community.Widgets.trim(request.responseText);
				SNI.Community.Widgets.fbPVCategory  = categoryTag;				
				if( document.getElementById("wid") ){
					SNI.Community.Widgets.fbPVWidgetId = document.getElementById("wid").value; 
				}
				var uploadModeAfterUploadURL = document.getElementById("cPVAfterUploadURL").value;
				
				if( SNI.Community.Widgets.trim(uploadModeAfterUploadURL) != ""){
					document.getElementById("afterUpload").value = uploadModeAfterUploadURL;
				}else{
					document.getElementById("afterUpload").value = d2cUrl;
				}	 				
 				
 				SNI.Community.Widgets.afterP2CreateCollection() 
 			}
			else if(request.status==500){
  				alert("You found an opportunity for improvement! Please try again later");

				SNI.Community.Widgets.displayOff('grey_background');
				SNI.Community.Widgets.displayOff('progressbarstatuscontrol');
				SNI.Community.Widgets.displayOff('processingStatus');
  			}	
 			else{
  				alert("There appears to be a connectivity problem. Please check your internet connection and try again.");

				SNI.Community.Widgets.displayOff('grey_background');
				SNI.Community.Widgets.displayOff('progressbarstatuscontrol');
				SNI.Community.Widgets.displayOff('processingStatus');
  			}	
		}
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send(reqParams);
}



SNI.Community.Widgets.afterP2CreateCollection = function(){
	SNI.Community.Widgets.startCallback();
	document.getElementById('sub').click();
	uploadCompleted(true,true);
}

//End single mode collection upload

SNI.Community.Widgets.showSingleEdit = function(){
	SNI.Community.Widgets.displayOff("cgp-id-page-image-image");
	SNI.Community.Widgets.displayOff("cgp-id-page-image-text");
	SNI.Community.Widgets.displayOff("collPhotoTag");
	SNI.Community.Widgets.displayOff("cgp-id-page-comment-top");
	SNI.Community.Widgets.displayOff("cgp-id-page-comments-area");
	SNI.Community.Widgets.displayOff("cgp-id-page-comment-bottom");
	SNI.Community.Widgets.displayOff("cgp-id-page-tool-bar");
	SNI.Community.Widgets.displayOff("cgp-id-page-description");
	
	SNI.Community.Widgets.displayOn("p2-d2cwide-cont");		
}

SNI.Community.Widgets.hideSingleEdit = function(){
	var userTagDisplay = document.getElementById("gUserTagDisplay").value;
	var tagSpan = document.getElementById("tagSpan").innerHTML;
	var itemDesc = document.getElementById("cgp-id-page-image-text").innerHTML;
	
	SNI.Community.Widgets.displayOff("p2-d2cwide-cont");

	SNI.Community.Widgets.displayOn("cgp-id-page-tool-bar");	
	SNI.Community.Widgets.displayOn("cgp-id-page-image-image");
	if(SNI.Community.Widgets.trim(itemDesc) != ""){
		SNI.Community.Widgets.displayOn("cgp-id-page-image-text");
	}
	if(SNI.Community.Widgets.trim(userTagDisplay)=="true"){
		SNI.Community.Widgets.displayOn("collPhotoTag");
	}
	SNI.Community.Widgets.displayOn("cgp-id-page-comment-top");
	SNI.Community.Widgets.displayOn("cgp-id-page-comments-area");
	SNI.Community.Widgets.displayOn("cgp-id-page-comment-bottom");
	
	if( document.getElementById('errorAlertMessage') && document.getElementById('saveMessage') ){
		document.getElementById('saveMessage').innerHTML= document.getElementById('errorAlertMessage').value;
	}

	SNI.Community.Widgets.saveButtonHideLoading();	
}

SNI.Community.Widgets.singleModeEdit = function(uType){

	//document.getElementById(
	var pvSyatemTag = "N/A";
	var pvCaption = "N/A";
	var userTagList="N/A";
	var objectText = "N/A";
	var pvCollectionId = "0";
	
	if(document.getElementById("cEdObjId")){
		pvCollectionId = document.getElementById("cEdObjId").value;
	}
	
	if(document.getElementById("gSystemTagList")){
		pvSyatemTag = document.getElementById("gSystemTagList").value; 
	}
	
	if(document.getElementById("caption")){
		pvCaption = document.getElementById("caption").value;
	}
	
	if(document.getElementById("public_tags")){
		userTagList = document.getElementById("public_tags").value;
	}
	
	if(document.getElementById("desc")){
		objectText = document.getElementById("desc").value;
	}	
	
	var uploadNonUr = "false";
	if(document.getElementById("uploadNonUr")){
		uploadNonUr = document.getElementById("uploadNonUr").value;
	}
	
	var qry;
	if(document.getElementById('qry')){
		qry =  document.getElementById("qry").value;
	}
		
	var para = "";
	var displayName="";
	var emailAddress="";
	para += pvSyatemTag;
	para += "<PICKLESEPERATOR>"+pvCaption;
	para += "<PICKLESEPERATOR>"+userTagList;
	para += "<PICKLESEPERATOR>"+objectText;
	para += "<PICKLESEPERATOR>"+pvCollectionId;

	SNI.Community.Widgets.saveButtonLoading();
	var widForPV = 0;
	if( document.getElementById("gWid") ){
		widForPV = document.getElementById("gWid").value;
	}

	var url= "/editsaveobjects.do?query="+qry+"&query_val="+escape(para)+"&ht="+pvCollectionId+"&cpur=true&wid="+widForPV+"&cp="+escape(document.location);
		
	simplePost(url,"SNI.Community.Widgets.singleModeAfterEdit('"+uType+"')");
}

SNI.Community.Widgets.singleModeAfterEdit = function(uType){
	var itemDesc = document.getElementById("desc").value;
	document.getElementById("objCaption_h1").innerHTML = document.getElementById("caption").value;
	
	if(SNI.Community.Widgets.trim(itemDesc) != ""){
	
		if( uType == 'internal'){
			document.getElementById("cgp-id-page-image-text").innerHTML =  "<p>"+SNI.Community.Widgets.repaceLineBreaks(document.getElementById("desc").value)+"</p>";
			document.getElementById("pObjDescription").innerHTML = SNI.Community.Widgets.repaceLineBreaks(document.getElementById("desc").value);
		}
		else{
			document.getElementById("cgp-id-page-image-text").innerHTML =  "<p>"+SNI.Community.Widgets.protectHTML(document.getElementById("desc").value)+"</p>";
			document.getElementById("pObjDescription").innerHTML = SNI.Community.Widgets.protectHTML(document.getElementById("desc").value);
		}
	}else{
		document.getElementById("cgp-id-page-image-text").innerHTML =  "";
		document.getElementById("pObjDescription").innerHTML = "";
	}
	if( uType == 'internal'){
		document.getElementById("tagSpan").innerHTML = SNI.Community.Widgets.repaceLineBreaks(document.getElementById("public_tags").value);
	}else{
		document.getElementById("tagSpan").innerHTML = SNI.Community.Widgets.protectHTML(document.getElementById("public_tags").value);
	}
	
	var tagSpan = document.getElementById("tagSpan").innerHTML;
	if(SNI.Community.Widgets.trim(tagSpan) != ""){
		document.getElementById("gUserTagDisplay").value = "true";
	}else{
		document.getElementById("gUserTagDisplay").value = "false";
	}
	SNI.Community.Widgets.hideSingleEdit();
}

SNI.Community.Widgets.singleRotate = function(object_id,rotate_direction,objSubType,purgeId){
	var bUrl = document.getElementById("gAjaxUrl").value;
	
	if(objSubType=="VIDEO" || objSubType=="video"){
		alert("Videos can't be rotated.");
		return;
	}

	var realUrl = document.getElementById("image_"+object_id).src;
	document.getElementById("image_"+object_id).src = document.getElementById('loading_image').src;
	var url = bUrl+"/rotateobject_p2.do?odl="+object_id+"&direction="+rotate_direction+"&purgeId="+purgeId+"&objType="+objSubType;
	simplePost(url,"emptyMethod('"+object_id+"','"+escape(realUrl)+"')");
}

SNI.Community.Widgets.drawIframeWidget = function(url,jsonUrl){
	document.writeln("<iframe id='pickle2container' name='pickle2container' src=\""+url+"\"  scrolling='no' height='0px' style='display:none;' width='0px' frameborder='0' ALLOWTRANSPARENCY='true'></iframe>");
	//document.writeln("<form name='p2_f1' id='p2_f1' action=\""+url+"\" method='post' target='pickle2container'>");
	//document.writeln("<input type='hidden' value='' name='includedcss' id='includedcss'>");
	//document.writeln("<input type='hidden' value='' name='includedjs' id='includedjs'>");
	//document.writeln("<input type='hidden' value='"+document.location+"' name='parenturl' id='parenturl'>");
	//document.writeln("</form>");
	//document.getElementById('includedcss').value = SNI.Community.Widgets.getPageElements("link");
	//document.getElementById('includedjs').value = SNI.Community.Widgets.getPageElements("script");
	var headID = document.getElementsByTagName("head")[0];
	//alert("head :"+headID.innerHTML);
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = jsonUrl;
	headID.appendChild(newScript);
	
	//document.getElementById('p2_f1').submit();
}
SNI.Community.Widgets.getPageElements = function(type)
{
		var links = document.getElementsByTagName(type);
	    var urls = "";
	    for(i=0;i<links.length;i++)
	     {
	     	if(i!=0)
	     		urls+= "__";
	     	if(type=="link")
	        	urls += links[i].href;
	        else if(type=="script")
	        	urls += links[i].src;	
	     }
	return urls;
}

SNI.Community.Widgets.setStyle = function(styleDef){
	document.getElementById("pickle2container").className = styleDef;
	document.getElementById("pickle2container").style.display = "block";
}
SNI.Community.Widgets.navigate = function(obj){
	if(parseInt(delivery_type)==1){
		window.parent.location = obj.href;
		return false;
	}
}

SNI.Community.Widgets.generateD2CUrl = function(projectUrl,categoryTag,titleText,objId){
	var d2cURL = projectUrl+"/";
	categoryTag =  categoryTag.replace(/[^a-zA-Z 0-9]+/g,'');
	categoryTag =  categoryTag.replace(/ /g,"-");
	categoryTag =  categoryTag.replace("Select","");
	categoryTag =  categoryTag.replace("select","");
	
	if( SNI.Community.Widgets.trim(categoryTag) != "" ){
		d2cURL += categoryTag+"/" 
	}

	titleText =  titleText.replace(/[^a-zA-Z 0-9]+/g,'');
	titleText =  titleText.replace(/ /g,"-");
	if( SNI.Community.Widgets.trim(titleText) != "" ){
		d2cURL += titleText+"/" 
	}
	
	d2cURL += "detail.esi?oid="+objId;
	
	return d2cURL;
}

SNI.Community.Widgets.changeJcauroselPageImage = function()
{
	var curJCarPagImgObj = "";
	var curJCarPagImgObjList = SNI.Community.Widgets.getElementsByClassName("jcarousel-pageimg", "div",document);
	
	for(var i=0;i<curJCarPagImgObjList.length;i++)
		curJCarPagImgObj = curJCarPagImgObjList[0];
		
	curJCarPagImgObj.style.top = "-20px";
}

SNI.Community.Widgets.protectHTML = function( input){
	
 	input = input.replace(/<b>/g,'&lt;b&gt;');
	input = input.replace(/<\/b>/g,'&lt;/b&gt;');
	input = input.replace(/<i>/g,'&lt;i&gt;');
	input = input.replace(/<\/i>/g,'&lt;/i&gt;');
	input = input.replace(/<u>/g,'&lt;u&gt;');
	input = input.replace(/<\/u>/g,'&lt;/u&gt;');
	
	input = input.replace(/</g,'&lt;');
	input = input.replace(/>/g,'&gt;');

	input = input.replace(/&lt;b&gt;/g,'<b>');
	input = input.replace(/&lt;\/b&gt;/g,'</b>');
	input = input.replace(/&lt;i&gt;/g,'<i>');
	input = input.replace(/&lt;\/i&gt;/g,'</i>');
	input = input.replace(/&lt;u&gt;/g,'<u>');
	input = input.replace(/&lt;\/u&gt;/g,'</u>');
	
	input = input.replace(/\n/g," <br/> ");
	
	input = input.replace(/ /g,"-$-");
	
	input = SNI.Community.Widgets.appendAnchorTag( input );
	
	return input;
} 

SNI.Community.Widgets.repaceLineBreaks = function( input ){
	input = input.replace(/\n/g," <br/> ");
	return input;
}

SNI.Community.Widgets.appendAnchorTag = function( input ){
	var result="";
	var arr2 = input.split("-$-");
	for( var j=0;j<arr2.length;j++){
		if( (arr2[j].indexOf('href=') ==-1) && (arr2[j].indexOf('value=') ==-1) && (arr2[j].indexOf('src=') ==-1) && (arr2[j].indexOf('http://') != -1 || 
			arr2[j].indexOf('www.') != -1)   ){
				if( arr2[j].substring(0,3) == 'www' )
					result = result+"<a href='http://"+arr2[j]+"' />"+arr2[j]+"</a>"+" ";
				else
					result = result+"<a href='"+arr2[j]+"' />"+arr2[j]+"</a>"+" ";		
		}
		else{
			result = result+arr2[j]+" ";
		}
	}
	return result;
}

SNI.Community.Widgets.setCookie = function(sortOrder, objectId){
	SNI.Community.Widgets.Set_Cookie( "pickle_pv_sort_order",sortOrder, '365', '/', '', '' );
	SNI.Community.Widgets.Set_Cookie( "pickle_pv_time_frame",'0', '365', '/', '', '' );
}

SNI.Community.Widgets.setCookieTopLayout = function(sortOrder,timeFrame, objectId){
SNI.Community.Widgets.Set_Cookie( "pickle_pv_sort_order",sortOrder, '30000', '/', '', '' );
SNI.Community.Widgets.Set_Cookie( "pickle_pv_time_frame",timeFrame, '30000', '/', '', '' );
}
/*
* Call Search on hitting Enter Key
*/
SNI.Community.Widgets.ifEnter = function(field,event){
var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

if (theCode == 13){
SNI.Community.Widgets.pickleGlobalSearch();
return false;
} 
else
return true;

}

SNI.Community.Widgets.ifEnterStop = function(field,event){

var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

if (theCode == 13){
 	event.returnValue=false;
    event.cancel = true;
	return false;
} 
else{
return true;
}
}
/*
* Craousel Wrapper Code Starts
*/


SNI.Community.Widgets.Carousel = function(ele, config)
   {
      config = $.extend(
      {
         pause : null, scroll : 1, animation : "slow", auto : 0, wrap : null, pagelink : null, pagetext : null, start : 1
      }
      , config);
      var crsl_itemFirstInCallback = function(carousel, item, idx, state)
      {
         if(config["pagelink"] == "text")
         {
            var tmpText = config["pagetext"];
            tmpText = tmpText.replace(/_current/ig, idx);
            tmpText = tmpText.replace(/_total/ig, carousel["options"]["size"]);
            carousel.container.find(".jcarousel-pagetext").html(tmpText);
         }
         else if(config["pagelink"] == "image")
         {
            jQuery(ele).find('.jcarousel-pageimg a.current').removeClass("current");
            link = jQuery(ele).find('.jcarousel-pageimg a')[idx - 1];
            jQuery(link).addClass("current");
         }
      }
      ;
      var crsl_initCallback = function(carousel, state)
      {
         if((config["pagelink"] == "text") || (config["pagelink"] == "both"))
         {
            carousel.container.append('<div class="jcarousel-pagetext"></div>');
         }
         else if((config["pagelink"] == "image") || (config["pagelink"] == "both"))
         {
            var imgLinks = "";
            var total=0;
            for(var i = 1; i <= carousel["options"]["size"];
            i ++ )
            {
               imgLinks += '<a href="#'+i+'">' + i + '</a>';
               total++;
            }
            
            carousel.container.append('<div class="jcarousel-pageimg"></div>');
            jQuery(ele).find(".jcarousel-pageimg").append(imgLinks);
            jQuery(ele).find(".jcarousel-pageimg").css("left", parseInt($(ele).width()) / 2 - parseInt($(ele).find(".jcarousel-pageimg").width()) / 2);
            jQuery(ele).find('.jcarousel-pageimg a').bind('click', function()
	            {
	               carousel.scroll(jQuery.jcarousel.intval(jQuery(this).html()));
	               return false;
	            }
            );
          	if(total==1){
          		jQuery(ele).find(".jcarousel-pageimg").css("visibility","hidden");
          	}
         }
      }
      ;
      
	  var Fallback;
		
	  if ( jQuery(ele).find('.jcarousel-clip-horizontal').width() > 0 ){ 
		 Fallback = jQuery(ele).find('.jcarousel-clip-horizontal').width();
	  } 
	  else{ 	
		Fallback = 300;
	  }
      
      $(ele).find('.crsl').jcarousel(
      {
         scroll : config["scroll"], animation : config["slow"], auto : config["auto"], wrap : config["wrap"], itemFirstInCallback : crsl_itemFirstInCallback, initCallback : crsl_initCallback, start : config["start"], itemFallbackDimension: Fallback
         
      }
      );
      
      //, itemFallbackDimension: 300
      // itemFallbackDimension: 300
      // Added to .jcarousel(), to resolve PICKLE-3307
};

/*
Events API code Starts here ...
*/

if(typeof(SNI.Community.Widgets.Events)=='undefined' )
	SNI.Community.Widgets.Events = {}

SNI.Community.Widgets.Events.AllowFBPost = false;
SNI.Community.Widgets.Events.FBNAME = "NA";


SNI.Community.Widgets.Events.getLoggedUserName = function(){
	var userIds = new Array();
	userIds[0] = FB.Facebook.apiClient.get_session().uid;
	var requiredFeilds = new Array();
	requiredFeilds[0] = "first_name";
	FB.Facebook.apiClient.users_getInfo(userIds,requiredFeilds,SNI.Community.Widgets.Events.setFBValues);
}

SNI.Community.Widgets.Events.setFBValues = function(obj)
{
	SNI.Community.Widgets.Events.FBNAME = obj[0]['first_name'];
}

//SNI.Community.Widgets.Events.api_key = "39b77ff5c12c27773d69818884e401d8";
//SNI.Community.Widgets.Events.channel_path = "xd_receiver.htm";
//FB.init(SNI.Community.Widgets.Events.api_key, SNI.Community.Widgets.Events.channel_path, {"ifUserConnected": SNI.Community.Widgets.Events.getLoggedUserName});

SNI.Community.Widgets.Events.RZCommenting = function() {
	this._caption;
	this._postedname;
	this._ratingcount = 2;
	this._commenttext;
	this._objecturl;
	this._imageurl;
	this._onsite;
	this._callback = null;
	
	this.setCallBack = function(callback){
		this._callback = callback;
	};
	this.setObjectUrl = function(objecturl)
	  {
	    this._objecturl = objecturl;
	  };
	this.setCaption = function(caption)
	  {
	    this._caption = caption;
	  };
	this.setPostedBy = function(postedname)
	  {
	    this._postedname = postedname;
	  };
	this.setRatingCount = function(ratingcount)
	  {
	    this._ratingcount = ratingcount;
	  };
	this.setCommentText = function(commenttext)
	  {
	    this._commenttext = commenttext;
	  };
	this.setOnSite = function(sitename)
	  {
	    this._onsite = sitename;
	  };
	this.setImageURL = function(imageurl)
	  {
	    this._imageurl = imageurl;
	  };
	this.getXML = function(){
		var xml = "<rz-reviewed-<SID>>"+// Note :: <SID> should be replaced by the siteId while we fetch on fly .... 
					"<caption><![CDATA["+this._caption+"]]></caption>"+
					"<posted-name><![CDATA["+this._postedname+"]]></posted-name>"+
					"<rating-count><![CDATA["+this._ratingcount+"]]></rating-count>"+
					"<comment-text><![CDATA["+this._commenttext+"]]></comment-text>"+
					"<object-url><![CDATA["+this._objecturl+"]]></object-url>";
			try{		
					var imgurl = this._imageurl.split(",");
					for(i=0;i<imgurl.length;i++)
					{
						xml +=	"<img>"+
						   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
						   			"<href><![CDATA["+this._objecturl+"]]></href>"+
						   		"</img>";
					}
				}catch(e){}		
			xml +=	"<recipe-time><TIME></recipe-time>"+// Note :: TIME should be replaced by actual time of the event while fetching .... 
					"<less-than>&lt;</less-than>"+
    				"<greater-than>&gt;</greater-than>"+
    			  "</rz-reviewed-<SID>>";
	return xml;
	}	
	
	this.getFaceBookXML = function(){
    	var xml = "<fb-upload>"+
    				"<message><![CDATA["+this._commenttext+"]]></message>"+
    				"<name><![CDATA["+this._caption+"]]></name>"+
    				"<description><![CDATA["+SNI.Community.Widgets.Events.FBNAME+" rated this recipe "+this._ratingcount+" on "+this._onsite+"]]></description>"+
    				"<action-text>View this</action-text>"+
    				"<callbackurl><![CDATA["+this._callback+"]]></callbackurl>"+
   					"<action-text-link><![CDATA["+this._objecturl+"]]></action-text-link>";
   			try{		
		   			var imgurl = this._imageurl.split(",");
					for(i=0;i<imgurl.length;i++)
					{
						xml +=	"<img>"+
						   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
						   			"<href><![CDATA["+this._objecturl+"]]></href>"+
						   		"</img>";
					}
				}catch(e){}
						
    		  xml += "</fb-upload>";
    	return xml;
    }
    this.getCallBack = function(){
		return this._callback;
	}
	return this;	
}
SNI.Community.Widgets.Events.FBUpload = function(){
	this._fbfirstname;
	this._caption;
	this._onsite;
	this._imgurl;
	this._imghref;
	this._objecturl;
	this._desc;
	this._callback = null;
	
	this.setCallBack = function(callback){
		this._callback = callback;
	};
	this.setDesc = function(desc){
		this._desc = desc;
	}
	this.setObjectUrl = function(objecturl)
	  {
	    this._objecturl = objecturl;
	  };
	this.setCaption = function(caption)
	  {
	    this._caption = caption;
	  };
	this.setOnSite = function(sitename)
	  {
	    this._onsite = sitename;
	  };
	this.setImageUrl = function(imgurl)
	  {
	    this._imgurl = imgurl;
	  };
	this.setImageHREF = function(imghref)
	  {
	    this._imghref = imghref;
	  };
	this.getFaceBookXML = function(){
    	var xml = "<fb-upload>"+
    				"<message><![CDATA["+this._desc+"]]></message>"+
    				"<name><![CDATA["+this._caption+"]]></name>"+
    				"<callbackurl><![CDATA["+this._callback+"]]></callbackurl>"+
    				"<description><![CDATA["+SNI.Community.Widgets.Events.FBNAME+" added photo(s) on "+this._onsite+"]]></description>"+
    				"<action-text>View this</action-text>"+
   					"<action-text-link><![CDATA["+this._objecturl+"]]></action-text-link>";
   			var imgurl = this._imgurl.split(",");
   			//var imghref = this._imghref.split(",");
			for(i=0;i<imgurl.length;i++)
			{
				xml +=	"<img>"+
				   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
				   			"<href><![CDATA["+this._objecturl+"]]></href>"+
				   		"</img>";
			}
			   		
    		xml +="</fb-upload>";
    	return xml;
    }
    this.getCallBack = function(){
		return this._callback;
	}
    return this;
}


SNI.Community.Widgets.Events.RZTopicCommenting = function() {
	this._caption;
	this._topicname;
	this._ratingcount;
	this._commenttext;
	this._objecturl;
	this._onsite;
	this._callback = null;
	
	this.setCallBack = function(callback){
		this._callback = callback;
	};
	this.setOnSite = function(sitename)
	  {
	    this._onsite = sitename;
	  };
	this.setObjectUrl = function(objecturl)
	  {
	    this._objecturl = objecturl;
	  };
	this.setCaption = function(caption)
	  {
	    this._caption = caption;
	  };
	this.setTopicName = function(topicname)
	  {
	    this._topicname = topicname;
	  };
	this.setRatingCount = function(ratingcount)
	  {
	    this._ratingcount = ratingcount;
	  };
	this.setCommentText = function(commenttext)
	  {
	    this._commenttext = commenttext;
	  };
	this.getXML = function(){
		var xml = "<rz-topic-review-<SID>>"+// Note :: <SID> should be replaced by the siteId while we fetch on fly .... 
					"<caption><![CDATA["+this._caption+"]]></caption>"+
					"<topic-name><![CDATA["+this._topicname+"]]></topic-name>"+
					"<rating-count><![CDATA["+this._ratingcount+"]]></rating-count>"+
					"<comment-text><![CDATA["+this._commenttext+"]]></comment-text>"+
					"<object-url><![CDATA["+this._objecturl+"]]></object-url>"+
					"<on-site>Recipezaar</on-site>"+
					"<recipe-time><TIME></recipe-time>"+// Note :: TIME should be replaced by actual time of the event while fetching .... 
					"<less-than>&lt;</less-than>"+
    				"<greater-than>&gt;</greater-than>"+
    			  "</rz-topic-review-<SID>>";
	return xml;
	}	
	
	this.getFaceBookXML = function(){
    	var xml = "<fb-upload>"+
    				"<message><![CDATA["+this._commenttext+"]]></message>"+
    				"<name><![CDATA["+this._topicname+"]]></name>"+
    				"<callbackurl><![CDATA["+this._callback+"]]></callbackurl>"+
    				"<description><![CDATA["+SNI.Community.Widgets.Events.FBNAME+" started a new discussion on "+this._onsite+"]]></description>"+
    				"<action-text>Join the Discussion</action-text>"+
   					"<action-text-link><![CDATA["+this._objecturl+"]]></action-text-link>"+
			   	  "</fb-upload>";
    	return xml;
    }
    this.getCallBack = function(){
		return this._callback;
	}
    
	return this;	
}

SNI.Community.Widgets.Events.RZSave = function() {
	this._caption;
	this._postedname;
	this._objecturl;
	this._callback = null;
	
	this.setCallBack = function(callback){
		this._callback = callback;
	};
	this.setObjectUrl = function(objecturl)
	  {
	    this._objecturl = objecturl;
	  };
	this.setCaption = function(caption)
	  {
	    this._caption = caption;
	  };
	this.setPostedBy = function(postedname)
	  {
	    this._postedname = postedname;
	  };
	
	this.getXML = function(){
		var xml = "<rz-save-<SID>>"+// Note :: <SID> should be replaced by the siteId while we fetch on fly .... 
					"<caption><![CDATA["+this._caption+"]]></caption>"+
					"<posted-name><![CDATA["+this._postedname+"]]></posted-name>"+
					"<object-url><![CDATA["+this._objecturl+"]]></object-url>"+
					"<on-site>Recipezaar</on-site>"+
					"<recipe-time><TIME></recipe-time>"+// Note :: TIME should be replaced by actual time of the event while fetching .... 
					"<less-than>&lt;</less-than>"+
    				"<greater-than>&gt;</greater-than>"+
    			  "</rz-save-<SID>>";
	return xml;
	}
	this.getCallBack = function(){
		return this._callback;
	}	
	return this;	
}


SNI.Community.Widgets.Events.RZFan = function() {
	this._postedname;
	this._objecturl;
	this._callback = null;
	
	this.setCallBack = function(callback){
		this._callback = callback;
	};
	this.setObjectUrl = function(objecturl)
	  {
	    this._objecturl = objecturl;
	  };
	this.setFanOf = function(postedname)
	  {
	    this._postedname = postedname;
	  };
	
	//<xsl:value-of select="on-site"/>
	this.getXML = function(){
		var xml = "<rz-fan-<SID>>"+// Note :: <SID> should be replaced by the siteId while we fetch on fly .... 
					"<posted-name><![CDATA["+this._postedname+"]]></posted-name>"+
					"<object-url><![CDATA["+this._objecturl+"]]></object-url>"+
					"<callbackurl><![CDATA["+this._callback+"]]></callbackurl>"+
					"<on-site>Recipezaar</on-site>"+
					"<recipe-time><TIME></recipe-time>"+// Note :: TIME should be replaced by actual time of the event while fetching .... 
					"<less-than>&lt;</less-than>"+
    				"<greater-than>&gt;</greater-than>"+
    			  "</rz-fan-<SID>>";
	return xml;
	}
	this.getCallBack = function(){
		return this._callback;
	}	
	return this;	
}

SNI.Community.Widgets.Events.RZUpload = function() {
	this._caption;
	this._imageurls;
	this._objecturl;
	this._callback = null;
	
	this.setCallBack = function(callback){
		this._callback = callback;
	};
	this.setObjectUrl = function(objecturl)
	  {
	    this._objecturl = objecturl;
	  };
	this.setCaption = function(caption)
	  {
	    this._caption = caption;
	  };
	this.setImageUrls = function(imageurls)
	  {
	    this._imageurls = imageurls;
	  };
	
	this.getXML = function(){
		var xml = "<rz-upload-<SID>>"+// Note :: <SID> should be replaced by the siteId while we fetch on fly .... 
					"<caption><![CDATA["+this._caption+"]]></caption>";
			var imgurl = this._imageurls.split(",");
			for(i=0;i<imgurl.length;i++)
			{
				xml +=	"<img>"+
				   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
				   			"<href><![CDATA["+this._objecturl+"]]></href>"+
				   		"</img>";
			}				
			xml	+=	"<recipe-time><TIME></recipe-time>"+// Note :: TIME should be replaced by actual time of the event while fetching .... 
					"<on-site>Recipezaar</on-site>"+
					"<callbackurl><![CDATA["+this._callback+"]]></callbackurl>"+
					"<object-url><![CDATA["+this._objecturl+"]]></object-url>"+
					"<less-than>&lt;</less-than>"+
    				"<greater-than>&gt;</greater-than>"+
    			  "</rz-upload-<SID>>";
	return xml;
	}	
	
	this.getFaceBookXML = function(){
    	var xml = "<fb-upload>"+
    				"<message><![CDATA[]]></message>"+
    				"<name><![CDATA["+this._caption+"]]></name>"+
    				"<description><![CDATA["+SNI.Community.Widgets.Events.FBNAME+" added photo(s) on "+this._onsite+"]]></description>"+
    				"<action-text>View Recipe</action-text>"+
    				"<callbackurl><![CDATA["+this._callback+"]]></callbackurl>"+
   					"<action-text-link><![CDATA["+this._objecturl+"]]></action-text-link>";
   				var imgurl = this._imageurl.split(",");
				for(i=0;i<imgurl.length;i++)
				{
					xml +=	"<img>"+
					   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
					   			"<href><![CDATA["+this._objecturl+"]]></href>"+
					   		"</img>";
				}	
			   		
    		xml +="</fb-upload>";
    	return xml;
    }
    this.getCallBack = function(){
		return this._callback;
	}
    
	return this;	
}

SNI.Community.Widgets.Events.RZSharedRecipe = function() {
	this._caption;
	this._imageurl;
	this._desc;
	this._objecturl;
	this._callback = null;
	
	this.setCallBack = function(callback){
		this._callback = callback;
	};
	this.setObjectUrl = function(objecturl)
	  {
	    this._objecturl = objecturl;
	  };
	this.setCaption = function(caption)
	  {
	    this._caption = caption;
	  };
	this.setImageUrl = function(imageurl)
	  {
	    this._imageurl = imageurl;
	  };
	this.setDesc = function(desc)
	  {
	    this._desc = desc;
	  };
	this.getXML = function(){
		var xml = "<rz-shared-recipe-<SID>>"+// Note :: <SID> should be replaced by the siteId while we fetch on fly .... 
					"<caption><![CDATA["+this._caption+"]]></caption>";
			var imgurl = this._imageurl.split(",");
			for(i=0;i<imgurl.length;i++)
			{
				xml +=	"<img>"+
				   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
				   			"<href><![CDATA["+this._objecturl+"]]></href>"+
				   		"</img>";
			}			
					"<desc><![CDATA["+this._desc+"]]></desc>"+
					"<object-url><![CDATA["+this._objecturl+"]]></object-url>"+
					"<on-site>Recipezaar</on-site>"+
					"<recipe-time><TIME></recipe-time>"+// Note :: TIME should be replaced by actual time of the event while fetching .... 
					"<less-than>&lt;</less-than>"+
    				"<greater-than>&gt;</greater-than>"+
    			  "</rz-shared-recipe-<SID>>";
    	return xml;
	}	
	
	this.getFaceBookXML = function(){
    	var xml = "<fb-upload>"+
    				"<message><![CDATA["+this._desc+"]]></message>"+
    				"<name><![CDATA["+this._caption+"]]></name>"+
    				"<description><![CDATA["+SNI.Community.Widgets.Events.FBNAME+" shared this recipe on "+this._onsite+"]]></description>"+
    				"<action-text>View Recipe</action-text>"+
   					"<action-text-link><![CDATA["+this._objecturl+"]]></action-text-link>"+
   					"<callbackurl><![CDATA["+this._callback+"]]></callbackurl>";
				var imgurl = this._imageurl.split(",");
				for(i=0;i<imgurl.length;i++)
				{
					xml +=	"<img>"+
					   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
					   			"<href><![CDATA["+this._objecturl+"]]></href>"+
					   		"</img>";
				}			
			   		
    		xml +="</fb-upload>";
    	return xml;
    }
    this.getCallBack = function(){
		return this._callback;
	}
    
	return this;
}

SNI.Community.Widgets.Events.RZSharedCookBook = function() {
	this._caption;
	this._imageurl;
	this._recipecount;
	this._desc;
	this._objecturl;
	this._callback = null;
	
	this.setCallBack = function(callback){
		this._callback = callback;
	};
	this.setObjectUrl = function(objecturl)
	  {
	    this._objecturl = objecturl;
	  };
	this.setCaption = function(caption)
	  {
	    this._caption = caption;
	  };
	this.setImageUrl = function(imageurl)
	  {
	    this._imageurl = imageurl;
	  };
	this.setRecipeCount = function(recipecount)
	  {
	    this._recipecount = recipecount;
	  };
	this.setDesc = function(desc)
	  {
	    this._desc = desc;
	  };
	this.getXML = function(){
		var xml = "<rz-shared-cookbook-<SID>>"+// Note :: <SID> should be replaced by the siteId while we fetch on fly .... 
					"<caption><![CDATA["+this._caption+"]]></caption>"+
					"<no-of-recipes><![CDATA["+this._recipecount+"]]></no-of-recipes>";
			var imgurl = this._imageurl.split(",");
			for(i=0;i<imgurl.length;i++)
			{
				xml +=	"<img>"+
				   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
				   			"<href><![CDATA["+this._objecturl+"]]></href>"+
				   		"</img>";
			}			
				xml +=	"<desc><![CDATA["+this._desc+"]]></desc>"+
					"<object-url><![CDATA["+this._objecturl+"]]></object-url>"+
					"<on-site>Recipezaar</on-site>"+
					"<recipe-time><TIME></recipe-time>"+// Note :: TIME should be replaced by actual time of the event while fetching .... 
					"<less-than>&lt;</less-than>"+
    				"<greater-than>&gt;</greater-than>"+
    			  "</rz-shared-cookbook-<SID>>";
    	return xml;
	}	
	
	this.getFaceBookXML = function(){
    	var xml = "<fb-upload>"+
    				"<message><![CDATA["+this._desc+"]]></message>"+
    				"<name><![CDATA["+this._caption+"]]></name>"+
    				"<callbackurl><![CDATA["+this._callback+"]]></callbackurl>"+
    				"<description><![CDATA["+SNI.Community.Widgets.Events.FBNAME+" shared this cookbook on "+this._onsite+"]]></description>"+
    				"<action-text>View Cookbook</action-text>"+
   					"<action-text-link><![CDATA["+this._objecturl+"]]></action-text-link>";
   			
			var imgurl = this._imageurl.split(",");
			for(i=0;i<imgurl.length;i++)
			{
				xml +=	"<img>"+
				   			"<src><![CDATA["+imgurl[i]+"]]></src>"+
				   			"<href><![CDATA["+this._objecturl+"]]></href>"+
				   		"</img>";
			}			
			   		
    		xml +="</fb-upload>";
    	return xml;
    }
	this.getCallBack = function(){
		return this._callback;
	}
	return this;
}

SNI.Community.Widgets.Events.loadLocalXML = function(text){
  if (window.DOMParser)
	  {
	  parser=new DOMParser();
	  xmlDoc=parser.parseFromString(text,"text/xml");
	  }
	else // Internet Explorer
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async="false";
	  xmlDoc.loadXML(text);
	  } 
	return xmlDoc;
}

SNI.Community.Widgets.Events.loadXML = function(src){
	if (window.XMLHttpRequest)
	  {
	  xhttp=new XMLHttpRequest();
	  }
	else // Internet Explorer 5/6
	  {
	  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xhttp.open("GET",src,false);
	xhttp.send("");
	xmlDoc=xhttp.responseXML; 
	return xmlDoc;
}


SNI.Community.Widgets.Events.postToFB = function (xml,obj){
	if(!SNI.Community.Widgets.Events.allowFBPublish){
		eval(obj.getCallBack()+"()");
		return false;
	}
	
	try{
		if(parseInt(SNI.Community.Widgets.Events.fbUserId) != parseInt(FB.Facebook.apiClient.get_session().uid))
		{
			eval(obj.getCallBack()+"()");
			return false;
		}
	}catch(e){}
	
	var singleton=FB.Connect._singleton;
	if(parseInt(singleton._userInfo.shortStorySetting) != parseInt(FB.FeedStorySetting.autoaccept)){
		FB.Connect.showPermissionDialog("publish_stream", function(granted){
	   if(granted != ""){
			var singleton=FB.Connect._singleton;
		    singleton._userInfo.shortStorySetting = FB.FeedStorySetting.autoaccept;
		    SNI.Community.Widgets.Events.postToFB(xml,obj);
	   }else{
	
	   }
	});
	return false;
	}
	
	var xml=SNI.Community.Widgets.Events.loadLocalXML(xml);
	var xsl=SNI.Community.Widgets.Events.loadXML("/xsltemplate.xslt");
	if(!document.getElementById('hidden_div'))
	{
		var div_ele = document.createElement('div');
		div_ele.style.display = "none";
		div_ele.id = "hidden_div";
		document.getElementsByTagName('head')[0].appendChild(div_ele);
	}else{
		document.getElementById("hidden_div").innerHTML = "";
	}
	var js_code = "";
	if (window.ActiveXObject)
	  {
		js_code=xml.transformNode(xsl);
		document.getElementById("hidden_div").innerHTML=js_code;
	  }
	  else if (document.implementation
	  && document.implementation.createDocument)
	  {
		xsltProcessor=new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		js_code = xsltProcessor.transformToFragment(xml,document);
		document.getElementById("hidden_div").appendChild(js_code);
	  }
	eval(document.getElementById("hidden_div").innerHTML);
}

SNI.Community.Widgets.Events.RegisterBulkevent = function(site,bulkObject){
	for(i=0;i<bulkObject.length;i++)
	{
		SNI.Community.Widgets.Events.Registerevent(site,bulkObject[i]);
	}
}

SNI.Community.Widgets.Events.Registerevent = function(site,voObject){
	
	if(!SNI.Community.Widgets.Events.postFBEvent)
		return;
	var url = "/eventlog.do?";
	var params = "site="+site+"&allowfbpost=true&mdata="+escape(voObject.getXML());	
	 var request=document.all?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	 request.onreadystatechange=function()
	 {
	  if(request.readyState==4)
	  {
	   if(request.status==200)
	   { 	
			SNI.Community.Widgets.Events.postToFB(voObject.getFaceBookXML(),voObject);	
	   }    
	  }
	 }
	 request.open("POST",url+params,true);
	 request.setRequestHeader("content-type","text/plain;charset=UTF-8");
	 request.setRequestHeader("Content-length", params.length);
	 request.send(''); 
}
SNI.Community.Widgets.doAjaxPost = function (url,params,callBack){
	var request=document.all?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	 request.onreadystatechange=function()
	 {
	  if(request.readyState==4)
	  {
	   if(request.status==200)
	   {
	   		eval(callBack);
	   }    
	  }
	 }
	 request.open("POST",url+params,true);
	 request.setRequestHeader("content-type","text/plain;charset=UTF-8");
	 request.setRequestHeader("Content-length", params.length);
	 request.send(''); 
}

function doSubmitUpload(){
	if(document.getElementById('sub'))
		document.getElementById('sub').click();
}

SNI.Community.Widgets.loadPVComments =  function (){
	var commPageNumber = "1";
	if(document.getElementById("gCommentsPageNumber")){
		commPageNumber = document.getElementById("gCommentsPageNumber").value;	
		if( isNaN(commPageNumber) ){
			commPageNumber = 1;
		}else if( parseInt(commPageNumber)<0 ){
			commPageNumber = 1;
		}
	}
	
	//PICKLE-427 - commented out below two line
	//Fix starts here
	var commentPagenoParameter = SNI.Community.Widgets.getParameter("cpageno");
	if( isNaN(commentPagenoParameter) || (commentPagenoParameter==null) || (commentPagenoParameter=="null") || (commentPagenoParameter=="") ){
		commPageNumber = 1;	
	} else if(  parseInt(commentPagenoParameter)<0 ){
		commPageNumber = 1;
	}else{
		commPageNumber = parseInt(commentPagenoParameter);
	}
	// Fix ends here
	if(SNI.Community.Toolbox.cIsCommentEnabled)
		SNI.Community.Widgets.moveToPageInternal(commPageNumber); //Load comments
}



SNI.Community.Widgets.getParameter = function(attribute)
{
	var result = null;
	var temp_url = document.location+"";
	var attributeArr = "";
	if(temp_url.indexOf("?")!=-1)
	{
		temp_url = temp_url.substring(temp_url.indexOf("?")+1,temp_url.length);
		attributeArr = SNI.Community.Widgets.Split_into_Array(temp_url,"&");
	}
	if(attributeArr!="")
	{
		for(k=0;k<attributeArr.length;k++)
		{
			var temp = SNI.Community.Widgets.Split_into_Array(attributeArr[k],"=");
			if(temp[0]==attribute)
			{
				result = temp[1];
				break;
			}			
		}
	}
	return result;	
}
SNI.Community.Widgets.Split_into_Array=function(input,seperator)
{
	var temp = new Array();
	while(input.indexOf(seperator)!=-1)
	{
		temp[temp.length] = input.substring(0,input.indexOf(seperator));
		input = input.substring(input.indexOf(seperator)+1,input.length);
	}
	temp[temp.length] = input;
	return temp;
}

SNI.Community.Widgets.displayOnWithAlignCenter = function(obj,popUpDivId){
	var top_temp;
	var left_temp;
	var real_obj;
	if(obj.id){
		real_obj = $('#'+obj.id)
	}else if(obj != undefined){
		real_obj = $('#'+obj)
	}
	top_temp = real_obj.offset().top;
	left_temp = real_obj.offset().left;
	var left_min = 0;
	var top_min = 0;
	
		if(document.getElementById('fullwidth-wrapper'))
		{
		 	left_min = $('#fullwidth-wrapper').offset().left;
		 	if(document.getElementById('cgp-id-page-title-area'))
		 		left_min = (left_min*2)+35;
			top_min = $('#fullwidth-wrapper').offset().top;
		}else if(document.getElementById('diy-w'))
		{
			left_min = $('#diy-w').offset().left;
			if(document.getElementById('cgp-id-page-title-area'))
				left_min = (left_min*2)+35;
		 	top_min = $('#diy-w').offset().top;
		}else if(document.getElementById('main-bd')){
			left_min = $('#main-bd').offset().left;
			top_min = $('#main-bd').offset().top;
		}else if(document.getElementById('pkg-wrapper')){
			left_min = $('#pkg-wrapper').offset().left;
			top_min = $('#pkg-wrapper').offset().top;
		}else if(document.getElementById('col3container')){
			left_min = $('#col3container').offset().left;
			top_min = $('#col3container').offset().top;
		}
		if(!obj.id){
			if(obj=="cgp-id-comment-ad")
			{
				top_temp = top_temp - parseInt($('#com-signin').height());
			}else if(obj.indexOf("cmt_usr_img_")!=-1){
				top_temp = top_temp - 100;
			}
		}else{
			if(document.getElementById('site-wrapper'))
			{
				top_min = $('#site-wrapper').offset().top;
			}
		}
		$('#'+popUpDivId).css({position:"absolute" , top: (top_temp-top_min), left: (left_temp-left_min)}).show();
}

//Profile Flag - palani

SNI.Community.Widgets.secureFlagForUserProfile = function(userId){
	secureComponent("SNI.Community.Widgets.displayOn('flag_profile_"+userId+"')","YOU NEED TO BE SIGNED IN TO DO THAT.",'flaghref_profile_'+userId,6);
}

SNI.Community.Widgets.postFlagUserProfile = function(objId){
	SNI.Community.Toolbox.cAssetId = objId;	
	SNI.Community.Toolbox.cSelectedId = objId;
	SNI.Community.Widgets.flagCacheKeys = document.getElementById("globalPageCacheKeys").value;
	//SNI.Community.Widgets.flagChannelId = document.getElementById('chId_'+objId).value;
	SNI.Community.Widgets.flagRequestFrom = "profile";
	SNI.Community.Widgets.flagInAppCid = "";
	SNI.Community.Widgets.flagInAppOid = "";
	SNI.Community.Widgets.flagInAppProfileid = "";
	/*if( document.getElementById("disp_name_id") ){
		SNI.Community.Widgets.flagUploadBy = document.getElementById("disp_name_id").innerHTML;
	}
	
	if( document.getElementById("userProfileURL_href_Id") ){
		SNI.Community.Widgets.flagUploadByUrl = document.getElementById("userProfileURL_href_Id").href; 
	}
	
	if( document.getElementById('objDesc_'+objId) ){
		SNI.Community.Widgets.flagDescription = document.getElementById('objDesc_'+objId).value;
	}*/
	
	SNI.Community.Widgets.flagAsInappropriateUserProfile(objId,'profile','flaghref_profile_'+objId,'null');
}

SNI.Community.Widgets.flagAsInappropriateUserProfile = function(id,flagType,obj,commentsId)
{
	SNI.Community.Toolbox.ie=document.all;
	var request=SNI.Community.Toolbox.ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	var comments = "";
	var caption = "";
	var uploadBy = "";
	var description = "";
	var uploadbyurl = "";
	var modId = id;
	var profileLink = window.location.href;
	profileLink = profileLink.replace(/#/g, "");
	var flagReason = "";
	var gOridWPID = '';
	var gWidgetInstanceId = '';
	var gWidgetTypeId = '';
	var normalUserId = '';
	var memberId= '';
	var parsonnaId = 0;
	
	if( document.getElementById("gOrigProjectId") )
		gOridWPID = trim(document.getElementById("gOrigProjectId").value);
	
	if( document.getElementById("gWidgetInstanceId") )
		gWidgetInstanceId = trim(document.getElementById("gWidgetInstanceId").value);
	
	if( document.getElementById("gWidgetTypeId") )
		gWidgetTypeId = trim(document.getElementById("gWidgetTypeId").value);

	if( document.getElementById("globalNormalUserId") )
		normalUserId = trim(document.getElementById("globalNormalUserId").value);

	if(document.getElementById("profile_flag_reason_"+id)){
		flagReason = trim( document.getElementById("profile_flag_reason_"+id).value );
	}
	
	if(document.getElementById("gMemberId")){
		memberId = trim( document.getElementById("gMemberId").value );
	}

	if( document.getElementById("globalPersonnaId") )
		parsonnaId = trim(document.getElementById("globalPersonnaId").value);
	
	if(trim(flagReason) == ""){
		SNI.Community.Widgets.displayOn("profile_flag_reason_error_"+id);
		document.getElementById("profile_flag_reason_error_"+id).innerHTML = "You must provide a reason for flagging this profile.";
		return;
	}else{
		SNI.Community.Widgets.displayOff('flag_profile'+id);
	}
		
	//var url= "http://localhost:8005/PickleWeb/profileflagasinapp.do";
	var url= "/profileflagasinapp.do";
	var params = "wpid="+gOridWPID;
	params += "&wid="+gWidgetInstanceId;
	params += "&wtid="+gWidgetTypeId;
	params += "&uid="+normalUserId;
	params += "&reason="+escape(flagReason);	
	params += "&pl="+escape(profileLink);
	params += "&memberid="+escape(memberId);
	params += "&pid="+parsonnaId; // PersonnaId
	
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200 ||request.status==12152)
			{
				obj = document.getElementById(obj);
				SNI.Community.Widgets.setPickleCookie("pickle_profile_inapp_"+id,id);
				SNI.Community.Widgets.displayOff('flag_profile_'+id);
				obj.parentNode.innerHTML = " Flagged";
			}
			else if(request.status==500){
				alert("You found an opportunity for improvement! Please try again later");
			}	
			else{
				alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
			}	
		}
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.send(params);
}


SNI.Community.Widgets.isValidSponsorbyContents =  function (){
	if( (document.getElementById('cgp-inline-ad').innerHTML.indexOf("img")!=-1 || document.getElementById('cgp-inline-ad').innerHTML.indexOf("IMG")!=-1) &&
			( document.getElementById('cgp-inline-ad').innerHTML.indexOf("1x1.gif")==-1 ) )
	{
		document.getElementById('cgp-inline-ad-sponser').style.display ="block";
	}
}

SNI.Community.Widgets.isValidSponsorbyContentsForTop =  function (){
	if( (document.getElementById('cgp-inline-ad').innerHTML.indexOf("img")!=-1 || document.getElementById('cgp-inline-ad').innerHTML.indexOf("IMG")!=-1) &&
			( document.getElementById('cgp-inline-ad').innerHTML.indexOf("1x1.gif")==-1 ) )
	{
		document.getElementById('sponsor').style.display ="block";
	}
}

//http://issues.scrippsnetworks.com/browse/PICKLE-1242
SNI.Community.Widgets.isPasswordStrong =  function (passwd){
	var isPasswordStrong = false;
	if( passwd.length>6 
		&& passwd.length<20 
		&& passwd.match(/[a-z]/) 
		&& passwd.match(/[A-Z]/) 
		&& passwd.match(/\d+/)){
		
		isPasswordStrong = true;
	}
	
	return isPasswordStrong;
}


/*RMR Related Starts*/

SNI.Community.Widgets.TopNavSecureFavorite = function(val){	
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	secureComponent("SNI.Community.Widgets.TopNavSubmitVotes('"+gObjId+"','"+val+"','main')","YOU NEED TO BE SIGNED IN TO DO THAT.",'rmr_fav',4);
}
//D2C Favorites
SNI.Community.Widgets.TopNavSecureD2CFavorite = function(val){	
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id
	secureComponent("SNI.Community.Widgets.TopNavSubmitVotes('"+gObjId+"','"+val+"','d2coverlay')","YOU NEED TO BE SIGNED IN TO DO THAT.",'ol_favorites',4);
}

SNI.Community.Widgets.TopNavSecureFlag = function(objId){
	if(SNI.Community.UR.logged_in==true)
	SNI.Omniture.ClickTrackFire('#rmr_flag', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Flag');
	
	secureComponent("SNI.Community.Widgets.showConfirm()","YOU NEED TO BE SIGNED IN TO DO THAT.",'rmr_flag',6);
	
}

SNI.Community.Widgets.TopNavSecureRating = function(id,retVal){	
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	var gObjId = document.getElementById("gObjId").value;  //Get PhotoVideo object id or Collection object id

	if(userLogin=="true"){
		if(SNI.Community.Widgets.getratingscookie()&&SNI.Community.Widgets.getratingscookie().search(gObjId)!=-1)
				return ;
	}
	secureComponent("SNI.Community.Widgets.TopNavSubmitRating('"+id+"','"+retVal+"')","YOU NEED TO BE SIGNED IN TO DO THAT.","rtng_cntr",3);
} 


SNI.Community.Widgets.getTopNavRating = function()
{	
	var percentage = 0;
	var ratingText = "";
	if(SNI.Community.Widgets.getratingscookie(1)){}else{
		$("#main_inner_rating_stars").mouseout(function(e) { $(this).width('0%');});
		 $("#rtng_cntr").mousemove(function(e) {
		  var offset = $(this).offset();
		  var x = e.pageX - offset.left;
		 
		  if(x>90){
		  	percentage = 100;
		  	//ratingText = "Outstanding";
		  	ratingText = ratingOptionText[4];
		  }else if(x>70){
		  	percentage = 80;
		  	//ratingText = "Excellent";
		  	ratingText = ratingOptionText[3];
		  }else if(x>50){
		  	percentage = 60;
		  	// ratingText = "Good";
		  	ratingText = ratingOptionText[2];
		  }else if(x>30){
		  	percentage = 40;
		  	//ratingText = "Fair";
		  	ratingText = ratingOptionText[1];
		  }else if(x>10){
		  	percentage = 20;
		  	//ratingText = "Poor";
		  	ratingText = ratingOptionText[0];
		  }
		  
		  $('#rtng_cntr span').width(percentage+'%');
		  $('#rtng_cntr span').attr('title', ratingText);
		  $('#rtng_cntr_omnt a').text(ratingText);
		  $('#rtng_cntr_omnt a').attr('rel','rate-'+ percentage);
		});
		
		 $("#rtng_cntr").click(function() {
		 	var rate_value = percentage/20;
		 	if(rate_value>0){
				 $('#main_inner_rating_stars_omnt').click();
		 		SNI.Community.Widgets.TopNavSecureRating($("#gObjId").val(),rate_value);
		 	}
		 });
	}
 }


SNI.Community.Widgets.TopNavSubmitVotes = function(itemid,favStatus, d2coverlay) {	
	if(document.getElementById("ispv")){
		SNI.Community.Widgets.isPVProject = true;
	} 

	var pv = SNI.Community.Widgets.isPVProject;
	var ie=document.all;
	var userId;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var origProjectId = document.getElementById("gOrigProjectId").value;
	var logUserId = document.getElementById("gUserId").value;
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	var url="";
	try{
		if(userLogin!="" && userLogin=="true"){
			url= baseUrl+'voteobject.do?objId='+itemid+'&favstatus='+favStatus+'&wpid='+origProjectId+'&d2curl='+escape(window.location)+"&oc="+$('.title').html()+"&pv="+pv+"&wid="+SNI.Community.Toolbox.cWidgetId;
		}else{
			if(SNI.Community.Widgets.Get_Cookie('AJAX_LOGIN_RESPONSE'))
				{
				   userId = SNI.Community.Widgets.Get_Cookie('AJAX_LOGIN_RESPONSE').split("||")[0];
				}else{
					userId = SNI.Community.Widgets.Get_Cookie('picklecookie').split(",")[0];
				}
			url= baseUrl+'voteobject.do?objId='+itemid+'&favstatus='+favStatus+'&wpid='+origProjectId+'&d2curl='+escape(window.location)+"&pv="+pv+"&wid="+SNI.Community.Toolbox.cWidgetId;
		}
		
	}catch(e){}
		if( d2coverlay == 'd2coverlay' ){
		//	var fav = document.getElementById('ol_favorites').className = "fa spinner";
		//	$("#ol_favorites").empty();
		SNI.Community.Widgets.toolsLoading('ol_favorites');
		}
		else{
			var fav = document.getElementById('rmr_fav').className = "fa spinner";
			$("#rmr_fav").empty();
		}
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200)
			{
				var no_of_votes = request.responseXML.getElementsByTagName('nofvotes');				
					if(favStatus=="removefav"){
					if (typeof console === "object" ) { console.log(" favStatus "+favStatus) }
						SNI.Community.Widgets.Delete_Cookie('pickle_votings'+itemid, '/', '');
						$("#ol_favorites").html("<em></em><p>Favorite</p>");
						$("#rmr_fav").html("Favorite");		
						$('#rmr_fav').attr('title', 'Favorite');		
						$("#rmr_fav").removeClass("active");
						$("#rmr_fav").removeClass("fa spinner");						
						var unfav = document.getElementById('rmr_fav').className = "fa";						
						$("#hd_fvt_cnt").html(no_of_votes.item(0).firstChild.nodeValue+' favorites');
						$('#rmr_fav').unbind('click');
						$('#ol_favorites').unbind('click');
						$('#rmr_fav').bind('click', function() {
							if(SNI.Community.UR.logged_in==true)
							SNI.Omniture.ClickTrackFire('#rmr_fav', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Favorites');
							
						  	SNI.Community.Widgets.TopNavSecureFavorite('addfav');
						});	
						if (typeof console === "object" ) { console.log(" removefav testing ") }
						$('#ol_favorites').bind('click', function() {
							SNI.Community.Widgets.TopNavSecureD2CFavorite('addfav');							
						});															
					}else{				
					if (typeof console === "object" ) { console.log(" favStatus "+favStatus) }
						SNI.Community.Widgets.setvotescookie(itemid);
						$("#ol_favorites").html("<em></em><p>Unfavorite</p>");
						$("#rmr_fav").html("Unfavorite");	
						$('#rmr_fav').attr('title', 'Unfavorite');										
						$("#rmr_fav").removeClass("fa spinner");					
						var unfav = document.getElementById('rmr_fav').className = "fa active";													
						$("#rmr_fav").addClass("active");
						$("#hd_fvt_cnt").html(no_of_votes.item(0).firstChild.nodeValue+' favorites');
						$('#rmr_fav').unbind('click');
						$('#ol_favorites').unbind('click');
						$('#rmr_fav').bind('click', function() {
							if(SNI.Community.UR.logged_in==true)
								SNI.Omniture.ClickTrackFire('#rmr_fav', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Favorites');
						  	SNI.Community.Widgets.TopNavSecureFavorite('removefav');
						});	
						$('#ol_favorites').bind('click', function() {
						  	SNI.Community.Widgets.TopNavSecureD2CFavorite('removefav');	
						});											
					}			
			}
		}
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send('');
}



SNI.Community.Widgets.TopNavSubmitRating = function(itemid,rating_val) {

	//Below four lines are added for Pickle 2306 issue
	SNI.Community.Widgets.displayOff("rating");
	SNI.Community.Widgets.displayOn("vote_loading");
	SNI.Community.Widgets.displayOn("vr-loading");
	SNI.Community.Widgets.displayOff("rating_number");
	//Changes Ends here
	var ratingText1 = ""; 
	if(document.getElementById("gRatingText1"))
		ratingText1 = document.getElementById("gRatingText1").value;
	
	var ratingText2 = ""; 
	if(document.getElementById("gRatingText2"))
		ratingText2 = document.getElementById("gRatingText2").value;
		
	var ratingText3 = "";
	if(document.getElementById("gRatingText3")) 
		ratingText3 = document.getElementById("gRatingText3").value;
		
	var ratingText4 = ""; 
	if(document.getElementById("gRatingText4"))
		ratingText4 = document.getElementById("gRatingText4").value;
	var ratingText5 = "";
	if(document.getElementById("gRatingText5")) 
		ratingText5 = document.getElementById("gRatingText5").value;
		

	if(document.getElementById("ispv")){
		SNI.Community.Widgets.isPVProject = true;
	} 

	var pv = SNI.Community.Widgets.isPVProject;
	var userLogin = null;
	if(document.getElementById("gUserLogin") != null){
	userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogin").value);
	}
	else{
		if(document.getElementById("gUserLogged") != null){
			userLogin = SNI.Community.Widgets.trim(document.getElementById("gUserLogged").value);
		}
	}
	var ur = 	SNI.Community.Widgets.trim(document.getElementById("gUrNonur").value);
	var origProjectId = SNI.Community.Widgets.trim( document.getElementById("gOrigProjectId").value );
	var logUserId = document.getElementById("gUserId").value;

	if(SNI.Community.Widgets.ratingUnderProcess)
		return;
	else
		SNI.Community.Widgets.ratingUnderProcess = true;
		

	var sURL = unescape(window.location);
	
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	var url= "";
	if(ur=="true"){
		if( userLogin!="" && userLogin=="true" ){
			url=baseUrl+'rateobject.do?objId='+itemid+'&rating='+rating_val+'&d2curl='+escape(window.location)+"&wpid="+origProjectId+"&pv="+pv+"&nameused="+SNI.Community.Toolbox.cWidgetNameUsedInApp+"&wid="+SNI.Community.Toolbox.cWidgetId+"&oc="+escape($('.title').html());
		}else{
			url=baseUrl+'rateobject.do?objId='+itemid+'&rating='+rating_val+"&pv="+pv+"&nameused="+SNI.Community.Toolbox.cWidgetNameUsedInApp+"&wid="+SNI.Community.Toolbox.cWidgetId;
		}
	}else{
		url=baseUrl+'rateobjectnonur.do?objId='+itemid+'&rating='+rating_val+'&d2curl='+escape(window.location)+"&pv="+pv+"&nameused="+SNI.Community.Toolbox.cWidgetNameUsedInApp+"&wid="+SNI.Community.Toolbox.cWidgetId;
	}
	
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200)
			{
				SNI.Community.Widgets.setratingscookie(itemid+"///"+rating_val);
				
				var no_of_rating = request.responseXML.getElementsByTagName('nofratings');
				var cumulative = request.responseXML.getElementsByTagName('ratingscumulative');
				var final_rating1 = request.responseXML.getElementsByTagName('showrate');
				var innerhtml = "";
				var rtng_cmltve = (parseFloat(cumulative.item(0).firstChild.nodeValue) / parseInt(no_of_rating.item(0).firstChild.nodeValue));
				var rtng_cmltveForText = Math.round(rtng_cmltve);
				var rtngText = "";

				if(rtng_cmltveForText<2){
					rtngText = ratingText1;
				}else if(rtng_cmltveForText<3){
					rtngText = ratingText2;
				}else if(rtng_cmltveForText<4){
					rtngText = ratingText3;
				}else if(rtng_cmltveForText<5){
					rtngText = ratingText4;
				}else if(rtng_cmltveForText<6){
					rtngText = ratingText5;
				}
				
				var final_rating = parseFloat(final_rating1.item(0).firstChild.nodeValue);
				//Added If Condition for Pickle 2306 issue
				if(parseInt(no_of_rating.item(0).firstChild.nodeValue) == 1 ){
					$('.rating p').html(no_of_rating.item(0).firstChild.nodeValue+' Rating');
				} else {
					$('.rating p').html(no_of_rating.item(0).firstChild.nodeValue+' Ratings');
				}
				var ratingFloat = parseFloat(rtng_cmltve).toFixed(1);
				
				$('.rating_number h3').html(SNI.Community.Widgets.roundNumber(rtng_cmltve,1));
				$('.rating_number p').html(rtngText);
				if(parseInt(no_of_rating.item(0).firstChild.nodeValue) == 1 ){
					$("#hd_rts_cnt").html(no_of_rating.item(0).firstChild.nodeValue+' rating');
				} else {
					$("#hd_rts_cnt").html(no_of_rating.item(0).firstChild.nodeValue+' ratings');
				}
				$('#rtng_cntr span').width((rating_val*20)+'%');
				$('#rtng_cntr').unbind('mousemove').unbind('click').unbind('click.omniture');		
				$('.inner_rating_stars').unbind('mouseout');	
				
				//Below four lines are added for Pickle 2306 issue
				SNI.Community.Widgets.displayOn('rating');
				SNI.Community.Widgets.displayOff('vote_loading');
				SNI.Community.Widgets.displayOff('vr-loading');
				SNI.Community.Widgets.displayOn("rating_number");
				//Changes Ends here					
			}
		}
	}
	request.open("POST",url,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send('');
}

//Added BY Vasanth
SNI.Community.Widgets.descRedaMore = function( objectId , imgTxt, maxLength){

	if( SNI.Community.Widgets.descReadMoreEnabled  ){
		if( $('#'+objectId) ){
			
			imgTxt = SNI.Community.Widgets.translateEntities(imgTxt);
			
			//alert('From JS Paragraph Height :'+$('#'+objectId).height() );
			var tmpDescText = imgTxt; //$('#'+objectId).text(); //Max Char 456
			var tmpDescHeight = $('#'+objectId).height(); // Max 137
			var tempDescTextLength = 0;
			
			try{
				tempDescTextLength = tmpDescText.length;
			}catch(e){}
			//var maxLength = 456;
		
			if( tempDescTextLength > maxLength ){
				//alert('Inside IF');
				var firstPart =  tmpDescText.substring(0,maxLength);
				var midPart = "<span id='spanDots'>... </span><a id='hrefReadMore' href=\"javascript:SNI.Community.Widgets.descRedaMoreShowFullText('"+objectId+"','spanDots','hrefReadMore','spanDescReadmore','"+tmpDescHeight+"');\">Read More</a>";
				var lastPart = "<span id='spanDescReadmore' style='display:none;'>"+tmpDescText.substring(maxLength,tempDescTextLength)+"</span>";

				var readMoreLink = "... <a id='hrefReadMore' href=\"javascript:SNI.Community.Widgets.descRedaMoreShowFullText('"+objectId+"','readMoreShortDiv','readMoreFullDiv','"+tmpDescHeight+"');\">Read More</a>";				
				var shortDiv = "<p id='readMoreShortDiv'>"+ SNI.Community.Widgets.trim(tmpDescText.substring(0,maxLength))+readMoreLink+"</p>";
				var fullDiv = "<p id='readMoreFullDiv' style='display:none;'>"+tmpDescText+"</p>";

				//$('#'+objectId).val("");
				document.getElementById("cgp-id-page-image-text").innerHTML = "";
				
				//alert(' After Empty '+$('#'+objectId).text() );
				
				$('#'+objectId).append(shortDiv);
				$('#'+objectId).append(fullDiv);
			}
		
			//alert( 'tmpDescText :'+ tmpDescText +' tmpDescText Length :'+tmpDescText.length );
					
		}
	}

}

SNI.Community.Widgets.descRedaMoreShowFullText= function( objectId,readMoreShortDiv,readMoreFullDiv,objDescHeight ){
	//alert(' Current Height :'+$('#'+objectId).height() +" objDescHeight :"+objDescHeight);
	//$('#'+objectId).height(objDescHeight+"px");
	//$('#'+objectId).delay(800).slideDown("slow");
	//$('#'+objectId).fadeIn(400);
	//$('#'+objectId).slideDown(10).delay(300).fadeIn(800);
	$('#readMoreShortDiv').fadeOut(250, function(){
		$('#readMoreFullDiv').fadeIn(250);
	});
	//SNI.Community.Widgets.displayOff(readMoreShortDiv);	
	//SNI.Community.Widgets.displayOn(readMoreFullDiv);
}


/*SNI.Community.Widgets.reSetBigBoxAd = function (){
	SNI.Community.Widgets.displayOn('interstitialBG');
	SNI.Community.Widgets.displayOn('interstitialAdDiv');
	
	var randomnumber=Math.floor(Math.random()*100000);
*/
	/*
	*  Big Box Ad setting
	*/
/*	var url = VideoPlayerAd("BIGBOX", "", 5);
	if(url.indexOf("ORD=")!=-1)
	{
	   var part1 = url.substring(0,url.indexOf("ORD="));
	   var part2 = url.substring(url.indexOf("ORD="),url.length);
	   part2 = part2.substring(part2.indexOf("&")+1,part2.length);
	   url = part1+part2;
	}
	url += "&ord=" + randomnumber;
	var iFrameCont = "<iframe border=0 style='overflow-x:hidden;overflow-y:hidden;overflow:-moz-scrollbars-none;x-hidden; padding: 0px; margin: 0px;' height='260px' width='310px' frameborder='0' ALLOWTRANSPARENCY='true' src='"+url+"'>";
	
	try{
		setDartEnterpriseBanner("BIGBOX", url);
		//document.getElementById('interstitialAdDivCont').innerHTML = "<iframe border=0 style='overflow-x:hidden;overflow-y:hidden;overflow:-moz-scrollbars-none;x-hidden; padding: 0px; margin: 0px;' height='452px' width='602px' frameborder='0' ALLOWTRANSPARENCY='true' src='"+url+"'>";
		document.getElementById('interstitialAdDivCont').innerHTML = iFrameCont;
	}catch(e){
	    document.getElementById('interstitialAdDivCont').innerHTML = iFrameCont;
	}
}*/

SNI.Community.Widgets.closeInterstitialAdDiv = function (){
	SNI.Community.Widgets.displayOff('interstitialBG');
	SNI.Community.Widgets.displayOff('interstitialAdDiv');
}

SNI.Community.Widgets.alignButtons = function(){
	var tp = 0;
	if(document.getElementById("cd"+SNI.Community.Widgets.posI)){// incase if its a video
		$("#cgp-id-page-image-image").width($("#cgp-id-page-image-image img").width());
		$("#cgp-id-page-image-image").height($("#cgp-id-page-image-image img").height());
		tp = 176; 
	}else{
		$("#cgp-id-page-image-image").width($("#cgp-id-page-image-image img").width());
		$("#cgp-id-page-image-image").height($("#cgp-id-page-image-image img").height());
		tp = ($("#cgp-id-page-image-image img").height()/2);
	}
	$("#prevLink").css( { "top":tp + "px" } );
	$("#nextLink").css( { "top":tp + "px" } );
}
SNI.Community.Widgets.imgMoveOn = function(){
	SNI.Community.Widgets.moveOn('incre',document.getElementById('img_next'));
}
SNI.Community.Widgets.expandImg = function(){
	var imgSrc = $("#imgTop"+SNI.Community.Widgets.posI).attr("src");
	$("#imgTop"+SNI.Community.Widgets.posI).attr("src",imgSrc.replace(/topmed1/g,"topmed2"));
	$("#imgTop"+SNI.Community.Widgets.posI).unbind("load");	
	
	$("#imgTop"+SNI.Community.Widgets.posI).bind("load", function () { SNI.Community.Widgets.alignButtons(); });
	
	$(".expanImage").unbind("click");
	$(".expanImage").addClass("close");
	$(".expanImage").html("<span>Shrink Photo</span>");
	$(".expanImage").bind("click", SNI.Community.Widgets.shrinkImg);
	
}

SNI.Community.Widgets.shrinkImg = function(){
	var imgSrc = $("#imgTop"+SNI.Community.Widgets.posI).attr("src");
	$("#imgTop"+SNI.Community.Widgets.posI).attr("src",imgSrc.replace(/topmed2/g,"topmed1"));
	$("#imgTop"+SNI.Community.Widgets.posI).unbind("load");
	
	$("#imgTop"+SNI.Community.Widgets.posI).bind("load", function () { SNI.Community.Widgets.alignButtons(); });
	
	$(".expanImage").unbind("click");
	$(".expanImage").removeClass("close");
	$(".expanImage").html("<span>Enlarge Photo</span>");
	$(".expanImage").bind("click", SNI.Community.Widgets.expandImg);
	
	
}



SNI.Community.Widgets.actImg = function(){
	var tWidth = objWidthArr[SNI.Community.Widgets.posI];
	var tHeight = objHeightArr[SNI.Community.Widgets.posI];
	$("#cgp-id-page-image-image img").css({width:tWidth+"px",height:tHeight+"px"});
	
	SNI.Community.Widgets.alignButtons();
	$(".expanImage").unbind("click");
	$(".expanImage").addClass("close");
	$(".expanImage").html("<span>Shrink Photo</span>");
	$(".expanImage").bind("click", SNI.Community.Widgets.smallImg);
	
}

SNI.Community.Widgets.smallImg = function(){
	if(parseInt(objWidthArr[SNI.Community.Widgets.posI]) > 300 && parseInt(objHeightArr[SNI.Community.Widgets.posI])>400){
		$("#cgp-id-page-image-image img").css({width:"300px"});
		$("#cgp-id-page-image-image img").css({height:(300*objAspectRatio[SNI.Community.Widgets.posI])+"px"});
	}
	SNI.Community.Widgets.alignButtons();
	$(".expanImage").unbind("click");
	$(".expanImage").removeClass("close");
	$(".expanImage").html("<span>Enlarge Photo</span>");
	$(".expanImage").bind("click", SNI.Community.Widgets.actImg);
	
	
}

SNI.Community.Widgets.considerCCTimeFrame = function( pageIdentifier ){

		if( SNI.Community.Widgets.crosstimeframecheck == 1 ){
			return false;
		}
			
		document.getElementById('vr-loading_timesort').style.display = "block";
		
		var systemTagList = '';
		if( document.getElementById("categoryTag") ){
			systemTagList = document.getElementById("categoryTag").value;
		}
		if( systemTagList == 'null' || systemTagList == null )
			systemTagList = '';
		
		var userSearchStr = SNI.Community.Widgets.Get_Cookie('pickle_pv_user_search');	
		
		if( userSearchStr == 'null' || userSearchStr == null )
			userSearchStr = '';
		
		// overwrite the categorytag/usersearch for d2c page
		if( pageIdentifier == 'd2c' ) {
			if( document.getElementById("gAjPVCategoryCookieValue") ){
				systemTagList = document.getElementById("gAjPVCategoryCookieValue").value;
			}else {
				systemTagList = '';
			}
			
			if( document.getElementById("gAjPVUsrSearchCookieValue") ){
				userSearchStr = document.getElementById("gAjPVUsrSearchCookieValue").value;
			}else{
				userSearchStr = '';
			}
		}
			
		var wid = document.getElementById('gWid').value;
		var userSearchString = '';
		var browL = document.location+"";
		var gAjaxUrl = document.getElementById("gAjaxUrl").value;

		if(browL.indexOf(":80/") != -1){
			gAjaxUrl = gAjaxUrl.replace(':80','');
		}
			
		var ie=document.all;
       	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
      	var url=gAjaxUrl+"/crosstimeframecheck.do?wid="+wid+"&categoryTag="+systemTagList+"&userSearchString="+userSearchStr+"&containerIdStr="+document.getElementById('gLContainerIdStr').value+"&wpid="+document.getElementById('gLWidPid').value;
  		request.onreadystatechange=function()
		{
			if(request.readyState==4)
			{
				
				if(request.status==200)
				{
					SNI.Community.Widgets.resultText = ""+request.responseText;	
					
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"\n","");
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"\r","");	
					SNI.Community.Widgets.resultText = SNI.Community.Widgets.replaceAll(SNI.Community.Widgets.resultText,"&","&amp;");				
				    SNI.Community.Widgets.parseTextToXMLCCD2C(SNI.Community.Widgets.resultText,pageIdentifier);
				}
				else if(request.status==500){
					alert("You found an opportunity for improvement! Please try again later");
				}	
				else{
					// alert("There appears to be a connectivity problem. Please check your internet connection and try again.");
				}	
			}
		}

		request.open("POST",url,true);
		request.setRequestHeader("content-type","application/x-www-form-urlencoded");
		request.send('');

	
}
SNI.Community.Widgets.parseTextToXMLCCD2C = function(text, pageIdentifier){
	
	var timeFrameSelected = 0; 
	
	//if( SNI.Community.Widgets.Get_Cookie('pickle_pv_time_frame') != null ){
		//timeFrameSelected = SNI.Community.Widgets.Get_Cookie('pickle_pv_time_frame');
	//}
	timeFrameSelected = $("#gAjPVTimeFrameCookieValue").val();
	
	
	// alert ( text );
	if( pageIdentifier == 'd2c' ) {
		document.getElementById('vr-loading_timesort').style.display = "none";
		var xmlDoc;
		if(SNI.Community.Widgets.ie){
	
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(text);
		}
		else if(SNI.Community.Widgets.ns6){
		    parser=new DOMParser();
		    xmlDoc=parser.parseFromString(text,"text/xml");
	    }
	    var tf_today = xmlDoc.getElementsByTagName('today')[0];
		if( tf_today.firstChild.nodeValue == 'show' ) {
			document.getElementById('tf_today').style.display="block";
			document.getElementById('tf_today').innerHTML = "<a href=\"javascript:void(0);\" onclick=\"changeTimeline('1');displayOff('flyout_18936514');\">Today</a>";
			if( parseInt(timeFrameSelected) == 1 )
				$("#tf_today").addClass("sel");
		}else{
			document.getElementById('tf_today').style.display="block";
			$("#tf_today").addClass("inact");
		}
		var tf_thisweek = xmlDoc.getElementsByTagName('week')[0];
		if( tf_thisweek.firstChild.nodeValue == 'show' ) {
			document.getElementById('tf_thisweek').style.display="block";
			document.getElementById('tf_thisweek').innerHTML = "<a href=\"javascript:void(0);\" onclick=\"changeTimeline('7');displayOff('flyout_18936514');\">This Week</a>";
			if( parseInt(timeFrameSelected) == 7 )
				$("#tf_thisweek").addClass("sel");
		}else{
			document.getElementById('tf_thisweek').style.display="block";
			$("#tf_thisweek").addClass("inact");
		}
		
		var tf_thismonth = xmlDoc.getElementsByTagName('month')[0];
		if( tf_thismonth.firstChild.nodeValue == 'show' ) {
			document.getElementById('tf_thismonth').style.display="block";
			document.getElementById('tf_thismonth').innerHTML = "<a href=\"javascript:void(0);\" onclick=\"changeTimeline('30');displayOff('flyout_18936514');\">This Month</a>";
			if( parseInt(timeFrameSelected) == 30 )
				$("#tf_thismonth").addClass("sel");
		}else{
			document.getElementById('tf_thismonth').style.display="block";
			$("#tf_thismonth").addClass("inact");
		}
		
		if( parseInt(timeFrameSelected) == 0 )
				$("#tf_all").addClass("sel");
				
		document.getElementById('tf_all').style.display="block";
	} else {
		
		document.getElementById('vr-loading_timesort').style.display = "none";
		var xmlDoc;
		if(SNI.Community.Widgets.ie){
	
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(text);
		}
		else if(SNI.Community.Widgets.ns6){
		    parser=new DOMParser();
		    xmlDoc=parser.parseFromString(text,"text/xml");
	    }
	    var tabUrl = document.getElementById('widgetTabURL').value;
	    tabUrl += "sortOrder=" + document.getElementById('sortOrderPassIn').value;
	    if(document.getElementById("mode")){
	    	if(document.getElementById("mode").value == 'chart'){
	    		tabUrl += "&displaymode=chart";
	    	}
	    }
	    var tf_today = xmlDoc.getElementsByTagName('today')[0];
		if( tf_today.firstChild.nodeValue == 'show' ) {
			document.getElementById('tf_today').style.display="block";
			document.getElementById('tf_today').innerHTML = "<a href=\""+ tabUrl +"&timeFrame=1\" onclick=\"displayOff('flyout_18936514');\">Today</a>";
			if( parseInt(timeFrameSelected) == 1 )
				$("#tf_today").addClass("sel");
		}else{
			document.getElementById('tf_today').style.display="block";
			$("#tf_today").addClass("inact");
		}
		
		var tf_thisweek = xmlDoc.getElementsByTagName('week')[0];
		if( tf_thisweek.firstChild.nodeValue == 'show' ) {
			document.getElementById('tf_thisweek').style.display="block";
			document.getElementById('tf_thisweek').innerHTML = "<a href=\""+ tabUrl +"&timeFrame=7\" onclick=\"displayOff('flyout_18936514');\">This Week</a>";
			if( parseInt(timeFrameSelected) == 7 )
				$("#tf_thisweek").addClass("sel");
		}else{
			document.getElementById('tf_thisweek').style.display="block";
			$("#tf_thisweek").addClass("inact");
		}
		
		var tf_thismonth = xmlDoc.getElementsByTagName('month')[0];
		if( tf_thismonth.firstChild.nodeValue == 'show' ) {
			document.getElementById('tf_thismonth').style.display="block";
			document.getElementById('tf_thismonth').innerHTML = "<a href=\""+ tabUrl +"&timeFrame=30\" onclick=\"displayOff('flyout_18936514');\">This Month</a>";
			if( parseInt(timeFrameSelected) == 30 )
				$("#tf_thismonth").addClass("sel");
		}else{
			document.getElementById('tf_thismonth').style.display="block";
			$("#tf_thismonth").addClass("inact");
		}
		
		if( parseInt(timeFrameSelected) == 0 )
				$("#tf_all").addClass("sel");
				
		document.getElementById('tf_all').style.display="block";
		
	}
	SNI.Community.Widgets.crosstimeframecheck = 1;
}


SNI.Community.Widgets.setUserSortCookie = function( anchorObj ){
	SNI.Community.Widgets.Set_Cookie( 'pickle_pv_user_selected_sorting', '1', '1', '/', '', '' );
	window.location = $(anchorObj).attr('url');
	
}

SNI.Community.Widgets.translateEntities = function (string){
    var text, p=document.createElement('p');
    p.innerHTML=string;
    text= p.innerText || p.textContent;
    p.innerHTML='';
    return text;
}

SNI.Community.Widgets.setPhotoNotes = function()
{
	var htmlStr1 = SNI.Community.Widgets.trim( $("#bigbox").html() );
	var htmlStr2 = $("#bigbox-300-150").html();

	if( htmlStr1 == null ||  htmlStr1==""){
		return;
	}	
	var src1 = $("img", $(htmlStr1)).attr ("src");
  //var src2 = $("img", $(htmlStr2)).attr ("src")
	
	
	//PICKLE-2634 start -- palani		
		
		if(src1 != null && src1 != ""){			
			$("#overSizeNoteId").css('display', 'none'); 
			$("#noteId").css('display', 'none');
		}
		//end	
	
	
	var newImg = new Image();
    newImg.src = src1;
    if (typeof console === "object" ) { console.log(" width: "+newImg.width+"  height : " +newImg.height) }
    p = $(newImg).ready(function(){
    	var height = newImg.height;
    	var width = newImg.width;	
       return {width: newImg.width, height: newImg.height};
      });
      

 var noteTxtObj = document.getElementById('photoNoteTxtFlag');
 if (typeof console === "object" ) { console.log(" ad size height "+p[0]['height']) }
 if(p[0]['height']   < 440)
 {
	 
	 $("#overSizeNoteId").css('display', 'none'); 
	 $("#noteTitleId_Ext").css('display','none');
	 $("#cgp-id-page-image-text-ext").css('display','none');
	 //if(noteTxtObj && noteTxtObj.value == "YES") {
		
	 	$("#noteId").css('display', 'block');
	 	$("#noteTitleId").css('display','block');
		$("#cgp-id-page-image-text").css('display','block');
	 //}
 }else{
	 
	 $("#noteId").css('display', 'none');
	 $("#noteTitleId").css('display','none');
	 $("#cgp-id-page-image-text").css('display','none');
	// if(noteTxtObj && noteTxtObj.value == "YES"){
		
		 $("#overSizeNoteId").css('display', 'block');
		 $("#noteTitleId_Ext").css('display','block');
		 $("#cgp-id-page-image-text-ext").css('display','block');
	 //}
 }
	 
}

/*RMR Related Ends*/

/* Flah Related code */
SNI.Community.Widgets.getFlashMovieObject = function(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}
 
SNI.Community.Widgets.StopFlashMovie = function()
{
	var flashMovie=SNI.Community.Widgets.getFlashMovieObject("myFlashMovie");
	flashMovie.StopPlay();
}

SNI.Community.Widgets.PlayFlashMovie = function()
{
	var flashMovie=SNI.Community.Widgets.getFlashMovieObject("myFlashMovie");
	flashMovie.Play();
	//embed.nativeProperty.anotherNativeMethod();
}
/* End Flash Related code */

/* Previous Next AJAX approach */

SNI.Community.Widgets.ajaxPostNew = function(url,reqParameters,callBack){
	var locationUrl = document.location+"";
	if(locationUrl.indexOf(":80")==-1 && url.indexOf(":80")!=-1){
 		var temp = url.substring(0,url.indexOf(":80"));
 		var temp1 = url.substring(url.indexOf(":80")+3,url.length);
 		url = temp + temp1;
	} 
	var request=document.all?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
 	request.onreadystatechange=function(){
  		if(request.readyState==4){
   			if(request.status==200){ 	
         		try{eval(callBack);}catch(e){}
   			}    
  		}
 	}
	request.open("POST",url,true);
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", reqParameters.length);
	request.setRequestHeader("Connection", "close");	
	request.send(reqParameters); 
}


SNI.Community.metaDataAjaxRefresh = function(objectId, nextprevCat ){
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	var targetUrl = "";
	var pageId = $('#gPageId').val();
	var adParam = 0;
	var siteId = $('#projectSiteId').val();
	var wpid = $('#gLWidPid').val();
	var categoryTag = $('#categoryTag').val();
	
	targetUrl = gAjaxUrl+"/pageMetaTag.do?";
	targetUrl += "pid="+pageId+"&adParam=0"+"&siteid="+siteId;
	targetUrl += "&wpid="+wpid+"&oid="+objectId+"&categoryTag="+nextprevCat+"&ajaxRefresh=true";
	//targetUrl += "&wpid="+wpid+"&oid="+objectId+"&ajaxRefresh=true";
		


	$.ajax({url: targetUrl,cache: false, async: false, success: function(data){
		    
		var evalScriptsVar = SNI.Community.getScriptsTagContent ( data );	
		evalScriptsVar = evalScriptsVar.replace( '<script type="text/javascript">' ,'');
		evalScriptsVar = evalScriptsVar.replace( '</script>' ,'');
		
		try{
			eval( evalScriptsVar );
		} catch(e){}
				
		var strippData = SNI.Community.stripScripts( data);

		var headData = data.replace("</head>",""); // remove closing head tag from response
        var newHead = $("<head>").html(headData); // create new off-DOM head node and insert response data
        var newMeta = newHead.find('meta'); // find meta tags in newly created head node
        var newTitle = newHead.find('title');
        var pageMeta = $('meta'); // select meta tags in current page

		
        //if (typeof console === "object" ) { console.log(newMeta) }
        newMeta.each(function(){ // for each of the new meta tags
                var theName = $(this).attr("name"); // get the name attribute
                if (theName != "undefined" 
                		&& theName == "tweetmeme-title") {
                                var newVal = $(this).attr("content"); // get the new value
                                if (typeof console === "object" ) { console.log("replacing :"+theName +" , New Content is :"+newVal) }
                                pageMeta.filter('[name="'+ theName +'"]').attr("content", newVal); // from the current page meta tags, find the meta tag matching name and update its value					
                }
        });
        
		// The following method definition call available in skins/ads/pageheader.js
		SNI.Community.initPageHeader();
		
		
		

		var newPageTilte = '';
		newPageTilte = SNI.Community.pageTitle;
		newPageTilte = newPageTilte.replace( /&#39;/g,"'");
		newPageTilte = newPageTilte.replace( /&#34;/g,"\"");		
				document.title = newPageTilte;
		    
		    
		    
		    
		}
		});
	
	
	
	
	
	
}

SNI.Community.Widgets.closeTopLayPopUps = function (){
	$('#moreCont_bg').hide();
	$('#moreCont').hide();
	$('#cgp-id-emf-window').hide();
}

var pageLoaduserrcwid;
var pageLoadcategoryrcwid;
		
SNI.Community.TopNavDetailAjaxRefresh = function(detailPageUrl,requestFrom,objectId, nextprevCategory,clickFrom ){
	SNI.Community.Widgets.isFirstItemLoad  = true;
	try{	
	if( document.getElementById("usergallery_rc_wid") )
		pageLoaduserrcwid = document.getElementById("usergallery_rc_wid").value;
	if( document.getElementById("category_rc_wid") ) 	
		pageLoadcategoryrcwid = document.getElementById("category_rc_wid").value;	
	}catch(e){}	
		
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;	
	var targetUrl = "";
	var targetParams = "";
	var wid = $("#gWid").val();
	var projectId = $("#gWidgetProjectId").val(); 
	var baseUrl = $("#gBaseUrl").val();
	var systemTag = $("#gSystemTagListD2C").val();
	var styleId = $("#gStyleId").val();
	
	$('#ajxPageLoadText').html('');
	if( clickFrom=='prev' ){
		$('#ajxPageLoadText').html('Loading the previous project...');
	}else if( clickFrom=='next' ){
		$('#ajxPageLoadText').html('Loading the next project...');
	}
	
	SNI.Community.Widgets.closeTopLayPopUps();
	
	$('.ajaxpageloader').show();
	//Meta Data Ajax Refresh call moved to after the collectionsdetail.do response	

	targetUrl = gAjaxUrl+"/collectionsdetail.do";
	
	targetUrl += "?wid="+wid+"&projectId="+projectId;
	targetUrl += "&appUrl="+escape(baseUrl);
	targetUrl +=  "&timeframe=" + $("#gAjPVTimeFrameCookieValue").val() + "&sortorder=" + $("#gAjPVSortOrderCookieValue").val(); // add the timeframe/sortorder/user search string param
	
	targetUrl +=  "&pageNumber=" + $("#gAjPVPageNumberCookieValue").val();
	
	if( document.getElementById('gAjPVCategoryCookieValue')  )
		targetUrl +=  "&categoryTag="+$("#gAjPVCategoryCookieValue").val();
		
	if( document.getElementById('gAjPVUsrSearchCookieValue') )
		targetUrl +=  "&usersearchstr="+$("#gAjPVUsrSearchCookieValue").val();
		
	if( document.getElementById('gAjPVCreatedUserIdCookieValue') )
		targetUrl +=  "&userid="+$("#gAjPVCreatedUserIdCookieValue").val();	
					
	targetUrl += "&styleid="+styleId+"&isa=true&oid="+objectId; // please keep oid as last parameter otherwise this will break sortorder
		
	
	$.get(targetUrl, function(data) {		
	
		var strippData = SNI.Community.stripScripts( data);		
		
		//if (typeof console === "object" ) { console.log( $("#cgp-detail-widget").html() ) }
		$("#cgp-detail-widget").html($(strippData).find("#cgp-detail-widget").html());
		
		SNI.Community.metaDataAjaxRefresh(objectId,nextprevCategory);
		
		SNI.Community.renderTwitters( data );		
		SNI.Community.afterNavDetailAjaxRefresh();

		
	});
	
	
	//window.history.replaceState('Object', 'Title', '/another-new-url');
	
}

SNI.Community.renderTwitters = function ( data) {

 	var $response = $( data );
  	$response.find('a.twitter-share-button').each(function()
  	{
   		$.ajax({ url: 'http://platform.twitter.com/widgets.js', dataType: 'script', cache:true});
   		try{
    		var tweet_button = new twttr.TweetButton( $( this ).get( 0 ) );
    		tweet_button.render();
   		}catch(e){}
  	});
  
}

SNI.Community.parseFBLike = function ( objId ) {
	FB.XFBML.parse($("#"+objId).get(0));	
}

SNI.Community.reinitializeFaceBook = function ( ) {
	var elem = $(document.createElement("fb:like"));
	elem.attr("href", $("#gDetailPageURL").val() );
	elem.attr("show_faces","true");
	elem.attr("layout","button_count");
	elem.attr("send","false");
	$("#tb-facebook-new").empty().append(elem);
	FB.XFBML.parse($("#tb-facebook-new").get(0));	
}

SNI.Community.TopNavDetailSortAjaxRefresh = function(detailPageUrl,requestFrom,objectId){
	
	SNI.Community.Widgets.topClickSortModifier = true;
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;	
	var targetUrl = "";
	var targetParams = "";
	var wid = $("#gWid").val();
	var projectId = $("#gWidgetProjectId").val(); 
	var baseUrl = $("#gBaseUrl").val();
	var systemTag = $("#gSystemTagListD2C").val();
	var styleId = $("#gStyleId").val();
	
	if( requestFrom == "detailpage" ){
		targetUrl = gAjaxUrl+"/collectionsdetail.do";
		
		targetUrl += "?wid="+wid+"&projectId="+projectId;
		targetUrl += "&appUrl="+escape(baseUrl);
		targetUrl += "&rf=ajax";
		targetUrl +=  "&timeframe=" + $("#gAjPVTimeFrameCookieValue").val() + "&sortorder=" + $("#gAjPVSortOrderCookieValue").val(); // add the timeframe/sortorder/user search string param
		
		if( document.getElementById('gAjPVCategoryCookieValue')  )
			targetUrl +=  "&categoryTag="+$("#gAjPVCategoryCookieValue").val();
			
		if( document.getElementById('gAjPVUsrSearchCookieValue') )
			targetUrl +=  "&usersearchstr="+$("#gAjPVUsrSearchCookieValue").val();
			
		if( document.getElementById('gAjPVCreatedUserIdCookieValue') )
			targetUrl +=  "&userid="+$("#gAjPVCreatedUserIdCookieValue").val();	
		
		if( document.getElementById('gAjPVPickleChanged').value == 'true' ){
			targetUrl +=  "&pickle_changed=true";
			document.getElementById('gAjPVPickleChanged').value = 'false';	
		}
				
		targetUrl += "&styleid="+styleId+"&isa=true&oid="+objectId; // please keep oid as last parameter otherwise this will break sortorder
		
	}

	try{
	if( document.getElementById("usergallery_rc_wid") )
		pageLoaduserrcwid = document.getElementById("usergallery_rc_wid").value;
	if( document.getElementById("category_rc_wid") ) 	
		pageLoadcategoryrcwid = document.getElementById("category_rc_wid").value;	
	}catch(e){}
		
	//$.get(targetUrl, function(data) {	
	
		//var strippData = SNI.Community.stripScripts( data);
		//$("#cgp-detail-widget").html($(strippData).find("#cgp-detail-widget").html());
		//SNI.Community.afterNavDetailAjaxRefresh();
		
	//});
		
	var ie=document.all;
	var request=ie?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
	request.onreadystatechange=function()
	{
		if(request.readyState==4)
		{
			if(request.status==200)
			{	
				 var results = request.responseText;		 
				 SNI.Community.objectId =  results.split(",")[0];
				 SNI.Community.TopNavDetailAjaxRefresh( detailPageUrl,requestFrom, SNI.Community.objectId , results.split(",")[1],'');
		
			}
		}
	}
	request.open("POST",targetUrl,true);
	request.setRequestHeader("content-type","application/x-www-form-urlencoded");
	request.send('');
	
}


SNI.Community.stripScripts = function (markup) {
  return markup.replace(/<script[^>]*?>[\s\S]*?<\/script>/gi, '');
}

SNI.Community.getScriptsTagContent = function (markup) {
  	var re = new RegExp(/<script[^>]*?>[\s\S]*?<\/script>/);
	var m = re.exec( markup);
	var result = '';
	if( m!= null ){
		for (i = 0; i < m.length; i++) {
      		result = result + m[i] + "\n";
      	}
    }	
  	return result;
}


SNI.Community.afterNavDetailAjaxRefresh = function(){
	
	
	//call the full page refresh routine for omniture
	try{
		//if (typeof s == "object") { s.t();}
	}catch(e){}
	//move just after initpageheader include
	
	//call leaderboard ad here
	//call bigbox ad here
	//Jim, this is getting called in line number 1560 which setDartEnterpriseBanner("BIGBOX", url);    setDartEnterpriseBanner("LEADERBOARD", url);
	//so this include is going to be second, so I removed it
	
	
	
	SNI.Community.initializeTopLayoutInlineJS('detail','Ajax');
	if( SNI.Community.Widgets.topClickSortModifier ){
		SNI.Community.Widgets.appendPoundFollwedUrl(); // PICKLE-2933
	}
	
	try{
		//This function is defined in PAGE_HTML by a site looking to override what happens after "Next Project" page refresh.
		//It may not need to be defined at all w/in the PAGE_HTML.
		//The immediate driver for this is the FB like functionality that on TC differs from rest of the sites.
		SNI.Community.Widgets.afterNavDetailAjaxRefreshSiteSpecific();
	}catch(e){}
	
	
	
	
}

SNI.Community.initializePhotoVideoArray = function(){
	
	var objIdTmp = 0;
	var pvCount = document.getElementById('tagsLen').value;
	var wid = document.getElementById('gWid').value;
	
	objArr = new Array();
	objTextArr = new Array();
	objIdArr = new Array();
	objTagArr = new Array();
	objCaptionArr = new Array();
	objProducerArr = new Array();
	objImgArr = new Array();
	
	objWidthArr = new Array();
	objHeightArr = new Array();
	objAspectRatio = new Array();

	for ( var indexObj=0; indexObj<parseInt(pvCount); indexObj++ ){	
		objIdTmp = document.getElementById('tmp_objecid'+indexObj).value;
		var imgObj = document.getElementById('imgTop' + indexObj );
		var imgObjWidth = $('#gAjImgTopWidth'+indexObj).val();
		var imgObjHeight = $('#gAjImgTopHeight'+indexObj).val();
		objIdArr[objIdArr.length] = document.getElementById('tmp_objecid'+indexObj).value;
		objTextArr[objTextArr.length] = escape(document.getElementById('desc'+indexObj).value);
		objTagArr[objTagArr.length] = escape(document.getElementById('tmp_user_tag'+indexObj).value);
		objCaptionArr[objCaptionArr.length] = escape(document.getElementById('tmp_caption'+indexObj).value);
		objProducerArr[objProducerArr.length] = escape(document.getElementById('tmp_producer'+indexObj).value);
		objImgArr[objImgArr.length] = document.getElementById('tmp_medium_filename'+indexObj).value;
		
		objWidthArr[objWidthArr.length] = document.getElementById('tmp_width'+indexObj).value;
		objHeightArr[objHeightArr.length] = document.getElementById('tmp_height'+indexObj).value;;
		objAspectRatio[objAspectRatio.length] = document.getElementById('tmp_aspect_ratio'+indexObj).value;
																			
		var objectSubType = document.getElementById('sObjType'+indexObj).value;
		if( document.getElementById('hot_spot'+indexObj).value ==' true' ){
			
			var objectEmbedTag = "<object width='"+imgObjWidth+"' height='"+imgObjHeight+"' id='PickleHotspotSWF' bgcolor='#000000' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' >"+
								"<param name='allowScriptAccess' value='always' />" +
								"<param name='allowFullScreen' value='true' />" +
								"<param name='wmode' value='transparent'>" +
								"<param name='FlashVars' value='serverurl="+document.getElementById("gAjaxUrl").value+"&id="+objIdTmp+"&scale=true'>" +
								"<param name='movie' value='"+document.getElementById("gAjaxUrl").value+"/skins/flash/pickleHotspotViewer.swf'>"+
								"<embed name='myFlashMovie' swliveconnect='true' type='application/x-shockwave-flash' src='"+document.getElementById("gAjaxUrl").value+"/skins/flash/pickleHotspotViewer.swf' id='PickleHotspotSWF' name='PickleHotspotSWF' bgcolor='#000000' quality='high' wmode='transparent' FlashVars='serverurl="+document.getElementById("gAjaxUrl").value+"&id="+objIdArr[objIdArr.length]+"&scale=true' width='"+imgObjWidth+"' height='"+imgObjHeight+"' >"+
								"</object>";
								
			objArr[ objArr.length] = objectEmbedTag;
			
		}
		else if( objectSubType == 'PHOTO' ) {
			objArr[ objArr.length] = escape ( "<img id='imgTop"+indexObj+"' onclick='SNI.Community.Widgets.imgMoveOn();' src='"+imgObj.getAttribute("src") + "' alt='"+imgObj.getAttribute("alt") +"' title='"+imgObj.getAttribute("title") +"' style=\"cursor: pointer;VAL\"  />" );
		} else if( objectSubType == 'VIDEO' ) {
		
			var objectEmbedTag = "<object width='"+imgObjWidth+"' height='"+imgObjHeight+"' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' id='cd"+indexObj+"' >"+
								"<param name='allowScriptAccess' value='always' />" +
								"<param name='allowFullScreen' value='true' />" +
								"<param name='wmode' value='transparent'>" +
								"<param name='FlashVars' value='slot="+(indexObj+1)+"' > "+
								"<param name='movie' value='"+document.getElementById("gAjaxUrl").value+"/flshentrw.flash/cp20/VP/"+wid+"/"+SNI.Community.siteCode+"/"+objIdTmp+"/"+document.getElementById("gObjId").value+"/1/1/"+imgObj.getAttribute("ref")+"' />" +
								"<embed name='myFlashMovie' swliveconnect='true' type='application/x-shockwave-flash' style='visibility: visible' flashvars=\"slot=4\" src='"+document.getElementById("gAjaxUrl").value+"/flshentrw.flash/cp20/VP/"+wid+"/"+SNI.Community.siteCode+"/"+objIdTmp+"/"+document.getElementById("gObjId").value+"/1/1/"+imgObj.getAttribute("ref")+"' type='application/x-shockwave-flash' allowfullscreen='true' wmode='transparent'  allowscriptaccess='always' width='"+imgObjWidth+"' height='"+imgObjHeight+"' >"+
								"</object>";
								
			objArr[ objArr.length] = objectEmbedTag;
		}
		
		document.getElementById('thumb_href'+objIdTmp).onclick = new Function("SNI.Omniture.ClickTrackFire('#thumb_href'+"+objIdTmp+",  SNI.Community.siteCode + ' : ' + SNI.Community.projectName + ' - Carousel Clicked');return false;");				
		
	}	

	
}

SNI.Community.replaceOtherTagsContents = function( data ){
	document.getElementById('tagsLen').value = $(data).find("#tagsLen").val() ;
	document.getElementById("gItemListCount").value = $(data).find("#gItemListCount").val() ;
}

var adminBaseUrl = '';
var base_Url = '';
var ratingOptionText = new Array();

SNI.Community.initializeTopLayoutInlineJS = function( pageName, requestFrom ){
	
	SNI.Community.siteCode = $('#gAjSiteCode').val();
	
	//toplayout.jsp
	adminBaseUrl = $('#gAjAdminBaseUrl').val();	
	base_Url = $('#gAjBaseUrl').val();	

	if(base_Url.indexOf(":80")!=-1 && base_Url.indexOf("8005")==-1)
		base_Url = base_Url.substring(0,base_Url.indexOf(":80"));	

	//tophat.jsp
	var showSearchBar = $('#gAjShowSearchBar').val();
	if( showSearchBar == "true" ){
		document.getElementById("cgp-search").style.display="block";
	}	

	var moreActive = $('#gAjMoreActive').val();
	if( moreActive == "true" ){
		document.getElementById("arrow").className = 'arrow sel';
	}
	
	if( document.getElementById('unapproved_flag') == null  ) {
		if( pageName == 'detail' ) {
			//detailpage.jsp		
			SNI.Community.initializeTopLayoutDetailPageInlineJS( requestFrom);
			
		}
	}
	
	//toplayout.jsp
	SNI.Community.Widgets.showHideDiv();	
	if(document.getElementById('showThumbnailRows3') && document.getElementById('showThumbnailRows2') &&  document.getElementById('showThumbnailRows2')){
		if(document.getElementById('showThumbnailRows3').style.display == "none" && document.getElementById('showThumbnailRows2').style.display == "none" && document.getElementById('showThumbnailRows1').style.display == "none"){
			document.getElementById('empty_').style.display = "block";
		}
	}	
	if( pageName == 'detail' ) {
		//omnitureevents.jsp
		SNI.Community.initializeTopLayoutOmnitureEvent();
	}

		
}

SNI.Community.getNextSibling = function (n){
	var x=n.nextSibling;
	while (x.nodeType!=1){
  		x=x.nextSibling;
  	}
	return x;
}


/* 
 * This function is called when a user hovers over the toolbar area.  It can't be called during ajax refresh, because IE does not set the
 * src attribute of the fb_ltr iframe until after the page loads (at some indeterminate time).
 * 
 */
SNI.Community.fbLikeSrcChanged=false;
SNI.Community.changeLike = function () {
	if(SNI.Community.fbLikeSrcChanged==false)
	{
		if (typeof console === "object" ) { console.log("Switching out LIKE URL") }
		$(".fb_edge_widget_with_comment").attr("href", $("#gDetailPageURL").val());
		var fbsrc = $(".fb_ltr").attr('src');
		fbsrc=fbsrc.replace(/href=*/, 'href='+$("#gDetailPageURL").val()+'&');
		$(".fb_ltr").attr('src', fbsrc);
		SNI.Community.fbLikeSrcChanged=true;
	}
	
	
	
}

SNI.Community.initializeTopLayoutToolBar = function (){
	var favoriteText = $('#rmr_fav').html();
	if( favoriteText == "Unfavorite" ){
		$('#rmr_fav').bind('click', function() {
			if(SNI.Community.UR.logged_in==true)
			SNI.Omniture.ClickTrackFire('#rmr_fav', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Favorites'); 
		  	SNI.Community.Widgets.TopNavSecureFavorite('removefav');
		});		
	}else{
		$('#rmr_fav').bind('click', function() {
			if(SNI.Community.UR.logged_in==true)
			SNI.Omniture.ClickTrackFire('#rmr_fav', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Favorites');
		  	SNI.Community.Widgets.TopNavSecureFavorite('addfav');
		});		
	}
	
	var flagText = $('#rmr_flag').html();
	if( flagText == "Flag" ){
		$("#rmr_flag").bind("click",function(){SNI.Community.Widgets.TopNavSecureFlag();});
	}
	
	//SNI.Community.reinitializeFaceBook();
    
    try{
    	SNI.Community.fbLikeSrcChanged=false;
	    SNI.Util.Toolbar({ printUrl: "" });
	    SNI.Community.parseFBLike("tb-facebook");
	    // Only call this method during mouseover - since IE doesn't actually set the src attribute of the iframes until after DOM is fully loaded   SNI.Community.changeLike(); // PICKLE-2978
    }catch(e){}
    
	//SNI.HGRM.IS.FB.like({element: "#tb-facebook"});
	//SNI.HGRM.IS.Twitter.share({element: "#tb-tweet"});	
}

SNI.Community.initializeTopLayoutPrvNxtOnClick = function (){
	if( document.getElementById('nav_prv_project') ){
		document.getElementById('topPrevLnk').onClick = new Function("return false;");
		document.getElementById('topPrevLnk').href= $('#gAjTopPreUrl').val();
		$('#nav_prv_project').bind('click', function() {
				try{
				SNI.Nielsen.trackPageView();
				} catch(e){}
		  	SNI.Community.TopNavDetailAjaxRefresh($('#gAjTopPreUrl').val(),'detailpage',$('#gAjTopPreObjId').val(), $('#gAjTopPreCat').val(),'prev' );
			//try{
			//	if (typeof s == "object") { s.t();}
			//}catch(e){}
		});						
	}

	if( document.getElementById('nav_nxt_project') ){
		document.getElementById('topNxtLnk').onClick = new Function("return false;");
		document.getElementById('topNxtLnk').href= $('#gAjTopNxtUrl').val();
		$('#nav_nxt_project').bind('click', function() {
				try{
				SNI.Nielsen.trackPageView();
				} catch(e){}
		  	SNI.Community.TopNavDetailAjaxRefresh($('#gAjTopNxtUrl').val(),'detailpage',$('#gAjTopNxtObjId').val(), $('#gAjTopNxtCat').val(),'next' );
			//try{
			//	if (typeof s == "object") { s.t();}
			//}catch(e){}
		});						
	}	
}

var inter_wrap;
SNI.Community.initializeTopLayoutDetailPageInlineJS = function ( requestFrom ){
	SNI.Community.Widgets.globalCountEMF = 0;
	SNI.Community.Widgets.descReadMoreEnabled = true;
	SNI.Community.Widgets.isFirstItemLoad  = true;
	SNI.Community.Widgets.interstitialAdEnabled = true;	
	SNI.Community.Widgets.isTopLayout = true;
	SNI.Community.Toolbox.cCommentsLayoutName = "internaltop";
	SNI.Community.Widgets.ratingUnderProcess = false;
	SNI.Community.Widgets.userRateStatus = false;
	
	// d2c overlay related variable re-initialization
	SNI.Community.Widgets.ovPos=0;
	SNI.Community.Widgets.currentTxtRec = 0;
	SNI.Community.Widgets.isOverlayAvailable = false;
	SNI.Community.Widgets.pageLoadFlag = true;
	SNI.Community.Widgets.posI = 0;
	
	
	jQuery(document).ready(function($) {
		SNI.Community.Widgets.getTopNavRating ();
		SNI.Community.initializeTopLayoutToolBar();	
	});
	
	//PrevNext Onclick	
	SNI.Community.initializeTopLayoutPrvNxtOnClick();

	//James code should comes here  or Initialize main well and jCarousel related code
	SNI.Community.initializePhotoVideoArray();
	
	SNI.Community.Widgets.Carousel("#photo-carousel", { pagelink:"image" });
	
	// Move this call to detail page since its getting reload		
	// BigboxAd('5');
	
	var showLongDesc = $("#gAjShowLongDesc").val();	
	if( showLongDesc == "true" ){
		$("#collection_description").show();
		$("#headerId").show();
	}else{
		$("#collection_description").hide();
		$("#headerId").hide();
	}

	//overlay
	var ovFavText = $('#ol_favorites').html();
	if( ovFavText == "Unfavorite" ){
		$('#ol_favorites').bind('click', function() {
		  	SNI.Community.Widgets.TopNavSecureD2CFavorite('removefav');
		});		
	}else{
		$('#ol_favorites').bind('click', function() {					
		  	SNI.Community.Widgets.TopNavSecureD2CFavorite('addfav');
		});		
	}
	
	SNI.Community.Widgets.crosstimeframecheck = 0;
	
	var channelId = $('#gAjChannelId').val();
	var collectionId = $('#gAjCollectionId').val();
	var wId = $('#gAjWid').val();
	var fromUrl = $('#gAjFromUrl').val();
	var ipAddress = $('#gAjIpAddress').val();
	var objectType = $('#gAjObjectType').val();
	var objId = $('#gAjObjectId').val();
	
	
	if( requestFrom == 'Ajax' ) {
		SNI.Community.refreshRelateContent( collectionId );
		
		//SNI.Util.Toolbar({ printUrl: ""  });	
	}			
	SNI.Community.Widgets.showThis($("#gAjDefaultPosition").val(),$("#gAjDefaultObjectType").val(),$("#gAjDefaultWidth").val(),$("#gAjDefaultHeight").val(),false);
	SNI.Community.Widgets.stats(channelId,collectionId,wId,fromUrl,'',ipAddress,'0','1','1',objectType);
	SNI.Community.Widgets.stats(channelId,objId,wId,fromUrl,'',ipAddress,'0','2','1',objectType);
	SNI.Community.Widgets.channelStats(channelId);
	SNI.Community.Widgets.inAppItemId = objId;
	
	try{	
		document.getElementById('txtEmfContent').value =escape(document.getElementById('cgp-id-emf-middle-container').innerHTML);
		document.getElementById('txtEmfTitleContent').value = escape("<div id='cgp-id-emf-title'>"+document.getElementById('cgp-id-emf-title').innerHTML+"</div>");
		document.getElementById('txtButtonContent').value = escape(document.getElementById('cgp-newedit-new-space-upload-button').innerHTML);
	}catch(e){}
	SNI.Community.Widgets.emfPosition();

	globalPrevNextPos = $('#gAjGlobalPrevNextPos').val();
	SNI.Community.Widgets.handleRated();
	if(SNI.Community.Widgets.getratingscookie(1)){
		 $('#rtng_cntr span').width((SNI.Community.Widgets.getratingscookie(1)*20)+'%');
	}else{
		 $('#rtng_cntr span').width('0%');
	}	
	
	var userLogin = $('#gUserLogin').val();
	var ur = $('#gUrNonur').val();
	
	if(userLogin=="false" && ur == "true"){
		$('#rtng_cntr span').width('0%');
	}
	
	ratingOptionText[0]=$('#gAjRatingOptionText1').val();
	ratingOptionText[1]=$('#gAjRatingOptionText2').val();
	ratingOptionText[2]=$('#gAjRatingOptionText3').val();
	ratingOptionText[3]=$('#gAjRatingOptionText4').val();
	ratingOptionText[4]=$('#gAjRatingOptionText5').val();
	
	if( SNI.Community.Widgets.Get_Cookie('pickle_pv_sort_order') != null ){
		mdManager.addParameter("SortOrderDetailPage", SNI.Community.Widgets.Get_Cookie('pickle_pv_sort_order'));
	 }
	
	if( SNI.Community.Widgets.Get_Cookie('pickle_pv_time_frame') != null ){
		mdManager.addParameter("TimeFrameDetailPage", SNI.Community.Widgets.Get_Cookie('pickle_pv_time_frame')); 
	}	
	
	//$('.ajaxpageloader').hide();
	
	//JEE, Vasanth Adding Interstitial Ads Code
	//SNI.DynamicAds.init({ container: $(".id-w"),
	//insert_tgt: $("#cgp-id-page-image-image"),
	try{
	if( typeof(SNI.DynamicAds) != 'undefined' ){
		SNI.DynamicAds.init( { container: $('.item_display'), insert_tgt: $('.interWrapParent'), dismiss_elts: $('.img_pre, .img_next') } );  
		inter_wrap = $('<div class="interwrap"></div>').appendTo(".interWrapParent");
	}
	}catch(e){}	
	
	
}

function changeSortOrder(sortOrderParam){
	var pageSortOrder = $('#gAjPageSortOrder').val();
	var pvFrPagePageCookie = $('#gAjPVFrPageCookie').val();
	var currentSortOrder = pageSortOrder;
	
	// SNI.Community.Widgets.Set_Cookie( 'pickle_pv_from_page','gallery', '1', '/', '', '' );
	// SNI.Community.Widgets.Set_Cookie( pvFrPagePageCookie,'gallery', '1', '/', '', '' );
	// SNI.Community.Widgets.Set_Cookie( 'pickle_changed','true', '1', '/', '', '' );
	// SNI.Community.Widgets.Set_Cookie( 'pickle_pv_sort_order',sortOrderParam, '1', '/', '', '' );
	
	document.getElementById('gAjPVPickleChanged').value = 'true';
	document.getElementById('gAjPVSortOrderCookieValue').value = sortOrderParam;
	document.getElementById('gAjPVTimeFrameCookieValue').value = '7'; 
	document.getElementById('gAjPVPageNumberCookieValue').value = '1'; 
	
	// if(currentSortOrder==2){
	if( sortOrderParam == 2 ){
	
		// SNI.Community.Widgets.Delete_Cookie( 'pickle_pv_time_frame', '/', '' );
		document.getElementById('gAjPVTimeFrameCookieValue').value = '0'; // I should see all matching results from All Time whenever I view Most Recent. 
		
		// consult this below block with shan since it used to read the value from cookie
		
		// if(!SNI.Community.Widgets.Get_Cookie('pickle_pv_user_search')){
		//if( document.getElementById( 'gAjPVUsrSearchCookieValue') ) {
			//SNI.Community.Widgets.Set_Cookie( 'pickle_pv_time_frame','7', '1', '/', '', '' );
			//document.getElementById('gAjPVTimeFrameCookieValue').value = '7';
		// }
	}
	
	//location.reload();
	SNI.Community.TopNavDetailSortAjaxRefresh("","detailpage",SNI.Community.objectId);
}

SNI.Community.Widgets.appendPoundFollwedUrl = function(){
	document.getElementById('dummyHrefForUrlChange').onClick = new Function("return false;");
	document.getElementById('dummyHrefForUrlChange').href= $('#gAjDetailPageURLWithoutDomain').val();
	var bAgent = navigator.userAgent;
	if( bAgent.indexOf("Chrome") != -1 ){
		try{
			SNI.Community.Widgets.fireEvent(document.getElementById('dummyHrefForUrlChange'),'click');
		}catch(e){}	
	}else{
		document.getElementById('dummyHrefForUrlChange').click();		
	}
	
	
	SNI.Community.Widgets.topClickSortModifier = false;
}

function changeTimeline(day){
	var pageSortOrder = $('#gAjPageSortOrder').val();
	var currentSortOrder = pageSortOrder;
	var sortOrderAssigned = false;
	//SNI.Community.Widgets.Set_Cookie( 'pickle_pv_from_page','gallery', '1', '/', '', '' );
	if(currentSortOrder==4 && parseInt(day)!=1){
		//SNI.Community.Widgets.Set_Cookie( 'pickle_pv_sort_order','4', '1', '/', '', '' );
		document.getElementById('gAjPVSortOrderCookieValue').value = '4';
		sortOrderAssigned = true;
	}
	if(currentSortOrder==3 && parseInt(day)!=1){
		//SNI.Community.Widgets.Set_Cookie( 'pickle_pv_sort_order','3', '1', '/', '', '' );
		document.getElementById('gAjPVSortOrderCookieValue').value = '3';
		sortOrderAssigned = true;
	}
	if(parseInt(day)==0 && currentSortOrder==3){
		//SNI.Community.Widgets.Set_Cookie( 'pickle_pv_sort_order','3', '1', '/', '', '' );
		document.getElementById('gAjPVSortOrderCookieValue').value = '3';
		sortOrderAssigned = true;
	}
	
	//SNI.Community.Widgets.Set_Cookie( 'pickle_changed','true', '1', '/', '', '' );
	//SNI.Community.Widgets.Set_Cookie( 'pickle_pv_time_frame',day, '1', '/', '', '' );
	
	if( !sortOrderAssigned ){
		document.getElementById('gAjPVSortOrderCookieValue').value = pageSortOrder;
	}
	
	document.getElementById('gAjPVPickleChanged').value = 'true';	
	document.getElementById('gAjPVTimeFrameCookieValue').value = day;
	
	SNI.Community.TopNavDetailSortAjaxRefresh("","detailpage",SNI.Community.objectId);
	
}

SNI.Community.initializeTopLayoutOmnitureEvent = function(){
	//alert('SNI.Community.initializeTopLayoutOmnitureEvent ');
	SNI.Omniture.MultiVar("#tophat", "Header");	

	//SNI.Omniture.MultiVar('#rmr_short_toprated', 'Rate my Remodel Sort Top Rated'.replace('&rsquo;','\u0027'));
	//SNI.Omniture.MultiVar('#rmr_short_mostrecent', 'Rate my Remodel Sort Most Recent'.replace('&rsquo;','\u0027'));
	//SNI.Omniture.MultiVar('#rmr_short_mostrelevent', 'Rate my Remodel Sort Most Relevent'.replace('&rsquo;','\u0027'));
	//SNI.Omniture.MultiVar('#rmr_sort_mostviewed', 'Rate my Remodel Sort Most Viewed'.replace('&rsquo;','\u0027'));

	//gallery page
	
	if(SNI.Community.UR.logged_in==true){
		//SNI.Omniture.MultiVar('#rmr_flag', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Flag');  				
		SNI.Omniture.MultiVar('#main_inner_rating_stars_omnt', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Ratings')
		SNI.Omniture.MultiVar('#pc_omniture1', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Post Comment');
		SNI.Omniture.MultiVar('#pc_omniture2', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Post Comment');  				
	}
	
	SNI.Omniture.MultiVar('#rmr_email', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Email');
	SNI.Omniture.MultiVar('#tb-tweet', 'Rate my Remodel Tweet'.replace('&rsquo;','\u0027'));
	SNI.Omniture.MultiVar('#tb-facebook', 'Rate my Remodel Facebook'.replace('&rsquo;','\u0027'));
	//SNI.Omniture.MultiVar('#nav_prv_project', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Next Gallery');
	//SNI.Omniture.MultiVar('#nav_nxt_project', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Previous Gallery');  				
	
	//SNI.Omniture.ClickTrackFire('#post-comment-omnt', SNI.Community.siteCode+' : '+SNI.Community.projectName+' - Post Comment');
}

SNI.Community.refreshRelateContent = function( objectId){

	try{
		
		if ( document.getElementById("isRMR") ) {
			$('.sni-e').remove();
		}
	}
	catch(e){}
	try{
	
	
	var rcHtml = "<div class='sni-e'>";
	rcHtml += "</div>";
		
	if( document.getElementById("isRMR") ){
		$('#below_main_well').append( rcHtml );	
	}
	else{
		rcHtml = "<div id='twocol-col2'>";
		rcHtml += "</div>";
		$('#below_main_well_tc').append( rcHtml );
	}
	 
	SNI.Community.relatedContentAjaxRefresh( objectId, 'usergalleryrc');
	SNI.Community.relatedContentAjaxRefresh( objectId, 'catgegoryalleryrc');
	
	
	}catch(e){}
}


SNI.Community.relatedContentAjaxRefresh = function(objectId, requestFor ){

	// alert( requestFor );
	var gAjaxUrl = document.getElementById("gAjaxUrl").value;
	var siteId = $('#projectSiteId').val();
	var wid = 0;
	
	if( requestFor=='usergalleryrc' ){
		wid = pageLoaduserrcwid;
	} else {
		wid = pageLoadcategoryrcwid;
	}
	
	var categoryTag = $("#gSystemTagListD2C").val();
	var wpid = $('#gLWidPid').val();
	
	targetUrl = gAjaxUrl+"/relatedcontent.do?wid="+wid+"&projectId="+wpid+"&rf=ajax";
	targetUrl += "&siteid="+siteId+"&oid="+objectId+"&categoryTag="+escape(categoryTag);	
	
	jQuery.ajax({ 	url: targetUrl, 
					success: function( data ) {
						if( document.getElementById("isRMR")  ){
							$('.sni-e').append( data );
						} else{
							$('#twocol-col2').append( data );							
						}
					}, 
					async:   false
	});  
	
	
}


function resetCookies(){
	SNI.Community.Widgets.Delete_Cookie( $('#gAjPVUsrSearchCookie').val(), '/', '' );
	SNI.Community.Widgets.Delete_Cookie( $('#gAjPVCatCookie').val(), '/', '' );
	SNI.Community.Widgets.Delete_Cookie( $('#gAjPVTimeFrameCookie').val(), '/', '' );
	SNI.Community.Widgets.Delete_Cookie( $('#gAjPVPageCookie').val(), '/', '' );
	SNI.Community.Widgets.Delete_Cookie( $('#gAjPVGallUrlCookie').val(), '/', '' );
	SNI.Community.Widgets.Set_Cookie( $('#gAjPVFrPageCookie').val(),'gallery', '1', '/', '', '' );
	SNI.Community.Widgets.Set_Cookie( $('#gAjPVSortOrderCookie').val(),'2', '1', '/', '', '' );
	SNI.Community.Widgets.Set_Cookie( 'pickle_changed','true', '1', '/', '', '' );
}	
function orderByUserIdWithoutReload( userIdFromRC, userNameFromRC ){
	SNI.Community.Widgets.Delete_Cookie( $('#gAjPVUsrSearchCookie').val(), '/', '' );
	SNI.Community.Widgets.Delete_Cookie( $('#gAjPVCatCookie').val(), '/', '' );
	SNI.Community.Widgets.Set_Cookie( $('#gAjPVPageCookie').val(),'1', '1', '/', '', '' );
	SNI.Community.Widgets.Delete_Cookie( $('#gAjPVTimeFrameCookie').val(), '/', '' );
	SNI.Community.Widgets.Set_Cookie( $('#gAjPVFrPageCookie').val(),'gallery', '1', '/', '', '' );
	SNI.Community.Widgets.Set_Cookie( $('#gAjPVSortOrderCookie').val(),'4', '1', '/', '', '' );
	SNI.Community.Widgets.Set_Cookie( $('#gAjPVTimeFrameCookie').val(),'0', '1', '/', '', '' );	
	
	//The following switch is works when click items from RCW in TBA uploads
	if( document.getElementById('unapproved_flag') == null ) {
		SNI.Community.Widgets.Set_Cookie( $('#gAjPVCreatedUserIdCookie').val(),$('#gAjVieUserId').val(), '1', '/', '', '' );
		SNI.Community.Widgets.Set_Cookie( $('#gAjPVCreatedUserNameCookie').val(),$('#gAjVieDisplayName').val(), '1', '/', '', '' );
	} else {
		SNI.Community.Widgets.Set_Cookie( $('#gAjPVCreatedUserIdCookie').val(),userIdFromRC, '1', '/', '', '' );
		SNI.Community.Widgets.Set_Cookie( $('#gAjPVCreatedUserNameCookie').val(),userNameFromRC, '1', '/', '', '' );	
	}
}
function orderByUserId(){
	resetCookies();
	SNI.Community.Widgets.Set_Cookie( $('#gAjPVCreatedUserIdCookie').val(),$('#gAjVieUserId').val(), '1', '/', '', '' );
	SNI.Community.Widgets.Set_Cookie( $('#gAjPVCreatedUserNameCookie').val(),$('#gAjVieDisplayName').val(), '1', '/', '', '' );
	location.reload();
}

var objArr = new Array();
var objTextArr = new Array();
var objIdArr = new Array();
var objTagArr = new Array();
var objCaptionArr = new Array();
var objProducerArr = new Array();
var objImgArr = new Array();
var objWidthArr = new Array();
var objHeightArr = new Array();
var objAspectRatio = new Array();


/* End Previous Next AJAX approach */

SNI.Community.Widgets.callNielsenTracking = function ()
{
	try{
		// Added by Prabakaran Vijayakumar (for Web Analytics)
		SNI.Nielsen.trackNSE(); 
		//alert('Nielson Tracking Tagged !.....');
	}catch(e){}
}

SNI.Community.Widgets.redirectPoundSignUrl = function (){
	var browserUrl = document.location+"";
	if( browserUrl.indexOf("#") != -1 ){
		var splitedUrl = browserUrl.split("#");
	
		if( splitedUrl.length > 1 
			&& splitedUrl[1].indexOf("oid")!=-1){
			var firstUrl = splitedUrl[0];
			var secondUrl = splitedUrl[1];
	
			var firstUrlSplit = firstUrl.split("/");
			var secondUrlSplit = secondUrl.split("/");
			
			//alert('firstUrlSplit :'+firstUrlSplit.length+' , secondUrlSplit :'+secondUrlSplit.length)
	
			var newUrl = "";
			for(var i=0;i<firstUrlSplit.length;i++){
				if(i<secondUrlSplit.length){
					if( i== ( secondUrlSplit.length-1 ) ){
						newUrl  += firstUrlSplit[i];
					}else{
						newUrl  += firstUrlSplit[i]+"/";
					}
				}
			}
			newUrl += secondUrl;
			document.location = newUrl;
		}
	}
	
}

SNI.Community.Widgets.isMobile = function() {

    alert("Checking for cell phones");
	var isCellphone = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())); 
    if (isCellphone) {  
     	var currentUrl=document.location.href;
      	currentUrl=currentUrl.replace("/registration/", "/mreg/");
      	document.location = currentUrl;
    }  

}

