var ajaxRequest = "";

function encodeString(TheString){
TheString = TheString.replace(/ /g, "^^")
TheString = TheString.replace(/\n/g, "##");
return TheString;
}

function setAjaxVariable()
{
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}
}

if(document.getElementById('r1link')){
	document.getElementById('r1link').className = 'spanover';
	document.getElementById('reviews').style.background = "url('/img/review"+document.getElementById('image1').innerHTML+".jpg') no-repeat bottom left";
	for (j=0;j<=document.getElementById('numreviews').value;j++){
		preLoad = document.createElement("img");
		preLoad.className = 'preload';
		preLoad.style.background = 'url(\'/img/review'+document.getElementById('image'+j).innerHTML+'.jpg\')';
		document.getElementById('reviews').insertBefore(preLoad,document.getElementById('reviews').lastChild);
	}
}
else if(document.getElementById('reviews')){
	document.getElementById('reviews').style.background = "url('/img/review5.jpg') no-repeat bottom left";
}

function changeReview(whichReview){
	for (i=0;i<=document.getElementById('numreviews').value;i++){
		if(document.getElementById('review'+i).innerHTML == 'shown'){
			document.getElementById('review'+i).innerHTML = document.getElementById('activereview').innerHTML;
			document.getElementById('r'+i+'link').className = '';
			break;
		}
	}
	document.getElementById('activereview').innerHTML = document.getElementById('review'+whichReview).innerHTML;
	document.getElementById('review'+whichReview).innerHTML = 'shown';
	document.getElementById('r'+whichReview+'link').className = 'spanover';
	document.getElementById('reviews').style.background = "url('/img/review"+document.getElementById('image'+whichReview).innerHTML+".jpg') no-repeat bottom left";
}

function addReview(whichElement){
	var ajaxDisplay = document.getElementById(whichElement);
	setAjaxVariable();
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	
	var thereview = encodeString(document.getElementById('thereview').value);
	var reviewname = encodeString(document.getElementById('reviewname').value);
	
	document.getElementById('numreviews').value = (document.getElementById('numreviews').value*1)+1;
	newReview = document.createElement("div");
	newReview.className = 'reviewcache';
	newReview.id = 'review'+document.getElementById('numreviews').value;
	newReview.innerHTML = document.getElementById('thereview').value+'<br><br>'+document.getElementById('reviewname').value+'<br>(review awaiting approval)';
	document.getElementById('reviews').insertBefore(newReview,document.getElementById('reviews').lastChild);
	
	newReviewLink = document.createElement("span");
	newReviewLink.id = 'r'+document.getElementById('numreviews').value+'link'
	newReviewLink.innerHTML = document.getElementById('numreviews').value;
	newReviewLink.onclick = function() {changeReview(this.innerHTML*1);}	
	document.getElementById('reviewnav').insertBefore(newReviewLink,document.getElementById('reviewnav').lastChild);
	
	newImage = document.createElement("div");
	newImage.innerHTML = '5';
	newImage.className = 'reviewcache';
	newImage.id = 'image'+document.getElementById('numreviews').value;
	document.getElementById('reviews').insertBefore(newImage,document.getElementById('reviews').lastChild);
	
	document.getElementById('thereview').value = document.getElementById('reviewname').value = '';
	
	changeReview(document.getElementById('numreviews').value)
	
	var queryString = "task=addreview&thereview="+thereview+"&reviewname="+reviewname;
	ajaxRequest.open("POST", "/ajax.html", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function getBlogPosts(whichURL){
	//var ajaxDisplay = document.getElementById('blogajax');
	setAjaxVariable();
	
	// Create a function that will receive data sent from the server
	//ajaxRequest.onreadystatechange = function(){
	//	if(ajaxRequest.readyState == 4){
	//		ajaxDisplay.innerHTML = ajaxRequest.responseText;
	//	}
	//}
	
	var queryString = "task=getrss&url="+whichURL;
	ajaxRequest.open("POST", "/ajax.html", true);
	ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	ajaxRequest.send(queryString); 
}

function comment(whichID)
{
	if (document.getElementById("theComment"))
	{
		hidecomment();
		comment(whichID);
	}
	else
	{
		//document.getElementById(commentsArray[i][1]).innerHTML = '<span id="theComment" onMouseOut="hidecomment();"></span>' + document.getElementById(whichID).innerHTML;
		//ajaxDisplay = document.getElementById("theComment");
		//ajaxDisplay.innerHTML = ajaxRequest.responseText;
		commentBubble = document.createElement("span");
		commentBubble.id = 'theComment';
		commentBubble.onmouseout = hidecomment;
		commentBubble.innerHTML = '<img src="/img/commenttop.png"><b><p>' + commentsArray[whichID][2] + '</p></b><img src="/img/commentbottom.png" onMouseOver="hidecomment();">';
		document.getElementById(commentsArray[whichID][1]).parentNode.insertBefore(commentBubble,document.getElementById(commentsArray[whichID][1]))
		topOffset = (17 - commentBubble.offsetHeight) + 'px';
		if (navigator.userAgent.indexOf("AppleWebKit") > 0) 
		{
			topOffset = (1 - commentBubble.offsetHeight) + 'px';
		}
		commentBubble.style.marginTop = topOffset;
			
	}
}

function hidecomment()
{
	if (document.getElementById("theComment")) {document.getElementById("theComment").parentNode.removeChild(document.getElementById("theComment"))}
}

var commentsArray = new Array();
commentsArray[0] = new Array("BBB Concerns","bbbcon","Many regional BBBs will give poor ratings to credit repair companies based solely on the fact that they provide credit repair services. Unless there are other warning signs such as unresolved complaints, a poor BBB rating is not necessarily indicative of a problem company.")
commentsArray[1] = new Array("BBB concerns","bbbcon","Many regional BBBs will give poor ratings to credit repair companies based solely on the fact that they provide credit repair services. Unless there are other warning signs such as unresolved complaints, a poor BBB rating is not necessarily indicative of a problem company.")
commentsArray[2] = new Array("Business type","bbbcon","Many regional BBBs will give poor ratings to credit repair companies based solely on the fact that they provide credit repair services. Unless there are other warning signs such as unresolved complaints, a poor BBB rating is not necessarily indicative of a problem company.")
commentsArray[3] = new Array("Credit Bureau Disputes","cbd","Taking advantage of your rights under the FCRA, credit bureau disputes are communications sent to the credit bureaus requesting they perform an investigation to verify the accuracy of disputed listings.")
commentsArray[4] = new Array("Debt Validation","dval","The FDCPA prohibits collections agencies from reporting negative information to the credit bureaus for debts they cannot prove you owe. Debt validation forces them to prove you owe a debt or remove any listings they have added to your credit reports.")
commentsArray[5] = new Array("Debt Settlement","dsett","Debt settlement services attempt to negotiate with your creditors to decrease the total amount you owe.")
commentsArray[6] = new Array("Seasoned Tradelines","strad","Seasoned tradelines are credit accounts in good standing that have been open for a longer period of time. By becoming an authorized user on these accounts, you may be able to increase your credit score.")
commentsArray[7] = new Array("Credit Score Coaching","csc","Credit score coaching helps you optimize elements of your credit profile such as credit mix and utilization ratios in order to help you increase your FICO&reg; score.")
commentsArray[8] = new Array("Goodwill Interventions","gwi","Unlike other confrontational credit repair tactics, goodwill interventions are requests to remove negative credit listings that leverage a good relationship with a creditor.")
commentsArray[9] = new Array("Info Requests","infor","Creditors are required to be able to provide you with certain information about any debts you owe. If your request for this information is not handled in the appropriate manner, you can push to have negative credit listings associated with the debt removed from your credit reports.")
commentsArray[10] = new Array("Goodwill Letters","gwl","Unlike other confrontational credit repair tactics, goodwill interventions are requests to remove negative credit listings that leverage a good relationship with a creditor.")
commentsArray[11] = new Array("Information Requests","infor","Creditors are required to be able to provide you with certain information about any debts you owe. If your request for this information is not handled in the appropriate manner, you can push to have negative credit listings associated with the debt removed from your credit reports.")
commentsArray[12] = new Array("No BBB Profile","nobbb","The lack of a BBB profile typically indicates that a company is either new or small. Often times, but not always, this can be a sign of a less reputable credit repair company so it is advised that consumers take special care to reseach the company before enrolling in services.")
var excludedPages = /add-company/g;

if(!excludedPages.test(location.href))
{
	for (i=0; i < commentsArray.length; i++) 
	{
		document.body.innerHTML = document.body.innerHTML.replace(commentsArray[i][0],'<span class="clink" id="'+commentsArray[i][1]+'" onMouseOver="comment('+i+');">'+commentsArray[i][0]+'</span>');
	}
}

