// insert only site special scripts not global scrips
// if you use the script in only one page write it as remark

// admin.tpl section=admin module=online-admin
function levelChanged(obj)
{
	var form = obj.form;
	var val = obj.options[obj.selectedIndex].value;
	var otr = (val == 2) ? 1 : 2;
	
	_('frm_termlessonid_'+val)[0].style.display = '';
	_('frm_teacherid_'+val)[0].style.display = '';
	_('frm_termlessonid_'+otr)[0].style.display = 'none';
	_('frm_teacherid_'+otr)[0].style.display = 'none';
}

// front->global_modules
function showDetail(ObjId, module)
{
	nw = window.open("front.php?section=guest&module="+module+"&frm_id="+ObjId, "Book_Detail", "width=500,height=350,toolbar=no,scrollbars=yes,status=no,menubar=no,resizable=yes");
	nw.focus();
}

// lesson-admin
function setTend(obj)
{
	var res = getAllChilds(obj.parentNode.parentNode);
	for(var i=0; i<res.length; i++){
		if(res[i].name == "frm_tendid[]"){
			res[i].checked = obj.checked;	
		}
	}
}

// lesson-admin
function checkTend(obj)
{
	var res = getAllChilds(obj.parentNode.parentNode);
	var flag_and = true;
	for(var i=0; i<res.length; i++){
		if(res[i].name == "frm_tendid[]"){
			flag_and &= res[i].checked;
		}
		if(res[i].tagName == "INPUT" && res[i].name==""){
			var chk = res[i];
		}
	}
	if(chk){
		chk.checked = flag_and;
	}
}

function openBasket(id, newWindow, frm_id, popup)
{	
	if(id) {
		var obj = (typeof(id)=='object') ? id : document.forms[id];
		var ch;
		var query = '';
		for(var i=0; i<obj.elements.length; i++) {
			ch = obj.elements[i];
			if(ch.checked && ch.name){
				query += "&"+ch.name+"=1";
			}
		}
	}
	query = 'front.php?section=user&module=basket&cmd=add&popup='+popup+'&frm_userid='+frm_id+'&'+query;
	if(newWindow){
		openNewWindow(query, 600, 410);
	} else {
		document.location.href=query;
	}
}

function addExamRow()
{
	var cnt = 1;
	var obj;
	while(obj = findObject('adminRow_'+cnt)) {
		if(obj.style.display=="none") {
			obj.style.display="";
			return;
		}
	}
}

function setPayMethod(obj)
{
	pm = findObject('payMethod');
	pmch = getAllChilds(pm);
	for(var i=0; i<pmch.length; i++) {
		if(pmch[i].tagName=='TD') {
			pmch[i].style.background = "#FFFFFF;";
		}
	}
	
	pmch = getAllChilds(obj.parentNode.parentNode);
	for(i=0; i<pmch.length; i++) {
		if(pmch[i].tagName=='TD') {
			pmch[i].style.background = "#FFFFE5;";
		}
	}
	
	var id = obj.id.replace(/PayRadio/, '');
	var tbl;
	for(i=1; i<=3; i++){
		if(tbl = $('tbl'+i)){
			tbl.style.display= (id==i)?'table':'none';
		}
	}	
}

function showPayInformation(type){
	switch(type){
		case 'credit':
			document.getElementById('tblcredit').style.display = 'inline';
			document.getElementById('credittd').style.backgroundColor = '#FFFFE5';
			document.getElementById('tblreceipt').style.display = 'none';
			document.getElementById('receipttd').style.backgroundColor = '#FFFFFF';
			break;
		
		case 'receipt':
			document.getElementById('tblreceipt').style.display = 'inline';
			document.getElementById('receipttd').style.backgroundColor = '#FFFFE5';
			if(document.getElementById('tblcredit')){
				document.getElementById('tblcredit').style.display = 'none';
				document.getElementById('credittd').style.backgroundColor = '#FFFFFF';
			}
			break;
	}
}

