function shop_favorites(IDitem) {
	var url = emd_adr_http+'_ajax/shop_favorites.php';
	var params = 'IDitem='+IDitem;
	var ajax = new Ajax.Updater(
	{success: 'shop_favorites_'+IDitem},
	url,
	{method: 'get', parameters: params, onFailure: domError});
}

function shop_cart (IDedit, IDdel, IDadd) {
	var url = emd_adr_http+'_ajax/shop_cart.php';
	var params;
	if (IDedit>0) {
		var cart_field='pcs'+IDedit;
		var cart_pcs=document.getElementById(cart_field).value;
		params = 'IDedit='+IDedit+'&pcs='+cart_pcs;
		//alert (params);
	} else if (IDdel>0) {
		params = 'IDdel='+IDdel;
		//alert (params);
	} else if (IDadd>0) {
		var shop_add_nr=document.getElementById('shop_add_nr_'+IDadd).value;
		params = 'IDadd='+IDadd+'&shop_add_nr='+shop_add_nr;
	}

	new Ajax.Request(url,
	  {
		method:'get', 
		parameters: params, 
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		  var responses=response.split('<delimiter>');
		  if (document.getElementById('shop_main_cart')) { 
			document.getElementById('shop_main_cart').innerHTML=responses[1]; 
		  }
		  document.getElementById('shop_cart_container').innerHTML=responses[0]; 
		  if (IDadd>0) {
		  	document.getElementById('shop_add_containter_'+IDadd).innerHTML='Produsul a fost adaugat in <a href="'+emd_adr_http+'cos">cosul de cumparaturi</a>.';
			//
			GB_ESTD_OCC = true;
			GB_ESTD_RELOAD = false;
			GB_showCenter('Confirmare',emd_adr_sfs+'_includes/grey-cos-conf.php?IDadd='+IDadd,255,400);
		  }
		  //alert("Success! \n\n" + response);
		},
		onFailure: domError
	  });
}


function shop_delivery(cc) {
	var url = emd_adr_http+'_ajax/shop_delivery.php';
	var params = 'cc='+cc;
	
	if (cc>0) {
		//var cart_IDcounty=$('cart_IDcounty').serialize();
		if (document.getElementById('cart_IDcounty')) {
			var cart_IDcounty=$('cart_IDcounty').serialize();
		} else {
			var cart_IDcounty='cart_IDcounty=';
		}

		if (cc==1) {
			var cart_IDcity='cart_IDcity=0';
		} else {
			if (document.getElementById('cart_IDcity')) {
				var cart_IDcity=$('cart_IDcity').serialize();
			} else {
				var cart_IDcity='cart_IDcity=';
			}
		}
		params+='&'+cart_IDcounty+'&'+cart_IDcity;
	}

	var ajax = new Ajax.Updater(
	{success: 'shop_delivery'},
	url,
	{method: 'get', parameters: params, onFailure: domError});
}

function user_check() {
	
	var url = emd_adr_http+'_ajax/user_check.php';
	var ju=document.getElementById('join_user').value;
	var params = 'join_user='+ju;
	new Ajax.Request(url,
	  {
		method:'get', 
		parameters: params, 
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		  var responses=response.split('|');
		  document.getElementById('join_user_ok').value=responses[1];
		  document.getElementById('user_check_answer').innerHTML=responses[0];
		},
		onFailure: domError
	  });
}

function email_check(jemail) {
	

	var url = emd_adr_http+'_ajax/email_check.php';
	//var je=document.getElementById('cart_u_email').value;
	var params = 'join_email='+jemail;
	new Ajax.Request(url,
	  {
		method:'get', 
		parameters: params, 
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		  var responses=response.split('|');
		  document.getElementById('join_email_ok').value=responses[1];
		  document.getElementById('email_check_answer').innerHTML=responses[0];
		},
		onFailure: domError
	  });


}

function email_check2(uemail, IDuser) {
	
	var url = emd_adr_http+'_ajax/email_check2.php';
	//var je=document.getElementById('cart_u_email').value;
	var params = 'edit_email='+uemail+'&IDuser='+IDuser;
	new Ajax.Request(url,
	  {
		method:'get', 
		parameters: params, 
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		  var responses=response.split('|');
		  document.getElementById('cart_u_email_ok').value=responses[1];
		  document.getElementById('email_check_answer').innerHTML=responses[0];
		},
		onFailure: domError
	  });
}
 
function email_check3(uemail, IDuser) {
	
	var url = emd_adr_http+'_ajax/email_check2.php';
	//var je=document.getElementById('cart_u_email').value;
	var params = 'edit_email='+uemail+'&IDuser='+IDuser;
	new Ajax.Request(url,
	  {
		method:'get', 
		parameters: params, 
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		  var responses=response.split('|');
		  document.getElementById('edit_email_ok').value=responses[1];
		  document.getElementById('email_check_answer').innerHTML=responses[0];
		},
		onFailure: domError
	  });
}

function domError() {
	alert("eroare");
}

function chFormEditAccount(edit_form)
{

	if (edit_form.edit_email_ok.value==-1) {
		edit_form.edit_submit.focus();
		return false;
	}

    if(edit_form.edit_name.value=="") {
        edit_form.edit_name.focus();
        edit_form.edit_name.style.borderColor='#F2797C';
        alert ("Introdu numele tau!");
        return false;
    }

    if(edit_form.edit_email.value==""){
        edit_form.edit_email.focus();
        edit_form.edit_email.style.borderColor='#F2797C';
        alert ("Introdu adresa ta de email!");
    return false;}

    if(edit_form.edit_email.value!=""){
        if(edit_form.edit_email.value.length < 6){
            edit_form.edit_email.focus();
            edit_form.edit_email.style.borderColor='#F2797C';
            alert ("Adresa de email introdusa nu e valida!");
            return false;}

        if(edit_form.edit_email.value.length > 49){
            edit_form.edit_email.focus();
            edit_form.edit_email.style.borderColor='#F2797C';
            alert ("Adresa de email introdusa nu e valida!");
            return false;}

        if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(edit_form.edit_email.value))){
            edit_form.edit_email.focus();
            edit_form.edit_email.style.borderColor='#F2797C';
            alert ("Adresa de email introdusa nu e valida!");
            return false;}

        if(edit_form.edit_email_ok.value!="1"){
            edit_form.edit_email.focus();
            edit_form.edit_email.style.borderColor='#F2797C';
            alert ("Emailul introdus este deja in uz!");
        return false;}
    }
}


function chFormCartDet(join_form) {
   if(join_form.cart_u_name.value=="") {

        join_form.cart_u_name.focus();

        join_form.cart_u_name.style.borderColor='#F2797C';

        alert ("Introdu numele tau!");

        return false;

    }
    

    if(join_form.cart_u_phone.value=="") {

        join_form.cart_u_phone.focus();

        join_form.cart_u_phone.style.borderColor='#F2797C';

        alert ("Introdu numarul tau de telefon!");

        return false;

    }



    if(join_form.cart_u_email.value==""){

        join_form.cart_u_email.focus();

        join_form.cart_u_email.style.borderColor='#F2797C';

        alert ("Introdu adresa ta de email!");

    return false;}
    

    if(join_form.cart_u_email.value!=""){

        if(join_form.cart_u_email.value.length < 6){

            join_form.cart_u_email.focus();

            join_form.cart_u_email.style.borderColor='#F2797C';

            alert ("Adresa de email introdusa nu e valida!");

            return false;}


        if(join_form.cart_u_email.value.length > 49){

            join_form.cart_u_email.focus();

            join_form.cart_u_email.style.borderColor='#F2797C';

            alert ("Adresa de email introdusa nu e valida!");

            return false;}

 

        if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(join_form.cart_u_email.value))){

            join_form.cart_u_email.focus();

            join_form.cart_u_email.style.borderColor='#F2797C';

            alert ("Adresa de email introdusa nu e valida!");

            return false;}


        if(join_form.cart_u_email_ok.value=="0") {

            join_form.cart_u_email.focus();

            join_form.cart_u_email.style.borderColor='#F2797C';

            alert ("Emailul introdus este deja in uz!");

        return false;}
    }

	if (join_form.cart_it[0].checked) {
		if (join_form.cart_p_ids.value=="") {
			join_form.cart_p_ids.focus();	
			join_form.cart_p_ids.style.borderColor='#F2797C';
			alert ("Introdu seria actului de identitate!");
			return false;
		}
		var v = join_form.cart_p_ids.value;
		var rx = new RegExp("^[A-Z]{2}$","g");
		if ( !(rx.test(v)) ) {
			alert("Serie BI/CI este introdusa gresit!");
			join_form.cart_p_ids.focus();
			join_form.cart_p_ids.style.borderColor='#F2797C';
			return false;
		}

		if (join_form.cart_p_idn.value=="") {
			join_form.cart_p_idn.focus();
			join_form.cart_p_idn.style.borderColor='#F2797C';
			alert ("Introdu numarul actului de identitate!");
			return false;
		}
		var v = join_form.cart_p_idn.value;
		var rx = new RegExp("^\\d{6}$","g");
		if ( !(rx.test(v)) ) {
			alert("Numar BI/CI este introdus gresit!");
			join_form.cart_p_idn.focus();
			join_form.cart_p_idn.style.borderColor='#F2797C';
			return false;
		}
	}

	if (join_form.cart_it[1].checked) {
		if(join_form.cart_c_name.value=="") {
			join_form.cart_c_name.focus();
			join_form.cart_c_name.style.borderColor='#F2797C';
			alert ("Introdu numele persoanei juridice!");
			return false;
		}
		
		if(join_form.cart_c_cui.value=="") {
			join_form.cart_c_cui.focus();
			join_form.cart_c_cui.style.borderColor='#F2797C';
			alert ("Introdu cod fiscal / CUI!");
			return false;
		}
		
		var v = join_form.cart_c_cui.value;
		var rx1 = new RegExp("^\\d{7}$","g");
		var rx2 = new RegExp("^RO\\d{7,8}$", "g");
		if ( !(rx1.test(v) || rx2.test(v)) ) {
			alert("Cod fiscal / CUI este introdus gresit!");
			join_form.cart_c_cui.focus();
			join_form.cart_c_cui.style.borderColor='#F2797C';
			return false;
		}
		
		if (join_form.cart_c_bank.value=="") {
			join_form.cart_c_bank.focus();	
			join_form.cart_c_bank.style.borderColor='#F2797C';
			alert ("Introdu numele bancii!");
			return false;
		}
		
		var v = join_form.cart_c_regcom.value;
		var rx = new RegExp("^J\\d{2}/\\d{3,5}/\\d{4}$", "g");
		if ( !(rx.test(v)) ) {
			alert("Nr. inreg la registrul comertului este introdus gresit!");
			join_form.cart_c_regcom.focus();
			join_form.cart_c_regcom.style.borderColor='#F2797C';
			return false;
		}
		
		var v = join_form.cart_c_account.value;
		var rx = new RegExp("^RO\\d{2}[A-Z]{4}[0-9A-Z]{16}$", "g");
		if ( !(rx.test(v)) ) {
			alert("Contul este introdus gresit!");
			join_form.cart_c_account.focus();
			join_form.cart_c_account.style.borderColor='#F2797C';
			return false;
		}
	}
}

function chFormJoin(join_form)
{

	if (join_form.join_email_ok.value==-1 || join_form.join_user_ok.value==-1) {
		join_form.join_submit.focus();
		return false;
	}

    if(join_form.join_name.value=="") {
        join_form.join_name.focus();
        join_form.join_name.style.borderColor='#F2797C';
        alert ("Introdu numele tau!");
        return false;
    }
    
    if(join_form.join_email.value==""){
        join_form.join_email.focus();
        join_form.join_email.style.borderColor='#F2797C';
        alert ("Introdu adresa ta de email!");
    return false;}
    
    if(join_form.join_email.value!=""){
        if(join_form.join_email.value.length < 6){
            join_form.join_email.focus();
            join_form.join_email.style.borderColor='#F2797C';
            alert ("Adresa de email introdusa nu e valida!");
            return false;}

        if(join_form.join_email.value.length > 49){
            join_form.join_email.focus();
            join_form.join_email.style.borderColor='#F2797C';
            alert ("Adresa de email introdusa nu e valida!");
            return false;}

        if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(join_form.join_email.value))){
            join_form.join_email.focus();
            join_form.join_email.style.borderColor='#F2797C';
            alert ("Adresa de email introdusa nu e valida!");
            return false;}
    
        if(join_form.join_email_ok.value!="1"){
            join_form.join_email.focus();
            join_form.join_email.style.borderColor='#F2797C';
            alert ("Emailul introdus este deja in uz!");
        return false;}

    }

    if(join_form.join_user.value==""){
        join_form.join_user.focus();
        join_form.join_user.style.borderColor='#F2797C';
        alert ("Introdu utilizatorul dorit!");
    return false;}

    //alert(join_form.join_user_ok);
    
    if(join_form.join_user_ok.value!="1"){
        join_form.join_user.focus();
        join_form.join_user.style.borderColor='#F2797C';
        alert ("Utilizatorul dorit nu este disponibil!");
    return false;}

    if(join_form.join_pass.value==""){
        join_form.join_pass.focus();
        join_form.join_pass.style.borderColor='#F2797C';
        alert ("Introdu parola dorita!");
    return false;}

    if(join_form.join_pass2.value==""){
        join_form.join_pass2.focus();
        join_form.join_pass2.style.borderColor='#F2797C';
        alert ("Introdu confirmarea parolei!");
    return false;}

    if(join_form.join_pass.value!=join_form.join_pass2.value){
        join_form.join_pass2.focus();
        join_form.join_pass2.style.borderColor='#F2797C';
        alert ("Parola nu este corect confirmata!");
    return false;}

}

    function chFormRecUser(form)
    {
        if(form.recovery_user.value=="") {
            form.recovery_user.focus();
            form.recovery_user.style.borderColor='#F2797C';
            alert ("Introdu numele de utilizator!");
            return false;
        }
   
        if(form.recovery_pass.value==""){
            form.recovery_pass.focus();
            form.recovery_pass.style.borderColor='#F2797C';
            alert ("Introdu parola dorita!");
        return false;}
    
        if(form.recovery_pass2.value==""){
            form.recovery_pass2.focus();
            form.recovery_pass2.style.borderColor='#F2797C';
            alert ("Introdu confirmarea parolei!");
        return false;}

        if(form.recovery_pass.value!=form.recovery_pass2.value){
           form.recovery_pass2.focus();
            form.recovery_pass2.style.borderColor='#F2797C';
            alert ("Parola nu este corect confirmata!");
        return false;}
    }

    function chFormRecEmail(form)
    {
        if(form.recovery_email.value=="") {
            form.recovery_email.focus();
            form.recovery_email.style.borderColor='#F2797C';
            alert ("Introdu adresa de email!");
            return false;
        }

        if(form.recovery_pass.value==""){
            form.recovery_pass.focus();
            form.recovery_pass.style.borderColor='#F2797C';
            alert ("Introdu parola dorita!");
        return false;}
    
        if(form.recovery_pass2.value==""){
            form.recovery_pass2.focus();
            form.recovery_pass2.style.borderColor='#F2797C';
            alert ("Introdu confirmarea parolei!");
        return false;}
 
        if(form.recovery_pass.value!=form.recovery_pass2.value){
            form.recovery_pass2.focus();
            form.recovery_pass2.style.borderColor='#F2797C';
            alert ("Parola nu este corect confirmata!");
        return false;}
    }

function chFormEditPass(pass_form)
{
	
        if(pass_form.old_pass.value==""){
            pass_form.old_pass.focus();
            pass_form.old_pass.style.borderColor='#F2797C';
            alert ("Introdu parola veche!");
        return false;}

        if(pass_form.new_pass.value==""){
            pass_form.new_pass.focus();
            pass_form.new_pass.style.borderColor='#F2797C';
            alert ("Introdu parola noua!");
        return false;}

        if(pass_form.new_pass2.value==""){
            pass_form.new_pass2.focus();
            pass_form.new_pass2.style.borderColor='#F2797C';
            alert ("Introdu confirmarea parolei!");
        return false;}
    
        if(pass_form.new_pass.value!=pass_form.new_pass2.value){
            pass_form.new_pass2.focus();
            pass_form.new_pass2.style.borderColor='#F2797C';
            alert ("Parola nu este corect confirmata!");
        return false;}

}

function estd_open_gb (caption, url) {
	
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

	GB_showCenter(caption,url,myHeight-100,940);
}



// centering the images
function center_img(containerID, imgID) {
	if ( $(containerID)==null || $(imgID)==null )
		return false;
	
	var div_w = $(containerID).getWidth();
	var div_h = $(containerID).getHeight();
	var img_w = $(imgID).getWidth();
	var img_h = $(imgID).getHeight();
	$(imgID).style.marginLeft = ((div_w-img_w)/2)+'px';
	$(imgID).style.marginTop = ((div_h-img_h)/2)+'px';
	//alert(img_w + ':' + img_h);
	return true;
}

function getYMstat() {
	var url = emd_adr_http+'_ajax/general.php';
	var params = '';
	new Ajax.Request(url,
	{
		method:'get', 
		parameters: params, 
		onSuccess: function(transport){
			var response = transport.responseText;
			document.getElementById('YM').innerHTML += response;
		},
		onFailure: domError
	});
}
