<!--

N = 0; 
var ob=null;
var rx = 0;
var ry = 0;
var rw = 0;
var rh = 0;
var pinx = 0;
var piny = 0;
var allowPin = 0;

var pcounter = 0;

function IncludeJavaScript(jsFile)
{
  	//document.write('<script type="text/javascript" src="'
    //+ jsFile + '"></ script>'); 
	var headID = document.getElementsByTagName("head")[0];
	var newScript = document.createElement('script');
	newScript.language = 'javascript';
	newScript.type = 'text/javascript';
	newScript.src = jsFile;
	headID.appendChild(newScript);	  
}

//IncludeJavaScript('scripts/lmenu.js');
//IncludeJavaScript('scripts/load.js');
//IncludeJavaScript('dwr/engine.js');
//IncludeJavaScript('dwr/util.js');
//IncludeJavaScript('dwr/interface/WebLoader.js');
//IncludeJavaScript('dwr/interface/Chat.js');
//IncludeJavaScript('dwr/interface/UploadMonitor.js');
//IncludeJavaScript('dwr/interface/DocumentProcessMonitor.js');

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function insertDocLink() {
  var x=document.getElementById("docsList");
  var y=document.getElementById("linkName");
  var ln = "";
  if (y.value=="") {
  	ln = x.options[x.selectedIndex].text;
  } 
  else {
  	ln = y.value;
  }
  
  //document.getElementById("content").value += "<link id=\""+x.options[x.selectedIndex].value+"\">"+ln+"</link>";
  //tinyMCE.triggerSave('content');  
  //document.getElementById("content").value += " <a href=\""+x.options[x.selectedIndex].value+"\">"+ln+"</a> ";
  tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent() +" <a href=\""+x.options[x.selectedIndex].value+"\">"+ln+"</a> ");
  MM_showHideLayers('insertDoc','','hide');
  return false;
}

function setMenu() {
	var menu = document.getElementById('pMenu');
	var nmenu = document.getElementById('noMenu');
	//alert(menu.innerHTML);
	if (menu != null && nmenu ==null) {
		dwr.util.setValue('LeftMenu',menu.innerHTML,{ escapeHtml:false });
		//fixmenus();
	}		
}

function showPage() {
	setMenu();
	var title = document.getElementById('pTitle');
	var status = document.getElementById('pStatus');
	var userp = document.getElementById('userpanel');	

	if (title !=null)
		dwr.util.setValue('PageTitle',title.innerHTML,{ escapeHtml:false });
	if (status !=null)
		dwr.util.setValue('StatusBar',status.innerHTML,{ escapeHtml:false });
	//if (userp !=null)
	//	dwr.util.setValue('startTab','Ο ΙΣΤΟΧΩΡΟΣ ΜΟΥ',{ escapeHtml:false });
}

function setTMenu (name) {
	var x1 = document.getElementById('start');	
	var x2 = document.getElementById('studies');
	var x3 = document.getElementById('course_catalog');
	var x4 = document.getElementById('webcourses_stats');
	var x5 = document.getElementById('info');	
	var x6 = document.getElementById('contact');
	x1.className = ''; x2.className = '';	x3.className = '';
	x4.className = '';	x5.className = '';	x6.className = '';
	if (name=='start' || name=='lesson' || name=='myCourses' || name=='my_courses') x1.className='current';
	else if (name=='studies') x2.className='current';
	else if (name=='course_catalog') x3.className='current';
	else if (name=='webcourses_stats') x4.className='current';
	else if (name=='info') x5.className='current';
	else if (name=='contact_mp' || name=='contact' || name=='register') x6.className='current';
}

function loadScript(tag) {
	var nss = dwr.util.getValue("pScript");
	var searchss,exScript;
	if (nss=="")
		return;
	else {
		if (nss.indexOf("js")==-1)
			return;
		exScript = nss.substring(nss.indexOf(tag)+1,nss.lastIndexOf(tag));
		if (exScript==null || exScript=="")
			return;
		searchss = exScript.substring(exScript.lastIndexOf("/")+1,exScript.lastIndexOf("js")+2);
	}
		
	//var ss = document.getElementsByTagName("script");
	//for (var idx in ss) {
		//alert(ss[idx].src);
	//	if (ss[idx].src!=null && ss[idx].src.indexOf(searchss)!=-1)
	//		return;
	//}
	var headID = document.getElementsByTagName("head")[0];
	
	var scriptTag = document.getElementById(searchss);
	if (scriptTag) headID.removeChild(scriptTag);	
	
	var newScript = document.createElement('script');
	newScript.language = 'javascript';
	newScript.type = 'text/javascript';
	newScript.id = searchss;
	newScript.src = exScript;
	headID.appendChild(newScript);		
}

function writeHistory(p,prs) {
	var params = "";
	for(x in prs)
		params += prs[x].replace(/&/g,'---')+'---';
	params += 'pc='+ pcounter++;
	var hframe = document.getElementById('historyFrame');
	if (hframe!=null)
		hframe.setAttribute('src','history.jsp?app_name='+p+'&app_params='+params);	
}

function close_app() {
	var app = document["ria_cs"]; 
	if (app!=null)
		if (app.close_application)
			try {
			  app.close_application("webcourses");
			}catch(err) {}

}

function request(id,p,prs,chhis) {
	//document.body.style.cursor = "wait";
	close_app();
	var title,status;
	if (chhis) 
		writeHistory(p,prs);
	else {
			WebLoader.getData(p,prs,function(data) {
			dwr.util.setValue(id, data, { escapeHtml:false });
			showPage();
			setTMenu(p);
			loadScript('#');
			loadScript('%');
			document.documentElement.scrollTop = 0;
			showInfoPanel();
		});
	}
	//document.body.style.cursor = "auto";
	if (p.match("^"+'mng_')=='mng_' || p.match("^"+'manage')=='manage' || p.match("^"+'msite')=='msite')
		editSiteMode();
	else
		normalSiteMode();
}

function prequest(p,prs) {
	request('MainPage',p,prs,true);
}

function brequest(p,prs) {
	request('MainPage',p,prs,false);
}

function postReply(id,ifrm) {
	var dname = null;
	var content = window.frames[ifrm].document.getElementById('PageContent');
	var dnamev = window.frames[ifrm].document.getElementById('div_name');
	if (dnamev)
		dname = dnamev.innerHTML;
	if (dname !=null && id == null)
		id = dname;
	else if (id==null)
		id = 'directory';
	if (content !=null) {
		dwr.util.setValue(id,content.innerHTML,{ escapeHtml:false });
		showPage();
		writeHistory('post');
		loadScript('#');
		loadScript('%');
		showInfoPanel();
	}
	endLoading();
}

function clearPostReply() {
	window.frames['RSIFrame'].document.body.innerHTML = "";
}

function hasPostReply() {
	if ( window.frames['RSIFrame'].document.getElementById('PageContent') )
		return true;
	else
		return false;
}

function ppostReply() {
	postReply('MainPage','RSIFrame');
}

function startActionMonitor (app_name,app_params){
	if (window.frames['historyFrame']==null)
		return;
		
	var happname = window.frames['historyFrame'].document.getElementById('app_name');
	var happs = window.frames['historyFrame'].document.getElementById('app_params');
	var haction = window.frames['historyFrame'].document.getElementById('app_action');
	if(happname) {
		var hh = happname.innerHTML;
		var pp = "";
		if (happs)
			pp = happs.innerHTML;
			
		//hh = hh.substring(hh.indexOf("hash=")+5);
		
		if ( ( (hh!=app_name && hh!='null')|| (hh==app_name && app_params!=pp) ) && (haction && haction.innerHTML=='get') ) {
			//alert('hh:'+hh+',app:'+app_name+',pp:'+pp+',app:'+app_params);
			var dpp = pp;
			if (pp)
				dpp = pp.replace(/---/g,"&");
			brequest(hh,dpp);
		}
		setTimeout("startActionMonitor('"+hh+"','"+pp+"')",300);
	}
	else
		setTimeout("startActionMonitor('"+app_name+"','"+app_params+"')",300);
}

function reloadInfo() {
	var infoFrame = window.frames['infoFrame'];
	if (infoFrame)
		setTimeout('infoFrame.document.location.reload()',10000);
}

function getInfo() {
	var infoFrame = window.frames['infoFrame'];
	var no_msgs = infoFrame.document.getElementById('no_msgs');
	if (no_msgs && no_msgs.innerHTML!='0') {
		if(!winList['message_panel'].isOpen) {
			posDiv('message_panel','MainPage');
			var x = document.getElementById('message_panel');
			if (x)
				x.style.top = document.documentElement.scrollTop +300+ "px";
			
			winList['message_panel'].open();
		}
		//if (infoFrame.document.getElementById('im').innerHTML.indexOf('Αίτηση Συνομιλίας με Εικόνα')!=-1 ) {
		//	playSound('ringSound');
		//}
		dwr.util.setValue('user_msg',infoFrame.document.getElementById('im').innerHTML,{ escapeHtml:false });//document.getElementById('user_msg').innerHTML+
	}
	//infoFrame.document.location.reload();
}

function closeInfo() {
	winList['message_panel'].close();
	dwr.util.setValue('user_msg','');
	request('resp_div','user_info',new Array('clear=true'));
}

function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oElement.x, oElement.y ];
  }
}

function posDiv(posDiv,pDiv) {
///*
	var elem = document.getElementById(posDiv);
	var pwin = document.getElementById(pDiv);

	var pos,width,pwidth,height,pheight;
	if (elem==null || pwin==null)
		return;

	pos = findPosition(pwin);
	width = elem.offsetWidth;
	pwidth = pwin.offsetWidth;
	height = elem.offsetHeight;
	pheight = pwin.offsetHeight;	
		
	//alert("pos:"+pos+" w:"+width+" pw:"+pwidth+" h:"+height+" ph:"+pheight);

	elem.style.left = (pos[0]+ pwidth/2 - width/2)+"px";
	elem.style.top = (pos[1]+ pheight/2 - height/2)+"px";
//*/
//	alert("x:"+elem.style.left+", y:"+elem.style.top);
}

function toggleEditor(id) {
	var elm = document.getElementById(id);
	if (elm==null) return;
	if (tinyMCE.getInstanceById(id) == null)
		tinyMCE.execCommand('mceAddControl', false, id);
	else {
		tinyMCE.execCommand('mceRemoveControl', false, id);
	}
}

function removeEditor(id) {
	try{
		if (tinyMCE.get(id))
			tinyMCE.execCommand('mceRemoveControl', false, id);
	} catch (ex) {
		//alert('tinyMCE exception');
	};
}

function loadEditorId(id,idx) {
	var elm = document.getElementById(id);
	if (elm==null) return;
	//tinyMCE.idCounter=0;
	//if (tinyMCE.getInstanceById(id) == null) {
	//	tinyMCE.execCommand('mceAddControl', false, id);
	//}
	//else {
		tinyMCE.idCounter=idx;
		tinyMCE.execCommand('mceAddControl', false, id);
	//}
}

function loadEditor(id) {
	var elm = document.getElementById(id);
	if (elm==null) return;
	//tinyMCE.idCounter=0;
	if (tinyMCE.getInstanceById(id) == null) {
		tinyMCE.execCommand('mceAddControl', false, id);
	}
	else {
		tinyMCE.idCounter=0;
		tinyMCE.execCommand('mceAddControl', false, id);
	}
}

function showInfoPanel() {
	var msg = document.getElementById('info_msg');
	if (msg !=null) {
		var ip = document.getElementById('info_panel');
		if (ip!=null) {
			posDiv('info_panel','MainPage');
			ip.style.top = document.documentElement.scrollTop +200+ "px";
			//ip.style.left = 200+"px";
			ip.style.visibility = 'visible';
			dwr.util.setValue('sys_msg',dwr.util.getValue('info_msg'));
			setTimeout('closeInfoPanel()', 4000);
		}
	}
	showErrorPanel();
}

function showErrorPanel() {
	var msg = document.getElementById('last_err_msg');
	if (msg !=null) {
		var ip = document.getElementById('error_panel');
		if (ip!=null) {
			posDiv('error_panel','MainPage');
			ip.style.top = document.documentElement.scrollTop +200+"px";
			//ip.style.left = 600+"px";
			ip.style.visibility = 'visible';
			dwr.util.setValue('err_msg',dwr.util.getValue('last_err_msg'));
			//setTimeout('closeInfoPanel()', 3000);
		}
	}
}

function raiseError(error) {
	var ip = document.getElementById('error_panel');
	if (ip!=null) {
		posDiv('error_panel','MainPage');
		ip.style.top = document.documentElement.scrollTop +300+ "px";
		ip.style.visibility = 'visible';
		dwr.util.setValue('err_msg',error);
	}
}

function closeInfoPanel() {
	var ip = document.getElementById('info_panel');
	if (ip!=null) {
		ip.style.visibility = 'hidden';
	}
}

function playSound(soundobj) {
  
  try {
	var tsound=document.getElementById(soundobj);
  	tsound.Play();
  }catch(err) {}
}

function setLoginFocus() {
	var x = document.getElementById('username');
	if (x) {
		try{
			x.focus();	
		} catch (err) {alert(err)};
	}
}


//LINK ΙΤΕΜ
function showLinkWindow() {
	//posDiv('linkDigItem','MainPage');
	var x = document.getElementById('linkDigItem');
	if (x) {
		x.style.top = 100+"px";
		x.style.left = 100+"px";
	}
	winList['linkDigItem'].open();
	request('winLinkDitem','digItemLink');	
}

function insertDitemLink(pointer, item_id, item_type, item_name, hitem_id) {
  var type_name;
  var pointer_type;
  
  switch (item_type) {
	  case 1: // all digital content
		type_name = "slides";
		pointer_type = "slPointer";
		break;
	  case 2: //multimedia presetations
		type_name = "slides";
		pointer_type = "prPointer";
		break;
  }
  
  var x=document.getElementById(pointer_type+pointer);
  var ln = "";
  var linkStr;

  switch (item_type) {
	  case 1: // all digital content
		if (x.selectedIndex==0)
			linkStr = "<a id=\"innerWClink\" href=\"digItem.jsp?ditem_id="+item_id+"&ditem_type=0"+"&ditem_fname="+item_name+"\" class=\"boxLink\"><img src=\"Images/Icons/link_digitem.png\" border=\"0\"></a><p></p>";
	  	else
			linkStr = "<a id=\"innerWClink\" href=\"javascript:prequest('presentation',new Array('pid="+item_id+"','ptype="+type_name+"','page="+x.selectedIndex+"','ilink=1'));\"><img src=\"Images/Icons/link_slidespres.png\"  border=\"0\"></a><p></p>";
		break;
	  case 2: //multimedia presetations
		linkStr = "<a id=\"innerWClink\" href=\"javascript:prequest('watchPres',new Array(";
  		var x;
		for(x in item_name)
			linkStr += "'"+item_name[x]+"',";
		linkStr += "'end=1'));\"><img src=\"Images/Icons/link_pres.png\" align=\"absmiddle\" border=\"0\" /></a><p></p>";
		break;
	  case 3: // forums
	  	linkStr = "<a id=\"innerWClink\" href=\"javascript:prequest('course_forums_view',new Array('forum_id="+item_id+"','ilink=1'));\"><img src=\"Images/Icons/link_forum.png\" align=\"absmiddle\" border=\"0\" /></a><p></p>";
		break;
	  case 4 : //Announcements
	  	linkStr = "<a id=\"innerWClink\" href=\"javascript:prequest('announcement',new Array('news_id="+item_id+"','state=1','ilink=1'));\"><img src=\"Images/Icons/link_announcement.png\" align=\"absmiddle\" border=\"0\" /></a><p></p>";
	  default:
  }

  tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent() +' '+linkStr+' ');
  winList['linkDigItem'].close();
  return false;
}


function changeLang () {
	var x=document.getElementById('chooselanform');
	if (x) 
		x.submit();
}
//LINK


function getScrollTop() {
	if (document.documentElement && document.documentElement.scrollTop && document.documentElement.scrollTop>0)
		return  document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop && document.body.scrollTop>0)
		return document.body.scrollTop;
	else
		return 0;
}

function enterPressed(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) 
		return true;
	else
		return false;
}

function editSiteMode() {
	//var x = document.getElementById("wrap");
	//if (x ) {
	//		x.style.background = "url('Styles/images/editmode.png')";
	//}
}

function normalSiteMode() {
	//var x = document.getElementById("wrap");
	//if (x ) {
	//		x.style.background = "#fff url(Styles/images/wrap_bg2.jpg) repeat-x";
	//}
}
//-->

