// JavaScript Document


function roundNumber(number) {
    var decimals = 2;
    var dec_point = '.';
    var thousands_sep = ',';
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

function stripPage(){
    myCode = document.body.innerHTML;
    myCodeArray = myCode.split('\<\!\-\-__START_TEMPLATE__-\-\>');
    myCode = myCodeArray[1];
    myCodeArray = myCode.split('\<\!\-\-__END_TEMPLATE__-\-\>');
    myCode = myCodeArray[0];
    document.body.innerHTML = myCode;

    window.print();

    //alert(myCodeArray[1]);
}

function goThere(url){
   window.location.href = url;

   return false;
}

function applyDisplay(element, value) {
   if(document.getElementById(element)){
      document.getElementById(element).style.display = value;
   }
}

function addReview(){
   //applyDisplay('productReviewsAddNote', 'none');
   applyDisplay('productReviewsAdd', 'block');
   document.reviewForm.reviewName.focus();
}

function showDescription(){
   applyDisplay('productDescription', 'block');
   applyDisplay('productReviews', 'none');
   applyDisplay('productsRelated', 'none');
}

function showReviews(){
   applyDisplay('productDescription', 'none');
   applyDisplay('productReviews', 'block');
   applyDisplay('productsRelated', 'none');
}

function showRelated(){
   applyDisplay('productDescription', 'none');
   applyDisplay('productReviews', 'none');
   applyDisplay('productsRelated', 'block');
}

function checkReview(){
   if(!document.reviewForm.reviewName.value || !document.reviewForm.reviewBody.value){
      alert("All Review Fields are Required Fields");
      return false;
   }

   return true;
}


function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=600,height=320,left = 240,top = 212');");
}
function popUp1(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=600,height=600,left = 240,top = 212');");
}

	var checkedBoxes = 0; 
	function validateForm(){
		
		if(checkedBoxes>0){
			return true;
		}else{
			alert('Please select an item.');
			return false;
		}
	}
	function calculateCheck(obj){
		if(obj.checked){
			checkedBoxes++;
		}else{
			checkedBoxes--;
		}
	}