function copy_contents(copyfrom, copyto){//function to dump the contents of one field into another
	document.getElementById(copyto).value = document.getElementById(copyfrom).value; 
}

function copy_dropdown(copyfrom, copyto){//function o copy the selected index in one drop down to another
	document.getElementById(copyto).selectedIndex = document.getElementById(copyfrom).selectedIndex; 
}

function configure_add_category_buttons(number_of_categories, maximum_number,button_name){//function for controlling the hiding and showing of the add and remove photographer category buttons

	if(document.getElementById(number_of_categories).value==maximum_number){//if the maximum number of categories is displayed, hide the buton for adding more
			document.getElementById(button_name).className="hidden";
			
	}else{//otherwise, show it
		document.getElementById(button_name).className="submit-button";
	
		if(document.getElementById(number_of_categories).value >0){
		
			document.getElementById(button_name).value = "Add another";
			
		}
	}
}

function show_uploading() {
	document.getElementById('competition-submit').style.display = 'block';
	document.getElementById('competition_entry_form').style.display = 'none';
}

function validate() {
	
	errors = 0;
	
	for (var i = 0; i < arguments.length; i++) {
		var lbl = document.getElementById(arguments[i]+'-note');
		lbl.className = 'required';
		lbl.innerHtml='';
	}
	
	for (var i = 0; i < arguments.length; i++) {
		var lbl = document.getElementById(arguments[i]+'-note');
		if(document.getElementById(arguments[i]).value == '') {
			lbl.innerHtml= '';
			lbl.className = 'required-failed';
			errors++;
		}
	}
	if(errors > 0) {
		alert('Please ensure you have filled in all required fields');
		return false;
	}
	return true;
}

function give_focus(element){
	this.document.getElementById(element).className = "form-focused";
}

function take_focus(element){
	this.document.getElementById(element).className = "input";
}

function strip_contents(element){
	this.document.getElementById(element).value = "";
}

function validate_business_category_selection(max) {
//function for validating the business category drop down menus. User must select at least one..
	ok = false;

	for(i=1;i<=max;i++){
		//alert(i);
		element = 'photographic_supplier_category_' + i;
		if(document.getElementById(element).value!=""){
			ok = true;
		}
	}
		if(ok==false){
			document.getElementById('photographic_supplier_category-note').className = 'required-failed';
		}else{
			document.getElementById('photographic_supplier_category-note').className = 'note';
		}	
	return ok;
}


function validate_photographer_category_selection(max) {
	ok = false;
	for(i=1;i<=max;i++){
		element = 'photographer_category_id_' + i;
		if(document.getElementById(element).value!=""){
			ok = true;
		}
	}
		if(ok==false){
			document.getElementById('photographer_category-note').className = 'required-failed';
		}else{
			document.getElementById('photographer_category-note').className = 'note';
		}	
	return ok;
}

$(function()
{
	$('.date-pick').datePicker()
	$('#start-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#end-date').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#end-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#start-date').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
});