function SetCookie (name, value) {
	var largeExpDate = new Date ();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000));
	var expires = largeExpDate;
	document.cookie = name + "=" + escape (value) +"; expires=" + expires.toGMTString() +  "; path=/";
}


function getCookie(name) {
	if(document.cookie == "") return false;
	else {
		var cookieStart, cookieEnd;
		var cookieString = document.cookie;
		cookieStart = cookieString.indexOf(name+"=");
		if(cookieStart != -1) {
			cookieStart += name.length+1;
			cookieEnd = cookieString.indexOf(";", cookieStart);
			if(cookieEnd == -1) cookieEnd = cookieString.length;
			return cookieString.substring(cookieStart, cookieEnd);
		} else {
			return false;
		}
	}
}

function getshopingcart() {
	var rows = new Array();
	var shopingcart = unescape(getCookie("shopingcart"));
	if(shopingcart) {
	rows = shopingcart.split(" ");
	}
	return rows.length;
}

function emptyshopingcart() {
	SetCookie("shopingcart", "");
	return false;
}

function removeposition(id) {
	var rows = new Array();
	var shopingcart = unescape(getCookie("shopingcart"));
	var newcartstring = "";
	if(shopingcart) {
		rows = shopingcart.split(" ");
		for(i=0; i<rows.length; i++){
			if(rows[i]!=id && rows[i]!='') {
				newcartstring = newcartstring + rows[i]+" ";
			}
		}
		
	}
	if(newcartstring.length) newcartstring = newcartstring.substr(0, newcartstring.length-1);
	SetCookie("shopingcart", newcartstring);
}

function toshopingcart(id) {
	var rows = new Array();
	var shopingcart = unescape(getCookie("shopingcart"));
	var flag_avaible = false;
	if(shopingcart) {
		rows = shopingcart.split(" ");
		for(i=0; i<rows.length; i++){
			if(rows[i]==id) {
				flag_avaible = true;
			}
		}
		
	}
	
	if(flag_avaible==false) {
		if(rows && rows[0]!="false") {
			rows[rows.length]=id;
		} else rows[0]=id;
		SetCookie("shopingcart", rows.join(" "));
	}
	if(flag_avaible==false) alert('This article is added into your shopping cart');
	else alert('This article is ALREADY added to your shopping cart');
}