function sendEmail() {
	hideError();
	var qr = $("#qrCodeImage").attr("src");
	if (qr != '/images/redlaser_qr.png') {
		var address = $("#qrEMailAddress").val();
		if (address != '') {
			var url = "email.php?address=" + address + "&qr=" + qr;
			$.get(url, function(data) {
				if (data == 1) {
					showSuccess("E-Mail Sent.");
				} else {
					showError("E-Mail did not Send");
				}
			});
		} else {
			showError("You must enter an e-mail address.");
		}
	}
}
function showError(title) {
	$("#dlgErrorText").html(title);
	$("#dlgError").fadeIn("slow");
}
function hideError(){
	$("#dlgError").fadeOut("slow");
}

function showSuccess(title) {
	$("#dlgSuccessText").html(title);
	$("#dlgSuccess").fadeIn("slow");
}
function hideSuccess(){
	$("#dlgSuccess").fadeOut("slow");
}
function changeQRAction() {
	hideSuccess();
	hideError();
	var type = $("#qrCodeType option:selected").val();
	var url = "/wp-content/themes/redlaser/qrcode/ajax.php?type=" + type;

	$.get(url, function(data) {
		$("#qrActionContainer").fadeOut("fast", function() {
			$("#qrActionContainer").html(data);
			$("#qrActionContainer").fadeIn("fast");
		});
	});
}

function swapQR(data) {
	hideSuccess();
	$("#qrCodeHover").fadeOut();
	if (data == -1) {
		showError("There was an error creating your QR Code");
	} else {
		hideError();
		$("#qrCodeImage").fadeOut("fast", function() {
			$("#qrCodeContainer").fadeOut("fast", function() {

				$("#qrCodeImage").attr("src", data);
				$("#qrCodeContainer").fadeIn("fast", function() {
					$("#qrCodeImage").fadeIn("fast");
				});
			});
		});
	}
}

function showMenu(id) {
	
	if(document.getElementById(id).style.display == "none") {
		document.getElementById(id).style.display = "block";	
	} else {
		document.getElementById(id).style.display = "none";		
	}
	
}

function showTip() {
	
	if(document.getElementById('UDID-tip').style.display == "none") {
		document.getElementById('UDID-tip').style.display = "block";	
	} else {
		document.getElementById('UDID-tip').style.display = "none";		
	}
	
}

function changeTabDeveloper(tab) {
	var stats = document.getElementById('stats');
	var myaccount = document.getElementById('myaccount');
	var newsdk = document.getElementById('newsdk');
	var upgrade = document.getElementById('upgrade');

	var statsOff = document.getElementById('stats-off');
	var myaccountOff = document.getElementById('myaccount-off');
	var newsdkOff = document.getElementById('newsdk-off');
	var upgradeOff = document.getElementById('upgrade-off');

	var statsDashboard = document.getElementById('dashboard-stats');
	var myaccountDashboard = document.getElementById('dashboard-myaccount');
	var newsdkDashboard = document.getElementById('dashboard-newsdk');
	var upgradeDashboard = document.getElementById('dashboard-upgrade');
	
	stats.style.display = "none";
	myaccount.style.display = "none";
	newsdk.style.display = "none";
	if (upgrade != null) {
		upgrade.style.display = "none";		
	}
	
	statsOff.style.display = "none";
	newsdkOff.style.display = "none";
	myaccountOff.style.display = "none";
	if (upgradeOff != null) {
		upgradeOff.style.display = "none";		
	}
	
	statsDashboard.style.display = "none";
	newsdkDashboard.style.display = "none";
	myaccountDashboard.style.display = "none";
	if (upgradeDashboard != null) {
		upgradeDashboard.style.display = "none";		
	}
	
	if(tab == "stats") {
		stats.style.display = "block";
		myaccountOff.style.display = "block";
		newsdkOff.style.display = "block";
		if (upgradeOff != null) {
			upgradeOff.style.display = "block";			
		}
		statsDashboard.style.display = "block";
	} else if(tab == "myaccount") {
		statsOff.style.display = "block";
		myaccount.style.display = "block";
		newsdkOff.style.display = "block";
		if (upgradeOff != null) {
			upgradeOff.style.display = "block";			
		}
		myaccountDashboard.style.display = "block";
	} else if(tab == "newsdk") {
		statsOff.style.display = "block";
		newsdk.style.display = "block";
		myaccountOff.style.display = "block";
		if (upgradeOff != null) {
			upgradeOff.style.display = "block";			
		}
		newsdkDashboard.style.display = "block";
	} else if(tab == "upgrade") {
		statsOff.style.display = "block";
		newsdkOff.style.display = "block";
		myaccountOff.style.display = "block";
		upgrade.style.display = "block";
		upgradeDashboard.style.display = "block";
	}
	
}

function changeTabFAQ(tab) {
	
	document.getElementById('consumer').style.display = "none";
	document.getElementById('developer').style.display = "none";
	
	document.getElementById('consumer-off').style.display = "none";
	document.getElementById('developer-off').style.display = "none";
	
	document.getElementById('faq-consumer').style.display = "none";
	document.getElementById('faq-developer').style.display = "none";
	
	if(tab == "consumer") {
		document.getElementById('consumer').style.display = "block";
		document.getElementById('developer-off').style.display = "block";
		document.getElementById('faq-consumer').style.display = "block";
	} else if(tab == "developer") {
		document.getElementById('consumer-off').style.display = "block";
		document.getElementById('developer').style.display = "block";
		document.getElementById('faq-developer').style.display = "block";
	}
	
}

function downloadFormIphone() {

    // Check that checkbox is checked
    if (!document.DownloadIphone.Terms.checked) {
                    alert("- You must agree to the Terms and Conditions.");
                    document.DownloadIphone.Terms.focus();
                    return false;
    }
    
    window.location = "/download/download.php?id=DevSDK";
    return true;
    
}

function downloadFormAndroid() {

    // Check that checkbox is checked
    if (!document.DownloadAndroid.Terms.checked) {
                    alert("- You must agree to the Terms and Conditions.");
                    document.DownloadAndroid.Terms.focus();
                    return false;
    }
    
    window.location = "/download/download.php?id=DevSDKAndroid";
    return true;
    
}

function expandAnswer(id) {

    if(document.getElementById(id).style.display == "none") {
                    document.getElementById(id).style.display = "block";
                    document.getElementById("expander-" + id).innerHTML = '<img src="/images/minus-sign.png" alt="Minus sign" width="14" height="13">';
    } else {
                    document.getElementById(id).style.display = "none";
                    document.getElementById("expander-" + id).innerHTML = '<img src="/images/plus-sign.png" alt="Plus sign" width="14" height="13">';
    }
    
}

function clearErrors(divID) {
	$(':text, :password, :file', divID).val('');
	$(':input,select option', divID).removeAttr('checked').removeAttr('selected');
	$('select option:first', divID).attr('selected', true);
	$('font', divID).text('');
}

function clearCompanyNameErrors(divID, defaultCompanyNameVal) {
	$(':text, :password, :file', divID).val(defaultCompanyNameVal);
	$('font', divID).text('');
}
