var hmlSubmit = {


	//*************************************************************************************
	//** initializeSubmitMix
	//*************************************************************************************
	initializeSubmitMix : function() {
	
		hmlHome.yE($('addAMix'),'click',hmlSubmit.addAMix);
		hmlHome.yE($('showInfo'),'click',hmlHome.showInfo);
		hmlHome.yE($('cancelLink'),'click',hmlHome.hideInfo);
		hmlHome.yE($('addATrack'),'click',hmlSubmit.addATrack);
		hmlHome.yE($('tags'),'click',hmlSubmit.clearTags);
		
			
		if ( ! readCookie("authenticated") ) { window.location.href = "login.html#submitamix.html" } else {
		hmlHome.showPage() }
		
		$('tags').value = "";
		$('url').value = "http://";
		$('title').value = "";
		$('title').focus();
					
		enableTooltips('mixesAjaxContainer');
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	
	
	
	
	
	//*************************************************************************************
	//** initializeAddSite
	//*************************************************************************************
	initializeAddSite : function() {
	
	
		hmlHome.yE($('addSiteBtn'),'click',hmlSubmit.addASite);
		hmlHome.yE($('showInfo'),'click',hmlHome.showInfo);
		hmlHome.yE($('closeLink'),'click',hmlHome.hideInfo);
		hmlHome.yE($('cancelLink'),'click',hmlHome.hideInfo);
		hmlHome.yE($('tags'),'click',hmlSubmit.clearTags);
			
		if ( ! readCookie("authenticated") ) { window.location.href = "login.html#addsite.html" } else {
		hmlHome.showPage() }
		
		$('tags').value = "";
		$('url').value = "http://";
		$('title').value = "";
		$('title').focus();
					
		enableTooltips('mixesAjaxContainer');
	
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	
	
	
	
	


	//*************************************************************************************
	//** ADDAMIX
	//*************************************************************************************
	addAMix : function() {
	
		var validation = "true"
	
		//make sure title is not blacnk
		if ( $('title').value == "" ) { 
	
			$('mtitle').innerHTML = "&nbsp;&nbsp;enter a name"
			$('title').className = "field notValid";
			validation = "false";
			
		} else { 
		
			$('mtitle').innerHTML = "&nbsp"
			$('title').className = "field"; 
			
		}
	
		//make sure the mix url is valid
		var validURL = IsValidMp3($('url').value);
		if ( validURL == "false" ) {
	
			validation = "false";
			$('murl').innerHTML = "&nbsp;&nbsp;invalid url"
			$('url').className = "field notValid";	
	
		} else { 
		
			$('murl').innerHTML = "&nbsp"
			$('url').className = "field";	 
			
		}
	
		//make sure they select the music style
		if ( $('genre').value == "Select Music Style" ) {
		
			validation = "false";
			$('mgenre').innerHTML = "&nbsp;&nbsp;select a genre"
			$('genre').className = "field notValid";
			
		} else {
		
			$('mgenre').innerHTML = "&nbsp;"
			$('genre').className = "field";	
			
		}
	
	
		//if validation doesn't pass, halt the script
		if ( validation == "false" ) return false;
	
		//strip out the spaces from the tags
		var tags = $('tags').value.replace(/\s*/g,'')
	
		//build the parameters
		var pars = new StringBuffer();
		pars.append("req=na")
		pars.append("&username=" + readCookie('authenticated'))
		pars.append("&title=" + $('title').value);
		pars.append("&url=" + $('url').value);
		pars.append("&genre=" + $('genre').value);
		pars.append("&tags=" + tags);
		pars.append("&pl=thissopenplaylisttext");
	
		hmlHome.ajaxCall(hmlHome.commentsURL,pars.toString(),hmlSubmit.confirmSubmit)
	
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	
	
	
	
	
	//*************************************************************************************
	//** ADDASITE
	//*************************************************************************************
	addASite : function() {
	
		var validation = "true"
	
		//make sure title is not blank
		if ( $('title').value == "" ) { 
	
			$('mtitle').innerHTML = "&nbsp;&nbsp;enter a title"
			$('title').className = "field notValid";
			validation = "false";
			
		} else { 
		
			$('mtitle').innerHTML = "&nbsp"
			$('title').className = "field"; 
			
		}
	
		//make sure this is a valid url
		var validURL = IsValidUrl($('url').value);
		if ( validURL == "false" ) {
	
			validation = "false";
			$('murl').innerHTML = "&nbsp;&nbsp;invalid url"
			$('url').className = "field notValid";	
	
		} else { 
	
			$('murl').innerHTML = "&nbsp"
			$('url').className = "field";	 
			
		}
	
		//make sure they selected a musical style
		if ( $('genre').value == "Select Music Style" ) {
		
			validation = "false";
			$('mgenre').innerHTML = "&nbsp;&nbsp;select a genre"
			$('genre').className = "field notValid";
			
		} else {
		
			$('mgenre').innerHTML = "&nbsp;"
			$('genre').className = "field";
			
		}
	
		
		//if validation didnt pass, then stop it
		if ( validation == "false" ) { return false; }
		
		//strip the spaces from the tags
		var tags = $('tags').value.replace(/\s*/g,'');
	
	
		//build the parameters
		var pars = new StringBuffer();
		pars.append("req=nw")
		pars.append("&username=" + readCookie('authenticated'))
		pars.append("&title=" + $('title').value);
		pars.append("&url=" + $('url').value);
		pars.append("&genre=" + $('genre').value);
		pars.append("&tags=" + tags);
		pars.append("&desc=" + $('description').value);
	
	
		//submit the site
		hmlHome.ajaxCall(hmlHome.commentsURL,pars.toString(),hmlSubmit.confirmSubmit)
	
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	
	
	
	
	//*************************************************************************************
	//** CONFIRMSUBMIT
	//*************************************************************************************
	confirmSubmit : function(resp) {
	
	if ( escape(resp.responseText) == "1%0A" ) { 
	
	
		if ( hmlHome.pageName == "addsite.html" ) { window.location.href = "confirmSite.html"} else { window.location.href = "confirmMix.html" }
		
	} else {
	
	//something went wrong with the submit
	$('murl').innerHTML = "&nbsp;&nbsp;site already exists"
	$('url').className = "field notValid";
	
	}
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------

	//*************************************************************************************
	//** ADDTRACK: adds additional track fields to the submit form
	//*************************************************************************************
	addATrack : function() {
	
		//grab the number of existing tracks
		var tracks = $$('td#playlist p').length;
	
		//write out the requisite html for a track line item
		newTrackHTML = "<p><input id='track" + (tracks + 1) + "' "
		newTrackHTML = newTrackHTML + "value='Track " + (tracks + 1) + 		"' "
		newTrackHTML = newTrackHTML + "name='track" + (tracks + 1) + "'/>"
		newTrackHTML = newTrackHTML + "<input class='time' value='0:00' name='time" + (	tracks + 1) + "'/></p>"
	
		//grab the current HTML of the tracks and write the new track line item
		currentTracks = $('playlist').innerHTML
		$('playlist').innerHTML = "";
		$('playlist').innerHTML = currentTracks + newTrackHTML;
	
		//focus the cursor / screen on the track line item that was added
		$('track'+ (tracks + 1)).focus();
	
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------

	
	
	//*************************************************************************************
	//** clearTags
	//*************************************************************************************
	clearTags : function() {
	
	this.value = "";
	
	}
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------




}




//*************************************************************************************
//** ISVALIDURL - LAUNCHES A FUNCTION ON WINDOW LOAD
//*************************************************************************************
function IsValidUrl(url) {

var urlRegxp = /^(http:\/\/|https:\/\/|ftp:\/\/){1}([\w]+)(.[\w]+){1,2}$/;

if (urlRegxp.test(url) != true) { return "false"; }

}
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------




//*************************************************************************************
//** ISVALIDMP3
//*************************************************************************************
function IsValidMp3(url) {

var urlRegxp = /^(http:\/\/|https:\/\/|ftp:\/\/){1}([\w]+)(.[\w]+){1,}\.mp3$/

if (urlRegxp.test(url) != true) { return "false"; }

}
//-------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------