function Reorder(frm, func, dir, index) {		

	if(dir == -1) 
		index2 = index - Number(1); 
	else 
		index2 = index + Number(1);
	
	frm.reorder_index1.value = index;
	frm.reorder_index2.value = index2;
	frm.task.value = 'ordering';
	eval(func);
}

/**************************************************************************/
/////////// TAX BUILDER FUNCTIONS START ///////////
function addElm(name, elm, elm_type) {
var x, current_x;

	current_x = -1;
	x = -1;
	if(his.length > 0)
		for(x = 0; x < his.length; x++) {
			if(his[x][0] == name) {
				current_x = x;
				break;
			}
		}
	if(current_x == -1) {
		current_x = x+1
		his[current_x] = new Array();
		his[current_x][0] = name;
		his[current_x][1] = -1;
		his[current_x][2] = new Array();
		his[current_x][5] = new Array();
		his[current_x][3] = document.getElementById(name).value;
		his[current_x][4] = (document.getElementById(name).value == '='?'O':'V');
			
	}

	if(elm_type != '=') {
		if(his[current_x][1] == -1) {
			if(his[current_x][4] == elm_type) {
				alert(alert_message);
				return false;
			}
		} else if(his[current_x][5][his[current_x][1]] == elm_type){
			alert(alert_message);
			return false;
		}
	} else {
		document.getElementById(name).value = '';
		elm_type = 'O';
	}

	document.getElementById(name).value += elm;

    his[current_x][1]++; 
    his[current_x][2][his[current_x][1]] = document.getElementById(name).value;
	his[current_x][5][his[current_x][1]] = elm_type;
    for(x = his[current_x][1]+1; x < his[current_x][2].length; x++) {
        his[current_x][2][x] = null; 
		his[current_x][5][x] = null;
	}
}

function undoFormula(name, type) {
var x, current_x;
 
    current_x = -1;
    for(x = 0; x < his.length; x++) {
        if(his[x][0] == name) {
            current_x = x;
            break;
        } 
    }
    if(current_x == -1)
		return false;

	if(type == 'R') {
		if((his[current_x][1]+1) < his[current_x][2].length)
			his[current_x][1]++;
	} else if(his[current_x][1] > -1)
		his[current_x][1]--;

	document.getElementById(name).value = ((his[current_x][1] == -1)?his[current_x][3]:his[current_x][2][his[current_x][1]]);
}

function checkFormula(name) {
var x, current_x;

	current_x = -1;
	x = -1;
	if(his.length > 0)
		for(x = 0; x < his.length; x++) {
			if(his[x][0] == name) {
				current_x = x;
				break;
			}
		}
	if(current_x == -1) {
		current_x = x+1
		his[current_x] = new Array();
		his[current_x][0] = name;
		his[current_x][1] = -1;
		his[current_x][2] = new Array();
		his[current_x][5] = new Array();
		his[current_x][3] = document.getElementById(name).value;
		his[current_x][4] = (document.getElementById(name).value == '='?'O':'V');
			
	}

	if(his[current_x][1] == -1) {
		if(his[current_x][4] == 'O') {
			alert(alert_message);
			return false;
		}
	} else if(his[current_x][5][his[current_x][1]] == 'O'){
		alert(alert_message);
		return false;
	}
	return true;
}

function clearFormula(name) {
var x, current_x;

	current_x = -1;
	x = -1;
	if(his.length > 0)
		for(x = 0; x < his.length; x++) {
			if(his[x][0] == name) {
				current_x = x;
				break;
			}
		}

	if(current_x != -1)
		document.getElementById(name).value = his[current_x][3];
}
/////////// TAX BUILDER FUNCTIONS END ///////////
/**************************************************************************/

// fck editor
function get_ed_text(editor_name){
   	var oEditor = FCKeditorAPI.GetInstance(editor_name) ;
   		if (oEditor.EditorDocument.body.innerHTML) { 
       	return oEditor.EditorDocument.body.innerHTML;
   	}
   	else return '';
}
function changeLang(lang){
	window.location.href = 'http://'+lang.value+'/';
}

// Calender script
function showCalendar(id) {
	var el = document.getElementById(id);
	//alert(el.name);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		calendar.create();		// create a popup calendar
		calendar.parseDate(el.value); // set it to a new date
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}
// End Calender