function redir(page) {
	window.location=page;
}
function change(id, state) {
	var agt=navigator.userAgent.toLowerCase();

	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
    
	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie3    = (is_ie && (is_major < 4));
	var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
	var is_ie4up  = (is_ie && (is_major >= 4));
	var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
	var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
	var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
	var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
	var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

	if (state) {
		document.getElementById(id).style.display=state;
	}
	else {
		if (document.getElementById(id).style.display=='none') {
			if (is_ie5up) document.getElementById(id).style.display ='block';
			else document.getElementById(id).style.display ='table-cell';
		}
		else document.getElementById(id).style.display='none';

		document.cookie = id+"="+document.getElementById(id).style.display+""+"; path=/";
	}
}

function duplicateHTML(copy,paste,baseid){
	if(document.getElementById(copy)){
		var e107_dupCounter = 1;
		e107_dupCounter++;
		var type = document.getElementById(copy).nodeName; // get the tag name of the source copy.
		var but = document.createElement('input');
		var br = document.createElement('br');
		but.type = 'button';
		but.value = 'x';
		but.className = 'button';
		but.onclick = function(){ this.parentNode.parentNode.removeChild(this.parentNode); };
		var destination = document.getElementById(paste);
		var source      = document.getElementById(copy).cloneNode(true);
		var newentry = document.createElement(type);
		newentry.appendChild(source);
		newentry.value='';
		newentry.appendChild(but);
		newentry.appendChild(br);
		if(baseid)
		{
			newid = baseid+e107_dupCounter;
			newentry.innerHTML = newentry.innerHTML.replace(new RegExp(baseid, 'g'), newid);
			newentry.id=newid;
		}
		destination.appendChild(newentry);
	}
}
function duplicateHTML_PRECAKAN(copy,paste,baseid){
	if(document.getElementById(copy)){
		var e107_dupCounter = 1;
		e107_dupCounter++;
		var type = document.getElementById(copy).nodeName; // get the tag name of the source copy.
		var but = document.createElement('input');
		var br = document.createElement('br');
		but.type = 'button';
		but.value = 'x';
		but.className = 'button';
		but.onclick = function(){ this.parentNode.parentNode.removeChild(this.parentNode); };
		var destination = document.createElement('span');
		var source      = document.getElementById(copy).cloneNode(true);
		var newentry = document.createElement(type);
		newentry.appendChild(br);
		newentry.appendChild(source);
		newentry.appendChild(but);
		
		newentry=document.createElement('input');
		newentry.type='file';
		
		destination.appendChild(br);
		destination.appendChild(newentry);
		destination.appendChild(but);
		document.getElementById(paste).appendChild(destination);
	}
}
function sf() {
	document.getElementById('files_div').innerHTML+='<br /><input type="file" name="files[]" value="" style="width:90%" />';
}
function makeReq(ajax_url, ajax_functions_id) {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        	ajax_functions(ajax_functions_id, xmlHttp.responseText);
        }
      }
    xmlHttp.open("GET",ajax_url,true);
    xmlHttp.send(null);
}

function makeReq_comment(ajax_url, comment_id) {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        	var element_id="comment_"+comment_id;
        	document.getElementById(element_id).innerHTML=xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",ajax_url,true);
    xmlHttp.send(null);
}

function ajax_functions(id, code) {
	if (id==5) {
		oDownload.startDownload(code,0);
	}
	if (id==1) location.href='http://23sou.info';
	if (id==2) {
		makeReq_comment('teacher_comment.php?show=1&id='+code, code);
	}
	else location.href=id;
}	
function ajax_comment(id) {
	makeReq_comment('teacher_comment.php?id='+id, id);
}
function form_comment(id) {
	makeReq('teacher_comment_edit.php?id='+id+'&comment='+document.getElementById('comment').value, '2');
}