/*
  $Id: tools.js,v 1.0 2007/11/30 22:30:55 hpdl Exp $
  Copyright (c) 2007 Design In Mind, Inc.
*/
	function popPage(x,y,URL,scroll) {
		if (scroll = ''){scroll = 'no';}
		var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no,left=50,top=50,width="+x+",height="+y;
		popup = window.open(URL,"MenuPopup",windowprops);
	}
	var current = '';
	function showDiv(state,id) {
    if (document.getElementById) {
      selection = document.getElementById(id);
    } else {
      selection = document.all[id];
    }
    if(current) current.style.display = 'none';

    if (state) {
    	selection.style.display = 'inline';
    } else {
    	selection.style.display = 'none';
    }
    current = selection;
	}

	var start=new Date();
	start=Date.parse(start)/1000;
	var counts=10;
	function CountDown(){
		var now=new Date();
		now=Date.parse(now)/1000;
		var x=parseInt(counts-(now-start),10);
		if(x>0){
			timerID=setTimeout("CountDown()", 100)
		}else{
	    if (document.getElementById) {
  	    selection = document.getElementById("Addcart");
    	} else {
      	selection = document.all["Addcart"];
    	}
    	if(selection)	selection.style.display = 'none';
   	}
	}
	window.setTimeout('CountDown()',100);

var selected;
function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }
  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;
  if (document.checkout_address.shipping[0]) {
    document.checkout_address.shipping[buttonSelect].checked=true;
  } else {
    document.checkout_address.shipping.checked=true;
  }
}
function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}
function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}
function clearText(thefield){
  if (thefield.defaultValue==thefield.value)
    thefield.value = ""
}
function validate(field) {
	if(amount > 0) {
		var valid = "0123456789.,"
		var ok = "yes";
		var temp;
		for (var i=0; i<field.value.length; i++) {
			temp = "" + field.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") ok = "no";
		}
		if (field.value <= 0) ok = "no";
		if (field.value > amount) ok = "no";
		if (ok == "no" && alert_text != '') {
			alert(alert_text);
			field.focus();
			field.select();
   	}
  }
}
var submitter = null;
function submitFunction() {
   submitter = 1;
}
function showPayment(state,id) {
/* 	document.all[id].style.visibility = 'visible';*/
    if (document.getElementById) {
      selection = document.getElementById(id);
    } else {
      selection = document.all[id];
    }
    if (state) {
    	selection.style.display = 'inline';
    } else {
    	selection.style.display = 'none';
    }
}
var selected;
function selectPayRowEffect(object, buttonSelect) {
//  if (!document.checkout_payment.payment[0].disabled){
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }
  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;
  if (document.checkout_payment.payment[0]) {
    document.checkout_payment.payment[buttonSelect].checked=true;
  } else {
    document.checkout_payment.payment.checked=true;
  }
//  }
}

function textlimiter(fname, count, limit) {
	if (fname.value.length > limit){ 
		fname.value = fname.value.substring(0, limit);
	} else {
		count.value = limit - fname.value.length;
	}
}

function qtylimiter(fname, limit, final, block) {
	var textalert = "";
	if (fname.value > limit){ 
		if (final) {
			textalert = "Your quantity of " + fname.value + " exceeds the final remaining stock of this item. \n The quantity has been changed to the number remaining. \nContact us for more information.";
			fname.value = limit;
		} else {
			textalert = "Your quantity of " + fname.value + " exceeds our current stock level of " + limit + ". \n Shipment will be delayed until stock is available. \nTo avoid delay of other items ordered, place this item on a separate order, or reduce the quantity to the available number. Contact us for more information if necessary.";
		}
		alert(textalert);
	} else {
		var qty = fname.value * 1;
		if (block > 1 && qty > block && (qty % block) != 0){
			var qtyup = qty + (block - (qty % block));
			var qtydn = qty - (qty % block);
			textalert = "To receive the best pricing, order in full cases.\n\nAdjust your quantity to the nearest casepack, either " + qtyup + " or " + qtydn + ".";
			alert(textalert);
		}
	}
}




