function submitbutton(pressbutton) {
	var form = document.adminForm;
    if(pressbutton == 'apply' || pressbutton == 'save'){
        // check require
    }
    form.task.value = pressbutton;
    form.submit();
	
}

function tableOrdering( order, dir, task ) {

    var form = document.adminForm;
    
    var url = location.href;
    pos = url.indexOf('#');
	if(pos > 0) {
		queryStr = url.substr(pos);
	}else {
		queryStr = '';
	}
	
	form.filter_order.value     = order;
    form.filter_order_Dir.value    = dir;
    form.task.value = task;
    form.action = form.action + queryStr;
 
    form.submit();
}

function listItemTask( id, field, task ) {
    var f = document.adminForm;
        
        f.cids.value = id;
        f.boxcheck.value = 1;
        f.task.value = task;
        f.field.value = field;
        
     	if(field == 'is_starred')
     	{
            var strTask = "starred";
            
	        if(task == 'activate')
	        	strTask = "starred";
	        else
	        	strTask = "unstarred";
            
	        try{
		        var url ='index.php?option=com_jajobboard&view=jashortlist&table_name=' + table_name +'&tmpl=component&task=' + strTask + '&cid[]=' + id + '&Itemid=' + Itemid;
				
		        var req = new Ajax(url, {
					method: 'get',
					update: $('log')
				});
				
				req.request();			
				
				var iconActive = '';
				var strOnclick = '';
				if(task == 'activate')
				{
					iconActive = siteurl + '/components/com_jajobboard/images/unstar.png';			
					strOnclick =  "listItemTask('" + id + "','is_starred','inactivate')";
				}else
				{
					iconActive = siteurl + '/components/com_jajobboard/images/star.png';					
					strOnclick =  "listItemTask('" + id + "','is_starred','activate')";
				}			
				$('img_' + id).src = iconActive;
				$('hrf_' + id).onclick = new Function(strOnclick);
				
	        }catch(err)
	        {
	        	alert(err);
	        }
     	}
     	else
     	{
     		 f.submit();
     	}                  
}

function show_edit_note(item_id)
{
	
	edit_div = $('edit_note_'+item_id);
	edit_div.setStyle('display','block');
	view_div = $('view_note_'+item_id);
	view_div.setStyle('display','none');
	edit_button_div = $('div_edit_button_'+item_id);
	edit_button_div.setStyle('display','block');
	view_button_div = $('div_view_button_'+item_id);
	view_button_div.setStyle('display','none');
}
function save_note(item_id, user_id, note_type)
{
	var url = 'index.php?option=com_jajobboard&view=janotes&task=ajax_save&user_id=' + user_id + '&note_type='+note_type+'&item_id='+item_id+'&&description=' + $('description_'+item_id).value;
	new Ajax(url, {method:'get', onComplete:update_saved_note}).request();	
}

function update_saved_note(text)
{
	item_id = text.substring(0,text.indexOf('_'));
	description = text.substring(text.indexOf('_')+1,text.length);
	edit_div = document.getElementById('edit_note_'+item_id);
	view_description_note = document.getElementById('view_description_'+item_id);
	view_description_note.innerHTML = description;
	edit_div.setStyle('display','none');
	view_div = document.getElementById('view_note_'+item_id);
	view_div.setStyle('display','block');
	edit_button_div = document.getElementById('div_edit_button_'+item_id);
	edit_button_div.setStyle('display','none');
	view_button_div = document.getElementById('div_view_button_'+item_id);
	view_button_div.setStyle('display','block');
	div_addnote_button = document.getElementById('div_addnote_button_' + item_id);
    div_addnote_button.setStyle('display','none');
}

function cancel_note(item_id){
	if($('description_' + item_id).value==''){
		$('add_note_' + item_id).setStyle( 'display', 'none');
	}
	else{
		edit_div = document.getElementById('edit_note_'+item_id);
		edit_div.setStyle('display','none');
		view_div = document.getElementById('view_note_'+item_id);
		view_div.setStyle('display','block');
		edit_button_div = document.getElementById('div_edit_button_'+item_id);
		edit_button_div.setStyle('display','none');
		view_button_div = document.getElementById('div_view_button_'+item_id);
		view_button_div.setStyle('display','block');
	}
}

function check_list(max)
{
	for (i=0;i<max;i++)
	{	
		cb_obj = document.getElementById('cb'+i);
		if (cb_obj.checked)
			return true;
	}
	return false;
}    

var boxfx;

function jalist_show_box_action(obj){
	if(obj.checked){
		if (!boxfx){
			boxfx = new Fx.Style($('ja-box-action'), 'bottom', {duration:300});
		}
		boxfx.stop();
		boxfx.start(0);
	}
	else if($('boxchecked').value==0){
		if (!boxfx){
			boxfx = new Fx.Style($('ja-box-action'), 'bottom', {duration:300});
		}
		boxfx.stop();
		boxfx.start(-60);
	}
	if (obj.name!='toggle')
		$('count-selection').innerHTML = $('boxchecked').value;
	else
	{
		if (obj.checked)
		{
			if (parseInt($('limit').value)>parseInt($('total_item').value))
			{
				var number_selected_item = $('total_item').value;
				
			}
			else
			{
				var number_selected_item = $('limit').value;
				
			}
			$('count-selection').innerHTML = number_selected_item;
			$('boxchecked').value = number_selected_item;
			if (!boxfx){
				boxfx = new Fx.Style($('ja-box-action'), 'bottom', {duration:300});
			}
			boxfx.stop();
			boxfx.start(0);
		}
		else
		{
			$('count-selection').innerHTML = 0;
			$('boxchecked').value = 0;
			if (!boxfx){
				boxfx = new Fx.Style($('ja-box-action'), 'bottom', {duration:300});
			}
			boxfx.stop();
			boxfx.start(-60);
		}
	}
	
}

function updateselectedjobs(obj){
	if (!obj.checked){
		$('li_'+obj.value).removeClass('selected');
//		obj.checked = false;
	}
	else{
		$('li_'+obj.value).addClass('selected');
//		obj.checked = true;
	}
	
	$('selectedJobs').value = $('boxchecked').value + ' ' + select_text;
	$('selectedJobs2').value = $('boxchecked').value + ' ' + select_text;
}

function updateselectalljobs(obj,num_obj){
	
	for (i=0;i<num_obj;i++)
	{
		updateselectedjobs($('cb'+i));
	}
	$('selectedJobs').value = $('boxchecked').value + ' ' + select_text;
	$('selectedJobs2').value = $('boxchecked').value + ' ' + select_text;
}

function submit_searchform(pressbutton)
{
	form = document.adminForm;
	if (pressbutton == 'search')
		form.submit();
	else
	{
		form.filter_title.value='';
		form.filter_created_date.value='';
		form.filter_education.value='';
		form.filter_location_id.value='';
		form.submit();
	}
}

function child_selection(obj,obj_option)
{
	var inc_array = new Array(obj_option.value);
	
if (obj_option.selected)	
	for (i=0;i<obj.options.length;i++)
	if (in_array(obj.options[i].value,inc_array))
	{
		if (obj.options[i].selected)
		{
			if (obj.id=='location_id')
			{
				if (child_location_id[obj.options[i].value])	
					for (k=0;k<child_location_id[obj.options[i].value].length;k++)
						for (ii=i+1;ii<obj.options.length;ii++)
							if (obj.options[ii].value==child_location_id[obj.options[i].value][k])
							{
								obj.options[ii].selected = true;
								inc_array[inc_array.length] = obj.options[ii].value;
							}
			}
			else
			{
				if (child_cat_id[obj.options[i].value])	
					for (k=0;k<child_cat_id[obj.options[i].value].length;k++)
						for (ii=i+1;ii<obj.options.length;ii++)
							if (obj.options[ii].value==child_cat_id[obj.options[i].value][k])
							{
								obj.options[ii].selected = true;
								inc_array[inc_array.length] = obj.options[ii].value;
							}
			}
		}
	}

}
function in_array(ele, inc_array)
{
	for (x in inc_array)
		if (inc_array[x]==ele)
			return true;
	return false;	
}
function cal_number_selection(field_name,child_array)
{
	sum_selection = 0;
	obj = document.getElementById(field_name);
	if (obj)
	for (i=0;i<obj.options.length;i++)
	{
		if (!check_exist_child(child_array,obj.options[i].value)&&obj.options[i].selected)
			sum_selection++;
	}
	return sum_selection;
	
}
function check_exist_child (child_array,ele)
{
	if (child_array[ele])
		return true;
	else
		return false;
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function  moveContent(objID){
	eleID = objID.indexOf('-');
	eleID = objID.substring(0,eleID);
	var content =  tinyMCE.activeEditor.getContent({format : 'raw'});
	$(eleID).value = content;
	
}
