var CsCommentNew = 0;
CsComment = function( productId, content ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var response = xml.getElementsByTagName( 'r' ).item(0);
window.scrollTo( $( 'comments' ).offsetLeft, $( 'comments' ).offsetTop );
$( 'comments' ).innerHTML = response.getAttribute( 'c' );
DrElement.show( $( 'CsCommentsCounterContainer' ) );
$( 'CsCommentCount' ).innerHTML = ( parseInt( $( 'CsCommentCount' ).innerHTML ) + 1 );
$( 'CsCommentCountM' ).innerHTML = parseInt( $( 'CsCommentCount' ).innerHTML ) == 1 ? '' : 's';
$( 'watchlist_popup_link' ).innerHTML = response.getAttribute( 'link' );
restoreHiddenComments();
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.comment&productId=' + productId + '&watch_comment=' + ( $( 'watch_1' ).checked ?1:0 )+ '&watch_endorsement=' + ($( 'watch_2' ).checked ?1:0) + '&watch_blog=' + ( $( 'watch_6' ).checked ? 1:0) + '&watch_edit=' + ( $( 'watch_5' ).checked ? 1:0 ) + '&comment=' + content );
}
CsUserRating = function( commentId, rating, authorUserId ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var response = xml.getElementsByTagName( 'r' ).item(0);
$( 'comment_' + response.getAttribute( 'id' ) + '_user_rating' ).innerHTML = response.getAttribute( 'c' );
$( 'comment_' + response.getAttribute( 'id' ) + '_rating_result' ).innerHTML = response.getAttribute( 'd' );
commentRating[ response.getAttribute( 'id' ) ] = parseInt( response.getAttribute( 'r' ) );
}
DrAjax.sendRequest(
'AjaxServer.php', this.getResponse, 'call=Product.commentRating&commentId=' + commentId + '&rating=' + rating + '&authorId=' + authorUserId
);
if( rating == -1 && !commentsHidden[ commentId ] ) {
hideComment( commentId );
} else if( rating == 1 && commentsHidden[ commentId ] ) {
showComment( commentId );
}
commentUserRating[ commentId ] = 1;
}
CsWatchlistSet = function( productId, userId ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var result = xml.getElementsByTagName( 'ok' );
if( result.length ) {
$( 'watchlist_popup_link' ).innerHTML = result[ 0 ].getAttribute( 'link' );
}
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.watch&productId=' + productId + '&userId=' + userId + '&watch_comment=' + ( $( 'main_watch_1' ).checked ?1:0 )+ '&watch_endorsement=' + ($( 'main_watch_2' ).checked ?1:0) + '&watch_blog=' + ( $( 'main_watch_6' ).checked ? 1:0) + '&watch_edit=' + ( $( 'main_watch_5' ).checked ? 1:0 ) );
PopupTrasher.killEmAll();
}
var CsCommentWatchOptionsFirst = true;
CsCommentWatchOptions = function( productId, userId ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var response = xml.getElementsByTagName( 'code' ).item(0);
$( 'watch_options_container' ).innerHTML = response.getAttribute( 'xhtml' );
}
if( CsCommentWatchOptionsFirst ) {
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.getProductWatchOptions&productId=' + productId + '&userId=' + userId );
}
CsCommentWatchOptionsFirst = false;
}
CsWatchlistSettings = function( productId, userId, element ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var response = xml.getElementsByTagName( 'code' ).item(0);
PopupTrasher.killEmAll();
var popup = DrElement.create( element.parentNode, 'div', 'watchlistPopup' + productId + parseInt( 100 * Math.random() ), { display: 'none', position: 'absolute', clear: 'left', width: '400px' } );
popup.innerHTML =
'
'
DrElement.fadeIn( popup, 300 );
PopupTrasher.register( popup );
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.getProductWatchOptions&productId=' + productId + '&userId=' + userId + '&main=1');
}
if( !commentsHidden ) {
var commentsHidden = [];
}
function hideComment( commentId, quick ) {
if( quick || Dr.safari ) {
DrElement.hide( $( 'comment_' + commentId ) );
DrElement.hide( $( 'comment_' + commentId + '_hide' ) );
DrElement.show( $( 'comment_' + commentId + '_show' ) )
} else {
DrElement.fadeOut( $( 'comment_' + commentId ) );
DrElement.hide( $( 'comment_' + commentId + '_hide' ) );
DrElement.fadeIn( $( 'comment_' + commentId + '_show' ) )
}
commentsHidden[ commentId ] = 1;
}
function showComment( commentId, quick ) {
if( quick || Dr.safari ) {
DrElement.hide( $( 'comment_' + commentId + '_show' ) );
DrElement.show( $( 'comment_' + commentId ) );
DrElement.show( $( 'comment_' + commentId + '_hide' ) );
} else {
DrElement.fadeIn( $( 'comment_' + commentId ) );
DrElement.hide( $( 'comment_' + commentId + '_show' ) );
DrElement.fadeIn( $( 'comment_' + commentId + '_hide' ) );
}
commentsHidden[ commentId ] = 0;
}
function restoreHiddenComments() {
for( commentId in commentsHidden ) {
if( commentsHidden[ commentId ] ) {
hideComment( commentId, true );
}
}
}
CsSaveCommentFilter = function( threshold ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=User.setCommentFilterThreshold&t=' + threshold );
}
CsAdminActions = function( productId, userId, element, methodName ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var response = xml.getElementsByTagName( 'code' ).item(0);
if( methodName == 'Product.productAdminActions' ) {
PopupTrasher.killEmAll();
var popup = DrElement.create( element.parentNode, 'div', 'adminActionsPopup' + productId, { display: 'none', position: 'absolute', clear: 'left', width: '400px' } );
} else {
var popup = $('adminActionsPopup' + productId);
}
popup.innerHTML =
''
if( methodName == 'Product.productAdminActions' ) {
DrElement.fadeIn( popup, 300 );
PopupTrasher.register( popup );
}
}
var methodName = (methodName == null) ? 'Product.productAdminActions' : methodName;
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.getProductAdminActions&productId=' + productId + '&userId=' + userId + '&method=' + methodName );
}
CsAdminEditProductName = function( productId, userId ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var result = xml.getElementsByTagName( 'ok' );
if( result.length ) {
nameField = $( 'prodname_' + productId );
nameField.innerHTML = newName;
document.title = newName + ' - CrowdStorm';
}
}
var newName = $('product_name').value;
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.changeProductName&productId=' + productId + '&userId=' + userId + '&productName=' + newName );
PopupTrasher.killEmAll();
}
CsAdminDeactivateProduct = function( productId, userId ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var result = xml.getElementsByTagName( 'ok' );
if( result.length ) {
nameField = $( 'prodname_' + productId );
nameField.innerHTML = nameField.innerHTML + ' [NOT ACTIVE]';
document.title = nameField.innerHTML + ' - CrowdStorm';
}
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.deactivateProduct&productId=' + productId + '&userId=' + userId );
PopupTrasher.killEmAll();
}
CsAdminDeactivateComment = function( commentId, userId ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var result = xml.getElementsByTagName( 'ok' );
if( result.length ) {
// nameField = $( 'prodname_' + productId );
// nameField.innerHTML = nameField.innerHTML + ' [NOT ACTIVE]';
// document.title = nameField.innerHTML + ' - CrowdStorm';
alert('Comment ' + commentId + ' is deactivated');
}
}
if ( confirm ('Really deactivate comment?') ) {
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.deactivateComment&commentId=' + commentId + '&userId=' + userId );
}
}
function commentFilter( threshold ) {
for( i in commentRating ) {
if( threshold == 2 ) {
if( !commentUserRating[ i ] && commentsHidden[ i ] ) {
showComment( i );
}
if( commentUserRating[ i ] && !commentsHidden[ i ] ) {
hideComment( i );
}
} else {
if( commentRating[ i ] >= threshold && commentsHidden[ i ] ) {
showComment( i );
}
if( commentRating[ i ] < threshold && !commentsHidden[ i ] ) {
hideComment( i );
}
}
}
new CsSaveCommentFilter( threshold );
}
var commentRating = [];
var commentsHidden = [];
var commentUserRating = [];
BuyItNow = function( productId, element ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
PopupTrasher.killEmAll();
var popup = DrElement.create( element.parentNode, 'div', 'but-it-now' + productId + parseInt( 100 * Math.random() ), { display: 'none', position: 'absolute', clear: 'left', width: '200px' } );
popup.innerHTML =
''
DrElement.fadeIn( popup, 300 );
PopupTrasher.register( popup );
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.buyItNow&productId=' + productId + '&main=1');
}
CsAdminEditMarchankLinks = function( productId, userId ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var result = xml.getElementsByTagName( 'ok' );
if( result.length ) {
}
}
var form = $('adminActions'+ productId).getElementsByTagName("input");
var sPath = '';
for ( i = 0; i < form.length; i++ ) {
sPath += '&'+form[i].name+'[]='+ escape(form[i].value);
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.updateMarchantLinks&productId=' + productId + '&userId=' + userId + sPath );
PopupTrasher.killEmAll();
}
CsAdminUpdateProductPhrase = function( productId, userId ) {
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var result = xml.getElementsByTagName( 'ok' );
if( result.length ) {
}
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.updateUpdateProductPhrase&productId=' + productId + '&userId=' + userId +'&phrase='+ $('keyphrase').value );
PopupTrasher.killEmAll();
}
function deleteMarchanLink( productId , mode, p, userId ) {
p *= 2;
var productId = 6444;
var form = $('adminActions'+ productId).getElementsByTagName("input");
var sPath = '';
for ( i = 0; i < form.length; i++ ) {
if ( form[i].name.search( mode ) != -1 && ( i == p || i == p + 1 ) ) {
form[i].value = '';
}
}
this.getResponse = function( id, status ) {
if( DrAjax.statuses[ status ] == 'Complete' ) {
var xml = DrAjax.getResponse( id );
var redirect = xml.getElementsByTagName("redirect").item(0);
if ( redirect ) {
self.location = redirect.getAttribute("url");
} else {
var error = xml.getElementsByTagName("e").item(0);
if ( error ) {
alert ( error.getAttribute("m") );
} else {
parseResponse( xml );
}
}
}
}
var parseResponse = function( xml ) {
var result = xml.getElementsByTagName( 'ok' );
if( result.length ) {
}
}
var form = $('adminActions'+ productId).getElementsByTagName("input");
var sPath = '';
for ( i = 0; i < form.length; i++ ) {
sPath += '&'+form[i].name+'[]='+form[i].value;
}
DrAjax.sendRequest( 'AjaxServer.php', this.getResponse, 'call=Product.updateMarchantLinks&productId=' + productId + '&userId=' + userId + sPath );
}