// JavaScript Document

function getStates(){
	var country=$('#country').val();
	$.ajax({
				type: "GET",
				url: '/includes/ajax_functions.php',
				data: "func_name=getStates&country="+country,
				success: function(html){
					$('#stateMenu').html(html);
					assignStateChange();
				}
		});			
}

function assignStateChange(){
	
	$('#state').change(function(){
			var country=$('#country').val();
			var state=$(this).val();
			$.ajax({
						type: "GET",
						url: '/includes/ajax_functions.php',
						data: "func_name=getRetailers&country="+country+"&state="+state,
						success: function(html){
							$('#storesContainer').html(html);
						}
				});	
		
	});	
	
	
}
function getZipStores(){
	var zip=$('#inpZip').val();
	$('#storesContainer').fadeOut('fast');
	$.ajax({
				type: "GET",
				url: '/ajax_store_search.php',
				data: "zip="+zip,
				success: function(html){
					$('#storesContainer').html(html);
					$('#storesContainer').fadeIn('fast');
					
				}
		});			
}
//
//
function downloadMedia(media_id,media_type){
	
var tempIFrame = document.createElement('iframe');
		tempIFrame.width=0;
		tempIFrame.height=0;
		
		//if(OSName=='Windows' || uses_downloader==false){
			//alert(uses_downloader);../checkout/filedownload.php?trackName='+trackNamex
			tempIFrame.src='/includes/getFile.php?media_id='+media_id+'&media_type='+media_type;
			//tempIFrame.src=pathtostore+'filedownload.php?trackName='+trackID+'&sid='+sid;
		//}else{
		//	tempIFrame.src=pathtostore+'filedownload2.php?track_id='+trackID+'&sid='+sid;
			//tempIFrame.src='bgusa://www.beggarsgroupusa.com/store/filedownload.php?track_id='+trackID+'&sid='+sid;
			
		//}
		
		
		tempIFrame.style.visibility="hidden";
		document.getElementById('downloadiframes').appendChild(tempIFrame);
		var pageVar="/myDownloads/"+"track_id"+"-"+"songName";
		pageTracker._trackPageview(pageVar);
}
//
//
$(document).ready(function() {
   
	assignStateChange();
	
	$('#countrySelect').change(function(){
		var terit=$(this).val();
		if(terit=='UK'){
			//forward to uk.buyearlygetnow.com
			window.location = "http://uk.buyearlygetnow.com/";
		}else{
			$('.hideUntilCountry').fadeIn('fast');
		}
	});
	
	

});
