// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


var bV=parseInt(navigator.appVersion);
NS6=document.getElementById&&!document.all;
IE4=((document.all)&&(bV>=4))?true:false;
ver4 = (NS6 || IE4) ? true : false;

function expandDiv(){return;}
function collapseDiv(){return;}


  //Start: Static code: document object initial settings.
  with (document) {
    write("<STYLE TYPE='text/css'>");
      write(".closed {display:block}");
      write(".open {display:none}");
      write(".nav_hidden {display:none}");
      write(".popup {display:none; position:absolute}");
    write("</STYLE>");
  }
  //Stop: Static code: document object initial settings.

  activeDiv = "";
  firstInd = -1;


//------------------------------------------------------
function expandDiv(el) 
//------------------------------------------------------
{
  if (!ver4) return;

//exclusive
if (activeDiv != "") collapseDiv(activeDiv);

  document.getElementById("open_" + el).style.display = "block";
  document.getElementById("closed_" + el).style.display = "none";
  activeDiv = el;
}
//------------------------------------------------------
function collapseDiv(el) 
//------------------------------------------------------
{
  if (!ver4) return;
  document.getElementById("open_" + el).style.display = "none";
  document.getElementById("closed_" + el).style.display = "block";
  activeDiv = "";
}

//------------------------------------------------------
function check_required_noble(){
	var success = true;
	if(document.noble_form.certificate_name.value == ""){
		document.noble_form.certificate_name.style.border="solid 3px red";
		success = false;
	}
	if(document.noble_form.certificate_date.value == ""){
		document.noble_form.certificate_date.style.border="solid 3px red";
		success = false;
	}
	if(!success){
		alert("Both the name and date are required");
	}
	return success;
}
//------------------------------------------------------
function check_required_ctpat(){
	var success = true;
	if(document.ctpat_form.ctpat_name.value == ""){
		document.ctpat_form.ctpat_name.style.border="solid 3px red";
		success = false;
	}
	if(!success){
		alert("Company Name is Required");
	}
	return success;
}
//------------------------------------------------------
function check_required(){
	var alert_text_billing = "\nBilling:";
	var alert_text_shipping = "\nShipping:";
	if(document.checkout_form.bill_first_name.value == ""){
		alert_text_billing+= "\n---First Name";
	}
	if(document.checkout_form.bill_last_name.value == ""){
		alert_text_billing+= "\n---Last Name";
	}
	if(document.checkout_form.invoice && !document.checkout_form.invoice.checked){
		if(document.checkout_form.credit_card_num.value == ""){
			alert_text_billing+= "\n---Credit Card Number";
		}
		if(document.checkout_form.credit_card_pid.value == ""){
			alert_text_billing+= "\n---Card Id";
		}
		if(document.checkout_form.credit_card_expire_month.value == ""){
			alert_text_billing+= "\n---Card Expire Month";
		}
		if(document.checkout_form.credit_card_expire_year.value == ""){
			alert_text_billing+= "\n---Card Expire Year";
		}
	}
	if(document.checkout_form.ship_fedex && document.getElementsByName("ship_fedex")[0].checked){
		if(document.getElementsByName("fedex_account")[0].value == "") alert_text_billing+= "\n---Fedex Account Number";
	}
	if(document.checkout_form.email.value == ""){
		alert_text_billing+= "\n---Email Address";
	}
	if(document.checkout_form.phone.value == ""){
		alert_text_billing+= "\n---Phone Number";
	}
	if(document.checkout_form.bill_address_1.value == ""){
		alert_text_billing+= "\n---Address";
	}
	if(document.checkout_form.bill_city.value == ""){
		alert_text_billing+= "\n---City";
	}
	if(document.checkout_form.bill_state.value == "@@@"){
		alert_text_billing+= "\n---State";
	}
	if(document.checkout_form.bill_zip.value == ""){
		alert_text_billing+= "\n---Zip Code";
	}
	if(document.checkout_form.bill_country.value == "@@@"){
		alert_text_billing+= "\n---Country";
	}
	
	if(!document.checkout_form.same_as_billing.checked){
		if(document.checkout_form.ship_first_name.value == ""){
			alert_text_shipping+= "\n---First Name";
		}
		if(document.checkout_form.ship_last_name.value == ""){
			alert_text_shipping+= "\n---Last Name";
		}
		if(document.checkout_form.ship_address_1.value == ""){
			alert_text_shipping+= "\n---Address";
		}
		if(document.checkout_form.ship_city.value == ""){
			alert_text_shipping+= "\n---City";
		}
		if(document.checkout_form.ship_state.value == "@@@"){
			alert_text_shipping+= "\n---State";
		}
		if(document.checkout_form.ship_zip.value == ""){
			alert_text_shipping+= "\n---Zip Code";
		}
		if(document.checkout_form.ship_country.value == "@@@"){
			alert_text_shipping+= "\n---Country";
		}

	}
	if(alert_text_billing  != "\nBilling:" || alert_text_shipping != "\nShipping:"){
		var alert_text = "The following required elements are missing:";
		if(alert_text_billing  != "\nBilling:"){
			alert_text+= alert_text_billing;
		}
		if(alert_text_shipping  != "\nShipping:"){
			alert_text+= alert_text_shipping;
		}
		alert(alert_text);
		return false;
	}else{
		return true;
	}
}

//------------------------------------------------------
function display_div(div_id)
//------------------------------------------------------
{
	var software_div = document.getElementsByName("software_link");
	
	var all_divs = document.getElementsByTagName("div");
	var div_names = "";

	//this looks redundat but, 
	
	//this one is for internet explorer
	for(i = 0; i < all_divs.length; i++){
		if(all_divs[i].name == "software_link"){
			all_divs[i].style.display = "none";
		}
	}
	
	//this one is for firefox
	for(i = 0; i < software_div.length; i++){
		software_div[i].style.display = "none";
	}
	
	document.getElementById(div_id).style.display = "block";
}

function disable_cc(box_checked){
	if(box_checked){
		document.getElementsByName("credit_card_type")[0].disabled 				='disabled';
		document.getElementsByName("credit_card_num")[0].disabled 				='disabled';
		document.getElementsByName("credit_card_pid")[0].disabled 				='disabled';
		document.getElementsByName("credit_card_expire_month")[0].disabled 	='disabled';
		document.getElementsByName("credit_card_expire_year")[0].disabled 	='disabled';

		//document.getElementsByName("credit_card_type")[0].value = "";
		document.getElementsByName("credit_card_num")[0].value 				= "";
		document.getElementsByName("credit_card_pid")[0].value 				= "";
		document.getElementsByName("credit_card_expire_month")[0].value 	= "";
		document.getElementsByName("credit_card_expire_year")[0].value 	= "";

	}else{
		document.getElementsByName("credit_card_type")[0].disabled='';
		document.getElementsByName("credit_card_num")[0].disabled='';
		document.getElementsByName("credit_card_pid")[0].disabled='';
		document.getElementsByName("credit_card_expire_month")[0].disabled='';
		document.getElementsByName("credit_card_expire_year")[0].disabled='';
	}
}

function flash_button(){
	document.getElementById("update_cart_btn").style.backgroundColor = "#A9CF67";
	setTimeout(
		function(){
			document.getElementById("update_cart_btn").style.backgroundColor = "";
		}
		, 500
	);
	setTimeout(
		function(){
			document.getElementById("update_cart_btn").style.backgroundColor = "#A9CF67";
		}
		, 900
	);
	setTimeout(
		function(){
			document.getElementById("update_cart_btn").style.backgroundColor = "";
		}
		, 1400
	);	
	setTimeout(
		function(){
			document.getElementById("update_cart_btn").style.backgroundColor = "#A9CF67";
		}
		, 1800
	);
	
	
}

function toggle_fedex(fedex_checked){
	if(fedex_checked){
		document.getElementsByName("fedex_account")[0].disabled = false;
	}else{
		document.getElementsByName("fedex_account")[0].value = "";
		document.getElementsByName("fedex_account")[0].disabled = true;
	}
}

function toggle_shipping(shipping_same_checked){
	if(shipping_same_checked){
		document.checkout_form.ship_company_name.disabled 	= true;
		document.checkout_form.ship_first_name.disabled 	= true;
		document.checkout_form.ship_last_name.disabled 		= true;
		document.checkout_form.ship_address_1.disabled 		= true;
		document.checkout_form.ship_address_2.disabled 		= true;
		document.checkout_form.ship_city.disabled 			= true;
		document.checkout_form.ship_state.disabled 			= true;
		document.checkout_form.ship_zip.disabled 				= true;
		document.checkout_form.ship_country.disabled 		= true;

		document.checkout_form.ship_company_name.value 	= "";
		document.checkout_form.ship_first_name.value 	= "";
		document.checkout_form.ship_last_name.value 		= "";
		document.checkout_form.ship_address_1.value 		= "";
		document.checkout_form.ship_address_2.value 		= "";
		document.checkout_form.ship_city.value 			= "";
		document.checkout_form.ship_zip.value 				= "";

		document.checkout_form.ship_state.selectedIndex 	= 0;
		//set to united stats
		document.checkout_form.ship_country.selectedIndex 	= 223;
		
	}else{
		document.checkout_form.ship_company_name.disabled 	= false;
		document.checkout_form.ship_first_name.disabled 	= false;
		document.checkout_form.ship_last_name.disabled 		= false;
		document.checkout_form.ship_address_1.disabled 		= false;
		document.checkout_form.ship_address_2.disabled 		= false;
		document.checkout_form.ship_city.disabled 			= false;
		document.checkout_form.ship_state.disabled 			= false;
		document.checkout_form.ship_zip.disabled 				= false;
		document.checkout_form.ship_country.disabled 		= false;
		
	}
}

var blog_teaser_body = "";
function toggle_blog_body(){
	if(document.getElementById("blog_body").style.display == "none"){
		blog_teaser_body = document.getElementById("blog_teaser_body").innerHTML
		document.getElementById("blog_teaser_body").innerHTML = "";
		$("#blog_body").show("normal");
	}else{
		$("#blog_body").hide("normal", 
			function(){
				document.getElementById("blog_teaser_body").innerHTML = blog_teaser_body;
			}
		);
	}
}

function toggle_testimonial_form(){
	$('#testimonial-block').css('display','block');

}
