// JavaScript Document
/*function validCNP(s)
{
	return true;
var suma=0;
var mesaj="";
if(s.length==13)
{
suma=parseInt(s.charAt(0))*2+parseInt(s.charAt(1))*7+parseInt(s.charAt(2))*9+pareInt(s.charAt(3))*1+parseInt(s.charAt(4))*4+parseInt(s.charAt(5))*6+parseInt(s.carAt(6))*3+parseInt(s.charAt(7))*5+parseInt(s.charAt(8))*8+parseInt(s.charAt(9))*2+parseInt(s.charAt(10))*7+parseInt(s.charAt(11))*9;
suma=suma%11;
if(suma==10)
suma=1;
if(suma==parseInt(s.charAt(12)))
return true;
else{
alert("CNP invalid !!!");
return false;
}

}
else{
alert("CNP de lungime necorespunzatoare (<>13) !!! ");
return false;
}
}
*/
function validCNP(cnp) {
   if( cnp.length != 13 )
      return false;
   if( isNaN(parseInt(cnp, 10)) )
      return false;
   var MASK = new Array(2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9);
   var crcSum = 0;
   var i;
   for( i=0; i!=12; i++) {
      crcSum += parseInt(cnp.charAt(i), 10) * MASK[i];
   }
   var crc = crcSum % 11;
   var crcVerif = parseInt(cnp.charAt(12), 10);
   if(
      ( crc < 10 && crc == crcVerif ) ||
      ( crc == 10 && 1 == crcVerif ) )
      return true;
   return false;
}
	
function show(id)
{
	document.getElementById(id).style.display='';
}
function hide(id)
{
	document.getElementById(id).style.display='none';
}

function showFizica()
{
		show('varsta_container');
		show('malus');
		show('permis');
		show('domactivitate_pf');
		show('reduceri');
		
		hide('domactivitate');
		hide('leasing');
		hide('maluspj');
	//	hide('caen');
		
}

function show_hide(id)
{
	if(el=document.getElementById(id))
	{
	
	if(el.style.display=='')
		hide(el.id);
	else show(el.id);
	}
}

function hideFizica()
{
		hide('varsta_container');
		hide('malus');
		hide('permis');
		hide('domactivitate_pf');
		hide('reduceri');
		
		hide('leasing');
		
		show('domactivitate');
		show('maluspj');
		
	//	show('caen');
}

function showLeasing()
{
	show('leasing');
}

function email_check(str) {

		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					
	}
	
	var imgpreload = new Image();
   imgpreload.src = '/imagini/loading_icon.gif';
	
	function check_loc()
	{
		
		if($('.subcat_input').val()=='')
		{
			$('.subcat_input').val($('.subcat_input').attr('placeholder'));
		//	alert($('.subcat_input').attr('rel'));
		//	return false;
		}
		
		if($('.subcat_input2').val()=='')
		{
			$('.subcat_input2').val($('.subcat_input2').attr('placeholder'));
		//	alert($('.subcat_input').attr('rel'));
		//	return false;
		}
		
		
		if(document.getElementById('persoana2').checked==false && document.getElementById('persoana5').checked==false)
		{
			if(document.getElementById('permis_month').value=='' || document.getElementById('permis_year').value=='')
				{
					alert('Nu ati selectat data obtinerii permisului!');
					return false;
				}
			else{ }
			
			if(document.getElementById('polita_veche').value=="")
			{
				alert('Nu ati selectat clasa de Bonus-Malus anterioara! Se gaseste in partea stanga jos a politei (vezi exemplu). Daca nu exista sau este prima oara cand faceti RCA la acest vehicul selectati B0');
				return false;
			}
		}
		else{ }
		
		



		if(document.getElementById('s_loc').value=='')
		{
			alert('Nu ati selectat localitatea!');
			return false;
		}
		
		document.getElementById('cautama').style.display='none';
		
		document.getElementById('rotite').style.display='';
				
		return true;
	}
	
	function validate_expira()
	{
		if(document.getElementById('data_rca')=="" || document.getElementById('data_rca')=='ZZ-LL-AAAA')
			{
				alert('Nu ati completat data!');
				return false;
			}
		
		if(!email_check(document.getElementById('exp_email').value))
			{
				alert('Adresa de e-mail nu este valida!');
				return false;
			}
			
		if(document.getElementById('exp_tel').value=="" || document.getElementById('exp_tel').value=="Numar telefon")
			{
				alert('Nu ati completat numarul de telefon!');
				return false;
			}
		return true;
	}
	
	function validate_feedback(captcha)
	{
	/*	if(document.getElementById('feedback_nume')=="")
			{
				alert('Nu ati completat numele!');
				return false;
			}
		*/
		
		if(captcha!=$('#captcha').val())
			{
				alert('Codul de siguranta nu este corect!');
				return false;
			}
		
		if(!email_check(document.getElementById('feedback_email').value))
			{
				alert('Adresa de e-mail nu este valida!');
				return false;
			}
	/*		
		if(document.getElementById('feedback_tel').value=="")
			{
				alert('Nu ati completat numarul de telefon!');
				return false;
			}*/
		return true;
	}
	
	
	function send_omniasig_fizica(sid)
	{
		
		if(document.getElementById('o_cnp').value=='')
			{
				alert('Nu ati completat CNP-ul!');
				return false;
			}
			
		
		
		if(document.getElementById('o_cnp').value.length<13 || document.getElementById('o_cnp').value.length>13)
		{
			alert('CNP-ul trebuie sa contina 13 caractere!');
			return false;
		}
		
			
		if(document.getElementById('o_dop_year').value=='')
			{
				alert('Nu ati completat anul obtinerii permisului!');
				return false;
			}
			
		if(document.getElementById('o_dop_month').value=='')
			{
				alert('Nu ati completat luna obtinerii permisului!');
				return false;
			}
			
		if(document.getElementById('o_sasiu').value=='')
			{
				alert('Nu ati completat seria sasiului!');
				return false;
			}
			
		str=document.getElementById('o_sasiu').value;
	/*	if(str.search(/o/i)>0)
			{
				alert('Numarul de identificare nu trebuie sa contina litera O. Intotdeauna  zero!');
				return false;
			}*/
		
		str = str.replace(/o/ig,'0');
		document.getElementById('o_sasiu').value = str;
		
		if(validCNP(document.getElementById('o_cnp').value)!=true)
			{
				alert('CNP incorect!');
				return false;
			}
		return true;
	}
	
	function send_omniasig_juridica(sid)
	{
		
		if(document.getElementById('o_cnp').value=='')
			{
				alert('Nu ati completat CUI-ul!');
				return false;
			}
		if(document.getElementById('o_sasiu').value=='')
			{
				alert('Nu ati completat seria sasiului!');
				return false;
			}
			
		
			
		if(document.getElementById('o_domeniu').value=='')
			{
				alert('Nu ati selectat domeniul de activitate!');
				return false;
			}
		
		str=document.getElementById('o_sasiu').value;
	/*	if(str.search(/o/i)>0)
			{
				alert('Numarul de identificare nu trebuie sa contina litera O. Intotdeauna  zero!');
				return false;
			}*/
		str = str.replace(/o/ig,'0');
		document.getElementById('o_sasiu').value = str;
		
	//	alert(str);
		
		return true;
	}
	
	function check_altele()
	{
		if(document.getElementById('alte_nume').value=='' || document.getElementById('alte_nume').value==' ' || document.getElementById('alte_nume').value=='Nume')
		{
			alert('Nu ati introdus numele!');
			return false;
		}
		
		if(document.getElementById('alte_email').value=='' || document.getElementById('alte_email').value=='Adresa e-mail')
		{
			alert('Nu ati introdus adresa de e-mail!');
			return false;
		}
		
		if(check_email(document.getElementById('alte_email').value)==false)
			{
				alert('Adresa de e-mail nu este valida!');
				return false;
			}
		
		if(document.getElementById('alte_tel').value=='' || document.getElementById('alte_tel').value==' ' || document.getElementById('alte_tel').value=='Numar telefon')
		{
			alert('Nu ati introdus numarul de telefon!');
			return false;
		}
		
		return true;
	}
	
	function check_asiglocuinte()
	{
		if(document.getElementById('locuinte_nume').value=='' || document.getElementById('locuinte_nume').value==' ' || document.getElementById('locuinte_nume').value=='Nume')
		{
			alert('Nu ati introdus numele!');
			return false;
		}
		
	/*	if(document.getElementById('locuinte_email').value=='' || document.getElementById('locuinte_email').value=='Adresa e-mail')
		{
			alert('Nu ati introdus adresa de e-mail!');
			return false;
		}
		
		if(check_email(document.getElementById('locuinte_email').value)==false)
			{
				alert('Adresa de e-mail nu este valida!');
				return false;
			}
		
		*/
		if(document.getElementById('locuinte_tel').value=='' || document.getElementById('locuinte_tel').value==' ' || document.getElementById('locuinte_tel').value=='Numar telefon')
		{
			alert('Nu ati introdus numarul de telefon!');
			return false;
		}
		
		return true;
	}
	
	function check_asiglocuinte2()
	{
		if(document.getElementById('locuinte_nume2').value=='' || document.getElementById('locuinte_nume2').value==' ' || document.getElementById('locuinte_nume2').value=='Nume')
		{
			alert('Nu ati introdus numele!');
			return false;
		}
		
	/*	if(document.getElementById('locuinte_email2').value=='' || document.getElementById('locuinte_email2').value=='Adresa e-mail')
		{
			alert('Nu ati introdus adresa de e-mail!');
			return false;
		}
		
		if(check_email(document.getElementById('locuinte_email2').value)==false)
			{
				alert('Adresa de e-mail nu este valida!');
				return false;
			}*/
		
		if(document.getElementById('locuinte_tel2').value=='' || document.getElementById('locuinte_tel2').value==' ' || document.getElementById('locuinte_tel2').value=='Numar telefon')
		{
			alert('Nu ati introdus numarul de telefon!');
			return false;
		}
		
		return true;
	}
	
	function check_altele2()
	{
		if(document.getElementById('alte_nume2').value=='' || document.getElementById('alte_nume2').value==' ' || document.getElementById('alte_nume2').value=='Nume')
		{
			alert('Nu ati introdus numele!');
			return false;
		}
		
		if(document.getElementById('alege_tip').value=='')
			{
				alert('Nu ati selectat asigurarea dorita!');
				return false;
			}
		
		/*
		if(document.getElementById('alte_email2').value=='' || document.getElementById('alte_email2').value=='Adresa e-mail')
		{
			alert('Nu ati introdus adresa de e-mail!');
			return false;
		}
		
		if(check_email(document.getElementById('alte_email2').value)==false)
			{
				alert('Adresa de e-mail nu este valida!');
				return false;
			}
		*/
		if(document.getElementById('alte_tel2').value=='' || document.getElementById('alte_tel2').value==' ' || document.getElementById('alte_tel2').value=='Numar telefon')
		{
			alert('Nu ati introdus numarul de telefon!');
			return false;
		}
		
		return true;
	}
	
	
	function rotate_nr()
	{
		show_hide('tel_rca1'); show_hide('tel_rca2');
		show_hide('nr_rca1'); show_hide('nr_rca2');
	}
	
	setInterval("rotate_nr()",'1300');
	
	$('#changeOferta').live('click',function(){
			
			window.location = 'cauta_rca?change=1&ocnp='+$('#o_cnp').val()+'&odomeniu='+$('#o_domeniu').val()+'&oputere='+$('#o_putere').val()+'&osasiu='+$('#o_sasiu').val();
			
			return false;
		})
	
	function send_oferta()
	{
		var compids = new Array();
		var compprices = new Array();
		var index=0;
		var get = '';
		
		if($('#tempHiddens').html() == "" && $('.toploader').size()==0)
		{
		clearInterval(intervalOferta);
		
		$('.preturi').each(function(){
				
				var elid = $(this).attr('id');
				
				compids[index] = $('#'+elid+' .comp_name').html();
				compprices[index] = '';
				$('#'+elid+' .comp_pret').each(function(){
						compprices[index] = compprices[index] + ':' + $(this).html();
					})
				index = index + 1;	
				
			});
		/*
		$('.hiddens').each(function(){
							
							compids[index] = this.name;
							compprices[index] = this.value;	
							//	alert($(this).html());
							index = index + 1;	
							});
			*/				
		for(i=0;i<compids.length;i++)
		{
			get = get + "\n" + compids[i] + compprices[i];
		}
		
		document.getElementById('send_oferta').style.display = '';
		document.getElementById('oferta_companii').value = get;
		}
	}
	
	function checkError()
    {
        var message = 'Nu a putut fi calculat pretul pentru';
		var companii = new Array();

		alert($('#tempHiddens').html());
		
		if($('#tempHiddens').html()=="")
		{
			alert('checking...');
			var i=0;
            $('.hidenns').each(function(){
            		
					if($(this).val() == 0 || $(this).val() == "")
					{
						if($(this).attr('rel')!='')
						companii[i] = $(this).attr('rel');
						i = i +1 ;
					}
				
                })

            if(companii.length>0)
            {
                for(i=0;i<companii.length;i++)
                {
                    message = message + companii[i];
                    alert(companii[i]);
                }
            }

            alert(message);
		}
    }
	
	$(document).ready(function(){
		
		var aux=0;
		
		var temp = new Image();
		temp.src = '/imagini/comanda_hover.jpg';
		
	//	$('input[placeholder],textarea[placeholder]').placeholder();
		
		$('.rowform tr').each(function(){
			//alert($(this).css('display'));
			
				if($(this).css('display') != "none")
				{
					if(aux%2==0)
						$(this).addClass('trone');
					else $(this).removeClass('trone');
				
					aux++;
				}
			
			});
			
		$('#polita_veche').live('click',function(){
				//alert('BM');
				if($(this).val()=='-1')
					$('#maluss').val('-1');
				
			
			});
		$('#maluss').live('click', function(){
			
				
			});
			
		$('#o_cnp').keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            if (
                key == 8 || 
                key == 9 ||
                key == 46 ||
				 key == 17 ||
				  key == 86 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105))
				
				return true;
			
			else{ alert('Doar cifre!'+key); return false;} 
        });
		
		
		$('.subcat_input').keydown(function(e)
        {
			
            var key = e.charCode || e.keyCode || 0;
			var ret = false;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            if (
                key == 8 || 
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105))
			{	
				ret = true;
			}
			else{ 
				
				ret = false;
				alert('Doar cifre!'); 
			} 
			
			return ret;
        });
			
		$('#lafel').click(function(){
				//alert($('#adresa_asigurat').val());
				if($(this).attr('checked')==true)
				$('#adresa_livrare').val($('#adresa_asigurat').val());
				else $('#adresa_livrare').val("");
			});
			
		$('#adresa_asigurat').keyup(function(){
			
				if($('#lafel').attr('checked')==true)
					$('#adresa_livrare').val($('#adresa_asigurat').val());
			});
			
		$('#adresa_livrare').keyup(function(){
			
				if($('#lafel').attr('checked')==true)
					$('#adresa_asigurat').val($('#adresa_livrare').val());
			});
			
		
		
		$('.bonus-tiriac').live('mouseover', function(){
				 ol_fgcolor = "";
			     ol_bgcolor = "";
			     ol_textcolor = "";
				 
				overlib('<img src="/imagini/redallianz.png" border="0">',WRAP, VAUTO);
				
			});
			
		$('.bonus-tiriac').live('mouseout', function(){
				 ol_fgcolor="#F7B101";
		  		 ol_bgcolor="#9D9D9D";
		 		 ol_textcolor="#9D9D9D";
				 nd();
				
			});
		
		$('.tooltip').live('mouseout',function()
	    {
		   ol_fgcolor="#F7B101";
		   ol_bgcolor="#9D9D9D";
		   ol_textcolor="#9D9D9D";  
		 
		   nd();
	    });
		
		$('.tooltip').live('mouseover',function()
	    {
		/*  $(this).qtip({
			 overwrite: false,
			 content: $(this).attr('tooltip'),
			 position: {
                  corner: {
                     tooltip: 'topLeft', // Use the corner...
                     target: 'bottomRight' // ...and opposite corner
                  }
               },
			show: {
				 ready: true // Needed to make it show on first mouseover event
			  },
			  
			hide: {
				 efect: false,
				 length: 0
			},
			  
			style: {
                  border: {
                     width: 2,
                     radius: 6
                  },
                  padding: 5,
				  width: 150, 
				  fontWeight: 'bold',
                  textAlign: 'center',
                  tip: true, // Give it a speech bubble tip with automatic corner detection
                  name: 'light' // Style it according to the preset 'cream' style
               }

		  });
		  
		  */
		  
		 
		 ol_fgcolor="";
		 ol_bgcolor="";
		 ol_textcolor="";  
		 
		overlib('<img src=/imagini/balon.png>',WRAP, VAUTO);
		  
		  var cimg = new Image();
		  	  cimg.src = '/imagini/comanda.jpg';
		  var cimg_hover = new Image();
		  	  cimg_hover.src = '/imagini/comanda_hover2.jpg';
	   
	   	 $('.comandaImg').mouseover(function(){
			 	
				$(this).attr('src',cimg_hover.src);
					 
			 })
			 
		$('.comandaImg').mouseout(function(){
			 	
				$(this).attr('src',cimg.src);
					 
			 })
		 
	   });	
	   	
	    
		
		});
		
		
	
		
		
