bioIndex = 0;























//============================== VISIBILITY  =========================







function getObjNN4(obj,name) 



{







	var x = obj.layers;







	var foundLayer;







	for (var i=0;i<x.length;i++)



	{







		if (x[i].id == name)







		 	foundLayer = x[i];







		else if (x[i].layers.length)







			var tmp = getObjNN4(x[i],name);







		if (tmp) foundLayer = tmp;







	}







	return foundLayer;







}















function getStyleObject(objectId, doc) {







    if(document.getElementById && document.getElementById(objectId)) {







	return document.getElementById(objectId).style;







    } else if (document.all && document.all(objectId)) {







	return document.all(objectId).style;







    } else if (document.layers && document.layers[objectId]) {







		return getObjNN4(document,objectId);







    } else {







	return false;







    }







} // getStyleObject















function changeObjectVisibility(objectId, newVisibility) {







    var styleObject = getStyleObject(objectId, document);







    if(styleObject) {







	styleObject.visibility = newVisibility;







	return true;







    } else {







	return false;







    }







}















function getObjectVisibility(objectId) {







    var styleObject = getStyleObject(objectId, document);







    if(styleObject) {







	if(styleObject.visibility == 'visible')







            return true;







        else







            return false;







    } else {







	return false;







    }







}















//======================================= CHANGE bg color ==================================







function changeBgColor(id, button){







	var buttonStyle = getStyleObject(button);







	if(buttonStyle) {







		buttonStyle.bgColor = (id==1) ? "#ffffff" : "#cccccc";







		return true;







        }







	else {







		return false;







        }







}















//=======================================  Show Product ======================================







function showSubProducts(theValue){







  if(getObjectVisibility('subproducts')){







      changeObjectVisibility('subproducts', 'hidden');







      bioIndex = 0;







      uncheckAll(theValue);







  }







  else{







      changeObjectVisibility('subproducts', 'visible');







      bioIndex = getElementIndex(theValue);







  }







}







function showOtherField(theValue){







  if(theValue==2){







      changeObjectVisibility('otherfield', 'hidden');











  }







  else{







      changeObjectVisibility('otherfield', 'visible');







  }







}







function selectValue(theSelect){



         with(theSelect){



            if(value=="Other")



                showOtherField(1);



            else



                showOtherField(2);



         }



}











//=============================================== Form Validation ==============================







function digitvalidation(entered, min, max, alertbox, datatype)







{







	with (entered){







	     checkvalue=parseFloat(value);







             if (datatype){







               smalldatatype=datatype.toLowerCase();







               if (smalldatatype.charAt(0)=="i"){







                 checkvalue=parseInt(value); 







                 if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}







               };







             }







             if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue){







               if (alertbox!="") {alert(alertbox);} 







               return false;







             }







             else {return true;}







      }







}















function emailvalidation(entered, alertbox){



	with (entered){



		apos=value.indexOf("@"); 



		dotpos=value.lastIndexOf(".");



		lastpos=value.length-1;



		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {



			if (alertbox) 



				alert(alertbox); 



			return false;



		}



		else 



			return true;



	}



}











function emptyvalidation(entered, alertbox){







         with (entered){







              if (value==null || value==""){







                //if (alertbox!="") {alert(alertbox);}







                return false;







              }







              else {return true;}







         }







}











function emptyvalidation2(entered, alertbox){







         with (entered){







              if (value==null || value==""){







                if (alertbox!="") {alert(alertbox);}







                return false;







              }







              else {return true;}







         }







}



function emptyvalidationzero(entered, alertbox){
         with (entered){
              if (value==null || value=="" || value == "0" || value == 0){
                if (alertbox!="") {alert(alertbox);}
                return false;
              }

              else {return true;}

         }
}




function valuevalidation(entered, min, max, alertbox, datatype){







	with (entered){







        checkvalue=parseFloat(value);







        if (datatype){







          smalldatatype=datatype.toLowerCase();







          if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};







        }







        if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue){







          if (alertbox!="") {alert(alertbox);} return false;







        }







        else {return true;}







        }







}















function formvalidation(thisform){







	with (thisform){







		if (emptyvalidation2(quantity,"Please enter a number.")==false) {quantity.focus(); return false;};







		if (digitvalidation(quantity,0,100,"Please enter a valid number.","I")==false) {quantity.focus(); return false;};	







		if (valuevalidation(quantity,1,10000,"Please enter a number between 1 and 10000.","I")==false) {quantity.focus(); return false;};		







	}







}















//================================================== CHECK Progress forms ===============================







function checkOrderFormP1(){







             var tmp = 0;















             for(i=1; i<document.orderForm.elements.length; i++){







                 if(document.orderForm.elements[i].checked)







                   tmp++;







             }







             if(getObjectVisibility('subproducts')){







                  var subcounter = 0;















                  for(i=bioIndex; i<document.orderForm.elements.length; i++){







                           if(document.orderForm.elements[i].checked)







                                    subcounter++;







                  }







                  if(subcounter<2){







                       alert("Please select a Bioball industry type to proceed!");







                       return false;







                  }







             }







             if(tmp<1){







                 alert("Please select a product to proceed!");







                 return false;







             }







             return true;







}











function checkOrderFormP2(){



  



             var tmp = 0;



             var tmpArrayName = "";



             var checkboxItr = 0;



             var checkboxes = new Array();







             var tmpItr = 0;



             var sep = "|";







             for(i=1; i<document.orderform.elements.length; i++){







                 if(document.orderform.elements[i].name.match("boxQty")){







                    if(document.orderform.elements[i].value!=null&&document.orderform.elements[i].value!=""){







                         if(valuevalidation(document.orderform.elements[i],1,10000,"Please enter a number between 1 and 10000.","I")==false){







                                document.orderform.elements[i].focus();







                                return false;







                         }



                         tmp++;







                    }







                 }







                 else if(document.orderform.elements[i].name.match("boxsizeSelected")){



                    if(document.orderform.elements[i].checked){







                         var tmpName = document.orderform.elements[i].name;



                         checkboxes[checkboxItr] = tmpName.substring(15);



                         checkboxItr++;







                    }



                 }







                 else{







                 }







             }     







             if(tmp<1){







                 alert("Please select at least one product to proceed!");







                 return false;







             }







             word = "";



             word2 ="";



             for(j=0; j<checkboxItr;j++){  







                for(i=1; i<document.orderform.elements.length; i++){



                 if(document.orderform.elements[i].name.match("boxQty")){



                    if(document.orderform.elements[i].name.substring(6)==checkboxes[j]){



                   //   word = word + checkboxes[j] + sep;



                   // word2 = word2 + checkboxes[j] + sep;



                       if(document.orderform.elements[i].value==null||document.orderform.elements[i].value==""){



                            alert("Please enter a quantity for the box you selected!");



                            document.orderform.elements[i].focus();



                            return false;



                       }



                    }



                 }



               }



             }



             //document.write(word);



             //document.write(word2);



             return true;



}











function checkOrderFormP3(){







             var tmp = 0;







             for(i=0; i<document.orderform.elements.length; i++){



                 if(document.orderform.elements[i].name.match("c_and_g_qty")){







                    if(document.orderform.elements[i].value!=null&&document.orderform.elements[i].value!=""){







                         tmp++;



                         if(valuevalidation(document.orderform.elements[i],1,10000,"Please enter a number between 1 and 10000.","I")==false){







                                document.orderform.elements[i].focus();







                                return false;







                         }







                    }







                 }



             }







             if(tmp<1){







                 alert("Please select at least one product to proceed!");







                 return false;







             }



             return true;



}







function checkOrderFormP4Quote(thisform){



	with (thisform){



		if (emptyvalidation2(company_name,"Please enter a company name.")==false) {company_name.focus(); return false;};



		if (emptyvalidation2(contact_name,"Please enter a contact name.")==false) {contact_name.focus(); return false;};



		if (emptyvalidation2(contact_phone,"Please enter a contact phone.")==false) {contact_phone.focus(); return false;};



		if (emptyvalidation2(contact_email,"Please enter a contact email.")==false) {contact_email.focus(); return false;};



		if (emailvalidation(contact_email,"Please enter a valid Email")==false) {contact_email.focus(); return false;};



                //if (digitvalidation(postcode,4,4,"Please enter a valid postcode, 4 digits expected.","I")==false) {postcode.focus(); return false;};



		if (emptyvalidation2(street_no,"Please enter a street number.")==false) {street_no.focus(); return false;};



		//if (digitvalidation(phone,8,12,"Please enter a valid telephone number.","I")==false) {phone.focus(); return false;};



		if (emptyvalidation2(street_name,"Please enter a street name.")==false) {street_name.focus(); return false;};



		//if (emailvalidation(email,"Please enter an valid Email")==false) {email.focus(); return false;};



		if (emptyvalidation2(city,"Please enter a city name.")==false) {city.focus(); return false;};



		if (emptyvalidation2(postcode,"Please enter a postcode.")==false) {postcode.focus(); return false;};







	}



}







function checkOrderFormP4New(thisform){



	with (thisform){

		if (emptyvalidation2(contact_company_name,"Please enter a contact company name.")==false) {contact_company_name .focus(); return false;};
		if (emptyvalidation2(contact_name,"Please enter a contact name.")==false) {contact_name .focus(); return false;};
		if (emptyvalidation2(contact_phone,"Please enter a contact phone.")==false) {contact_phone .focus(); return false;};
		if (emptyvalidation2(contact_fax,"Please enter a contact fax.")==false) {contact_fax .focus(); return false;};
		if (emptyvalidation2(contact_email,"Please enter a contact email.")==false) {contact_email .focus(); return false;};

		if (emptyvalidation2(company_name,"Please enter a company name.")==false) {company_name.focus(); return false;};



		//if (emptyvalidation2(company_type,"Please select a company type.")==false) {company_type.focus(); return false;};



		if (emptyvalidation2(billing_contact,"Please enter a contact name.")==false) {billing_contact.focus(); return false;};



		if (emptyvalidation2(billing_phone,"Please enter a contact phone.")==false) {billing_phone.focus(); return false;};



		if (emptyvalidation2(billing_email,"Please enter a contact email.")==false) {billing_email.focus(); return false;};



		if (emailvalidation(billing_email,"Please enter a valid Email")==false) {billing_email.focus(); return false;};



                //if (digitvalidation(postcode,4,4,"Please enter a valid postcode, 4 digits expected.","I")==false) {postcode.focus(); return false;};



		if (emptyvalidation2(billing_street_no,"Please enter a street number.")==false) {billing_street_no.focus(); return false;};



		//if (digitvalidation(phone,8,12,"Please enter a valid telephone number.","I")==false) {phone.focus(); return false;};



		if (emptyvalidation2(billing_street_name,"Please enter a street name.")==false) {billing_street_name.focus(); return false;};



		//if (emailvalidation(email,"Please enter an valid Email")==false) {email.focus(); return false;};



		if (emptyvalidation2(billing_city,"Please enter a city name.")==false) {billing_city.focus(); return false;};



		if (emptyvalidationzero(billing_country,"Please select your country.")==false) {billing_country.focus(); return false;};



		if (emptyvalidation2(billing_state_province,"Please enter a billing state/province.")==false) {return false;};


		if (emptyvalidation2(billing_postcode,"Please enter a postcode.")==false) {billing_postcode.focus(); return false;};










                if (emptyvalidation2(shipping_contact,"Please enter a contact name.")==false) {shipping_contact.focus(); return false;};



             	if (emptyvalidation2(shipping_phone,"Please enter a contact phone.")==false) {shipping_phone.focus(); return false;};



		if (emptyvalidation2(shipping_email,"Please enter a contact email.")==false) {shipping_email.focus(); return false;};



		if (emailvalidation(shipping_email,"Please enter a valid Email")==false) {shipping_email.focus(); return false;};



                //if (digitvalidation(postcode,4,4,"Please enter a valid postcode, 4 digits expected.","I")==false) {postcode.focus(); return false;};



		if (emptyvalidation2(shipping_street_no,"Please enter a street number.")==false) {shipping_street_no.focus(); return false;};



		//if (digitvalidation(phone,8,12,"Please enter a valid telephone number.","I")==false) {phone.focus(); return false;};



		//if (emptyvalidation2(shipping_street_name,"Please enter a street name.")==false) {shipping_street_name.focus(); return false;};



		//if (emailvalidation(email,"Please enter an valid Email")==false) {email.focus(); return false;};



		if (emptyvalidation2(shipping_city,"Please enter a city name.")==false) {shipping_city.focus(); return false;};


		if (emptyvalidation2(shipping_state_province,"Please enter a shipping state/province.")==false) {shipping_state_province.focus(); return false;};


		if (emptyvalidation2(shipping_postcode,"Please enter a postcode.")==false) {shipping_postcode.focus(); return false;};




		if (!document.getElementById("ConditionsAgree").checked) {alert("You must agree to the BTF Terms and Conditions of Sale before completing your order.");return false;};


	}



}











function checkOrderFormP4Exist(thisform){



	with (thisform){



		if (emptyvalidation2(company_name,"Please enter a company name.")==false) {company_name.focus(); return false;};



		if (emptyvalidation2(contact_name,"Please enter a customer contact name.")==false) {contact_name.focus(); return false;};



		if (emptyvalidation2(contact_phone,"Please enter a contact phone.")==false) {contact_phone.focus(); return false;};



		if (emptyvalidation2(contact_email,"Please enter a contact email.")==false) {contact_email.focus(); return false;};



		if (emailvalidation(contact_email,"Please enter a valid Email")==false) {contact_email.focus(); return false;};



                //if (digitvalidation(postcode,4,4,"Please enter a valid postcode, 4 digits expected.","I")==false) {postcode.focus(); return false;};



		if (emptyvalidation2(street_no,"Please enter a street number.")==false) {street_no.focus(); return false;};



		//if (digitvalidation(phone,8,12,"Please enter a valid telephone number.","I")==false) {phone.focus(); return false;};



		if (emptyvalidation2(street_name,"Please enter a street name.")==false) {street_name.focus(); return false;};



		//if (emailvalidation(email,"Please enter an valid Email")==false) {email.focus(); return false;};



		if (emptyvalidation2(city,"Please enter a city name.")==false) {city.focus(); return false;};



		if (emptyvalidation2(postcode,"Please enter a postcode.")==false) {postcode.focus(); return false;};



		if (!document.getElementById("ConditionsAgree").checked) {alert("You must agree to the BTF Terms and Conditions of Sale before completing your order.");return false;};




	}



}







/*



function checkOrderFormP2(){







             var tmp = 0;







             var tmpArrayName = "";







             //var tmpArray = new Array[3];







             var tmpItr = 0;



             var result = "|";







             for(i=1; i<document.orderform.elements.length; i++){







                 if(document.orderform.elements[i].name.match("boxQty")){







                    if(document.orderform.elements[i].value!=null&&document.orderform.elements[i].value!=""){







                         if(valuevalidation(document.orderform.elements[i],1,10000,"Please enter a number between 1 and 10000.","I")==false){







                                document.orderform.elements[i].focus();







                                return false;







                         }







                         if(tmpArrayName!=""){



                             //alert("asdasd");



                             result += document.orderform.elements[i].name;



                             //document.write(document.orderform.elements[i].name);



                             if(document.orderform.elements[i].value==null||document.orderform.elements[i].value==""){



                                alert("Please enter a number for the product you selected.");



                                document.orderform.elements[i].focus();







                                return false;



                            }



                            else{



                              result += document.orderform.elements[i].value + "||";



                             //alert("||"+document.orderform.elements[i].value+"||");



                                if(valuevalidation(document.orderform.elements[i],1,10000,"Please enter a number between 1 and 10000.","I")==false){







                                    document.orderform.elements[i].focus();



                                    return false;







                                }



                            }



                         }



                           //document.write(document.orderform.elements[i].name); }







                           //     tmpArray[tmpItr] = document.orderform.elements[i].name;







                         //}







                         tmpItr++;







                         tmp++;







                    }







                 }







                 else if(document.orderform.elements[i].name.match("catalogSelected")){







                    if(document.orderform.elements[i].checked){







                         tmpItr = 0;







                         //tmpArray = new Array[3];







                         tmpArrayName = document.orderform.elements[i].name;







                    }







                    else{







                         tmpArrayName = "";







                    }







                 }







                 else{















                 }







             }



             document.write(result);



             if(tmp<1){







                 alert("Please select at least one product to proceed!");







                 return false;







             }







             return true;







} */















//========================================= Other functions ========================================







function uncheckAll(theValue){







       for(i=getElementIndex(theValue); i<document.orderForm.elements.length; i++){







           document.orderForm.elements[i].checked = false;







       }







}















function getElementIndex(theValue){







         for(i=1; i<document.orderForm.elements.length; i++){







             if(document.orderForm.elements[i].value==theValue)







                  return i;







         }







         return 0;







}















function rollbg(chosen, objectID) {







   if(document.getElementById && document.getElementById(objectID)){







         if(chosen == 1) {







               document.getElementById(objectID).className="roll";







         }







         else {







              document.getElementById(objectID).className="over";







         }







   }







}















function ticks(theType, theName, thisName){







 // alert("asdsadsadasdas");







   if(theType==1){







       if(document.orderform.elements[thisName].checked)







           document.orderform.elements[theName].checked = true;







   }







   else{







       document.orderform.elements[thisName].checked = true;







       document.orderform.elements[theName].checked = true;







   }







}















function switchInputs(theBool, theName){







   // var org = new String(theName);







   // var regEx = new RegExp("catalogSelected", "gi");







   //alert("boxQty"+theName.substring(15,theName.length));







   // var org1 = theName.replace(/catalogSelected/, "boxsizeSelected");







   // var org2 = theName.replace(/catalogSelected/, "boxQty");







       // alert(org1);







       // alert(org2);







       var name1 = "boxQty"+theName.substr(15) ;







       var name2 = "boxsizeSelected"+theName.substr(15) ;















    for(i=0; i<document.orderform.elements.length; i++){







     // var tmpName = new String(document.orderform.elements[i].name);















      //alert(org2.match(document.orderform.elements[i].name));







      //var tmpName2 = tmpName.match(org2);







       if(document.orderform.elements[i].name==name1)  {







          document.orderform.elements[i].disabled = !theBool;







       }







    }







}















function tick(myID) {







   document.orderform.elements[myID].click();







}











//=======================================  Show The Other Input Field ======================================







function showOthers(){



  if(!getObjectVisibility('others')){



      changeObjectVisibility('others', 'visible');



  }







  else{



      changeObjectVisibility('others', 'hidden');



  }







}











//=============================================== Input Window ===================







function inputWindow(input, id){



		var props = "width=380, height=130, resizable=no,status=yes,toolbar=no,menubar=no,location=no,fullscreen=no";

		var props2 = "width=380, height=430, resizable=no,status=yes,toolbar=no,menubar=no,location=no,fullscreen=no";

	

		if(input==6)

			roELearningWindow = window.open("form.html", window.document.uniqueID+"content", props2);

		else

            roELearningWindow = window.open("shipping_policy.php?product="+input, window.document.uniqueID+"content", props);



}



function fShow() {



		if (roELearningWindow) roELearningWindow.focus();



}
















