// Modal Dialog Box
// copyright 8th July 2006 by Stephen Chapman
// http://javascript.about.com/
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
var findRep;
function pageWidth() 
{
	return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
function pageHeight() 
{
	return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}
function posLeft() 
{
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}
function posTop()
{
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}
function scrollFix()
{
	var obol=$('ol');
  obol.style.top=posTop()+'px';
  obol.style.left=posLeft()+'px';
}
function sizeFix()
{
	var obol=$('ol');obol.style.height=pageHeight()+'px';obol.style.width=pageWidth()+'px';
}
function kp(e)
{
	ky=e?e.which:event.keyCode;if(ky==88||ky==120)hm();return false
}
function inf(h)
{
	tag=document.getElementsByTagName('select');
	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
	tag=document.getElementsByTagName('iframe');
	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
	tag=document.getElementsByTagName('object');
	for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;
}
function sm(obl, wd, ht, type, dept, styleId)
{

 	var h='hidden';
	var b='block';
	var p='px';
	var obol=$('ol'); 
	var obbxd = $('mbd');
 var type = type;
	obbxd.innerHTML = $(obl).innerHTML;
	obol.style.height=pageHeight()+p;obol.style.width=pageWidth()+p;
	obol.style.top=posTop()+p;
	obol.style.left=posLeft()+p;
	obol.style.display=b;
	var tp=posTop()+((pageHeight()-ht)/2)-12;
	var lt=posLeft()+((pageWidth()-wd)/2)-12;
	var obbx=$('mbox');
	obbx.style.top=(tp<0?0:tp)+p;
	obbx.style.left=(lt<0?0:lt)+p;
	obbx.style.width=wd+p;
	obbx.style.height=ht+p;
	inf(h);
	obbx.style.display=b;
 
	if(type==0)
	{
		getVenueForm(dept, styleId);
	}
  else if(type == 3)
  {
   getOppVenueForm(dept, styleId)
  }   
  else if(type == 'BU-1') //added by selva for bu 15.03.2010
  {
   getCategoryTagEditForm(dept)
  }
  else if(type == 'BU-Q')
  {
    getQualificationTagForm(dept)
  }else if(type == 'FRA')
  {
  
    getForumAnswerSheet()
  }
  else if("BU-2".match("^"+"BU"))
  {
    getManuallAssign(type,dept)
  }
	return false;
}
function hm()
{
	var v='visible';
	var n='none';
	$('ol').style.display=n;
	$('mbox').style.display=n;
	inf(v);
  document.onkeypress='';  
  
  if($('help')){
  $('help').style.display='none';
  }
   
}
function initmb()
{
	var ab='absolute';
	var n='none';
	var obody=document.getElementsByTagName('body')[0];
	var frag=document.createDocumentFragment();
	var obol=document.createElement('div');
	obol.setAttribute('id','ol');
  document.body.scrollTop = 0
	obol.style.display=n;
	obol.style.position=ab;
  obol.style.top=0;
	obol.style.left=0;
	obol.style.zIndex=998;
	obol.style.width='100%';
	frag.appendChild(obol);
  var obbx=document.createElement('div');
	obbx.setAttribute('id','mbox');
	obbx.style.display=n;
	obbx.style.position=ab;
	obbx.style.zIndex=999;
	var obl=document.createElement('span');
	obbx.appendChild(obl);
	var obbxd=document.createElement('div');
	obbxd.setAttribute('id','mbd');
	obl.appendChild(obbxd);
	frag.insertBefore(obbx,obol.nextSibling);
	obody.insertBefore(frag,obody.firstChild);
	window.onscroll = scrollFix; window.onresize = sizeFix;
}
window.onload = initmb;
function displayForm(ajax)
{
  $("newvenueform").innerHTML=ajax.response;
  $("ajax-div").style.display="none";
 	$("newvenueform").style.display="block"; 
}
function getVenueForm(dept, styleId)
{
	var url=contextPath+"/venue/select-venue.html?action=Add&countryId="+$("countryId").value+"&institutionId="+$("institutionId").value+"&ajax=1"+"&styleId="+styleId;
	if(dept==1){url+="&dept=1";}
  if(styleId == 'eflFlag' && $("countryId").value!=211 && $("countryId").value!=168){    
    url+="&vtype=NV";
  }
	$("ajax-div").style.marginTop="100px";
	$("ajax-div").style.display="block";
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ displayForm(ajax); };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
}

function getForumAnswerSheet()
{


	var url=contextPath+"/forum/getAnswerSheet.html?action=addEditAnswer&questionId="+$("questionId").value+"&answerId="+$("answerId").value;
 

 
  $("ajax-div").style.marginTop="100px";
	$("ajax-div").style.display="block";
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){   displayAnswerForm(ajax); };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
}
function displayAnswerForm(ajax)
{

  $("answerform").innerHTML=ajax.response;
  $("ajax-div").style.display="none";
 	$("answerform").style.display="block"; 
  eval($("ckScript").innerHTML);
   
  
}
function getOppVenueForm(dept, styleId)
{
	var url=contextPath+"/venue/select-venue.html?action=Add&countryId="+$("countryId").value+"&institutionId="+$("institutionId").value+"&ajax=1"+"&styleId="+styleId;
	if(dept==1){
  url+="&dept=1";
  }else if(dept==5){
   url+="&vtype=ND&dept=1";
  }else{
  url+="&vtype=NV";
  }
	$("ajax-div").style.marginTop="100px";
	$("ajax-div").style.display="block";
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ displayOppVenueForm(ajax); };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
}
function displayOppVenueForm(ajax)
{ 
  $("newvenueform").innerHTML=ajax.response;
  $("ajax-div").style.display="none";
  $("newvenueform").style.display="block";
  eval($("script").innerHTML);
}
/*!. added by selva for bulk upload to edit the category tags content details for auto-categorisation  */
function getCategoryTagEditForm(categoryid) {
 var url=contextPath+"/bureport.html?action=editcat&categoryId="+categoryid;
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ loadBUCategoryEditContent(ajax) };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
}
function loadBUCategoryEditContent(ajax)
{ 
  $("newvenueform").innerHTML=ajax.response;
  $("ajax-div").style.display="none";
  $("newvenueform").style.display="block";
}
/*end of the code added by selva for auto categorisation */
// MANUAL ASSIGNMENT
function getManuallAssign(type,courseId) 
{
  if(type == "BU-2")
  {
    var url=contextPath+"/bureport.html?action=manualcat&courseId="+courseId;
  }
  else if(type == "BU-3")
  {
    var url=contextPath+"/bureport.html?action=autoqual&courseId="+courseId;
  }
  else if(type == "BU-4")
  {
    var url = contextPath+"/bureport.html?action=autolevel&courseId="+courseId;
  }
	var ajax=new sack();
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ loadManualAssign(ajax) };	// Specify function that will be executed after file has been found
	ajax.runAJAX();
}
function loadManualAssign(ajax)
{
  $("newvenueform").innerHTML=ajax.response;
  $("ajax-div").style.display="none";
  $("newvenueform").style.display="block";
}
//ADDED ON 15-NOV-2011
function getQualificationTagForm(qualId) 
{
  var url=contextPath+"/bureport.html?action=editqualtags&qId="+qualId;
  var ajax=new sack();
  ajax.requestFile = url;	// Specifying which file to get
  ajax.onCompletion = function(){ loadBUQualificationContent(ajax) };	// Specify function that will be executed after file has been found
  ajax.runAJAX();
}
function loadBUQualificationContent(ajax)
{ 
  $("newvenueform").innerHTML=ajax.response;
  $("ajax-div").style.display="none";
  $("newvenueform").style.display="block";
}

