openmenus = new Array();
tickerTimer = null;
tickerStep = 139;
tickerPosition = 0;
tickerShown = 5;

function change_manufacturer(manufacturer) {
    document.getElementById('products').options.length = 0;

    newoption = document.createElement('option');
    newoption.value = 0;
    newoption.appendChild(document.createTextNode('Alegeti un produs...'));
    document.getElementById('products').appendChild(newoption);

    for(var id in products) {
        if((manufacturer == 0) || (products[id][0] == manufacturer)) {
            newoption = document.createElement('option');
            newoption.value = id;

            if(manufacturer == 0) {
                newoption.appendChild(document.createTextNode(manufacturers[products[id][0]] + ' ' + products[id][1]));
            }
            else {
                newoption.appendChild(document.createTextNode(products[id][1]));
            }

            document.getElementById('products').appendChild(newoption);
        }
    }
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode != 8 && (charCode > 31 && (charCode < 48 || charCode > 57)) ) {
        return false;
    }
    return true;
}

function isAlphaKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (!((charCode >=65 && charCode <= 90) || (charCode >=97 && charCode <= 122) || (charCode == 32) || (charCode == 8)  || (charCode == 45) )) {
        return false;
    }
    return true;
}

function focus(targetId) {
    document.getElementById(targetId).focus();
}

function toggle(targetId) {
    if (document.getElementById) {
        target = document.getElementById(targetId);
        if (target.style.display == "block") {
            target.style.display = "none";
        }
        else {
            target.style.display = "block";
        }
    }
}

function setState(which, state) {
    document.getElementById(which).style.display = state;
    if (self["timer"+which]!=null) clearTimeout(self["timer"+which]);
}

function checkValid(id, msg, regula, valoare) {
    var prefix = "* ";
    var suffix = "\n";

    switch(regula) {
        case 'required':
                        if (document.getElementById(id).value=="") {
                            return prefix+msg+suffix;
                        }
                        break;
        case 'select':
                        if (document.getElementById(id).options[document.getElementById(id).selectedIndex].value=="") {
                            return prefix+msg+suffix;
                        }
                        break;
        case 'numeric':
                        var validch = "0123456789.-";
                        var isNumber=true;
                        var ch;
                        var val = document.getElementById(id).value;
                        for (i=0; i<val.length && isNumber == true; i++) {
                            ch = val.charAt(i);
                            if (validch.indexOf(ch) == -1) {
                                return prefix+msg+suffix;
                            }
                        }
                        break;
        case 'email':
                        var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
                        if (!filter.test(document.getElementById(id).value)) {
                            return prefix+msg+suffix;
                        }
                        break;
        case 'integer':
                        var validch = "0123456789";
                        var isNumber=true;
                        var ch;
                        var val = document.getElementById(id).value;
                        for (i=0; i<val.length && isNumber == true; i++) {
                            ch = val.charAt(i);
                            if (validch.indexOf(ch) == -1) {
                                return prefix+msg+suffix;
                            }
                        }
                        break;
        case 'limitpercent':
                        if (document.getElementById(id).value<0 || document.getElementById(id).value>100) {
                            return prefix+msg+suffix;
                        }
                        break;
        case 'notzero':
                        if (document.getElementById(id).value==0) {
                            return prefix+msg+suffix;
                        }
                        break;
        case 'date':
                        msg = isDate(document.getElementById(id).value);
                        if (msg != "0") {
                            return prefix+msg+suffix;
                        }
                        break;
        case 'lessthan':
                        if (document.getElementById(id).value > valoare) {
                            return prefix+msg+suffix;
                        }
                        break;
        case 'equals':
                if (document.getElementById(id).value != valoare) {
                    return prefix+msg+suffix;
                }
                break;
    }
    return "";
}

// form validation
function checkRegistration() {
	
    msg = checkValid('firstname', 'Completati prenumele', 'required');
    msg += checkValid('lastname', 'Completati numele', 'required');
    msg += checkValid('telephone', 'Completati numarul de telefon', 'required');
    msg += checkValid('regemail', 'Completati adresa de e-mail', 'required');
    if(document.getElementById('email').value != '') {
        msg += checkValid('regemail', 'Introduceti o adresa valida de e-mail', 'email');
    }
    msg += checkValid('regpassword', 'Completati parola', 'required');

    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
        return true;
    }
}

function checkLogin() {
    msg = checkValid('password', 'Completati parola', 'required');
    msg += checkValid('email', 'Completati adresa de e-mail', 'required');
    if(document.getElementById('email').value != '') {
        msg += checkValid('email', 'Introduceti o adresa valida de e-mail', 'email');
    }

    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
        return true;
    }
}

function checkQuickOrder(f) {
    msg = '';
   
     if (f.qname.value=="")
    	msg += '*Completati numele\n';
     if (f.qsurname.value=="")
    	msg += '*Completati prenumele\n';	
     if (f.qphone.value=="")
    	msg += '*Completati telefonul\n';
     if (f.qemail.value=="")
    	msg += '*Completati adresa de e-mail\n';			

    if(f.qemail.value != '') {
    	 var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (!filter.test(f.qemail.value)) {
            msg += '*Introduceti o adresa valida de e-mail\n';	
        }
    }

    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
    	
    	if (!f.terms.checked)
	    {
	    	alert("Trebuie sa fiti de acord cu termenii si conditiile!");
	    	return false;
	    }
        return true;
    }
}

function checkAccount1(){
   
    if((document.getElementById('de_acord'))&&(document.getElementById('de_acord').checked!=true)){
        alert('Trebuie sa fiti de acord cu Termenii si Conditiille de utilizare si Politica de Confidentialitate'); 
        return false; 
    }else if(!(document.getElementById('newsletteryes').checked==true || document.getElementById('newsletterno').checked==true)) {
        alert('Trebuie sa precizati daca doriti sau nu sa primiti newsletter'); return false;
    }else{
        return checkAccount();
    }
}

function checkAccount3(){
    msg = checkValid('firstname', 'Completati prenumele dvs.', 'required');
    msg += checkValid('lastname', 'Completati numele dvs.', 'required');

    msg += checkValid('nemail', 'Completati adresa de e-mail', 'required');
    if(document.getElementById('nemail').value != '') {
        msg += checkValid('nemail', 'Introduceti o adresa valida de e-mail', 'email');
    }
    
    msg += checkValid('regpassword', 'Completati parola', 'required');
    msg += checkValid('reregpassword', 'Completati parola reintrodusa', 'required');
    if(document.getElementById('regpassword').value != document.getElementById('reregpassword').value){
        msg += "Parolele introduse nu coincid\n";
    }
 
    if (msg != '') {
        alert(msg);
        return  false;
    }
    else {
        return true;
	
    }
}

function checkAccount() {
    msg = checkValid('firstname', 'Completati prenumele dvs.', 'required');
    msg += checkValid('lastname', 'Completati numele dvs.', 'required');
    msg += checkValid('telephone1', 'Completati telefonul mobil.', 'required');

    msg += checkValid('email', 'Completati adresa de e-mail', 'required');
    if(document.getElementById('email').value != '') {
        msg += checkValid('email', 'Introduceti o adresa valida de e-mail', 'email');
    }

    if(cid_l=document.getElementById('customer_id')){
        if(cid_l.value==''){ // cont nou
            msg += checkValid('regpassword', 'Completati parola', 'required');
            msg += checkValid('reregpassword', 'Completati parola reintrodusa', 'required');
            if(document.getElementById('regpassword').value != document.getElementById('reregpassword').value){
                msg += "Parolele introduse nu coincid\n";
            }
        }
    }
  
    if (msg != '') {
        alert(msg);
        return  false;
    }
    else {
    	var numbers = /([0-9+]+)$/
	
		if ((document.getElementById('telephone1').value!="")&&((!numbers.test(document.getElementById('telephone1').value))||(document.getElementById('telephone1').value.length!=10)||(document.getElementById('telephone1').value.substr(0,1)!="0")))
		{
			alert("Numarul de telefon mobil nu este introdus corect!\nIntroduceti 10 cifre fara spatiu.");	
			return false;
		}
		
		if ((document.getElementById('telephone2').value!="")&&((!numbers.test(document.getElementById('telephone2').value))||(document.getElementById('telephone2').value.length!=10)||(document.getElementById('telephone2').value.substr(0,1)!="0")))
		{
			alert("Numarul de telefon fix nu este introdus corect!\nIntroduceti 10 cifre fara spatiu.");	
			return false;
		}
        return true;
    }
}


function checkAccount2() {
    msg = checkValid('nume_pren', 'Completati numele si prenumele dvs.', 'required');
    msg += checkValid('adresa', 'Completati adresa dvs.', 'required');
    msg += checkValid('descriere', 'Completati sesizarea dvs.', 'required');
    msg += checkValid('email', 'Completati adresa de e-mail', 'required');
    if(document.getElementById('email').value != '') {
        msg += checkValid('email', 'Introduceti o adresa valida de e-mail', 'email');
    }
    if (msg != '') {
        alert(msg);
        return  false;
    }
    else {
        return true;
    }
}

function checkPassword() {
    msg = checkValid('password', 'Completati parola actuala', 'required');
    msg += checkValid('newpassword', 'Completati parola noua', 'required');
    msg += checkValid('newpassword2', 'Confirmati parola noua', 'required');
    msg += checkValid('newpassword', 'Cele 2 parole nu sunt egale', 'equals', document.getElementById('newpassword2').value);
    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
        return true;
    }
}

function checkAddress() {
    msg = checkValid('address', 'Completati adresa', 'required');
    msg += checkValid('city', 'Completati orasul', 'required');
    msg += checkValid('state', 'Completati judetul', 'required');
	if($('#state').val() == '...'){
			msg += '* Completati judetul';
	}
    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
        return true;
    }
}

function checkCompany() {
    msg = checkValid('name', 'Completati nume firmei', 'required');
    msg += checkValid('code', 'Completati codul unic de inregistrare', 'required');
    msg += checkValid('registration', 'Completati numarul de inregistrare la Registrul Comertului', 'required');
    msg += checkValid('bankaccount', 'Completati numarul contului bancar', 'required');

    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
        return true;
    }
}

function checkComment() {
    msg = checkValid('customer_name', 'Completati numele dvs.', 'required');
    msg += checkValid('customer_email', 'Completati adresa de e-mail', 'required');
    if(document.getElementById('customer_email').value != '') {
        msg += checkValid('customer_email', 'Introduceti o adresa valida de e-mail', 'email');
    }
    msg += checkValid('customer_location', 'Completati locatia dvs.', 'required');
    msg += checkValid('customer_comment', 'Scrieti un comentariu despre acest produs', 'required');

    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
        return true;
    }
}

function checkRequestInfo() {
    msg = checkValid('customer_name', 'Completati numele dvs.', 'required');
    msg += checkValid('customer_email', 'Completati adresa de e-mail', 'required');
    if(document.getElementById('customer_email').value != '') {
        msg += checkValid('customer_email', 'Introduceti o adresa valida de e-mail', 'email');
    }
    msg += checkValid('request', 'Completati informatiile solicitate despre produs', 'required');

    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
        return true;
    }
}

function checkRecommend() {
    msg = checkValid('name', 'Completati numele dvs.', 'required');
    msg += checkValid('email', 'Completati adresa dvs de e-mail', 'required');
    if(document.getElementById('email').value != '') {
        msg += checkValid('email', 'Introduceti o adresa valida de e-mail', 'email');
    }
    msg += checkValid('friend', 'Completati adresa de e-mail a prietenului', 'required');
    if(document.getElementById('friend').value != '') {
        msg += checkValid('friend', 'Introduceti o adresa valida de e-mail', 'email');
    }

    if (msg != '') {
        alert(msg);
        return false;
    }
    else {
        return true;
    }
}

/* popup windows */
function popup(url, winname, w, h) {
    compensatew = 0;
    compensateh = 0;

    if ($.browser.msie && parseInt($.browser.version) < 7) {
        compensatew = 10;
        compensateh = 30;
    }

    w = w - compensatew;
    h = h - compensateh;

    l = (screen.availWidth - w - compensatew) / 2;
    t = (screen.availHeight - h - compensateh) / 2;

    if (l < 0) {
        l = 0;
    }
    if (t < 0) {
        t = 0;
    }
    if (w > screen.availWidth) {
        w = screen.availWidth;
    }
    if (h > screen.availHeight) {
        h = screen.availHeight;
    }
    window.open(url, winname, 'top='+t+',left='+l+',width='+w+',height='+h+',scrollbars=yes,menubar=no,toolbar=no,location=no,resizable=yes,status=no');
}

function compare(id) {
    w = screen.availWidth;
    h = screen.availHeight;
    popup('/compara/'+id, 'compareWin', w, h);
}

function comment(id) {
    w = 770;
    h = 470;
    popup('/comenteaza/'+id, 'commentWin', w, h);
}

function info(id) {
    w = 700;
    h = 400;
    popup('/cere-informatii/'+id+'/', 'requestInfoWin', w, h);
}

function senderr(id) {
    w = 700;
    h = 400;
    popup('/semnaleaza-eroare/'+id+'/', 'sendErrWin', w, h);
}

function recommend(id, theme, color, color2) {
    w = 770;
    h = 380;
    popup('/recomanda/'+id+'&theme='+theme+'&color='+color+'&color2='+color2+'/', 'recommendWin', w, h);
}

function changethumb(id, file) {
    $('#mainimg').attr('src', '/content/products/images/'+parseInt(id)+'/normal/'+file);
    $('#mainimga').attr('href', '/content/products/images/'+parseInt(id)+'/full/'+file);
}

function change_manufacturer(manufacturer) {
    document.getElementById('products').options.length = 0;

    newoption = document.createElement('option');
    newoption.value = 0;
    newoption.appendChild(document.createTextNode('Alegeti un produs...'));
    document.getElementById('products').appendChild(newoption);

    for(var id in products) {
        if((manufacturer == 0) || (products[id][0] == manufacturer)) {
            newoption = document.createElement('option');
            newoption.value = id;

            if(manufacturer == 0) {
                newoption.appendChild(document.createTextNode(manufacturers[products[id][0]] + ' ' + products[id][1]));
            }
            else {
                newoption.appendChild(document.createTextNode(products[id][1]));
            }

            document.getElementById('products').appendChild(newoption);
        }
    }
}

function showSubmenu(which) {
    for (i=0; i<30; i++) {
        $("#sc_"+which+"_"+i).removeClass("scf");
        $("#sc_"+which+"_"+i).addClass("blocked");

    }
}

function hideSubmenu(which) {
    for (i=0; i<30; i++) {
        $("#sc_"+which+"_"+i).removeClass("blocked");
        $("#sc_"+which+"_"+i).addClass("scf");
    }
}


function placeholder() {
    // nothing
}

function hideSCD() {
    $('#scdetails').hide();
    $('#scdtop').html('');
    $('#scdbottom').html('');
}

function st(tab) {
    $(".tabmenu ul li a").removeClass("tsel");
    $("#sta"+tab).addClass("tsel");

    $(".stc").hide();
    $("#stc"+tab).show();
}

function validEmail(field) {
     var str = trim(field.value); // email string
     var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
     var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
     if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
       return true;
    }
    return false;
}

function Register_Newsletter(id){
    var frm=document.forms['newsform'+id];
    nami=frm.elements.newsname.value;
    emi=frm.elements.newsemail.value;
    nami=nami.replace('/','_');
    emi=emi.replace('/','_');
    if(Verif_alerta_email_news(id)){
	    return true;
    }
    return false;
}

function AlertaStoc(f,prodi){
	email = eval("f.alerta_email_1220622045_"+prodi);
    if(Verif_alerta_email_1220622(email))
	{
        RecEmail_1220622(email.value, prodi, f.news.value);
    }
}

function Verif_alerta_email_news(id){
    var frm=document.forms['newsform'+id];
    c=frm.elements.newsemail;
    if (!validEmail(c)){
        alert("Introduceti o adresa valida de E-mail!");
        c.focus();
        return false;
    }
    return true;
}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function Verif_alerta_email_1220622(email){
    
    if (!validEmail(email)){
        alert("Introduceti o adresa valida de E-mailll!");
		return false;
    }
	//
    return true;
}


/* AJAX Stuff */
function createRequestObject()
{
    var request;
    var browser=navigator.appName;
    if(browser=="Microsoft Internet Explorer")
        request=new ActiveXObject("Microsoft.XMLHTTP");
    else
        request=new XMLHttpRequest();
    return request;
}

var http=createRequestObject();

function RecEmail_1220622(emi, prodi, news){
    http.open('GET', "/ajax/emailrec/" + escape(prodi) + "/" + escape(emi) + "/" + escape(news) + "/");
    http.onreadystatechange=afterRecEmail_1220622;
    try {http.send(null);} catch(e1) {}
    return;
}


function afterRecEmail_1220622(){
    if(http.readyState==4)  {
        alert(http.responseText);
		if(http.responseText == 'Cererea dumneavoastra a fost inregistrata.\nVeti fi anuntat de indata ce produsul va fi disponibil in stoc')
		{
			return hs.close();
		}
    }
}

var slideMenu=function(){
    var sp,st,t,m,sa,l,w,sw,ot;
    return{
        build:function(sm,sw,mt,s,sl,h){
            sp=s; st=sw; t=mt;
            m=document.getElementById(sm);
            if(typeof(m)!="undefined"){
                sa=m.getElementsByTagName('li');
                l=sa.length; w=m.offsetWidth; sw=w/l;
                ot=Math.floor((w-st)/(l-1)); var i=0;
                for(i;i<l;i++){s=sa[i]; s.style.width=sw+'px'; this.timer(s)}
                if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t)}
            }
        },
        timer:function(s){s.onmouseover=function(){clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t)}},
        slide:function(s){
            var cw=parseInt(s.style.width,'10');
            if(cw<st){
                var owt=0; var i=0;
                for(i;i<l;i++){
                    if(sa[i]!=s){
                        var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width,'10');
                        if(ow>ot){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'}
                        owt=owt+(ow-oi)}}
                s.style.width=(w-owt)+'px';
            }else{clearInterval(m.timer)}
        }
    };
}();

var filters;
var man;
function cancelFilters(catID, section){

    if(section == undefined || section == null){
        $(".filtercheck").each(function(){
            this.checked = false;
        });
        $("#cancelTab").hide();
        buildFiltersList(catID,1);
		$("#filterAll"+section).attr({checked:true});
    } else {
        $("#filterBox" + section + " input.filtercheck").attr({checked:false});
        buildFiltersList(catID,1);
		$("#filterAll2").attr({checked:true});
	}
}

function buildFiltersList(catID,page,manURL){
	$("#loadingTab").show();
	var filterString = '';
	var manString    = '';
	var tipString    = '';
    var hashData = new Array();
	$(".filtercheck:checked").each(function(){
		if($(this).attr('name') != 'man' && $(this).attr('name') != 'tip'){
			filterString +=  $(this).val();
		} else if($(this).attr('name') == 'man'){
			manString +=  $(this).val() + "-";
		} else if($(this).attr('name') == 'tip'){
			tipString +=  $(this).val() + "-";
		}
        hashData.push($(this).parent().attr('name'));
	});
	
	if (document.getElementById('products_order'))
    	filterString+="&sort=price&dir="+document.getElementById('products_order').options[document.getElementById('products_order').selectedIndex].value;
    if (document.getElementById('products_show1'))
    	filterString+="&stoc="+document.getElementById('products_show1').options[document.getElementById('products_show1').selectedIndex].value;
    if (document.getElementById('products_show2'))
    	filterString+="&promo="+document.getElementById('products_show2').options[document.getElementById('products_show2').selectedIndex].value;	
    if (parseFloat(document.getElementById('min_price').value)>0)
    	filterString+="&min_price="+parseFloat(document.getElementById('min_price').value);
    if (parseFloat(document.getElementById('max_price').value)>0)
    	filterString+="&max_price="+parseFloat(document.getElementById('max_price').value);		
    hashData.push("page-"+page);
	setHashStuff(hashData);
	if(manURL != '' && manURL != 'undefined' && manURL != undefined  && manURL != 0) manString = manURL;
	filterProducts(filterString, catID, page, manString,tipString);
}

function filterProducts(filterString,catID,page,manString, tipString){

	if($(".filtercheck:checked:not(.cancelf)").length > 0){
		$("#cancelTab").show();
	} else {
	
	}

	$('#productsArea').load(
 		'/index.php?sa=viewcategory_ajax&catid='+catID+'&filterString='+filterString+'&page='+page+'&manid='+manString+'&tip='+tipString,
   		function(){
			$("#loadingTab").hide();
		}
	);
    
}

function hideFilters(filter, subfilter){
	
	
	for(i=6;i<=subfilter;i++){
		
		$("#filterLine" + filter + '-' + i).hide();
	}
	
}
var t0=0,t1=0, t2=0, t3=0, t4=0, t5=0,t6=0, t7=0, t8=0, t9=0, t10=0, t11=0, t12=0, t13=0,t14=0,t15=0,t16=0,t17=0,t18=0,t19=0,t20=0,t21=0;
function showFilters(filter, subfilter){
	
	for(i=6;i<=subfilter;i++){
		
		$("#filterLine" + filter + '-' + i).toggle();
	
	}
		flag = eval("t"+filter);
		
		if(flag == 0){
			$('#more'+filter).html('[restrange]');
			eval("t"+filter+"=1;");
		} else{
			$('#more'+filter).html('[mai multe]');
			eval("t"+filter+"=0;");
		}
	
}

function goToPage(page,catID){
	buildFiltersList(catID,page);
    window.scroll(0,0);
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}


function setHashStuff(hashArr){
    var str = '';

    $.each(hashArr, function(hindex,hvalue){
        str +=  hvalue + "|";
    });
    if(str.length > 0){
    	document.location.href = "#" + str;
    }
   
}

function selectURLMan(manid,cat,p){
	$(".filtercheck[value="+manid+"]").attr({checked:true});
	//$("#cancelTab").show();
}

function checkHistory(cat,p){
    var s = document.location.hash.substr(1);
    if(s){
        var boxes = s.split("|");
        $.each(boxes, function(hindex,hvalue){
            if(hvalue){
            	ff=hvalue.split("-");
               // $('#filterAll'+ff[0]).attr({checked:false});
                $('.fname[name='+hvalue+']').attr({checked:false});
                //$('#filterLine' + hvalue+ ' .filtercheck').attr({checked:true});
                $('.fname[name='+hvalue+'] .filtercheck').attr({checked:true});
            }
        });
	
    }
    buildFiltersList(cat,p,0);
   
}

function printProductCount(cnt){
	if(cnt != undefined){
		if(cnt > 1)
			$('#countTab').html('('+cnt+' produse)');
		else
			$('#countTab').html('('+cnt+' produs)');
	} else {
			$('#countTab').html('(0 produse)');
	}
}


function showAdvancedFilters(){
	$('#showFilterTabs').show();
}
var adv=0;
function showSimpleFilters(){
	adv=1;
}

function hideAdvancedSpace(){
	$("#filtreTop").addClass("selected3");
}

function check_terms(url)
{
	if (document.getElementById("acord").checked==true)
		window.location=document.getElementById("url").value;
	else
	{
		alert("Trebuie sa fiti de acord cu termenii si conditiile de mai jos!");
		document.getElementById("acord").focus();
	}	
}

function selCity(county,cityid)
{
    /*$.getJSON("/index.php",{a: "user", sa: "selcities", county: county}, function(j){
      var options = '';
      for (var i = 0; i < j.length; i++) {
        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
      }
      $("select#"+cityid).html(options);
      $("select#"+cityid).attr("disabled",false);
    })*/
    
    
    $.ajax({
	    type: 'GET',
	    url: '/index.php',
	    dataType: 'json',
	    success: function(j) { 
	    	  var options = '';
		      for (var i = 0; i < j.length; i++) {
		        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		      }
		      $("select#"+cityid).html(options);
		      $("select#"+cityid).attr("disabled",false);
	    },
	    data: {a: "user", sa: "selcities", county: county},
	    async: false
	});


}

function roundnumber(rnum) {
	rlength = 2; // The number of decimal places to round to
	newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	return newnumber;
}

function is_cnp(cnp)
{
    if(cnp.length != 13)
    {
        alert('Introducetin CNP cu 13 cifre!')
        return false
    }
    else
    {
        if (parseInt(cnp.substr(3,2))<1 || parseInt(cnp.substr(3,2))>12)
        {
            alert('CNP incorect!')
            return false
        }
        else if (parseInt(cnp.substr(5,2))<1 || parseInt(cnp.substr(5,2))>31)
        {
            return false
            alert('CNP incorect!')
        }
        else return true
    }
}