function popup (url) {

	var w = parseInt(screen.width) - 200;
	var h = parseInt(screen.height) - 200;
	window.open(url, "popup", "height="+h+",width="+w+",left=100,top=100,scrollbars=1,status=1");
}


function getFlashWidth(flashsrc) { // function to get flash's width
	var flashTag = document.getElementById(flashsrc);
	var iWidth = flashTag.width;
	return iWidth;
}

function getFlashHeight(flashsrc) { // function to get flash's height
	var flashTag = document.getElementById(flashsrc);
	var iHeight = flashTag.height;
	return iHeight;
}


// cookie related

function append_cookie(name, appendvalue, path) {
	var cookievalue = read_cookie(name);
	var duplicate = false;
	if (cookievalue != "" && cookievalue != null) {
		var cookie_array = cookievalue.split(":");
		for (var i=0; i<cookie_array.length; ++i) {
			if (cookie_array[i] == appendvalue) {
				duplicate = true;
			}
		}
	}
	if (duplicate) {
		alert("This item is already inside your cart.");
	} else {
		if (cookievalue != null)
			cookievalue = cookievalue + ":" + appendvalue;
		else
			cookievalue = appendvalue;
		write_cookie(name, cookievalue, path);
		alert("Item has been added to your cart.");
	}
}

function delete_item(name, itemID) {
	cookievalue = read_cookie(name);
	var cookie_array = cookievalue.split(":");
	var duplicate = false;
	var tmp_string = "";
	for (var i=0; i<cookie_array.length; ++i) {
		if (cookie_array[i] != itemID) {
			if (tmp_string == "") 
				tmp_string = cookie_array[i];
			else
				tmp_string = tmp_string + ":" + cookie_array[i];
		}
	}
	alert("Item has been removed from your cart.");
	write_cookie(name, tmp_string, "");
	window.location.reload(); // reload the current page
}

function write_cookie(name, value, path) {
	var cookie_string = escape(name) + "=" + escape(value);
	document.cookie = cookie_string;
}

function read_cookie(key, skips) {
	var cookie_string = "" + document.cookie;
	var cookie_array = cookie_string.split ("; ");
	for (var i=0; i<cookie_array.length; ++i) {
		var single_cookie = cookie_array[i].split ("=");
		if (single_cookie.length != 2)
			continue;
		var name  = unescape(single_cookie [0]);
		var value = unescape(single_cookie [1]);
	}
	if (key == name) // Return cookie if found
		return value;
	else // return null if requested cookie not found
		return null;
}




function delete_cookie(name, path) {
	// set expiry date
	//var expiration_date = new Date();
	//expiration_date.setYear (expiration_date.getYear () - 1);
	var expiration_date = new Date("January 31, 1900");
	expiration_date = expiration_date.toGMTString();
	// create cookie string
	var cookie_string = escape (name) + "=; expires=" + expiration_date + "; path=/";

	//if (path != null)
	//	cookie_string += "; path=" + path;
	// Delete cookie
	document.cookie = cookie_string;
}

function delete_all_cookies(path) {
	// read the cookie and split them into array
	var cookie_string = "" + document.cookie;
	var cookie_array = cookie_string.split ("; ");
	// go through the array and delete everyone of them
	for (var i = 0; i < cookie_array.length; ++ i) {
		var single_cookie = cookie_array [i].split ("=");
		if (single_cookie.length != 2)
			continue;
		var name = unescape(single_cookie [0]);
		delete_cookie(name, path);
	}
}

function confirmDelete() {
	var confirmation = confirm("Proceed to clear your cart content?");
	if (confirmation) {
		//delete_cookie("cartcontent", "");
		delete_all_cookies();
		window.location.reload(); // reload the current page
	}
}
