//
function getXmlHttpRequestObjectNew() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser Sucks!\nIt's about time to upgrade don't you think?");
	}
}
var PTH	=	'/'

var newList = getXmlHttpRequestObjectNew();
///
///searchReq.open("GET", window.location.protocol + '//' + window.location.hostname+'/YoYoDevelopment/suggest/searchSuggest.php?search=' + str, true);		
///

function ListPrds(prods,pgno,atts){
	pg		=	parseInt(pgno)
	if(isNaN(pg)){
		alert("Error 1")
		return false
	}
	if(pg <= 0){
		pg	=	1
	}		
   txtara			=	document.filtero.optionopted
   limit			=	document.filtero.rpp.value
   sort_ord			=	document.filtero.sort_ord.value   
   str	=	'?products_filtered='+prods+'&pg='+pg+'&attributes='+atts+'&sort_ord='+sort_ord+'&limit='+limit	
   txtara.value	= window.location.protocol + '//' + window.location.hostname+'/catprods.php' + str + '&pageis='+popen
   var ss = document.getElementById('ListingDiv')
   ss.innerHTML = '<p align="center"><br>Loading Products List...<br><img src="preload/bigload.gif"></p>'; 
   var ss2 = document.getElementById('attloader')
   ss2.innerHTML = '';//'<p align="center"><br>Loading products filter...<br><img src="preload/smallload.gif"></p>';    
   newList.open("GET", window.location.protocol + '//' + window.location.hostname+'/catprods.php' + str + '&pageis='+popen, true);			
   newList.onreadystatechange = populateListings; 
   newList.send(null);   
	
}
function ListCategoryProducts(categoryid,pgno,atts){
	catid	=	parseInt(categoryid)
	pg		=	parseInt(pgno)
	if(isNaN(catid) || isNaN(pg)){
		alert("Error 1")
		return false
	}
	if(catid <= 0){
		alert("Error 2")
		return false
	}
	if(pg <= 0){
		pg	=	1
	}		
   txtara			=	document.filtero.optionopted
   limit			=	document.filtero.rpp.value
   sort_ord			=	document.filtero.sort_ord.value
   if(catid==80808080){
	 str	=	'?catid='+catid+'&products_filtered='+document.filtero.productsSelected.value+'&pg='+pg+'&attributes='+atts+'&sort_ord='+sort_ord+'&limit='+limit	  
   }else{
	 if(document.getElementById("productsSelected")!=null){
		str	=	'?catid='+catid+'&products_filtered='+document.filtero.productsSelected.value+'&pg='+pg+'&attributes='+atts+'&sort_ord='+sort_ord+'&limit='+limit	  		 
	 }else{
     str	=	'?catid='+catid+'&pg='+pg+'&attributes='+atts+'&sort_ord='+sort_ord+'&limit='+limit	
	 }
   }
   
   txtara.value	= window.location.protocol + '//' + window.location.hostname+'/catprods.php' + str + '&pageis='+popen
   var ss = document.getElementById('ListingDiv')
   ss.innerHTML = '<p align="center"><br>Loading Products List...<br><img src="preload/bigload.gif"></p>'; 
   var ss2 = document.getElementById('attloader')
   ss2.innerHTML = '';//'<p align="center"><br>Loading products filter...<br><img src="preload/smallload.gif"></p>';    
   newList.open("GET", window.location.protocol + '//' + window.location.hostname+'/catprods.php' + str + '&pageis='+popen, true);			
   newList.onreadystatechange = populateListings; 
   newList.send(null);   
}

function populateListings(){
	if (newList.readyState == 4) {
		var ss = document.getElementById('ListingDiv')
		ss.innerHTML = '';
		ss.innerHTML=newList.responseText
		pidlisted	=	document.getElementById("ProductsListedHere").value
		
			if(pidlisted!=''){
				setAttributes(pidlisted)
			}
	}
}

function setOpt(){
	
	fopt			=	document.filtero.filterOptions
	categoryid		=	document.filtero.cci.value
	if(document.filtero.TOTSEL!=null){
	TOTSEL			=	document.filtero.TOTSEL.value
	}else{
		TOTSEL=0
	}

	pgno			=	1
	atts			=	''
	if(fopt!=null){
	foptlen			=	fopt.length
	
	alreadyopted	=	document.filtero.opt.value
	//alert(foptlen)
	if(TOTSEL==1){
		v	=	fopt.value
		////////////////////////////////////////////////////////////////////////////////
		if(v=='-100'){
		}else{
			if(alreadyopted.indexOf(v)==-1){
				varr	=	v.split("^^^")
				v2show	=	varr[1]
				document.getElementById("selectHolder0").style.display="none"
				document.getElementById("selectValue0").style.display="block"
				b='<br><a href="javascript;" onclick="removeValue(\''+v+'\',0);return false;" style="color:#ffffff;width:120px;">Change</a>'
				document.getElementById("selectValue0").innerHTML=v2show + b
				
			atts+=v+"~~~"
			}else{
			}
		}
		////////////////////////////////////////////////////////////////////////////////
	}else{
		for(i=0;i<foptlen;i++){
		v	=	fopt[i].value		
		if(v=='-100'){
		}else{
			if(alreadyopted.indexOf(v)==-1){
				varr	=	v.split("^^^")
				v2show	=	varr[1]
				document.getElementById("selectHolder"+i).style.display="none"
				document.getElementById("selectValue"+i).style.display="block"
				b='<br><a href="javascript;" onclick="removeValue(\''+v+'\','+i+');return false;" style="color:#ffffff;width:120px;">Change</a>'
				document.getElementById("selectValue"+i).innerHTML=v2show + b
				
			atts+=v+"~~~"
			}else{
			}
		}
	}
	}
	document.filtero.opt.value	=	document.filtero.opt.value + atts
	atts						=	document.filtero.opt.value
	}
	ListCategoryProducts(categoryid,pgno,atts)
}

function removeValue(val,ind){
	val+="~~~"
	alreadyopted					=	document.filtero.opt.value	
	alreadyopted					=	alreadyopted.replace(val,"")
	document.filtero.opt.value		=	alreadyopted
	//document.getElementById("selectHolder"+ind).style.display="block"
	//document.getElementById("selectValue"+ind).style.display="none"	
	//document.filtero.filterOptions[ind].value=-100
	setOpt()
}

function setAttributes(pids){
	if(pids	==	''){
		return false
	}

   alreadyopted					=	document.filtero.opt.value	
   var ss = document.getElementById('attloader')
   ss.innerHTML = '<p align="center"><br>Loading products filter...<br><img src="preload/smallload.gif"></p>';      
   newList.open("GET", window.location.protocol + '//' + window.location.hostname+'/attsfill.php?cci='+document.filtero.cci.value+'&alreadyopted='+alreadyopted+'&pids=' + pids, true);			
   newList.onreadystatechange = populateAtts; 
   newList.send(null); 	
	
}


function populateAtts(){
	if (newList.readyState == 4) {
		var ss = document.getElementById('attloader')
		ss.innerHTML = '';
		ss.innerHTML=newList.responseText
	}	
}