// JavaScript Document

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=2", "pagenum=1")+'&pagesize=9999&sortEntity=0&SecID=0&DistID=0';
}


else {
	self.location=location+'?pagesize=9999&sortEntity=0&SecID=0&DistID=0';
}

}



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
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) {
var Pathname2 = new String(document.location.href);

if (Pathname2.indexOf("p-") !=-1) {
		
		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 jumpto() {
	document.location = document.location+"#ReviewHeader";	
}


function matchcat() {
		if (document.getElementById("youarehere").innerHTML == "grid") {

	
	if (document.location.search.indexOf("sortEntity") == -1) {
		document.getElementById("filterarea").style.display = "none";	
	}
	
	
		
		
	
		var divs = document.getElementsByTagName("a");
		
		for (i = 0; i < divs.length; i++) {
		  if (divs[i].className == "selectedcat") {
			inner = divs[i].id;
			}
		  }
		var deptname = document.getElementById(inner).id+"-dept";
		var distname = document.getElementById(inner).id+"-dist";
		if (document.getElementById(deptname) != null) {	
			document.getElementById(deptname).className="matched";
		}
		if (document.getElementById(distname) != null) {	
			document.getElementById(distname).className="matched";
		}

	if (document.location.search.indexOf("sortEntity") != -1) {
		var str3=location.search.match(/\bDistID\= *([^\&]+)/);
		var varid3=str3[1];
		var str2=location.search.match(/\bSecID\= *([^\&]+)/);
		var varid2=str2[1];
		var sorter=location.search.match(/\bsortEntity\= *([^\&]+)/);
		var varid4=sorter[1];
		var deptclearfilter = '<a href="javascript:" onclick="clearDept()" id="clearfilter"><img src="skins/Skin_1/images/clearfilter_img.gif" alt="Clear Filter" /></a>';
		var distclearfilter = '<a href="javascript:" onclick="clearDist()" id="clearfilter"><img src="skins/Skin_1/images/clearfilter_img.gif" alt="Clear Filter" /></a>';
		if (self.location.search.indexOf("sortEntity") != -1) {	

		if (varid2 != 0) {	
			document.getElementById("dep"+varid2).className = "jsover";
			//Begin Indicator
			document.getElementById("filtercontent").innerHTML = document.getElementById("dep"+varid2).innerHTML+deptclearfilter;
		}

		if (varid3 != 0) {	
			document.getElementById("dis"+varid3).className = "jsover";
			//Begin Indicator
			document.getElementById("filtercontent2").innerHTML = document.getElementById("dis"+varid3).innerHTML+distclearfilter;
			if (document.getElementById("filtercontent").innerHTML == "No Filters Selected")
				{document.getElementById("filtercontent").innerHTML = ""};
		}
	
		if (varid4 == '13') {																	
			document.getElementById('sortselector').selectedIndex = "1"
		}
		
		if (varid4 == '14') {																	
			document.getElementById('sortselector').selectedIndex = "2"
		}
	
		if (varid4 == '7') {																	
			document.getElementById('sortselector').selectedIndex = "3"
		}
		
		if (varid4 == '8') {																	
			document.getElementById('sortselector').selectedIndex = "4"
		}
	}
	
	}
	
	
	}
}
//Filter Functionality

//Filter Dept

function appenddept(dept) {
var Pathname = new String(document.location.search+'');
var url = window.location.toString();
var anchor_index = url.indexOf('&SecID');
if (Pathname.indexOf("SecID=0") !=-1) {
	self.location=location.search.replace('SecID=0', 'SecID='+dept);

}
else if (Pathname.indexOf("SecID=") !=-1) {
	var str=location.search.match(/\bSecID\= *([^\&]+)/);
	var varid2=str[1];
		self.location=location.search.replace(varid2, dept);
}
else if (Pathname.indexOf("pagenum") !=-1) {
	var pagestr=location.search.match(/\bpagenum\= *([^\&]+)/);
	var pagevarid=pagestr[1];
	self.location=location.search.replace(pagevarid, '1')+'&pagesize=9999&sortEntity=0&SecID='+dept+'&DistID=0';
}
else {
	self.location=location+'?pagesize=0&sortEntity=0&SecID='+dept+'&DistID=0';
}

}

//Filter Dept

function appenddist(dist) {
var Pathname = new String(document.location.search+'');
var url = window.location.toString();
var anchor_index = url.indexOf('&DistID');
if (Pathname.indexOf("DistID=0") !=-1) {
	self.location=location.search.replace('DistID=0', 'DistID='+dist);

}

else if (Pathname.indexOf("DistID=") !=-1) {
		self.location=location.search.replace(varid3, dist);
	var str=location.search.match(/\bDistID\= *([^\&]+)/);
	var varid3=str[1];
}


else if (Pathname.indexOf("pagenum") !=-1) {
	var pagestr=location.search.match(/\bpagenum\= *([^\&]+)/);
	var pagevarid=pagestr[1];
	self.location=location.search.replace(pagevarid, '1')+'&pagesize=9999&sortEntity=0&SecID=0&DistID='+dist;
	
}

else {
	self.location=location+'?pagesize=0&sortEntity=0&SecID=0&DistID='+dist;
}

}




//Sort By Filters

function appendsort(sortentity) {
var Pathname = new String(document.location.search+'');
var url = window.location.toString();
var anchor_index = url.indexOf('&sortEntity');

if (Pathname.indexOf("sortEntity=") !=-1) {
	var str=location.search.match(/\bsortEntity\= *([^\&]+)/);
	var varid4=str[1];
		self.location=location.search.replace(varid4, sortentity);

}
else if (Pathname.indexOf("pagenum") !=-1) {
	self.location=location+'&pagesize=0&sortEntity='+sortentity+'&SecID=0&DistID=0';
}

else {
	self.location=location+'?pagesize=0&sortEntity='+sortentity+'&SecID=0&DistID=0';
}
}



//Clear Filters
function clearDept() {
	var str=location.search.match(/\bSecID\= *([^\&]+)/);
	var varid=str[1];
	var pagestr=location.search.match(/\bpagesize\= *([^\&]+)/);
	var pagevarid=pagestr[1];
	self.location=location.search.replace(varid, 0);
}

function clearDist() {
	var str=location.search.match(/\bDistID\= *([^\&]+)/);
	var varid=str[1];
		self.location=location.search.replace(varid, 0);
}
function clearPattern() {
	var str=location.search.match(/\bSearchTerm\= *([^\&]+)/);
	var varid=str[1];
		self.location=location.search.replace(varid, 0);
}

function clearFabric () {
	var str=location.search.match(/\bSearchTerm\= *([^\&]+)/);
	var varid=str[1];
		self.location=location.search.replace(varid, 0);
}

function startList() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
function showImage(variant) {
        document.getElementById('mainimage').src = "images/VARIANT/medium/" + variant + ".jpg";
	    document.getElementById('pimage').src = "images/VARIANT/large/" + variant + ".jpg";
		document.getElementById('imagebox').style.display = "none";
		document.getElementById('imagebox2').style.display = "block";
		
		if (variant == "") {
	document.getElementById('imagebox2').style.display = "none";
	document.getElementById('imagebox').style.display = "block";
}			
}



function showpopup() {
	document.getElementById('popupimage').style.display = "block";	
}
function hidepopup() {
	document.getElementById('popupimage').style.display = "none";	
}


window.onload=function() {
	startList();
	matchcat();

}