// NebuCart - The JavaScript Shopping Cart
//Originally authored by Pat Friedl pfriedl@nebulus.org
//
// Copyright 1999-2006 all rights reserved.

// None of this script may be redistributed or sold
// without the authors express consent.
// Violations of copyright will be prosecuted.

// If you would like to use NebuCart,
// email us at admin@javascriptcart.com
// or visit http://www.javascriptcart.com

// ********************************************
// NebuCart Cart Formatting Routines          *
// ********************************************
// DO NOT CHANGE ANYTHING BELOW THIS LINE!    *
// ********************************************

var myFont      = fontFace;
var currentDate = new Date();
var Months      = new Array();
 Months[0]   = 'Januar';
 Months[1]   = 'Februar';
 Months[2]   = 'M&auml;rz';
 Months[3]   = 'April';
 Months[4]   = 'Mai';
 Months[5]   = 'Juni';
 Months[6]   = 'Juli';
 Months[7]   = 'August';
 Months[8]   = 'September';
 Months[9]   = 'Oktober';
 Months[10]  = 'November';
 Months[11]  = 'Dezember';
var today       = Months[currentDate.getMonth()];
if(navigator.appName == 'Netscape'){
 var tmpYr = String(currentDate.getYear());
// today = today + ' ' + currentDate.getDate() + ', 20' + tmpYr.substring(tmpYr.length-2,tmpYr.length);
today = currentDate.getDate() + '. ' + today + ' 20' + tmpYr.substring(tmpYr.length-2,tmpYr.length);
} else {
// today = today + ' ' + currentDate.getDate() + ', ' + currentDate.getYear();
today = currentDate.getDate() + '. ' + today + ' ' + currentDate.getYear();
}
function getValue(itemID,valType){
 optionVal = '';
 if(valType == ''){
  objVal = document.NC_form.elements[itemID];
 } else {
  objVal = document.NC_form.elements[itemID + '_' + valType];
 }
 // special case for detecting radio objects
 if(typeof(objVal) == 'object' && typeof(objVal.type) == 'undefined'){
  for(j = 0; j < objVal.length; j ++){
   if(objVal[j].checked){
    optionVal = objVal[j].value;
   }
  }
 // normal case form element detection
 } else if(typeof objVal != 'undefined'){
  switch (objVal.type){
  case 'text':
   optionVal = objVal.value;
  break
  case 'hidden':
   optionVal = objVal.value;
  break
  case 'textarea':
   optionVal = objVal.value;
  break
  case 'checkbox':
   if(objVal.checked){
    optionVal = objVal.value;
   }
  break
  case 'radio':
   if(objVal.checked){
    optionVal = objVal.value;
   }
  break
  case 'select-one':
   optionVal = objVal.options[objVal.selectedIndex].value;
   if(optionVal == ''){
    optionVal = objVal.options[objVal.selectedIndex].text;
   }
  break
  case 'select-multiple':
   for(j = 0; j < objVal.length; j ++){

    if(objVal.options[j].selected){
     currVal = objVal[j].value;
     if(currVal == ''){
      currVal = objVal[j].text;
     }
     if(optionVal == ''){
      optionVal = currVal;
     } else {
      optionVal = optionVal + ', ' + currVal;
     }
    }
   }
  break
  }
 }
 return optionVal;
}
function focus(fld){
 fldObj = document.NC_form.elements[fld];
 if(typeof(fldObj) == 'object' && typeof(fldObj.type) != 'undefined'){
  fldObj.focus();
 }
}
function clear(fld){
 fldObj = document.NC_form.elements[fld];
 if(typeof(fldObj) == 'object' && typeof(fldObj.type) != 'undefined'){
  fldObj.value = '';
 }
}
function formatDecimal(amt,places){
 var tmpString = new String(amt);
 var strBegin = 0;
 var strEnd = 0;
 var endVal = 0;
 var defaultPlaces = 2;
 if(!Number(amt)){
  if(useDecimal){
   return '0.00';
  } else {
   return '0';
  }
 }
 if(tmpString.indexOf(',') != -1){
  tmpString = tmpString.split(',');
  tmpNum    = '';
  for(t = 0; t < tmpString.length; t++){
   tmpNum += String(tmpString[t]);
  }
  tmpString = tmpNum;
 }
 if(places == '' || places == null || !Number(places)){
  places = defaultPlaces;
 }
 if(tmpString.indexOf('.') != -1){
  strBegin = tmpString.substring(0, tmpString.indexOf('.'));
  if(strBegin == ''){ strBegin = 0; }
  strEnd = tmpString.substring(tmpString.indexOf('.')+1, tmpString.length);
  if(strEnd.length > places){
   keeper = Number('.' + strEnd.substring(0,places));;
   rounder = strEnd.charAt(places);
   if(rounder >= 5){
    adder = '';
    for(inc = 0; inc < places -1; inc ++){
     adder += '0';
    }
    adder = Number('.' + adder + '1');
    strEnd = Number(keeper) + adder;
    tmpString = new String(Number(strBegin) + Number(strEnd));
   }
  }
 }
 if(tmpString.indexOf('.') != -1){
  clipper = tmpString.indexOf('.') + 1;
  strBegin = tmpString.substring(0, clipper);
  if(strBegin.charAt(0) == '.'){ strBegin = '0.'; }
  strEnd = tmpString.substring(clipper, clipper+places);
  if(strEnd.length == 1){ strEnd += '0'; }
  tmpString = strBegin + strEnd;
 } else {
  var zeros = '.'
  for(plcCount = 0; plcCount < places; plcCount++){
   zeros += '0';
  }
  tmpString += zeros;
 }
 if(!useDecimal){
  tmpNum = tmpString.split('.');
  if(tmpNum.length > 1){
   tmpNum1 = tmpNum[0];
   tmpNum2 = tmpNum[1];
   tmpString = (Number(tmpNum2))? String(tmpNum1) + String(tmpNum2) : String(tmpNum1);
  }
 }
 if(useThousands && tmpString.length > 3){
  tmpNum  = '';
  tmpNum1 = '';
  if(useDecimal){
   tmpString = tmpString.split('.');
   tmpNum1   = tmpString[1];
   tmpString = tmpString[0];
  }
  while(tmpString.length > 0){
   if(tmpString.length > 3){
    tmpNum    = ',' + String(tmpString.substring(tmpString.length - 3,tmpString.length)) + tmpNum;
    tmpString = tmpString.substring(0,tmpString.length-3);
   } else {
    tmpNum    = String(tmpString) + String(tmpNum);
    tmpString = '';
   }
  }
  tmpString = tmpNum;
  if(useDecimal){
   tmpString = String(tmpString) + ',' + String(tmpNum1);
  }
 }
 return tmpString;
}
function getShipRule(amt,qty){
 var custCountry   = shopperArray[8].toLowerCase();
 var countryList   = new Array();
 var isDomestic    = false;
 var applyDomestic = false;
 var percent       = false;
 var inBounds      = false;
 var useQty        = false;
 var useAmt        = false;
 var ruleMatch     = false;
 var shipCost      = 0;
 var theShipping   = 0;
 if(myShipRules.length == 0){
  alert('no Ship Rules');
  return theShipping;
 }
 for(ruleCount = 0; ruleCount < myShipRules.length; ruleCount ++){
  applyDomestic = myShipRules[ruleCount].applyDomestic;
  percent       = myShipRules[ruleCount].percent;
  shipCost      = myShipRules[ruleCount].shipCost;
  amtLbound     = myShipRules[ruleCount].amtLbound;
  amtUbound     = myShipRules[ruleCount].amtUbound;
  qtyLbound     = myShipRules[ruleCount].qtyLbound;
  qtyUbound     = myShipRules[ruleCount].qtyUbound;
  if(!Number(1+percent)   || !Number(1+shipCost)  ||
     !Number(1+amtLbound) || !Number(1+amtUbound) ||
     !Number(1+qtyLbound) || !Number(1+qtyUbound)){
      return theShipping;
      break;
  }
  if(amtLbound == amtUbound){
   useAmt   = false;
   inBounds = false;
  } else {
   if(amtLbound > amtUbound){
    var tmpBound = amtLbound;
    amtLbound = amtUbound;
    amtUbound = tmpBound;
   }
   useAmt = true;
   if((amt >= amtLbound) && (amt <= amtUbound)){
    inBounds = true;
   }
  }
  if(!useAmt){
   if(qtyLbound == qtyUbound){
    useQty   = false;
    inBounds = false;
   } else {
    if(qtyLbound > qtyUbound){
     var tmpBound = qtyLbound;
     qtyLbound = qtyUbound;
     qtyUbound = tmpBound;
    }
    useQty = true;
    if((qty >= qtyLbound) && (qty <= qtyUbound)){
     inBounds = true;
    }
   }
  }
  if(useAmt && useQty){
   useAmt   = false;
   useQty   = false;
   inBounds = false;
   return theShipping;
   break;
  }
  countryList = myShipRules[ruleCount].countries.split(delim);
  if(countryList.length == 0){
   return theShipping;
   break;
  }
  for(countryCount = 0; countryCount < countryList.length; countryCount ++){
   if(custCountry.toLowerCase() == countryList[countryCount].toLowerCase()){
    isDomestic = true;
    break;
   }
  }
  if((isDomestic == applyDomestic) && inBounds){
   if(percent){
    theShipping = (shipCost * amt);
   } else {
    theShipping = (shipCost * qty);
   }
   return theShipping;
   break;
  } else {
   isDomestic    = false;
   applyDomestic = false;
   percent       = false;
   inBounds      = false;
   useQty        = false;
   useAmt        = false;
   ruleMatch     = false;
   shipCost      = 0;
   theShipping   = 0;
   countryList   = new Array();
  }
 }
 return theShipping;
}
function setupCountrySel(n,v){
 var Cselect   = eval('document.NC_form.' + n);
 var noCountry = true;
 if(Cselect){
  for(countryCnt = 0; countryCnt < Cselect.options.length; countryCnt ++){
   if(Cselect.options[countryCnt].value.toLowerCase() == v.toLowerCase()){
    Cselect.options[countryCnt].selected = true;
    noCountry = false;
    break;
   }
  }
  if(noCountry){
   Cselect.options[0].selected = true;
  }
 }
}
function setupStateSel(n,v){
 var Sselect   = eval('document.NC_form.' + n);
 var noState   = true;
 if(Sselect){
  if(useStateSelect){
   for(stateCnt = 0; stateCnt < Sselect.options.length; stateCnt ++){
    if(Sselect.options[stateCnt].value.toLowerCase() == v.toLowerCase()){
     Sselect.options[stateCnt].selected = true;
     noState = false;
     break;
    }
   }
   if(noState){
    Sselect.options[0].selected = true;
   }
  } else {
   Sselect.value = v;
  }
 }
}
function getCookie(key){
 theCookie = '';
 if(document.cookie && document.cookie.indexOf(key) != -1){
  theCookie = document.cookie;
  theCookie = theCookie.substring(theCookie.indexOf(key),theCookie.length);
  if(theCookie.indexOf(';') != -1){
   theCookie = theCookie.substring(0,theCookie.indexOf(';'));
  }
  return theCookie;
 }
}
function getCookieVal(key){
 theCookie = getCookie(key);
 if(theCookie != '' && theCookie != null){
  theVal = theCookie.substring(theCookie.indexOf(key) + key.length + 1,theCookie.length);
  if(theVal.indexOf(delim) != -1){
   theVal = theVal.split(delim);
  }
  return theVal;
 } else {
  return '';
 }
}
function setCookie(key,val,exp,path,site){

 theCookie = key + '=' + val;
 if(exp != '' && exp != null){
  theCookie += ';expires=' + exp.toGMTString();
 }
 if(path != '' && path != null){
  theCookie += ';path=' + path;
 }
 if(site != '' && site != null){
  theCookie += ';domain=' + site;
 }
 currLocation = String(location).toLowerCase();
 if(currLocation.indexOf('https') != -1){
  theCookie += ';secure';
 }
 document.cookie = theCookie;

}
function killCookie(key){
 setCookie(key,'',setExp(0,0,0,0,0,0,-2),cookiePath,unsecureDomain);
}
function setExp(S,M,H,D,W,Mo,Y){
 exp = new Date();
 sec = 1000;
 min = 60  * sec;
 hr  = 60  * min;
 day = 24  * hr;
 wk  = 7   * day;
 mo  = 30  * day;
 yr  = 365 * day;
 theLen  = exp.getTime();
 theLen += (S * sec) + (M * min) + (H * hr);
 theLen += (D * day) + (W * wk) + (Mo * mo);
 theLen += (Y * yr);
 exp.setTime(theLen);
 return exp;
}
function trim(){
 tmpTxt = this.toString();

 while(tmpTxt.charAt(0) == ' '){
  tmpTxt = tmpTxt.substring(1,tmpTxt.length);
 }
 while(tmpTxt.charAt(tmpTxt.length - 1) == ' '){
  tmpTxt = tmpTxt.substring(0,tmpTxt.length-1);
 }
 return tmpTxt;
}
String.prototype.trim = trim;
if(String(location).indexOf('checkedOut') != -1){
 Cart = new Array();
 cartToCookie();
} else {
 cookieToCart();
}
function encrypt(str) {
 var pwd     = ' ';
 var prand   = '';
 var enc_chr = '';
 var enc_str = '';
 var sPos, mult, incr, modu, salt;
 for(var i=0; i<pwd.length; i++) {
  prand += pwd.charCodeAt(i).toString();
 }
 sPos = Math.floor(prand.length / 5);
 mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));
 incr = Math.ceil(pwd.length / 2);
 modu = Math.pow(2, 31) - 1;
 salt = Math.round(Math.random() * 1000000000) % 100000000;
 prand += salt;
 while(prand.length > 10) {
  prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
 }
 prand = (mult * prand + incr) % modu;
 for(var i=0; i<str.length; i++) {
  enc_chr = parseInt(str.charCodeAt(i) ^ Math.floor((prand / modu) * 255));
  if(enc_chr < 16) {
   enc_str += "0" + enc_chr.toString(16);
  } else {
   enc_str += enc_chr.toString(16);
  }
  prand = (mult * prand + incr) % modu;
 }
 salt = salt.toString(16);
 while(salt.length < 8){
  salt = "0" + salt;
 }
 enc_str += salt;
 return enc_str;
}
function decrypt(str){
 var pwd     = ' ';
 var enc_chr = '';
 var enc_str = '';
 var prand   = '';
 var sPos, mult, incr, modu, salt;
 for(var i=0; i<pwd.length; i++){
  prand += pwd.charCodeAt(i).toString();
 }
 sPos = Math.floor(prand.length / 5);
 mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));
 incr = Math.round(pwd.length / 2);
 modu = Math.pow(2, 31) - 1;
 salt = parseInt(str.substring(str.length - 8, str.length), 16);
 str    = str.substring(0, str.length - 8);
 prand += salt;
 while(prand.length > 10){
  prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
 }
 prand = (mult * prand + incr) % modu;
 for(var i=0; i<str.length; i+=2){
  enc_chr = parseInt(parseInt(str.substring(i, i+2), 16) ^ Math.floor((prand / modu) * 255));
  enc_str += String.fromCharCode(enc_chr);
  prand = (mult * prand + incr) % modu;
 }
 return enc_str;
}
function checkMod10(ccNum){
 var cardDigits  = new Array(ccNum.length);
 var i           = 0
 var sum         = 0;

 for(i  = 0; i < ccNum.length; ++i) {
  cardDigits[i] = parseInt(ccNum.charAt(i));
 }
 /*
 you have to start from the right, and work back.
 every second digit starting with the right most (check digit)
 will be doubled, and summed with the skipped digits.
 if the double digit is > 9, ADD those individual digits together
 */
 for(i = cardDigits.length -2; i >= 0; i-=2) {
  cardDigits[i] *= 2;
  if(cardDigits[i] > 9){
   cardDigits[i]-=9;
  }
 }
 for(i = 0; i < cardDigits.length; ++i){
  sum += cardDigits[i];
 }
 // if the sum is divisible by 10 mod10 succeeds
 return (((sum%10)==0)?true:false);
}

