/* COOKIE JS SCRIPTS */
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}
function SetCookie (name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	// This cookie is history  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


/* FRAMING SCRIPTS */
function frames_addpid(fpid,fsid) {
	pathname = location.pathname;
	myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var largeExpDate = new Date ();
	largeExpDate.setTime(largeExpDate.getTime() + (30 * 24 * 3600 * 1000));
	SetCookie('fpid',fpid,largeExpDate,myDomain);
	SetCookie('fsid',fsid,largeExpDate,myDomain);
}
	
function frames_addtoCart(sidclick) {
	if (GetCookie('fpid') == null) {
		alert('Please select a frame style for this size');
	} else {
		var fpid = GetCookie('fpid');
		var fsid = GetCookie('fsid');
		if (fsid != sidclick) {
			alert('Please select a frame style for this size');
		} else {
			var go_url = 'cart_addto.php?pid=' + fpid + '&sid=' + fsid + '&section=frame';
			
			//send string to cart addition script
			self.location = go_url;
		}
	}
}


/* SHOPPING CART JS SCRIPTS */
function popup(url) {
        var new_window = window.open(url,'Info','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=340,height=150');
}
	
function removeProduct (id,label) {
	if(confirm('Are you sure you want to remove '+label+'?')) {
		document.location.href='?function=remove&id='+id;
	}
}

function updateCart () {
	document.formquantity.submit();
}
