/* POPUP WINDOWS */

function openWin(win, w, h) {
	newwindow = window.open(win,null,"height="+h+",width="+w+",status=no,toolbar=no,scrollbars=yes,menubar=no,location=no, left=",false);
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}

/* COOKIES */

var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "Fri, 3 Aug 2021 20:47:11 UTC";
		document.cookie = name+"="+value+expires+"; path=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};
Cookies.init();


/* COOKIE FUNCTIONS */


// SAVE

function saveUSC(name) {
	Cookies.create(name,'usc_downloads',1825);
	// alert('Cookie ' + name + ' created');
	window.location = "../downloads/usc/index.php";
}

function saveSTB(name) {
	Cookies.create(name,'stb_downloads',1825);
	window.location = "../downloads/stb/index.php";
}


// READ

function readUSC(name) {
	//alert('The value of the cookie is ' + Cookies[name]);
	if (Cookies[name] != "usc_downloads") {
		window.location = "../../forms/cad_download_request_usc.php?msg=signup";
	}
	else {}
}

function readSTB(name) {
	if (Cookies[name] != "stb_downloads") {
		window.location = "../../forms/cad_download_request_stb.php?msg=signup";
	}
	else {}
}


// REDIRECT

function redirectUSC(name) {
	// alert('The value of the cookie is ' + Cookies[name]);
	if (Cookies[name] == "usc_downloads") {
		window.location = "../downloads/usc/index.php";
		return false;
	}
	else {}
}

function redirectSTB(name) {
	// alert('The value of the cookie is ' + Cookies[name]);
	if (Cookies[name] == "stb_downloads") {
		window.location = "../downloads/stb/index.php";
		return false;
	}
	else {}
}


// ERASE

function eraseIt(name) {
	Cookies.erase(name);
	// alert('Cookie erased');
}



/* function init() {
	for (var i=1;i<3;i++) {
		var x = Cookies['ppkcookie' + i];
		if (x) window.location = "cad_downloads_x.php";
	}
} */