var whichForm;
var isPostForm = 'false';

function GetXmlHttpObject(handler)
{
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

function makeChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById(whichForm + "_Model").innerHTML= xmlHttp.responseText;
	}
	else
	{
		document.getElementById(whichForm + "_Model").innerHTML= "<center><img src='http://cars.ozfreeonline.com/images/ajax-loader.gif' /></center>";
	}
	if( isPostForm == 'true' )
	{
	    if( document.PostForm.CategoryID.value != "7" )
	        document.getElementById("PostForm_Model").innerHTML = "<input name='search_model' class='fDefault' type='text' id='model' onKeyPress='return AlphaNum(event)' value='' maxlength='40'>";
	}
}

function catChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById(whichForm + "_Make").innerHTML= xmlHttp.responseText;
		document.getElementById(whichForm + "_Model").innerHTML= '<select name="search_model" style="width: 145px;" class="fDefault"><option value="">-( Select Model )-</option></select>';
	}
	else
	{
			document.getElementById(whichForm + "_Make").innerHTML= "<center><img src='http://cars.ozfreeonline.com/images/ajax-loader.gif' /></center>";
	}
	if( isPostForm == 'true' )
	{
	    if( document.PostForm.CategoryID.value != "7" )
	        document.getElementById("PostForm_Model").innerHTML = "<input name='search_model' class='fDefault' type='text' id='model' onKeyPress='return AlphaNum(event)' value='' maxlength='40'>";
	}
}

function catChanged2()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById(whichForm + "_Make").innerHTML= xmlHttp.responseText;
	}
	else
	{
			document.getElementById(whichForm + "_Make").innerHTML= "<center><img src='http://cars.ozfreeonline.com/images/ajax-loader.gif' /></center>";
	}
}

function listingsChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("cnt_category_list").innerHTML= xmlHttp.responseText;
	}
	else
	{
		document.getElementById("cnt_category_list").innerHTML= "<div style='padding-top: 30px; padding-left: 60px;'><img alt='Loading...' src='http://cars.ozfreeonline.com/images/ajax-loader.gif' /></div>";
	}
}

function doFUNC( url, qStr, func )
{
	url=url+"?"+qStr; 
	url=url+"&frm="+whichForm;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=func;

    xmlHttp.open("GET",url,true) ;
    xmlHttp.send(null);	
}

// Will populate data based on input
function htmlData(url, qStr, frm)
{
	if( frm != '') //check if there has been a specific form select menu to change
	{
		whichForm = frm;
		if( whichForm == 'PostForm' )
			isPostForm = 'true';
	}

    if (url.length==0)
    {
        alert("Can not get requested file");
		return;
    }

    xmlHttp=GetXmlHttpObject()

    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
	
	if( qStr.indexOf('cur=') >= 0 )
	{
	    doFUNC( url, qStr, catChanged2 );
	}
	else if( qStr.indexOf('category=') >= 0 )
	{
		doFUNC( url, qStr, listingsChanged );
	}
	else if( qStr.indexOf('sub=') >= 0 )
	{
		doFUNC( url, qStr, makeChanged );	
	}
	else if( qStr.indexOf('cat=') >= 0 )
	{
		doFUNC( url, qStr, catChanged );
	}
}

/*--------------------------------------------
 *  (c) 2007 CrossBrowserAjax, version 1.10
 *  Type: Compressed
 *--------------------------------------------*/
function cbaDOM(){
	this.removeElement=function(_element){
    	_element.parentNode.removeChild(_element);
    };
    this.createElement=function(_parent,_type,_property,_text){
	    var el=document.createElement(_type);
        for(var k in _property){
    		var keys=k.split('.');
	    	if(keys.length==2){
			    el[keys[0]][keys[1]]=_property[k];
        	}
	        else{
    	    	el[k]=_property[k];
        	}
        }
       	if(_text!='')
        	el.innerHTML=_text;
            _parent.appendChild(el);
        return el;
    };
    this.createScript=function(_parent,_id,_request){
						  var span=this.createElement(_parent,'span',{'style.display':'none','id':_id},'%<s'+'cript></'+'script>');
                          setTimeout(function(){
                          		var _script=span.getElementsByTagName('script')[0];_script.type='text/javascript';_script.src=_request;
                                },5);

	}
}

function cbaCache(buffer_size,length_ct){
	this._rct=function(_request,_length){
    	var control=0;
    	var start=Math.floor(_request.length/_length);
        if(start<1)start=1;
        for(var i=_request.length;i>0;i-=start){
        control+='                                  !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~???S??Z???s??zY ???ค?ฆง?ฉ?ซฌญฎ?ฐฑ???ตถท???ป????AAAAAA?CEEEEIIII?NOOOOO?OUUUUY??aaaaaa?ceeeeiiii?nooooo?ouuuuy?y'.indexOf(_request.charAt(i));}return control;};this._search=function(_request){var _hash=this._rct(_request,this._length_ct);for(i in this._cache){if(this._cache[i][0]==_hash&&this._cache[i][1]==_request){this._search_buffer=this._data_cache[i];return true;}}return false;};this._add=function(_request,_data){if(this._cache_index>=this._buffer_size){this._cache_index=0;}var _hash=this._rct(_request,this._length_ct);this._cache[this._cache_index]=[_hash,_request];this._data_cache[this._cache_index]=_data;this._cache_index++;};this._init=function(buffer_size,length_ct){this._buffer_size=buffer_size;this._length_ct=length_ct;this._cache=new Array();this._data_cache=new Array();this._cache_index=0;this._search_buffer=null;};this._init(buffer_size,length_ct);}function cbaRequest(){this._init=function(){this._handler_error=true;if(this._handler_error){window.onerror=this.cbaJsError;}this._parent_id_name='_cba_parent_id';this._url_id='_cba_request_id';this._id_prefix='_cba_pack_';this.dom=new cbaDOM();this._parent_element=this.createParentElement();this._requests=new Array();this._caching_enabled=true;if(this._caching_enabled){this._buffer_size=25;this._length_ct=100;this.cache=new cbaCache(this._buffer_size,this._length_ct);}};this.cbaJsError=function(_message,_url,_line){var _file="File: "+_url+" :: "+_line+"\n";var _title="There was an error on this page.\n--------------------------\n";var _error=_title;_error+="Error: "+_message+"\n";_error+=_file;if(_message.indexOf('unterminated string literal')+_message.indexOf('missing ;')+_message.indexOf('Syntax error')>-3){_error+='--------------------------\nRecommendation:\n   Check response from the server.\n   He may return incorrect JavaScrip.';}alert(_error);};this.createParentElement=function(){if(document.getElementById(this._parent_id_name)){return document.getElementById(this._parent_id_name);}else{return this.dom.createElement(document.body,'div',{'id':this._parent_id_name},'');}};this.query=function(_url,_callback){if(arguments.length>2){var _use_cache=arguments[2];}else{var _use_cache=true;};if(_use_cache&&(this.cache&&this.cache._search(_url))){this.answer=this.cache._search_buffer;if(_callback instanceof Function)_callback();}else{var _id=this._requests.push({'callback':_callback,'request':_url})-1;if(_url.indexOf('?')==-1){_url+='?';}else{_url+='&';};_url+=this._url_id+'='+_id;this.dom.createScript(this._parent_element,this._id_prefix+_id,_url);}};this.ready=function(_id,_result){this.answer=_result;if(this.cache)this.cache._add(this._requests[_id].request,_result);if(this._requests[_id].callback instanceof Function)this._requests[_id].callback();if(document.getElementById(this._id_prefix+_id)){this.dom.removeElement(document.getElementById(this._id_prefix+_id));}delete(this._requests[_id]);};this._init(arguments);}var _cba=null;
        
    function cbaUpdateElement(_doc_id,_url){
    	var _loading_text=(arguments[2])?arguments[2]:'Loading...';
        var _caching=(arguments.length>3)?arguments[3]:true;
        var _template=(arguments[4])?arguments[4]:'%1';
        var _error_template=(arguments[5])?arguments[5]:null;
        var _user_method=(arguments[6])?arguments[6]:null;

		var xcatContent = getCategory(_url);
        var xcatImage   = getImage(_url);

        if(_loading_text)document.getElementById(_doc_id).innerHTML=_loading_text;
        	if(!_cba)_cba=new cbaRequest();
            _cba.query(_url,function(){
            					if((_error_template)&&_cba.answer==_error_template[0]){
                                		document.getElementById(_doc_id).innerHTML=_error_template[1];
                                }
                                else{
                                	if(typeof(_cba.answer)=='object'){
                                    	var _result=_template;
                                        for(key in _cba.answer){
                                           _result=_result.replace('%'+key+'%',_cba.answer[key]);
                                        }         
                                        
                                        var catContent = document.getElementById("categoryLoad");
                                        var catImage   = document.getElementById("categoryImage");
                                        if(catImage){
                                            catImage.innerHTML = xcatImage;
                                        }
                                        if(catContent){
                                            catContent.innerHTML = xcatContent;	
                                        }
                                        document.getElementById(_doc_id).innerHTML=_result;
                                    
                                    }
                                else{
                                	document.getElementById(_doc_id).innerHTML=_template.replace('%1',_cba.answer);
                                }
             };
        if(_user_method&&_user_method instanceof Function)_user_method();},_caching);}

function getData(target, url, param, template, text, cache) {
	if(template == undefined) template = '%content%';
	text = "<div style='padding-top: 30px; padding-left: 60px;'><img alt='Loading...' src='http://cars.ozfreeonline.com/images/ajax-loader.gif' /></div>";
	if(cache == undefined) cache = true;
	if(param != undefined) url = url + '?' + param;
	cbaUpdateElement(target, url, text, cache, template);
}


function getCategory(_url){
	var xpos = _url.lastIndexOf("=");
	xpos = xpos +1;
	var xCat = _url.substring(xpos);

	ret = getDisplayCategory(xCat);
	
	return ret;
}


function getImage(_url){
	var xpos = _url.lastIndexOf("=");
	xpos = xpos +1;
	var xCat = _url.substring(xpos);

	ret = getDisplayImage(xCat);
	
	return ret;
}

function getDisplayImage(strCategory){
	
    switch(strCategory){
        case 'Motorcycles':
            xxCateg = "<div><img src='../images/sell_your_motorcycle.jpg'/></div>";
            break;
            
        case 'Passenger Vehicles':
            xxCateg = "<div><img src='../images/sell_your_car.jpg'/></div>";
            break;
            
        case 'Caravans/Motor Homes':
            xxCateg = "<div><img src='../images/sell_your_carvan.jpg'/></div>";
            break;
            
        case 'Classic/Muscle Cars':
            xxCateg = "<div><img src='../images/sell_your_classic_car.jpg'/></div>";
            break;            
            
        case 'Commercial Vehicles':
            xxCateg = "<div><img src='../images/sell_your_comcar.jpg'/></div>";
            break;            
    
        }
    
        return xxCateg;
}


function getDisplayCategory(strCategory){

	switch(strCategory){
		case 'Motorcycles':
			xxCateg = "<div><strong class='f3E8290'>OzFreeOnline - Place for great car deals for the best value for your money.</strong><br></div>";
            xxCateg = xxCateg + "<br> A huge number of listings of new and used motorcycles from any model/make is available for browsing and free car";
            xxCateg = xxCateg + " classified advertising is offered to those who are selling cars, motorcycles, motorhomes or any kind of vehicle.";
            xxCateg = xxCateg + "<br><br>Feel free to browse all of the pictures of motorcycles for sale that are waiting for you to take them home.";
            xxCateg = xxCateg + "<br><br>So what are you waiting for? Visit <strong class='f3E8290'>OzFreeOnline</strong> now to find your dream ride or";
			xxCateg = xxCateg + "<a href='http://cars.ozfreeonline.com/r1.php'><strong class='f3E8290'> Register</strong></a>"; 
			xxCateg = xxCateg + " for free to get your car for sale advertised for free..";            

			break;
            
		case 'Passenger Vehicles':
			xxCateg = "<div><strong class='f3E8290'>OzFreeOnline - Place for great car deals for the best value for your money.</strong><br></div>";
            xxCateg = xxCateg + "<br>Browse a huge range of free car listing of all the available new or used cars for sale in <strong class='f3E8290'>";
            xxCateg = xxCateg + " Brisbane, Perth, Queensland, Melbourne, Adelaide</strong> or any parts of Australia.";
            xxCateg = xxCateg + " Compare used car values and pricing of automobiles sold by car auctions, individual owners and car dealers.";
            xxCateg = xxCateg + "<br><br> Get the car that would best suit your taste and would fit for your budget."; 
			xxCateg = xxCateg + "<br><br>Free car advertising if you sell cars- get that car for sale advertised nationwide to get more potential";
			xxCateg = xxCateg + " buyers to see it and get it sold fast.<br />";
			xxCateg = xxCateg + "<a href='http://cars.ozfreeonline.com/r1.php'><strong class='f3E8290'>Register</strong></a>";
			xxCateg = xxCateg + " now to avail all of these great services for FREE.";
			break;
            
		case 'Caravans/Motor Homes':
			xxCateg = "<div><strong class='f3E8290'>OzFreeOnline - Place for great car deals for the best value for your money.</strong><br></div>";
            xxCateg = xxCateg + "<br><strong class='f3E8290'>Search for quality yet affordable</strong> motorhomes and caravans that are listed with";
            xxCateg = xxCateg + "<strong class='f3E8290'> OzFreeOnline.</strong>";
            xxCateg = xxCateg + " All used caravans come with everything you need to know to decide if this is the caravan/motorhome that you";
            xxCateg = xxCateg + " would drive home with-cars pricing, features, description and the location where you can locate them.";
			xxCateg = xxCateg + "<br><br>You can also take advantage of car advertising for free that will be posted <strong class='f3E8290'>nationwide.";
  			xxCateg = xxCateg + " All </strong> you have to do is to <a href='http://cars.ozfreeonline.com/r1.php'><strong class='f3E8290'>Register</strong></a>";
            xxCateg = xxCateg + " for free to avail all of these great services.";
			break;
            
		case 'Classic/Muscle Cars':
			xxCateg = "<div><strong class='f3E8290'>OzFreeOnline - Place for great car deals for the best value for your money.</strong><br></div>";
            xxCateg = xxCateg + "<br>Love modifying or fixing vintage and used cars but having a hard time to locate one?";
            xxCateg = xxCateg + " Well worry no more for OzFreeOnline presents you with a free car listing of all the classic and muscle cars";
            xxCateg = xxCateg + "  that are available for sale in Australia.";
            xxCateg = xxCateg + "<br><br> Whether you are looking for a vintage car to fix, a used car or a muscle to modify, a classic car to";
            xxCateg = xxCateg + " <strong class='f3E8290'>renovate</strong>,";
            xxCateg = xxCateg + " as long as it is available in Australia, it is in OzFreeOnline's classified ads.";
            xxCateg = xxCateg + "<br><br>You can also get your car for sale advertised nationwide for free just by";
            xxCateg = xxCateg + " <a href='http://cars.ozfreeonline.com/r1.php'><strong class='f3E8290'>registering</strong></a> once.";
            xxCateg = xxCateg + " Enjoy all of these great and free car services just by visiting the place for great car deals <strong class='f3E8290'>and";
            xxCateg = xxCateg + " services- OzFreeOnline</strong>.";            
			break;        
            
		case 'Commercial Vehicles':
			xxCateg = "<div><strong class='f3E8290'>OzFreeOnline - Place for great car deals for the best value for your money.</strong><br></div>";
            xxCateg = xxCateg + "<br>If you are having a hard time deciding in which utility car would be best for your interest then you came to the right place.";
            xxCateg = xxCateg + " You may <a href='http://cars.ozfreeonline.com/advanced.php'><strong class='f3E8290'>search</strong></a> all of";
            xxCateg = xxCateg + " <strong class='f3E8290'>OzFreeOnline's</strong> available commercial vehicles and choose from a wide selection ";
            xxCateg = xxCateg + "<strong class='f3E8290'>for a vehicle that best suits</strong> your needs.";
            xxCateg = xxCateg + "<br><br>Cars for sale are posted with their description, features and cars pricing to help you decide easier in which vehicle";
            xxCateg = xxCateg + " would fit your lifestyle and your budget.";
			xxCateg = xxCateg + "<br><br>You may also place cars classifieds for free in any of the category that your car for sale fits into. ";
            xxCateg = xxCateg + " Avail all of this great and free car services just by ";
            xxCateg = xxCateg + "<a href='http://cars.ozfreeonline.com/r1.php'><strong class='f3E8290'>registering</strong></a> once.";            
			break;            

	}

	return xxCateg;

}





