var edit = false;
IncludeJavaScript("js/ajax.js");
var updateQueue=new Array();
function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}
var init_field = function(obj){
	if(obj.value=="username or email" || obj.value=="click to login"){
		obj.style.color="#000000";
		obj.value="";
		}
}
var init_pass = function(obj,realPassObj){
	realPassObj.style.display=obj.style.display;
	obj.style.display="none";	
	realPassObj.focus();
	}
function postComment(formObj,pubObj){
	ajaxFunction('php_exe/post_comment.php', 'comment='+formObj.elements['post_comment'].value+'&subject_id='+formObj.elements['subject_id'].value, ajaxInnerHTML, null, pubObj);
//	alert(formObj.elements['post_comment'].value);
	formObj.reset();
	}
function initPassword(obj,newSize){
	if(newSize==null)newSize=14;
	obj.type='password';
	initText(obj,newSize);
}
function deleteFile(file){
	alert(file);
	}
function globalConfirm(){
	//nothing!	
	}
globalConfirmVar=0;
function addFriend(id){
	ajaxFunction('php_exe/add_friend.php', 'id='+id, ajaxInnerHTML, null, 	document.getElementById('add_friend_'+id));	

	}
function deleteComment(comment_id){
	ajaxFunction('php_exe/delete_comment.php', 'comment='+comment_id, ajaxInnerHTML, null, document.getElementById('comment_'+comment_id));	
	}
function deleteSubject(subject_id){
	ajaxFunction('php_exe/delete_subject.php', 'subject='+subject_id, ajaxInnerHTML, null, document.getElementById('subject_'+subject_id));	
	}	
function editPageElement(element){
	loadSideWindow('opt_component/editComponent.php','id='+element.parentNode.id);
	}
function initConfirm(string, confirmFunction, confirmVariable){
	var mConfirm_bg = document.getElementById('confirm_bg');
	var mConfirmContent = document.getElementById('confirm_content');	
	mConfirmContent.innerHTML=string;
	mConfirm_bg.style.visibility='visible';
	mConfirm_bg.style.left='0px';	
	mConfirm_bg.style.top='0px';
	mConfirm_bg.style.width=document.documentElement.offsetWidth+'px';	
	mConfirm_bg.style.height=(document.documentElement.scrollHeight)+'px';		
	confirmRefresh();
	updateQueue.push(confirmRefresh);
	globalConfirm=confirmFunction;
	globalConfirmVar=confirmVariable;	
	}
function confirmRefresh(){
	var mConfirm = document.getElementById('confirm');
	mConfirm.style.left=(document.documentElement.offsetWidth/2-mConfirm.offsetWidth/2) + 'px';	
	mConfirm.style.top=((document.documentElement.scrollTop)+ (document.documentElement.clientHeight||innerHeight)/2 - 50)+'px';
	}
function mdAlert(string){
	var mAlert_bg = document.getElementById('alert_bg');
	var mAlertContent = document.getElementById('alert_content');	
	mAlertContent.innerHTML=string;
	mAlert_bg.style.visibility='visible';
	mAlert_bg.style.left='0px';	
	mAlert_bg.style.top='0px';
	mAlert_bg.style.width=document.documentElement.offsetWidth+'px';	
	mAlert_bg.style.height=(document.documentElement.scrollHeight+(0))+'px';		
	alertRefresh();
	updateQueue.push(alertRefresh);
	
	}
function alertRefresh(){
	var mAlert = document.getElementById('alert');
	mAlert.style.left=(document.documentElement.offsetWidth/2-mAlert.offsetWidth/2) + 'px';	
	mAlert.style.top=((document.documentElement.scrollTop)+ (document.documentElement.clientHeight||innerHeight)/2 - 50)+'px';
	}
function confirmCancel(){
	var mAlert = document.getElementById('confirm_bg');
	mAlert.style.visibility='hidden';
	mAlert.style.height='0px';
	mAlert.style.width='0px';
	for(key in updateQueue){
		if(updateQueue[key]==confirmRefresh){
			updateQueue.splice(key,1);
			break;
			}
		}
	}
function confirmSubmit(){
	globalConfirm(globalConfirmVar);
	confirmCancel();
	}
function closeAlert(){
	var mAlert = document.getElementById('alert_bg');
	var mAlert_main = document.getElementById('alert');
	document.getElementById('alert_content').innerHTML='';	
	mAlert.style.visibility='hidden';
	mAlert.style.height='0px';
	mAlert.style.width='0px';
	for(key in updateQueue){
		if(updateQueue[key]==alertRefresh){
			updateQueue.splice(key,1);
			break;
			}
		}
	}	
function findAbs(obj){
	var left=0;
	var top=0;	
	while(obj.nodeName!="BODY"){
		left += obj.offsetLeft;
		top += obj.offsetTop;
		obj=obj.offsetParent;
		}
		return(Array(left,top));
}
function focusDetail(html, obj){
	var fDetail = document.getElementById('focus_detail');
	fDetail.innerHTML=html;
	fDetail.style.visibility='visible';
	fDetail.style.width=(obj.offsetWidth-8)+'px';	
	var pnt=findAbs(obj);
	fDetail.style.left=pnt[0]+'px';
	fDetail.style.top=(pnt[1])+'px';
	fDetail.onmouseout=clearFocusDetail;
}
function loadHTMLFocus(url,obj){
	ajaxFunction("form_components/upload_pic.php", '', ajaxFocusDetailBottom, nullF, obj);
	}
function focusDetailBottom(html, obj){
	clearTimeoutT();
	var fDetail = document.getElementById('focus_detail');
	fDetail.innerHTML=html;
	fDetail.style.visibility='visible';
	fDetail.style.width=(obj.offsetWidth-2)+'px';
	var pnt=findAbs(obj);
	fDetail.style.left=pnt[0]+'px';
	fDetail.style.top=(pnt[1]+obj.offsetHeight)+'px';
	fDetail.onmouseout=clearFocusDetail;
	detailBlock=false;
}
function clearFocusDetail(){
	var fd = document.getElementById('focus_detail');
	fd.t = window.setTimeout("forceClearDetail()",500);
	fd.onmouseover=clearTimeoutT;
	
	}
function clearTimeoutT(){
	clearTimeout(document.getElementById('focus_detail').t);
	}	
var detailBlock=false;
	
function forceClearDetail(){
	var fDetail=document.getElementById('focus_detail');
	var pnt=findAbs(fDetail);
	if(!detailBlock && (globmsX < pnt[0] || globmsX > pnt[0]+fDetail.offsetWidth || globmsY < pnt[1] || globmsY > pnt[1]+fDetail.offsetHeight)){
		fDetail.innerHTML='';
		fDetail.style.width='auto';
		fDetail.style.left='0px';
		fDetail.style.top='0px';
		fDetail.style.visibility='hidden';	
		}
	}

function applyFunction(good, ugly, gfunc,ufunc, group, parent){
	var typeArray;
	var parentTag;
	if(parent){
		parentTag = parent;	
	}else{
		parentTag = document;
	}
	if(group){
		typeArray = group;
	}else{
		typeArray = new Array('input','textarea','a', 'div', 'form');
	}
	for(type in typeArray){
		var doc = parentTag.getElementsByTagName(typeArray[type]);
		for(var i = 0; i < doc.length; i++){
			if(!doc[i].className)continue;
				if(doc[i].className.match(good)){
					if(gfunc)gfunc(doc[i]);
				}else if(doc[i].className.match(ugly)){
					if(ufunc)ufunc(doc[i]);					
					}
			}
	}		
}
function applyFunctionReturn(good, gfunc, parent){
	var parentTag;
	if(parent){
		parentTag = parent;	
	}else{
		parentTag = document;
	}
	var	typeArray = new Array('input','textarea','a', 'div', 'form');

	for(type in typeArray){
		var doc = parentTag.getElementsByTagName(typeArray[type]);
		for(var i = 0; i < doc.length; i++){
			if(!doc[i].className)continue;
				if(doc[i].className.match(good)){
					return gfunc(doc[i]);
				}
			}
	}		
}
var getValue = function(obj){
	return obj.value;
	}
function applyFunctionByTag(good, ugly, gfunc,ufunc){
		
		if(good.name =="profile_admin")alert("OMG");
	var doc = document.getElementsByTagName(good);	
	for(var i = 0; i < doc.length; i++){
		if(!doc[i])continue;
		if(gfunc)gfunc(doc[i]);
		if(ufunc)ufunc(doc[i]);					
		

	}
	doc = document.getElementsByTagName(ugly);		
	for(var i = 0; i < doc.length; i++){
		if(!doc[i])continue;
		if(gfunc)gfunc(doc[i]);
		if(ufunc)ufunc(doc[i]);					
		
	}
	
}
var resetThis = function(obj){
	obj.reset();
	}
var clear = function(obj){
	obj.style.display="none";
}
var show = function(obj){
	obj.style.display="block";
}
function applyExceptionRule(exception, rule, efunc, rfunc){
	var typeArray = new Array('input','textarea','a', 'div');
	for(type in typeArray){
		var doc = document.getElementsByTagName(typeArray[type]);
		for(var i = 0; i < doc.length; i++){
			if(!doc[i].className)continue;
				if(doc[i].id.match(exception)){
					efunc(doc[i]);
				}else if(doc[i].className.match(rule) && !(doc[i].id.match(exception))){
					rfunc(doc[i]);
					}
			}
	}	
}
var sessionFunc = function(varThis){
	if(varThis != "0"){
		document.login_f.style.display="none";
		document.logout_f.style.display="block";
		refreshLinks("logged", "unlog");
		//refreshLinks("logged", "unlogged");
	}else{
		document.login_f.style.display="block";
		document.logout_f.style.display="none";
		refreshLinks("unlog", "logged");
	}
}
function clearStuff(){
	document.login_f.style.display="none";
	document.logout_f.style.display="none";
}
var visible = function(obj){
	obj.style.visibility="visible";
	}
function makePassword(obj){
	if(obj.type != "password"){
	obj.type = "password";
	obj.value = "";
	}
}

var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var globmsX = 0;
var globmsY = 0;

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    globmsX = event.clientX + document.body.scrollLeft;
    globmsY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    globmsX = e.pageX;
    globmsY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (globmsX < 0){globmsX = 0}
  if (globmsY < 0){globmsY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true;
}

