function check_field(type, id){
	var result = true
	if(type == 'num'){
		lastChar = $F(id).charAt($F(id).length-1)
		if(isNaN(lastChar)){
			if(lastChar != '.'){
				$(id).value = $(id).value.substring(0, $F(id).length-1)
				result = false
				return result
				
			}
			else{
				result = true
				return result	
			}
		}
	}
	else if(type == 'email'){
		if($F(id).length !== 0){
			if($F(id).search('@') == -1){
				alert('This must contain an email address')
				$(id).style.border = '1px solid red'
				return false
			}
			else{
				$(id).style.border = ''
				return true
			}
		}
		else{
			$(id).style.border = ''

			return true
		}
	}
}

////////////////////////
function blind(ele){
	Effect.toggle(ele,'slide', {duration:0.3})
}
///////////////////////
function validate_form(id, form, submit_frm){
	var submit_frm = (submit_frm == null) ? true : submit_frm;
	var id_array = id.split("|");
	var valid = true
	var id_array_l = id_array.length
	for(i=0; i <id_array_l; i++){
		var fld = id_array[i]
		var val = $(fld).value
		if(val == '' || val == null){
			$(fld).style.border = '1px solid red'
			valid = false
		}
		else{
			$(fld).style.border = '1px solid green'
		}
	}
	if(!valid){
		alert('Please fill in required fields')
		return false
	}
	else{
		if(submit_frm){
			$(form).submit()
		}
		else{
			return true
		}
		
	}
}
///////////////////////
function rand_no(){
	var rand  = parseInt(Math.random()*99999);
	return rand	
}
 // register event listeners on the Ajax requests to show/hide the processing indicator
 Ajax.Responders.register({
    onCreate: function() {
  if (Ajax.activeRequestCount === 1) {
    $('loading').show();
   }
    },
    onComplete: function() {
   if (Ajax.activeRequestCount === 0) {
    $('loading').hide();
   }
    }
 });
 
 /////////////////////
function create_timeout(time, function_name){
	timeout = window.setTimeout(function_name, time)
}
//////////////////////
function display_added(){
	blind('added')
	create_timeout(3000, "blind('added')")
}


////// Observers

// Set Nav Height
//Event.observe(window, 'load', set_nav_height);

function set_nav_height(){
	$('nav').style.height = (Element.getHeight($('main_window'))) - 40
}


