function echeck(str) { // check for valid email addresses
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}	
	if (str.indexOf(" ")!=-1){
		return false
	}
	return true					
}
//-------------------------------------------
function fValidateContact() {
	//nume
	if ((document.getElementById("txtNume").value.length < 3) || (document.getElementById("txtNume").value.length > 50)) {
		alert("Va rugam completati campul 'Nume' (3-50 caractere)");
		document.getElementById("txtNume").focus();
		return false;
	}
	
	//email
	var oEmail = document.getElementById("txtEmail");
	if ((oEmail.value == null) || (oEmail.value.length < 1)){
		alert("Va rugam completati campul 'Adresa E-mail'.");
		oEmail.focus();
		return false;
	}
	if (echeck(oEmail.value) == false){
		alert("Adresa E-mail introdusa nu este valida.");
		oEmail.focus();
		return false;
	}
	
	//mesaj
	if ((document.getElementById("txtMesaj").value.length < 1) || (document.getElementById("txtMesaj").value.length > 3000)) {
		alert("Va rugam completati campul 'Mesaj' (1-3000 caractere)");
		document.getElementById("txtMesaj").focus();
		return false;
	}
	
	//cod securitate
	if (document.getElementById("txtCodSecuritate").value.length < 6) {
		alert("Campul 'Cod Securitate' trebuie sa contina 6 cifre.");
		document.getElementById("txtCodSecuritate").focus();
		return false;
	}
	return true;
}
//-------------------------------------------
function fValidateEmisii() {
	//motorizare
	if (document.getElementById("selMotorizare").value < 1) {
		alert("Alegeti cel putin Fabricant, Model, Versiune.");
		document.getElementById("selMotorizare").focus();
		return false;
	}

	//cod securitate
	if (document.getElementById("txtCodSecuritate").value.length < 6) {
		alert("Campul 'Cod Securitate' trebuie sa contina 6 cifre.");
		document.getElementById("txtCodSecuritate").focus();
		return false;
	}
	return true;
}
//-------------------------------------------
function fPageChanger(iSelectID) {

	iIdProducator = document.getElementById('selProducator').value;
	if (iSelectID == "selProducator") {
		iIdModel = 0;
		iIdCombustibil = 0;
		iIdTransmisie = 0;
		iIdCategorie = 0;
		iIdMotorizare = 0;
	} else {
		iIdModel = document.getElementById('selModel').value;
		if (iSelectID == "selModel") {
			iIdCombustibil = 0;
			iIdTransmisie = 0;
			iIdCategorie = 0;
			iIdMotorizare = 0;
		} else {
			iIdTransmisie = document.getElementById('selTransmisie').value;
			iIdCategorie = document.getElementById('selCategorie').value;
			iIdCombustibil = document.getElementById('selCombustibil').value;
			iIdMotorizare = document.getElementById('selMotorizare').value;
		}
	}
	
	var sURL = 'emisii';
	sURL += '-p' + iIdProducator;
	sURL += '-m' + iIdModel;
	sURL += '-g' + iIdCategorie;
	sURL += '-c' + iIdCombustibil;
	sURL += '-t' + iIdTransmisie;
	sURL += '-v' + iIdMotorizare + '.htm';
	document.location = sURL;
}
//-------------------------------------------
function getModelList(sel) {

	//reset 
	document.getElementById('selCategorie').options.length = 0;
	document.getElementById('selTransmisie').options.length = 0;
	document.getElementById('selCombustibil').options.length = 0;
	document.getElementById('selMotorizare').options.length = 0;

	var obj = document.getElementById('selCategorie');
	obj.options[obj.options.length] = new Option('Alege','0');

	var obj = document.getElementById('selTransmisie');
	obj.options[obj.options.length] = new Option('Alege','0');

	var obj = document.getElementById('selCombustibil');
	obj.options[obj.options.length] = new Option('Alege','0');

	var obj = document.getElementById('selMotorizare');
	obj.options[obj.options.length] = new Option('Alege','0');


	var iIdProducator = sel.options[sel.selectedIndex].value;
	document.getElementById('selModel').options.length = 0;
	if(iIdProducator.length > 0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'ajax/getItems.php?action=models&iIdProducator=' + iIdProducator;
		ajax[index].onCompletion = function(){ createModels(index) };
		ajax[index].runAJAX();
	}
}
function createModels(index) {
	var obj = document.getElementById('selModel');
	eval(ajax[index].response);	
}
//-------------------------------------------
function getCategoriesList(sel) {
	var iIdModel = sel.options[sel.selectedIndex].value;
	document.getElementById('selCategorie').options.length = 0;
	if(iIdModel.length > 0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'ajax/getItems.php?action=categories&iIdModel=' + iIdModel;
		ajax[index].onCompletion = function(){ createCategories(index) };
		ajax[index].runAJAX();
	}
}
function createCategories(index) {
	var obj = document.getElementById('selCategorie');
	eval(ajax[index].response);	
}
//-------------------------------------------
function getTransmissionList(sel) {
	var iIdModel = sel.options[sel.selectedIndex].value;
	document.getElementById('selTransmisie').options.length = 0;
	if(iIdModel.length > 0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'ajax/getItems.php?action=transmission&iIdModel=' + iIdModel;
		ajax[index].onCompletion = function(){ createTransmissions(index) };
		ajax[index].runAJAX();
	}
}
function createTransmissions(index) {
	var obj = document.getElementById('selTransmisie');
	eval(ajax[index].response);	
}
//-------------------------------------------
function getFuelList(sel) {
	var iIdModel = sel.options[sel.selectedIndex].value;
	document.getElementById('selCombustibil').options.length = 0;
	if(iIdModel.length > 0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'ajax/getItems.php?action=fuel&iIdModel=' + iIdModel;
		ajax[index].onCompletion = function(){ createFuels(index) };
		ajax[index].runAJAX();
	}
}
function createFuels(index) {
	var obj = document.getElementById('selCombustibil');
	eval(ajax[index].response);	
}
//-------------------------------------------
function getVersionsListByModel(sel) {
	var iIdModel = sel.options[sel.selectedIndex].value;
	document.getElementById('selMotorizare').options.length = 0;
	if(iIdModel.length > 0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'ajax/getItems.php?action=versions_by_model&iIdModel=' + iIdModel;
		ajax[index].onCompletion = function(){ createVersionsByModel(index) };
		ajax[index].runAJAX();
	}
}
function createVersionsByModel(index) {
	var obj = document.getElementById('selMotorizare');
	eval(ajax[index].response);	
}
//-------------------------------------------
function getVersionsList() {

	var iIdModel = document.getElementById("selModel").options[document.getElementById("selModel").selectedIndex].value;
	var iIdCategorie = document.getElementById("selCategorie").options[document.getElementById("selCategorie").selectedIndex].value;
	var iIdTransmisie = document.getElementById("selTransmisie").options[document.getElementById("selTransmisie").selectedIndex].value;
	var iIdCombustibil = document.getElementById("selCombustibil").options[document.getElementById("selCombustibil").selectedIndex].value;

	document.getElementById('selMotorizare').options.length = 0;
	if(iIdModel.length > 0){
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'ajax/getItems.php?action=versions&iIdModel=' + iIdModel + '&iIdCategorie=' + iIdCategorie + '&iIdTransmisie=' + iIdTransmisie + '&iIdCombustibil=' + iIdCombustibil;
		ajax[index].onCompletion = function(){ createVersions(index) };
		ajax[index].runAJAX();
	}
}
function createVersions(index) {
	var obj = document.getElementById('selMotorizare');
	eval(ajax[index].response);	
}
//-------------------------------------------
//-------------------------------------------