// cc test 4111111111111111

var popupWin
var isIE3 = (navigator.appVersion.indexOf("MSIE 3") != -1) ? true : false

function closecart() {
    ViewMyItem()
    popupWin.close()
}

function form_submit() {
 document.order.submit()
}

function AddMyItem(qty, item, desc, price) {

  addtobasket(qty, item, desc, price);

if (document.cookie.length<1) {

  alert("Sorry, your browser does not support cookies\n\nor they are disabled.  Please contact us for\n\nproduct availability:\n\n\nE-mail: cpl1beach@aol.com\n\n\nPhone: (727) 397-9111");

} else {
  
  // initialize winX and winY to default values
  // for cases where Screen object isn't supported
  var winX = 0;
  var winY = 0;
  var url = "mybasket.htm#cart_bottom"
  var name = "addtobasket"
  var w = 525
  var h = 350
  var perc = 50

  // only set new values if 4.0 browser
  if (parseInt(navigator.appVersion) >= 4) {
    winX = (screen.availWidth - w)*perc*.01;
    winY = (screen.availHeight - h)*perc*.01;
  }
  if (isIE3) {
  // if window is already open, nothing appears to happen
  // but if not, the subwindow flashes momentarily (yech!)

  popupWin = window.open("", name,'resizable,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
  }
                    
  if (popupWin  && !popupWin.closed) {
   popupWin.close()
  }

  popupWin = window.open(url, name,'scrollbars,resizable,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
    if (popupWin.opener == null) {
	popupWin.opener = window
    }

  popupWin.focus();
  
}
}

function ViewMyItem() {
  // addtobasket(qty, item, desc, price);
  // initialize winX and winY to default values
  // for cases where Screen object isn't supported
  var winX = 0;
  var winY = 0;
  var url = "mybasket.htm#cart_bottom"
  var name = "addtobasket"
  var w = 525
  var h = 350
  var perc = 50

  // only set new values if 4.0 browser
  if (parseInt(navigator.appVersion) >= 4) {
    winX = (screen.availWidth - w)*perc*.01;
    winY = (screen.availHeight - h)*perc*.01;
  }
  if (isIE3) {
  // if window is already open, nothing appears to happen
  // but if not, the subwindow flashes momentarily (yech!)

  popupWin = window.open("", name,'resizable,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
  }
                    
  if (popupWin  && !popupWin.closed) {
   popupWin.close()
  }

  popupWin = window.open(url, name,'scrollbars,resizable,width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
    if (popupWin.opener == null) {
	popupWin.opener = window
    }

  popupWin.focus();
  

}

//Global variables used as delimeters
delimitem = "~";
delimoption = "^";

//Cookie functions
function getCookie(name){
	var cookiename = name + "=";
	var doccookie = document.cookie;
	if (doccookie.length > 0) {
		start = doccookie.indexOf(cookiename);
		if (start != -1) {
			start += cookiename.length;
			end = doccookie.indexOf(";", start);
			if (end == -1) end = doccookie.length;
			return unescape(doccookie.substring(start, end));
		}
	}
	return null;
}

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");
}

function delCookie (name) {
	var delDate=new Date("January 1, 1999 23:30:00");
	setCookie(name,null,delDate);
}

//Seperate strings
function separatedata(datain,delimin){
	var i=0;
	var xarray=new Array(datain);
	var j=0;

	for(i=0;i<datain.length;i++){
	   var tempstring=datain.substring(i,datain.length);
	   var x=tempstring.indexOf(delimin);
	   if(x>0){
	   var k=x+i;
	   xarray[j++]=datain.substring(i,k);
	   i+=x}
	   else{
	   xarray[j++]=tempstring;
	   i=datain.length}
	}

	return xarray;
}

function clear_cc(form) {
  form.cc_num.value = ""
}

function clear_cardtype() {
document.order.Card_Type.options[0].selected = true;
}

function set_mastercard() {
document.order.Card_Type.options[1].selected = true;
}

function set_amex() {
document.order.Card_Type.options[2].selected = true;
}

function set_visa() {
document.order.Card_Type.options[2].selected = true;
}

function set_discover() {
document.order.Card_Type.options[4].selected = true;
}

var encrypt_it = true;

function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  if (st.length < 16)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);
}

function getCCNum(default_val) {
 msg = 'Please enter your credit card number here. '
  + 'It will be '
  + ((encrypt_it) ? "encrypted and then " : "")
  + 'put into the credit card field of the form '
  + 'after it is validated.';
 return prompt(msg,default_val);
}

function encrypt(val) {
 val = "" + val;
 var result = "";
 for (i=0;i<val.length;i++) {
  character = val.charAt(i);
  if ("0123456789".indexOf(character) != -1) {
   character = parseInt(character);
   character = (character+1)%10;
  }
  result += character;
 }
 if (result != "")
  result += "e";
 return result;
}

function unencrypt(val) {
 val = "" + val;
 for (n=0;n<9;n++)
  val = encrypt(val);
 return (val.substring(0,val.indexOf('e')));
}

function strip(val) {
 val = "" + val;
 if (!val)
  return "";
 var result = "";
 for (i=0;i<val.length;i++) {
  character = val.charAt(i);
  if ("0123456789".indexOf(character) != -1)
   result += character;
 }
 return result;
}

var last_entry = "";
function doCCStuff(form_element) {
 if (blur_reset) {
  last_entry = form_element.value;
  if (last_entry && last_entry.indexOf('e') != -1)
   last_entry = unencrypt(last_entry);
  entry = getCCNum(last_entry);
  stripped_entry = strip(entry);
  while (entry && (!isCreditCard(stripped_entry))) {
   alert('The credit card number you entered could not be '
    + 'validated. Please check the number and try again.');
   last_entry = entry;
   entry = getCCNum(last_entry);
   stripped_entry = strip(entry);
  }
  if (entry) {
   if (encrypt_it)
    form_element.value = encrypt(entry);
   else
    form_element.value = entry;
  }
  blur_form(form_element);
 }
 return false;
}
var blur_reset = true;
function blur_form(form_element) {
 form_element.blur();
 blur_reset = false;
 setTimeout("blur_reset=true",500);
}
