var isIE = false; if(Prototype.Browser.IE) { var ua = navigator.userAgent, MSIEOffset = ua.indexOf("MSIE "); isIE = parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset))); }
//-------------------------------------------------------------------------------------------------------------------
var $numFld=function(o,ml,dec){ var v=$F(o), ml=ml||false; dec=dec||0; /* ***onKeyUp*** */
	var tArr = ['0-9','0-9\.'], regxp=!dec?tArr[0]:tArr[1];
	eval('var rx1 = /^['+regxp+']+$/i;'); eval('var rx2 = "[^'+regxp+']+";');
	if(!rx1.test(v)) { var rx=new RegExp(rx2,"i"), v=v.replace(rx,""); }
	if(ml){ if(v.length>ml) { v=v.substr(0,ml); } } $(o).value=v;
};
//-------------------------------------------------------------------------------------------------------------------
function register_select_account() {
	$('register-company-name','register-company-size').invoke('hide');
	if($F("e_123")==707){ // Business
		$('register-company-name','register-company-size').invoke('show');	
	}
}
function eula ( ) { if($('eula').visible()) { $('eula').hide(); } else { $('eula').show(); } }
//-------------------------------------------------------------------------------------------------------------------
<!-- winDiv -->
var winDivId="dWinDiv";
var $winDiv=function(o,options,obj) { 
	var options=options||{},
		id=options.id||winDivId,
		ls=options.ls||'s',
		cn=options.clss||'Wht'; 
	options.bOf=options.bOf||false; 
	$remWinDiv(id);
	var div=new Element('div',{'id':id}).addClassName('winDivObj').addClassName('win'+cn).hide(); 
	$(document.body).insert(div,{position:'top'}); 
	var obj=obj||{}; 
	if(false!==options.bOf){ var dims=o.getDimensions(); options.bOf ? obj.offsetTop=dims.height:obj.offsetLeft=dims.width; }
	if(o){ div.clonePosition(o,obj); } 
	div.update('Loading...'); div.show(); return div;
}

var $reposWinDiv = function(winObj,o,options){
	var dims=o.getDimensions(),options=options||{},styObj={},obj={offsetTop:dims.height}; 
	if(options.width){ obj.setWidth=false; styObj.width=options.width+'px'; }
	winObj.clonePosition(o,obj);
	if(isIE!==false && isIE<=7) { styObj.top = (o.cumulativeOffset()[1]+o.getHeight())+'px'; }
	winObj.setStyle(styObj);
}
var $remWinDiv=function(id){ var id=id||winDivId; if($(id)){ $(id).remove(); } }
//-------------------------------------------------------------------------------------------------------------------
function debugObj(o) { debug(objStr(o)); }
function alertObj(o) { var str=''; for(x in o) { str += "["+x+"] "+o[x]+"\n"; } alert(str); }
function writeObj(o) { var str=''; for(x in o) { str += "["+x+"] "+o[x]+"\n"; } d.write(str); }
function objStr(o)   { var str=''; for(x in o) { str += "["+x+"] "+o[x]+"\n<br />"; } return str; }
function debug(txt) { if ($('divDebug')==undefined) { var e = new Element('div',{id:'divDebug'}).setStyle({backgroundColor:'#FFF'}); $(document.body).insert(e,{'position':'top',zIndex:9999}); }
var t = new Element('div').update('<tt>'+txt+'</tt>'); Element.insert($('divDebug'),{"bottom":t}); };
//-------------------------------------------------------------------------------------------------------------------
//for search category
var searchCat = Class.create({
	initialize:function() { 
		this.ctn=$('dSWP'); 
		this.init(); 
		this.showWinDiv(this.ctn);
		Event.observe(document, 'click', this.docClick.bindAsEventListener(this));
		Event.observe(document, 'keydown', function(e){ if(e.keyCode==13) { e.stop(); return false; } } ); // Tabs
		Event.observe(this.ctn.select('ul')[0],  'click', this.doTabs.bindAsEventListener(this)); // Tabs
		//Event.observe($$('#dSWP ul[tabs]')[0],  'click', this.doTabs.bindAsEventListener(this)); // Tabs
		Event.observe(this.ctn.select('div')[0], 'keyup', this.doPnlKeyUp.bindAsEventListener(this)); // Input Panels
		//Event.observe($$('#dSWP div[oPnl]')[0], 'keyup', this.doPnlKeyUp.bindAsEventListener(this)); // Input Panels
	},
	init:function(){
		var liArr=this.ctn.select('ul')[0].childElements(); liArr.each(function(o,i){o.writeAttribute('idx',i)}); this.tabSel=liArr[0]; 
		//var liArr=$$('ul[tabs]')[0].childElements(); liArr.each(function(o,i){o.writeAttribute('idx',i)}); this.tabSel=liArr[0]; 
	    this.pnlArr=this.ctn.select('div')[0].childElements(); this.pnlArr.each(function(o,i){o.writeAttribute('pnl',i)});
		//this.pnlArr=$$('div[oPnl]')[0].childElements(); this.pnlArr.each(function(o,i){o.writeAttribute('pnl',i)}); 
		
	},
	
	docClick:function(e) {//alert(11);
		if(this.winObj) { this.winObj.hide(); } 
	},
	doTabs:function(e){
		var o=Event.element(e), li=o.nodeName.toUpperCase()!=='LI'?o.up("li"):o;
		if(!Object.isUndefined(li)) {
			this.tabSel.removeClassName('selected'); this.pnlArr[this.tabSel.readAttribute('idx')].hide();
			li.addClassName('selected'); this.pnlArr[li.readAttribute('idx')].show(); this.tabSel=li;
		}
	},
	doPnlKeyUp:function(e){
		var o=Event.element(e), pnl=o.nodeName.toUpperCase()!=='P'?o.up("p[pnl]"):o;
		if(!Object.isUndefined(pnl)) {
			var pnlIdx=parseInt(pnl.readAttribute("pnl"));
			switch(pnlIdx){
				default:
					if(o.nodeName.toUpperCase()=="INPUT") {
						this._search(o);
					}
			}
		}
	},
	showWinDiv:function(o){
		this.winObj = $winDiv(o,{id:'searchCat',bOf:true});
		this.winObj.addClassName('winDivClass').setStyle({minHeight:'250px',overflowX:'auto'}).hide();
	},
	_search: function(o) {
		var pObj = {fld:o.id,text:$F(o)};
		if(o.id=="_catpost") { 
			var ctn = $('srchRes');
			pObj.adtype = $F('adtype');
		} else {
			var ctn = this.winObj;
			$reposWinDiv(this.winObj,o); this.winObj.show();
		}
		new Ajax.Updater(ctn, '/_search.php',{parameters:pObj});//,onComplete:function(){$('change_main_cat').clear()}});
	},
	showMoreCats: function(o,catid) { // Show Extra Categories for _postAd
		var pObj = {fld:"_catMORE",text:$F('_catpost'),adtype:$F('adtype'),setCatid:catid};
		new Ajax.Updater(o,'/_search.php',{  parameters:pObj, insertion:Insertion.After,onSuccess:$(o).hide() });
	}
});
var searchCatObj = {}, searchCatJS = false; // true is mod activated
function searchCatInitialize ( ) {
	if(searchCatJS) { if($('dSWP')) { searchCatObj = new searchCat(); } else { searchCatInitialize.defer(); } }
}
//-------------------------------------------------------------------------------------------------------------------
var fpBanner = Class.create({
	initialize: function(){ this.nav=$('fp-nav-ul'); this.nxtExt='-1';
		Event.observe(this.nav,'click',this.doTab.bindAsEventListener(this));
		this.pObjArr=$('fpBanner').select('div.fp-panel'); this.pObjArr[0].setStyle({display:'block'});
		this.navAArr=this.nav.select('a'); this.navAArr[0].addClassName('Sel');
		var arr=window.location.toString().split("#"); this._doTab(arr[1],this.nav.select('a')[(arr[1]-1)]);
		setInterval(this.swPic.bind(this),4000);
	},
	swPic:function(){
		if($('fp1').visible()) {
			$('fp1').setStyle({backgroundImage:'url(/images/content/pic01'+this.nxtExt+'.png)'});
			this.nxtExt = this.nxtExt.empty() ? '-1' : '';
		}
	},
	doTab:function(e){ var o=Event.element(e);
		if(o.nodeName.toUpperCase()=="LI") { o=o.down('a'); } var arr=o.href.split("#"); this._doTab(arr[1],o);
	},
	_doTab:function(no,o){
		if ($('fp'+no)) {
			this.navAArr.invoke('removeClassName','Sel'); this.pObjArr.invoke('hide'); 
			$('fp'+no).setStyle({display:'block'}); o.addClassName('Sel');
		}
	}
});
var fpBannerObj = {}, pfBannerJS = false; // true is mod activated
function pfBannerInitialize ( ) {
	if(pfBannerJS) { if($('fpBanner')) { fpBannerObj = new fpBanner(); } else { pfBannerInitialize.defer(); } }
}
//-------------------------------------------------------------------------------------------------------------------

//functions for listing extra
function showPaneH() {
	$('liTabH').addClassName('exTabSelected');
	$('liTabF').removeClassName('exTabSelected');
	
	$('liSpanH').removeClassName('imgHN');
	$('liSpanH').addClassName('imgHS');
	
	$('liSpanF').removeClassName('imgFS');
	$('liSpanF').addClassName('imgFN');
	
	$('exPaneH').setStyle({display:'block'});
	$('exPaneF').setStyle({display:'none'});
	
	createCookie("MATabs","H",30,"/","",false);
	//alert(readCookie("extraTab"))
}

function showPaneF() {
	$('liTabH').removeClassName('exTabSelected');
	$('liTabF').addClassName('exTabSelected');
	
	$('liSpanH').removeClassName('imgHS');
	$('liSpanH').addClassName('imgHN');
	
	$('liSpanF').removeClassName('imgFN');
	$('liSpanF').addClassName('imgFS');
	
	$('exPaneH').setStyle({display:'none'});
	$('exPaneF').setStyle({display:'block'});
	
	createCookie("MATabs","F",30,"/","",false);
}

///////
function createCookie(n,v,d,pa,dm,se) {
	var x=new Date(),d=d||1; x.setTime( x.getTime()+((24*60*60*1000)*d) ); pa=pa||"/"; // Default
	document.cookie=n+"="+escape(v)+(x?";expires="+x.toGMTString():"")+";path="+pa+(dm?";domain="+dm:"")+(se?";secure":"");
} 

function readCookie(n) { var nEQ = n+"="; var ca = document.cookie.split(';');
	for (var i=0; i<ca.length; i++) { var c=ca[i];
		while (c.charAt(0)==' ') { c = c.substring(1,c.length); } if (c.indexOf(nEQ)==0) { return unescape(c.substring(nEQ.length,c.length)); }
	} return '';
}
function removeCookie(n) { createCookie(n,'',-1); }
function updateCookie(cn,f,v) { var j=readCookie(cn), h=$H((j.empty()?{}:j.evalJSON(true))); h.set(f,v); createCookie(cn,h.toJSON(),30); }
/////

function setMATab() {
	var tab = readCookie("MATabs"); $('exPaneH','exPaneF').invoke('hide');
	if(tab=='') { tab = "H"; }
	if(tab=='H') { showPaneH(); } else { showPaneF(); }
}

function createCookie2 (n,v,d) {
	var x=new Date(),d=d||1; x.setTime( x.getTime()+((24*60*60*1000)*d) ); // Default
	document.cookie=n+"="+escape(v)+(x?";expires="+x.toGMTString():"");

}

function phoneShow(id, url,span) {
	if(span=="u") {$('user_p_h').hide();$('user_p_s').show();}
	if(span=="a1") {$('a1_p_h').hide();$('a1_p_s').show();}
	if(span=="a2") {$('a2_p_h').hide();$('a2_p_s').show();}
	
	var site_url = "http://"+url+"/phone_view.php?id="+id;
	var aj = new Ajax.Request(  
		site_url, {  
		method:'get',   
		parameters: id,   
		onComplete: getResponse  
		}  
	);  
	
	
}

function getResponse(aj) {
	$('p_view').update(aj.responseText);
}

function showFeedback() {
	$('showFB').hide();
	$('hideFB').show();
	$('feedback').show();
}

function hideFeedback() {
	$('hideFB').hide();
	$('showFB').show();
	$('feedback').hide();
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Search Form Submit onChange ptype */
function searchForm (v,t) {
	//location.href = "/index.php?p=search&do_search=Search&type="+t+"&catid_search="+v;
	location.href = "/index.php?p=search&do_search=Search&t="+t+"&catid_search="+v;
}



//--------------------------------------------------------------------------------------------------
//testing
var testFun = Class.create({
	initialize:function() { 
		this.ctn=$('testing'); 
		this.showWinDiv(this.ctn);
	},
	showWinDiv:function(o){
		this.winObj = $winDiv(o,{id:'testFunDiv',bOf:true});
		//sthis.winObj.addClassName('winDivClass').setStyle({minHeight:'250px',overflowX:'auto'}).show();
	}
});

var testFunObj = {};
function testFunInitialize ( ) {
	if($('testing')) { var testFunObj = new testFun(); } else { testFunInitialize.defer(); }
}

//--------------------------------------------
//disable enter key from form submit
function disableEnterKey(e){
	//alert(123);
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     
     return (key != 13);
}

function chcat_type(t) {
	if(t!="") {
		location.href = "/index.php?p=choose_cat&adtype="+t;
	}
}

