var noshadows = false; // will turn off shadow rendering

var $shadowOpts = {
    xoffset: 1,
    yoffset: 1,
    opacity: .2,
    color: '#444',
    relative: false
};

var $shadowOpts2 = {
	    xoffset: 3,
	    yoffset: 3,
	    opacity: .2,
	    color: '#444',
	    relative: false
	};

// global variable to detect if DOM is ready
if (typeof dd_domreadycheck=="undefined") {
	var dd_domreadycheck = false;
}

function microtime (get_as_float) {
    // Returns either a string or a float containing the current time in seconds and microseconds  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/microtime    // +   original by: Paulo Ricardo F. Santos
    // *     example 1: timeStamp = microtime(true);
    // *     results 1: timeStamp > 1000000000 && timeStamp < 2000000000
    var now = new Date().getTime() / 1000;
    var s = parseInt(now, 10); 
    return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}

/* ####################### JQuery Related Functions ###################### */

/**
 * Useful for ensuring new dom items are hooked with jquery functionality
 */
function loadJqMain(sub) {
	if (typeof(sub) == "undefined") {
		$("a[rel^='ilight']").iLight();
	} else {
		$(sub).find("a[rel^='ilight']").iLight();
	}
}

function loadContent(id, url, data, hookDom)
{
	if (typeof(hookDom) == "undefined") {
		hookDom = true;
	}

	$.ajax({
		type: 		"POST",
		url: 		url,
		cache:		false,
		data:		data,
		success:	function (html) {
						if (html) {
							$(id).show();
							$(id).html(html); // load content
							if (hookDom) loadJqMain(id); // hook the main jq fncs to the dom
						} else {
							$(id).hide();
						}
					},
		error: 		function (err) {
							$(id).show();
							$(id).html(err);
					}
	});
}

function loadContentSignup(input_id, div_id, data)
{
	switch(input_id) {
		case 'fullname':
			if (!data.indexOf(' ')) {
				$(div_id).html('<font color="red">Must enter your fullname (i.e. John Smith)</font>');
			} else {
				$(div_id).html('<img src="images/buttons/signup_check.gif">ok');
			}
			break;
		case 'username':
			break;
		case 'password':
			if (!data.indexOf(' ')) {
				$(div_id).html('<font color="red">Must enter your fullname (i.e. John Smith)</font>');
			} else {
				$(div_id).html('<img src="images/buttons/signup_check.gif">ok');
			}
			break;
		case 'email':
			break;
	}
	
	
	$.ajax({
		type: 		"POST",
		url: 		url,
		cache:		false,
		data:		data,
		success:	function (html) {
						if (html) {
							$(id).show();
							$(id).html(html); // load content
							loadJqMain(); // hook the main jq fncs to the dom
						}
					}
	});
}

function loadJSContent(selectBox, url, data)
{
	$.ajax({
		type: 		"POST",
		url:		url,
		cache: 		false,
		data:		data,
		success:	function (html) { eval(html); }
	});
}

/* ################### End JQuery Related Functions ####################### */


/* ################### Video and Playlist Functions ####################### */

function loadPlayerMedia(autoplay, file, title, description, authorized, membershipID, addToPlaylist) 
{
	if (authorized == false) {
		alert('You must be logged in to create playlists');
		return;
	}

	file_orig = file;
	
	if (file_orig.substr(0,7) != 'http://') {
		file = 'http://www.canadianmusicians.com/'+file;
	}
	
	var playlist = '<playlist><item><filename>'+file+'</filename><title>'+title+'</title><description>'+description+'</description></item></playlist>';

	if (membershipID && addToPlaylist) {
		$.ajax({
			type: 		"POST",
			url: 		'/inc/ajax/addToPlaylist.php',
			cache:		false,
			data:		({file:file_orig, membershipID:membershipID}),
			success:	function (html) { alert('Song added to your profile playlist.'); }
		});
	} else {
		if (wimpy_popout_window != 'undefined') {
			try{
				wimpy_popout_window.focus();
				wimpy_popout_window.wimpy_appendPlaylist(playlist, 'no');
			} catch (e) {
				wimpy_popAndPlay(playlist, 'yes');
			}
		} else {
			wimpy_popAndPlay(playlist, 'yes');
		}
	}
}

function removeMedia(songID)
{
	if (songID) {
		$.ajax({
			type: 		"POST",
			url: 		'/inc/ajax/removeFromPlaylist.php',
			cache:		false,
			data:		({songID:songID}),
			success:	function (html) { 
			alert('Song removed from profile playlist.');
			//$('#'+songID).find('a').html('Add&nbsp;to&nbsp;Playlist');
			}
		});
	}
}

/* ################# End Video and Playlist Functions ##################### */

/* ######################### Common Functions ############################# */

function toggleDiv(div) {
	$('#'+div).toggle(400);
	/*
	var theElement = document.getElementById(div);
	
	if(theElement.style.display == "block") {
		theElement.style.display = "none";
	} else {
		theElement.style.display = "block";
	}*/
}

function hideDiv(div, isHidden) {
	var theElement = document.getElementById(div);
	
	if(isHidden == true) {
		theElement.style.display = "none";
	} else {
		theElement.style.display = "block";
	}
}

function popUp(url){
	window.open(url,"pop","width=650,height=500,toolbars=0,scrollbars=1");
}

function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}

function getElementsByClassName(oElm, strTagName, strClassName) {
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

/* ######################### End Common Functions ############################# */


/* ######################### iNav System ############################### */
/*
function inav()
{	
	var time = 300;
	var leftOffset = 40; // this should be taken from element with pos declaration
	var inav_timer = '';
	
	$("#nav dl").css({display: "none"}); // Opera Fix
	
	// @TODO The menu stays the whole time you are anywhere in the menu bar 
	$("#nav dt").hover(
		function(){
			if($(this).parent('dl').is('#nav')) {

				if ($(this).next('dd').find('dl:first').css('visibility') != 'visible') {
					
					$("#nav dd").shadowDestroy();
					$("#nav dd").find('dl:first').css({visibility: "hidden", display: "none"});
					
				} else {

					clearTimeout(inav_timer);
					
				}
				
			} else {
				
				clearTimeout(inav_timer);
				
			}
			
			$(this).removeClass('nav-a');
			$(this).addClass('nav-a-hover');
			var pos = $(this).position();
			
			$(this).next('dd').find('dl:first').css({visibility: "visible", marginLeft: pos.left-leftOffset}).fadeIn(time)
									.queue(function() { if ($(this).css('visibility') == 'visible') $(this).shadow($shadowOpts); $(this).dequeue(); });
			
		},function(){
			
			$(this).removeClass('nav-a-hover');
			$(this).addClass('nav-a');

			if ($("#nav dd").find('dl:first').css('visibility') == 'visible') {
				inav_timer = setTimeout(function() {
					$("#nav dd").shadowDestroy();
					$("#nav dd").find('dl:first').css({visibility: "hidden", display: "none"});
				}, time+100);
			}
			
		});
}
*/

function inav(param) {
	var mouseIsOver = true;
	$(param).parent().hover(function() { mouseIsOver = true; inavShow(param); }, function() { mouseIsOver = false; if (!$(param).hasClass('focus')) { inavHide(param); }; } );
	$(param).parent().click(function() { inavShow(param); } );  
}

function inavShow(param) {
	if ($(param).next('div').css('display') == 'none') {
		$(param).next('div').show(200)
							.queue(function() { $(this).shadow($shadowOpts2); $(this).dequeue(); });
	}
}

function inavHide(param) {
	$(param).next('div').queue(function() { $(this).parent().shadowDestroy(); $(this).dequeue(); })
						.hide(200);
}

/* ######################### End iNav System ############################### */

/* ######################### CMR Radio Functions ########################### */

function refresh_cc_stream_info() 
{
    var ccsib = document.getElementsByTagName("BODY")[0];
    var ccsis = document.createElement("script");
    ccsis.type = "text/javascript";
    ccsis.src = window.ccsiu;
    ccsib.appendChild(ccsis);
}


function cc_streaminfo_get_callback(ccsiv) 
{
	var st = ccsiv["song"];

	if (st != $("#cc_stream_info_song").html()) {
		$("#cc_stream_info_song").fadeOut(2000);
		$("#cc_stream_info_song").queue(function() { $(this).html(st); $(this).dequeue(); });
		$("#cc_stream_info_song").fadeIn(2000);
	}
    
    window.ccsiu = ccsiv.url;
    if (window.ccsic++ < 90) {
        setTimeout("refresh_cc_stream_info()", 30000);
    }
}

window.ccsic = 0;

/* ######################### End CMR Radio Functions ########################## */

/* ######################### Passwords and Validation ########################## */

/* ************************************************************
Created: 20060120
Author:  Steve Moitozo <god at zilla dot us> -- geekwisdom.com
Description: This is a quick and dirty password quality meter 
		 written in JavaScript so that the password does 
		 not pass over the network.
License: MIT License (see below)
Modified: 20060620 - added MIT License
Modified: 20061111 - corrected regex for letters and numbers
                     Thanks to Zack Smith -- zacksmithdesign.com
---------------------------------------------------------------
Copyright (c) 2006 Steve Moitozo <god at zilla dot us>

Permission is hereby granted, free of charge, to any person 
obtaining a copy of this software and associated documentation 
files (the "Software"), to deal in the Software without 
restriction, including without limitation the rights to use, 
copy, modify, merge, publish, distribute, sublicense, and/or 
sell copies of the Software, and to permit persons to whom the 
Software is furnished to do so, subject to the following 
conditions:

   The above copyright notice and this permission notice shall 
be included in all copies or substantial portions of the 
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
OR OTHER DEALINGS IN THE SOFTWARE. 
---------------------------------------------------------------


Password Strength Factors and Weightings

password length:
level 0 (3 point): less than 4 characters
level 1 (6 points): between 5 and 7 characters
level 2 (12 points): between 8 and 15 characters
level 3 (18 points): 16 or more characters

letters:
level 0 (0 points): no letters
level 1 (5 points): all letters are lower case
level 2 (7 points): letters are mixed case

numbers:
level 0 (0 points): no numbers exist
level 1 (5 points): one number exists
level 1 (7 points): 3 or more numbers exists

special characters:
level 0 (0 points): no special characters
level 1 (5 points): one special character exists
level 2 (10 points): more than one special character exists

combinatons:
level 0 (1 points): letters and numbers exist
level 1 (1 points): mixed case letters
level 1 (2 points): letters, numbers and special characters 
					exist
level 1 (2 points): mixed case letters, numbers and special 
					characters exist

************************************************************ */
function testPassword(passwd)
{
		var minLength  = 6;
		var intScore   = 0;
		var strVerdict = "weak";
		var strLog     = "";
		
		if (passwd.length>=minLength) {
			
			// PASSWORD LENGTH
			if (passwd.length>minLength) // start adding points for length greater than minLength
			{
				intScore = (intScore+(passwd.length*passwd.length/(passwd.length*.75)));
				strLog   = strLog + "6 points for length (" + passwd.length + ")\n"
			}
			else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
			{
				intScore = (intScore+10)
				strLog   = strLog + "10 points for length (" + passwd.length + ")\n"
			}
			else if (passwd.length>15)                    // length 16 or more
			{
				intScore = (intScore+16)
				strLog   = strLog + "16 point for length (" + passwd.length + ")\n"
			}
			else if (passwd.length>24)                    // length 25 or more
			{
				intScore = (intScore+21)
				strLog   = strLog + "21 point for length (" + passwd.length + ")\n"
			}
			
			// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
			if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
			{
				intScore = (intScore+1)
				strLog   = strLog + "1 point for at least one lower case char\n"
			}
			
			if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
			{
				intScore = (intScore+5)
				strLog   = strLog + "5 points for at least one upper case char\n"
			}
			
			// NUMBERS
			if (passwd.match(/\d+/))                                 // [verified] at least one number
			{
				intScore = (intScore+5)
				strLog   = strLog + "5 points for at least one number\n"
			}
			
			if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
			{
				intScore = (intScore+5)
				strLog   = strLog + "5 points for at least three numbers\n"
			}
			
			
			// SPECIAL CHAR
			if (passwd.match(/.[^a-zA-Z0-9]/))            // [verified] at least one special character
			{
				intScore = (intScore+5)
				strLog   = strLog + "5 points for at least one special char\n"
			}
			
										 // [verified] at least two special characters
			if (passwd.match(/([a-zA-Z0-9]+)?[^a-zA-Z0-9]([a-zA-Z0-9]+)?[^a-zA-Z0-9]/))
			{
				intScore = (intScore+5)
				strLog   = strLog + "5 points for at least two special chars\n"
			}
		
			
			// COMBOS
			if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
			{
				intScore = (intScore+2)
				strLog   = strLog + "2 combo points for upper and lower letters\n"
			}
	
			if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
			{
				intScore = (intScore+2)
				strLog   = strLog + "2 combo points for letters and numbers\n"
			}
	 
										// [verified] letters, numbers, and special characters
			if (passwd.match(/([a-zA-Z0-9].*[^a-zA-Z0-9])|([^a-zA-Z0-9].*[a-zA-Z0-9])/))
			{
				intScore = (intScore+4)
				strLog   = strLog + "4 combo points for letters, numbers and special chars\n"
			}
		}
	
		if(passwd.length<minLength)
		{
			strVerdict = "too short"
			strColor = "red";
		}
		else if (intScore < 15)
		{
			strVerdict = "weak"
			strColor = "red";
		}
		else if (intScore > 16 && intScore < 26)
		{
		   strVerdict = "medium"
		   strColor = "orange";
		}
		else if (intScore > 27 && intScore < 45)
		{
		   strVerdict = "strong"
		   strColor = "green";
		}
		else
		{
		   strVerdict = "very strong"
		   strColor = "green";
		}
	
		return new Array(intScore, strVerdict, strColor, strLog);
}

var search_timeout = undefined;
var fullname_timeout = undefined;
var username_timeout = undefined;
var password_timeout = undefined;
var email_timeout = undefined;
var success_pre = '<img src="images/buttons/signup_check.gif">';
var success_post = '';
var fail_pre = '<font color="red">';
var fail_post = '</font>';
var fullname_info = "enter your first and last name";
var username_info = "pick a unique name to represent yourself";
var password_info = "6 or more characters (something hard to crack)";
var email_info = "we'll email you a confirmation";
var captcha_info = "cannot read the image? click it to generate a new one";

function loadContentSignupInfo(div_id, string) 
{
	$("#"+div_id).html('<img src="images/buttons/signup_info.gif"></img>'+string);
}


function loadContentSignup(input_id, div_id, event)
{
	// only when tab 
	// Delay any action for a bit so we aren't DDOSing
    if(search_timeout != undefined) {
        clearTimeout(search_timeout);
	}
    
	switch (input_id) {
		
		case 'fullname':
			if(fullname_timeout != undefined) {
		        clearTimeout(fullname_timeout);
			}		
			if ($("#"+input_id).val() == '') {
				loadContentSignupInfo(div_id, fullname_info);
		    } else {
				fullname_timeout = setTimeout(function() {
			        fullname_timeout = undefined;
			        validateFullname(input_id, div_id);
				}, 600);
		    }
			
			break;
			
		case 'username':	
			if(username_timeout != undefined) {
		        clearTimeout(username_timeout);
			}
			if ($("#"+input_id).val() == '') {
				loadContentSignupInfo(div_id, username_info);
		    } else {
				username_timeout = setTimeout(function() {
				        username_timeout = undefined;
				        validateUsername(input_id, div_id);
				}, 2000);
		    }
			
			break;
			
		case 'password':
			if(password_timeout != undefined) {
		        clearTimeout(password_timeout);
			}
			if ($("#"+input_id).val() == '') {
				loadContentSignupInfo(div_id, password_info);
		    } else {
				password_timeout = setTimeout(function() {
			        password_timeout = undefined;
			        validatePassword(input_id, div_id);
				}, 600);
		    }
		
		break;
		
		case 'email':
			if(email_timeout != undefined) {
		        clearTimeout(email_timeout);
			}
			if ($("#"+input_id).val() == '') {
				loadContentSignupInfo(div_id, email_info);
		    } else {
				email_timeout = setTimeout(function() {
			        email_timeout = undefined;
			        validateEmail(input_id, div_id);
				}, 600);
		    }
			
		break;	

		case 'captcha':
		
			loadContentSignupInfo(div_id, captcha_info);
			
		break;
	}
}

function validateFullname(input_id, div_id)
{
	data = $("#"+input_id).val();
	
	if (data.indexOf(' ') == -1) {
		$("#"+div_id).html(fail_pre+'Must enter your fullname (i.e. John Smith)'+fail_post);
	} else {
		$("#"+div_id).html(success_pre+'ok'+success_post);
	}
}

function validateUsername(input_id, div_id) 
{
	var $data = $("#"+input_id).val();
	
	var reg = /^([A-Za-z0-9\-])+$/;
	
	if (reg.test($data) == false) {
		$("#"+div_id).html(fail_pre+'username can only contain letters, numbers, and dashes (-)'+fail_post); // load content
	} else {
		$.ajax({
			type: 		"POST",
			url: 		"inc/ajax/validateUsername.php",
			cache:		false,
			data:		"username="+$data,
			success:	function (html) {
							if (html == 'available') {
								$("#"+div_id).html(success_pre+'ok'+success_post); // load content
							} else {
								$("#"+div_id).html(fail_pre+'username has already been taken'+fail_post); // load content
							}
						}
		});
	}
}

function validatePassword(input_id, div_id)
{
	data = $("#"+input_id).val();
	
	passInfo = testPassword(data);
	if (passInfo[0] < 20) {
		$("#"+div_id).html('<font color="'+passInfo[2]+'">'+passInfo[1]+'</font>');
	} else {
		$("#"+div_id).html(success_pre+'<font color="'+passInfo[2]+'">'+passInfo[1]+'</font>'+success_post);
	}
}

function validateEmail(input_id, div_id)
{
	$data = $("#"+input_id).val();
	
	// only when tab key pressed (simulates onchange)
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test($data) == false) {
		$("#"+div_id).html(fail_pre+'invalid email address'+fail_post);
	} else {
		$.ajax({
			type: 		"POST",
			url: 		"inc/ajax/validateEmail.php",
			cache:		false,
			data:		"email="+$data,
			success:	function (html) {
							if (html == 'available') {
								$("#"+div_id).html(success_pre+'ok'+success_post); // load content
							} else {
								$("#"+div_id).html(fail_pre+'email already in our system. If you would like to create additional accounts, please contact us for information.'+fail_post); // load content
							}
						}
		});
	}
}


/* ######################### End Passwords and Validation ########################## */


/* ######################### Zone Information ##########################*/

var lists = new Array();

//First set of text and values
lists['CA']    = new Array();
	lists['CA'][0] = new Array(
		'-- Select Province --',
		'Alberta',
		'British Columia',
		'Manitoba',
		'New Brunswick',
		'Newfoundland',
		'Northwest Territories',
		'Nova Scotia',
		'Nunavut',
		'Ontario',
		'Prince Edward Island',
		'Quebec',
		'Saskatchewan',
		'Yukon Territory'
	);
	lists['CA'][1] = new Array(
		'',
		'AB',
		'BC',
		'MB',
		'NB',
		'NF',
		'NT',
		'NS',
		'NU',
		'ON',
		'PE',
		'QC',
		'SK',
		'YT'
);

//Second set of text and values
lists['US']    = new Array();
	lists['US'][0] = new Array(
		'-- Select State --',
		'Alabama',
		'Alaska',
		'Arkansas',
		'Arizona',
		'California',
		'Colorado',
		'Connecticut',
		'Dist Of Col',
		'Delaware',
		'Florida',
		'Georgia',
		'Hawaii',
		'Iowa',
		'Idaho',
		'Illinois',
		'Indiana',
		'Kansas',
		'Kentucky',
		'Louisiana',
		'Massachusetts',
		'Maryland',
		'Maine',
		'Michigan',
		'Minnesota',
		'Missouri',
		'Mississippi',
		'Montana',
		'North Carolina',
		'North Dakota',
		'Nebraska',
		'New Hampshire',
		'New Jersey',
		'New Mexico',
		'Nevada',
		'New York',
		'Ohio',
		'Oklahoma',
		'Oregon',
		'Pennsylvania',
		'Rhode Island',
		'South Carolina',
		'South Dakota',
		'Tennessee',
		'Texas',
		'Utah',
		'Virginia',
		'Vermont',
		'Washington',
		'Wisconsin',
		'West Virginia',
		'Wyoming'
	);
	lists['US'][1] = new Array(
		'',
		'AK',
		'AL',
		'AR',
		'AZ',
		'CA',
		'CO',
		'CT',
		'DC',
		'DE',
		'FL',
		'GA',
		'HI',
		'IA',
		'ID',
		'IL',
		'IN',
		'KS',
		'KY',
		'LA',
		'MA',
		'MD',
		'ME',
		'MI',
		'MN',
		'MO',
		'MS',
		'MT',
		'NC',
		'ND',
		'NE',
		'NH',
		'NJ',
		'NM',
		'NV',
		'NY',
		'OH',
		'OK',
		'OR',
		'PA',
		'RI',
		'SC',
		'SD',
		'TN',
		'TX',
		'UT',
		'VA',
		'VT',
		'WA',
		'WI',
		'WV',
		'WY'
);
	
//Third set of text and values
lists['other']    = new Array();
	lists['other'][0] = new Array(
		'Select Country'
	);
	lists['other'][1] = new Array(
		'N/A'
);

//Fourth set of text and values
lists['empty']    = new Array();
	lists['empty'][0] = new Array(
		'-- Select Country First --'
	);
	lists['empty'][1] = new Array(
		''
);

//This function goes through the options for the given
//drop down box and removes them in preparation for
//a new set of values
function emptyList( box ) {
	//Set each option to null thus removing it
	while ( box.options.length ) box.options[0] = null;
}

//This function assigns new drop down options to the given
//drop down box from the list of lists specified
function fillList( box, arr ) {
	//arr[0] holds the display text
	//arr[1] are the values
	for ( i = 0; i < arr[0].length; i++ ) {
		//Create a new drop down option with the
		//display text and value from arr
		option = new Option( arr[0][i], arr[1][i] );

		//Add to the end of the existing options
		box.options[box.length] = option;
	}

	//Preselect option 0
	box.selectedIndex=0;
}

//This function performs a drop down list option change by first
//emptying the existing option list and then assigning a new set
function changeList(box) {
	//Isolate the appropriate list by using the value
	//of the currently selected option
	list = lists[box.options[box.selectedIndex].value];
	value = box.options[box.selectedIndex].value;

	//Next empty the slave list
	emptyList(box.form.province);

	//Then assign the new list values
	if(value!="US" && value!="CA" && value!="empty") {
		list = lists["other"];
	}
	
	fillList(box.form.province, list);
}

//This function goes through the options for the given
//drop down box and removes them in preparation for
//a new set of values
function emptyMailingList( box ) {
	//Set each option to null thus removing it
	while ( box.options.length ) box.options[0] = null;
}

//This function assigns new drop down options to the given
//drop down box from the list of lists specified
function fillMailingList( box, arr ) {
	//arr[0] holds the display text
	//arr[1] are the values
	for ( i = 0; i < arr[0].length; i++ ) {
		//Create a new drop down option with the
		//display text and value from arr
		option = new Option( arr[0][i], arr[1][i] );

		//Add to the end of the existing options
		box.options[box.length] = option;
	}

	//Preselect option 0
	box.selectedIndex=0;
}

//This function performs a drop down list option change by first
//emptying the existing option list and then assigning a new set
function changeMailingList(box) {
	//Isolate the appropriate list by using the value of the currently selected option
	list = lists[box.options[box.selectedIndex].value];

	//Next empty the slave list
	emptyMailingList(box.form.mailingState);

	//Then assign the new list values
	fillMailingList(box.form.mailingState, list);
}

/* ############################ End Zone Information #########################*/

/* ############################ iFRAME Functions #############################*/

function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}

/* ########################## End iFRAME Functions ###########################*/

/* ########################## String Manipulation ############################*/

function ucwords(str) {
    // Uppercase the first character of every word in a string  
    // 
    // version: 1001.2911
    // discuss at: http://phpjs.org/functions/ucwords    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Waldo Malqui Silva
    // +   bugfixed by: Onno Marsman
    // +   improved by: Robin
    // *     example 1: ucwords('kevin van zonneveld');    // *     returns 1: 'Kevin Van Zonneveld'
    // *     example 2: ucwords('HELLO WORLD');
    // *     returns 2: 'HELLO WORLD'
    return (str + '').replace(/^(.)|\s(.)/g, function ($1) {
        return $1.toUpperCase();    });
}

/* ########################## String Manipulation ############################*/

/* ######################### Search ############################# */

function searchTip(e) {
	switch(e.val()) {
		case 'keyword':
			$('#searchOptionsTip').html('e.g. Singer; Retail; Jazz');
			break;
		case 'artist':
			$('#searchOptionsTip').html('e.g. Vocalist; Piano; Acoustic Guitar; etc');
			break;
		case 'group':
			$('#searchOptionsTip').html('e.g. Pop; Rock; Choral; Orchestra; etc');
			break;
		case 'industry':
			$('#searchOptionsTip').html('e.g. Venues; Producers; Retail; Video; etc');
			break;
		case 'event':
			$('#searchOptionsTip').html('Search for events in your area');
			break;
		case 'venue':
			$('#searchOptionsTip').html('Search for venues in your area');
			break;
		default:
			$('#searchOptionsTip').html('<b>Search Options:</b>');
			break;
	}
}


function isearch() {
	var mouseIsOver = true;
	$('#top-nav-search').hover(function() { mouseIsOver = true; }, function() { mouseIsOver = false; if (!$('#searchBox').hasClass('focus')) { searchHide(); }; } );
	$('#top-nav-search').find('input').change(function() { searchTip($(this)); $('#searchBox').focus(); });
	$('#top-nav-search').click(function() { searchShow(); } );
	$('#searchBox').focus(function() { $(this).addClass('focus'); });
	$('#searchBox').blur(function() { $(this).removeClass('focus'); if (!mouseIsOver) { searchHide(); }; });  
}

function searchShow() {
	if ($('#searchOptions').css('display') == 'none') {
		$('#searchOptions').show(200)
				.queue(function() { $(this).shadow($shadowOpts2); $(this).dequeue(); });
	}
	if ($('#searchBox').val() == 'search') { 
		$('#searchBox').val('');
	}
}

function searchHide() {
	$('#searchOptions').hide(200);
	$('#top-nav-search').queue(function() { $(this).shadowDestroy(); $(this).dequeue(); });
	
	if ($('#searchBox').val() == '') { 
		$('#searchBox').val('search');
	}
}

function toggleInfo(elm)
{
	html = $(elm).parent().find('a:first').html();
	html = html.substring(1, html.length);
	$(elm).toggle(400)
					.queue(function() {
						if ($(elm).css('display') == 'none') {
							$(elm).parent().find('a:first').html('+'+html);
						} else {
							$(elm).parent().find('a:first').html('-'+html);
						}
						$(this).dequeue();
					});
}

function hideOptions()
{
	$('#options').hide(400);
	$('#genres').hide(400);
	$('#categoriesDiv').hide(400);
}

function showOptions()
{
	$('#options').show(400)
		.find('#categoriesDiv')
		.hide(200)
		.show(400);
}

function hideGenres()
{
	$('#genres').hide(400);
	
}

function showGenres()
{
	$('#genres').show(400); 
	
	loadContent('#genreDiv', 'inc/ajax/getGenres.php'); 
}

function changeClass(classType)
{
	if(classType=="artist") {
		showOptions();		
		showGenres();
		
		loadContent('#categoriesDiv', 'inc/ajax/getArtistCategories.php');
	} else if(classType=="group") {
		showOptions();
		showGenres();
		
		loadContent('#categoriesDiv', 'inc/ajax/getGroupCategories.php');
	} else if(classType=="industry") {
		showOptions();
		hideGenres();
		
		loadContent('#categoriesDiv', 'inc/ajax/getIndustryCategories.php');
	} else {
		hideOptions();
	}
}

/* ######################### End Search ############################# */


/* ######################### Feedback ############################# */

var GSFN;
if(GSFN == undefined) {
  GSFN = {};
  
  GSFN.gId = function(id) {
    return document.getElementById(id);
  };

  GSFN.hasClassName = function(element, className) {
    var elementClassName = element.className;

    return (elementClassName.length > 0 && (elementClassName == className ||
      new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
  };

  GSFN.addClassName = function(element, className) {
    if (!GSFN.hasClassName(element, className))
      element.className += (element.className ? ' ' : '') + className;
    return element;
  };

  GSFN.removeClassName = function(element, className) {
    var newClass = GSFN.strip(element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' '));
    element.className = newClass;
    return element;
  };

  GSFN.strip = function(string) {
    return string.replace(/^\s+/, '').replace(/\s+$/, '');
  };
}

GSFN.feedback = function(url, tab_options) {
  this.empty_url = "https://s3.amazonaws.com/getsatisfaction.com/feedback/transparent.gif";
  this.feedback_url = url;
  this.tab_options = tab_options ? tab_options : {};
  this.tab_options.placement = this.tab_options.placement ? this.tab_options.placement : 'left';
  this.tab_options.color = this.tab_options.color ? this.tab_options.color : '#222';
  
  
  this.tab_html = '<a href="#" id="fdbk_tab" class="fdbk_tab_'+this.tab_options.placement+'" style="background-color:'+this.tab_options.color+'">FEEDBACK</a>';
  this.overlay_html = '<div id="fdbk_overlay" style="display:none">' +
                        '<div id="fdbk_container">' +
                          '<a href="#" onclick="GSFN.hide();return false" id="fdbk_close"></a>' +
                          '<iframe src="' + this.empty_url + '" id="fdbk_iframe" allowTransparency="true" scrolling="no" frameborder="0" class="loading"></iframe>' +
                        '</div>' +
                        '<div id="fdbk_screen"></div>' +
                      '</div>';
                      
  if(this.tab_options.container) {
    var container_el = this.gId(this.tab_options.container);
    container_el.innerHTML = this.tab_html + this.overlay_html;
  } else {
    document.write(this.tab_html);
    document.write(this.overlay_html);      
  }                   

  this.gId('fdbk_tab').onclick = function() { GSFN.show(); return false; }
  this.gId('fdbk_iframe').setAttribute("src", this.empty_url);
};

GSFN.set_position = function() {
  this.scroll_top = document.documentElement.scrollTop || document.body.scrollTop;
  this.scroll_height = document.documentElement.scrollHeight;
  this.client_height = window.innerHeight || document.documentElement.clientHeight;
  this.gId('fdbk_screen').style.height = this.scroll_height+"px";
  this.gId('fdbk_container').style.top = this.scroll_top+(this.client_height*0.1)+"px";
};

GSFN.show = function() {
  this.gId('fdbk_iframe').setAttribute("src", this.feedback_url);
  if (this.gId('fdbk_iframe').addEventListener) {
    this.gId('fdbk_iframe').addEventListener("load", GSFN.loaded, false);
  } else if (this.gId('fdbk_iframe').attachEvent) {
    this.gId('fdbk_iframe').attachEvent("onload", GSFN.loaded);
  }
  this.set_position();
  
  GSFN.addClassName(document.getElementsByTagName('html')[0], 'feedback_tab_on');
  this.gId('fdbk_overlay').style.display = "block";
};
  
GSFN.hide = function() {
  if (GSFN.gId('fdbk_iframe').addEventListener) {
    GSFN.gId('fdbk_iframe').removeEventListener("load", GSFN.loaded, false);
  } else if (GSFN.gId('fdbk_iframe').attachEvent) {
    GSFN.gId('fdbk_iframe').detachEvent("onload", GSFN.loaded);
  }
  this.gId('fdbk_overlay').style.display = "none";
  this.gId('fdbk_iframe').setAttribute("src", this.empty_url);
  GSFN.gId('fdbk_iframe').className = "loading";

  GSFN.removeClassName(document.getElementsByTagName('html')[0], 'feedback_tab_on');
};
  
GSFN.loaded = function() {
  GSFN.gId('fdbk_iframe').className = "loaded";
};

/* ######################### End Feedback ############################# */
