function ReadCookie(name)
{
	var search = name + "="
	if (document.cookie.length > 0) {	// if there are any cookies
		offset = document.cookie.indexOf(search);
		if (offset != -1) { // if cookie exists
			offset += search.length;					// set index of beginning of value
			end = document.cookie.indexOf(";", offset);	// set index of end of cookie value
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
}

function WriteCookie (cookieName, cookieValue, expiry, path, domain) 
{
	var expDate = new Date();
	var cookieBody = cookieName + "=" + escape (cookieValue);

	if(expiry)
	{
		expDate.setTime (expDate.getTime() + expiry);
		cookieBody += "; expires=" + expDate.toGMTString();
	}

	if(path)
		cookieBody += "; path=" + path;

	if(domain)
		cookieBody += "; domain=" + domain;

	document.cookie = cookieBody;
}

function GetCartName()
{
	return ReadCookie("ShoppingCart");
}

function SetCartName(cartName)
{
	WriteCookie("ShoppingCart", cartName, 0, "/", ".ultrasoft.com");
}

function ClearCart()
{
	WriteCookie("ShoppingCart", "undefined", 0, "/", ".ultrasoft.com");
}

function GetVendorName()
{
	return ReadCookie("Vendor");
}

function SetVendorName(vendorName)
{
	WriteCookie("Vendor", vendorName, 1000 * 60 * 60 * 24 * 45, "/", ".ultrasoft.com");
}

function ClearVendor()
{
	WriteCookie("Vendor", "undefined", 0, "/", ".ultrasoft.com");
}

function buyNow()
{
	vendorName = GetVendorName();
	
	switch (vendorName) {
		case "PalmGear" :
			vendorURL = "http://www.palmgear.com/index.cfm?fuseaction=software.developer&userID=974265679&searchtitle=Ultrasoft+Digital+Media";
			break;
		case "Handango" :
			vendorURL = "http://www.handango.com/SoftwareCatalog.jsp?siteId=1&platformId=1&N=96804+4294954631";
			break;
		default:
			vendorURL = "http://store.ultrasoft.com";
			break;
	}

	open(vendorURL, target="_self");
}

