var requestCount = 0;

function makeRequest(func_name, params, return_func) {
	
	function onErr() {	
		requestCount--;
		document.getElementById('status').innerHTML = errorRetrieving;					
	}
	
	document.getElementById('status').innerHTML = processingText;			
	
	requestCount++;
	loader = new net.ContentLoader('', return_func, func_name, params, onErr);
}

function getDomains(page,order,newList) {
	
	params = new Array;
	
	params[0] = page;
	params[1] = order;
	params[2] = document.getElementById("src").value;
	
	params[3] = document.getElementById("domain_tld").value;
	params[4] = document.getElementById("price_range").value;
	
	params[5] = document.getElementById("noIDN").checked;
	params[6] = document.getElementById("noNum").checked;
	params[7] = document.getElementById("noDash").checked;
	
	params[8] = document.getElementById("results").value;
	
	if (newList)
		params[9] = 'true';
	else 
		params[9] = 'false';
			
	makeRequest("getDomainList", params, addDomainList);
}

function addDomainList() {
	
	requestCount--;
	
	try {
		
		data = this.req.responseText;
		temp = new Array();
		temp = data.split('%$-order-$%');
	 
		orderText = temp[0];
		width = temp[1];
		pages = temp[2];
		data = temp[3];
		newSearch = temp[4];
		
		if (!data) {
			
			document.getElementById('pagesBox').innerHTML = '';
			document.getElementById('domainsBox').innerHTML = noResults;	
		}
		else {

			document.getElementById('instText').innerHTML = '<b>' + orderText + '</b>';
			document.getElementById('domainsBox').innerHTML = data;				
			
			if (newSearch == 1) {	
				
				if (pages == '') {
					
						document.getElementById('pagesBox').innerHTML = '';
				}
				else {
					
					if (document.getElementById('pagesBox').innerHTML == '') {
						
						document.getElementById('pagesBox').innerHTML = "<div id='pagesBox' style='width:500px;'><div onMouseOver='PerformScroll(1,-10);' onMouseOut='CeaseScroll();' style='float:left;margin-left:10px;margin-right:5px;'><img border=0 src='http://subasta.domainsparty.es/images/ArrowLeft.jpg' width='25' height='25'></div><div id='selBoxWork'><div id='selBoxActualContent' style='position:absolute;width:" + width + "px;' style='float:left;'>" + pages + "</div></div><div onMouseOver='PerformScroll(1,10);' onMouseOut='CeaseScroll();' style='float:left;margin-left:5px;'><img border=0 src='http://subasta.domainsparty.es/images/ArrowRight.jpg' width='25' height='25'></div></div></center>";
	
						InitialiseScrollableArea();					
						
					}
					else {
						
						document.getElementById('selBoxActualContent').style.width = width;
						document.getElementById('selBoxActualContent').innerHTML = pages;
						InitialiseScrollableArea();
					}
				}
			}
			else {
				
				i = 1;
				while (document.getElementById('page' + i)) { 
					
					if ((document.getElementById('page' + i).className == 'noStyle') && (i != pages))
						document.getElementById('page' + i).className = '';
					
					i++;	
				}
			}
		}
	}
	catch (e) {
		document.getElementById('status').innerHTML = "";		
		document.getElementById('domainsBox').innerHTML = errorProcessing;			
	}
	
	if (requestCount == 0)
		document.getElementById('status').innerHTML = "";	
}

function clearFields() {
	
	document.getElementById('src').value = "";
	document.getElementById('domain_tld').value = "";
	document.getElementById('price_range').value = "";

	document.getElementById('noIDN').checked = false;
	document.getElementById('noNum').checked = false;
	document.getElementById('noDash').checked = false;
	
	document.getElementById('results').value = "20";
}

// ----------------------------------------
// SELECTION BOX FUNCTIONS
// ----------------------------------------


function verifyCompatibleBrowser(){
    
	  this.ver = navigator.appVersion;
    this.dom = document.getElementById ? 1 : 0;
    this.ie5 = (this.ver.indexOf("MSIE 5")>-1 && this.dom) ? 1 : 0;
    this.ie4 = (document.all && !this.dom) ? 1 : 0;
    this.ns5 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
 
    this.ns4 = (document.layers && !this.dom) ? 1 : 0;
    this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns5);
    return this;
}

var initialised;
var bw = new verifyCompatibleBrowser();
var speed = 10;
var loop, timer;
 
function ConstructObject(obj, nest){
	
    nest = (!nest) ? '' : 'document.'+nest+'.';
    
    this.el = bw.dom ? document.getElementById(obj) : bw.ie4?document.all[obj] : bw.ns4 ? eval(nest+'document.'+obj) : 0;
    this.css = bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style : bw.ns4 ? eval(nest+'document.'+obj) : 0;
    this.scrollHeight = bw.ns4 ? this.css.document.height : this.el.offsetHeight;
    this.clipHeight = bw.ns4 ? this.css.clip.height : this.el.offsetHeight;
    this.up = MoveAreaUp; 
    this.down = MoveAreaDown;

    this.scrollWidth = bw.ns4 ? this.css.document.width : this.el.offsetWidth;
    this.clipWidth = bw.ns4 ? this.css.clip.width : this.el.offsetWidth;
    this.left = MoveAreaLeft;
    this.right = MoveAreaRight;

	
    this.MoveArea=MoveArea; this.x=0; this.y=0;
    this.obj = obj + "Object";
    eval(this.obj + "=this");
    return this;
}
function MoveArea(x,y){
	
    this.x = x;
    this.y = y;
    this.css.left = this.x;
    this.css.top = this.y;
}
 
function MoveAreaDown(move){
   
	if(this.y>-this.scrollHeight+objContainer.clipHeight){
		
    this.MoveArea(this.x,this.y-move);
    if(loop) 
    	setTimeout(this.obj+".down("+move+")",speed);
  }
}

function MoveAreaUp(move){
   
	 if(this.y<0){
    
	 	this.MoveArea(this.x,this.y-move);
    if(loop) 
    	setTimeout(this.obj+".up("+move+")",speed);
   }
}

function MoveAreaRight(move){
   
	 if(-this.x + objContainer.clipWidth < this.scrollWidth){
    
	 	this.MoveArea(this.x-move,this.y);
    if(loop) 
    	setTimeout(this.obj+".right("+move+")",speed);
   }
   
   window.status = "right no action " + this.x;
}

function MoveAreaLeft(move){
   
	 if(this.x<0){
    
	 	this.MoveArea(this.x-move,this.y);
    
	 	if(loop) 
    	setTimeout(this.obj+".left("+move+")",speed);
   }
   
   window.status = "left no action " + this.x;
}
 
function PerformScroll(direction,speed){
	
	if(initialised){
    loop=true;
	  
    if(direction == 0){

	  		if(speed>0) 
	  			objScroller.down(speed);
        else 
        	objScroller.up(speed);
	  }
	  else {
	      if(speed>0) 
	      	objScroller.right(speed)
        else 
        	objScroller.left(speed)
	  }
  }
}
 
function CeaseScroll(){
    
		loop=false;
    if(timer) 
    	clearTimeout(timer);
}

function InitialiseScrollableArea(){
		
    objContainer = new ConstructObject('selBoxWork');
    objScroller = new ConstructObject('selBoxActualContent','selBoxWork');
    objScroller.MoveArea(0,0);
    objContainer.css.visibility = 'visible';
    initialised=true; 
}

// ----------------------------------------
// SELECTION BOX FUNCTIONS END
// ----------------------------------------