﻿//----------Kick-off / Page Load Functions----------
$(document).ready(function(){
    
    //Add last class to remove border in css
	if ( $(".featured-products").length > 0 ) {
	    $(".featured-products td:last-child").addClass("last");
    }
    
	//New tab popup
	$("a[rel='external']").attr("target", "_blank");
	
	//Zebra-Stripe
	$("#archive div.archiveArticle:even").addClass("rowEven");
	$("#archive div.archiveArticle:odd").addClass("rowOdd");
	$(".prodCompareTable tbody tr:odd").addClass("rowOdd");
	
	
	//Activate Tabs
	if ( $("#product_tabs").length > 0 ) {
		$("#product_tabs").tabs();
	}
    
    //Activate Accordion
	$("#accordion").accordion({ header: "h3", autoHeight: false });
	
});

//----------Input Field from AndyStratton.com--------
$(document).ready(function(){
	$("input.populate").each( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	$("input.populate").focus(function(){
		if ( $(this).val() == $(this).attr("title") ) {
			$(this).val("");
		}
	});
	$("input.populate").blur(function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
});

//----------Email Encrypt from AndyStratton.com--------
$(document).ready(function(){

	$(".email-replace").each(function(){
		var ats, dots, address, i;
		ats = [ ' at ', ' (at) ', ' [at] ' ];
		dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			address = address.replace(dots[i], '.');
		}
		$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
	});
	
});


//------------------Popup Functions------------------
function popuptopicfooter(title,topic,w,h,scrollbars)
{
    newPopup = window.open('popup.aspx?title=' + title + '&topic=' + topic,'Popup17906','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=no,copyhistory=no,width=' + w + ',height=' + h);
    newPopup.focus();
    return (true);
}

//JQuery Popup Functions
$(function(){
	// Live Chat Popup
	$("a[rel='live_chat_popup']").click(function(){
		var l=window.open($(this).attr("href"), 'live_chat_popup', 'width=490, height=404, toolbar=no,location=no,directories=no,menubar=no,status=no,scrollbars=no,resizable=yes,replace=no');
		l.focus();
		return false;
	});

	// Topic Page Popup
	$("a[rel='topic_popup']").click(function(){
		var t=window.open($(this).attr("href"), 'topic_popup', 'width=600, height=500, scrollbars=yes, menubar=no, toolbar=no');
		t.focus();
		return false;
	});
	
	// External Page Popup
	$("a[rel='external_popup']").click(function(){
		var e=window.open($(this).attr("href"), 'external_popup', 'width=900, height=500, scrollbars=yes, menubar=yes, toolbar=yes');
		e.focus();
		return false;
	});
	
	// Assurance Page Popup
	$("a[rel='assurance_popup']").click(function(){
		var a=window.open($(this).attr("href"), 'assurance_popup', 'width=600, height=500, scrollbars=yes, menubar=no, toolbar=no');
		a.focus();
		return false;
	});
});



//----------Switches Visibility on Items----------
function switchVisibility(obj) {
    var el = document.getElementById(obj);

    if ( el.style.display != "none" ) {
        el.style.display =
        'none';
    }

    else {
        el.style.display =
        '';
    }
}

function switchVisibilityCheckbox(obj, checkbox) {
    var el = document.getElementById(obj);

    if ( el.style.display != "none" && document.getElementById(checkbox).checked == true) {
        el.style.display =
        'none';
    }

    else if (document.getElementById(checkbox).checked == false) {
        el.style.display =
        '';
    }
}

function switchVisibilityCheckout(obj, checkbox) {
    var el = document.getElementById(obj);

    var style_attrib = window.document.createAttribute("style");
        style_attrib.nodeValue = "display: none;";
    //scDiv.attributes.setNamedItem(style_attrib);

    if (document.getElementById(checkbox).checked == true) {
        el.style.display =
        'none';
    }

    else if (document.getElementById(checkbox).checked == false) {
        el.style.display =
        '';
    }
}



//-------------Validate Function For Quantity Selection Kit Group-------------
function validatebox()
{
	var msg1='Please verify your quantities and select exactly';
    var kitgroup=document.forms['kit'].elements['kgid'];
    
    var kid=kitgroup.value;
    var kitgroupid=new Array();
    kitgroupid=kid.split(",");
   
	for(var j=0; j<kitgroupid.length-1; j++)
	{
	    var gid=document.forms['kit'].elements['groupid_' + kitgroupid[j]];
	    group_id=gid.value;
	    var mid=document.forms['kit'].elements['max_number_' + kitgroupid[j]];
	    max_number=mid.value;
	    var tid=document.forms['kit'].elements['textboxid_' + kitgroupid[j] ];
	    var textboxid1=tid.value
	    var mval=document.forms['kit'].elements['max_value_' + kitgroupid[j] ];
	    var max_value=parseInt(mval.value);
	    var ids =new Array();
	    ids=textboxid1.split(",");
	    var sum=0;
	    var i=0; 
	      
	    while(max_number > 0)
	    {
		    if(ids[i]!="")
		    {
			    var value='KitGroupID_' + group_id + '_TextOption_' + ids[i];
			    var sum1=document.forms['kit'].elements['KitGroupID_' + group_id + '_TextOption_' + ids[i]];
			    i=i+1;
	            if (sum1.value!="")
                {
          	        sum=sum + parseInt(sum1.value);
			    }
			    max_number=max_number-1;
		    }
	    }
	
	    if (parseInt(sum) < parseInt(max_value) )
	    {
		    window.alert(msg1 + ' ' + max_value + '.');
	    	return false;
	    }
	    else if (parseInt(sum) > parseInt(max_value) )
	    {
		    window.alert(msg1 + ' ' + max_value + '.');
	   		return false;
	    }
	    
	    
	    if(ids.length>=0)
	    {
	    	ids.pop();
	    }
	    
	    sum=0;
	    group_id=0;
		max_number=0;
		max_values=0;
	}
}

