// JavaScript Document

//Sort by Price

function appendprice(PriceRange) {
var Pathname = new String(document.location.search+'');
var url = window.location.toString();
var anchor_index = url.indexOf('&MinPrice');
if (Pathname.indexOf("MinPrice=") !=-1) {
	
	if (Pathname.indexOf("pagesize=9999&MinPrice=0000&MaxPrice=9999") !=-1) {
	
	self.location=location.search.replace(/pagesize=9999&MinPrice=0000&MaxPrice=9999/, PriceRange);
	
	}

	if (Pathname.indexOf("MinPrice=0000&MaxPrice=9999") !=-1) {
	
	self.location=location.search.replace(/MinPrice=0000&MaxPrice=9999/, PriceRange);
	
	}


	if (Pathname.indexOf("pagesize=9999&MinPrice=0000&MaxPrice=0100") !=-1) {
	
	self.location=location.search.replace(/pagesize=9999&MinPrice=0000&MaxPrice=0100/, PriceRange);
	
	}

	if (Pathname.indexOf("pagesize=9999&MinPrice=0100&MaxPrice=0200") !=-1) {
	self.location=location.search.replace(/pagesize=9999&MinPrice=0100&MaxPrice=0200/, PriceRange);
	}

	if (Pathname.indexOf("pagesize=9999&MinPrice=0200&MaxPrice=0400") !=-1) {
	
	self.location=location.search.replace(/pagesize=9999&MinPrice=0200&MaxPrice=0400/, PriceRange);
	
	}
	
}
else if (Pathname.indexOf("ManID") !=-1) {
	self.location=location.search+'&'+PriceRange;
}
else if (Pathname.indexOf("pagenum") !=-1) {
	var str=location.search.match(/\bpagenum\= *([^\&]+)/);
	var varid3=str[1];
	self.location=location.search.replace("pagenum="+varid3, "pagenum=1")+'&'+PriceRange;
}
else if (Pathname.indexOf("?") !=-1) {
	self.location=location.search+PriceRange;
}


else {
	self.location=location+'?'+PriceRange;
}

}

//Sort By Filters
function appendsort() {
var Pathname = new String(document.location.search+'');
	
	if (document.getElementById('sortselector').value == "Name") {	
		if (Pathname.indexOf("sortEntity=14") !=-1) {

		self.location=location.search.replace(/14/, '13');
		
		}
		else if (Pathname.indexOf("sortEntity=13") !=-1) {
		
		self.location=location.search.replace(/13/, '14');
		
		}
	
		else {
			self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+'?sortEntity=14';
			}
		
	}

	if (document.getElementById('sortselector').value == "Price") {	
		if (Pathname.indexOf("sortEntity=7") !=-1) {
		
		self.location=location.search.replace(/7/, '8');
		
		}
		else if (Pathname.indexOf("sortEntity=8") !=-1) {
		
		self.location=location.search.replace(/8/, '7');
		
		}
		else {
			self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+'?sortEntity=8';
			}
	}
	

}


function resetsort() {
	var str2=location.search.match(/\bsortEntity\= *([^\&]+)/);
	var varid2=str2[1];
	
	
	document.getElementById('sortarrow').src = "skins/Skin_1/images/up-arrow.gif";
	if (document.getElementById('sortselector').value == "Name") {	
		self.location=location.search.replace("sortEntity="+varid2, "sortEntity=13");
	}
	else if (document.getElementById('sortselector').value == "Price") {	
		self.location=location.search.replace("sortEntity="+varid2, "sortEntity=7");
	}


}



function checksort() {
	if (self.location.search.indexOf('13') != -1) {																	
		document.getElementById('sortarrow').src = "skins/Skin_1/images/up-arrow.gif";
		document.getElementById('sortselector').value = "Name"
	}
	
	else if (self.location.search.indexOf('14') != -1) {																	
		document.getElementById('sortarrow').src = "skins/Skin_1/images/down-arrow.gif";
		document.getElementById('sortselector').value = "Name"
	}

	else if (self.location.search.indexOf('7') != -1) {																	
		document.getElementById('sortarrow').src = "skins/Skin_1/images/up-arrow.gif";
		document.getElementById('sortselector').value = "Price"
	}
	
	else if (self.location.search.indexOf('8') != -1) {																	
		document.getElementById('sortarrow').src = "skins/Skin_1/images/down-arrow.gif";
		document.getElementById('sortselector').value = "Price"
	}

}


function appendsort2(sortentity) {
var Pathname = new String(document.location.search+'');

	if (Pathname.indexOf("sortEntity=") !=-1) {
		
		if (Pathname.indexOf("sortEntity=7") !=-1) {
		
		self.location=location.search.replace(/7/, sortentity);
		
		}
	
		if (Pathname.indexOf("sortEntity=8") !=-1) {
		
		self.location=location.search.replace(/8/, sortentity);
		
		}
	
		if (Pathname.indexOf("sortEntity=9") !=-1) {
		
		self.location=location.search.replace(/9/, sortentity);
		
		}
	
	
		if (Pathname.indexOf("sortEntity=10") !=-1) {
		
		self.location=location.search.replace(/10/, sortentity);
		
		}
	
	
		if (Pathname.indexOf("sortEntity=11") !=-1) {
		
		self.location=location.search.replace(/11/, sortentity);
		
		}
	
		if (Pathname.indexOf("sortEntity=12") !=-1) {
		
		self.location=location.search.replace(/12/, sortentity);
		
		}
	
		if (Pathname.indexOf("sortEntity=13") !=-1) {
		
		self.location=location.search.replace(/13/, sortentity);
		
		}
	
	
		if (Pathname.indexOf("sortEntity=14") !=-1) {
		
		self.location=location.search.replace(/14/, sortentity);
		
		}
	
	
		if (Pathname.indexOf("sortEntity=15") !=-1) {
		
		self.location=location.search.replace(/15/, sortentity);
		
		}
	
		if (Pathname.indexOf("sortEntity=16") !=-1) {
		
		self.location=location.search.replace(/16/, sortentity);
		
		}
	
		if (Pathname.indexOf("sortEntity=17") !=-1) {
		
		self.location=location.search.replace(/17/, sortentity);
		
		}
	
	
		if (Pathname.indexOf("sortEntity=18") !=-1) {
		
		self.location=location.search.replace(/18/, sortentity);
		
		}
	
	
	
	
	
	}
	
	else if (Pathname.indexOf("SearchTerm") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&sortEntity='+sortentity;
	}

	else if (Pathname.indexOf("DistID") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&sortEntity='+sortentity;
	}

	else if (Pathname.indexOf("ManID") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&sortEntity='+sortentity;
	}
	else if (Pathname.indexOf("SecID") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&sortEntity='+sortentity;
	}
	else if (Pathname.indexOf("pagesize") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&sortEntity='+sortentity;
	}
	else {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+'?sortEntity='+sortentity;
	}


}


function appendpagesize(sortentity) {
var Pathname = new String(document.location.search+'');

	
	if (Pathname.indexOf("SearchTerm") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&pagesize='+sortentity;
	}

	else if (Pathname.indexOf("DistID") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&pagesize='+sortentity;
	}

	else if (Pathname.indexOf("ManID") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&pagesize='+sortentity;
	}
	else if (Pathname.indexOf("SecID") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&pagesize='+sortentity;
	}
	else if (Pathname.indexOf("pagesize") !=-1) {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+self.location.search+'&pagesize='+sortentity;
	}
	else {
		self.location=self.location.protocol+'//'+self.location.host+self.location.pathname+'?pagesize='+sortentity;
	}


}

function hideAllDivsFirst() {
		faqD = document.getElementsByTagName('div');
		for(var i=0;i<faqD.length;i++) {
			if(faqD[i].className=="faqTab") {
				faqD[i].style.display = "none";
			}
		}
	}
	function showFAQ(which) {
		hideAllDivsFirst();
		targetDivName = "faq_"+which;
		tabLiName = "tab_"+which;
		document.getElementById(targetDivName).style.display = "block";
	}
	function swapTopTab(whichID,onoff) {
		if(document.getElementById(whichID).className=="tab_sub") document.getElementById(whichID).className = "tab_sub_over";
		else if(document.getElementById(whichID).className=="tab_sub_over") document.getElementById(whichID).className = "tab_sub";
	}
	function hilite(tID) {
if (document.location.pathname.indexOf("p-") !=-1) {
		var Pathname = new String(document.location.search+'');

		var allD = document.getElementsByTagName('li');
		for(var j=0;j<allD.length;j++) {
			if(allD[j].className=="tab_sub_selected") {
				allD[j].className = "tab_sub";
			}
		}
		var targetContentDiv = tID.split("_")[1];
		document.getElementById(tID).className = "tab_sub_selected";
		showFAQ(targetContentDiv);
	}
	}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function appendman(man) {
var Pathname = new String(document.location.search+'');
var url = window.location.toString();
var anchor_index = url.indexOf('&ManID');
if (Pathname.indexOf("ManID=0") !=-1) {
	self.location=location.search.replace('ManID=0', 'ManID='+man);

}

else if (Pathname.indexOf("ManID=") !=-1) {
		self.location=location.search.replace(varid3, man);
	var str=location.search.match(/\bManID\= *([^\&]+)/);
	var varid3=str[1];
}



else if (Pathname.indexOf("sortEntity") !=-1) {
	self.location=location+'&ManID='+man;
	
}

else if (Pathname.indexOf("MaxPrice") !=-1) {
	self.location=location+'&ManID='+man;
	
}
else if (Pathname.indexOf("pagenum") !=-1) {
	var str=location.search.match(/\bpagenum\= *([^\&]+)/);
	var varid3=str[1];
	self.location=location.search.replace("pagenum="+varid3, "pagenum=1")+'&ManID='+man;
	
}


else {
	self.location=location+'?ManID='+man;
}

}

//Clear Filters
function clearMan() {
	var str=location.search.match(/\bManID\= *([^\&]+)/);
	var varid=str[1];
		self.location=location.search.replace(varid, 0);
}
function clearMinPrice() {
	var str=location.search.match(/\bMinPrice\= *([^\&]+)/);
	var varid=str[1];

	self.location=location.search.replace('&pagesize=9999&MinPrice='+varid, '');
}

function clearMaxPrice() {
	var strMin=location.search.match(/\bMinPrice\= *([^\&]+)/);
	var varidMin=strMin[1];

	var strMax=location.search.match(/\bMaxPrice\= *([^\&]+)/);
	var varidMax=strMax[1];

	self.location=location.search.replace('pagesize=9999&MinPrice='+varidMin+'&MaxPrice='+varidMax, 'MinPrice=0000&MaxPrice=9999');
}

function editMinPrice() {
	var Pathname = new String(document.location.search+'');
	if (document.getElementById("filtercontent2")!=null) {
		var str=document.getElementById("filtercontent2").innerHTML;
		if (document.getElementById("filtercontent2").innerHTML=='0000') {
			document.getElementById("filtercontent2").innerHTML=document.getElementById("filtercontent2").innerHTML.replace("0000", "$0");
		}
		if (document.getElementById("filtercontent2").innerHTML=='0100') {
			document.getElementById("filtercontent2").innerHTML=document.getElementById("filtercontent2").innerHTML.replace("0100", "$100");
		}
		if (document.getElementById("filtercontent2").innerHTML=='0200') {
			document.getElementById("filtercontent2").innerHTML=document.getElementById("filtercontent2").innerHTML.replace("0200", "$200");
		}


	}
}
function editMaxPrice() {
	var Pathname = new String(document.location.search+'');
	if (document.getElementById("filtercontent3")!=null) {
		var str=document.getElementById("filtercontent3").innerHTML;
		if (document.getElementById("filtercontent3").innerHTML=='0100') {
			document.getElementById("filtercontent3").innerHTML=document.getElementById("filtercontent3").innerHTML.replace("0100", "$100");
		}
		if (document.getElementById("filtercontent3").innerHTML=='0200') {
			document.getElementById("filtercontent3").innerHTML=document.getElementById("filtercontent3").innerHTML.replace("0200", "$200");
		}
		if (document.getElementById("filtercontent3").innerHTML=='0400') {
			document.getElementById("filtercontent3").innerHTML=document.getElementById("filtercontent3").innerHTML.replace("0400", "$400");
		}
	}
}

function appendpagenumber(pagenumber) {
var Pathname = new String(document.location.search+'');
var url = window.location.toString();
var anchor_index = url.indexOf('&pagenum');

if (Pathname.indexOf("pagenum=") !=-1) {
	var str=location.search.match(/\bpagenum\= *([^\&]+)/);
	var varid4=str[1];
		self.location=location.search.replace('pagenum='+varid4, 'pagenum='+pagenumber);

}
else if (Pathname.indexOf("ManID") !=-1) {
	self.location=location+'&pagenum='+pagenumber;
}
else if (Pathname.indexOf("SecID") !=-1) {
	self.location=location+'&pagenum='+pagenumber;
}
else if (Pathname.indexOf("SearchTerm") !=-1) {
	self.location=location+'&pagenum='+pagenumber;
}
else if (Pathname.indexOf("sortEntity") !=-1) {
	self.location=location+'&pagenum='+pagenumber;
}

else {
	self.location=location+'?pagenum='+pagenumber;
}
}
function viewall() {
var Pathname = new String(document.location.search+'');
var url = window.location.toString();
var anchor_index = url.indexOf('&DistID');
if (Pathname.indexOf("pagesize=") !=-1) {

	var str=location.search.match(/\bpagesize\= *([^\&]+)/);
	var varid1=str[1];
self.location=location.search.replace(varid1, 9999);

}

else if (Pathname.indexOf("pagenum") !=-1) {
	var str2=location.search.match(/\bpagenum\= *([^\&]+)/);
	var varid5=str2[1];

	self.location=location.search.replace("pagenum=", "")+'&pagesize=9999';
}

else if (Pathname.indexOf("sortEntity") !=-1) {
	self.location=location+'&pagesize=9999';
}
else if (Pathname.indexOf("ManID") !=-1) {
	self.location=location+'&pagesize=9999';
}

else {
	self.location=location+'?pagesize=9999';
}

}

window.onload=function() {
	checksort();
	editMinPrice();
	editMaxPrice();
}
