function ajaxObject()
{
	if (document.all && !window.opera)
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	else
		obj = new XMLHttpRequest();

	return obj;
}




function goto(url)
{
	window.location=url;
}


function pop_win(url)
{
	window.open(url,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no');
}


function check_search_form()
{
	var errorMsg = '';
	errorMsg += validateInput(document.search_form.search_word.value, 1, "", "Search word");
	errorMsg += validateInput(document.search_form.search_col.value, 1, "", "In cols");

	if(errorMsg == ""){ document.search_form.submit(); }
	else{ alert(errorMsg); }
}


function clean(id)
{
	// sterge tot ce e in causta cu id-ul ID 
	document.getElementById(id).value="";
	
}


/**
 * adauga camera - fct care descopera un div pitit cu camera noua 
 **/

function adaugaCamera(nr_cam)
{
	var i;
	for(i=1;i<nr_cam;i++)
	{		
		if (document.getElementById('cam_'+i).style.display == 'none')
		{
			document.getElementById('cam_'+i).style.display = 'block';
			return;
		}
	}
}


// functie care face sa apara formul de persoana fizica sau juridica dupa cum se bifeaza butoanele radio
// p - id-ul butonului radio apasat
function show_form(p)
{
		if (p == 'pf')
		{
			document.getElementById('pf').style.display = "block";
			document.getElementById('pj').style.display = "none";			
		}
		else
		{ 
			if (p == 'pj')
			{
				document.getElementById('pf').style.display = "none";
				document.getElementById('pj').style.display = "block";						
			}
		}
	
}

// functie care face sa apara formul de persoana fizica sau juridica dupa cum se bifeaza butoanele radio
// p - id-ul butonului radio apasat
function showHide(divId)
{
	var d = document.getElementById(divId);
	
	if (d.style.display == "block")
		d.style.display = "none";
	else
		d.style.display = "block";
}

function CheckFrontRezervare()
{
	var err = '';
	var sjpj = document.getElementById('sjpj');
	var sjpf = document.getElementById('sjpf');
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(document.getElementById('tc1').value.length == 0)
    {
        alert("Introduceti tipul camerei !");
        document.getElementById('tc1').focus();
        return false;
    }
    if(document.getElementById('ds1').value.length == 0 || document.getElementById('de1').value.length == 0)
    {
        alert("Selectati perioada de rezervare !");
        document.getElementById('ds1').value = '';
        document.getElementById('de1').value = '';
        document.getElementById('ds1').focus();
        return false;
    }
    
	/* check persoana juridica */
	if (sjpj.checked)
	{
		if (document.getElementById('nume_firma').value.length < 5)
				err += 'Lungimea minina a numelui firmei este de 5 caractere. \n';
				
		if (document.getElementById('adresa_firma').value.length < 5)
				err += 'Lungimea minina a adresei este de 5 caractere. \n';
				
			if (!validareCif(document.getElementById('cui').value))
				err += 'CUI invalid. \n';
		
		if (document.getElementById('nr_reg_com').value.length < 5)
				err += 'Lungimea minina a Nr Reg. Comertului este de 5 caractere. \n';
				
		if (document.getElementById('telefon_mobil_firma').value.length < 10)
				err += 'Lungimea minina a numarului de telefon este de 10 caractere. \n';
	    //if(document.getElementById('telefon_mobil_firma').value.length==0)
         //   err += 'Introduceti un numar de mobil. \n';
		var emailFirma = document.getElementById('email_firma');		
			
		if (filter.test(emailFirma.value) == false)
			err +='Emailul este invalid. \n';
	}
	else
	{
		/* check persoana fizica */
		if(sjpf.checked)
		{
			if (document.getElementById('nume_client').value.length < 5)
				err += 'Lungimea minina a numelui este de 5 caractere. \n';
				
			if (document.getElementById('telefon_mobil').value.length < 10)
				err += 'Lungimea minina a numarului de telefon este de 10 caractere. \n';
           // if(document.getElementById('telefon_mobil').value.length==0)
           //      err += 'Introduceti un numar de mobil. \n';
			
			var email = document.getElementById('email');
			
			if (filter.test(email.value) == false)
				err +='Emailul este invalid. \n';
		}	
		else
			err += 'Alegeti statutul juridic. \n';
	}
	
	
	if (err != '')
	{
		alert(err);
		return false;
	}
	return true;
}



function checkCaptcha(cod)
{ 
	var ajaxMethod = 'GET';
	var ajaxUrl = 'captcha.php'
	    
    var ajaxHttp = ajaxObject();
	url=ajaxUrl+"?sid="+Math.random()+"&code="+cod;
		
    ajaxHttp.open(ajaxMethod, url); 
    ajaxHttp.onreadystatechange = function()
    {
		if(ajaxHttp.readyState == 4)
		{
			var ajaxResponse = ajaxHttp.responseText;		    
			var rasp = ajaxResponse;
			if (rasp == '0')
				document.getElementById('submit').disabled = true;
			else	
				document.getElementById('submit').disabled = false;
				
		}
			    		
    }

    ajaxHttp.send(null);
}

function changePic()
{ 
	var ajaxMethod = 'GET';
	var ajaxUrl = 'sim.php'
	    
    var ajaxHttp = ajaxObject();
	
		
    ajaxHttp.open(ajaxMethod, ajaxUrl); 
    ajaxHttp.onreadystatechange = function()
    {
		if(ajaxHttp.readyState == 4)
		{			
			document.getElementById('dynPicture').src ='sim.php'+"?sid="+Math.random();
			document.getElementById('ajax_loader').src='images/al_blank.gif';			
		}
		else
			document.getElementById('ajax_loader').src='images/al.gif';
			
			    		
    }

    ajaxHttp.send(null);
}




function validareCif(cif) 
{
	var CIF = cif;	
	NrCifre = CIF.length;
	
	/* daca contine spatii le elimin */
	CIF = CIF.split(' ').join('');
	
	/*Daca incepe cu RO elimin acest ro*/
	if ( (CIF.charAt(0).toLowerCase() == 'r') &&  (CIF.charAt(1).toLowerCase() == 'o'))
	{
		CIF = CIF.substring(2,NrCifre);
		NrCifre = CIF.length;
	}

	CifraControl = CIF.substring(NrCifre-1,NrCifre);
	CIF = CIF.substring(0,NrCifre-1);
	while (CIF.length < 9) 	
		CIF = '0'+CIF;
	

	SUMA=CIF.charAt(0) * 7 + CIF.charAt(1) * 5 + CIF.charAt(2) * 3 + CIF.charAt(3) * 2 + CIF.charAt(4) * 1 + CIF.charAt(5) * 7 + CIF.charAt(6) * 5 + CIF.charAt(7) * 3 + CIF.charAt(8) * 2;
	SUMA=SUMA*10;
	var REST = SUMA%11;
	if ( REST==10 ) 
		REST=0;
		
	if (REST == CifraControl) 
		return true;
	
	return false;
}



function setGeoLocation(hid,lat,lon)
{
	ajaxMethod = 'GET';
	ajaxUrl	   = 'getGeoLocation.php';
	ajaxOutput = 'value';

    var ajaxHttp = ajaxObject();
    url=ajaxUrl+"?hid="+hid+"&lat="+lat+"&long="+lon+"&sid="+Math.random();
    ajaxHttp.open(ajaxMethod, url);
    ajaxHttp.onreadystatechange = function()
    {
    	if(ajaxHttp.readyState == 4)
        {
            var ajaxResponse = ajaxHttp.responseText;
                //alert(ajaxResponse);

        }

    }

    ajaxHttp.send(null);
}


function show_comm(id,hotel_id)
{
    if(initiated == false)
    {
         
        jQuery('#comentarii').load("http://www.travelro.ro/load_hotel.php?id="+hotel_id);
        initiated = true;
        
    }
           
        if(id=='comentarii'){
        document.getElementById("comentarii").style.display="";
        document.getElementById("prezentare").style.display="none";
        if (navigator.appName == "Microsoft Internet Explorer")
        {
            document.getElementById("prezentare_tarife").className = "prezentare_tarife_inactive";
            
        }
        else
            document.getElementById("prezentare_tarife").setAttribute("class", "prezentare_tarife_inactive");
        if(document.getElementById("comentarii_link").className=="comentarii_link"){
            if (navigator.appName == "Microsoft Internet Explorer")
            {
                document.getElementById("comentarii_link").className= "comentarii_link_inactive"; 
                document.getElementById("prezentare_tarife").className = "prezentare_tarife_inactive";
            }
            else
            {
                document.getElementById("comentarii_link").setAttribute("class", "comentarii_link_inactive"); 
                document.getElementById("prezentare_tarife").setAttribute("class", "prezentare_tarife_inactive");
            }
             
        }
            
         
        }
         if(id=='prezentare'){
            document.getElementById("comentarii").style.display="none";
            document.getElementById("prezentare").style.display="";
            if(document.getElementById("prezentare_tarife").className=="prezentare_tarife_inactive"){
                if (navigator.appName == "Microsoft Internet Explorer")
            {
                document.getElementById("prezentare_tarife").className= "prezentare_tarife"; 
                document.getElementById("comentarii_link").className = "comentarii_link";
            }
            else
            {
                document.getElementById("prezentare_tarife").setAttribute("class", "prezentare_tarife"); 
             document.getElementById("comentarii_link").setAttribute("class", "comentarii_link"); 
            }
        }
                 
        
    }
   
}

function show_stars()
{
	if(document.getElementById("filtrare_stele").className=="bright_star"){
  		document.getElementById("filtrare_stele").setAttribute("class", "hidden_star"); 
	document.getElementById("stars_table").style.display="none";
	}
	else if(document.getElementById("filtrare_stele").className=="hidden_star"){
  	
			document.getElementById("filtrare_stele").setAttribute("class", "bright_star"); 
			document.getElementById("stars_table").style.display="";
	}
}

	function filtreaza(id,o,inp)
	{
		var decide = id.split("_");
	 
		if(decide[0] =='stea'){
		  if($('input[id=stele_'+decide[1]+']').is(':checked') == false && inp==true){
		      sterge(id,o);              
		  }
          else{
            jQuery('#'+id).attr('class','green');
			jQuery('.stars').hide();
			jQuery('#'+id).show();
			jQuery('#sterge_'+decide[1]).show();
			jQuery('#nr_'+decide[1]).hide();
			jQuery('#ajax').load("http://www.travelro.ro/filtrare.php?id="+id+"&o="+o+"&action=filt","",function(){
				$("#filtrare_stele").load("http://www.travelro.ro/generare.php?o="+o+"&action=generare_stele");
				$("#filtrare_facilitati").load("http://www.travelro.ro/generare.php?o="+o+"&action=generare_facilitati",function(){$("#nr_hoteluri").load("http://www.travelro.ro/show_hoteluri.php")});
			
            });
            
          }
			
		}
		else{
		  if($('input[id=check_'+decide[0]+'_'+decide[1]+']').is(':checked')==false && inp==true){
		      sterge(id,o);              
		  }
          else{
		  
			jQuery('#'+id).attr('class','green');
			jQuery('#fac_nr_'+id).hide();
			jQuery('#sterge_fac_'+id).show();
			jQuery('#ajax').load("http://www.travelro.ro/filtrare.php?id="+id+"&o="+o+"&action=filt","",function(){
				$("#filtrare_stele").load("http://www.travelro.ro/generare.php?o="+o+"&action=generare_stele");
				$("#filtrare_facilitati").load("http://www.travelro.ro/generare.php?o="+o+"&action=generare_facilitati",function(){$("#nr_hoteluri").load("http://www.travelro.ro/show_hoteluri.php")});
               
			});
           }
			
		}
	}
    function filterHoteluri(id,pret)
    {
        if(pret == 'c')
            jQuery('#ajax').load("http://www.travelro.ro/filtrare.php?o="+id+"&action=filt&pret=ASC");
        else
            jQuery('#ajax').load("http://www.travelro.ro/filtrare.php?o="+id+"&action=filt&pret=DESC");
    }
	function sterge(id,o)
	{
		var decide = id.split("_");
	
		if(decide[0] =='stea'){
		if(jQuery('#stele_'+decide[1]).attr('checked')){
			jQuery('#stele_'+decide[1]).attr('checked',false);
		}
			jQuery('#stea_'+decide[1]).attr('class','orange_row stars');
			jQuery('.stars').show();
			jQuery('#sterge_'+decide[1]).hide();
			jQuery('#nr_'+decide[1]).show();
			jQuery('#ajax').load("http://www.travelro.ro/filtrare.php?id="+id+"&o="+o+"&action=remove","",function(){
				$("#filtrare_stele").load("http://www.travelro.ro/generare.php?id="+id+"&o="+o+"&action=generare_stele");
				$("#filtrare_facilitati").load("http://www.travelro.ro/generare.php?o="+o+"&action=generare_facilitati",null,$("#nr_hoteluri").load("http://www.travelro.ro/show_hoteluri.php"));
			});
		}
		else{
			jQuery('#'+id).attr('class','orange_row stars');
			if(jQuery('#check_'+id).attr('checked')){
				jQuery('#check_'+id).attr('checked',false);
			}
			
			jQuery('#ajax').load("http://www.travelro.ro/filtrare.php?id="+id+"&o="+o+"&action=remove","",function(){
				$("#filtrare_stele").load("http://www.travelro.ro/generare.php?id="+id+"&o="+o+"&action=generare_stele");
				$("#filtrare_facilitati").load("http://www.travelro.ro/generare.php?id="+id+"&o="+o+"&action=generare_facilitati",null,$("#nr_hoteluri").load("http://www.travelro.ro/show_hoteluri.php"));
			});
			jQuery('#fac_nr_'+id).show();
			jQuery('#sterge_fac_'+id).hide();
		}
	}
    
    function arata_harta(hotel,oras)
    {   
        document.getElementById('harta').innerHTML = '<img src="images/ajax-loader.gif" />';
        document.getElementById('harta').innerHTML = '<iframe style="width:560px; height:300px;" scrolling="no"  src="http://www.travelro.ro/hotel_map.php?oras='+oras+'&hotel_id='+hotel+'"></iframe>';
        
        if( document.getElementById('harta').style.display == 'none' ){
            document.getElementById('harta').style.display = '';
        }
       else if( document.getElementById('harta').style.display == '' ){
            document.getElementById('harta').style.display = 'none';
        }
            
    }

    function arata_harta_oras(oras)
    {   
        document.getElementById('harta').innerHTML = '<img src="images/ajax-loader.gif" />';
        document.getElementById('harta').innerHTML = '<iframe style="width:560px; height:300px;" scrolling="no"  src="http://www.travelro.ro/harta_oras.php?oras='+oras+'"></iframe>';
        
        if( document.getElementById('harta').style.display == 'none' ){
            document.getElementById('harta').style.display = '';
        }
       else if( document.getElementById('harta').style.display == '' ){
            document.getElementById('harta').style.display = 'none';
        }
            
    }







