function popUp(URL,width,height) 
{
	x = (screen.width - width) / 2;
	y = (screen.height - height) /2;
	window.open(URL,'Image','toolbar=no,width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y);
}

var allPageTags = new Array(); 
function hide_all() {
	//Populate the array with all the page tags 
	var allPageTags=document.getElementsByTagName("*"); 
	//Cycle through the tags using a for loop 
	for (i=0; i<allPageTags.length; i++) { 
		 //Pick out the tags with our class name 
		if (allPageTags[i].className=='menu_container') { 
			//Manipulate this in whatever way you want 
	 		//allPageTags[i].style.display='none';
	 		new Effect.BlindUp(allPageTags[i]);
		} 
	} 
} 

function rollUpDown(whichDiv)
{
	if(document.getElementById(whichDiv).style.display == "none")
		new Effect.BlindDown(document.getElementById(whichDiv));
	else
		new Effect.BlindUp(document.getElementById(whichDiv));
}

function showHide(theid){
	var allPageTags=document.getElementsByTagName("*"); 
	for (i=0; i<allPageTags.length; i++) 
	{ 
		if (allPageTags[i].className=='menu_container' && allPageTags[i].id != theid && allPageTags[i].style.display != "none")
	 		new Effect.BlindUp(allPageTags[i]);
	} 
	if(document.getElementById(theid).style.display == "none")
		new Effect.BlindDown(document.getElementById(theid));	
	else 
		new Effect.BlindUp(document.getElementById(theid));
}

function pausecomp(millis) 
{
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); } 
	while(curDate-date < millis);
} 	

function fadeOut(theid)
{
	//new Effect.Fade(document.getElementById(theid),{duration: .1});
	document.getElementById(theid).style.display = 'none';
}

function fadeIn(theid)
{
	//new Effect.Appear(document.getElementById(theid),{duration: .1});
	document.getElementById(theid).style.display = 'block';
}

function removeDescriptiveElement(formName,controlToRemoveFirstElementFrom)
{
	if(document.forms[formName].elements[controlToRemoveFirstElementFrom].options[0].text == 'Country')
		document.forms[formName].elements[controlToRemoveFirstElementFrom].options[0] = null;
}

function modShipSelect()
{
	/*document.getElementById('sm_label').style.display = 'block';*/
	document.getElementById('sm_content').style.display = 'block';
	
	var countryName = document.getElementById('country').value;
		
	if(countryName == 'United States')
	{
		document.forms['checkout_1'].elements['shipping_method_united_states'].name = "shipping_method";
		document.forms['checkout_1'].elements['shipping_method_canada'].name = "shipping_method_1";
		document.forms['checkout_1'].elements['shipping_method_overseas'].name = "shipping_method_2";
		
		document.getElementById('os_ship_not').style.display = 'none';
		document.getElementById('shipping_method_united_states').style.display = 'inline';
		document.getElementById('shipping_method_canada').style.display = 'none';
		document.getElementById('shipping_method_overseas').style.display = 'none';

		getShippingCost('shipping_method_united_states');
	}
	else if(countryName == 'Canada')
	{
		document.forms['checkout_1'].elements['shipping_method_united_states'].name = "shipping_method_1";
		document.forms['checkout_1'].elements['shipping_method_canada'].name = "shipping_method";
		document.forms['checkout_1'].elements['shipping_method_overseas'].name = "shipping_method_2";
		
		document.getElementById('os_ship_not').style.display = 'none';
		document.getElementById('shipping_method_united_states').style.display = 'none';
		document.getElementById('shipping_method_canada').style.display = 'inline';
		document.getElementById('shipping_method_overseas').style.display = 'none';

		getShippingCost('shipping_method_canada');		
	}
	else
	{
		document.forms['checkout_1'].elements['shipping_method_united_states'].name = "shipping_method_1";
		document.forms['checkout_1'].elements['shipping_method_canada'].name = "shipping_method_2";
		document.forms['checkout_1'].elements['shipping_method_overseas'].name = "shipping_method";

		document.getElementById('os_ship_not').style.display = 'inline';
		document.getElementById('shipping_method_united_states').style.display = 'none';
		document.getElementById('shipping_method_canada').style.display = 'none';
		document.getElementById('shipping_method_overseas').style.display = 'inline';
		
		getShippingCost('shipping_method_overseas');		
	}
}

function modTaxAdded(showCode,whichInput)
{
	if(showCode == false)
	{
		if(whichInput == 'zip')
		{
			tax_active_bybilling = false;
			document.getElementById('taxAdded').style.display = 'none';
		}
		else if(whichInput == 'ship_zip')
		{
			tax_active_byshipping = false;
			document.getElementById('taxAdded_ship').style.display = 'none';

			tax_active_bybilling = false;
			document.getElementById('taxAdded').style.display = 'none';
		}

		if(tax_active_bybilling == false && tax_active_byshipping == false)
		{
			document.getElementById('tax_table').style.display = 'none';
			tax_active = false;
		}
	}
	else if(showCode == true)
	{
		if(whichInput == 'zip')
		{
			document.getElementById('taxAdded').style.display = 'block';
			tax_active_bybilling = true;
		}
		else if(whichInput == 'ship_zip')
		{
			document.getElementById('taxAdded_ship').style.display = 'block';
			tax_active_byshipping = false;
		}

		document.getElementById('tax_table').style.display = 'block';
		tax_active = true;
	}
}

function checkForTaxableZipCode(whichInput)
{
	zipData = document.getElementById(whichInput).value;
	if(whichInput == 'ship_zip' && zipData == '')
	{
		whichInput = 'zip';
		zipData = document.getElementById('zip').value;
	}
	zipRequestUrl = 'https://www.alternativecinema.com/ajax/ajax.taxable_zipcode.php?zip_data='+zipData;
	new Ajax.Request(zipRequestUrl, 
	{ method:'get',
    	onSuccess: function(transport)
    	{
      		var response = transport.responseText || "no response text";
      		if(response == '1') modTaxAdded(true,whichInput);
      		else modTaxAdded(false,whichInput);

      		recalculateCost();
    	}
  	});
}

function getShippingCost(currentShippingSelectorControl)
{
	valSh = document.getElementById(currentShippingSelectorControl).value;
	shipRequestUrl = 'https://www.alternativecinema.com/ajax/ajax.calculate_shipping_cost.php?shipping_method_id='+valSh+'&quantity='+total_quantity;
	new Ajax.Request(shipRequestUrl, 
	{ method:'get',
    	onSuccess: function(transport)
    	{
      		var response = transport.responseText || "no response text";
      		if(response == 'error')
      		{
      			shipping_active = false;
      		}
      		else
      		{
	      		shipping_cost = response;
      			shipping_active = true;
				document.getElementById('ship_table').style.display = 'block';
				document.getElementById('shipping').innerHTML = "$"+shipping_cost;
      		}
      		recalculateCost();
    	}
  	});
}

function recalculateCost()
{
	if(shipping_active == true && tax_active == true)
	{
		addNumbersRequestUrl = 'https://www.alternativecinema.com/ajax/ajax.add_numbers.php?n1='+original_total+'&n2='+shipping_cost+'&n3='+tax;
	}
	else if(shipping_active == true)
	{
		addNumbersRequestUrl = 'https://www.alternativecinema.com/ajax/ajax.add_numbers.php?n1='+original_total+'&n2='+shipping_cost;	
	}
	else if(tax_active == true)
	{
		addNumbersRequestUrl = 'https://www.alternativecinema.com/ajax/ajax.add_numbers.php?n1='+original_total+'&n2='+tax;
	}
	new Ajax.Request(addNumbersRequestUrl,
	{ method:'get',
		onSuccess: function(transport)
		{
      		var response = transport.responseText || "no response text";
      		if(response == 'error')
      		{
      		}
      		else
      		{
      			changeTotalDisplay(response);
      		}
		}
	});
}

function changeTotalDisplay(anum)
{
	document.getElementById('total').innerHTML = "$"+anum;	
	document.getElementById('total_paypal').innerHTML = "$"+anum;	
	document.getElementById('total_mailin').innerHTML = "$"+anum;	
}

function cardTypeChange()
{
	var ctype = document.getElementById('card_type').value;
	if(ctype =='Visa' || ctype == 'MasterCard' || ctype =='Discover')
	{
		document.getElementById('credit_card').style.display = "block";
		document.getElementById('paypal').style.display = "none";
		document.getElementById('mail-in').style.display = "none";
	}
	else if(ctype == 'Paypal')
	{
		document.getElementById('credit_card').style.display = "none";
		document.getElementById('paypal').style.display = "block";
		document.getElementById('mail-in').style.display = "none";	
	}
	else if(ctype == 'Mail-in payment')
	{
		document.getElementById('credit_card').style.display = "none";
		document.getElementById('paypal').style.display = "none";
		document.getElementById('mail-in').style.display = "block";	
	}

}

function ageVerify()
{
	var ageVal = document.getElementById('age_verify').value;
	if(ageVal == 'on') document.getElementById('submit').disabled = 0;
	else document.getElementById('submit').disabled = 1;
}
