// JavaScript Document
/**
 * Sets a Cookie with the given name and value.
 *
 * c_name       Name of the cookie
 * value      Value of the cookie
 * expiredays Expiration date of the cookie (default: end of current session)
 */
function setCookie(c_name,value,expiredays) {
	var exdate = new Date();
	exdate.setTime(exdate.getTime()+(expiredays*24*60*60*1000));
	document.cookie=c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate);
	//alert(exdate);
	//alert(expiredays);
	return true;
} 


/**
 * Gets the value of the specified cookie.
 *
 * c_name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1 ;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) {
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return null;
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
/*
from 
http://www.netspade.com/articles/2005/11/16/javascript-cookies/

JavaScript Cookie Example

Set Cookie! 
<a href="#" onclick='setCookie("name", "Jason Davies", 365);return false'>Set Cookie!</a>

Get Cookie! 
<a href="#" onclick='alert(getCookie("name"));return false'>Get Cookie!</a>
*/

function getCs() {
	a = getCookie('adViewed');
	b = getCookie('skipAd');
	alert('ad viewed: ' + a + '\nskip ad: ' + b);
}
function delCs() {
	deleteCookie('adViewed');
	deleteCookie('skipAd');
}
function skipAndGo(bool) {
	if(bool) {
		if(setCookie('skipAd','true',365)) {
			window.location.href='index.htm';
		}
	}
}
