// JavaScript Document
$j(function() {
	var qrtext = 'http://vodafone.co.nz';
	var qrsize = '230x230';
	$j(".formBtn").click(function() {
		var whatTab 	= $j("#selectQRcode input:checked").val();
		var qrsize 		= $j("#qrcode input:checked").val();
		var qrposition	= $j("#qrcode input:checked").attr("id");
		var qrtext 		= escape($j("#" + whatTab + " input.qrtext").val());
		var qrtextarea	= escape($j("#" + whatTab + " textarea").val());

		var qrname		= "AN%3A" + escape($j("#" + whatTab + " input.qrname").val()) + "%3B";
		var qrnumber	= "TEL%3A" + escape($j("#" + whatTab + " input.qrnumber").val()) + "%3B";
		var qremail		= "EMAIL%3A" + escape($j("#" + whatTab + " input.qremail").val()) + "%3B";
		var theCode;
		
		if((qrtextarea != null) && (qrtextarea != "undefined") && (qrtextarea != "")) {
			theCode		= qrtextarea;
		} else if ((qrtext != null) && (qrtext != "undefined") && (qrtext != "")) {
			theCode		= qrtext;
		} else {
			theCode		= "MECARD%3" + qrname + qrnumber + qremail;
		}

		var fullSrc 	= "http://chart.apis.google.com/chart?cht=qr&chs=" + qrsize +"&chl=" + theCode + "&choe=UTF-8"
		var embed 		= '&lt;img src="' + fullSrc + '" alt="qrcode" /&gt;';
					
		$j("#qrcode img").attr("src", fullSrc);
		$j(".img").attr("class", "img " + qrposition);
		
		$j(".qrdetails .embed").remove();
		$j(".qrdetails").append('<p class="embed"> ' + embed + '</p>');
	});
	
	// Tab Switch
	$j("#selectQRcode input").click(function() {
		var whatTab = $j(this).val();
		$j("#createQR div").each(function() {
			$j(this).removeClass("selected");
		});
		$j("#" + whatTab).addClass("selected");
	});
	
	$j('#qr_text .qrtext').limit('160','.counter');
});
