
var dimages=new Array();
var numImages=3;
for (i=0; i<numImages; i++)
{
dimages[i]=new Image();
dimages[i].src="/images/dogdna_header"+(i+1)+".jpg";
}
var curImage=-1;
function swapPicture()
{
if (document.images)
{
var nextImage=curImage+1;
if (nextImage>=numImages)
nextImage=0;
if (dimages[nextImage] && dimages[nextImage].complete)
{
var target=0;
if (document.images.dogdna)
target=document.images.dogdna;
if (document.all && document.getElementById("dogdna"))
target=document.getElementById("dogdna");
// make sure target is valid.  It might not be valid
//   if the page has not finished loading
if (target)
{
target.src=dimages[nextImage].src;
curImage=nextImage;
}
setTimeout("swapPicture()", 5000);
}
else
{
setTimeout("swapPicture()", 500);
}
}
}
setTimeout("swapPicture()", 5000);
function popitup(url) {
newwindow=window.open(url,'name','scrollbars=yes,resizable=yes,height=420,width=600');
if (window.focus) {newwindow.focus()}
return false;
}
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}

function calcTotal() {
	var shipping = 0;
	var price = document.orderForm.price.value;
	var quantity = document.orderForm.quantity.value;
	var order_total = 0;
	var now = new Date();
	var year = now.getYear();
	
	/*
	if(year < 2009 && quantity > 1) { 
		price = price * 0.9;
		order_total = round_decimals(order_total * 0.9, 2);
		document.getElementById('yellow').innerHTML = "(+10% Off)";
	} else {
		document.getElementById('yellow').innerHTML = "(Sale)";
	}
	*/
	
	var shipMethod = document.orderForm.ship_method.value;
	var shipTo_country = document.orderForm.shipTo_country.value;

	if(shipMethod == "expedited") {
		if(shipTo_country == "Canada") {
			document.orderForm.ship_method.value = "free";
			alert('FedEx shipping is not available to Canada');
		}else{
			shipping = 20;
		}
	}
	
	order_total = (quantity * price) + shipping;
	price = round_decimals(price, 2);
	order_total = round_decimals(order_total, 2);
	document.getElementById('screenPrice').innerHTML = price;
	document.orderForm.total.value = order_total;
}




function round_decimals(original_number, decimals) {
var result1 = original_number * Math.pow(10, decimals)
var result2 = Math.round(result1)
var result3 = result2 / Math.pow(10, decimals)
return pad_with_zeros(result3, decimals)
}
function pad_with_zeros(rounded_value, decimal_places) {
// Convert the number to a string
var value_string = rounded_value.toString()
// Locate the decimal point
var decimal_location = value_string.indexOf(".")
// Is there a decimal point?
if (decimal_location == -1) {        
// If no, then all decimal places will be padded with 0s
decimal_part_length = 0        
// If decimal_places is greater than zero, tack on a decimal point
value_string += decimal_places > 0 ? "." : ""
}
else {
// If yes, then only the extra decimal places will be padded with 0s
decimal_part_length = value_string.length - decimal_location - 1
}
// Calculate the number of decimal places that need to be padded with 0s
var pad_total = decimal_places - decimal_part_length    
if (pad_total > 0) {        
// Pad the string with 0s
for (var counter = 1; counter <= pad_total; counter++) 
value_string += "0"
}
return value_string
}
function popupCVN(){
var dest = "help/EN/cvn.html";
var leftPosition = (screen.availWidth - 400) / 2;
var topPosition = (screen.availHeight - 550) / 2;
var attributes = "scrollbars=no,resizable=no,width=500,height=710,left=" + leftPosition;
attributes += ",screenX=";
attributes += leftPosition;
attributes += ",top=";
attributes += topPosition;
attributes += ",screenY=";
attributes += topPosition;
window.open(dest, "cvn_help_window", attributes);
return false;
}
function popupCheck(){
var dest = "help/EN/check.html";
var leftPosition = (screen.availWidth - 400) / 2;
var topPosition = (screen.availHeight - 360) / 2;
var attributes = "scrollbars=no,resizable=no,width=500,height=490,left=" + leftPosition;
attributes += ",screenX=";
attributes += leftPosition;
attributes += ",top=";
attributes += topPosition;
attributes += ",screenY=";
attributes += topPosition;
window.open(dest, "check_help_window", attributes);
return false;
}
function setShipFromBill(){
if(document.orderForm.ship_same_as_bill.checked){
document.orderForm.shipTo_firstName.value = document.orderForm.billTo_firstName.value;
document.orderForm.shipTo_lastName.value = document.orderForm.billTo_lastName.value;
document.orderForm.shipTo_company.value = document.orderForm.billTo_company.value;
document.orderForm.shipTo_street1.value = document.orderForm.billTo_street1.value;
document.orderForm.shipTo_street2.value = document.orderForm.billTo_street2.value;
document.orderForm.shipTo_city.value = document.orderForm.billTo_city.value;
document.orderForm.shipTo_state.value = document.orderForm.billTo_state.value;
document.orderForm.shipTo_postalCode.value = document.orderForm.billTo_postalCode.value;
document.orderForm.shipTo_country.value = document.orderForm.billTo_country.value;
document.orderForm.shipTo_cityCanada.value = document.orderForm.billTo_cityCanada.value;
document.orderForm.shipTo_provinceCanada.value = document.orderForm.billTo_provinceCanada.value;		
}else{
document.orderForm.shipTo_firstName.value = "";
document.orderForm.shipTo_lastName.value = "";
document.orderForm.shipTo_company.value = "";
document.orderForm.shipTo_street1.value = "";
document.orderForm.shipTo_street2.value = "";
document.orderForm.shipTo_city.value = "";
document.orderForm.shipTo_state.value = "";
document.orderForm.shipTo_postalCode.value = "";
document.orderForm.shipTo_country.value = "Choose";
}
}

function uncheckShipFromBill(){
	document.orderForm.ship_same_as_bill.checked = false;
	var ship_country = document.orderForm.shipTo_country.value;
	var ship_method = document.orderForm.ship_method.value;
	
	if(ship_country == "Canada") {
		if(ship_method == "expedited") {
			document.orderForm.ship_method.value = "free";
			alert('FedEx shipping is not available to Canada');
		}
	}
}
function toggleCVN(oob) {
var cvvDisplay = document.orderForm.displayCVV.value;
var cvvRequired = document.orderForm.requireCVV.value;
var elem = document.getElementById('cvnrow');
var elem2 = document.getElementById('cvnlabel');
var switch1 = document.getElementById('switchrow1');
var switch2 = document.getElementById('switchrow2');
if(oob.value == '' || oob.value == 'NONE'){
elem.style.display = 'none';
} else if (cvvRequired.indexOf(oob.value,0) != -1) {
elem.style.display = '';
elem2.className = 'required';
} else if (cvvDisplay.indexOf(oob.value,0) != -1) {
elem.style.display = '';
elem2.className = '';
} else {
elem.style.display = 'none';
}
if('024' == oob.value){
switch1.style.display = '';
switch2.style.display = '';
}else{
switch1.style.display = 'none';
switch2.style.display = 'none';
}
}
function toggleOff(oob) {
var elem;
elem = document.getElementById(oob);
elem.style.display = 'none';
}
function togglePhone() {
var elem1 = document.getElementById('phone_number');
if(!elem1){ return; }
if(3 == 3){ elem1.className = ''; return; }
if (document.orderForm.paymentOption[3].checked){
elem1.className = 'required';
}else{
elem1.className = '';
}
}
function requirePhone() {
var elem1 = document.getElementById('phone_number');
if(!elem1){ return; }
elem1.className = 'required';
}
function billcity(){
var billcountry = document.orderForm.billTo_country.value;
if("United States" == billcountry || "Choose" == billcountry){
document.getElementById('billCityUS').style.display = '';
document.getElementById('billCityCanada').style.display = 'none';
}else if("Canada" == billcountry){
document.getElementById('billCityUS').style.display = 'none';
document.getElementById('billCityCanada').style.display = '';

//this.billCityUS.style.visibility = 'hidden';
//this.billCityCanada.style.visibility = 'visible';
}
}

function shipcity(){
var shipcountry = document.orderForm.shipTo_country.value;
if("United States" == shipcountry || "Choose" == shipcountry){
document.getElementById('shipCityUS').style.display = '';
document.getElementById('shipCityCanada').style.display = 'none';
}else if("Canada" == shipcountry){
document.getElementById('shipCityUS').style.display = 'none';
document.getElementById('shipCityCanada').style.display = '';
}
}
