var request = false;
try {
	request = new XMLHttpRequest();
} catch (trymicrosoft) {
	try {
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
		try {
			request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (failed) {
			request = false;
		}
	}
}

if (!request)
alert("Error initializing XMLHttpRequest!");

function UpdateQnt(value,ProdID,secondh,rent) {
	if(secondh=='') { secondhtxt = "" ;}
	else { secondhtxt = "&sh=" + secondh}
	if(rent=='') { renttxt = "" ;}
	else { renttxt = "&rent=" + rent}
	var url = "command_process.php?cmd=EditQnt" + "&ProdID=" + ProdID + "&value=" + value + secondhtxt + renttxt;
	request.open("GET", url, true);
	request.onreadystatechange = updatePage;
	request.send(null);
}

function updatePage() {
	if (request.readyState == 4)
	if (request.status == 200) {
		//window.location.reload();
		return 1;
	}
}

//VALIDATION//

function validate_cart_from(theForm) {
var reason = "";

  if(validateEmail(theForm.email)) reason +='O adresa de E-mail valida.\n';
  if(validateEmpty(theForm.nume))  reason +='Un nume.\n';
  if(validateEmpty(theForm.companie)) reason +='Compania.\n';
  if(validateEmpty(theForm.J)) reason +='Numar inregistrare RC.\n';
  if(validateEmpty(theForm.RO)) reason +='CUI.\n';
  if(validateEmpty(theForm.tel)) reason +='Un numar de telefon.\n';
  if(validateEmpty(theForm.fax)) reason +='Un numar de fax.\n';
  if(validateEmpty(theForm.primad)) reason +='O adresa primara.\n';
  if(validateEmpty(theForm.secad)) reason +='O adresa secundara.\n';
      
  if (reason != "") {
    alert("Va rugam introduceti:\n\n" + reason);
    return false;
  }

  return true;
}


function validate_rent_from(theForm) {
var reason = "";

  if(validateEmail(theForm.email)) reason +='O adresa de E-mail valida.\n';
  if(validateEmpty(theForm.nume))  reason +='Un nume.\n';
  if(validateEmpty(theForm.tel)) reason +='Un numar de telefon.\n';
  if(validateEmpty(theForm.data)) reason +='Data preluarii.\n';
  if(validateEmpty(theForm.perioada)) reason +='Perioada de inchiriere.\n';
  if(validateEmpty(theForm.tip)) reason +='Tipul masinii.\n';
      
  if (reason != "") {
    alert("Va rugam introduceti:\n\n" + reason);
    return false;
  }

  return true;
}

//Validare formular de servicii

function validate_service_from(theForm) {
var reason = "";

  if(validateEmail(theForm.email)) reason +='O adresa de E-mail valida.\n';
  if(validateEmpty(theForm.nume))  reason +='Un nume.\n';
  if(validateEmpty(theForm.tel)) reason +='Un numar de telefon.\n';
  if(validateEmpty(theForm.piese)) reason +='Tipul masinii.\n';
      
  if (reason != "") {
    alert("Va rugam introduceti:\n\n" + reason);
    return false;
  }

  return true;
}


//Gol

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#8d9fa0';
        fld.style.border = 'solid 1px white';
        error = "Va rugam completati datele markate cu alb.\n"
    } else {
       fld.style.background = '#3d4a54';
       fld.style.border = 'solid 1px #92999e';
    }
    return error;  
}

//EMAIL

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#8d9fa0';
        fld.style.border = 'solid 1px white';
        fld.value='';
        error = "Nu ati introdus o adresa de E-mail.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#8d9fa0';
        fld.style.border = 'solid 1px white';
        fld.value='';
        error = "Va rugam introduceti o adresa de E-mail valida.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "Adresa de E-mail contine caractere ilegale.\n";
    } else {
       fld.style.background = '#3d4a54';
       fld.style.border = 'solid 1px #92999e';
    }
    return error;
}

//
//
