// JavaScript Document

//********************** AJAX Functionality START **********************
var req;
var couponid;
function createRequestObject() {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	return req;
}

//********************** AJAX Functionality START for Coupon Voting **********************
function ajaxupdate() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
			var response = req.responseText;
			//alert(couponid + response);
			document.getElementById(couponid+"couponVotes").innerHTML = response;
        } else {
            alert("There was a problem retrieving the data:\n" + req.statusText);
        }
    }
}

function voteCoupon(cid, vote)
 {
	if(cid!="" && vote != "")
	{	
		couponid = cid;
		req=createRequestObject();
		if(req) {
			req.onreadystatechange = ajaxupdate;
			url="ajaxFunctions.php?couponid="+cid+"&vote="+vote;
			//alert(url);
			req.open("GET", url, true);
			req.send("");
		}
	}	
 }
 
//********************** AJAX Functionality START for StoreName search **********************
function storeUpdate() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
			var response = req.responseText;
			//alert(response);
			document.getElementById("storeNames").style.display = "";
			document.getElementById("storeNames").innerHTML = response;
        } /*else {
            alert("There was a problem retrieving the data:\n" + req.statusText);
        }*/
    }
}

function getStoreNames(store)
 {
	if(store != "")
	{	
		req=createRequestObject();
		if(req) {
			req.onreadystatechange = storeUpdate;
			url="ajaxFunctions.php?store="+store;
			//alert(url);
			req.open("GET", url, true);
			req.send("");
		}
	}	
 } 
