// Rollovers
function On(dir,src) { 
	var newImg = new Image();
	newImg.src = "http://www.leakalarm.com/assets/images/" + dir + "/" + src + "_ON.gif"; 
	document.images[src].src = newImg.src;
}

function Off(dir,src) { 
	var newImg = new Image();
	newImg.src = "http://www.leakalarm.com/assets/images/" + dir + "/" + src + "_OFF.gif"; 
	document.images[src].src = newImg.src;
}

// Form functions
function getRadioVal(radioGroup) {
	for (var i = 0; i < radioGroup.length; i++) {
		if (radioGroup[i].checked) return radioGroup[i].value;
	}
}

// Include required shipping fields if different shipping address is chosen
function setShipping(country) {
	set_variables('s_address1','blank','Shipping Street Address','');
	set_variables('s_city','blank','Shipping City','');
	
	if (country == 'Canada') {
		// Set Variables
		set_variables('s_province','blank','Shipping Province','');

		// Unset Variables
		unset_variables('s_state','blank','Shipping State','');
		
	} else if (country == 'Other') {
		// Set Variables
		set_variables('s_addressforeign','blank','Shipping Address','');

		// Unset Variables
		unset_variables('s_state','blank','Shipping State','');
		//unset_variables('ship_zip','blank','Shipping ZIP or Postal Code','');
		//unset_variables('ship_zip','Minimum Length','Shipping Zip Code','5');
		//unset_variables('ship_zip','Maximum Length','Shipping Zip Code','7');
		unset_variables('s_province','blank','Shipping Province','');
		
	} else if (country == 'United States') {
		// Set Variables
		set_variables('s_country','blank','Shipping Country','');
		set_variables('s_state','blank','Shipping State','');
		//set_variables('ship_zip','blank','Shipping ZIP or Postal Code','');
		//set_variables('ship_zip','Minimum Length','Shipping Zip Code 3','5');
		//set_variables('ship_zip','Maximum Length','Shipping Zip Code 4','7');
		
		// Unset Variables
		unset_variables('s_province','blank','Shipping Province','');
		unset_variables('s_addressforeign','blank','Shipping Address','');
	
	}
	// Show New Elements
	displayCountryElements(country);
}

function setBilling(country) {
	var radioVal = getRadioVal(document.checkout.addressMatch);
	unsetShipping();
	if (radioVal == 0) setShipping(country);
		 
	if (country == 'Canada') {
		// Set Variables
		set_variables('b_province','blank','Billing Province','');

		// Unset Variables
		unset_variables('b_state','blank','Billing State','');		
	} else if (country == 'Other') {
		// Set Variables
		set_variables('b_addressforeign','blank','Billing Address','');

		// Unset Variables
		unset_variables('b_state','blank','Billing State','');
		unset_variables('b_province','blank','Billing Province','');
		
	} else if (country == 'United States') {
		// Set Variables
		set_variables('b_state','blank','Billing State','');
		
		// Unset Variables
		unset_variables('b_province','blank','Billing Province','');
		unset_variables('b_addressforeign','blank','Billing Address','');
	}
}

function unsetShipping() {
	unset_variables('s_country','blank','Shipping Country','');
	unset_variables('s_address1','blank','Shipping Street Address','');
	unset_variables('s_city','blank','Shipping City','');
	unset_variables('s_state','blank','Shipping State','');
	//unset_variables('ship_zip','blank','Shipping ZIP or Postal Code','');
	//unset_variables('ship_zip','Minimum Length','Shipping ZIP or Postal Code','5');
	//unset_variables('ship_zip','Maximum Length','Shipping ZIP or Postal Code','7');
	unset_variables('s_province','blank','Shipping Province','');
	unset_variables('s_addressforeign','blank','Shipping Address','');
}

function addOne(form,which) {
	var val = document.forms[form].elements['qty1'].value;
	var newVal = parseInt(val);
	if (which != "qty1" && which != "qty2") {
		if (document.forms[form].elements[which].checked) {
			newVal++;
			document.forms[form].elements['qty1'].value = newVal;
			document.forms[form].elements['qty2'].value = newVal;
		} else {
			newVal--;
			document.forms[form].elements['qty1'].value = newVal;
			document.forms[form].elements['qty2'].value = newVal;
		}
	} else {
		newVal = document.forms[form].elements[which].value;
		document.forms[form].elements['qty1'].value = newVal;
		document.forms[form].elements['qty2'].value = newVal;
	}
	//document.forms[form].elements['qty'].value = newVal;
}

// Show and Hide Divs
function showHide(div,display) {
	if (document.getElementById && document.getElementById(div)) document.getElementById(div).style.display = display;
	else if (document.all && document.all[div]) document.all[div].style.display = display;
	else if (document.layers && document.layers[div]) document.layers.display = display;
}

function displayCountryElements(country) {
	if (country == "United States") {
		if (document.getElementById && document.getElementById('unitedstates')) document.getElementById('unitedstates').style.display = 'block';
		if (document.getElementById && document.getElementById('canada')) document.getElementById('canada').style.display = 'none';	
		if (document.getElementById && document.getElementById('foreign')) document.getElementById('foreign').style.display = 'none';	
		if (document.getElementById && document.getElementById('Sunitedstates')) document.getElementById('Sunitedstates').style.display = 'block';
		if (document.getElementById && document.getElementById('Scanada')) document.getElementById('Scanada').style.display = 'none';	
		if (document.getElementById && document.getElementById('Sforeign')) document.getElementById('Sforeign').style.display = 'none';	
		/*else if (document.all && document.all[div]) document.all[div].style.display = display;
		else if (document.layers && document.layers[div]) document.layers.display = display;*/
	} else if (country == "Canada") {
		if (document.getElementById && document.getElementById('unitedstates')) document.getElementById('unitedstates').style.display = 'none';
		if (document.getElementById && document.getElementById('canada')) document.getElementById('canada').style.display = 'block';	
		if (document.getElementById && document.getElementById('foreign')) document.getElementById('foreign').style.display = 'none';	
		if (document.getElementById && document.getElementById('Sunitedstates')) document.getElementById('Sunitedstates').style.display = 'none';
		if (document.getElementById && document.getElementById('Scanada')) document.getElementById('Scanada').style.display = 'block';	
		if (document.getElementById && document.getElementById('Sforeign')) document.getElementById('Sforeign').style.display = 'none';	
	} else {
		if (document.getElementById && document.getElementById('unitedstates')) document.getElementById('unitedstates').style.display = 'none';
		if (document.getElementById && document.getElementById('canada')) document.getElementById('canada').style.display = 'none';	
		if (document.getElementById && document.getElementById('foreign')) document.getElementById('foreign').style.display = 'block';	
		if (document.getElementById && document.getElementById('Sunitedstates')) document.getElementById('Sunitedstates').style.display = 'none';
		if (document.getElementById && document.getElementById('Scanada')) document.getElementById('Scanada').style.display = 'none';	
		if (document.getElementById && document.getElementById('Sforeign')) document.getElementById('Sforeign').style.display = 'block';	
	}
}

function cartSelect(country) {
	if (country == 'US') {
		document.getElementById('US').style.display='block';
		document.forms['tax-and-ship'].action = 'tax-and-shipping2.php';
	} else {
		document.getElementById('US').style.display='none';
		document.forms['tax-and-ship'].action = 'intl-tax-and-ship.php';
	}
}