
function viewBasket() {
	var temp = getCookie(COOKIENAME);
	if (temp == null || temp == '') {
		alert('Shopping cart is empty. Please select some items first.');
	} else {
		location.href = 'EcatBasket?comp_id='+document.form1.comp_id.value+'&product_id='+temp;
	}
}

function viewBasket2() {
	var temp = getCookie(COOKIENAME);
	if (temp == null || temp == '') temp = '';
	location.href = 'EcatBasket?comp_id='+document.form1.comp_id.value+'&product_id='+temp;
}

function checkexist(what) {
	var temp = getCookie(COOKIENAME);
	if (temp == null || temp == "") {
		return 0;
	}
	if (temp.indexOf(','+what+',') > -1) return 1;
	return 0;
	/*
	selected = temp.split(',');
	for (i=0;i<selected.length;i++) {
		if (selected[i] == what) {
			return 1;
		}
	}
	return 0;
	*/
}

function checkchange(what) {
	temp = getCookie(COOKIENAME);
	if (temp == null || temp == '') {
		alert('Item added to shopping cart.\n\nYou can now continue shopping or \nclick \'Shopping Cart\' icon to view \nselected item(s) and proceed checkout.');
		temp = ',';
	}
	temp2 = what + ',';
	if (checkexist(what)) {
		pos = temp.indexOf(',' + temp2);
		temp = temp.substring(0, pos) + temp.substring(pos + temp2.length);
	} else {
		temp += temp2;
	}
	if (temp == ',') temp = '';
	setCookie(COOKIENAME,temp);
}

// EcatCatg, EcatProduct
function clickCheckbox(product_id) {
	var fm = document.form1;
	fm['P'+product_id].checked = !fm['P'+product_id].checked;
	checkchange(product_id);
}

// Franco 28-10-03
function addToBasket(what) {
	temp = getCookie(COOKIENAME);
	if (temp == null || temp == '') {
		temp = ',';
	}
	if (!checkexist(what)) {
		temp += what + ',';
		setCookie(COOKIENAME,temp);
	}
	alert('Item added to basket.\n\nYou can click \'View Basket\' to view \nselected item(s) and send inquiry.');
}

function MM_checkbox(what)
{
	existing = checkexist(what);
	ckb = "<INPUT TYPE=CHECKBOX NAME='P" + what + "' VALUE='" + what + "'";
	if (existing == 1) {
		ckb += " CHECKED";
	}
	ckb += " onClick=\"checkchange\('" + what + "')\">";

	this.document.open();
	this.document.writeln(ckb);
	this.document.close();
}

// Heinle's function for retrieving a cookie.
function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

// An adaptation of Dorcht's function for setting a cookie.
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// An adaptation of Dorcht's function for deleting a cookie.
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

