function fieldFocus(object) {
if (object.className == 'field') object.className = 'field_select';
}

function fieldBlur(object) {
  if (object.className == 'field_select') object.className = 'field';
}

function fancyFieldFocus(object,display) {
  alert('12');
  //if(object.value==display){object.value='';}
  //fieldFocus(object);
  
}

function store(el,source) {
  for (var i=0, l=source.options.length;i<l;i++) {
       if (source.options[i].selected){
		   if (source.options[i].value != -1){
			   el.value = source.options[i].text;
			   //alert(el.value);
			   }
	   }
    }
  //alert('store done');
  //el.value = 0
}


function bump_hour(f,serial_num) {
	
	
	//alert (el+' - '+val);
	// el.value=val;
		start_h = 'hour_'+serial_num;
		end_h = start_h+'_end';
		start_am = 'morn_eve_'+serial_num;
		end_am = start_am+'_end';
		start_m = 'minute_'+serial_num;
		end_m = start_m+'_end';

//alert(f.elements['hour_'+serial_num].value);
		// this for NS4, check to see if it works for Safari
		//	if(isSaf){
		//	 thisval = f.elements[start_h][f.elements[start_h].selectedIndex].value;
		//	 f.elements[end_h].options[thisval].selected=true; // this is one hour later since first array position is at zero
		//	alert(thisval);
		//	}


		hour_num= f.elements[start_h].value;
		//alert(f.elements[start_h].value);
		//alert(hour_num);
		if(hour_num<12){
			f.elements[start_am].value='AM';
		}else{
			f.elements[start_am].value='PM';
		}
			
		incremented_hour = ++hour_num
		
		if(incremented_hour<12){
			f.elements[end_am].value='AM';
		}else{
			f.elements[end_am].value='PM';
		}
		
		if(incremented_hour<24) {
			f.elements[end_h].value=incremented_hour;
		}else{
			f.elements[start_m].value=':00'; //prevent neg duration loop possibility
			f.elements[end_h].value=23;
			f.elements[end_m].value=':45';
		}
		
		duration_calc (f,serial_num);
		
		//alert(el);
		
}


function duration_calc (f,serial_num){
	//alert('duration_calc');
	start_h = f.elements['hour_'+serial_num].value;  //,f.elements['morn_eve_'+serial_num].value;
	start_secs = HMStoSec1 (start_h+f.elements['minute_'+serial_num].value+':00');
	end_h = f.elements['hour_'+serial_num+'_end'].value;  //f.elements['morn_eve_'+serial_num+'_end'].value;
	end_secs = HMStoSec1 (end_h+f.elements['minute_'+serial_num+'_end'].value+':00');
	
	duration_secs = end_secs - start_secs;
	hours = Math.floor(duration_secs/3600);
	minutes = (duration_secs % 3600)/60;
	if (duration_secs>0){
		f.elements['duration_'+serial_num].value=hours+'h '+minutes+'m';
	}else{
		alert('End time must be later than start time.');
		//bump_hour(f,serial_num);
	}
}

function HMStoSec1(T) { // h:m:s
  var A = T.split(/\D+/) ; return (A[0]*60 + +A[1])*60 + +A[2] }
  
  
function bump_minute(f,serial_num)  {
	f.elements['minute_'+serial_num+'_end'].value=f.elements['minute_'+serial_num].value;
	duration_calc (f,serial_num);
}

function eval_end_am(f,serial_num) {
		//alert ('eval_end_am');
		end_h = 'hour_'+serial_num+'_end';
		hour_num= +f.elements[end_h].value;
		end_am = 'morn_eve_'+serial_num+'_end';
		if(hour_num<12){
			f.elements[end_am].value='AM';
		}else{
			f.elements[end_am].value='PM';
		}	
}

function eval_am(f) {
		hour_num= +f.elements['hour'].value;
		if(hour_num<12){
			f.elements['morn_eve'].value='AM';
		}else{
			f.elements['morn_eve'].value='PM';
		}	
}
/* 

 */
 
function select_talent(el,this_value)  { 
	
	if(this_value == 99){
		el.disabled=false;
		el.size=16;
		el.className = 'field_select';
		alert ('You have selected "other...", please type a talent name.');
		el.focus();
	}else{
		el.value='';
		el.size=1;
		el.disabled=true;
		el.className = 'field_hide';
	}

} 
 
 
function  check_audition_form(this_form){

	if  (this_form.project.value.length == 0) { alert("Please enter a project name.");this_form.project.focus();return false;}
	
	// union validation
	//	union_selected = 0;
	//	for (i=0; i<this_form.union.length; i++) { 
	//		if (this_form.union[i].checked) {
	//				union_selected = 1;
	//			}
	//	}
	//	if  (union_selected==0) { alert("Is this a union job?  Please select the appropriate option.");this_form.project.focus();return false;}
	
	if  (this_form.time_zone_id.value == -1) { alert("Please enter a time zone.");this_form.time_zone_id.focus();return false;}
	if  (this_form.company.value.length == 0) { alert("Please enter a company name.");this_form.company.focus();return false;}
	
	var these_elements = new Array("company_fname","company_lname","company_phone");
//,"company_mobile"    ,"company_email","company_address_1","company_address_2" -- edit 010824 TAH
	if (validate_fancy_fields(this_form,these_elements,' company contact ')==false){return false;};
	
	// delivery_id validation
	
			for (i=0; i<this_form.delivery_id.length; i++) {
				if (this_form.delivery_id[i].checked) {
					if(this_form.delivery_id[i].value==6){  // if auditioning in person, validate location fields
						// removed 090915
						//var these_elements = new Array("location");
						// var these_elements = new Array("location_fname","location_lname","location_phone","location_email","location_address_1","location_address_2");
						// if (validate_fancy_fields(this_form,these_elements,' location contact ')==false){return false;};
						if  (this_form.location.value.length == 0) { alert("Please enter a Studio Name.");this_form.location.focus();return false;}
					}
				}
			}
 
	

	// if a talent 'other...' option has been selected and NO name was entered, alert
 	for (i=1; i<11; i++) {
		fname = 'talent_select_'+i;
		
		// if 'other' is selected
		if(this_form.elements[fname].value==99){
			
			fname = 'talent_write_in_'+i;
			el = this_form.elements[fname];
			
			// if the 'write-in' field has nothing in it
			if(el.value==''){
				// hilight the write-in field
				el.className = 'field_select';
				alert ('You have selected "other..." for this talent, please type a talent name.');
				el.focus();
				return false;
			}
		}
	}
	 
	/*	*/
	// everything that is required checks out, so zero the NOT required fancy fields.
	// elements that are NOT required
	not_required_elements = new Array("company_mobile",
										"location_fname","location_lname","location_phone","location_email"
										,"location_address_1","location_address_2");
	clear_these(this_form,not_required_elements);
	this_form.send.value = 'Sending... Please stand by!';
	//if(front){
		document.images['progress'].src='images/clock.gif';
	//}else{
		//document.images['progress'].src='../images/clock.gif';
	//}
	return true;  //    false
}

function validate_fancy_fields(this_form,these_elements,msg_header){
	for(var i=0; i<this_form.elements.length; i++){  // loop through the form elements check company
			el = this_form.elements[i];
			for(var j=0; j<these_elements.length; j++){ //find a matches on in this array
				if (these_elements[j] == el.name){
					init_text = this_form.elements[i+1].value; // hidden field just after contains default value
					clearme(el,init_text);
					if  (el.value.length == 0) { 
						alert("Please enter"+msg_header+init_text+".");
						el.focus();
						return false;
						break;}
					
					// validate email address
					if (el.name.indexOf('email')!=-1)
						{if(echeck(el.value)==false){
							alert("Please enter a valid"+msg_header+"email address.");
							el.focus();
							return false;
							break;}
						}
					
				}
			}
		}

}

function copy_company_to_signatory(this_form){
	//alert('yes');
	if(this_form.signatory_use_company.checked){
		this_form.signatory_company.value =this_form.company.value;
		this_form.signatory_fname.value = this_form.company_fname.value;
		this_form.signatory_lname.value = this_form.company_lname.value;
		this_form.signatory_phone.value = this_form.company_phone.value;
		this_form.signatory_address_1.value = this_form.company_address_1.value;
		this_form.signatory_address_2.value = this_form.company_address_2.value;
		
	}else{
		this_form.signatory_company.value = "[ company ]";
		this_form.signatory_fname.value = "[ first name ]";
		this_form.signatory_lname.value = "[ last name ]";
		this_form.signatory_phone.value = "[ phone ]";
		this_form.signatory_address_1.value = "[ address 1 ]";
		this_form.signatory_address_2.value = "[ address 2 ]";
	}
}

function copy_company_to_location(this_form){
	//alert('yes');
	if(this_form.location_use_company.checked){
		this_form.location.value =this_form.company.value;
		this_form.location_fname.value = this_form.company_fname.value;
		this_form.location_lname.value = this_form.company_lname.value;
		this_form.location_phone.value = this_form.company_phone.value;
		this_form.location_email.value = this_form.company_email.value;
		this_form.location_address_1.value = this_form.company_address_1.value;
		this_form.location_address_2.value = this_form.company_address_2.value;
		
	}else{
		this_form.location.value = "[ company ]";
		this_form.location_fname.value = "[ first name ]";
		this_form.location_lname.value = "[ last name ]";
		this_form.location_phone.value = "[ phone ]";
		this_form.location_email.value = "[ email ]";
		this_form.location_address_1.value = "[ address 1 ]";
		this_form.location_address_2.value = "[ address 2 ]";
	}
}

function validateNum(entry){
	if(Number(entry) && entry > 0 && entry < 100){return false}
		else{return true}
}
function validateNumErrorMsg(entry){
	if(Number(entry) && entry > 0 && entry < 100){return '';}
		else{return'A valid quantity is between 1 and 99.';}
}

function  check_booking_form(this_form){
	//alert('hold please');return false;

	if  (this_form.talent_select_1.value<1) { alert("Please select talent.");this_form.talent_select_1.focus();return false;}
		
	if  (this_form.talent_name_1.value == 'other...' & this_form.talent_write_in_1.value.length < 2) { 
		alert("Please type a talent or select one from the list.");this_form.talent_write_in_1.focus();return false;}
	if  (this_form.time_zone_id.value == -1) { alert("Please enter a time zone.");this_form.time_zone_id.focus();return false;}
	if  (this_form.project.value.length == 0) { alert("Please enter a project name.");this_form.project.focus();return false;}
	
	if  (this_form.booking_type_id_1.value < 0 & this_form.booking_type_id_2.value < 0 & this_form.booking_type_id_3.value < 0 & this_form.booking_type_id_4.value < 0 & this_form.booking_type_id_5.value < 0) { 
		alert("Please select at least one booking type.");this_form.booking_type_id_1.focus();return false;}
	
	if  (this_form.booking_type_id_1.value > 0 & validateNum(this_form.booking_type_quantity_1.value) ) { 
		alert("Please enter a '"+this_form.booking_type_name_1.value+"' quantity.\n\n"+validateNumErrorMsg(this_form.booking_type_quantity_1.value));
		this_form.booking_type_quantity_1.value='';
		this_form.booking_type_quantity_1.focus();return false;
	}
	
	if  (this_form.booking_type_id_2.value > 0 & validateNum(this_form.booking_type_quantity_2.value) ) { 
		alert("Please enter a '"+this_form.booking_type_name_2.value+"' quantity.\n\n"+validateNumErrorMsg(this_form.booking_type_quantity_2.value));
		this_form.booking_type_quantity_2.value='';
		this_form.booking_type_quantity_2.focus();return false;}
	
	if  (this_form.booking_type_id_3.value > 0 & validateNum(this_form.booking_type_quantity_3.value) ) { 
		alert("Please enter a '"+this_form.booking_type_name_3.value+"' quantity.\n\n"+validateNumErrorMsg(this_form.booking_type_quantity_3.value));
		this_form.booking_type_quantity_3.value='';
		this_form.booking_type_quantity_3.focus();return false;}
	
	if  (this_form.booking_type_id_4.value > 0 & validateNum(this_form.booking_type_quantity_4.value) ) { 
		alert("Please enter a '"+this_form.booking_type_name_4.value+"' quantity.\n\n"+validateNumErrorMsg(this_form.booking_type_quantity_4.value));
		this_form.booking_type_quantity_4.value='';
		this_form.booking_type_quantity_4.focus();return false;}
	
	if  (this_form.booking_type_id_5.value > 0 & validateNum(this_form.booking_type_quantity_5.value) ) { 
		alert("Please enter a '"+this_form.booking_type_name_5.value+"' quantity.\n\n"+validateNumErrorMsg(this_form.booking_type_quantity_5.value));
		this_form.booking_type_quantity_5.value='';
		this_form.booking_type_quantity_5.focus();return false;}
	
	//var signatory_elements = new Array("signatory_company","signatory_fname","signatory_lname","signatory_phone");
	//if (validate_fancy_fields(this_form,signatory_elements,' signatory ')==false){return false;};
	
	if  (this_form.company.value.length == 0) { alert("Please enter a company name.");this_form.company.focus();return false;}
	
	var company_elements = new Array("company_fname");
	if (validate_fancy_fields(this_form,company_elements,' company contact ')==false){return false;};
		 // moved these fields to NOT required (below) on 080331 March 31 2008
		 // ,"company_lname","company_phone","company_email","company_address_1","company_address_2"
		 
		 // delivery_id validation
	// Disabled delivery validation 090915
				for (i=0; i<this_form.delivery_id.length; i++) {
					if (this_form.delivery_id[i].checked) {
						if(this_form.delivery_id[i].value==6){  // if auditioning in person, validate location fields
							//alert('in person');
							//var these_elements = new Array("location_fname","location_lname","location_phone","location_email","location_address_1","location_address_2");
							//if (validate_fancy_fields(this_form,these_elements,' location contact ')==false){return false;};
							if  (this_form.location.value.length == 0) { alert("Please enter a Studio Name.");this_form.location.focus();return false;}
						}
					}
				}
	
	// everything that is required checks out, so zero the fancy fields that have non-default data.
	// elements that are NOT required
	// this is a combination of location and company elements.
	not_required_elements = new Array("signatory_company","signatory_fname","signatory_lname","signatory_phone","signatory_address_1","signatory_address_2","company_mobile","location_fname","location_lname","location_phone","location_email","location_address_1","location_address_2","company_lname","company_phone","company_email","company_address_1","company_address_2");
	clear_these(this_form,not_required_elements);
	
	this_form.send.value = 'Sending... Please stand by!';
	//if(front){
		//document.images['progress'].src='images/clock.gif';
	//}else{
		document.images['progress'].src='../images/clock.gif';
	//}

	if  (this_form.staff_notes){
		if  (this_form.staff_notes.value.length == 0) { alert("Please enter rate information.");this_form.staff_notes.focus();return false;}
	}
	
	return true;  //    false
}

function select_booking_type(el,this_value)  { 
	
	if(this_value == 99){
		el.disabled=false;
		el.size=16;
		el.className = 'field_select';
		alert ('You have selected "other...", please enter a booking type.');
		el.focus();
	}else{
		el.value='';
		el.size=1;
		el.disabled=true;
		el.className = 'field_hide';
	}

} 

function clear_these(this_form,these_elements) {
	for(var i=0; i<these_elements.length; i++){
		el = this_form.elements[these_elements[i]];
		init_text = this_form.elements[these_elements[i]+'_default'].value;
		clearme(el,init_text);
	}
}

function  check_my_account_form(el){
	/*	*/

	if (el.pass_1.value != el.pass_2.value) { alert("These passwords do not match.");el.pass_1.focus();return false;}
	
	if (el.pass_1.value.length > 0) { 
		if (el.pass_1.value.length < 4) {
			alert("Password must be at least 4 characters long.");el.pass_1.value = '';el.pass_2.value = '';el.pass_1.focus();return false;}
		if (el.pass_1.value.length > 12) { 
			alert("Password must be less than 12 characters long.");el.pass_1.value = '';el.pass_2.value = '';el.pass_1.focus();return false;}
	}

	if (el.uname.value == '') { alert("Please enter a user name.");el.uname.focus();return false;}
	if (el.fname.value == '') { alert("Please enter your first name.");el.fname.focus();return false;}
	if (el.lname.value == '') { alert("Please enter your last name.");el.lname.focus();return false;}
	if (el.company.value == '') { alert("Please enter your company name.");el.company.focus();return false;}
	if (el.phone.value == '') { alert("Please enter your phone number.");el.phone.focus();return false;}
	//if (el.mobile.value == '') { alert("Please enter your mobile number.");el.mobile.focus();return false;}
	if (echeck(el.email.value)==false){ alert("Please enter a valid email address.");el.email.focus();return false;}
	if (el.address_1.value == '') { alert("Please enter the first line of your address.");el.address_1.focus();return false;}
	if (el.address_2.value == '') { alert("Please enter your the second line of your address.");el.address_2.focus();return false;}

	return true;  //    false
}




function validate(this_form,params)
	{
	//sArray = this_form.name.split("_");
	this_function = 'check_'+this_form.name;
	//alert (this_function);

	if(this_form.name=='scratch_form'){this_function = 'check_audition_form';}
	//alert(this_function);
	//alert(params);
	debug = 0;
	if(debug){
		alert('validation is off');
		this_form.action = params;
		this_form.submit();
		}
	else{
		//alert (this_function);
		if(eval(this_function)(this_form)){
			this_form.action = params;
			//alert (this_form.action);
			this_form.submit();
		}
	}
	}

function go(where){
	//alert(where);
	if(where==-1){
		history.go(-1);
	}else{
		location.href=where;
	}
}
// when isdn, pp or audition in person is selected, turn on appropriate elements
// otherwise, turn off
function location_toggle(this_form,turn_on){

	var loc_elements = "location,location_fname,location_lname,location_phone,location_email,location_address_1,location_address_2";

	if(turn_on){
		//alert('on');
		this_form.elements['location_label'].className='field_label_sm';
		// alert(this_form.elements['location_label'].className);
		this_form.elements['contact_label'].className='field_label_sm';
		
		for(var i=0; i<this_form.elements.length; i++){
			el = this_form.elements[i];
			if (loc_elements.indexOf(el.name)!=-1){
				el.disabled=false;
				el.className='field';
				
				if (this_form.elements[i+2].value==''){    // no session data
					el.value=this_form.elements[i+1].value;  // hidden field just after contains default value
					//alert (this_form.elements[i+1].value+' first');
				}else{
					
					el.value=this_form.elements[i+2].value;  // in case there IS session information, hidden field +2
					//alert (this_form.elements[i+2].value+' second');
				}
				
			}
			
		}
		//alert(el.name);
		//alert(this_form.elements['location_label'].className);

	}
	
	else{
		//alert('off');
		for(var i=0; i<this_form.elements.length; i++){
			el = this_form.elements[i];
			if (loc_elements.indexOf(el.name)!=-1){
				el.value='';
				el.disabled=true;
				el.className='field_hide';
			}
		}
		this_form.elements['location_label'].className='field_label_sm_hide';
		this_form.elements['contact_label'].className='field_label_sm_hide';
	}
}

function location_remind(this_form){
	alert('Please fill in the Studio information.');
	this_form.elements['location'].className = 'field_select';
	this_form.elements['location'].focus();
}
function location_remind_alt(this_form,which){
	alert('If you are not using Talent Home Studio for '+which+', please fill in the Studio information.');
	this_form.elements['location'].className = 'field_select';
	this_form.elements['location'].focus();
}


// when required (audition in person, etc.), turn on appropriate elements
// otherwise, turn off
function time_toggle(this_form,turn_on,label){ 

	if(turn_on){
		
		this_id = 0;
		last_id = 0;
		this_talent_id = -1;
		at_least_one_talent_active = 0;
		
		// cycle through all of the talent entries
		for(var i=0; i<this_form.elements.length; i++){
			el = this_form.elements[i];
			
			// get the id number for this group
			//is there more than one underscore?
			if (el.name.indexOf('talent')!=-1) {
				this_val = el.name.substring( (el.name.lastIndexOf("_")+1), el.name.length);
				this_id = +this_val;
				if (this_id>last_id){
					//alert(this_id+' talent id:'+el.value);
					this_talent_id = +el.value;
					last_id = this_id;
					//calculate duration
				}
			}
			
			if ( (this_talent_id>0) && ((el.name.indexOf('hour')!=-1) || (el.name.indexOf('minute')!=-1) ) ){
					el.disabled=false;
					el.className='select';
					at_least_one_talent_active = 1;
			}
			if ( (this_talent_id>0) && (  (el.name.indexOf('duration')!=-1) || (el.name.indexOf('morn_eve')!=-1)  ) ){
					el.className='field_read_only';
			}
		}
		
		if(at_least_one_talent_active && label){
			this_form.elements['start_time_label'].className='field_label';
			this_form.elements['end_time_label'].className='field_label';
			this_form.elements['duration_label'].className='field_label';
			}
	}
	
	else{
		
		for(var i=0; i<this_form.elements.length; i++){
			el = this_form.elements[i];
			
			if ( (el.name.indexOf('hour')!=-1) || (el.name.indexOf('minute')!=-1) ){
				el.disabled=true;
				el.className='field_hide'; 
				
			}
			if (  (el.name.indexOf('duration')!=-1 && el.name.indexOf('booking_type')!=-1 ) || (el.name.indexOf('morn_eve')!=-1) 
					|| (el.name.indexOf('start_time_label')!=-1) || (el.name.indexOf('end_time_label')!=-1) || (el.name.indexOf('duration_')!=-1)  ){
				el.className='field_read_only_hide';
			}
		}

		// 
		//this line doesn't work for the admin.  couldn't get isDefined to work, but must
		//if(label)this_form.elements['start_time_label'].className='field_read_only_hide';
		//if(label)this_form.elements['end_time_label'].className='field_read_only_hide';
		//if(label)this_form.elements['duration_label'].className='field_read_only_hide';
		//alert('ttttttttttt');
	}
	
}

function get_selected_radio(this_form){
		for (i=0; i<this_form.delivery_id.length; i++) {
			if (this_form.delivery_id[i].checked) {
				return(this_form.delivery_id[i].value);
			}
		}
		return -1;
}

function activate_times(this_form,talent_num,selected_talent_id,label){
	//alert(selected_talent_id);
	//alert('activating times');
	if (get_selected_radio(this_form) > 3 || get_selected_radio(this_form) == 1) {   
		// only for the last three delivery options AND the first (FTP)
	
		var hm_elements = new Array('hour_'+talent_num,'hour_'+talent_num+'_end','minute_'+talent_num,'minute_'+talent_num+'_end');
		
		if(selected_talent_id>1){
			for(var i=0; i<hm_elements.length; i++){
				el = this_form.elements[hm_elements[i]];
				el.disabled=false;
				el.className='select';
			}
				
			this_form.elements['duration_'+talent_num].className='field_read_only'; 
			this_form.elements['morn_eve_'+talent_num].className='field_read_only'; 
			this_form.elements['morn_eve_'+talent_num+'_end'].className='field_read_only';
			if(label)this_form.elements['start_time_label'].className='field_label';
			if(label)this_form.elements['end_time_label'].className='field_label'; 
			if(label)this_form.elements['duration_label'].className='field_label';  
			//alert(label);
			
		}else{
			//alert(selected_talent_index);
			for(var i=0; i<hm_elements.length; i++){
				el = this_form.elements[hm_elements[i]];
				el.disabled=true;
				el.className='field_hide';
			}
			
			this_form.elements['duration_'+talent_num].className='field_read_only_hide'; 
			this_form.elements['morn_eve_'+talent_num].className='field_read_only_hide'; 
			this_form.elements['morn_eve_'+talent_num+'_end'].className='field_read_only_hide';
		}
	}
	// alert('activated times');
}

				
function activate_notification(this_form,talent_num,selected_talent_id,is_booking){
	//alert(this_form);
	//alert('activating notification');
	
	
	//alert(this_form.name);
	//is_booking = this_form.name.indexOf('audition')!=-1;
	
	these_labels = new Array('notified_talent_by_email_'+talent_num,'label_notify_talent_by_email_'+talent_num,
							   'label_notified_talent_by_phone_'+talent_num,'label_calendared_'+talent_num,
							   'label_delivered_'+talent_num);
							   
	these_fields = new Array('notify_talent_by_email_'+talent_num,
						   'notified_talent_by_phone_'+talent_num,'calendared_'+talent_num,
						   'delivered_'+talent_num);
	
	if(is_booking){
		//alert(is_booking);
		these_labels[these_labels.length]='notify_agent_by_email_'+talent_num;
		these_labels[these_labels.length]='notified_agent_by_email_'+talent_num;
		these_fields[these_fields.length]='notify_agent_by_email_'+talent_num;
	}else{
		these_labels[these_labels.length]= 'label_got_the_job_'+talent_num;
		these_fields[these_fields.length]= 'got_the_job_'+talent_num;
	}
					   
	//if(is_booking){
		//these_fields[]='notify_agent_by_email_'+talent_num;
	//}
	
	if(selected_talent_id>1){
		
		for(var i=0; i<these_labels.length; i++){
			el = this_form.elements[these_labels[i]];
			el.className='field_read_only';
		}	
		for(var i=0; i<these_fields.length; i++){
			el = this_form.elements[these_fields[i]];
			el.disabled=false;
		}	
		
		if(is_booking){
			//this_form.elements['agent_email_type_'+talent_num][0].disabled = false;		
			//this_form.elements['agent_email_type_'+talent_num][1].disabled = false;		
		}

		//alert(label);
		
	}else{
		for(var i=0; i<these_labels.length; i++){
			el = this_form.elements[these_labels[i]];
			el.className='field_read_only_hide';
		}	
		for(var i=0; i<these_fields.length; i++){
			el = this_form.elements[these_fields[i]];
			el.disabled=true;
		}	
		
		if(is_booking){
			this_form.elements['agent_email_type_'+talent_num][0].disabled = true;		
			this_form.elements['agent_email_type_'+talent_num][1].disabled = true;		
		}

	}
	
	//alert('activated notification');
}

function format_toggle(this_form,turn_on){
	
	these_elements = new Array('ftp_server_id','format_id','frequency_id');
	//alert (this_form);
	if(turn_on){
		for(var i=0; i<these_elements.length; i++){
			el = this_form.elements[these_elements[i]];
			//el = document.forms[this_form_name].elements[these_elements[i]];
			el.disabled=false;
			el.className='select';
		}
	}
	else{
		//alert(this_form);
		for(var i=0; i<these_elements.length; i++){
			el = this_form.elements[these_elements[i]];
			//el = document.forms[this_form_name].elements[these_elements[i]];
			el.disabled=true;
			el.className='field_hide';
		}
	}
}

function checkbox_toggle(this_form,form_name_prefix,turn_on){
//alert (form_name_prefix);
	if(turn_on){
		for (i=1; i<11; i++) {
			fname = 'talent_select_'+i;
			el = this_form.elements[fname];
			// if the talent select has a value, turn it on
			if(el.value>0){
				fname = form_name_prefix+i;
				el = this_form.elements[fname];
				el.checked=true;
			}
		}
		
	}else{  // turn off
		for (i=1; i<11; i++) {
				fname = form_name_prefix+i;
				el = this_form.elements[fname];
				el.checked=false;
		}
	}
}

function billing_options(this_form,my_val){
	//alert(my_val);
	if(my_val){
		//turn on the labels, make the fields active, if there was an existing value diplay it
		this_form.elements['sent_bill'].disabled = false;		
		this_form.elements['payment_received'].disabled = false;	
		this_form.elements['label_sent_bill'].className='field_read_only'; 	
		this_form.elements['label_payment_received'].className='field_read_only'; 	

	}else{  // turn off
		this_form.elements['sent_bill'].disabled = true;		
		this_form.elements['payment_received'].disabled = true;	
		this_form.elements['label_sent_bill'].className='field_read_only_hide'; 
		this_form.elements['label_payment_received'].className='field_read_only_hide'; 		
	}
}

function notify_staff(this_form){
	//alert(my_val);
	if(this_form.elements['bill_company'].checked == true || this_form.elements['bill_talent'].checked == true){
		this_form.elements['staff_email_notification'].checked=true;		
	}else{
		this_form.elements['staff_email_notification'].checked=false;	
	}
}

function clearme(fe,txt){
		// check to see that the form element is the default text
		if (fe.value == txt){
			// clear the default text
			fe.value = "";
		}
		return;
	}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


