/**
 * This function increment the cookie count by 1
 * if the cookie is not present, it will create it also.
 *
 * name  Name of the desired cookie.
 */
function incrementCookieCounter() {
	var cookieVal = getCookie('RES_TRIAL_COOKIE');
	if (cookieVal == null) {
		setCookie('RES_TRIAL_COOKIE',1,'Thu, 1 Jan 2010 00:00:01 GMT','/','.vendio.com','');
	}
	else {
		//invalid case
		if (cookieVal > 3)  {
			return false;
		}
		else {
			cookieVal++;
			setCookie('RES_TRIAL_COOKIE',cookieVal,'Thu, 1 Jan 2010 00:00:01 GMT','/','.vendio.com','');			
		}
	}
}

function displayResearchBox() {
	var cookieVal = getCookie('RES_TRIAL_COOKIE');
	if (cookieVal == null || cookieVal < 3)
		return true;
	return false;
}

function setCookie(name, value, expires, path, domain, secure) {
    var resCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
		
	document.cookie = resCookie;
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}