function getCookie(name) 
{
  var prefix = name + "=";
  var cookieStartIndex = document.cookie.indexOf(prefix);

  if (cookieStartIndex == -1)
    return null

  var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)

  if (cookieEndIndex == -1)
    cookieEndIndex = document.cookie.length

  return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function deleteCookie(name)
{
  if (getCookie(name)) 
  {
    var path = "/";
    var domain = ".smartphoneware.com";
    document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    return true;
  }

  return false;
}

function setCookie(c_name,value,expiredays)
{  
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function removeAndRefresh(id)
{
  deleteCookie("CPID"+id);
  deleteCookie("CDEV"+id);
  window.location.href = window.location.href;
}

function Buy(p)
{
  document.getElementById('buy_'+p).submit();
}


function CartReset()
{
  setCookie("CART0", getCookie("CART"), 30);
  deleteCookie("CART");
}

function CartAction(a,l)
{
  document.getElementById('do_action').value = a;
  document.getElementById('cart').action = l;
  document.getElementById('cart').submit();
}
