_editor_url = "/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }

function del()
{
	return confirm('Are you sure you want to delete this item?');
}

function MediaChange()
{

	document.all.flabel.innerHTML='File:';
	document.all.f.innerHTML='<input type=file name=fname>';
	document.all.subject.options.length = 0;
	document.all.desc.innerHTML='';

	if (document.all.title.disabled)
	{
		document.all.title.value = '';
		document.all.title.disabled = false;
		document.all.description.value = '';
		document.all.description.disabled = false;
	}

	if (document.profile.media.options[document.profile.media.selectedIndex].text == "Music")
	{
		var opts = new Array("2-step","A\'cappella","Acoustic","Afro-beat","Alternative","Ambient","Big Beat","Black Metal","Bluegrass","Blues","Breakbeat","Christian","Christian Rap","Classic Rock","Classical","Club","Comedy","Country","Death Metal","Disco House","Down-tempo","Drum & Bass","Drum and Bass","Drum and Bass","Dub","Electro","Electronica","Emo","Experimental","Folk","Folk Rock","Funk","Garage","Gothic","Grindcore","Grunge","Happy Hardcore","Hard House","Hardcore","Hip Hop","House","IDM","Indie","Industrial","Jam Band","Jazz","Jungle","Latin","Lounge","Metal","New Wave","Nu-Jazz","Other","Pop","Pop Punk","Post Hardcore","Powerpop","Progressive","Progressive House","Psychedelic","Psychobilly","Punk","R&amp;B","Rap","Reggae","Rock","Rockabilly","Screamo","Ska","Soul","Southern Rock","Surf","Techno","Thrash","Trance","Trip Hop");
		document.all.subject[0]=new Option("-- Select Genre --");
		for (i=1;i<=opts.length;i++)
			document.all.subject[i]=new Option(opts[i-1]);
	}
	else if (document.profile.media.options[document.profile.media.selectedIndex].text == "Acting")
	{
		var opts = new Array("Male","Female");
		document.all.subject[0]=new Option("-- Select Subcategory --",0);
		for (i=1;i<=opts.length;i++)
			document.all.subject[i]=new Option(opts[i-1]);
	}
	else
	{
		var opts = new Array("Abstract","Animals","Architecture","Book","Illustration","Children","Corporate","Design/Layout","Editorial","Fantasy/Mythical","Fashion/Beauty","Florals","Food/Beverage","Historical/Patriotic","Holidays/Seasonal","Humorous/Comic","Landscape/Outdoor","Lettering","Medical","Movies/Music/TV","Mystical/New","Age","Nature/Wildlife","Other/Misc.","People/Portrait","Places/Events","Religious","Science/Technology","Sci-Fi/Fantasy","Sci-Fi/Space","Sports/Recreation","Still","Life","Transportation","Underwater/Sea","Life","World","Culture","Youth");
		document.all.subject[0]=new Option("-- Select Subcategory --",0);
		for (i=1;i<=opts.length;i++)
			document.all.subject[i]=new Option(opts[i-1]);
	}	

	switch (document.profile.media.options[document.profile.media.selectedIndex].text)
	{
		case "Music":
			document.all.desc.innerHTML='<b>Music submissions must be mp3 files and cannot be larger than 4MB</b>';
			break;
		case "Writing":
			document.all.flabel.innerHTML='Sample:';
			document.all.f.innerHTML="<textarea name=textbox rows=4 cols=60 onclick=\"javascript:if (this.value=='Type text here'){this.value='';}\">Type text here</textarea>";
			break;
		case "Poetry":
			document.all.flabel.innerHTML='Sample:';
			document.all.f.innerHTML="<textarea name=textbox rows=4 cols=60 onclick=\"javascript:if (this.value=='Type text here'){this.value='';}\">Type text here</textarea>";
			break;
		case "Acting":
			document.all.flabel.innerHTML='Resume:';
			document.all.f.innerHTML="<textarea name=textbox rows=4 cols=60 onclick=\"javascript:if (this.value=='Type resume here'){this.value='';}\">Type resume here</textarea>";
			document.all.title.value = document.all.artistname.value;
			document.all.title.disabled = true;
			document.all.description.value = 'Resume for '+document.all.artistname.value;
			document.all.description.disabled = true;
			break;
		case "Filmmaking":
			document.all.desc.innerHTML='<b>Film submissions cannot be larger than 5MB, and should be .avi, .mov, .mpeg, .wmv, or .rm files</b>';
			break;
		default:
			document.all.desc.innerHTML='';
			break;
	}

	var framesetQuery = "";
	if ( window.top.location.search != 0 )
		framesetQuery = window.top.location.search;
	else 
		framesetQuery = "?OpenFrameset";
	var c = getParameter ( framesetQuery, 'subcategory' );

	for (var i = 0; i < document.all.subject.options.length; i++) 
		if (document.all.subject.options[i].value == c) 
			document.all.subject.options[i].selected = true;

	function getParameter ( queryString, parameterName )
	{
		var parameterName = parameterName + "=";
		if ( queryString.length > 0 ) 
		{
			begin = queryString.indexOf ( parameterName );
			if ( begin != -1 )
			{
				begin += parameterName.length;
				end = queryString.indexOf ( "&" , begin );
				if ( end == -1 )
				{
					end = queryString.length
				}
				return unescape ( queryString.substring ( begin, end ) );
			}
			return "null";
		}
	}
}

function MediaChangeEdit()
{
	document.all.subject.options.length = 0;
	
	if (document.all.title.disabled)
	{
		document.all.title.value = '';
		document.all.title.disabled = false;
		document.all.description.value = '';
		document.all.description.disabled = false;
	}

	if (document.profile.media.options[document.profile.media.selectedIndex].text == "Music")
	{
		var opts = new Array("2-step","A\'cappella","Acoustic","Afro-beat","Alternative","Ambient","Big Beat","Black Metal","Bluegrass","Blues","Breakbeat","Christian","Christian Rap","Classic Rock","Classical","Club","Comedy","Country","Death Metal","Disco House","Down-tempo","Drum & Bass","Drum and Bass","Drum and Bass","Dub","Electro","Electronica","Emo","Experimental","Folk","Folk Rock","Funk","Garage","Gothic","Grindcore","Grunge","Happy Hardcore","Hard House","Hardcore","Hip Hop","House","IDM","Indie","Industrial","Jam Band","Jazz","Jungle","Latin","Lounge","Metal","New Wave","Nu-Jazz","Other","Pop","Pop Punk","Post Hardcore","Powerpop","Progressive","Progressive House","Psychedelic","Psychobilly","Punk","R&amp;B","Rap","Reggae","Rock","Rockabilly","Screamo","Ska","Soul","Southern Rock","Surf","Techno","Thrash","Trance","Trip Hop");
		document.all.subject[0]=new Option("-- Select Genre --");
		for (i=1;i<=opts.length;i++)
			document.all.subject[i]=new Option(opts[i-1]);
	}
	else if (document.profile.media.options[document.profile.media.selectedIndex].text == "Acting")
	{
		var opts = new Array("Male","Female");
		document.all.subject[0]=new Option("-- Select Subcategory --",0);
		for (i=1;i<=opts.length;i++)
			document.all.subject[i]=new Option(opts[i-1]);
	}
	else
	{
		var opts = new Array("Abstract","Animals","Architecture","Book","Illustration","Children","Corporate","Design/Layout","Editorial","Fantasy/Mythical","Fashion/Beauty","Florals","Food/Beverage","Historical/Patriotic","Holidays/Seasonal","Humorous/Comic","Landscape/Outdoor","Lettering","Medical","Movies/Music/TV","Mystical/New","Age","Nature/Wildlife","Other/Misc.","People/Portrait","Places/Events","Religious","Science/Technology","Sci-Fi/Fantasy","Sci-Fi/Space","Sports/Recreation","Still","Life","Transportation","Underwater/Sea","Life","World","Culture","Youth");
		document.all.subject[0]=new Option("-- Select Subcategory --",0);
		for (i=1;i<=opts.length;i++)
		{
			document.all.subject[i]=new Option(opts[i-1]);
			if (document.all.subject[i].value == document.all.subcat.value)
			{
				document.all.subject[i].selected = true;
			}
		}
	}	

	var framesetQuery = "";
	if ( window.top.location.search != 0 )
		framesetQuery = window.top.location.search;
	else 
		framesetQuery = "?OpenFrameset";
	var c = getParameter ( framesetQuery, 'subcategory' );

	for (var i = 0; i < document.all.subject.options.length; i++) 
		if (document.all.subject.options[i].value == c) 
			document.all.subject.options[i].selected = true;

	function getParameter ( queryString, parameterName )
	{
		var parameterName = parameterName + "=";
		if ( queryString.length > 0 ) 
		{
			begin = queryString.indexOf ( parameterName );
			if ( begin != -1 )
			{
				begin += parameterName.length;
				end = queryString.indexOf ( "&" , begin );
				if ( end == -1 )
				{
					end = queryString.length
				}
				return unescape ( queryString.substring ( begin, end ) );
			}
			return "null";
		}
	}

}



function validate_join()
{
	if (document.join.firstname.value == '')
	{
		alert('You must enter your first name.');
		document.join.firstname.focus();
		return false;
	}
	if (document.join.lastname.value == '')
	{
		alert('You must enter your last name.');
		document.join.lastname.focus();
		return false;
	}
	if (document.join.email.value == '')
	{
		alert('You must enter your email address.');
		document.join.email.focus();
		return false;
	}
	if (!checkMail(document.join.email.value))
	{
		alert('You did not enter a valid email address.');
		document.join.email.focus();
		return false;
	}
	if (document.join.state.value == '' && document.join.country.value == 'US')
	{
		alert('You must enter your state.');
		document.join.state.focus();
		return false;
	}
	if (document.join.country.value == '')
	{
		alert('You must enter your country.');
		document.join.country.focus();
		return false;
	}
	if (document.join.username.value == '')
	{
		alert('You must enter a username.');
		document.join.username.focus();
		return false;
	}
	if (document.all.pwd.value == '')
	{
		alert('You must enter a password.');
		document.join.password.focus();
		return false;
	}
	if (document.join.howhear.selectedIndex == 0)
	{
		alert('Please select where you heard of ArtistSearch.net');
		document.join.howhear.focus();
		return false;
	}
	return true;
}

function validate_headshot()
{
	if (document.all.fname.value == '')
	{
		alert('You must enter a file name.');
		document.all.fname.focus();
		return false;
	}
	return true;
}

function validate_blog()
{
	if (document.all.title.value == '')
	{
		alert('You must enter a title for your post.');
		document.all.title.focus();
		return false;
	}
	if (document.all.body.value == '')
	{
		alert('Your post has no text!');
		document.all.body.focus();
		return false;
	}
	return true;
}

function validate_blog_edit()
{
	if (document.all.title.value == '')
	{
		alert('You must enter a title for your post.');
		document.all.title.focus();
		return false;
	}
	if (document.all.body.value == '')
	{
		alert('Your post has no text!');
		document.all.body.focus();
		return false;
	}
	return true;
}

function checkMail(val)
{
	var x = val;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(x)
}

// This is a global value to determine which item to select
var selectedOption = 0;
var KeyPressEnabled = true;


function SelectChange()
{
   // We use this function to disable any dynamic selecting of the
   // combo-box when the user uses the mouse to select items.
   
   if (KeyPressEnabled)
   {
      document.profile.media.selectedIndex = selectedOption;   
   }
}

function KeyPress(event)
{
	if (event.keyCode == 38 || event.keyCode == 40)
	{
		MediaChange();
	}
}

function KeyPressEdit(event)
{
	if (event.keyCode == 38 || event.keyCode == 40)
	{
		MediaChangeEdit();
	}
}

function validate_artwork()
{
	if (document.all.title.value == '')
	{
		alert('You must enter a title for your artwork.');
		document.all.title.focus();
		return false;
	}
	if (document.all.subject.selectedIndex == 0)
	{
		alert('You must select a sub-category.');
		document.all.subject.focus();
		return false;
	}
	document.all.message.innerHTML = "<font color=red><b>Please wait while your artwork is submitted.  If you are uploading a large file, this may take several minutes...</b></font>";
	document.all.sub.disabled = true;
	return true;
}
