//UPLOAD SIGLA

function startUpload(){
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}

function stopUpload(success, cuc){
      var pozaUp = ''
	  var result = '';
      if (success == 1){
         result = '<span class="msg">Fotografia a fost incarcata!<\/span><br/><br/>';		
		 var objPhoto = document.getElementById("poze");
		 objPhoto.innerHTML = cuc;		  		
      }
      else {
         result = '<B>Fotografia nu a fost incarcata!</b><br>';
		 alert('Fotografia nu a fost incarcata!\n Cauze:\n   Nu este in format: jpeg, gif sau png.\n   Depaseste dimensiunea de 1Mb.\n   Ati depasit limita de 6 Fotografii adaugate.\n');
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      document.getElementById('f1_upload_form').style.visibility = 'visible';      
	  return true;   
}

//UPLOAD SIGLA END

//UPLOAD  FOTO PARC

function startUploadSigla(){
      document.getElementById('f1_upload_processSigla').style.visibility = 'visible';
      document.getElementById('f1_upload_formSigla').style.visibility = 'hidden';
      return true;
}

function stopUploadSigla(success, cuc){
      var pozaUp = ''
	  var result = '';
      if (success == 1){
         result = '<span class="msg">Fotografia a fost incarcata!<\/span><br/><br/>';		
		 var objPhoto = document.getElementById("sigle");
		 objPhoto.innerHTML = cuc;		  		
      }
      else {
         result = '<B>Fotografia nu a fost incarcata!</b><br>';
		 alert('Fotografia nu a fost incarcata!\n Cauze:\n   Nu este in format: jpeg, gif sau png.\n   Depaseste dimensiunea de 1Mb.\n   Aveti o sigla uploadata deja.\n  Daca doriti sa o schimbati mai intai trebuie sa o sergeti pe eca existenta.\n');
      }
      document.getElementById('f1_upload_processSigla').style.visibility = 'hidden';
      document.getElementById('f1_upload_formSigla').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      document.getElementById('f1_upload_formSigla').style.visibility = 'visible';      
	  return true;   
}

//UPLOAD FOTO PARC END

//INCARCA MODEL
function incarcaModele(url)
{
  var sel = document.getElementById("marca");
  var marca = sel.options[sel.selectedIndex].value;
  var deAfis = document.getElementById("deAfis");
  url+="?marca_sel=" + marca;

  dojo.io.bind({url: url,
  				load: function(type, data, evt) {deAfis.innerHTML = data; },
				error: function(type, error) {alert(error.message);},
				mimetype: "text/html"});
}
//INCARCA SUBCATEGORIE
function incarcaSubgrupa(url)
{
  var sel = document.getElementById("grupa");
  var grupa = sel.options[sel.selectedIndex].value;
  var deSubgrupa = document.getElementById("deSubgrupa");
  url+="?sg_sel=" + grupa;

  dojo.io.bind({url: url,
  				load: function(type, data, evt) {deSubgrupa.innerHTML = data; },
				error: function(type, error) {alert(error.message);},
				mimetype: "text/html"});
}
//VALIDARE FORMULAR ADAUGARE ANUNT PIESE
function formValidator(){
	// Make quick references to our fields
	var tip_of = document.getElementById('tip_of');
	var model = document.getElementById('model');
	var modele = document.getElementById('modele');
	var categorie = document.getElementById('categorie');
	var an = document.getElementById('an');
	var titlu_anunt = document.getElementById('titlu_anunt');
	var descriere_anunt = document.getElementById('descriere_anunt');
	var judet = document.getElementById('judet');
	var tel_mob = document.getElementById('tel_mob');	
	var mail = document.getElementById('mail');
	var pret = document.getElementById('pret');
	var moneda = document.getElementById('moneda');
	
   

	// Check each input in the order that it appears in the form!
	if(madeSelection(tip_of, "Nu ati selectat Tipul Ofertei!"))
		if(madeSelection(model, "Nu ati selectat Marca!"))
			if(madeSelection(modele, "Nu ati selectat Modelul!"))
				if(madeSelection(categorie, "Nu ati selectat Categoria!"))
					if(madeSelection(an, "Nu ati selectat Anul de fabricatie!"))
						if(isAlphanumeric(titlu_anunt, "Nu ati introdus titlul anuntului!"))
							if(isTextarea(descriere_anunt, "Nu ati introdus Descrierea Anuntului!"))
						      if(madeSelection(judet, "Nu ati selectat Judetul!"))						
								if(isNumeric(tel_mob, "Nu ati introdus Numarul de telefon!"))
								  if(emailValidator(mail, "Nu ati introdus adresa de mail(Adresa de mail trebuie sa fie valida)!"))
									if(isNumeric(pret, "Nu ati introdus pretul!"))
										if(madeSelection(moneda, "Nu ati selectat moneda!"))
										 return true;

	return false;
}
//VALIDARE FORMULAR CREARE CONT
function formValidatorCont(){
	// Make quick references to our fields
	var utilizator = document.getElementById('utilizator');
	var parola = document.getElementById('parola');
	var re_parola = document.getElementById('re_parola');
	var nume = document.getElementById('nume');
	var zi = document.getElementById('zi');
	var luna = document.getElementById('luna');
	var an = document.getElementById('an');
	var sex = document.getElementById('sex');
	var localitate = document.getElementById('localitate');	
	var judet = document.getElementById('judet');
	var mail = document.getElementById('mail');
	var tel_mob = document.getElementById('tel_mob');
	
   

	// Check each input in the order that it appears in the form!
	if(isAlphanumeric(utilizator, "Nu ati introdus userul!"))
		if(isAlphanumeric(parola, "Nu ati introdus parola!"))
		  if(isPass(re_parola, parola, "Parola repetata nu este identica cu parola!"))
			if(isAlphanumeric(nume, "Nu ati introdus numele!"))
				if(madeSelection(zi, "Nu ati selectat Ziua nasterii!"))
					if(madeSelection(luna, "Nu ati selectat luna nasterii!"))
						if(madeSelection(an, "Nu ati selectat anul nasterii!"))
							if(madeSelection(sex, "Nu ati selectat sexul!"))
						      if(isAlphanumeric(localitate, "Nu ati introdus Localitatea!"))						
								if(madeSelection(judet, "Nu ati selectat Judetul!"))
								  if(emailValidator(mail, "Nu ati introdus adresa de mail(Adresa de mail trebuie sa fie valida)!"))
									if(isNumeric(tel_mob, "Nu ati introdus Numarul de telefon!"))										
								 return true;

	return false;
}
//VALIDARE FORMULAR SCHIMBARE PAROLA
function formSchimbParola(){
	// Make quick references to our fields
	var old_pass = document.getElementById('old_pass');
	var new_pass = document.getElementById('new_pass');
	var re_pass = document.getElementById('re_pass');  

	// Check each input in the order that it appears in the form!
	if(isAlphanumeric(old_pass, "Nu ati introdus parola veche!"))
		if(isAlphanumeric(new_pass, "Nu ati introdus parola noua!"))
		  if(isPass(re_pass, new_pass, "Parola repetata nu este identica cu parola noua!"))
			 return true;

	return false;
}
function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-z A-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9 a-z A-Z\?\!\-\=\_\,\.]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function isTextarea(elem, helperMsg){
	
	if(elem.value != ""){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function isPass(elem, elm2, helperMsg){
	
	if(elem.value == elm2.value){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "no"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function madeSelectionRadio(elem, helper)
{
   if(elem.checked)
	   return true;
   else
   {
      alert(helper);
	  return false;
   }
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
 
		//SFARAIT FORMULAR ADAUGARE ANUNT




