<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function switchTab() {
	var deviceName = gup( 'device' );
	if (deviceName != '') {
		ColdFusion.Layout.selectTab('DeviceTabs',deviceName);
	}
}

function viewChannelLineup(){
	window.top.location = "/onxm/full-channel-listing.cfm";
}

function changeDevice(theIndex){
var dropdownIndex = theIndex;

if (dropdownIndex == 0) {
	$('#tabs').tabs('select', 0);
}
else 
	if (dropdownIndex == 1) {
		$('#tabs').tabs('select', 1);
	}
else 
	if (dropdownIndex == 2) {
		$('#tabs').tabs('select', 2);
	}
else 
	if (dropdownIndex == 3) {
		$('#tabs').tabs('select', 3);
	}
	else {
		$('#tabs').tabs('select', 1);

		
		//pageTracker._trackPageview('/gatrack/blackberry/home_dropdown_'+dropdownIndex);
		var BBDevices = new Array("0", "8500", "8900", "9000", "9700","9500", "tour"); // condensed array
		if (dropdownIndex > 1) {
			var theIndex = dropdownIndex - 2;
			var picValue = BBDevices[theIndex];
			ShowBB2(picValue);
			document.getElementById('device').selectedIndex = dropdownIndex;
			document.getElementById('appDownloadDevice').selectedIndex = (dropdownIndex-3);
		}
	}
}
function ShowBB2(bbModel) {
//pageTracker._trackPageview('gatrack/blackberry/home_curve_'+bbModel);
var BBDevices=new Array("8500","8900","9000","9700","9500","tour"); // condensed array
var BBModel = bbModel;
for(var i=0; i<BBDevices.length; i++) {
	var value = BBDevices[i];
	document['menu_'+value].src='../images/online/blackberry/menu_'+value+'_off.jpg';
}

var lBB = 'bbLarge';
var mBB = 'menu_'+bbModel;
lOn = '../images/online/blackberry/device_'+bbModel +'.jpg';
mOn = '../images/online/blackberry/menu_' +bbModel +'_on.jpg';
document.getElementById(lBB).src = lOn;
document.getElementById(mBB).src = mOn;
}
//-->

$().ready(function() {

	var oTxtFields = $('input,textarea');
	$.each(oTxtFields, function(){
		var label = $('label[for=' + $(this).attr('id') + ']');
		label.addClass('overlayed');
		if (!$(this).val() == '') {
			label.hide();
		}
		$(this)
			.focus(function(e){
				$('label[for=' + $(e.target).attr('id') + ']').hide();
			})
			.blur(function(e){
				if ($(e.target).val() == '') {
					$('label[for=' + $(e.target).attr('id') + ']').show();
				}
			});
});
	
function showTrialSubmit(showLoading,msg){
	
	if(showLoading == "true"){
		$("#submitBox").css("display","none");
		$("#loadBar").css("display","block");
		$("#errorMessage").css("display","none");
		$("#errorMessage #errorText").html("");
	}else{
		$("#submitBox").css("display","block");
		$("#loadBar").css("display","none");
		$("#errorMessage").css("display","block");
		$("#errorMessage #errorText").html(msg);
	}	
}

function showDownloadSubmit(showLoading,msg){
	
	if(showLoading == "true"){
		$("#bbDownloadBar").css("display","block");
		$("#errorMessage1").css("display","none");
		$("#errorMessage1 #errorText1").html("");
	}else{
		$("#bbDownloadBar").css("display","none");
		$("#errorMessage1").css("display","block");
		$("#errorMessage1 #errorText1").html(msg);
	}	
}

function bbDownloadSuccess(){
		$("#bbDownload").css("display","none");
		$("#bbDownloadConfirm").css("display","block");
}

function androidDownloadSubmit(showLoading,msg){
	
	if(showLoading == "true"){
		$("#androidDownloadBar").css("display","block");
		$("#errorMessage1").css("display","none");
		$("#errorMessage1 #errorText1").html("");
	}else{
		$("#androidDownloadBar").css("display","none");
		$("#errorMessage1").css("display","block");
		$("#errorMessage1 #errorText1").html(msg);
	}	
}

function androidDownloadSuccess(){
		$("#androidDownload").css("display","none");
		$("#androidDownloadConfirm").css("display","block");
}

$("#bbDownloadform").validate({
 submitHandler: function(form) {
   
		showDownloadSubmit("true","");
		
		$.post('app_download.cfm', $("#bbDownloadform").serialize(), function(data, status){

		switch (eval(data)) {

		    case 999:
		       showDownloadSubmit("false","Sorry, your download could not be completed at this time.  Please try again.");
		        break;
			case 000:
				bbDownloadSuccess();
				break;
			default:
				showDownloadSubmit("false","Sorry, we could not complete your request at this time.");	
				break;
			}
	});
 },
		rules: {
			bbDownloadEmail: {
				required: true,
				QAsEmailValidator: true
			},
			appDownloadDevice: {
				required: true
			}
		},
		messages: {
			bbDownloadEmail: {
				required: "Please enter your email address",
				QAsEmailValidator: "Please enter a valid email address"
			},
			appDownloadDevice: {
				required: "Please select your BlackBerry model"
			}
		}
});

$("#androidDownloadform").validate({
 submitHandler: function(form) {
   
		androidDownloadSubmit("true","");
		
		$.post('app_download.cfm', $("#androidDownloadform").serialize(), function(data, status){

		switch (eval(data)) {

		    case 999:
		       androidDownloadSubmit("false","Sorry, your download could not be completed at this time.  Please try again.");
		        break;
			case 000:
				androidDownloadSuccess();
				break;
			default:
				androidDownloadSubmit("false","Sorry, we could not complete your request at this time.");	
				break;
			}
	});
 },
		rules: {
			androidDownloadEmail: {
				required: true,
				QAsEmailValidator: true
			},
			appDownloadDevice: {
				required: true
			}
		},
		messages: {
			androidDownloadEmail: {
				required: "Please enter your email address",
				QAsEmailValidator: "Please enter a valid email address"
			},
			appDownloadDevice: {
				required: "Please select your Android model"
			}
		}
});
	
$("#trialForm").validate({
 submitHandler: function(form) {
   
		showTrialSubmit("true","");
		
		$.post('trial_register.cfm', $("#trialForm").serialize(), function(data, status){

		switch (eval(data)) {
		    case 150:
		        showTrialSubmit("false","Sorry, the email address is already in use. Please enter a new email address.");
				$("#email").focus();
		        break;
		    case 130:
		       	showTrialSubmit("false","Please enter a password.");
		        break;
		    case 110:
		       	showTrialSubmit("false","Please enter all required fields.");
		        break;
		    case 300:
		       	showTrialSubmit("false","Sorry, the Promotion Code you entered is invalid. Please try again.");
		        break;
		    case 301:
		       	showTrialSubmit("false","Sorry, the Promotion Code you entered is expired. Please try again.");
		        break;
		    case 141:
		       	showTrialSubmit("false","Sorry, your trial has expired.  Please visit xmradio.ca/getonline to purchase XM online+");
		        break;
			case 000:
				window.location.href= 'trial_success.cfm';
				break;
			default:
				 showTrialSubmit("false","Sorry, we could not complete your request at this time.");	
				break;
			}
	});
 },
		rules: {
			firstName: "required",
			lastName: "required",
			email: {
				required: true,
				QAsEmailValidator: true
			},
			password1: {
				required: true,
				minlength: 6
			},
			password2: {
				required: true,
				equalTo: "#password1"
			}
		},
		messages: {
			firstName: "Please enter your first name",
			lastName: "Please enter your last name",
			email: {
				required: "Please enter your email address",
				QAsEmailValidator: "Please enter a valid email address"
			},
			password1: {
				required: "Please enter a password",
				minlength: "Your password must be at least 6 characters"
			},
			password2: {
				required: "Please confirm your password",
				equalTo: "Your passwords do not match"
			}
		}
});
	
	//$("#tabs").tabs({ fx: { opacity: 'toggle' } });
	
$(function() {

	function handleTabSelect(event, tab) {

    	if (tab.index == 0) {
			// web player
			document.getElementById('device').selectedIndex = 0;
			$('img#imgTab1').attr({ src: "../images/online/tab_web_on.png" });
			$('img#imgTab2').attr({ src: "../images/online/tab_blackberry_off.png" });
			$('img#imgTab3').attr({ src: "../images/online/tab_iphone_off.png" });
			$('img#imgTab4').attr({ src: "../images/online/tab_android_off.png" });
		 }
		else if (tab.index == 1) {
			document.getElementById('device').selectedIndex = 1;
			// Blackberry
			$('img#imgTab1').attr({ src: "../images/online/tab_web_off.png" });
			$('img#imgTab2').attr({ src: "../images/online/tab_blackberry_on.png" });
			$('img#imgTab3').attr({ src: "../images/online/tab_iphone_off.png" });
			$('img#imgTab4').attr({ src: "../images/online/tab_android_off.png" });
		}
		else if (tab.index == 2) {
			document.getElementById('device').selectedIndex = 2;
			// iPhone
			$('img#imgTab1').attr({ src: "../images/online/tab_web_off.png" });
			$('img#imgTab2').attr({ src: "../images/online/tab_blackberry_off.png" });
			$('img#imgTab3').attr({ src: "../images/online/tab_iphone_on.png" });
			$('img#imgTab4').attr({ src: "../images/online/tab_android_off.png" });
		}
		else if (tab.index == 3) {
			document.getElementById('device').selectedIndex = 3;
			// android
			$('img#imgTab1').attr({ src: "../images/online/tab_web_off.png" });
			$('img#imgTab2').attr({ src: "../images/online/tab_blackberry_off.png" });
			$('img#imgTab3').attr({ src: "../images/online/tab_iphone_off.png" });
			$('img#imgTab4').attr({ src: "../images/online/tab_android_on.png" });
		}
	}

         // Set Tab Constructor values & initialize tabs

	$('#tabs').tabs({ selected: '0', 

	fx: { opacity: 'toggle'}, select: handleTabSelect });

//			alert(jQuery.url.param("tab"));
			
// 			if (jQuery.url.param("tab") == "web") {
//				$('#tabs').tabs('select', 0);
//			}
//			else 
//				if (jQuery.url.param("tab") == "android") {
//					$('#tabs').tabs('select', 3);
//				}else{
	$('#tabs').tabs('select', 0);
//	$('#tabs').tabs('select', 0);
//				} 
    });
	

	$("#dialog").dialog({
      bgiframe: true, autoOpen: false, height: 450, width: 700, modal: true
    });
	
	// Code to unveil buttons
	$("#btnTrial").click(function () {
		if ($("#sidebar_trialform").is(":hidden")) {
        	$("#sidebar_trialform").fadeIn();
			$("#btn_sidebar_trial").css("border-bottom","none");
      	}
	});
	
	$("#btn_sidebar_login").click(function () {
		if ($("#btnListenNow").is(":hidden")) {
        	$("#btnListenNow").fadeIn();
      	}
	});
	
	$("#replaceme").click(function () {
		if ($("#btnChoices").is(":visible")) {
			$("#replaceme").html("<input type='image' src='images/btn14dayOn.gif' height='47' width='245' id='btn14Day' alt='Get your free 14-day trial now. Commitment free' title='Get your free 14-day trial now. Commitment free' />");
        	$("#btnChoices").slideUp("slow");
      	}
	});
});
