/* ------------------------------------------------------------------------------------------ */
/* Preload Images */

preload_hdr = new Image(0,0);
preload_hdr.src="/img/gradients/loginHdr_bg.png";
preload_subNav = new Image(0,0);
preload_subNav.src = "/img/content_bg.png";

/* ------------------------------------------------------------------------------------------ */
/* Toggle Login area */
function pulldownGo(id, type) {

	var dropDown = document.getElementById(id); 
	var myindex  = dropDown.selectedIndex
	var selValue = dropDown.options[myindex].value
	
	var baseURL = '/tutorials/' + selValue + '-' + id;
	
	
	top.location.href = baseURL;
    
}

function pullDownGoNew(type) {

	var dropDown = document.getElementById(type); 
	var myindex  = dropDown.selectedIndex
	var selValue = dropDown.options[myindex].value
	
	switch (type) {
		case 'application':
		case 'genre':
		case 'trainer':
			var baseURL = '/tutorials/' + selValue + '-' + type;
			break;
		case 'bundle':
			var baseURL = '/bundlebuilder/?bc=1&action=add&type=preset&id=' + selValue;
			break;
	}
	
	top.location.href = baseURL;
	
}

/* ------------------------------------------------------------------------------------------ */
/* Check all */
function checkAll( id, flag ) {
	
	if ($("#" + flag).val() == 1) {
		$("form#" + id + " INPUT[type='checkbox']").attr('checked', false);
		$("#" + flag).val(0);
	} else {
		$("form#" + id + " INPUT[type='checkbox']").attr('checked', true);
		$("#" + flag).val(1);
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Toggle Login area */
function toggleLogin(status) {
	
	switch (status) {
		case "show":
			$("#trialBadge").fadeOut("slow");
			$("#launchPlayer").fadeOut("slow");
			$("#loginHdr").animate({"top": "+=95px"	},400);
			document.getElementById('username').focus();
			break;
		case "hide":
			$("#loginHdr").animate({"top": "-=95px" },400);
			$("#launchPlayer").fadeIn("slow");
			$("#trialBadge").fadeIn("slow");
			break;
	}
}


/* ------------------------------------------------------------------------------------------ */
/* Function to get the window/player area dimensions */

var new_width = '';
var new_height = '';
var new_player_width = '';
var new_player_height = '';
var new_menu_height = '';

function getDimensions(aspect) {

	switch (aspect) {
		default:
		case '4:3':
			new_width = '1060';
			new_height = '655';
			new_player_width = '768px';
			new_player_height = '592px';
			new_menu_height = '445px';
			break;
			
		case '16:9':
			new_width = '1255';
			new_height = '635';
			new_player_width = '960px';
			new_player_height = '556px';
			new_menu_height = '409px';
			break;
			
	}
}

/* Function to display Download/Subscribe Price */
function togglePrice(type) {

	switch (type) {
		case "download":
			document.getElementById('cost_download').style.display='block';
			document.getElementById('cost_subscribe').style.display='none';
			document.getElementById('cost_launch').style.display='none';
			document.getElementById('library').style.display='none';
			document.getElementById('runtime').style.display='block';
			document.getElementById('launch').style.display='none';
			break;
			
		case "subscribe":
			document.getElementById('cost_download').style.display='none';
			document.getElementById('cost_subscribe').style.display='block';
			document.getElementById('cost_launch').style.display='none';
			document.getElementById('library').style.display='block';
			document.getElementById('runtime').style.display='none';
			document.getElementById('launch').style.display='none';
			break;
			
		case "launch":
			document.getElementById('cost_download').style.display='none';
			document.getElementById('cost_subscribe').style.display='none';
			document.getElementById('cost_launch').style.display='block';
			document.getElementById('library').style.display='none';
			document.getElementById('runtime').style.display='none';
			document.getElementById('launch').style.display='block';
			break;
			
	}
}
/* ------------------------------------------------------------------------------------------ */
/* Function to open a window (with all settings adjustable) */
function openNEDweb(url, safetitle, aspect) {

	getDimensions(aspect);
	
	var width = new_width;
	var height = new_height;
	var resizable = '0';
	var scrollbars = '0';
	var location = '1';
	var menubar = '0';
	var directories = '0';
	var toolbar = '0';
	var status = '1';
	
	var settings = 'width=' + width + ',height=' + height + ',resizable=' + resizable + ',scrollbars=' + scrollbars + ',location=' + location + ',menubar=' + menubar + ',directories=' + directories + ',toolbar=' + toolbar + ',status=' + status + '';
	
	var Win = window.open(url,'NEDweb',settings);

}

/* ---- Function to check aspect ratio of video ------------------------------------------------------- */
function chkAspect(aspect) {

	// Determine which size to resize to
	getDimensions(aspect);
	
	// Resize player/menu area
	if (document.getElementById('player_area')) {
		document.getElementById('player_area').style.width=new_player_width;
		document.getElementById('player_area').style.height=new_player_height;
	}
	
	if (document.getElementById('nav_nedweb_area')) {
		document.getElementById('nav_nedweb_area').style.height=new_menu_height;
	}
	
	// Add some extra space
	new_width = new_width;
	new_height = (Number(new_height) + 113);
	
	// Resize the window
	window.resizeTo(new_width, new_height);
	
}

/* Function for confirmation box */
function confirm_box( text ) {
	var result = confirm( text );
	
	if ( result ) {
		return true;
	}
	else {
		return false;
	}
}

/* Function to toggle display of Monthly/Quarterly views for Royalties */
function toggleRoyaltyViewType() {

	if (document.getElementById('quarterly').style.display != 'none') {
	
		// Monthly
		document.getElementById('quarterly').style.display='none';
		document.getElementById('mth_start').style.display='';
		document.getElementById('mth_end').style.display='';
		document.getElementById('vtype').value='monthly';
		document.getElementById('toggleLink').innerHTML = 'Switch to Quarterly';
		
	} else {
		
		// Quarterly
		document.getElementById('quarterly').style.display='';
		document.getElementById('mth_start').style.display='none';
		document.getElementById('mth_end').style.display='none';
		document.getElementById('vtype').value='quarterly';
		document.getElementById('toggleLink').innerHTML = 'Switch to Monthly';
		
	}
}

/* Function to pre-load images */
function loadIMG() {
}

/* Function to pre-load bundle builder bar images */
function preloadBars() {
}

/* ------------------------------------------------------------------------------------------ */
/* Function to perform Mouse-Overs */
function swapImage(button_name, button_id, status) {

	switch (button_name) {
		case "order_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/add_to_cart_byob_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/add_to_cart_byob.gif'; }
			break;
			
		case "pre_order_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/preorder_now_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/preorder_now.gif'; }
			break;
			
		case "view_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/view_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/view.gif'; }
			break;
			
		case "add_to_cart_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/add_to_cart_plus_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/add_to_cart_plus.gif'; }
			break;
			
		case "add_to_cart_byob_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/add_to_cart_byob_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/add_to_cart_byob.gif'; }
			break;
			
		case "view_bundle_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/tiles/make_it_a_bundle_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/tiles/make_it_a_bundle.gif'; }
			break;
			
		case "view_sample_video":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/sample_film_cell_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/sample_film_cell.gif'; }
			break;
			
		case "dl_mac_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/download_platform_mac_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/download_platform_mac.gif'; }
			break;
			
		case "dl_win_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/download_platform_windows_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/download_platform_windows.gif'; }
			break;
			
		case "add2ned_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/add_to_ned_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/add_to_ned.gif'; }
			break;

		case "addtutorial_button":
			if (status == 'on') { document.getElementById(button_id).src = '/img/buttons/add_tutorial_b.gif'; }
			if (status == 'off') { document.getElementById(button_id).src = '/img/buttons/add_tutorial.gif'; }
			break;
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to open a window */
function OpenWind(url, width, height) {
	var Win = window.open(url,"Preview",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=1,location=no,menubar=no,status=no' );
}

/* ------------------------------------------------------------------------------------------ */
/* Function to open a window */
function OpenWindSet(url, width, height, resizeable, scrollbars, location, menubar, status) {
	var Win = window.open(url,"Preview",'width=' + width + ',height=' + height + ',resizable=' + resizeable + ',scrollbars=' + scrollbars + ',location=' + location + ',menubar=' + menubar + ',status=' + status);
}

/* ------------------------------------------------------------------------------------------ */
/* Function to redirect on OK click */
function confirmRedirect(url, msg) {

	var redirect = confirm(msg);
	if (redirect == true) { window.location= url; }
}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide sub-menus */
function hideSubs() {
}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide and show sub-menus */
function show(id) {
	var d = document.getElementById(id);
	
	if (d.style.display == 'none') {
		hideSubs();
		d.style.display='block';
	
	} else if (d.style.display == 'block') {
		d.style.display='none';
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to auto clear input field */
function clearInput(id, orig_txt) {
	if (document.getElementById(id).value == orig_txt) {
		document.getElementById(id).value="";
	} else if (document.getElementById(id).value=="") {
		document.getElementById(id).value=orig_txt;
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to show icon change */
function expandArrow(id, state) {
	var d = document.getElementById(id);
	
	if (state == 1) {
		d.src = '../img/icons/expanding_arrow_down.gif';
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to open tutorial video */
function viewerWindow(url) {
	window.open(url,"newWindow","width=1040,height=800,scrollbar=no")
}

/* ------------------------------------------------------------------------------------------ */
/* Function to calculate price totals */
function calcPrice(quantity, id, price) {
	var q = id + "_quantity";
	var t = id + "_price";
	var total = quantity * price;
	
	total = total.toFixed(2);
	
	document.getElementById(q).innerHTML = quantity;
	document.getElementById(t).innerHTML = total;
}

/* ------------------------------------------------------------------------------------------ */
/* Function to calculate total */
function calcTotal(total, subtotal, totalcost) {
	var t = 0;
	
	for (var i = 0; i < total; i++) {
		var price_field = i + "_price";
		t = t + Number(document.getElementById(price_field).innerHTML);
	}
	
	if (t > 0) {
		document.getElementById('checkout_button').disabled = false;
	} else {
		document.getElementById('checkout_button').disabled = true;
	}
	
	t = t.toFixed(2);
	
	document.getElementById(subtotal).innerHTML = t;
	document.getElementById('total_field').value = t;
	document.getElementById(totalcost).innerHTML = t;
	
	
}

/* ------------------------------------------------------------------------------------------ */
/* Function to jump CC number fields */
function fieldJump(field) {
	var f = document.getElementById(field);
	var len = f.value.length;
	
	if (len == 4) {
	
		switch (field) {
			case "ccnum1":
				document.getElementById("ccnum2").focus();
				break;
			
			case "ccnum2":
				document.getElementById("ccnum3").focus();
				break;
				
			case "ccnum3":
				document.getElementById("ccnum4").focus();
				break;
		}
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to empty field upon focus */
function clearField(id) {
	var f = "product_" + id;
	
	if (document.getElementById(f).value == "0") {
		document.getElementById(f).value = "";
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to reset field to 0 */
function resetField(id) {
	var f = "product_" + id;
	var q = id + "_quantity";

	if (document.getElementById(f).value == '') { 
		document.getElementById(f).value = "0";
		document.getElementById(q).innerHTML = "0";
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to change pagination page */
function chgPage(sec, value, order) {

	var path = "?sec=" + sec + "&sid=" + value; 

	if (order != '') {
		path = path + "&order=" + order;
	}
	
	location.href = path;
	
}

/* ------------------------------------------------------------------------------------------ */
/* Function to calculate total plus shipping cost */
function calcShipping(subtotal, type) {

	var sub = Number(subtotal);

	switch (type) {
		case "1":
			document.getElementById('track_num_value').innerHTML = 'Yes';
			document.getElementById('delivery_time_value').innerHTML = '3 Business Days';
			document.getElementById('cost_value').innerHTML = '0.00';
			document.getElementById('shipping_value').innerHTML = '0.00';
			
			/* Set Shipping Value */
			var shipping = Number(0.00);
			break;
			
		case "2":
			document.getElementById('track_num_value').innerHTML = 'No';
			document.getElementById('delivery_time_value').innerHTML = '3-10 Business Days';
			document.getElementById('cost_value').innerHTML = '10.50';
			document.getElementById('shipping_value').innerHTML = '10.50';
			
			/* Set Shipping Value */
			var shipping = Number(10.50);
			break;
			
		case "3":
			document.getElementById('track_num_value').innerHTML = 'Yes';
			document.getElementById('delivery_time_value').innerHTML = '1-3 Business Days';
			document.getElementById('cost_value').innerHTML = '20.00';
			document.getElementById('shipping_value').innerHTML = '20.00';
			
			/* Set Shipping Value */
			var shipping = Number(20.00);
			break;
			
		case "4":
			document.getElementById('track_num_value').innerHTML = 'Yes';
			document.getElementById('delivery_time_value').innerHTML = '1-2 Business Days';
			document.getElementById('cost_value').innerHTML = '35.00';
			document.getElementById('shipping_value').innerHTML = '35.00';
			
			/* Set Shipping Value */
			var shipping = Number(35.00);
			break;
	}
	
	/* Calculate Total */
	var total = sub + Number(shipping);
	
	/* Set Total Value */
	document.getElementById('total_value').innerHTML = total.toFixed(2);
	
	/* Apply Values to Hidden Fields */
	document.getElementById('shipping_method_value').value = type;
	document.getElementById('shipping_cost_value').value = shipping.toFixed(2);
}

/* ------------------------------------------------------------------------------------------ */
/* Function to calculate total plus shipping cost */
function calcShpTotal(subtotal, shipping, type) {

	var sub = Number(subtotal);
	var shipping = Number(shipping);
	
	/* Calculate Total */
	var total = sub + shipping;
	
	/* Set Total Value */
	document.getElementById('total_value').innerHTML = total.toFixed(2);
	document.getElementById('shipping_value').innerHTML = shipping.toFixed(2);
	
	/* Apply Values to Hidden Fields */
	document.getElementById('shipping_method_value').value = type;
	document.getElementById('shipping_cost_value').value = shipping.toFixed(2);
	
}

/* ------------------------------------------------------------------------------------------ */
/* Function to check and uncheck all boxes */
function CheckAll(chk_name, form_name) {

	var frm_name = document.getElementById(form_name);
	var chk_count = frm_name.ids.length;
	
	if (document.getElementById(form_name + '_chk_all').checked == true) {
	
		for (i = 0; i < chk_count; i++) {
			frm_name.ids[i].checked = true;
		}
		
	} else {

		for (i = 0; i < chk_count; i++) {
			frm_name.ids[i].checked = false;
		}

	}
}


/* ------------------------------------------------------------------------------------------ */
/* Function to set the opacity */
function setOpacity(obj, opacity) {

	opacity = (opacity == 100)?99.999:opacity;
	
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	
}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide a message box after a short delay */
function fadeMsgOut(objectID, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objectID);
			
		if (opacity > 0) {
			setOpacity(obj, opacity);
			opacity = opacity - 10;
			window.setTimeout("fadeOut('"+objectID+"',"+opacity+")", 75);
		
		} else {
		
			obj.style.width = 0;
			obj.style.height = 0;
			obj.style.display = 'none';
			
		}
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to fade DIV out */
function fadeOut(objectID, opacity) {

	if (document.getElementById) {
		obj = document.getElementById("div_" + objectID);
		
		if (opacity >= 0) {
			setOpacity(obj, opacity);
			opacity = opacity - 10;
			window.setTimeout("fadeOut('"+objectID+"',"+opacity+")", 25);
		
		} else {
		
			obj.style.display = 'none';
			document.getElementById("off_" + objectID).style.display = 'none';
			document.getElementById("on_" + objectID).style.display = 'block';
		
		}
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to fade DIV in */
function fadeIn(objectID, opacity) {

	if (document.getElementById) {
		obj = document.getElementById("div_" + objectID);
			
		if (opacity <= 100) {
			obj.style.display = 'block';
			obj.style.width = '618px';
			
			setOpacity(obj, opacity);
			opacity = opacity + 10;
			window.setTimeout("fadeIn('"+objectID+"',"+opacity+")", 25);
		
		} else {
		
			document.getElementById("on_" + objectID).style.display = 'none';
			document.getElementById("off_" + objectID).style.display = 'block';
		
		}
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to toggle the disability of an item */
function toggleDisable(id) {
	
	if (document.getElementById('gift_note_chk').checked == true) { 
	
		document.getElementById(id).disabled = false;
		document.getElementById('chars_left').disabled = false;
		document.getElementById(id).focus();
		
	} else { 
	
		document.getElementById(id).disabled = true;
		document.getElementById('chars_left').disabled = true;
		
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to count number of characters in a field */
function countChars(max, field, remain_field) {

	if (document.getElementById(field).value.length > max) {
	
		alert("You've reach the limit of " + max + " characters for this field.");
		
	} else {
	
		document.getElementById(remain_field).value = max - document.getElementById(field).value.length;
		
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide/show alternate address fields */
function showHideAlternateFields() {

	if (document.getElementById('use_secondary').checked == true) {
		var visible_fields = 'block';
	} else {
		var visible_fields = 'none';
	}
		
		
	document.getElementById('fname_b').style.display= visible_fields;
	document.getElementById('lname_b').style.display= visible_fields;
	document.getElementById('address1_b').style.display= visible_fields;
	document.getElementById('address2_b').style.display= visible_fields;
	document.getElementById('city_b').style.display= visible_fields;
	document.getElementById('state_province_b').style.display= visible_fields;
	document.getElementById('country_b').style.display= visible_fields;
	document.getElementById('zip_postal_b').style.display= visible_fields;
	document.getElementById('warning_msg_b').style.display= visible_fields;

}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide/show gift note fields */
function showHideGiftNoteFields() {

	if (document.getElementById('gift_note_chk').checked == true) {
		var visible_fields = 'block';
	} else {
		var visible_fields = 'none';
	}
		
		
	document.getElementById('giftnote_field').style.display= visible_fields;
	document.getElementById('giftnote_chars_left').style.display= visible_fields;

}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide/show radio button arrow */
function showHideRadioArrow(radio_num, free) {

	switch (radio_num) {
		case 1:
			document.getElementById('arr_2').style.color= '#ddd';
			document.getElementById('arr_3').style.color= '#ddd';
			document.getElementById('arr_4').style.color= '#ddd';
			break;
			
		case 2:
			document.getElementById('arr_2').style.color= '#333';
			document.getElementById('arr_3').style.color= '#ddd';
			document.getElementById('arr_4').style.color= '#ddd';
			break;
			
		case 3:
			document.getElementById('arr_2').style.color= '#ddd';
			document.getElementById('arr_3').style.color= '#333';
			document.getElementById('arr_4').style.color= '#ddd';
			break;
			
		case 4:
			document.getElementById('arr_2').style.color= '#ddd';
			document.getElementById('arr_3').style.color= '#ddd';
			document.getElementById('arr_4').style.color= '#333';
			break;
			
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to change the admin page area */
function chgTab(tab) {

	switch (tab) {
		case ("customer_details"):
			document.getElementById("customer_details").style.display = "block";
			document.getElementById("secondary_details").style.display = "none";
			document.getElementById("gift_note").style.display = "none";
			document.getElementById("customer_comment").style.display = "none";
			document.getElementById("internal_comment").style.display = "none";
			document.getElementById("associate").style.display = "none";
			document.getElementById("system_info").style.display = "none";
			document.getElementById("referrer").style.display = "none";
			document.getElementById("coupon_code").style.display = "none";
			break;
			
		case ("secondary_details"):
			document.getElementById("customer_details").style.display = "none";
			document.getElementById("secondary_details").style.display = "block";
			document.getElementById("gift_note").style.display = "none";
			document.getElementById("customer_comment").style.display = "none";
			document.getElementById("internal_comment").style.display = "none";
			document.getElementById("associate").style.display = "none";
			document.getElementById("system_info").style.display = "none";
			document.getElementById("referrer").style.display = "none";
			document.getElementById("coupon_code").style.display = "none";
			break;
			
		case ("gift_note"):
			document.getElementById("customer_details").style.display = "none";
			document.getElementById("secondary_details").style.display = "none";
			document.getElementById("gift_note").style.display = "block";
			document.getElementById("customer_comment").style.display = "none";
			document.getElementById("internal_comment").style.display = "none";
			document.getElementById("associate").style.display = "none";
			document.getElementById("system_info").style.display = "none";
			document.getElementById("referrer").style.display = "none";
			document.getElementById("coupon_code").style.display = "none";
			break;
			
		case ("customer_comment"):
			document.getElementById("customer_details").style.display = "none";
			document.getElementById("secondary_details").style.display = "none";
			document.getElementById("gift_note").style.display = "none";
			document.getElementById("customer_comment").style.display = "block";
			document.getElementById("internal_comment").style.display = "none";
			document.getElementById("associate").style.display = "none";
			document.getElementById("system_info").style.display = "none";
			document.getElementById("referrer").style.display = "none";
			document.getElementById("coupon_code").style.display = "none";
			break;
			
		case ("internal_comment"):
			document.getElementById("customer_details").style.display = "none";
			document.getElementById("secondary_details").style.display = "none";
			document.getElementById("gift_note").style.display = "none";
			document.getElementById("customer_comment").style.display = "none";
			document.getElementById("internal_comment").style.display = "block";
			document.getElementById("associate").style.display = "none";
			document.getElementById("system_info").style.display = "none";
			document.getElementById("referrer").style.display = "none";
			document.getElementById("coupon_code").style.display = "none";
			break;
			
		case ("associate"):
			document.getElementById("customer_details").style.display = "none";
			document.getElementById("secondary_details").style.display = "none";
			document.getElementById("gift_note").style.display = "none";
			document.getElementById("customer_comment").style.display = "none";
			document.getElementById("internal_comment").style.display = "none";
			document.getElementById("associate").style.display = "block";
			document.getElementById("system_info").style.display = "none";
			document.getElementById("referrer").style.display = "none";
			document.getElementById("coupon_code").style.display = "none";
			break;
			
		case ("system_info"):
			document.getElementById("customer_details").style.display = "none";
			document.getElementById("secondary_details").style.display = "none";
			document.getElementById("gift_note").style.display = "none";
			document.getElementById("customer_comment").style.display = "none";
			document.getElementById("internal_comment").style.display = "none";
			document.getElementById("associate").style.display = "none";
			document.getElementById("system_info").style.display = "block";
			document.getElementById("referrer").style.display = "none";
			document.getElementById("coupon_code").style.display = "none";
			break;
			
		case ("referrer"):
			document.getElementById("customer_details").style.display = "none";
			document.getElementById("secondary_details").style.display = "none";
			document.getElementById("gift_note").style.display = "none";
			document.getElementById("customer_comment").style.display = "none";
			document.getElementById("internal_comment").style.display = "none";
			document.getElementById("associate").style.display = "none";
			document.getElementById("system_info").style.display = "none";
			document.getElementById("referrer").style.display = "block";
			document.getElementById("coupon_code").style.display = "none";
			break;
			
		case ("coupon_code"):
			document.getElementById("customer_details").style.display = "none";
			document.getElementById("secondary_details").style.display = "none";
			document.getElementById("gift_note").style.display = "none";
			document.getElementById("customer_comment").style.display = "none";
			document.getElementById("internal_comment").style.display = "none";
			document.getElementById("associate").style.display = "none";
			document.getElementById("system_info").style.display = "none";
			document.getElementById("referrer").style.display = "none";
			document.getElementById("coupon_code").style.display = "block";
			break;
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to focus a field onLoad */
function focusField(step) {

	switch (step) {
		case ("step1"):
			
			document.checkout_form.user_email.focus();
			break;
			
		case ("step2"):
			break;
			
		case ("step3"):
		
			document.checkout_form.ccname.focus();
			break;
		
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide/show change buttons/fields */
function hideShowChangeFields(field, status) {

	switch (status) {
		
		case "show":
			document.getElementById(field + '_txt').style.display='none';
			document.getElementById(field + '_field').style.display='inline';
			document.getElementById(field + '_field').focus();
			document.getElementById(field + '_update').style.display='inline';
			document.getElementById(field + '_cancel').style.display='inline';
			break;
			
		
		case "hide":
			document.getElementById(field + '_txt').style.display='inline';
			document.getElementById(field + '_field').style.display='none';
			document.getElementById(field + '_update').style.display='none';
			document.getElementById(field + '_cancel').style.display='none';
			break;
	
	}
}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide smartfind results */
function closeSFResults() {
	document.getElementById('smartfind_results').innerHTML = '';
	document.getElementById('smartfind_results').style.display = 'none';
	document.getElementById('sf_query').value = '';
	document.getElementById('sf_query').focus();
}

/* ------------------------------------------------------------------------------------------- */
/* Function to determine number of Tutorials select for Custom Bundle */
function countCustomTutorials(tut_select_id, discount_amount, discount_type) {

	//alert(discount_amount);
	//alert(discount_type);
	
	var tut_count = 0;
	var i = 1;
	var subTotal = 0;
	
	// Count number of selected Tutorials
	for (i; i < 15; i++) {
		
		// Check if the element exists
		if (document.getElementById('tut' + i)) { 
			
			// Check to make sure something is selected
			if (document.getElementById('tut' + i).value != "#") { 
			
				// Make delete icon visible
				document.getElementById('del_' + (i - 1)).style.display = 'inline';
				
				// Increase number of tutorials count
				tut_count++; 
				
				// Get product safename and price
				var details = document.getElementById('tut' + i).value;
				var elements = details.split('|');
				
				// Check if download discount should be applied
				/*if (document.getElementById('format_type_download').checked == true && elements[0] != '1055' && elements[0] != '1092') {
					elements[2] = (Number(elements[2]) - (Number(elements[2]) * 0.10));
				}*/
				
				// Add up product price for sub-total
				subTotal += Number(elements[2]);
				
				// Display fields and update discount amount based on number of Tutorials
				if (discount_amount > 25) {
					
					document.getElementById('curr_discount').innerHTML = discount_amount;
					
					if (document.getElementById('tut' + (tut_count+1) + '_select_a').style.display='none') {
						document.getElementById('tut' + (tut_count+1) + "_select_a").style.display='block';
						document.getElementById('tut' + (tut_count+1) + "_select_b").style.display='block';
					}
					
				} else if (tut_count < 3) {
				
					document.getElementById('curr_discount').innerHTML = '0';
				
				} else if (tut_count >= 3 && tut_count <= 4) { 
					
					document.getElementById('curr_discount').innerHTML = '15';
				
					if (document.getElementById('tut' + (tut_count+1) + '_select_a').style.display='none') {
						document.getElementById('tut' + (tut_count+1) + "_select_a").style.display='block';
						document.getElementById('tut' + (tut_count+1) + "_select_b").style.display='block';
					}
					
				} else if (tut_count >= 5 && tut_count <= 6) { 
				
					document.getElementById('curr_discount').innerHTML = '20';
				
					if (document.getElementById('tut' + (tut_count+1) + '_select_a').style.display='none') {
						document.getElementById('tut' + (tut_count+1) + "_select_a").style.display='block';
						document.getElementById('tut' + (tut_count+1) + "_select_b").style.display='block';
					}
					
				} else if (tut_count >= 7) { 
				
					document.getElementById('curr_discount').innerHTML = '25';
				
					if (document.getElementById('tut' + (tut_count+1) + '_select_a').style.display='none') {
						document.getElementById('tut' + (tut_count+1) + "_select_a").style.display='block';
						document.getElementById('tut' + (tut_count+1) + "_select_b").style.display='block';
					}
					
				}
			}
		}
	}
	
	// Update Sub-total
	document.getElementById('curr_subtotal').innerHTML = subTotal.toFixed(2);
	
	// Create Savings Percent
	var savings_percent = Number(('0.' + document.getElementById('curr_discount').innerHTML));
	
	// Get Total
	var total = Number(subTotal) - (Number(subTotal) * savings_percent);
	document.getElementById('curr_total').innerHTML = total.toFixed(2);
	
	// Get Savings
	var savings = subTotal - total;
	document.getElementById('curr_savings').innerHTML = savings.toFixed(2);
	
	loadBYOBGraphics();
	
	return true;
}

/* ------------------------------------------------------------------------------------------- */
/* Function to toggle display of contact list */
function toggleContacts() {

	if (document.getElementById('contact_list').style.display == 'none') {
	
		document.getElementById('contact_list').style.display = 'block';
		LoadContactList();
		
	} else {
	
		document.getElementById('contact_list').style.display = 'none';
		
	}
}

/* ------------------------------------------------------------------------------------------- */
/* Function to add tutorials from preset bundle */
function addFromzzBundle(tutorials) {
	
	var tuts = tutorials.split(' - ');
	var tut_count = tuts.length;
	
	for (i = 0; i < tut_count; i++) {
		var elements = tuts[i].split('|');
		var id = elements[0];
		var safetitle = elements[1];
		var price = elements[2];
		
		if (document.getElementById('tut' + (i + 1) + '_select_a').style.display='none') {
			document.getElementById('tut' + (i + 1) + "_select_a").style.display='block';
			document.getElementById('tut' + (i + 1) + "_select_b").style.display='block';
		}
		
		document.getElementById('tut' + (i + 1)).selectedIndex = id + "|" + safetitle + "|" + price;
	}
	
	alert(tut_count);
}

/* ------------------------------------------------------------------------------------------- */
/* Function to shift Opacity */
function shiftOpacity(id, millisec) { 
	
	//if an element is invisible, make it visible, else make it ivisible 
	if(document.getElementById(id).style.opacity == 0) { 
		opacity(id, 0, 100, millisec); 
	} else { 
		opacity(id, 100, 0, millisec); 
	} 
}

/* Function to change the opacity of a DIV */
function opacity(id, opacStart, opacEnd, millisec) {

	//speed for each frame 
	var speed = Math.round(millisec / 100); 
	var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    
	} else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    }
} 

/* ------------------------------------------------------------------------------------------- */
//change the opacity for different browsers 
function changeOpac(opacity, id) { 
	var object = document.getElementById(id).style;
	
	if (document.getElementById(id).style.display='none') {
		document.getElementById(id).style.display='block';
	}
	
	object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

/* ------------------------------------------------------------------------------------------- */
// Toggle display of Help Request Form
function toggleFormFields(status) {

	switch (status) {
		case 1:
			document.getElementById('form_fields').style.display='block';
			document.getElementById('kbase_query_results').style.display='none';
			break;
		case 2:
			document.getElementById('form_fields').style.display='none';
			document.getElementById('kbase_query_results').style.display='block';
			break;
	}
}

/* ------------------------------------------------------------------------------------------- */
// Toggle display of Help Request Form
function countDownTimer() {
	
	countdown('07', '10', '15', '12', '00', 1);
	
	function countdown(year, month, day, hour, minute, format) {
		Today = new Date();
		Todays_Year = Today.getFullYear() - 2000;
		Todays_Month = Today.getMonth() + 1;                  
		
		//Convert both today's date and the target date into miliseconds.                           
		Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
		Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
		Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
		
		//Find their difference, and convert that into seconds.                  
		Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
		
		if(Time_Left < 0) Time_Left = 0;
		
		switch(format) {
		
			case 0:
			
				//The simplest way to display the time left.
				document.all.countdown.innerHTML = Time_Left + ' seconds';
				break;
			
			case 1:
				
				//More datailed.
				days = Math.floor(Time_Left / (60 * 60 * 24));
				Time_Left %= (60 * 60 * 24);
				hours = Math.floor(Time_Left / (60 * 60));
				Time_Left %= (60 * 60);
				minutes = Math.floor(Time_Left / 60);
				Time_Left %= 60;
				seconds = Time_Left;
		
				dps = 's'; 
				hps = 's'; 
				mps = 's'; 
				sps = 's';
				
				//ps is short for plural suffix.
				if(days == 1) dps ='';
				if(hours == 1) hps ='';
				if(minutes == 1) mps ='';
				if(seconds == 1) sps ='';
				
				dateString = days + '&nbsp;day' + dps + ',&nbsp;' + hours + '&nbsp;hour' + hps + ',&nbsp;' + minutes + '&nbsp;minute' + mps + ' and ' + seconds + '&nbsp;second' + sps;
				document.getElementById('countdown_value').innerHTML = dateString;
				
				/*document.getElementById('countdown_value').innerHTML = days + '&nbsp;day' + dps + ',&nbsp;';
				document.getElementById('countdown_value').innerHTML += hours + '&nbsp;hour' + hps + ',&nbsp;';
				document.getElementById('countdown_value').innerHTML += minutes + '&nbsp;minute' + mps + ' and ';
				document.getElementById('countdown_value').innerHTML += seconds + '&nbsp;second' + sps;*/
				break;
				default: 
		
			document.getElementById('countdown_value').innerHTML = Time_Left + ' seconds';
		}
		
		//Recursive call, keeps the clock ticking.
		setTimeout('countDownTimer(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
	}
}


/* ------------------------------------------------------------------------------------------- */
// Change tab function. REQUIRES jquery
function changeTab(section,num_tabs,tab){
	var active = "";
	var tab_name = "";
	var content_name = "";
	for(var i = 1; i<=num_tabs; i++){
		
		tab_name = "#" + section + "_tab_" + i;
		content_name = "#" + section + "_content_" + i; 		
		
		if(i == tab){
			$(content_name).show();
			$(tab_name).attr('class','active');
		}
		else{
			$(content_name).hide();
			$(tab_name).attr('class','');
		}
	}
}