var itemNum = new Array();
var itemDescr = new Array();
var itemCost = new Array();



function itemsOrdered() {
 if (getCookieData("Scart")) {
 substr0 = getCookieData("Scart")
 cLen = substr0.length
 offset0 = substr0.indexOf("@")
 counter = substr0.substring(0,offset0)
 j = 0
 for (i=1; i<=counter; i++) {
  offsetq = eval('offset' + j + '');
  substrq = eval('substr' + j + '');
  eval('ind' + i + ' = offsetq + 1');
  eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
  eval('offset' + i + ' = substr' + i + '.indexOf("^")');
  eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
  eval('catInd' + i + ' = item' + i + '.indexOf("`")');
  eval('itemCat' + i + ' = item' + i + '.substring(0,catInd' + i + ')');
  eval('descrInd' + i + ' = item' + i + '.indexOf("~")');
  eval('itemDes' + i + ' = item' + i + '.substring((catInd' + i + ' + 1),descrInd' + i + ')');
  eval('itemPr' + i + ' = item' + i + '.substring((descrInd' + i + ' + 2),offset' + i + ')'); 
  eval('orderDetail(i,itemCat' + i + ',itemDes' + i + ',itemPr' + i + ')');
  j++
 }
 writeCart();
 }
}



function orderDetail(seq,num,descr,cost) {
 itemNum[seq] = num
 itemDescr[seq] = descr
 itemCost[seq] = cost
}




function writeCart() {
  var ordFrm = '<br>'
  ordFrm += '<form name="shopCart" method="POST" action="http://www.genija.com/cgi-bin/formmail.pl" onSubmit="return validate_form()"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="okvir-no-margin" align=center>'
  ordFrm += '<input type="hidden" name="recipient" value="&#x69;&#110;&#102;&#111;&#64;&#x67;&#101;&#x6e;&#105;&#106;&#97;&#46;&#99;&#x6f;&#x6d;">'
  ordFrm += '<input type="hidden" name="subject" value="Narocilo knjige">'
  ordFrm += '<input type=hidden name="redirect" value="http://www.genija.com/odjava.php">'
  ordFrm += '<input type="hidden" name="print_config" value="Podatki:">'
  ordFrm += '<input type="hidden" name="orderDetail" value="newOrder">'
//
  ordFrm += '	<tr>'
  ordFrm += '	<td colspan="4" valign=top align=left class="narocilo-header"><strong>Naročili boste naslednje knjige:</strong></span></td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '	<td colspan="4" valign=top align=left>&nbsp;</td>'
  ordFrm += '	</tr>'
//
  for (i = 1; i <= counter; i++) {
//
  ordFrm += '	<tr>'
  ordFrm += '		<td width="220" valign=top align=left class=body-text>' + itemNum[i] + '</td>'
  ordFrm += '		<td width="300" valign=top align=left class=body-text>' + itemDescr[i] + '</td>'
  ordFrm += '		<td valign=top align=right class=body-text>' + itemCost[i] + '</td>'
  ordFrm += '		<td width="50" align=left class=body-text><a href="javascript:clearIt('+i+')">Izbriši</a></td>'
  ordFrm += '	</tr>'
  }
  ordFrm += '	<tr>'
  ordFrm += '	<td colspan="4" valign=top align=left>&nbsp;</td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '		<td colspan="4" height="1" bgcolor="#CCCCCC"></td>'
  ordFrm += '	</tr>'
	ordFrm += '	<tr>'
  ordFrm += '		<td colspan="2" bgcolor="#FFFFF5" align="left" class=body-text><strong>SKUPAJ</strong></td>'
  ordFrm += '		<td bgcolor="#FFFFF5" align="right"><input type="text" class="box" name="subtotal" size=5 maxlength=5 value="0.00" onFocus="document.shopCart.subtotal.blur()"></td>'
  ordFrm += '		<td bgcolor="#FFFFF5" align=left class=body-text><strong>€</strong></td>'
  ordFrm += '	</tr>'
  ordFrm += '</table>'
  ordFrm += '<table width=100% table border=0 align=center><tr><td height="25" valign=bottom align=left class=ISBN>* cene so z DDV-jem. <b>10%</b> popusta bo upoštevano na računu. <b>Najnižji znesek naročila je <b>10 €</b>.</b></td></table><br><br>'
//
  ordFrm += '<table width="100%" border="0" cellpadding="0" cellspacing="0" class="okvir-no-margin" align=center>'
  ordFrm += '	<tr>'
  ordFrm += '	<td colspan="2" valign=top align=left class="narocilo-header"><strong>Vaši podatki:</strong></span></td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '	<td colspan="2" valign=top align=left>&nbsp;</td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '		<td width="105" height="22" align=left valign="bottom" class="body-text">Ime in priimek:</td>'
  ordFrm += '		<td width="*" align=left><input type="text" size="63" name="ime" class="box04"></td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '		<td width="105" height="22" align=left valign="bottom" class="body-text">E-mail:</td>'
  ordFrm += '		<td width="*" align=left><input type="text" size="63" name="email" class="box04"></td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '		<td width="105" height="22" align=left valign="bottom" class="body-text">Telefon:</td>'
  ordFrm += '		<td width="*" align=left><input type="text" size="63" name="phone" class="box04"></td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '		<td width="105" height="22" align=left valign="bottom" class="body-text">Naslov:</td>'
  ordFrm += '		<td width="*" align=left><input type="text" size="63" name="naslov" class="box04"></td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '		<td width="105" height="22" align=left valign="bottom" class="body-text">Pošta in mesto:</td>'
  ordFrm += '		<td width="*" align=left><input type="text" size="63" name="mesto" class="box04"></td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '		<td width="105" align=left valign=top class="body-text">&nbsp;</td>'
  ordFrm += '		<td width="*" align=left><textarea rows=5 cols=56 name="instructions" class="box04">Vaše opombe:</textarea></td>'
  ordFrm += '	</tr>'
  ordFrm += '	<tr>'
  ordFrm += '	<td colspan="2" valign=top align=left>&nbsp;</td>'
  ordFrm += '	</tr>'
  ordFrm += '</table>'
  ordFrm += '<table width=100% table border=0 align=center><tr><td height="25" valign=top align=left class=ISBN> * vsi podatki razen opomb so obvezni. Osebne podatke ne shranjujemo.</td></table>'
//
  ordFrm += '<br>'
  ordFrm += '<br>'
  ordFrm += '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
  ordFrm += '	<tr>'
  ordFrm += '		<td width="180" align="left" class="body-text"><input type="image" name="submit" value=<img src="common-pic/poslji-01.gif" width="135" height="15" border="0"></td>'
  ordFrm += '		<td align="center" class="body-text">&nbsp;</td>'
  ordFrm += '		<td width="200" align="right" class="body-text"><img src="common-pic/delete01.gif"> <a href="javascript:killCart()">Prekliči in izprazni košarico</a></td>'
  ordFrm += '	</tr>'
  ordFrm += '</table>'
  ordFrm += '</center></form>'
  document.write(ordFrm);
  document.close();
}


function clearIt(num) {
 itemNum[num] = "item"
 itemDescr[num] = "cancelled"
 itemCost[num] = 0
 rewriteCookie(num)
 update()
}



function rewriteCookie(num) {
 dataUpdate = ""
 for (i=1; i<=counter; i++) {
   if (itemNum[i] != "item") {
    dataUpdate += itemNum[i] + '`' + itemDescr[i] + '~$' + itemCost[i] + '^'
   }
 }
 counter = counter - 2
 cookData = dataUpdate
 setCookieData("Scart", cookData, expdate.toGMTString())
 history.go(0)
}




function writeShipping() {

 leng = 1;
 options = new Array(leng);
 options[0] = "Ground (Insurance)";


 html_code2 = "";
 
 html_code2 += '<font size=3>Shipping & Handling: </font><select size=1 '
  + 'name="ShipVia" onChange="update()">';
 for (o=0;o<leng;o++)
  html_code2 += '<option value="'+options[o]+'"'
   + ((o==0) ? ' selected>':'>') + options[o];
 html_code2 += '</select></td><td>';
 html_code2 += '<input type="text" name="ShipCharges" size=6 '
 html_code2 += 'maxlength=6 value="0.00" '
 html_code2 += 'onFocus="document.shopCart.ShipCharges.blur()">';
 return html_code2;
}



var shipCost = 0



function shippingCost() {
shipCost = 0
itemUp = counter - 1 // variable to increment charges
multiplier = 0.00 // additional charge per item after first.
 if (document.shopCart.ShipVia.options[0].selected) {
   shipCost = 0.00 + (itemUp * multiplier) + (itemUp * 0.85) }  // $9.95 plus insurance
}




function update() {
if (getCookieData("Scart")) {
 var sub_total = 0;
 for (i=1; i<itemNum.length; i++)
  eval('sub_total += parseFloat(itemCost[' + i + ']);');
 document.shopCart.subtotal.value= fix(sub_total);
}
}


function fix(num) {
 string = "" + num;
 if (string.indexOf('.') == -1)
  return string + '.00';
 seperation = string.length - string.indexOf('.');
 if (seperation > 3)
  return string.substring(0,string.length-seperation+3);
 else if (seperation == 2)
  return string + '0';
 return string;
}

function validate_form() {
 detailUpdate = "\n"
 for (i=1; i<=counter; i++) {
   detailUpdate += itemNum[i] + ' ' + itemDescr[i] + ' $' + itemCost[i] + '\n'
   }
 document.shopCart.orderDetail.value = detailUpdate
 validity = true;
 if (document.shopCart.ime.value == "") {
  alert('Vsi podatki so obvezni!');
  validity = false;
 }

 if (document.shopCart.phone.value == "") {
  alert('Vsi podatki so obvezni!');
  validity = false;
 }
 if (document.shopCart.naslov.value == "") {
  alert('Vsi podatki so obvezni!');
   valid = false;
 }
 
 if ((document.shopCart.mesto.value == "")) {
  alert('Vsi podatki so obvezni!');
  validity = false;
 }

 if (validity) {
  alert("Naročilo je poslano!");
  killCookie("Scart");
 }
 return validity;
}



function killCart() {
 killCookie("Scart")
 history.go(-1)
}

