function edittitle(){
	$('audtitle').style.display="none";
	$('audtitleinput').style.display="block";
}
function appendDom2( text, li ){		
			
		var show_id 		= li.id;
		new Ajax.Request('/Ajax/GetShowTitle', {
			  method: 'post',
			  parameters: { show_id : show_id },
			  onSuccess: function(res) {
				var response = eval('(' + res.responseText + ')');
				
				show_title = response.show_title.split('-');
				show_type=response.show_type;
				addShow( show_title[0], show_id,show_type );
				$('shows_auto').value = '';						
			
			}
		});		
	//	getShow(show_id);
}

function chooseShow(text,li){
		var show_id 		= li.id;
		var id	= show_id.split("_");
		addShow1(id);
	
		$('shows_auto').value = '';
	
}

function addShow1(show_id){

		new Ajax.Request('/Ajax/GetShowTitle', {
			  method: 'post',
			   parameters: { show_id : show_id },
			  onSuccess: function(res) {
				var response = eval('(' + res.responseText + ')');
				show_title = response.show_title.split('-');
                

				show_type=response.show_type;
	

		var newNode = document.createElement("LI");
		newNode.setAttribute("style","padding:0px;margin-bottom:0px;");
		newNode.setAttribute("id", "show_" + show_id);
		
		newNode.innerHTML = '<input type="hidden" id="show_id" name="show_id" value="'+show_id+'"><div style="float: left;"><a href="/Shows/View/'+show_id+'" class="bold_txt">' + show_title[0] +'</a>-<i>'+show_type+'</i>'+ '</div>' + '<div style="float: right"><a href="javascript:removeMe3(\'show_'+show_id+'\')">Remove</a></div><div style="clear: both;"></div>';
		$('enter_show').style.display="none";
	
		$('shows_auto').style.display="none";
		$('add_shows1').appendChild(newNode);
		$('add_shows1').style.display="block";
		}
	});
}


function addShow( title, show_id,show_type ){

		
	if( show_id != 'none' ) {		
	
		var newNode = document.createElement("LI");
		newNode.setAttribute("style","padding:0px;margin-bottom:0px;");
		newNode.setAttribute("id", "show_" + show_id);
		
		newNode.innerHTML = '<input type="hidden" id="show_id" name="show_id" value="'+show_id+'"><div style="float: left;"><a href="/Shows/View/'+show_id+'" class="bold_txt">' + title +'</a>-<i>'+show_type+'</i>'+ '</div>' + '<div style="float: right"><a href="javascript:removeMe3(\'show_'+show_id+'\')">Remove</a></div><div style="clear: both;"></div>';			
		$('enter_show').hide();
	
		$('shows_auto').style.display="none";
		$('add_shows1').appendChild(newNode);
	} else {
		alert("Please Pick a Show First");
	}
}
function removeMe3(element){
	
	$(element).remove();
	$('enter_show').style.display="block";

	$('shows_auto').style.display="block";
}
function chooseOrg(text, li){
		var org_id 		= li.id;
		var id	= org_id.split("_");
		addorg(id[0]);
	
		$('orgs_auto1').value = '';
}
function addorg(org_id){
	new Ajax.Request('/Ajax/FindOrg', {
			  method: 'post',
			  parameters: {org_id:org_id},
			  onSuccess: function(res) {
				var response = eval('(' + res.responseText + ')');
				org_id = response.org_info.id;
				title = response.org_info.name;
	

		var newNode = document.createElement("LI");
		newNode.setAttribute("id", "org_" + org_id);
		newNode.setAttribute("class", "org_ids");
		newNode.innerHTML = '<div style="float: left;" class="bold_txt"><input type="hidden" id="org_id" name="org_id" value="'+org_id+'">' + title + '</div><div style="float: right;"><a href="###" onclick="removeMe2(\'org_'+org_id+'\')" >Remove</a></div><div style="clear: both;">';		
		$('orgs_auto1').style.display = "none";
		$('add_org_text').style.display = "none";
		$('add_orgs').appendChild(newNode);
		$('add_orgs').style.display="block";
		}
	});
}
function removeMe2(element){

	$(element).remove();
	$('add_org_text').style.display = "block";
	$('orgs_auto1').style.display = "block";
}
function chooseVenue(text, li){	
		var venue_id 		= li.id;
		var id	= venue_id.split("_");
		
		addVenue(id);
		$('venues_auto').value = '';
}
function addVenue(venue_id,f){
	
	new Ajax.Request('/Ajax/FindVenue', {
			  method: 'post',
			  parameters: {venue_id:venue_id},
			  onSuccess: function(res) {
				var response = eval('(' + res.responseText + ')');
				
				title = response.venue_name;
		
		var newNode = document.createElement("LI");
		newNode.setAttribute("id", "venue_" + venue_id);
		newNode.setAttribute("class", "org_ids");
		newNode.innerHTML = '<div style="float: left;" class="bold_txt"><input type="hidden" id="venue_id" name="venue_id" value="'+venue_id+'">' + title + '</div><div style="float: right;"><a href="###" onclick="removeMe(\'venue_'+venue_id+'\')" >Remove</a></div><div style="clear: both;"></div>';		
		$('venues_auto').style.display = "none";
		$('add_venue_text').style.display = "none";
		$('add_venues').appendChild(newNode);
		$('add_venues').style.display="block";
	//	setaddress(response.address,response.state,response.country,response.city);
		
		}
	});
}	


function removeMe(element){

	$(element).remove();
	$('add_venue_text').style.display = "block";
	$('venues_auto').style.display = "block";
}







function padout(number) { return (number < 10) ? '0' + number : number; }
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function validate(what) {
   var startday = what.start_day.options[what.start_day.selectedIndex].value;
    var startmonth = what.start_month.options[what.start_month.selectedIndex].value;
    var startyear = what.start_year.options[what.start_year.selectedIndex].text;
    var endday = what.end_day.options[what.end_day.selectedIndex].value;
    var endmonth = what.end_month.options[what.end_month.selectedIndex].value;
    var endyear = what.end_year.options[what.end_year.selectedIndex].text;

    unvalidstartdate = startmonth + '/' + startday + '/' + startyear;
    unvalidenddate = endmonth + '/' + endday + '/' + endyear;
	
    var startdate = new Date(startyear-0,startmonth-1,startday-0);
    var enddate = new Date(endyear-0,endmonth-1,endday-0);
   var validstartdate = padout(startdate.getMonth()+1) + '/' + padout(startdate.getDate()) + '/' + y2k(startdate.getYear())
    var validenddate = padout(enddate.getMonth()+1) + '/' + padout(enddate.getDate()) + '/' + y2k(enddate.getYear())
 
    if (unvalidenddate != validenddate) {
        alert('End Date: ' + what.end_day.options[what.end_day.selectedIndex].text +
                       ' ' + what.end_month.options[what.end_month.selectedIndex].text +
                       ' ' + what.end_year.options[what.end_year.selectedIndex].text + ' is invalid');
        return false;
    }
    if (unvalidstartdate != validstartdate) {
        alert('Start Date: ' + what.start_day.options[what.start_day.selectedIndex].text +
                       ' ' + what.start_month.options[what.start_month.selectedIndex].text +
                       ' ' + what.start_year.options[what.start_year.selectedIndex].text + ' is invalid');
        return false;
    }
	
 
    
     if (Date.parse(validstartdate) <= Date.parse(validenddate))  {
        // valid
    }
	 else{
        alert('You cannot submit an audition with a start date later than the end date.');
        return false
    }
    
    currentdate = new Date();
   
    if (Date.parse(validenddate) >= Date.parse(currentdate.toDateString())) {
        // valid
    }
    else {
        alert('Invalid End Date! End Date should be future date');
        return false;
    }
    
    return true;
}



function validateForm(f){
	f=document.getElementById(f);

	var errorsOnPage = true;
	var newErrors = false;

	if( errorsOnPage == true ) {
		if (f.title.value==''){
			newErrors=true;
			f.title.style.borderColor='Red';
			
		}
		
		
		
		
		if (f.city.value.length <1){
				newErrors=true;
				f.city.style.borderColor='Red';
			}
			var iSelect1 = f.country.options[f.country.selectedIndex].value ;
			
			if (iSelect1==''){
				newErrors=true;
				f.country.style.borderColor='Red';
			}
			if (iSelect1 ==840 || iSelect1 == 124 || iSelect1==36 || iSelect1==826){
				var iSelect = f.state.options[f.state.selectedIndex].value;
				
				if (iSelect == '') {
					newErrors = true;
					f.state.style.borderColor='Red';
				}
			}
		if( newErrors == true ) {
			alert("There are some fields missing, please fill out all fields");
			return false;
		}else if (!validate(f)){
			
				newErrors=true;
				return false;
			}else{
				return true;
			}
		
	} else {
		
		alert("There were errors");
		return false;
	} 
}




// for edit  auditions
function to_display(orgset,venueset,showset){
	if (orgset !=null && orgset > 1){
		addorg(orgset);

	}
	else {
		$('add_orgs').style.display="none" ;
		$('add_org_text').style.display="block";
		
	}
	if (venueset!=null && venueset >1){
		addVenue(venueset);
	}
	else{
		$('add_venues').style.display="none";
		$('add_venue_text').style.display="block";
		
	}
	if (showset!= null && showset >1){
		
		addShow1(showset);
	}
	else{
		$('enter_show').style.display="block";
		$('add_shows1').style.display="none";
		
	}

}

function set_aud_type(audtype){
	if (audtype !=null){
		document.forms['edit_audition'].type[audtype].selected=true;
	}
}



    function set_state(val){
        if (val == '840'){
            $('state').style.display="block";
              $('state_text').value='';
            $('state_text').style.display="none";
            var options = new Array();
            /* USA states*/
            options = 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");



            $('state').options.length = 0;

            $('state').options[0] = new Option('----select----','');

            for(c=1;c<options.length;c++){

                $('state').options[c] = new Option(options[c],options[c]);
            }




        }else{
            $('state').options[0].selected=true;
            $('state').style.display="none";
           $('state_text').value='';
            $('state_text').style.display="block";
        }
    }


    function init_state(country,state){
        var options = new Array();
        /* USA states*/
        options = 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");
        var v=$('country').length;
        if(country != ''){

            for (j = 0; j <= v ; j++)
            {


                if (country== $('country')[j].value)
                {

                    $('country')[j].selected=true;
                    break;
                }
            }
            n = 0;

            if(country == '840'){
                $('state').style.display="block";
                $('state_text').value='';
                $('state_text').style.display="none";
                $('state').options.length = 0;
                $('state').options[0] = new Option('----select----','');
                for(c=1;c<options.length;c++){
                    if(state == options[c]){

                        $('state').options[c] = new Option(options[c],options[c],true);

                        $('state').options[c].selected=true;

                    }else{
                        $('state').options[c] = new Option(options[c],options[c]);

                    }
                }

            }else{
                $('state').style.display="none";
                $('state_text').style.display="block";
            }
        }

    }


