<!--//
//Hide/Show Script Based Items
function s_h () {
	
	allTags = document.getElementsByTagName('*');
	
	totalTags = allTags.length;
	
	for (i=0; i<totalTags; i++) {
		
		currentTag = allTags[i];
		
		tagClass = currentTag.className;
		
		
		if (tagClass.indexOf('s_h') != -1) {
			
			currentTag.style.display = 'none';
			
		}
		
		
		
	}
	
}

function s_t_s () {
	
	allTags = document.getElementsByTagName('*');
	
	totalTags = allTags.length;
	
	for (i=0; i<totalTags; i++) {
		
		currentTag = allTags[i];
		
		tagClass = currentTag.className;
		
		if (tagClass.indexOf('s_t_s') != -1) {
						
			if(navigator.appName == 'Microsoft Internet Explorer') {
				currentTag.style.removeAttribute('display');
			}
			
			if (navigator.appName != 'Microsoft Internet Explorer') {
				currentTag.style.removeProperty('display');
			}
		}
		
		
		
	}
	
}

//Empty Category remove border
function emptyCategory() {
var catDivContainer = document.getElementById('cat_list');
var catSubSpan = catDivContainer.getElementsByTagName('span');
var noSubSpans = catSubSpan.length;
i = 0;
while (i<noSubSpans) {
curSubSpan = catSubSpan[i];
if (curSubSpan.className == 'sub_cat_hide' && curSubSpan.innerHTML == '') {curSubSpan.style.border = 'none';}
i++;
}}

//Quick Cart Item Qty
function getCartQty(empty) {
var currentQty=0;
var tableRows=document.getElementById('cartQV').rows;
var numbItems=tableRows.length;
var itemS;
if (document.getElementById('cartQV').rows[0].cells[2]!= undefined) {
i=0;
while (i<numbItems) {
var tCells=document.getElementById('cartQV').rows[i].cells;
currentQty=parseInt(currentQty,10) + parseInt(tCells[2].innerHTML,10);
i++;}
if (currentQty>1){itemS='Items';} else {itemS='Item';}
document.getElementById('displayCartQty').innerHTML=" - " + currentQty + " " + itemS;
}
else {document.getElementById('displayCartQty').innerHTML=" - " + empty;}
}

function cartFSCalc(subTotal) {
var freeShip = 300;
var amtToFS = freeShip - subTotal;
var freeShip;
if (amtToFS > 0) {freeShip = "Purchase $" + amtToFS + " more to receive FREE shipping";}
else {freeShip = "FREE Shipping";}
document.getElementById('quickCartFS').innerHTML=freeShip;
if (document.getElementById('shopCartFS') != null) {document.getElementById('shopCartFS').innerHTML=freeShip;}
}
  
//Feature List Formatting
function featureFormat () {
var featureMain=document.getElementById('feature_list');
var featureDivs=featureMain.getElementsByTagName('div');
var totalDivs=featureDivs.length;
var toggleAllDiv=document.getElementById('expand_feature');
toggleAllDiv.onclick = toggleAll;
for (i=0; i<totalDivs; i++) {
var currentDiv=featureDivs[i];
currentDiv.className += "feature_list";
currentDivID='feature' + i;
currentDiv.setAttribute("id", currentDivID);
currentDiv.onclick = featureToggle;}
j=3;
clearedDivs = totalDivs/3;
for (i=1; i<clearedDivs; i++) {
divID = 'feature' + j;
if (document.getElementById(divID)!=null) {
clearDiv = document.getElementById(divID);
clearDiv.style.clear = 'both';
j=j+3;}
}
var featureLinks=featureMain.getElementsByTagName('a');
var totalLinks=featureLinks.length;
for (i=0; i<totalLinks; i++) {
var currentLink=featureLinks[i];
currentLink.onclick = extLink;	
currentLink.parentNode.style.backgroundImage='none';
currentLink.parentNode.onclick=null;}
}

function featureToggle () {
divID = this.id;
toggleDiv=document.getElementById(divID);
if (toggleDiv.className=='feature_list') {toggleDiv.className='feature_list_open'}
else {toggleDiv.className='feature_list'}
}

function toggleAll () {
divID = this.id;
var featureMain=document.getElementById('feature_list');
var featureDivs=featureMain.getElementsByTagName('div');
var totalDivs=featureDivs.length;
toggleDiv=document.getElementById(divID);
if (toggleDiv.className=='feature_list') {
toggleDiv.className='feature_list_open';
toggleDiv.innerHTML='Collapse All';
for (i=0; i<totalDivs; i++) {
currentDiv=featureDivs[i];
currentDiv.className='feature_list_open';}
}
else {
toggleDiv.className='feature_list';
toggleDiv.innerHTML='Expand All';
for (i=0; i<totalDivs; i++) {
currentDiv=featureDivs[i];
currentDiv.className='feature_list';}
}}

//Open Links Externally
function extLink() {
newwindow=window.open(this.href, 'afwExtWindow');
return false;}

//Options Info
function showOptionInfo (rowID){
infoRow = document.getElementById(rowID);
infoRow.style.display = 'table-cell';
infoRow.style.position = "absolute";
infoRow.style.zIndex = '1000';
infoRow.style.width = '25%'
infoRow.style.border = '1px solid #000';}
function hideOptionInfo (rowID){
infoRow = document.getElementById(rowID);
infoRow.style.display = 'none';}

//Total Price Scripting
function stripDollar (str) {
var cleanMoney = /^\$|,/g;
return str.replace(cleanMoney,"");}

function priceOut (tPrice) {
document.getElementById('total_price').innerHTML = tPrice;
document.getElementById('total_option_price').innerHTML = tPrice;
if (tPrice >=300) {
	document.getElementById('shipInfo').innerHTML = "Shipping Included";
	document.getElementById('shipDisclaimer').innerHTML = "";
}
else {
	document.getElementById('shipInfo').innerHTML = "$10 Flat Rate Shipping";
	document.getElementById('shipDisclaimer').innerHTML = " shipping or";
}
}

function optionClick(elType, elName, elValue, elSelect) {
hForm = document.getElementById("product_form");
vForm = document.getElementById("product_form_visible");
if (elType == "radio" || "checkbox"){
for (i=0; i<hForm.length; i++) {
if (hForm[i].value == elValue) {
	hForm[i].checked = elSelect;
}}}
if (elType == "select") {
optSel = document.getElementById('product_form_visible')[elName].selectedIndex;
document.getElementById('product_form')[elName].selectedIndex = optSel;
}
if (elType == "textarea" || "text"){
for (i=0; i<hForm.length; i++) {
if (hForm[i].name == elName) {
	hForm[i].value = elValue;
}}}

priceUpdater();	
}
function priceUpdater (){
if (document.getElementById('sale_price')!=null) {
var price=document.getElementById('sale_price').innerHTML;
bPrice = stripDollar(price);}
else {
var price = document.getElementById('product_price').innerHTML;
bPrice = stripDollar(price);}	
uPrice=bPrice;
pForm = document.getElementById('product_form');
fEl = pForm.elements;
for (i=0; i<fEl.length; i++) {
cEl = fEl[i];

if (cEl.type=='radio' && cEl.checked == true) {
if (cEl.title=='') {oVal = 0; continue;}
else {oVal = cEl.title.substring(5);}
optPrice = parseFloat(oVal);
if (cEl.title.charAt(0)=='-') {
uPrice = parseFloat(uPrice) - parseFloat(optPrice);
}
else {
uPrice = parseFloat(uPrice) + parseFloat(optPrice);}
}

if (cEl.type=='checkbox' && cEl.checked == true) {
if (cEl.title=='') {oVal = 0; continue;}
else {oVal = cEl.title.substring(5);}
optPrice = parseFloat(oVal);
if (cEl.title.charAt(0)=='-') {
uPrice = parseFloat(uPrice) - parseFloat(optPrice);
}
else {
uPrice = parseFloat(uPrice) + parseFloat(optPrice);}
}

if (cEl.type=='select-one') {
sOption = cEl.selectedIndex;
if(cEl.options[sOption].title=='') {oVal = 0; continue;}
else {
oVal = cEl.options[sOption].title.substring(5);
} 
optPrice = parseFloat(oVal);
if (cEl.options[sOption].title.charAt(0)=='-') {
uPrice = parseFloat(uPrice) - parseFloat(optPrice);
}
else {
uPrice = parseFloat(uPrice) + parseFloat(optPrice);}
}
}
itmQty = document.getElementById('itmQty').value;
parseInt(itmQty);
uPrice = uPrice * itmQty;
priceOut(uPrice.toFixed(2));
}

//Combine Forms

function processForms() {

pForm = document.getElementById('prod_form');
oForm = document.getElementById('opt_form');
pEl = pForm.elements; 
oEl = oForm.elements;
pElNo = pEl.length;
oElNo = oEl.length;

if (bClicked == "Add to Cart" && oElNo < 1) {
document.forms['product_form'].submit();
}

if (bClicked == "OptionClicked") {
priceUpdater();
}
if (oElNo == null) {document.forms['product_form'].submit();}

	
}

function openChat(){
	window.open('https://www.afwfilters.com/chat/chat.php','','width=590,height=610,left=0,top=0,resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes');
}

//Insert Dynamic Chat Image 
//function chatImage() {
//	document.getElementById('chat_image').innerHTML='<img src="http://www.afwfilters.com/chat/onlinestatus_html.php?dep=" border="0" />';
//}

//Add Benefit list image
function benefitImage () {
benList = document.getElementById('product_benefits');
listI = benList.getElementsByTagName('div');
for (i=0; i<listI.length; i++) {
oldHTML = listI[i].innerHTML;
imgLink = "<img class='blist_img' src='themes/AFW/images/Water_Drop.png' alt='' />"
if (i!=0 && i%2 == 0) {
listI[i].innerHTML = imgLink + oldHTML;
listI[i].style.clear = "both";
}
else {
listI[i].innerHTML = imgLink + oldHTML;
}
}
}

//Error Report URL
function feedbackURL() {
	var uRL=window.location.href;
	var errorLink = "<a href='http://www.afwfilters.com/store/index.php?l=page_view&amp;p=customer_feedback&amp;url=" + uRL +"'>here</a>";
	var errorPageLink = "<a href='http://www.afwfilters.com/store/index.php?l=page_view&amp;p=customer_feedback&amp;url=" + uRL +"'>Customer Feedback Form</a>";
	document.getElementById('customerFeedback').innerHTML = errorLink;
	if (document.getElementById('errorReport') != null){document.getElementById('errorReport').innerHTML = errorPageLink;}
}

// Email Encoding

function emailMask () {
var	one ='&#115;' //s
var	two ='&#097;' //a
var	three ='&#108;' //l
var	four ='&#101;' //e
var	five ='&#064;' //@
var	six ='&#102;' //f
var	seven ='&#119;' //w
var	eight ='&#105;' //i
var	nine ='&#116;' //t
var	ten ='&#114;' //r
var	eleven ='&#046;' //.
var	twelve ='&#099;' //c
var	thirteen ='&#111;' //o
var	fourteen ='&#109;' //m

email = one + two + three + four + one + five + two + six + seven + six + eight + three + nine + four + ten + one + eleven + twelve + thirteen + fourteen;
emailLink = "<br /><a href='mailto:" + email + "'>" + email + "</a><br />"; 
document.getElementById('maskMail').innerHTML = emailLink;

}


//onLoad Scripts
function customOnLoad(){
var oldOnLoad=window.onload;
if (typeof window.onload != 'function') {
window.onload = function() {
if (document.getElementById('js_pd')!=null) {
priceUpdater();  
featureFormat();}
s_t_s();
s_h();
emptyCategory()
//chatImage()
feedbackURL()
emailMask ()
if (document.getElementById('product_benefits') != null) {
benefitImage();
}
};
}

else {
window.onload = function() {
oldOnLoad();
if (document.getElementById('js_pd')!=null) {
priceUpdater();  
featureFormat();}
s_t_s();
s_h();
emptyCategory()
//chatImage()
feedbackURL()
emailMask ()
if (document.getElementById('product_benefits') != null) {
benefitImage();
}
};
}
}
customOnLoad();
//-->
