function embedFlash(movieWmode,protocol) {
  var wmode = (movieWmode==undefined) ? "window" : movieWmode;
  var myProtocol = (protocol==undefined) ? "http" : protocol;
  var toWrite = "";
	toWrite += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
	toWrite += " codebase=\""+myProtocol+"://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0\"";
	toWrite += " width=\""+movieWidth+"\"";
	toWrite += " height=\""+movieHeight+"\"";
	toWrite += " id=\"flashMovie\">";
	toWrite += "<param name=\"movie\" value=\""+movieName+"\">" ;
	toWrite += "<param name=\"wmode\" value=\""+wmode+"\">";
	toWrite += "<param name=bgcolor value=" + movieBG + ">";
	toWrite += "<param name=\"menu\" value=\"false\"><param name=\"quality\" value=\"high\"><param name=\"allowScriptAccess\" value=\"always\"><param name=\"scale\" value=\"noscale\"><param name=\"salign\" value=\"TL\">";
	toWrite += "<param name=\"flashVars\" value=\""+movieFlashVars+"\">";
	toWrite += "<embed src=\'"+movieName+"\'";
	toWrite += " menu='false' quality='high' wmode='"+wmode+"' allowscriptaccess='always' scale='"+movieScale+"' bgcolor='"+movieBG+"' width='"+movieWidth+"' height='"+movieHeight+"' salign='TL'";
	toWrite += " name=\'flashMovie\' flashvars=\'" + movieFlashVars + "\' ";
	toWrite += " type=\'application/x-shockwave-flash\' pluginspage=\'"+myProtocol+"://www.macromedia.com/go/getflashplayer\'>";
	toWrite += "</embed></object>";
	document.write(toWrite);
}

function popWindow(url, w, h, name) {
	var windowX = Math.ceil( (window.screen.width-w)/2 );
	var windowY = Math.ceil( (window.screen.height-h)/2 )-20;
	var params = "height="+h+",width="+w;
	params += ",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes";
	win = window.open(url,name,params);
	win.moveTo(windowX, windowY);
	win.focus();
}

function toggleIncluded(item) {
	toToggle = document.getElementById('included'+item);
	toggleLink = document.getElementById('toggleLink'+item);
	if (toToggle.style.display=="none") {
		toToggle.style.display = "";
		toggleLink.innerHTML = "Hide Included Items >>";
	}
	else {
		toToggle.style.display = "none";
		toggleLink.innerHTML = "Show Included Items >>";
	}
}

function toggleDescription(item) {
	toToggle = document.getElementById('included'+item);
	toggleLink = document.getElementById('toggleLink'+item);
	if (toToggle.style.display=="none") {
		toToggle.style.display = "";
		toggleLink.innerHTML = "Hide Review >>";
	}
	else {
		toToggle.style.display = "none";
		toggleLink.innerHTML = "Show Review >>";
	}
}

function togglePackageMenu(item) {
  packageMenuItems = [];
  packageMenuItems[0] = 'package_included';
  packageMenuItems[1] = 'mfg_included';
  packageDisplayText = [];
  packageDisplayText[0] = 'Included in this Kit';
  packageDisplayText[1] = 'Included in the Camera Box';
  linkDisplayText = [];
  linkDisplayText[0] = 'Included Items';
  linkDisplayText[1] = 'The Camera Box';
  for (a=0;a<packageMenuItems.length;a++) {
	  toToggle = document.getElementById(packageMenuItems[a]);
	  linkToggle = document.getElementById(packageMenuItems[a]+'_link');
    if (packageMenuItems[a]==item) {
      toToggle.style.display =  "";
      toggleH1 = document.getElementById('package_included_title');
      toggleH1.innerHTML = packageDisplayText[a];
      linkToggle.innerHTML = '<b>'+linkDisplayText[a]+' >></b>';
    }
    else {
	    toToggle.style.display =  "none";
      linkToggle.innerHTML = linkDisplayText[a]+' >>';
    }
  }
}

function checkStart() {
  selectedCount = 0;
  for (a=0;a<category_count;a++) {
    tItem = document.getElementById('compare_check'+compare_id[a]);
    if (tItem.checked) {
      document.getElementById('result_row'+compare_id[a]).style.background = '#DDDDD5';
      selectedCount++;
    }
  }
  compare_button.disabled = (selectedCount>=1) ? 0 : 1;
}

function clickPackage(myID) {
  cItem = document.getElementById('compare_check'+myID);
  pItem = document.getElementById('result_row'+myID);
  pItem.style.background = (cItem.checked) ? '#DDDDD5' : '#FFFFFF';
  selectedCount = 0;
  for (a=0;a<category_count;a++) {
    tItem = document.getElementById('compare_check'+compare_id[a]);
    selectedCount += (tItem.checked) ? 1 : 0;
  }
  compare_button.disabled = (selectedCount>=1) ? 0 : 1;
}

function doCompare() {
  itemsToCompare = [];
  i = 0;
  for (a=0;a<category_count;a++) {
    tItem = document.getElementById('compare_check'+compare_id[a]);
    if (tItem.checked) {
      itemsToCompare[i] = compare_id[a];
      i++;
    }
  }
  newURL = 'compare.php?compare='+itemsToCompare.join('|');
  popWindow(newURL, 780, 550, 'compare');
}

function continueCompare(myID) {
  window.opener.location.href = 'package.php?id='+myID;
  window.close();
}

function number_format(myInput) {
  if (isNaN(myInput)) {
    return '0.00';
  }
  else {
    myInput = myInput.toString();
    var parts = myInput.split('.');
  	part1 = parts[0];
  	if (parts.length>=2) {
  		part2 = '.'+parts[1];
  		part2 += (part2.length<=2) ? '0' : '';
    }
    else {
      part2 = '.00';
    }
  	var rgx = /(\d+)(\d{3})/;
  	while (rgx.test(part1)) {
  		part1 = part1.replace(rgx, '$1' + ',' + '$2');
  	}
  	return part1 + part2;
  }
}

function updateQuantity(myID,myIndex) {
  qItem = document.getElementById('quantity'+myID);
  cart_qty[myIndex] = qItem.value;
  num_subtotal = cart_qty[myIndex]*cart_prc[myIndex];
  subtotal_text = number_format(num_subtotal.toFixed(2));
  pItem = document.getElementById('subtotal'+myID);
  pItem.innerHTML = '$'+subtotal_text;
  updateCartInfo(shipping_country,country_ship,shipping_state,state_ship,shipping_option);
  path = 'includes/update.inc.php?action=updateQuantity&id='+myID+'&quantity='+qItem.value;
  document.all.update_frame.contentWindow.location.replace(path);
}

function updateCartInfo(c_val,c_ship,s_val,s_ship,o_val) {
  
  myButton = document.getElementById('checkoutButton');
  shipping_country = c_val;
  country_ship = c_ship;
  shipping_state = s_val;
  state_ship = s_ship;
  shipping_option = o_val;
  
  var tax_val = '';
  var shipping_val = '';
  var items_total = 0;
  var shipping_total = 0;
  var button_val = 'Proceed to Checkout';
  var button_disabled = 0;
  
  for (a=0;a<cart_count;a++) {
    items_total += cart_qty[a]*cart_prc[a];
    shipping_total += cart_qty[a]*cart_shp[a];
  }
  var tax_total = (shipping_state==1453) ? items_total*8.875/100 : 0;
  var cart_total = items_total + shipping_total + tax_total;
  
  if (shipping_country==187) {
    if (shipping_state==0) {
      tax_val = 'Select State';
      shipping_val = 'Select State';
      total_val = '';
      button_val = 'Proceed to Checkout';
      button_disabled = 1;
    }
    else if (!s_ship) {
      tax_val = 0;
      shipping_val = '';
      total_val = '';
      button_val = 'Get Shipping Quote';
      button_disabled = 0;
    }
    else {
      tax_val = tax_total;
      if (shipping_option==0) {
        shipping_val = 'Select Shipping';
        total_val = '';
        button_val = 'Proceed to Checkout';
        button_disabled = 1;
      }
      else if (shipping_option==1) {
        shipping_val = shipping_total;
        total_val = cart_total;
        button_val = 'Proceed to Checkout';
        button_disabled = 0;
      }
      else {
        shipping_val = '';
        total_val = '';
        button_val = 'Get Shipping Quote';
        button_disabled = 0;
      }
    }
  }
  else if (shipping_country==31 || shipping_country==111) {
    tax_val = 0;
    shipping_val = '';
    total_val = '';
    button_val = 'Get Shipping Quote';
    button_disabled = (shipping_state==0) ? 1 : 0;
  }
  else {
    tax_val = 0;
    shipping_val = '';
    total_val = '';
    button_val = 'Get Shipping Quote';
    button_disabled = (c_ship) ? 0 : 1;
  }
  
  if (cart_total>10000) {
    myButton.value = 'Exceeds $10,000 Limit';
    myButton.disabled = 1;
  }
  else {
    myButton.value = button_val;
    myButton.disabled = button_disabled;
  }
  
  document.getElementById('items_total').innerHTML = '$'+number_format(items_total.toFixed(2));
  document.getElementById('tax_total').innerHTML = (isNaN(tax_val)) ? tax_val : '$'+number_format(tax_val.toFixed(2));
  document.getElementById('shipping_total').innerHTML = (isNaN(shipping_val)) ? shipping_val : '$'+number_format(shipping_total.toFixed(2));
  document.getElementById('cart_total').innerHTML = (total_val.length==0) ? '' : '$'+number_format(cart_total.toFixed(2));
  
  document.getElementById('shipping_total').style.visibility = (shipping_val.length==0) ? 'hidden' : 'visible';
  document.getElementById('shipping_title').style.visibility = (shipping_val.length==0) ? 'hidden' : 'visible';
  document.getElementById('cart_total').style.visibility = (total_val.length==0) ? 'hidden' : 'visible';
  document.getElementById('total_title').style.visibility = (total_val.length==0) ? 'hidden' : 'visible';
  
  path = 'includes/update.inc.php?action=updateShipping&country='+shipping_country+'&state='+shipping_state+'&option='+shipping_option;
  document.all.update_frame.contentWindow.location.replace(path);
  
}

function continueCart() {
  for (a=0;a<cart_count;a++) {
    qItem = document.getElementById('quantity'+cart_id[a]);
    cart_qty[a] = qItem.value;
  }
  id_list = cart_id.join("|");
  qty_list = cart_qty.join("|");
  new_location = (server_name=='www.getitdigital.com') ? 'https://www.getitdigital.com/checkout.php' : 'checkout.php';
  new_location += '?action=update&id='+id_list+'&quantity='+qty_list+'&shipping_country='+shipping_country+'&shipping_state='+shipping_state+'&shipping_option='+shipping_option;
  window.location = new_location;
}
