
/**
 * @author Rigre G. Garciandia Sonora
 * 
 */

function ajaxShowMoreFromThisContributorListings(listingId, extraParameters) {
    populateAJAXPlaceholder(getContextName() + "search-more-from-this-contributor-listings.do?lid=" + listingId + "&" + extraParameters, "related-listings-content");
}
function ajaxAddListingToMyChannel(listingId) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=addToMyChannel&pfid=-1&lid=" + listingId);
}
function ajaxMarkAsInapropiate(listingId) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=markAsInapropiate&lid=" + listingId);
}
function ajaxSubscribe(prsid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=subscribe&prsid=" + prsid);
}
function ajaxUnSubscribe(prsid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=unsubscribe&prsid=" + prsid);
}
function ajaxActive(neid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=active&neid=" + neid);
}
function ajaxInactive(neid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=inactive&neid=" + neid);
}
function ajaxBannerActive(locale) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=activebanner&locale=" + locale);
}
function ajaxBannerInactive(locale) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=inactivebanner&locale=" + locale);
}

function ajaxActiveRelease(releaseid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=activerelease&releaseid=" + releaseid);
}
function ajaxInactiveRelease(releaseid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=inactiverelease&releaseid=" + releaseid);
}

function ajaxActiveKit(kitid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=activekit&kitid=" + kitid);
}
function ajaxInactiveKit(kitid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=inactivekit&kitid=" + kitid);
}


function ajaxActiveAds(adsid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=activeads&adsid=" + adsid);
}
function ajaxInactiveAds(adsid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=inactiveads&adsid=" + adsid);
}

function ajaxActiveHeadline(headlineid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=activeheadline&headlineid=" + headlineid);
}
function ajaxInactiveHeadline(headlineid) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=inactiveheadine&headlineid=" + headlineid);
}



function ajaxVoteForListing(listingId, rating) {
    if (ratingComponent.isEnableEvents()) {
        executeAJAXCommand(getContextName() + "anonymous-ajax-command.do?command=voteForListing&lid=" + listingId + "&rating=" + rating);
    }
}

function ajaxSubmitValidationEmail(email,fullName,returnURL){
	executeAJAXCommand(getContextName() + "anonymous-ajax-command.do?command=validateEmail&email=" + email + "&fullName=" + fullName+ "&returnURL=" + returnURL);
	}
	
function ajaxSubmitValidationEmailForEmail(email,fullName,returnURL){
	executeAJAXCommand(getContextName() + "anonymous-ajax-command.do?command=validateEmailForEmail&email=" + email + "&fullName=" + fullName+ "&returnURL=" + returnURL);
	}
	
function ajaxSubmitValidationEmailForComment(email,fullName,returnURL){
	executeAJAXCommand(getContextName() + "anonymous-ajax-command.do?command=validateEmailForComment&email=" + email + "&fullName=" + fullName+ "&returnURL=" + returnURL);
	}
	
function ajaxRemoveExecuteInSession(execution){
	executeAJAXCommand(getContextName() + "anonymous-ajax-command.do?command=removeExecute&execution=" + execution);
	}


function ajaxShowComments(listingId, returnUrl) {
    populateAJAXPlaceholder(getContextName() + "listing-comments.do?lid=" + listingId + "&returnurl=" + Url.encode(returnUrl), "video-comment-content");
}

function ajaxShowInterfaceManageNewsEvent(locale){
	  populateAJAXPlaceholder(getContextName() + "manage-newsevent.do?locale="+locale, "manage-newsevent-"+locale);
	  
	}
	
	
function ajaxShowInterfaceManageAds(locale){
	  populateAJAXPlaceholder(getContextName() + "manage-ads.do?locale="+locale, "manage-ads-"+locale);
	  
	}
	
function ajaxShowInterfaceManageACPress(locale,monthId,action){
	  populateAJAXPlaceholder(getContextName() + "manage-acpress.do?locale="+locale+ "&monthId="+ monthId+"&action="+ action, "manage-acpress-"+locale);
	 }
	 
function ajaxShowInterfaceManageHeadline(locale,monthId,action){
	  
	  populateAJAXPlaceholder(getContextName() + "manage-headline.do?locale="+locale+ "&monthId="+ monthId+"&action="+ action+ "&id=2009", "manage-headline-"+locale);
	 }
	
	function ajaxShowInterfaceManageNewsFrontpage(div){
	  populateAJAXPlaceholder(getContextName() + "subconfiguration.do", div);
	  
	}
		
function ajaxSubmitManageNewsEvent(formName,divName){
	populateAJAXFormPlaceholder(getContextName() + "manage-newsevent.do", createFormParameters(formName, new Array("locale","action", "pageNumber")), divName);
	}
	
	
	function ajaxSubmitManageACPress(formName,divName){
	populateAJAXFormPlaceholder(getContextName() + "manage-acpress.do", createFormParameters(formName, new Array("locale","action", "monthId")), divName);
	}
	
	function ajaxSubmitManageHeadline(formName,divName){
	populateAJAXFormPlaceholder(getContextName() + "manage-headline.do", createFormParameters(formName, new Array("locale","action", "monthId","id")), divName);
	}
	
	function ajaxSubmitRemoveNewsEvent(formName,divName){
		populateAJAXFormPlaceholder(getContextName() + "manage-newsevent.do", createFormParameters(formName, new Array("locale","id","action", "pageNumber")), divName);
	}
	
	
	function ajaxSubmitRemoveAds(formName,divName){
		populateAJAXFormPlaceholder(getContextName() + "manage-ads.do", createFormParameters(formName, new Array("locale","id","action", "pageNumber")), divName);
	}
	
	
	function ajaxSubmitRemovePress(formName,divName){
		populateAJAXFormPlaceholder(getContextName() + "manage-acpress.do", createFormParameters(formName, new Array("locale","id","action", "pageNumber")), divName);
	}
	
	function ajaxSubmitRemoveHeadline(formName,divName){
		populateAJAXFormPlaceholder(getContextName() + "manage-headline.do", createFormParameters(formName, new Array("locale","id","action", "pageNumber")), divName);
	}
	
	function ajaxSubmitConfigFrontpageForm(formName,divName){
		populateAJAXFormPlaceholder(getContextName() + "subconfiguration.do", createFormParameters(formName, new Array("welcomeENPageSize","welcomeENPageGroupSize","welcomeFRPageSize","welcomeFRPageGroupSize","welcomeESPageSize","welcomeESPageGroupSize")), divName);
	}
	
	function ajaxSubmitValidateRegisterMemberForm(formName,divName){
		populateAJAXFormPlaceholder(getContextName() + "registration-validate-altcontributor.do", createFormParameters(formName, new Array("login","name","lastname","email","password","confirmPassword","verification","logoFileName","default_logos","dateOfBirth","zipcode","phone","mobilePhone","fax","agree","informationTruthful")), divName);
	}
	
	function ajaxSubmitValidateRegisterContributorForm(formName,divName){
		populateAJAXFormPlaceholder(getContextName() + "registration-validate-altcontributor.do", createFormParameters(formName, new Array("login","name","lastname","email","password","confirmPassword","dateOfBirth","zipcode","phone","mobilePhone","fax","inEditMode")), divName);
	}
	
	function ajaxSubmitConfigFeatureVideoForm(formName,divName){
			populateAJAXFormPlaceholder(getContextName() + "manage-feature-video.do", createFormParameters(formName, new Array("featureVideoENId","featureVideoENRandom","featureVideoFRId","featureVideoFRRandom","featureVideoESId","featureVideoESRandom")),divName);
	}

function ajaxFilterComment(formVar) {
	
	var result = encodeURIComponent(formVar);
result = result.replace(/%20/g,"+");
for ( var p = result.indexOf("%u"); p != -1; p = result.indexOf("%u")  ) {
   var code = result.substr(p,6);
   var rep = '%' + code.substr(2,2) + '%' + code.substr(4,2);
   result = result.replace(code,rep);
}
var p = -1;
for ( p = result.indexOf("%",p+1); p != -1; p = result.indexOf("%",p+1)  ) {
   var code = result.substr(p,3);
   var rep = code.toUpperCase();
   result = result.replace(code,rep);
}
return result;
}
function ajaxSubmitCommentListingForm(listingId) {
	   populateAJAXFormPlaceholder(getContextName() + "listing-comments.do?lid=" + listingId, createFormParameters("commentForm", new Array("text", "action", "pageNumber")), "video-comment-content");
}

function ajaxSubmitContactList(formName,divName){
	    populateAJAXFormPlaceholder(getContextName() + "import-contact.do", createFormParameters(formName, new Array("account", "domain", "password")),divName);
	}
function ajaxMarkCommentAsSPAM(commentId) {
    executeAJAXCommand(getContextName() + "member-ajax-command.do?command=markCommentAsSPAM&comment=" + commentId);
}
function ajaxSelectPortfolio() {
    if (!isVisible("add-listing-to-my-channel-select-portfolio-content")) {
        populateAJAXPlaceholderWithPostAction(getContextName() + "search-select-portfolio.do", "add-listing-to-my-channel-select-portfolio-content", function (ajaxContext) {
            setVisible("add-listing-to-my-channel-select-portfolio-content", true);
        });
    } else {
        closeSelectPortfolio();
    }
}
function closeSelectPortfolio() {
    cleanDiv("add-listing-to-my-channel-select-portfolio-content");
    setVisible("add-listing-to-my-channel-select-portfolio-content", false);
}
function analyzePortfolioSelection(selectPortfolio) {
    if (selectPortfolio.options[selectPortfolio.selectedIndex].value == -2) {
        populateAJAXPlaceholderWithPostAction(getContextName() + "search-add-portfolio.do", "add-listing-to-my-channel-select-portfolio-content", function (ajaxContext) {
            setVisible("add-listing-to-my-channel-select-portfolio-content", true);
        });
    } else {
        changeFormProperty("searchResultForm", "destinationPortfolioId", selectPortfolio.options[selectPortfolio.selectedIndex].value);
    }
}
function ajaxSubmitAddPortfolioForm() {
    populateAJAXFormPlaceholder(getContextName() + "search-add-portfolio.do", createFormParameters("addPortfolio", new Array("name")), "add-listing-to-my-channel-select-portfolio-content");
}
function ajaxImportRSS(url, rssurl, rssindex) {
    executeAJAXCommand(getContextName() + "admin-ajax-command.do?command=importRSS&url=" + encode(url) + "&rssurl=" + Url.encode(rssurl) + "&rssindex=" + rssindex);
}
function ajaxShowSearchComponent(url, divName) {
	    populateAJAXPlaceholder(url, divName);
	   
}


function ajaxSubmitSearchComponentForm(formName, action, url, divName) {
    changeFormProperty(formName, "action", action);
    populateAJAXFormPlaceholder(url, createFormParameters(formName, new Array("newVideoState", "catalogListingState", "catalogListingId", "videoState", "action", "pageNumber", "selectedCategoryListing", "destinationPortfolioId", "viewState", "genericData", "state")), divName);
}
function ajaxNominate(listingId, nomid) {
    if (nomid != "-1") {
        executeAJAXCommand(getContextName() + "member-ajax-command.do?command=nominate&lid=" + listingId + "&nomid=" + nomid);
    }
}
//Admin site
function ajaxAdminListingChangeContextFilter() {
    var contextValue = document.adminResultForm.selectContextFilter.options[document.adminResultForm.selectContextFilter.selectedIndex].value;
    if (contextValue != "") {
        populateAJAXPlaceholder(contextValue, "admin-listings-content");
    }
}
function ajaxRecoverListingField() {
    executeAJAXCommand(getContextName() + "admin-ajax-command.do?command=recoverListingField");
}

function ajaxShowInterfaceManageFeatureVideo(div){
	  populateAJAXPlaceholder(getContextName() + "manage-feature-video.do", div);
	  
	}

//Registration
function ajaxChangePassword(form, login) {
    executeAJAXPostCommand(getContextName() + "member-ajax-command.do?command=changePassword&login=" + login, createFormParameters(form, new Array("oldPassword", "newPassword", "confirmNewPassword", "ctx")));
}
function ajaxResetPassword(login) {
    executeAJAXPostCommand(getContextName() + "admin-ajax-command.do?command=resetPassword&login=" + login);
}


//methods from ajax-commands.jsp
function commandAddToMyChannel(textSaveDone) {
		populateDiv('videoSaveButton', textSaveDone);
}

function commandMarkListingAsSPAM(commentsId,textForInappropriate) {
	
  populateDiv("mark-as-SPAM-content" + commentsId, textForInappropriate);
}
function commandImportRSS(rssid) {
	setVisible("import-rss-content-" + rssid, false);
}
function commandMarkAsInapropiate(videoFlagDoneButton) {
	populateDiv('videoFlagButton', videoFlagDoneButton);
}

function activeNewsEventCommand(id,textNewEventActiveLink) {
        populateDiv("active-inactive-"+id, textNewEventActiveLink);
}

function inActiveNewsEventCommand(id,textNewseventInactiveLink) {
            	populateDiv("active-inactive-"+id, textNewseventInactiveLink);  
}

function activeNewsEventBannerCommand(locale,textNeweventActiveLink) {
         	 populateDiv("active-inactive-banner-"+locale, textNeweventActiveLink);
}
function inActiveNewsEventBannerCommand(locale,textNewseventInactiveLink) {
           populateDiv("active-inactive-banner-"+locale, textNewseventInactiveLink);  
}
function activePressReleaseCommand(id,textNewseventActiveLink) {
         	 populateDiv("active-inactive-release-"+id, textNewseventActiveLink);
}
function inActivePressReleaseCommand(id,textNewseventActiveLink) {
         	 	populateDiv("active-inactive-release-"+id, textNewseventActiveLink);
}
function activePressKitCommand(id,textNewseventActiveLink) {
        populateDiv("active-inactive-kit-"+id, textNewseventActiveLink);
 
}
function inActivePressKitCommand(id,textNewseventActiveLink) {
         populateDiv("active-inactive-kit-"+id, textNewseventActiveLink);
}


function activeHeadlineCommand(id,textNewseventActiveLink) {
        	 populateDiv("active-inactive-release-"+id, textNewseventActiveLink);
}
function inActiveHeadlineCommand(id,textNewseventActiveLink) {
           populateDiv("active-inactive-release-"+id, textNewseventActiveLink);
}
function activeAdsCommand(id,textNewseventActiveLink) {
         	 	 populateDiv("active-inactive-"+id, textNewseventActiveLink);
}
function inActiveAdsCommand(id,textNewseventActiveLink) {
           	populateDiv("active-inactive-"+id, textNewseventActiveLink);  
}
function commandNominate(nominationCount,textDetailVideoAlreadyNominatedLabel) {
	var select = document.getElementById("nomination");
	
	if (select.item(0).value == "-1") {
		select.remove(0);
	}
	
    //populateDiv("nominate-label-content", "<spring:message code="detail.video.already.nominated.label" />");
    	populateDiv("nominate-label-content", textDetailVideoAlreadyNominatedLabel);
    populateDiv("nomination-count-content", nominationCount);
}


//RSS admin
function commandChangeRSS(code, url) {
	if (code == "ok") {
		MM_goToURL('parent', url)
	}
	
	if (code == "invalid-order") {
		//alert("<spring:message code="rss.list.error.invalid.position.label" />");
	}
}
//Edit listing admin
function commandRecoverListingField(titles, synopsis, locales, isCurrent) {
	for (var i = 0; i < locales.length; i++) {
		$("title[" + locales[i] + "]").value = titles[i];
		$("synopsis[" + locales[i] + "]").value = synopsis[i];
		if (isCurrent[i] == 'true') {
			$("tmptitle").value = titles[i];
		}
	}
	$("tmptitle").disabled=false;
	for (var i = 0; i < locales.length; i++) {
		$("title_language[" + locales[i] + "]").disabled=false;
		$("synopsis_language[" + locales[i] + "]").disabled=false;
	}
}



//Registration
function commandResetPassword(code) {
	showHideWithOverlay('change_password_box_open');
}

function commandChangePassword(code,changePasswordSuccessLabel,errorInvalidPasswordLabel,errorPasswordNotMatchLabel,errorPasswordInvalidComplexityLabel) {
	if (code == "ok") {
		alert(changePasswordSuccessLabel);
	}
	
	if (code == "invalid-password") {
		alert(errorInvalidPasswordLabel);
	}
	
	if (code == "not-match") {
		alert(errorPasswordNotMatchLabel);
	}
	
	if (code == "invalid-complexity") {
		alert(errorPasswordInvalidComplexityLabel);
	}
}



function commandSubscribe(count,detailProfileSubscribersCountLabel,detailProfileOneSubscriberCountLabel,detailProfileUnsubscribersLink) {
   if(count>1) var countlabel= detailProfileSubscribersCountLabel;
  	else countlabel=detailProfileOneSubscriberCountLabel;
	populateDiv("subscriber-count-content", count + " " + countlabel);
  populateDiv("subscriber-command", detailProfileUnsubscribersLink);
}

function commandUnSubscribe(count,detailProfileSubscribersCountLabel,detailProfileOneSubscriberCountLabel,detailProfileSubscribersLink) {
  if(count>1) var countlabel= detailProfileSubscribersCountLabel;
  	else countlabel=detailProfileOneSubscriberCountLabel;
	populateDiv("subscriber-count-content", count + " " + countlabel);
  populateDiv("subscriber-command", detailProfileSubscribersLink);
}

