function showMsg(x){
	var el = document.getElementById(x);
	el.style.visibility= 'visible';
}
function hideMsg(x){
	var el = document.getElementById(x);
	el.style.visibility= 'hidden';
}

// validates the coupon form 
  function validDiscForm(passedForm){
	  
	 // ---------------------------- Edit these items only --------------------------------------------------------- //
	  
	 baseProdRate = 16.95      // full ZeoPro bag rate
	 singleBagWeight = 10.5    // ZeoPro ship weight
	 
	 caseProdRate = 67.80     // full ZeoPro case rate
	 caseBagWeight = 42       // ZeoPro case shipping weight
	 
     discCode1 = "NSS32"
	 discRate1 = .25            // percent of discount - coupons
	 
	 discCode2 = "RET32"
	 discRate2 = .59            // percent of discount - wholesale
	 
	 // ------------------------------------ Edit nothing below here ------------------------------------------------- //
	
	 discRate1String = Math.round(discRate1*100) + "% off"
	 discRate2String = Math.round(discRate2*100) + "% off"
	 cCodeGiven = ""
	
	// tests for presence of and gets coupon codes 
     if (document.ccForm1){
	      if (document.ccForm1.ccode.value != ""){
		      cCodeGiven = document.ccForm1.ccode.value.toUpperCase()
	      } 
	 }
	if (document.ccForm2){
	      if (document.ccForm2.ccode.value != ""){
		     cCodeGiven = document.ccForm2.ccode.value.toUpperCase()
	      } 
	 }
	 if (document.ccForm3){	 
	     if (document.ccForm3.ccode.value  != ""){
		    cCodeGiven = document.ccForm3.ccode.value.toUpperCase()
	    } 
	 }
	 if (document.ccForm4){
	     if (document.ccForm4.ccode.value != ""){
	     cCodeGiven = document.ccForm4.ccode.value.toUpperCase()
	    } 
	 }
    if (document.ccForm5){
	     if (document.ccForm5.ccode.value  != ""){
	     cCodeGiven = document.ccForm5.ccode.value.toUpperCase()
	    } 
	 }
	 
	 
	 //check validity of entered coupon code
		 if(cCodeGiven != discCode1 && cCodeGiven != discCode2 && cCodeGiven != ""){
			  alert("Sorry, you have not entered a valid Coupon Code. \n If you do not have a coupon code, please leave the Coupon code fields blank.")
		      clearVals();
		      return false
		 }
	 
	 
	 // do if we have no coupon code entered
     if (cCodeGiven == ""){
		 if (passedForm.id =="zeoFormSingle" || passedForm.id =="zeoFormSingle2" || passedForm.id == "buyZeoNow1" || passedForm.id == "buyZeoNow2"){
	         passedForm.item_1.value = ("s-3372^ZeoPro^ZeoPro - 10 lb Bag^" + baseProdRate + "^1^^^^" + singleBagWeight)
	         return true
		 }
		 if (passedForm.id =="zeoFormCase" || passedForm.id =="zeoFormCase2"){ 
	        passedForm.item_1.value = ("s-3372^ZeoPro^ZeoPro - 10 lb Bags (case of 4)^" + caseProdRate + "^1^^^^" + caseBagWeight)
	        return true
		 }
	 } 

	 // do if we have a valid code
	 if (cCodeGiven == discCode1){
		if (passedForm.id =="zeoFormSingle" || passedForm.id =="zeoFormSingle2"  || passedForm.id == "buyZeoNow1" || passedForm.id == "buyZeoNow2"){
		   newRate =  Math.round(100*(baseProdRate*((100-(discRate1*100))/100)))/100   //calculates discount price
	       passedForm.item_1.value = ("s-3372^ZeoPro^ZeoPro - 10 lb Bag (" + discRate1String+ " - Coupon Discount)^" + newRate + "^1^^^^" + singleBagWeight)
		   return true
		}
		if (passedForm.id =="zeoFormCase" || passedForm.id =="zeoFormCase2"){
		   newRate =  Math.round(100*(caseProdRate*((100-(discRate1*100))/100)))/100   //calculates discount price
		   passedForm.item_1.value = ("s-3372^ZeoPro^ZeoPro - 10 lb Bags (case of 4) (" + discRate1String+ " - Coupon Discount)^" + newRate + "^1^^^^" + caseBagWeight)
		   return true
		}
	 } 
	 
	  if (cCodeGiven == discCode2){
		if (passedForm.id =="zeoFormSingle" || passedForm.id =="zeoFormSingle2"  || passedForm.id == "buyZeoNow1" || passedForm.id == "buyZeoNow2"){
		   newRate =  Math.round(100*(baseProdRate*((100-(discRate2*100))/100)))/100   //calculates discount price
	       passedForm.item_1.value = ("s-3372^ZeoPro^ZeoPro - 10 lb Bag (" + discRate2String+ " - Wholesale Discount)^" + newRate + "^1^^^^" + singleBagWeight)
		   return true
		}
		if (passedForm.id =="zeoFormCase" || passedForm.id =="zeoFormCase2"){
		   newRate =  Math.round(100*(caseProdRate*((100-(discRate2*100))/100)))/100   //calculates discount price
		   passedForm.item_1.value = ("s-3372^ZeoPro^ZeoPro - 10 lb Bags (case of 4) (" + discRate2String+ " - Wholesale Discount)^" + newRate + "^1^^^^" + caseBagWeight)
		   return true
		}
	 } 
	 
  }
  
function clearVals(){
    if (document.ccForm1){
	     document.ccForm1.ccode.value = "";
	 }
	if (document.ccForm2){
          document.ccForm2.ccode.value = "";
	 }
	 if (document.ccForm3){	 
          document.ccForm3.ccode.value = "";
	 }
	 if (document.ccForm4){
          document.ccForm4.ccode.value = "";
	 }
    if (document.ccForm5){
          document.ccForm5.ccode.value = "";
	 }
}
  
function showAlert() {
   alert("Please Note: We will be unavailable to ship orders between April 16 and April 24.  Shopping will resume on the 24th.  Sorry for any inconvenience, and thank you for thinking of Tindara.");
}

//----------------------------------------------------------------------------------------------//

function setMinHeight(){
	var divhL = document.getElementById('framecontentLeft').offsetHeight + 90;
	var divhR = document.getElementById('framecontentRight').offsetHeight + 90;

	var heightReq = '';
	if(divhL<divhR){
		heightReq = divhR;
	}else{
		heightReq = divhL;
	}
	
	 document.getElementById('maincontent').style.minHeight = heightReq + 'px'; 
}

function writeDate(which){
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
var suffix  // grammatical suffix added - Darrin Norton
switch(date){
  case 1:
    suffix="st"
	break
  case 21:
    suffix="st"
	break
  case 31:
    suffix="st"
	break
  case 2:
	suffix="nd"
	break
  case 22:
	suffix="nd"
	break
  case 3:
	suffix="rd"
	break
  case 23:
	suffix="rd"
	break
  default:
    suffix="th"
	}
if (year < 2000)    // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
var year = time.getFullYear()
	if(which == 'yr'){
		document.write(year);
	}else{
		document.write(lmonth + " ");
		document.write(date + "<span class='subscr'>" + suffix + "</span> " + year + "");
	}
}


	function returnDocument() {
        var file_name = document.location.href;
        var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
        return file_name.substring(file_name.lastIndexOf("/")+1, end);
    }
	
	function savePageName(q){
		
		var x = returnDocument();
		//alert(x);
		if(q!='view'){
			x = x + q;
		}
		createCookie("pageFrom",x,30);
		
		if(q == "view"){
			window.location = 'cart.htm';
		}
	}
	
	
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		//var pg = readCookie("pageFrom");
		//alert('read cookie: ' + pg);
	}

	
