var request;
var queryString;   //will hold the POSTed data
function voteOldSchool () {
	var id = ""
	var vote = ""
	var url="/js/oldschoolrecordclick.html"
	var crumb = ""
	var newURL = "http://help.yahoo.com/"

	if(document.getElementById('id')) {
		id = document.getElementById('id').value
		vote = "cc"
		queryString="vote=Cc&id=" + encodeURIComponent(id)
	}
	if(document.getElementById('.crumb')) {
		crumb = document.getElementById('.crumb').value;
	}
	if(document.getElementById('rating_yes').checked) {
		vote = "yes"
		document.getElementById('rating_yes').checked=false;
	}
	if(document.getElementById('rating_no').checked) {
		vote = "no"
		document.getElementById('rating_no').checked=false;
	}
	if(vote == "yes") {
		queryString="vote=Yes&id=" + encodeURIComponent(id)
	}
	if(vote == "no") {
		queryString="vote=No&id=" + encodeURIComponent(id)
	}
	if(vote != "") {
		queryString += "&crumb=" + encodeURIComponent(crumb)
		httpRequest("POST",url,true);

		if(vote == "cc") {
			if(document.getElementById('.cc'))
			{
				newURL = document.getElementById('.cc').value
			}
			window.location=newURL
		}else{
			document.getElementById('feedback_form').style.display = "none";
			document.getElementById('feedback_thankyou').style.display = 'block';
		}
	}
}
function helpVote () {
	var vote;
	var id = ""
	var feedback = ""
	var url="/js/recordclick.html"
	var versionId = -4;
	var crumb = ""
	if(document.getElementById('.feedback')) {
		feedback = document.getElementById('.feedback').value;
	}
	if(document.getElementById('.versionId')) {
		versionId = document.getElementById('.versionId').value;
	}

	if(document.getElementById('id')) {
		id = document.getElementById('id').value
		vote = "cc"
	}
	if(document.getElementById('.crumb')) {
		crumb = document.getElementById('.crumb').value;
	}
	if(document.getElementById('rating_yes').checked) {
		vote = "yes"
		document.getElementById('rating_yes').checked=false;
	}
	if(document.getElementById('rating_no').checked) {
		vote = "no"
		document.getElementById('rating_no').checked=false;
	}
	if(vote != "") {
		queryString="feedback=" + encodeURIComponent(feedback) + "&";
		queryString += "vote=" + encodeURIComponent(vote) + "&";
		queryString += "crumb=" + encodeURIComponent(crumb) + "&";
		queryString += "vid=" + encodeURIComponent(versionId) + "&";
		queryString += "path=" + encodeURIComponent(id);

		if(vote == "cc") {
			httpRequest("POST",url,false);
			setTimeout("contactCustomerCare",4000);
			if(document.getElementById('.cc'))
			{
				window.location  = document.getElementById('.cc').value
			}
		}else{
			httpRequest("POST",url,true);
			document.getElementById('feedback_form').style.display = "none";
			document.getElementById('feedback_thankyou').style.display = 'block';
		}
	}
}

function contactCustomerCare()
{
	if(document.getElementById('.cc'))
	{
		window.location  = document.getElementById('.cc').value
	}
}

/* Initialize a request object that is already constructed.
 Parameters:
   reqType: The HTTP request type, such as GET or POST.
   url: The URL of the server program.
   isAsynch: Whether to send the request asynchronously or not. */
function initReq(reqType,url,isAsynch){
    /* Specify the function that will handle the HTTP response */
    request.onreadystatechange=handleResponse;
    request.open(reqType,url,isAsynch);
    /* Set the Content-Type header for a POST request */
    request.setRequestHeader("Content-Type",
            "application/x-www-form-urlencoded; charset=UTF-8");
    request.send(queryString);
}

/* Wrapper function for constructing a request object.
 Parameters:
  reqType: The HTTP request type, such as GET or POST.
  url: The URL of the server program.
  asynch: Whether to send the request asynchronously or not. */
  
function httpRequest(reqType,url,asynch){
    //Mozilla-based browsers
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest(  );
    } else if (window.ActiveXObject){
        request=new ActiveXObject("Msxml2.XMLHTTP");
        if (! request){
            request=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    //the request could still be null if neither ActiveXObject
    //initialization succeeded
    if(request){
        initReq(reqType,url,asynch);
    } else {
        alert("Your browser does not permit the use of all "+
              "of this application's features!");
    }
}
//event handler for XMLHttpRequest
function handleResponse(  ){
    if(request.readyState == 4){
        if(request.status == 200){
					// do nothing
        } else {
            alert("A problem occurred with communicating between "+
                  "the XMLHttpRequest object and the server program.");
        }
    }//end outer if
}
