function createRequestObject() {
     var ro;
     var browser = navigator.appName;
     if(browser == "Microsoft Internet Explorer"){
          ro = new ActiveXObject("Microsoft.XMLHTTP");
     }else{
          ro = new XMLHttpRequest();
     }
     return ro;
}

var http = createRequestObject();
var SpecDone = 0;

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function toggleShow(sId)
{
	if (document.getElementById(sId).style.display == "block")
	{
		document.getElementById(sId).style.display="none";
	}
	else
	{
		document.getElementById(sId).style.display="block";
	}
}

function compareProduct(action, sku, site)
{
	http.open("POST", "../commonContent/compare-wire.asp", true);
	var params = "action=" + encodeURIComponent(action) + "&sku=" + encodeURIComponent(sku) + "&site=" + encodeURIComponent(site);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = compareResponse;
	http.send(params);
}

function compareResponse() {
	if(http.readyState == 4){
		var response = http.responseText;
		if (trimAll(response) != "")
		{
			document.getElementById("ComparisonProductHolder").style.display = "block";
			document.getElementById("ComparisonProductDiv").innerHTML = response;
		}
		else
		{
			document.getElementById("ComparisonProductHolder").style.display = "none";
			document.getElementById("ComparisonProductDiv").innerHTML = "";
		}
		document.getElementById("tinyLoader").style.display = "none";
     }
     else
     {
		document.getElementById("tinyLoader").style.display = "block";
     }
}

function makeComment(isTestimonial)
{
	var comment = trimAll(document.getElementById("makeCommentsText").value);
	var sku = trimAll(document.getElementById("makeCommentsSKU").value);
	var email = trimAll(document.getElementById("makeCommentsEmail").value);
	var name = trimAll(document.getElementById("makeCommentsName").value);
	if (comment == "") 
	{
		document.getElementById("makeCommentsFeedback").innerHTML = "Please enter a question or comment into the box above";
		document.getElementById("makeCommentsText").value = "";
	}
	else
	{
		if (email == "") 
		{
			document.getElementById("makeCommentsFeedback").innerHTML = "Please enter an email address into the box above";
			document.getElementById("makeCommentsEmail").value = "";
		}
		else
		{
			if (name == "") 
			{
				document.getElementById("makeCommentsFeedback").innerHTML = "Please enter a display name into the box above";
				document.getElementById("makeCommentsName").value = "";
			}
			else
			{
				var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
				if( !filter.test(email) )
				{
					document.getElementById("makeCommentsFeedback").innerHTML = "Please enter a valid email address into the box above";
				}
				else
				{
					document.getElementById("makeCommentsFeedback").innerHTML = "";
					document.getElementById("makeCommentsText").disabled = true;
					document.getElementById("makeCommentsEmail").disabled = true;
					document.getElementById("makeCommentsName").disabled = true;
					document.getElementById("makeCommentsButton").disabled = true;
					document.getElementById("makeCommentsButton").style.backgroundColor = "#DEDEDE";
					document.getElementById("makeCommentsText").value = "Please wait...";
					//alert("Do some stuff with this:\n\n" + comment);
					http.open("POST", "../commoncontent/postcomments.asp");
					var params = "action=makecomment&comment=" + encodeURIComponent(comment);
					params = params + "&sku=" + encodeURIComponent(sku);
					params = params + "&email=" + encodeURIComponent(email);
					params = params + "&displayname=" + encodeURIComponent(name);
					http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					http.setRequestHeader("Content-length", params.length);
					http.setRequestHeader("Connection", "close");
					if (isTestimonial == "true")
					{
						http.onreadystatechange = testimonialResponse;
					}
					else
					{
						http.onreadystatechange = commentResponse;
					}
					http.send(params);
				}
			}
		}
	}
}

function commentResponse()
{
	if(http.readyState == 4)
	{
		//alert(http.responseText);
		document.getElementById("makeCommentsDiv").innerHTML = "<p>Thank you for asking your question. We will try to answer your question as soon as possible. Thank you.</p>";
	}
}

function testimonialResponse()
{
	if(http.readyState == 4)
	{
		//alert(http.responseText);
		document.getElementById("makeCommentsDiv").innerHTML = "<p>Thank you for your testimonial, we'll review it and you might see it on this page soon.</p>";
	}
}
function ReqFAQ(action) {
     //http.open("GET", "/cnetspec/" +action+ ".htm");
     //http.open("GET", "http://sql2005/easycom/cnetspec/" +action+ ".htm");
     http.open("GET", "../commonContent/comments-standalone.asp?FAQCode=" + action + "");
     http.onreadystatechange = faqResponse;
     http.send(null);
}

function faqResponse() {
     if(http.readyState == 4){
          var response = http.responseText;
          response = response.replace(/specsheets.css/i, "");
          document.getElementById("feedback").innerHTML = response;
          }
}

