/* ------------------------------------------- */
/* UnbelievableBeats.com | JavaScript Document */
/* Coded by X-JHEDStudios 					   */
/* ------------------------------------------- */

function initELEMreg(){
	regOBJ('rev_tbox','focus_blur',anim_txtbox);
}

function showLicense(licTYPE,licID,bID,bID_n){
	var icOBJ = document.getElementById('ipop_icontent');
	var licOBJ = document.getElementById(licID);
	var beatNameOBJ = document.getElementById('beat_title_'+bID);
	var a2cFRM = document.getElementById('add2cart_frm');
	if(licTYPE == 1){
		var NEbeatPriceOBJ = document.getElementById('beat_price_ne_'+bID);
		var NEbeatPriceTxtOBJ = document.getElementById('beat_price_ne_txt_'+bID);
	}else{
		var EXbeatPriceOBJ = document.getElementById('beat_price_ex_'+bID);
		var EXbeatPriceTxtOBJ = document.getElementById('beat_price_ex_txt_'+bID);
	}

	/* Replace Objects */
	var licOBJcontent = licOBJ.value;
	if(licTYPE == 1){
		licNEW = licOBJcontent.replace('{beat_price_word}',NEbeatPriceTxtOBJ.value);
		licNEW = licNEW.replace('{beat_price}',NEbeatPriceOBJ.value);
	}else{
		licNEW = licOBJcontent.replace('{beat_price_word}',EXbeatPriceTxtOBJ.value);
		licNEW = licNEW.replace('{beat_price}',EXbeatPriceOBJ.value);
	}
	licNEW = licNEW.replace("{beat_title}",beatNameOBJ.value);
	licNEW += a2cFRM.value;

	/* Display License */
	showIpop();
	icOBJ.innerHTML = licNEW;

	var a2c_bidOBJ = document.getElementById('a2c_bid');
	var a2c_licOBJ = document.getElementById('a2c_lic');
	a2c_bidOBJ.value = bID_n;
	a2c_licOBJ.value = licTYPE;
}

function roverStar(rCtr,bid,ctr){
	var rstar_id = '';
	var i = 0;
	while(i < 5){
		rstar_id = "rstar_"+ctr+"_"+bid+"_"+i;
		if(i < rCtr) document.getElementById(rstar_id).className = 'rslink_hov';
		else document.getElementById(rstar_id).className = 'rslink';
		i++;
	}
}

function returnStar(rtg,ctr,bid){
	var i = 0;
	while(i < 5){
		if(i < rtg) cName = 'rslink_sel';
		else cName = 'rslink';
		document.getElementById('rstar_'+ctr+'_'+bid+'_'+i).className = cName;
		i++;
	}
}

function rateBeat(bid,rating){
	conURL = sdom+"modules/ajax-rate-beat.mod.php?bid="+bid+"&rating="+rating;
	http_request.abort(); http_request.onreadystatechange = rateBeat_response;
	/* Send Request */
	http_request.open('GET', conURL, true); http_request.send(null); return http_request;
}

function rateBeat_response(){
	var icOBJ = document.getElementById('ipop_icontent');
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			icOBJ.innerHTML = http_request.responseText;
			showIpop();
			if(document.getElementById('just_rated')) autoHideIPOP();
		}
		else{ showIpop(); icOBJ.innerHTML = "<div class=\"ipc_inner\">"+writeMessage('lost_connection')+"<p class=\"fs_11px mb_0px col_999999\">This message will automatically close in <span id=\"timerCTR\">5</span> seconds.</p></div>"; autoHideIPOP(); }
	}
}

function addToFavs(bid){
	conURL = sdom+"modules/ajax-add-to-favs.mod.php?bid="+bid;
	http_request.abort(); http_request.onreadystatechange = add2favs_response;
	/* Send Request */
	http_request.open('GET', conURL, true); http_request.send(null); return http_request;
}

function add2favs_response(){
	var icOBJ = document.getElementById('ipop_icontent');
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			icOBJ.innerHTML = http_request.responseText;
			showIpop();
			if(document.getElementById('just_faved')) autoHideIPOP();
		}
		else{ showIpop(); icOBJ.innerHTML = "<div class=\"ipc_inner\">"+writeMessage('lost_connection')+"<p class=\"fs_11px mb_0px col_999999\">This message will automatically close in <span id=\"timerCTR\">5</span> seconds.</p></div>"; autoHideIPOP(); }
	}
}

var curr_UID;
var curr_UNAME;
function postReview(bid,uid,uname){
	reviewOBJ = document.getElementById('rev_tbox');
	msgOBJ = document.getElementById('ajax_save');
	buttonsOBJ = document.getElementById('ajax_save_buttons');
	buttonsOBJ.style.display = 'none';
	curr_UID = uid;
	curr_UNAME = uname;

	reviewOBJ.disabled = true;
	msgOBJ.innerHTML = "<p class=\"fs_12px fbold\">"+writeMessage('loader_b')+"</p>";

	review = escape(reviewOBJ.value);
	conURL = sdom+"modules/ajax-post-reviews.mod.php?bid="+bid+"&uid="+uid+"&review="+review;
	http_request.abort(); http_request.onreadystatechange = postReviews_response;
	/* Send Request */
	http_request.open('GET', conURL, true); http_request.send(null); return http_request;
}

function postReviews_response(){
	if (http_request.readyState == 4){
		if (http_request.status == 200){
			response_value = http_request.responseText;
			if(response_value == 1){
				reviews_allOBJ = document.getElementById('reviews_all');
				reviewOBJ = document.getElementById('rev_tbox');
				msgOBJ = document.getElementById('ajax_save');
				revCTRobj = document.getElementById('revCTR');
				
				if(parseInt(revCTRobj.value)%2) bgCol = " bgcol_484d58";
				else bgCol = "";

				msgOBJ.innerHTML = "<span class=\"fs_11px\">Congrats! Your comment has been successfully posted.</span>";
				reviews_allOBJ = document.getElementById('reviews_all');
				newReview = "<div class=\"rbc_inner"+bgCol+"\"><a href=\""+sdom+"ub/forum/profile.php?id="+curr_UID+"\" class=\"avatar\"><img src=\""+sdom+"images/avatars/"+uAvatar+"\" width=\"46\" class=\"fl\" border=\"0\" /></a><p class=\"fs_11px mb_5px\">Posted by <a href=\""+sdom+"ub/forum/profile.php?id="+curr_UID+"\" class=\"ub_links_FFFFFF fbold\">"+curr_UNAME+"</a> on "+cDate+" </p><p class=\"fs_12px mb_0px col_b6b8be\">"+reviewOBJ.value+"</p></div>";

				// RENDER NEW REVIEW
				if(revCTRobj.value > 0) reviews_allOBJ.innerHTML += newReview;
				else reviews_allOBJ.innerHTML = newReview;
			}
		}
		else{ icOBJ.innerHTML = "<div class=\"fs_11px\">"+writeMessage('lost_connection')+"</div>"; }
	}
}

function valRevFRM(bid,uid,uname){
	reviewOBJ = document.getElementById('rev_tbox');
	if(reviewOBJ.value == ""){
		alert("Please enter your comment to proceed");
		reviewOBJ.focus();
		return false;
	}
	postReview(bid,uid,uname);
}

function valA2C(){
	var chkOBJ = document.getElementById('agree');
	if(chkOBJ.checked == false){
		alert("You must first read and agree with the License Agreement to purchase Beat License.");
		return false;
	}
}

function tooltip(tid,tvalue,divPosOBJ){
	var tooltipOBJ = document.getElementById('tooltip');
	var tooltipConOBJ = document.getElementById('tooltip_content');
	var tvalueOBJ;

	newPos = getDIVPosABSO(divPosOBJ);

	tooltipOBJ.style.position = 'absolute';
	tooltipOBJ.style.top = (newPos[1]+22)+'px';
	/* DISPLAY CONTENT */
	tooltipConOBJ.innerHTML = document.getElementById('tooltip_lic_'+tid).value;
	if(tid == 1){
		tooltipOBJ.style.left = newPos[0]-130+'px';
		tvalueOBJ = document.getElementById('ttlic_01');
		tvalueOBJ.innerHTML = tvalue;
	}else if(tid == 2){
		tooltipOBJ.style.left = newPos[0]-150+'px';
		tvalueOBJ = document.getElementById('ttlic_02');
		tvalueOBJ.innerHTML = tvalue;
	}else if(tid == 3){
		tooltipOBJ.style.left = newPos[0]-125+'px';
	}
	tooltipOBJ.style.display = 'block';
}

function hideTooltip(){
	var tooltipOBJ = document.getElementById('tooltip');
	var tooltipConOBJ = document.getElementById('tooltip_content');
	tooltipOBJ.style.display = 'none';
	tooltipConOBJ.innerHTML = '';
}

/* ---------------------------------------------------------- */
/* -------------------- Custom Beats Start ------------------ */
var processing = '<img src="'+sdom+'images/loading-small.gif" align="top" /> Loading... Please Wait...';;

function showCB(cid){
	var ipop_con = document.getElementById('ipop_icontent_wide');
	ipop_con.innerHTML = "";

	ipop_con.innerHTML = processing;
	$.get(sdom+"modules/ajax-custombeats-main.mod.php", { cb_id: cid },
	function(data){
		ipop_con.innerHTML = data;
	});

	showIpopWide();
}

function showCBupdates(cid){
	var ipop_con = document.getElementById('ipop_icontent_wide');
	ipop_con.innerHTML = "";

	ipop_con.innerHTML = processing;
	$.get(sdom+"modules/ajax-manage-cb-updates.mod.php", { cb_id: cid },
	function(data){
		ipop_con.innerHTML = data;
	});
}

function showCBinvoice(cid){
	var ipop_con = document.getElementById('ipop_icontent_wide');
	ipop_con.innerHTML = "";

	ipop_con.innerHTML = processing;
	$.get(sdom+"modules/ajax-manage-cb-invoice.mod.php", { cb_id: cid },
	function(data){
		ipop_con.innerHTML = data;

		var ipop_con_n = document.getElementById('invoice_con');
		ipop_con_n.innerHTML = "";
	
		ipop_con_n.innerHTML = processing;
		$.get(sdom+"_modules/ajax-manage-cb-prices.mod.php", { cb_id: cid, dontCheck: 1 },
		function(data){
			ipop_con_n.innerHTML = data;
		});

	});
}

/* ---------------------------------------------------------- */

function sendCBUpdates(cbID){
	var detailsOBJ = document.getElementById('details');
	var sendCBUpd_buttonOBJ = document.getElementById('sendCBUpd_button');

	if(detailsOBJ.value == false){
		alert('Message Box must not contain a Null value. Please enter your message to proceed.');
		detailsOBJ.focus();
		return false;
	}

	var ipop_con = document.getElementById('cbu_container');
	ipop_con.innerHTML = "";

	detailsOBJ.disabled = true;
	sendCBUpd_buttonOBJ.disabled = true;

	ipop_con.innerHTML = processing;
	$.get(sdom+"modules/ajax-custombeats-save-converse.mod.php", { cb_id: cbID, details: detailsOBJ.value, type: 0 },
	function(data){
		ipop_con.innerHTML = data;
		detailsOBJ.disabled = false;
		sendCBUpd_buttonOBJ.disabled = false;
	});

}

function sendCBUpdatesEdit(cbID,cbuID){
	var detailsOBJ = document.getElementById('cbu_text_edit'+cbuID);

	if(detailsOBJ.value == false){
		alert('Message Box must not contain a Null value. Please enter your message to proceed.');
		detailsOBJ.focus();
		return false;
	}

	var ipop_con = document.getElementById('cbu_container');
	ipop_con.innerHTML = "";

	ipop_con.innerHTML = processing;
	$.get(sdom+"modules/ajax-custombeats-save-converse.mod.php", { cb_id: cbID, cbu_id: cbuID, details: detailsOBJ.value, type: 1 },
	function(data){
		ipop_con.innerHTML = data;
	});

}

function editCBUpdate(cbID,cbuID){
	cbu_text_conOBJ = document.getElementById('cbu_text_con'+cbuID);
	cbu_text_editOBJ = document.getElementById('cbu_text_edit'+cbuID);
	sendCBUpd_buttonOBJ = document.getElementById('sendCBUpd_button'+cbuID);
	cancelCBUpd_buttonOBJ = document.getElementById('cancelCBUpd_button'+cbuID);
	
	cbu_text_conOBJ.style.display = 'none';
	cbu_text_editOBJ.style.display = 'block';
	sendCBUpd_buttonOBJ.style.display = 'inline';
	cancelCBUpd_buttonOBJ.style.display = 'inline';
}

function cancelCBUpdate(cbID,cbuID){
	cbu_text_conOBJ = document.getElementById('cbu_text_con'+cbuID);
	cbu_text_editOBJ = document.getElementById('cbu_text_edit'+cbuID);
	sendCBUpd_buttonOBJ = document.getElementById('sendCBUpd_button'+cbuID);
	cancelCBUpd_buttonOBJ = document.getElementById('cancelCBUpd_button'+cbuID);
	
	cbu_text_conOBJ.style.display = 'block';
	cbu_text_editOBJ.style.display = 'none';
	sendCBUpd_buttonOBJ.style.display = 'none';
	cancelCBUpd_buttonOBJ.style.display = 'none';
}

function deleteCBUpdate(cbID,cbuID){
	var actReq = confirm("Warning: This operation cannot be undone.\nAre you sure you want to remove this Update?");
	if (actReq == true){
		var ipop_con = document.getElementById('cbu_container');
		ipop_con.innerHTML = "";
	
		ipop_con.innerHTML = processing;
		$.get(sdom+"modules/ajax-custombeats-save-converse.mod.php", { cb_id: cbID, cbu_id: cbuID, type: 2 },
		function(data){
			ipop_con.innerHTML = data;
		});
	}else{
		return false;
	}
}

function popPlay(fid){
	window.open (sdom+"sinplayer/index.php?fid="+fid,"popPlay","resizable=no,width=486,height=120"); 
}

/* -------------------- Custom Beats End -------------------- */
/* ---------------------------------------------------------- */
