// JavaScript Document
function buy(itemID){
var oForm2 = document.forms['cart'];
oForm2.hID.value = itemID;
oForm2.hAction.value='add';
var oFormEl = document.forms['itemForm'];
if(oFormEl != null)
{
	//alert("form found")
	var len = oFormEl.elements.length;
	for (var i = 0; i < len; i++) {
	    var e = oFormEl.elements[i];
	    if (e.name == "itemoptions") {
		oForm2.hOVID.value += e.options[e.selectedIndex].value + '|';
	    }
	}
}
oForm2.submit();
}

function compare() {
var oForm3 = document.forms['formcompare'];
oForm3.submit();
}

function del(itemID, opt){
var oForm = document.forms['cart'];
	oForm.hID.value = itemID;
	oForm.hAction.value='del';
	oForm.hOVID.value=opt;
	oForm.submit();
}
function checkout() {
var oForm = document.forms['cart'];
	oForm.hAction.value='checkout';
	oForm.submit();
}

function confirmorder(pCode){
var oForm = document.forms['cart'];
	oForm.hAction.value='confirm';
	oForm.hPmt.value=pCode;
	oForm.submit();
}

function paywith(pCode){
var oForm = document.forms['form1'];
	oForm.hAction.value='pmt';
	oForm.hPmtCode.value=pCode;
	oForm.submit();
}

function orderhistory() {
var oForm = document.forms['cart'];
	oForm.hAction.value='history';
	oForm.submit();
}

function recalc(){
var oForm = document.forms['cart'];
	oForm.hAction.value = 'recalc';
	oForm.submit();
}

function empty(){
var oForm = document.forms['cart'];
	oForm.hAction.value = 'empty';
	oForm.submit();
}
function KeyPress () {
	var keycode;
	var e=true;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13) {
		recalc();
	}
	return true; 
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
//  window.alert(objName);
  var obj = MM_findObj(objName);
//  window.alert(obj.className);
   if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
 // }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='in campul - '+nm+' trebuie sa introduceti o adresa de email.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='campul - '+nm+' trebuie sa contina un numar.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='campul - '+nm+' trebuie sa contina un numar intre '+min+' si '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' este obligatoriu.\n'; }
  } if (errors) alert('Va rugam sa corectati urmatoarele erori:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}
