var LPURL = "http://" + location.host + "/LPNew/";
var totalScore = 0;
var scored = 0;
var subScore = 0;
var subTotal = 0;

$(document).ready(function() {
	$("#mainCol").css("width",$(window).width()-220);
	setInterval("updateStats()", 5000);
});
$(window).resize(function() {
	$("#mainCol").css("width",$(window).width()-220);
});

function updateStats() {
	$.ajax({ 
	    	url: LPURL + "linkCounters.asp", 
		async: true,
		complete: function(xhr, statusText) { 
			if (statusText == "success") {
				$("#lnkCounter").html(xhr.responseText);
			}
		}
	});
}
function validateURL(url) {
	if (url.indexOf("http://") == -1 && url.indexOf("https://") == -1) {
		return false;
	}
	return true;
}
Array.prototype.isIn = isInArray;
function isInArray(val) {
	for (var ii=0; ii<this.length; ii++) {
		if (this[ii].toLowerCase() == val.toLowerCase()) {
			return ii;
			break;
		}
	}
	return -1;
}

function getKeyWords(kArr) {
	var retArr = [];
	for (var k=0; k<kArr.length; k++) {
		wordArr = kArr[k].split(" ");
		for (w=0; w<wordArr.length; w++) {
			if (wordArr[w].length > 2) {
				if (retArr.isIn(wordArr[w]) == -1) {
					retArr.push(wordArr[w]);
				}
			}
		}
	}
	return retArr;
}
function submitReview(dirID, btn) {
	var frm = btn.form;
	var rating = frm.rating.value;
	var review = frm.review.value;
	var reviewBy = frm.reviewBy.value;
	$.ajax({
		url: LPURL + "addReview.asp?dID=" + dirID + "&rt=" + rating + "&rb=" + reviewBy + "&rv=" + review,
		async: true,
		complete: function(xhr, statusText) {
			newRatings = xhr.responseText.split("~");
			$("#usr" + dirID).text(newRatings[0]);
			$("#overRate" + dirID).text(newRatings[1]);
			$("#usrReviews").hide();
			$("#lbBack").hide();
			$("#dir" + dirID).hide();
		}
	});
}
function showUserReviews(dirID) {
	$.ajax({
		url: LPURL + "getUserReviews.asp?dID=" + dirID,
		async: true,
		complete: function(xhr, statusText) {
			Lightbox(xhr.responseText, true);
		}
	});
}
function reviewDirectory(dirID) {
	$.ajax({
		url: LPURL + "userReview.asp?dID=" + dirID,
		async: true,
		complete: function(xhr, statusText) {
			if (xhr.responseText.indexOf("Sorry") > -1) {
				alert(xhr.responseText);
			}
			else {
				Lightbox(xhr.responseText, true);
			}
		}
	});
}
function Lightbox(html, shw) {
	if (shw) {
		$("#usrReviews").html(html);
		$("#usrReviews").show();
		$("#usrReviews").css("top",document.body.scrollTop + 150);
		$("#lbBack").css("top",document.body.scrollTop);
		$("#lbBack").show();
	}
	else {
		$('#usrReviews').hide();
		$("#lbBack").hide();
	}
}

function encHTMLStr(str) {
	reQuot = /\"/g;
	reStT = /</g;
	reEnT = />/g;
	reSQuot = /'/g;
	reCrLf = /\n/g;
	reTab = /\t/g;
	str = str.replace(reQuot, "&quot;");
	str = str.replace(reSQuot, "&lsquo;");
	str = str.replace(reStT, "&lt;");
	str = str.replace(reEnT, "&gt; ");
	str = str.replace(reCrLf, "<br>");
	str = str.replace(reTab, "&nbsp;&nbsp;&nbsp;");
	return str;
}
function removeTags(str) {
	reStT = /</g;
	reEnT = />/g;
	str = str.replace(reStT, "&lt;");
	str = str.replace(reEnT, "&gt; ");
	return str;
}
function gEl(obj) {
	return document.getElementById(obj);
}
function gElt(obj) {
	return document.getElementsByTagName(obj);
}
function showProgress(bool) {
	gEl("rpt").style.display = (bool)? "none":"block";
	gEl("outputDiv").style.display = (bool)? "none":"block";
	gEl("PageSrc").style.display = (bool)? "none":"block";
	gEl("outputSrc").style.display = (bool)? "none":"block";
	gEl("prog").style.display = (bool)? "block":"none";
	gEl("summaryDiv").style.display = (bool)? "none":"block";
	gEl("PageSrcScore").style.display = (bool)? "none":"block";
	gEl("rptScrore").style.display = (bool)? "none":"block";
}
var debugWin = null;
function wdPop(str) {
	if (!top.debugWin || top.debugWin.closed) {
		top.debugWin = window.open("","debugWin","target=debugWin,width=600,height=400,scrollbars=1");
		top.debugWin.document.open();
		top.debugWin.document.write("<html><head><title>Debugger</title><style>body {font-family:verdana; font-size:xx-small } </style></head><body><a href='javascript:void(0)' onclick=\"document.getElementById('debugger').innerHTML = '';\">Clear</a><br><div id=debugger></div></body></html>");
		top.debugWin.document.close();
	}
	top.debugWin.document.getElementById("debugger").innerHTML += (str + "<br>");
}
