/* function searchPagination added by sreeramabrahmam on 31-10-2008 for CARAZOO-671 */
function searchPagination(val){
	document.newcarbyprice.action=val;
    document.newcarbyprice.method="post";
   	document.newcarbyprice.submit();
}
	
	function putValueForNavigation(val){
		//alert(val);
		document.page_rec.userAction.value=val;
		if(val=="city"){
		 
			document.page_rec.action="newcars/city/"+replaceCharacterWithDash(document.page_rec.cCity.value); // changed from sCity to cCity by sreeramabrahmam on 31-Oct-08 for CARAZOO-671 
		}
		else if(val=='pricerange'){
			document.page_rec.action="newcars/pricerange/"+replaceCharacterWithDash(document.page_rec.sPrice.value);
		}
		else if(val=='bodystyle'){
			document.page_rec.action="newcars/bodystyle/"+replaceCharacterWithDash(document.page_rec.sbStyle.value);
		}

else if(val=='category'){
			document.page_rec.action="newcars/category/"+replaceCharacterWithDash(document.page_rec.sCategory.value);
		}	
		
		//alert(document.page_rec.action);
		document.page_rec.submit();
	}

	function changeSortOrder(userAction, id, state, city, fromPrice, toPrice, currentPage, displayRecord, orderBy)
	{
		//alert(state);
		document.getElementById(id).href = "/servlet/CarazooController?userAction="+userAction+"&cState="+state+"&cCity="+city+"&fromPrice="+fromPrice+"&toPrice="+toPrice+"&currentPage="+currentPage+"&maxRecords="+displayRecord+"&orderBy="+orderBy;
	}
function checkBasedOnSearchType(searchType,fromVal) //changed the function signature by sreeramabrahmam on 31-10-2008 for CARAZOO-671  to identofy from where it is calling to call submit
{

 var isValid=true;
 objForm = document.newcarbyprice;
 //added by sreeramabrahmam on 31-Oct-08 for CARAZOO-671 
	if (searchType != "City"){
		 var dispCity = document.new_car_sort.dispCity.value; 
		objForm.cCity.value = dispCity;
	}
//end of adding
 if (searchType == "Price")
    {
     if(objForm.prPrice.selectedIndex == 0)
   {
   alert("Please Select a Price Range" );
   objForm.prPrice.focus();
   isValid=false;
   return false;   
   }
    }
 else if (searchType == "Body Style")
    {
     if(objForm.cBody.selectedIndex == 0)
   {
   alert("Please Select a Body Style" );
   objForm.cBody.focus();
   isValid=false;
   return false;   
   }
    }
 else if (searchType == "Category")
    {
     if(objForm.cCategory.selectedIndex == 0)
	   {
	   alert("Please Select a Category" );
	   objForm.cCategory.focus();
	   isValid=false;
	   return false;   
	   }
   }
  /*if(objForm.cState.selectedIndex == 0){
  alert("Please Select a State");
  isValid=false;
  objForm.cState.focus();
  return false;
 }*/
	else if (searchType == "City") {
		 if(objForm.cCity.selectedIndex == 0){
			  alert("Please Select a City");
			  isValid=false;
			  objForm.cCity.focus();
			  return false;
		 }
	 }
 objForm.cType.value = searchType;
 if(isValid==true)
  submitBasedOnSearchType(searchType,fromVal);//changed the function signature by sreeramabrahmam on 31-10-2008 for CARAZOO-671  to identofy from where it is calling to call submit
}//end 
 function submitBasedOnSearchType(searchType,fromVal)//changed the function signature by sreeramabrahmam on 31-10-2008 for CARAZOO-671  to identofy from where it is calling to call submit
{
	//alert(searchType);
 var obj =document;
	   if (searchType == "Price"){
          var seoQuery ="/newcars/pricerange/";
		  			 seoQuery= seoQuery + replaceSpaceWithSpace(obj.getElementById('prPrice').value) ; 
		    /* seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cState').value) + "-";
 	         seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cCity').value)  ;*/
 
	   }
	   if (searchType == "Body Style"){
            var seoQuery ="/newcars/bodystyle/";
				seoQuery= seoQuery + replaceCharacterWithDash(obj.getElementById('cBody').value) ;
		    /*seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cState').value) + "-";
 	        seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cCity').value)  ;*/
		
	   }
	   if (searchType == "Category"){
            var seoQuery ="/newcars/category/";
			seoQuery= seoQuery + replaceCharacterWithDash(obj.getElementById('cCategory').value) ;
		   /* seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cState').value) + "-";
 	        seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cCity').value) ;*/

	   }
	   
	    if (searchType == "City"){
			var seoQuery ="/newcars/city/";
			seoQuery= seoQuery + replaceCharacterWithDash(obj.getElementById('cCity').value) ;
           // var seoQuery ="/servlet/CarazooController?userAction=NEW_CAR_SEARCH_BY_PRICE&cCity=";
			//seoQuery=seoQuery+obj.getElementById('cCity').value+"&cType=City";
			/*seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cCategory').value)  + ".chm" ;
		    seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cState').value) + "-";
 	        seoQuery= seoQuery + replaceSpaceWithDash(obj.getElementById('cCity').value) ;*/

	   }
//	  alert(seoQuery);
	  document.newcarbyprice.action=seoQuery;
      document.newcarbyprice.method="post";
//      document.URL=seoQuery; //commented by sreeramabrahmam on 31-Oct-08 for CARAZOO-671  to avoid submission more than once.
     if(fromVal=='dispCity')	//added by sreeramabrahmam on 31-Oct-08 for CARAZOO-671 
    	document.newcarbyprice.submit();
}
function replaceCharacterWithDash(StringToReplace){
	var a=StringToReplace;
	a = a.replace(" ","_");
	return a;
}

function replaceSpaceWithDash(StringToReplace){
	var a=StringToReplace;
	a = a.replace(" ","-");
	return a;
}

function replaceSpaceWithSpace(StringToReplace){
	var a=StringToReplace;
	a = a.replace(" "," ");
	return a;
}


function newcar_pricerange(){
var con_ht=document.getElementById("leftCol").offsetHeight;
			var whitehe = 0;
			
			if(con_ht<315)
			{
					if(document.all)
					{
						offst=(315-con_ht)+14;
					}
					else{offst=315-con_ht;}
					whitehe=315+"px";
					document.getElementById("flbnr").style.display ="none";
					document.getElementById("flbnr1").style.display ="none";
					document.getElementById("hfbnr").style.display ="none";				
			}
			else if(con_ht>315 && con_ht<=405)
			{
					if(document.all)
					{
						offst=(405-con_ht)+14;
					}
					else{offst=405-con_ht;}
					whitehe=405+"px";
					document.getElementById("flbnr").style.display ="none";
					document.getElementById("flbnr1").style.display ="none";
					document.getElementById("hfbnr").style.display ="block";				
			}
			else if(con_ht>405 && con_ht<=520)
			{
					if(document.all)
					{
						offst=(520-con_ht)+14;
					}
					else{offst=520-con_ht;}
					whitehe=520+"px";
					document.getElementById("flbnr").style.display ="block";
					document.getElementById("flbnr1").style.display ="none";
					document.getElementById("hfbnr").style.display ="none";				
			}			
			else if(con_ht>520 && con_ht<=660)
			{
					if(document.all)
					{
						offst=(660-con_ht)+14;
					}
					else{offst=660-con_ht;}
					whitehe=660+"px";
					document.getElementById("flbnr").style.display ="block";
					document.getElementById("flbnr1").style.display ="none";
					document.getElementById("hfbnr").style.display ="block";				
			}
			else if(con_ht>645 && con_ht<=777)
			{
					if(document.all)
					{
						offst=(777-con_ht)+14;
					}
					else{offst=777-con_ht;}
					whitehe=777+"px";
					document.getElementById("flbnr").style.display ="block";
					document.getElementById("flbnr1").style.display ="block";
					document.getElementById("hfbnr").style.display ="none";				
			}
			//alert(offst);
			document.getElementById("spcdiv").style.height=offst+"px";
			document.getElementById("leftCol").style.height=whitehe;
			document.getElementById("div_bnr").style.height=whitehe;	
}
