


ActiveStatus=0;
G_lng=new Array();
jsRED='#FCD8CD';
jsOK='#f5f5f5';
jsOKBase=jsOK;
globalSE='';
globalSim='';
globalGrp='';


function lR(s,a) {lI('regi.php?do=view_prof&sim='+s,a);}
function lM(s,a) {lI('comm.php?do=messu&sim='+s,a);}
function hS(g,i,u) {hideDIV('usrSel');lS('news.php?do=view&joli=upsch&grp='+g+'&di='+i+'&du='+u,'id_search');}

function lA(uid,eid,qid) {
	var o=document.getElementsByTagName('input');
	var val='';
	for(var i=0;i<o.length;i++) {
		if (o[i].type=='radio' && o[i].name==qid && o[i].checked) {
			val=o[i].value;
			i=o.length;
		}
	}
	if (val!='') {
		var a=qid.split('-');
		var id=a[0]+'-'+a[1];
		lS('news.php?do=myans&du='+uid+'&di='+eid+'&id='+val+'&old='+qid+'&page='+a[0],'html-'+id);
	} else {alert(G_lng[12]);}
}

function set_class_id(id,cl){
	var id=document.getElementById(id);
	if (id) {id.className=cl;}
}

function set_class_group(n,cl){
	var obj=n.split(',');
	if (obj.length>0) {
		for (var i=0;i<obj.length;i++) {
			var id=document.getElementById(obj[i]);
			if (id) {id.className=cl;}
		}
	}
}

function get_option_val(o){
	o=o.options;
	var s='';
	for(var i=0;i<o.length;i++){
		if(o[i].selected){s=o[i].value;}
	}
	return s;
}


function callStu(bc){
	if (document.getElementById('big_screen')) {alert(G_lng[11]);return;}
	lI('news.php?do=view_stu&bc='+bc,'a');
}

function doSCHproc(scr) {
	if (document.getElementById('big_screen')) {scr=1;}
	var fid=document.getElementById('f_id');
	var fdi=document.getElementById('f_di');
	var fi1=document.getElementById('f_f1');
	var fi2=document.getElementById('f_f2');
	var fi3=document.getElementById('f_f3');
	var fif=document.getElementById('f_f_ch');
	var fip=document.getElementById('f_pay');
	var fis=document.getElementById('f_se');
	var fit=document.getElementById('f_sta');
	var fph=document.getElementById('f_f_ph');
	var fex=document.getElementById('f_f_ex');
	var fi4=document.getElementById('f_f4');
	if (fid && fdi) {
		var fbc='~~';
		if (fi1 && fi2 && fi3) {
			fbc=get_option_val(fi1)+'~'+get_option_val(fi2)+'~'+get_option_val(fi3);
		}
		fbc+='~'+get_option_val(fdi)+'~'+get_option_val(fid)+'~';
		if (fif) {fbc+=(fif.checked?'1':'0');}
		fbc+='~';
		if (fip) {fbc+=get_option_val(fip);}
		fbc+='~';
		if (fis) {fbc+=encodeURI(eClear( fis.value.replace(/~/g,'') ));}
		fbc+='~';
		if (scr==1) {fbc+='20';}
		fbc+='~';
		if (fit) {fbc+=get_option_val(fit);}
		fbc+='~';
		if (fph) {fbc+=(fph.checked?'1':'0');}
		fbc+='~';
		if (fex) {fbc+=(fex.checked?'1':'0');}
		fbc+='~';
		if (fi4) {fbc+=get_option_val(fi4);}
		fbc+='~';
		if (scr==1) {
			document.getElementById('psh_content').innerHTML='';
			hideDIV('id_psh');
			lS('news.php?do=view_stu&bc='+fbc,'id_search');
		} else {
			lI('news.php?do=view_stu&bc='+fbc,'a');
		}

	} else {alert(G_lng[11]);}
}

function doRE(str,id,fsim) {
	var tmp='tab_'+id;
	if (fsim!='') {tmp='d_'+fsim;}
	var tab=document.getElementById(tmp);
	id='c_cont'+id;
	if (document.getElementById(id) && tab && tab.style.display!='none') {insertAtCursor(id, str+' ');} else {alert(G_lng[11]);}
}

function selFS(id) {
	var val=id+'_';
	id=document.getElementById(id);
	if (id) {
		var state=id.checked;
		var o=document.getElementsByTagName('input');
		var s='';
		if (typeof o.length != 'undefined' && o.length>0) {
			for (var i=0;i<o.length;i++) {
				if (o[i].type=='checkbox'){
					s=new String(o[i].id);
					s=s.substr(0,4);
					if (s==val) {
						o[i].checked=state;
						o[i].disabled=state;
					}
				}
			}
		}
	}
}
function checkSch(){
	var ok=false;
	var o=document.getElementsByTagName('input');
	if (typeof o.length != 'undefined' && o.length>0) {
		for (var i=0;i<o.length;i++) {
			if (o[i].type=='checkbox'){
				if (o[i].checked) {ok=true;}
			}
		}
	}
	return ok;
}

function checkFS(id) {
	var val=id+'_';
	id=document.getElementById(id);
	if (id) {
	if (!id.disabled) {
		var state=id.checked;
		var o=document.getElementsByTagName('input');
		var s='';
		var do_sel = true;
		if (typeof o.length != 'undefined' && o.length>0) {
			for (var i=0;i<o.length;i++) {
				if (o[i].type=='checkbox'){
					s=new String(o[i].id);
					s=s.substr(0,4);
					if (s==val) {
						if(!o[i].checked) {do_sel=false;}
					}
				}
			}
			if (do_sel) {
				id.checked=true;
				for (var i=0;i<o.length;i++) {
					if (o[i].type=='checkbox'){
						s=new String(o[i].id);
						s=s.substr(0,4);
						if (s==val) {
							o[i].disabled=true;
						}
					}
				}
			}
		}
	}
	}
}

function biblio(sim,id,p) {
	globalSim=sim;
	var pos=findPos(p);
	var tmp_x=pos[0];
	var tmp_y=pos[1];
	setDIVxy(id,tmp_x,tmp_y);
	showDIV(id);
}

function grpSelect(sim,id,p) {
	hideDIV('usrSel');
	globalGrp=sim;
	var pos=findPos(p);
	var tmp_x=pos[0];
	var tmp_y=pos[1];
	setDIVxy(id,tmp_x,tmp_y);
	showDIV(id);
	var o=document.getElementById('ins_userGroup');
	if (o) {
		if(o.innerHTML.length<20) {loadAJAX('info.php?menu=9&di='+sim,'ins_userGroup');}
	}
}

function usrSelect(sim,id,p) {
	hideDIV('grpSel');
	var pos=findPos(p);
	var tmp_x=pos[0];
	var tmp_y=pos[1];
	setDIVxy(id,tmp_x,tmp_y);
	showDIV(id);
	var o=document.getElementById('ins_userAuthor');
	if (o) {
		if(o.innerHTML.length<20) {loadAJAX('info.php?menu=10&di='+sim,'ins_userAuthor');}
	}
}

function getKeyStr(n) {
	var baseStr='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
	var str='';
	for (var i=0;i<n;i++) {str=str+baseStr.charAt( Math.floor(Math.random()*(baseStr.length-2)) );}
	return str;
}

function MakeArray(n) {
	this.length=n;
	for (var i=1; i<=n; i++) this[i]="";
	return this
}

function checkDate(id,er) {
	var s=document.getElementById(id).value;
	var u=s.split('-');
	var d=new Date();
	var y=parseInt(u[0],10);
	var m=parseInt(u[1],10)-1;
	var a=parseInt(u[2],10);
	d.setDate(1); d.setMonth(0); d.setYear(y); d.setMonth(m); d.setDate(a);
	var dd=d.getYear();if(dd<1000){dd+=1900;}
	if(dd==y&&d.getMonth()==m&&d.getDate()==a){return true;}
	document.getElementById(id).style.backgroundColor=jsRED; alert(er); return false;
}

function checkEma(id,er) {
	var str=document.getElementById(id).value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!filter.test(str)) {alert(er);document.getElementById(id).style.backgroundColor=jsRED;return false;}
	return true;
}

function checkPas(id,id2,er) {
	id=document.getElementById(id);
	id2=document.getElementById(id2);
	if (id.value!=id2.value) {id.style.backgroundColor=jsRED;id2.style.backgroundColor=jsRED;alert(er);return false;}
	return true;
}

function checkFile(id,ext,er) {
	val=document.getElementById(id).value;
	if (val!='') {
		var t=val.split('.');
		if (t.length>0) {
			if ( t[t.length-1].toUpperCase()==ext.toUpperCase() ) {
				document.getElementById(id).style.backgroundColor=jsOK;
				return true;
			}
		}
	}
	alert(er);
	document.getElementById(id).style.backgroundColor=jsRED;
	return false;
}

function checkReq(ids,er) {
	var tmp=ids.split(';');
	var err=0;
	var id='';
	for (var i=0;i<tmp.length;i++){
		id=document.getElementById(tmp[i]);
		if (id) {
		switch (id.type) {
			case 'password': 
			case 'textarea':
			case 'text': if (id.value=='') {err=1;id.style.backgroundColor=jsRED} else {id.style.backgroundColor=jsOK}; break;
			case 'checkbox': if (!id.checked) {err=1;id.style.backgroundColor=jsRED} else {id.style.backgroundColor=jsOK}; break;
		}}
	}
	jsOK=jsOKBase;
	if (err) {alert(er);return false;}
	return true;
}

function getKeyPress(e) {
	if (window.event) {return e.keyCode;}//ie
	else if (e.keyCode) {return e.keyCode;}//moz
}

function eClear(str) {
	str=str.replace(/\'/g,' ');
	str=str.replace(/\"/g,' ');
	str=str.replace(/`/g,' ');
	str=str.replace(/\&/g,' ');
	str=str.replace(/\\/g,' ');
	return str.replace(/^\s+|\s+$/, ''); ;
}

function Llang(la) {
	SetCookie('langKS','',-1);
	SetCookie('langKS',la,0);
	window.location.reload();
}

function confi(n,uri) {
	if (confirm(n)) {location.replace(uri);}
}

function confiX(n,uri) {
	if (confirm(n)) {var v='y';if (ISshowDIV('id_psh')) {v='a';} lI(uri,v);}
}

function promi(n,str,uri) {
	var nval=prompt(n,'');
	if (nval) {location.replace(uri+'&'+str+'='+nval);}
}

function reloadSRC(id,uri) {
	if (document.getElementById(id)) {
		document.getElementById(id).src = uri;
	}
}

function findPos(obj) {
	obj=document.getElementById(obj);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function findPosByObj(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function CopyToClipboard(id) {
	document.getElementById(id).focus();
	document.getElementById(id).select(); 
	CopiedTxt = document.selection.createRange();
	CopiedTxt.execCommand('copy');
}

function PasteFromClipboard(id) { 
	document.getElementById(id).focus();
	PastedText = document.getElementById(id).createTextRange();
	PastedText.execCommand('paste');
} 

function insertAtCursor(id, myValue) {
	//opera
	if (navigator.userAgent.indexOf("Opera") != -1) {
		document.getElementById(id).value += myValue;
	} 
	//ie
	else if (document.selection) {
		document.getElementById(id).focus();
		document.selection.clear();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//moz
	else if (document.getElementById(id).selectionStart || document.getElementById(id).selectionStart == '0') {
		var startPos = document.getElementById(id).selectionStart;
		var endPos = document.getElementById(id).selectionEnd;
		document.getElementById(id).value = document.getElementById(id).value.substring(0, startPos) + myValue + document.getElementById(id).value.substring(endPos, document.getElementById(id).value.length);
	} else {
		document.getElementById(id).value += myValue;
	}
	document.getElementById(id).focus();
	document.selection.clear();
}

function changeBC(id,color) {id.style.backgroundColor=color;}

function changeBCbyId(id,color,border) {
	if (document.getElementById(id)) {
		document.getElementById(id).style.backgroundColor=color;
		document.getElementById(id).style.borderColor=border;
	}
}

function hideDIV(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'none';
	}
}

function showDIV(id,val) {
        if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'block';
		if (val) document.getElementById(id).innerHTML = val;
	}
}

function switchDIV(id,sw1,sw2) {
	var sw = document.getElementById(id).style.display=='none';
	document.getElementById(id).style.display = sw ? 'block':'none';
	if (sw1) {
		sw = sw ? sw2 : sw1;
		reloadSRC(id+'_sw',sw+'.gif');
	}
}

function ISshowDIV(id) {
        if (document.getElementById(id)) {
                return document.getElementById(id).style.display=='block';
        }
        return false;
}

function setFromDIV(id1,id2) {
	var pos=findPos(id1);
	setDIVxy(id2,pos[0],pos[1]-5);
}

function setDIVxy(id,x,y) {
	document.getElementById(id).style.top = y;
	document.getElementById(id).style.left= x;
}

function setClip(id,t,r,b,l) {
	var obj=document.getElementById(id);
	obj.style.clip = 'rect('+t+'px '+r+'px '+b+'px '+l+'px)';
}

function SetCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*nDays);
	var exps='';
	if (nDays>0||nDays<0) exps=";expires="+expire.toGMTString();
	document.cookie = cookieName+"="+escape(cookieValue)+exps;
}

function GetCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return '';
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}


//--- G_event;

G_event = new Object;
G_event.x=0;
G_event.y=0;
G_event.Moz=navigator.userAgent.indexOf("MSIE")==-1?1:0;

document.onclick = customClick;
document.onmousedown = customClick;
document.onmousemove = customClick;

function customClick(e) {
	if (e||window.event) {
		G_event.x = e ? e.pageX : window.event.x;
		G_event.y = e ? e.pageY : window.event.y;
	}
}

function getMouseXY() {
	var Xpos = (!window.event) ? G_event.x+1-document.body.scrollLeft: window.event.x-2;
	var Ypos = (!window.event) ? G_event.y+1-document.body.scrollTop : window.event.y-2;
	return [Xpos,Ypos];
}


//--- move DIV;

G_move = new Object;
G_move.moveX = 1;
G_move.moveY = 1;
G_move.afterdrop = '';
G_move.slimX1 = null;
G_move.slimX2 = null;
G_move.slimY1 = null;
G_move.slimY2 = null;


function dragDIV(e) {
	if (e) {customClick(e);}
	var tmp_c=getMouseXY();
	var x_tmp = G_move.SelectedX + (tmp_c[0] - G_move.MouseX);
	var y_tmp = G_move.SelectedY + (tmp_c[1] - G_move.MouseY);
	if ((x_tmp + G_move.lx) > parseInt(document.body.scrollWidth)) {x_tmp=parseInt(document.body.scrollWidth)-G_move.lx;}
	if ((y_tmp + G_move.ly) > parseInt(document.body.scrollHeight)) {y_tmp=parseInt(document.body.scrollHeight)-G_move.ly;}
	if (x_tmp < 0) {x_tmp=0;}
	if (y_tmp < 0) {y_tmp=0;}
	if (G_move.moveX) {
		var passX=true;
		if (G_move.slimX1!=null&&G_move.slimX2!=null) {
			if (x_tmp>G_move.slimX2||x_tmp<G_move.slimX1) passX=false;
		}
		if (passX) {G_move.SelectedItem.style.left = x_tmp+'px';}
	}
	if (G_move.moveY) {
		var passY=true;
		if (G_move.slimY1!=null&&G_move.slimY2!=null) {
			if (y_tmp>G_move.slimY2||y_tmp<G_move.slimY1) passY=false;
		}
		if (passY) {G_move.SelectedItem.style.top = y_tmp+'px';}
	}
	if (G_move.lim) {
		setClip(G_move.id,0-(y_tmp-G_move.SelectedY),G_move.lx-(x_tmp-G_move.SelectedX),G_move.ly-(y_tmp-G_move.SelectedY),0-(x_tmp-G_move.SelectedX));
	}
	return false;
}

function dropDIV(e) {
	G_move.SelectedItem.style.zIndex = G_move.zBackValue;
	G_move.moveX = 1;
	G_move.moveY = 1;
	G_move.slimX1 = null;
	G_move.slimX2 = null;
	G_move.slimY1 = null;
	G_move.slimY2 = null;
	document.onmouseup = null;
	document.onclick = customClick;
	document.onmousedown = customClick;
	document.onmousemove = customClick;
	var s=G_move.afterdrop;
	G_move.afterdrop='';
	if (s!='') {eval(s);}
	if (document.selection) {document.selection.clear();}
}

function moveDIV(id,x,y,lim) {
	G_move.id = id;
	G_move.lx = x;
	G_move.ly = y;
	G_move.lim = lim;
	G_move.SelectedItem = document.getElementById(id);
	if (x) {G_move.lx = x;} else {G_move.lx = parseInt(G_move.SelectedItem.style.pixelWidth);} if (id=='id_psh') {G_move.lx+=G_event.Moz*20;}//---Moz;
	if (y) {G_move.ly = y;} else {G_move.ly = parseInt(G_move.SelectedItem.style.pixelHeight);}
	G_move.SelectedX = parseInt(G_move.SelectedItem.style.left);
	G_move.SelectedY = parseInt(G_move.SelectedItem.style.top);
	G_move.zBackValue = G_move.SelectedItem.style.zIndex;
	G_move.SelectedItem.style.zIndex = 10000;
	var tmp_c=getMouseXY();
	G_move.MouseX = tmp_c[0];
	G_move.MouseY = tmp_c[1];
	document.onmousemove = dragDIV;
	document.onmouseup = dropDIV;
	document.onmousedown = dragDIV;
}

function HSi(ids) {var id=document.getElementById(ids);if (id) { if (id.style.display=="none") {id.style.display="block";document.getElementById(ids+"_").className="pMS";} else {id.style.display="none";document.getElementById(ids+"_").className="pPL";}}}


