/* 
###################################################################################
#
#	SET's FUNCTIONS	 --------------------------------------------------------------
#	
###################################################################################
*/

// ----------------------
// Function Set_Main
// ----------------------

function setmain( fbox ){
	
	if ( fbox ) {
	  
		if ( ( fbox.category)&&( fbox.sub_cat)&&( fbox.marki) ){
		
			category='';
        
			if ( fbox.category.selectedIndex>=0 ){
				
				category= fbox.category.options[ fbox.category.selectedIndex].value-1;
			}
          
			fbox.sub_cat.length=0;

			marki= fbox.marki.value.split('**');
			i=0;
        
			while ( (i<marki.length)&&( fbox.sub_cat.length==0) ){
	        
				marki[i]=marki[i].split('~');
            
				if ( i==category ){
	            
					k=0;
                
					while ( k<marki[i].length ){
			                
						optval=marki[i][k];
		                    
						if ( optval=='' ){
			                    
							optval='всички';
						}
						
						fbox.sub_cat.options[k]=new Option(optval,marki[i][k]);
						k++;
					}
				}
			
				i++;
			}
          
	        if ( fbox.sub_cat.length==0 ){
	        
				fbox.sub_cat.options[0]=new Option('','');
			}
		}
	}
      
} // End Set_Main


// -----------------------------------------------------------------------------------
// Function Set_Cars
// -----------------------------------------------------------------------------------

function setcars( fbox )
{
  if ( fbox  )
    if ( ( fbox.car)&&( fbox.model)&&( fbox.marki) )
      {
        marka='';
        if (  fbox.car.selectedIndex>=0 )
          marka= fbox.car.options[ fbox.car.selectedIndex].value;
         fbox.model.length=0;

        marki= fbox.marki.value.split('**');
        i=0;
        while ( (i<marki.length)&&( fbox.model.length==0) )
          {
            marki[i]=marki[i].split('~');
            if ( marki[i][0]==marka )
              {
                k=1;
                while ( k<marki[i].length )
                  {
                    optval=marki[i][k];
                    if ( optval=='' )
                      optval='всички модели';
                     fbox.model.options[k-1]=new Option(optval,marki[i][k]);
                    k++;
                  }
              }
            i++;
          }
        if (  fbox.model.length==0 )
           fbox.model.options[0]=new Option('','');
      }
      
} // End Set_Cars


/* 
###################################################################################
#
#	COOKIES FUNCTIONS	 ----------------------------------------------------------
#	
###################################################################################
*/

// -----------------------
// Function Clear_Cookies
// -----------------------

function clearcookies() {

	var kill_date = new Date("January 1, 1970");

	document.cookie = "car_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "model_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "price_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "p1_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "p2_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "month_cookie=stub;expires=" + kill_date.toGMTString();	
	document.cookie = "year_cookie=stub;expires=" + kill_date.toGMTString();		
	document.cookie = "y1_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "y2_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "km_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "color_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "valuta_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "city_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "power_cookie=stub;expires=" + kill_date.toGMTString();
	document.cookie = "otherinfo_cookie=stub;expires=" + kill_date.toGMTString();	
	document.cookie = "sort_cookie=stub;expires=" + kill_date.toGMTString();	
	
} // End Clear_Coocies

function clearerrors() {
	
	var kill_date = new Date("January 1, 1970");
	
	document.cookie = "car_error=stub;expires=" + kill_date.toGMTString();
	document.cookie = "model_error=stub;expires=" + kill_date.toGMTString();
}
// -----------------------------------------------------------------------------------
// Function Set_Cookies
// -----------------------------------------------------------------------------------

function setcookie( fbox ) {
	
	if( fbox.options ) {
		
		this_id = fbox.selectedIndex
		this_name = fbox.name
		document.cookie = this_name+'_cookie='+this_id
		
	}
	else{
		
		this_value = fbox.value
		this_name = fbox.name
		document.cookie = this_name+'_cookie='+this_value
	}
	
} // End Set_Cookies


function img_change( img ){

	document.images['first'].src = img;

}