// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function numeralsOnly(evt)
{
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if(charCode > 31 && (charCode < 48 || charCode > 57)){
		alert("Error: You must fill in only numbers!");
		return false;
	}
	return true;
}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    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=document.getElementById(args[i]);
      if (val) { nm=val.name; if(nm=='password1') nm='password'; if(nm=='password2') nm='verify password'; if(nm=='email1') nm='e-mail'; if(nm=='email2') nm='verify e-mail'; if(nm=='zip') nm='zip code'; if(nm=='mail') nm='e-mail'; if(nm=='numeb') nm='billing name'; if(nm=='prenumeb') nm='billing first name'; if(nm=='orasb') nm='billing city'; if(nm=='tarab') nm='billing country'; if(nm=='adresab') nm='billing address'; if(nm=='codb') nm='billing zip code'; if(nm=='mailb') nm='e-mail'; if(nm=='telefonb') nm='phone'; if(nm=='numee') nm='shipping name'; if(nm=='prenumee') nm='shipping first name'; if(nm=='orase') nm='shipping city'; if(nm=='adresae') nm='shipping address'; if(nm=='first_name') nm='first name'; if(nm=='code') nm='shipping zip code'; if(nm=='numep') nm='friend\'s name'; if(nm=='prenumep') nm='friend\'s first name'; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\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+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function verificare(){
	var pass1 = document.crearecont.parola1.value;
	var pass2 = document.crearecont.parola2.value;
	var mail1 = document.crearecont.email1.value;
	var mail2 = document.crearecont.email2.value;
	if(pass1!=pass2) {
		alert('The password fields don\'t match!');
		return false;
	}
	if(mail1!=mail2) {
		alert('The e-mail fields don\'t match!');
		return false;
	}
	
	if(document.crearecont.country.value=="nimic"){
		alert('ERROR! Please select the country!');
		return false;
	}
	
	return true;
}

var flag=0;

function docheck()
{
	if(flag==0){
		MM_validateForm('numeb','','R','prenumeb','','R','orasb','','R','adresab','','R','codb','','R','telefonb','','R','mailb','','R','numee','','R','prenumee','','R','orase','','R','adresae','','R','code','','R');	
	}
	else if(flag==1){
		MM_validateForm('numeb','','R','prenumeb','','R','orasb','','R','adresab','','R','codb','','R','telefonb','','R','mailb','','RisEmail');
	}
}

function tariver(){
	
	if(document.frmForm.tarab.value=="nimic"){
		alert('ERROR! Please select billing country!');
		return false;
	}

	if(document.frmForm.tarae.value=="nimic"){
		alert('ERROR! Please select shipping country!\n We can deliver the products only in some countries!');
		return false;
	}
	
	if(document.frmForm.tarae.value=="us"&&document.frmForm.state.value=="-"){
		alert('ERROR! Please select shipping state!\n We can deliver the products only in some USA states!');
		return false;
	}
	
	if(document.frmForm.plata.value<2){
		document.frmForm.action="trimite_comanda.php";	
	}
	else{
		document.getElementById('BILL_LNAME').value=document.getElementById('numeb').value;
		document.getElementById('BILL_FNAME').value=document.getElementById('prenumeb').value;
		document.getElementById('BILL_COUNTRYCODE').value=document.getElementById('tarab').value;
		document.getElementById('BILL_CITY').value=document.getElementById('orasb').value;
		document.getElementById('BILL_STATE').value=document.getElementById('statb').value;
		document.getElementById('BILL_ADDRESS').value=document.getElementById('adresab').value;
		document.getElementById('BILL_ZIPCODE').value=document.getElementById('codb').value;
		document.getElementById('BILL_PHONE').value=document.getElementById('telefonb').value;
		document.getElementById('BILL_EMAIL').value=document.getElementById('mailb').value;
		document.getElementById('DELIVERY_LNAME').value=document.getElementById('numee').value;
		document.getElementById('DELIVERY_FNAME').value=document.getElementById('prenumee').value;
		document.getElementById('DELIVERY_ADDRESS').value=document.getElementById('adresae').value;
		document.getElementById('DELIVERY_ZIPCODE').value=document.getElementById('code').value;
		document.getElementById('DELIVERY_CITY').value=document.getElementById('orase').value;
		document.getElementById('DELIVERY_STATE').value=document.getElementById('state').value;
		document.frmForm.action="https://secure.epayment.ro/order/lu.php";
	}
	
	return true;
}

function dodisable()
{
	if(flag==0){
		document.frmForm.numee.value=document.frmForm.numeb.value;
		document.frmForm.prenumee.value=document.frmForm.prenumeb.value;
		document.frmForm.orase.value=document.frmForm.orasb.value;
		document.frmForm.adresae.value=document.frmForm.adresab.value;
		document.frmForm.code.value=document.frmForm.codb.value;
		flag=1;
	}
	else if(flag==1){
		flag=0;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj){ //v3.0
	var plata=document.getElementById('plata').value;
	var prenumeben=document.getElementById('prenumeb').value;
	var numeben=document.getElementById('numeb').value;
	var taraben=document.getElementById('tarab').value;
	var orasben=document.getElementById('orasb').value;
	var statben=document.getElementById('statb').value;
	var adresaben=document.getElementById('adresab').value;
	var codben=document.getElementById('codb').value;
	var telben=document.getElementById('telefonb').value;
	var emailben=document.getElementById('mailb').value;
	var prenumeexp=document.getElementById('prenumee').value;
	var numeexp=document.getElementById('numee').value;
	var orasexp=document.getElementById('orase').value;
	var statexp=document.getElementById('state').value;
	var adresaexp=document.getElementById('adresae').value;
	var codexp=document.getElementById('code').value;
  	eval(targ+".location='finalizare_comanda.php?pl="+plata+"&te="+selObj.options[selObj.selectedIndex].value+"&pb="+prenumeben+"&nb="+numeben+"&tb="+taraben+"&ob="+orasben+"&sb="+statben+"&ab="+adresaben+"&cb="+codben+"&tlb="+telben+"&eb="+emailben+"&pe="+prenumeexp+"&ne="+numeexp+"&oe="+orasexp+"&se="+statexp+"&ae="+adresaexp+"&ce="+codexp+"'");
  //	if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenu_m(targ,selObj){ //v3.0
	var plata=document.getElementById('plata').value;
	var prenumeexp=document.getElementById('prenumee').value;
	var numeexp=document.getElementById('numee').value;
	var orasexp=document.getElementById('orase').value;
	var statexp=document.getElementById('state').value;
	var adresaexp=document.getElementById('adresae').value;
	var codexp=document.getElementById('code').value;
  	eval(targ+".location='finalizare_comanda.php?pl="+plata+"&te="+selObj.options[selObj.selectedIndex].value+"&pe="+prenumeexp+"&ne="+numeexp+"&oe="+orasexp+"&se="+statexp+"&ae="+adresaexp+"&ce="+codexp+"'");
  //	if (restore) selObj.selectedIndex=0;
}

