/************************************************************************************
 * Nume proiect:    MagComp
 * Nume script:     get_object.js
 * Descriere:       fisier cu functii AJAX pentru aplicatie
 * Data:            03.11.2006
 * Firma:           SC Codelines 
 * Autor:           Chis Marcel
 * Programare:      JavaScript, AJAX
 ************************************************************************************/

var xmlHttp
var xmlHttpCateg
var xmlHttpSearch

function validSearchForm() {
	real         = /^([0-9\.])+$/
	ctg          = document.getElementById('categorie').selectedIndex
	prd			  = document.getElementById('producator').selectedIndex
	//subctg       = document.src_form.subcategorie.selectedIndex
/*	if (document.getElementById('subcategorie').options[ctg].value != "") {
		alert("Atentie!\nCampul Categorie este obligatoriu!")
		document.getElementById('subcategorie').focus()
		return false
	}*/

	if ((document.getElementById('pret_de_la').value != "") && (!real.test(document.getElementById('pret_de_la').value))) {
		alert("Introduceti cifre pentru Pret de la")
		document.getElementById('pret_de_la').focus()
		return false
	}
	if ((document.getElementById('pret_pana_la').value != "") && (!real.test(document.getElementById('pret_pana_la').value))) {
		alert("Introduceti cifre pentru Pret pana la")
		document.getElementById('pret_pana_la').focus()
		return false
	}
	afiseaza_pagina("content.php?item=search&categorie="+ document.getElementById('categorie').options[ctg].value +"&produs="+ document.getElementById('produs').value  +"&producator="+ document.getElementById('producator').options[prd].value  +"&pret_min="+ document.getElementById('pret_de_la').value +"&pret_max="+ document.getElementById('pret_pana_la').value +"&pg=1")
	return true
}

function validQuickSearchForm() {
	afiseaza_pagina("content.php?item=quick_search&produs="+ document.getElementById('produs').value +"&pg=1")
	return true
}

function sortPret(item,categ,subcateg,pg,order)
{ order = document.getElementById('sort_pret').value
  afiseaza_pagina("content.php?item="+item+"&id_categ="+categ+"&id_subcateg="+subcateg+"&pg="+pg+"&order="+order);
  
}

// formularul de login
function validFormLogin() {
	eml = /^\w+([\.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
	if (!eml.test(document.login_form.email.value)) {
		alert("Adresa email invalida")
		document.login_form.email.focus()
		return false
	}
	if (document.login_form.pass.value == "") {
		alert("Nu ati introdus parola")
		document.login_form.pass.focus()
		return false
	}
	afiseaza_pagina("content.php?item=login&email="+ document.login_form.email.value +"&pass="+ document.login_form.pass.value +"&btn="+ document.login_form.btn.value)
	afiseaza_titlu("");
	return true
}

// formularul de login din continut
function validContentFormLogin() {
	eml = /^\w+([\.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
	
	if (!eml.test(document.getElementById("c_login_form").email.value)) {
	alert("Adresa email invalida")
	document.getElementById("c_login_form").email.focus()
	return false
	}
	
	if (document.getElementById("c_login_form").pass.value == "") {
		alert("Nu ati introdus parola")
		document.getElementById("c_login_form").pass.focus()
		return false
	}
	afiseaza_pagina("content.php?item=login&email="+ document.getElementById("c_login_form").email.value +"&pass="+ document.getElementById("c_login_form").pass.value +"&btn="+ document.getElementById("c_login_form").btn.value)
	return true
	
}

function SendDateFaraAutentificare() {
	
	eml = /^\w+([\.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
	if (!eml.test(document.getElementById("EmailUserNeautentificat").value)) {
	alert("Adresa email invalida")
	document.getElementById("EmailUserNeautentificat").focus()
	return false
	}
	
	afiseaza_pagina("content.php?item=login&email="+ document.getElementById("frmFaraAutentificare").email.value + "&emailuser="+document.getElementById("frmFaraAutentificare").EmailUserNeautentificat.value +"&pass="+ document.getElementById("frmFaraAutentificare").pass.value +"&key="+ document.getElementById("frmFaraAutentificare").key.value +"&btn="+ document.getElementById("frmFaraAutentificare").btn.value)
	return true
}

function validFormContact() {
	eml = /^\w+([\.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
	if (document.frmContactForm.LastName.value == "") {
		alert("Introduceti numele dumneavoastra")
		document.frmContactForm.LastName.focus()
		return false
	}
	if (document.frmContactForm.FirstName.value == "") {
		alert("Introduceti prenumele dumneavoastra")
		document.frmContactForm.FirstName.focus()
		return false
	}
	if (!eml.test(document.frmContactForm.email.value)) {
		alert("Adresa email invalida")
		document.frmContactForm.email.focus()
		return false
	}
	if (document.frmContactForm.message.value == "") {
		alert("Nu ati introdus mesajul dumneavoastra")
		document.frmContactForm.message.focus()
		return false
	}
	afiseaza_pagina("content.php?item=getcontent&job=sendcontact&email="+ document.frmContactForm.email.value +"&message="+ document.frmContactForm.message.value +"&LastName="+ document.frmContactForm.LastName.value +"&FirstName="+ document.frmContactForm.FirstName.value +"&Telephone="+ document.frmContactForm.Telephone.value +"&city="+ document.frmContactForm.city.value +"&profesie="+ document.frmContactForm.profesie.value +"&typeQuery="+ document.frmContactForm.typeQuery.value +"&idmenu="+ document.frmContactForm.idmenu.value)
	return true
}

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=900,height=680,menubar=yes,resizable=yes,status=yes,scrollbars=yes');
return false;
}

// la finalizare comanda
function validFormOrder() {

	
	if (!document.frm_cart.deacord.checked) {
		alert("Nu ati bifat ca ati luat la cunostinta de termenii si conditiile de livrare")
		document.frm_cart.deacord.focus()
		return false
	}
	
	if (document.getElementById('select_group2').checked)
	{
	var nume=document.getElementById('user_nume_liv').value
	var adresa=document.getElementById('user_adresa_liv').value
	var loc=document.getElementById('user_localitate_liv').value
	var judet=document.getElementById('id_judet_liv').value
  var codpostal=document.getElementById('id_judet_liv').value
	var tel=document.getElementById('user_telefon_liv').value
	//modplata = document.frm_cart.mod_plata.options[mpl].value		
		afiseaza_pagina("content.php?item=buy&mod_plata="+ $F('mod_plata')+"&taxa_livrare="+$F('taxa_livrare') + "&usermail="+ document.frm_cart.user_email.value + "&mesaj="+document.frm_cart.mesajclient.value+"&btn="+ document.frm_cart.btn.value+"&nume_livrare="+nume+"&adresa_livrare="+adresa+"&loc_livrare="+loc+"&judet="+judet+"&tel="+tel+"&codpostal="+codpostal)
		
	}
	else {	
	  afiseaza_pagina("content.php?item=buy&mod_plata="+ $F('mod_plata')+"&taxa_livrare="+$F('taxa_livrare') + "&usermail="+ document.frm_cart.user_email.value + "&mesaj="+document.frm_cart.mesajclient.value+"&btn="+ document.frm_cart.btn.value)}
	
	return true
}

// formularul de trimitere parola
function checkSendPass() 
{
	eml = /^\w+([\.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
	if (!eml.test(document.getElementById('email').value)) {
		alert("Adresa email invalida")
		document.send_psv_form.email.focus()
		return false
	}
	afiseaza_pagina("content.php?item=psw&email="+ document.send_psv_form.email.value +"&btn="+ document.send_psv_form.btn.name)
	return true
}

function recalculQuqntity(name, value)
{
	afiseaza_pagina("content.php?item=recalcul&cant_nume="+ name +"&cant_val="+ value)
}

// functie pentru validarea formularului de modificare client logat
function validUpdateLogedClient() {
	real   = /^([0-9\.])+$/
	cifre  = /^(\d)+$/
	cd_jud = /^(\d{6})+$/
	cnp    = /^(\d{13})+$/
	iban   = /^(\w{24})+$/
	eml    = /^\w+([\.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
	if (document.getElementById('user_password').value != document.getElementById('user_confirmed_password').value) {
		alert("Parola introdusa nu este aceeasi cu parola confirmata")
		document.getElementById('user_password').focus()
		document.getElementById('user_password').select()
		return false
	}
	if (!eml.test(document.getElementById('user_email').value)) {
		alert("Adresa email invalida")
		document.getElementById('user_email').focus()
		return false
	}
	if (document.getElementById('user_nume').value == "") {
		alert("Nu ati introdus numele si prenumele de utilizator")
		document.getElementById('user_nume').focus()
		return false
	}
	if (document.getElementById('user_telefon').value == "") {
		alert("Nu ati introdus numarul de telefon")
		document.getElementById('user_telefon').focus()
		return false
	}
	if (!cnp.test(document.getElementById('user_cnp').value)) {
		alert("Codul numeric personal trebuie sa contina 13 cifre");
		document.getElementById('user_cnp').focus();
		return false
	}
/*	usr_tip = -1
	for (i = 0; i < document.getElementById('tip_user').length; i++) {
		if (document.getElementById('tip_user')[i].checked) {
			usr_tip = i
		}
	}
	if (usr_tip == -1) {
		alert("Nu ati selectat tipul de utilizator")
		return false
	}*/
	if (document.getElementById('user_strada').value == "") {
		alert("Adresa dumneavoastra este necesara pentru facturarea produselor comandate. Va rugam introduceti strada, numarul si eventual bloc/apartament")
		document.getElementById('user_strada').focus()
		return false
	}
	if (document.getElementById('user_localitate').value == "") {
		alert("Nu ati introdus localitatea")
		document.getElementById('user_localitate').focus()
		return false
	}
    jd = document.getElementById('id_judet').selectedIndex
	if (document.getElementById('id_judet').options[jd].value == "") {
		alert("Nu ati selectat judetul")
		document.getElementById('id_judet').focus()
		return false
	}
//	if (!cd_jud.test(document.frm_client.user_cod_postal.value)) {
//		alert("Codul postal trebuie sa contina 6 cifre")
//		document.frm_client.user_cod_postal.focus()
//		return false
//	}
/*	if (document.getElementById('tip_user')[usr_tip].value == "2" && document.getElementById('user_firma').value == "") {
		alert("Daca sunteti Firma/Institutie trebuie sa introduceti numele firmei")
		document.getElementById('user_firma').focus()
		return false
	}
	if (document.getElementById('tip_user')[usr_tip].value == "2" && document.getElementById('user_cui').value == "") {
		alert("Daca sunteti Firma/Institutie trebuie sa introduceti CUI firma")
		document.getElementById('user_cui').focus()
		return false
	}
	if (document.getElementById('tip_user')[usr_tip].value == "2" && document.getElementById('user_nr_reg_com').value == "") {
		alert("Daca sunteti Firma/Institutie trebuie introdus numarul din Reg. Com.")
		document.getElementById('user_nr_reg_com').focus()
		return false
	}
	if (document.getElementById('tip_user')[usr_tip].value == "2" && document.getElementById('banca').value == "") {
		alert("Daca sunteti Firma/Institutie introduceti nume Banca/Trezorerie")
		document.getElementById('banca').focus()
		return false
	}
	if (document.getElementById('tip_user')[usr_tip].value == "2" && !iban.test(document.getElementById('user_cont_bancar').value)) {
		alert("Daca sunteti Firma/Institutie trebuie introdus cont IBAN - 24 de caratere (fara spatii)")
		document.getElementById('user_cont_bancar').focus()
		return false
	}*/
	
	return afiseaza_pagina("content.php?action=1&item=upd_account&user_password="+document.getElementById('user_password').value+
	       "&user_email="+document.getElementById('user_email').value+"&user_nume="+document.getElementById('user_nume').value+
	       "&user_telefon="+document.getElementById('user_telefon').value+"&user_cnp="+document.getElementById('user_cnp').value+
	       "&user_strada="+document.getElementById('user_strada').value+"&user_bloc="+document.getElementById('user_bloc').value+
	       "&user_scara="+document.getElementById('user_scara').value+"&user_apartament="+document.getElementById('user_apartament').value+
	       "&user_cod_postal="+document.getElementById('user_cod_postal').value+"&user_nr="+document.getElementById('user_nr').value+
	       "&user_localitate="+document.getElementById('user_localitate').value+"&id_judet="+document.getElementById('id_judet').value+
	       "&user_firma="+document.getElementById('user_firma').value+"&user_cui="+document.getElementById('user_cui').value+
	       "&user_nr_reg_com="+document.getElementById('user_nr_reg_com').value+"&banca="+document.getElementById('banca').value+
	       "&user_cont_bancar="+document.getElementById('user_cont_bancar').value)
}

function afiseaza_pagina(str)
{
    if (str.length == 0) { 
        document.getElementById("content").innerHTML=""
        return
    }
    xmlHttp=incarca_obiectul_XMLHTTP()
    if (xmlHttp == null) {
        alert ("Browserul nu suporta cererile prin AJAX ")
        return
    } 
	var url
    url = str
	url = url + ((url.indexOf('?') + 1) ? '&' : '?')
    url = url + "sid=" + Math.random()
    xmlHttp.onreadystatechange = starea_incarcarii 
    xmlHttp.open("GET", url, true)
    xmlHttp.send(null)
} 

function starea_incarcarii() 
{ 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { 
        document.getElementById("content").innerHTML=xmlHttp.responseText 
    } 
} 

function afiseaza_categ(str)
{
    if (str.length == 0) { 
        document.getElementById("categ").innerHTML=""
        return
    }
    xmlHttpCateg=incarca_obiectul_XMLHTTP()
    if (xmlHttpCateg == null) {
        alert ("Browserul nu suporta cererile prin AJAX ")
        return
    } 
	var url
    url = str
	url = url + ((url.indexOf('?') + 1) ? '&' : '?')
    url = url + "sid=" + Math.random()
    xmlHttpCateg.onreadystatechange = starea_incarcarii_categ 
    xmlHttpCateg.open("GET", url, true)
    xmlHttpCateg.send(null)
} 

function starea_incarcarii_categ() 
{ 
    if (xmlHttpCateg.readyState == 4 || xmlHttpCateg.readyState == "complete") { 
        document.getElementById("categ").innerHTML=xmlHttpCateg.responseText 
    } 
}

function afiseaza_meniu(str)
{
    if (str.length == 0) { 
        document.getElementById("menu").innerHTML=""
        return
    }
    xmlHttpCateg=incarca_obiectul_XMLHTTP()
    if (xmlHttpCateg == null) {
        alert ("Browserul nu suporta cererile prin AJAX ")
        return
    } 
	var url
    url = str
	url = url + ((url.indexOf('?') + 1) ? '&' : '?')
    url = url + "sid=" + Math.random()
    xmlHttpCateg.onreadystatechange = starea_incarcarii_meniu 
    xmlHttpCateg.open("GET", url, true)
    xmlHttpCateg.send(null)
} 

function starea_incarcarii_meniu() 
{ 
    if (xmlHttpCateg.readyState == 4 || xmlHttpCateg.readyState == "complete") { 
        document.getElementById("menu").innerHTML=xmlHttpCateg.responseText 
    } 
}

function afiseaza_cart(str)
{
    if (str.length == 0) { 
        document.getElementById("cart").innerHTML=""
        return
    }
    xmlHttpCateg=incarca_obiectul_XMLHTTP()
    if (xmlHttpCateg == null) {
        alert ("Browserul nu suporta cererile prin AJAX ")
        return
    } 
	var url
    url = str
	url = url + ((url.indexOf('?') + 1) ? '&' : '?')
    url = url + "sid=" + Math.random()
    xmlHttpCateg.onreadystatechange = starea_incarcarii_cart 
    xmlHttpCateg.open("GET", url, true)
    xmlHttpCateg.send(null)
} 

function starea_incarcarii_cart() 
{ 
    if (xmlHttpCateg.readyState == 4 || xmlHttpCateg.readyState == "complete") { 
        document.getElementById("cart").innerHTML=xmlHttpCateg.responseText 
    } 
}

function afiseaza_search(str)
{
    if (str.length == 0) { 
        document.getElementById("search").innerHTML=""
        return
    }
    xmlHttpSearch=incarca_obiectul_XMLHTTP()
    if (xmlHttpSearch == null) {
        alert ("Browserul nu suporta cererile prin AJAX ")
        return
    } 
	var url
    url = str
	url = url + ((url.indexOf('?') + 1) ? '&' : '?')
    url = url + "sid=" + Math.random()
    xmlHttpSearch.onreadystatechange = starea_incarcarii_search 
    xmlHttpSearch.open("GET", url, true)
    xmlHttpSearch.send(null)
} 

function starea_incarcarii_search() 
{ 
    if (xmlHttpCateg.readyState == 4 || xmlHttpSearch.readyState == "complete") { 
        document.getElementById("search").innerHTML=xmlHttpCateg.responseText 
    } 
}

function incarca_obiectul_XMLHTTP()
{
    var cerere_http=null;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        cerere_http=new XMLHttpRequest();
        if (cerere_http.overrideMimeType) {
            cerere_http.overrideMimeType('text/xml'); 
        }
    } else if (window.ActiveXObject) { // IE
        try {
            cerere_http=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                cerere_http=new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {} 
        } 
    }
 
    if (!cerere_http) {
        alert('Nu se poate initializa obiectul XMLHTTP');
        return false; 
    } else {
        return cerere_http;
    }
}





function afiseaza_titlu(str)
{
    if (str.length == 0) { 
        document.getElementById("titlucon").innerHTML=""
        return
    }
    xmlHttpTitle=incarca_obiectul_XMLHTTP()
    if (xmlHttpTitle == null) {
        alert ("Browserul nu suporta cererile prin AJAX ")
        return
    } 
	var url
    url = str
	url = url + ((url.indexOf('?') + 1) ? '&' : '?')
    url = url + "sid=" + Math.random()
    xmlHttpTitle.onreadystatechange = starea_incarcarii_title 
    xmlHttpTitle.open("GET", url, true)
    xmlHttpTitle.send(null)
} 
function starea_incarcarii_title() 
{ 
    if (xmlHttpTitle.readyState == 4 || xmlHttpTitle.readyState == "complete") { 
        document.getElementById("titlucon").innerHTML=xmlHttpTitle.responseText 
    } 
} 


function afiseaza_login(str)
{
    if (str.length == 0) { 
        document.getElementById("titluc").innerHTML=""
        return
    }
    xmlHttpTitle=incarca_obiectul_XMLHTTP()
    if (xmlHttpTitle == null) {
        alert ("Browserul nu suporta cererile prin AJAX ")
        return
    } 
    
    var url = str
	//url = url + ((url.indexOf('?') + 1) ? '&' : '?')
	url =url + "&user="+$F('email')+"&pass="+$('pass').value; 
    $('login').setStyle({marginBottom: '60px'});


    xmlHttpTitle.onreadystatechange = login_menu 
    xmlHttpTitle.open("GET", url, true)
    xmlHttpTitle.send(null)
} 

function login_menu() 
{ 
    if (xmlHttpTitle.readyState == 4 || xmlHttpTitle.readyState == "complete") { 
        document.getElementById("login").innerHTML=xmlHttpTitle.responseText 
    } 
} 

function sendComment(id)
{
  var nume=document.getElementById('nume'+id).value
  var locatie=document.getElementById('locatie'+id).value  
  var mesaj=document.getElementById('mesaj'+id).value  
  
  if ((nume != '') && (mesaj != ''))
  {
  alert("Multumim! Comentariu a fost trimis cu sucess.") 
  afiseaza_pagina("content.php?item=send_comment&id="+id+"&nume="+nume+"&locatie="+locatie+"&mesaj="+mesaj)
  }
  else {alert('Va rugam complectati campurile nume si mesaj!')}
}

function doSerialization (){
 if ($F('latime') == 0){
   alert('Selectati latimea materialului!')
   $('latime').focus();
   return false
  }

  if ($F('inaltime') == 0){
    alert('Introduceti inaltimea  materialului!')
    $('inaltime').focus();
    return false
  }

  if ($F('ramase') > 0){
    alert('Numarul lamelelor selectate trebuie sa fie egal cu cel calculat!')
    return false
   }

  if ($F('ramase') > 0){
    alert('Numarul lamelelor selectate trebuie sa fie egal cu cel calculat!')
    return false
   }

  if (($F('cantitate') == '') || ($F('cantitate') == 0)){
     alert('Va rugam introduceti cantitatea dorita!')
     $('cantitate').focus();
     return false
  }

  link = $('comanda').serialize();
  afiseaza_pagina("content.php?item=add&"+link);
  return true;
}

function doSerializationSina (){
 if ($F('latime') == 0){
   alert('Selectati lungimea dorita!')
   $('latime').focus();
   return false
  }
 
  if (($F('cantitate') == '') || ($F('cantitate') == 0)){
     alert('Va rugam introduceti cantitatea dorita!')
     $('cantitate').focus();
     return false
  }
  
  link = $('comanda').serialize();
  afiseaza_pagina("content.php?item=add&"+link);
  return true;
  
}

function doSerializationFix(){
 
  if (($F('cantitate') == '') || ($F('cantitate') == 0)){
     alert('Va rugam introduceti cantitatea dorita!')
     $('cantitate').focus();
     return false
  }
  
  link = $('comanda').serialize();
  afiseaza_pagina("content.php?item=add&"+link);
  return true;
  
}

function doSerializationRulouri (){
 if ($F('latime') == 0){
   alert('Selectati latimea materialului!')
   $('latime').focus();
   return false
  }

  if ($F('inaltime') == 0){
    alert('Introduceti inaltimea  materialului!')
    $('inaltime').focus();
    return false
  }

  if (($F('cantitate') == '') || ($F('cantitate') == 0)){
     alert('Va rugam introduceti cantitatea dorita!')
     $('cantitate').focus();
     return false
  }

  link = $('comanda').serialize();
  afiseaza_pagina("content.php?item=add&"+link);
  return true;
}


// functie pentru validarea formularului de inregistrare client pentru login
function validRegisterClient() {
	real   = /^([0-9\.])+$/
	cifre  = /^(\d)+$/
	cd_jud = /^(\d{6})+$/
	cnp    = /^(\d{13})+$/
	iban   = /^(\w{24})+$/
	eml    = /^\w+([\.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
	if (document.frm_client.user_password.value == "") {
		alert("Trebuie sa introduceti noua parola trimisa pentru a va autentifica")
		document.frm_client.user_password.focus()
		return false
	}
	if (document.frm_client.user_password.value != document.frm_client.user_confirmed_password.value) {
		alert("Parola introdusa nu este aceeasi cu parola confirmata")
		document.frm_client.user_password.focus()
		document.frm_client.user_password.select()
		return false
	}
	if (!eml.test(document.frm_client.user_email.value)) {
		alert("Adresa email invalida")
		document.frm_client.user_email.focus()
		return false
	}
	if (document.frm_client.user_nume.value == "") {
		alert("Nu ati introdus numele si prenumele dumneavoastra")
		document.frm_client.user_nume.focus()
		return false
	}
	if (document.frm_client.user_telefon.value == "") {
		alert("Nu ati introdus numarul de telefon")
		document.frm_client.user_telefon.focus()
		return false
	}
	if (!cnp.test(document.frm_client.user_cnp.value)) {
		alert("Codul numeric personal este necesar pentru facturarea unui produs si trebuie sa contina 13 cifre")
		document.frm_client.user_cnp.focus()
		return false
	}
	usr_tip = -1
	for (i = 0; i < document.frm_client.tip_user.length; i++) {
		if (document.frm_client.tip_user[i].checked) {
			usr_tip = i
		}
	}
	if (usr_tip == -1) {
		alert("Nu ati selectat tipul de utilizator")
		return false
	}
	if (document.frm_client.user_strada.value == "") {
		alert("Adresa dumneavoastra este necesara pentru facturarea produselor comandate. Va rugam introduceti strada, numarul si eventual bloc/apartament")
		document.frm_client.user_strada.focus()
		return false
	}

	if (document.frm_client.user_localitate.value == "") {
		alert("Nu ati introdus localitatea")
		document.frm_client.user_localitate.focus()
		return false
	}
    jd = document.frm_client.id_judet.selectedIndex
	if (document.frm_client.id_judet.options[jd].value == "") {
		alert("Nu ati selectat judetul")
		document.frm_client.id_judet.focus()
		return false
	}


	if (document.frm_client.tip_user[usr_tip].value == "2" && document.frm_client.user_firma.value == "") {
		alert("Daca sunteti Firma/Institutie trebuie sa introduceti numele firmei")
		document.frm_client.user_firma.focus()
		return false
	}
	if (document.frm_client.tip_user[usr_tip].value == "2" && document.frm_client.user_cui.value == "") {
		alert("Daca sunteti Firma/Institutie trebuie sa introduceti CUI")
		document.frm_client.user_cui.focus()
		return false
	}
	if (document.frm_client.tip_user[usr_tip].value == "2" && document.frm_client.user_nr_reg_com.value == "") {
		alert("Daca sunteti Firma/Institutie trebuie introdus numarul de inregistrare Reg. Com.")
		document.frm_client.user_nr_reg_com.focus()
		return false
	}

    link = $('frm_client').serialize();
    afiseaza_pagina("content.php?item=register&"+link);
	return true
}

// functie pentru validarea formularului de inregistrare client pentru login
function validUpdateLogedClient() {
	real   = /^([0-9\.])+$/
	cifre  = /^(\d)+$/
	cd_jud = /^(\d{6})+$/
	cnp    = /^(\d{13})+$/
	iban   = /^(\w{24})+$/
	eml    = /^\w+([\.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/
	if (document.frm_client.user_password.value == "") {
		alert("Trebuie sa introduceti noua parola trimisa pentru a va autentifica")
		document.frm_client.user_password.focus()
		return false
	}
	if (document.frm_client.user_password.value != document.frm_client.user_confirmed_password.value) {
		alert("Parola introdusa nu este aceeasi cu parola confirmata")
		document.frm_client.user_password.focus()
		document.frm_client.user_password.select()
		return false
	}
	if (!eml.test(document.frm_client.user_email.value)) {
		alert("Adresa email invalida")
		document.frm_client.user_email.focus()
		return false
	}
	if (document.frm_client.user_nume.value == "") {
		alert("Nu ati introdus numele si prenumele dumneavoastra")
		document.frm_client.user_nume.focus()
		return false
	}
	if (document.frm_client.user_telefon.value == "") {
		alert("Nu ati introdus numarul de telefon")
		document.frm_client.user_telefon.focus()
		return false
	}
	if (!cnp.test(document.frm_client.user_cnp.value)) {
		alert("Codul numeric personal este necesar pentru facturarea unui produs si trebuie sa contina 13 cifre")
		document.frm_client.user_cnp.focus()
		return false
	}
	usr_tip = -1
	for (i = 0; i < document.frm_client.tip_user.length; i++) {
		if (document.frm_client.tip_user[i].checked) {
			usr_tip = i
		}
	}
	if (usr_tip == -1) {
		alert("Nu ati selectat tipul de utilizator")
		return false
	}
	if (document.frm_client.user_strada.value == "") {
		alert("Adresa dumneavoastra este necesara pentru facturarea produselor comandate. Va rugam introduceti strada, numarul si eventual bloc/apartament")
		document.frm_client.user_strada.focus()
		return false
	}

	if (document.frm_client.user_localitate.value == "") {
		alert("Nu ati introdus localitatea")
		document.frm_client.user_localitate.focus()
		return false
	}
    jd = document.frm_client.id_judet.selectedIndex
	if (document.frm_client.id_judet.options[jd].value == "") {
		alert("Nu ati selectat judetul")
		document.frm_client.id_judet.focus()
		return false
	}


	if (document.frm_client.tip_user[usr_tip].value == "2" && document.frm_client.user_firma.value == "") {
		alert("Daca sunteti Firma/Institutie trebuie sa introduceti numele firmei")
		document.frm_client.user_firma.focus()
		return false
	}
	if (document.frm_client.tip_user[usr_tip].value == "2" && document.frm_client.user_cui.value == "") {
		alert("Daca sunteti Firma/Institutie trebuie sa introduceti CUI")
		document.frm_client.user_cui.focus()
		return false
	}
	if (document.frm_client.tip_user[usr_tip].value == "2" && document.frm_client.user_nr_reg_com.value == "") {
		alert("Daca sunteti Firma/Institutie trebuie introdus numarul de inregistrare Reg. Com.")
		document.frm_client.user_nr_reg_com.focus()
		return false
	}

    link = $('frm_client').serialize();
    afiseaza_pagina("content.php?item=upd_account&"+link);
	return true
}

function getTax(){
var url = 'content.php?item=taxa_livrare&id_curier='+$F('mod_livrare');
// notice the use of a proxy to circumvent the Same Origin Policy.

new Ajax.Request(url, {
  method: 'get',
  onSuccess: function(transport) {
   if ($F('mod_livrare') != ''){
    $('taxe').innerHTML = transport.responseText;
    }else {
        $('taxe').innerHTML = "" ;
    }
   }
});


}
