/* 
---------------------------------------------------------------------------------------
written by Tran Nguyen San
Create : 12/24/2003 - Happy and Merry Christmas 
Last Updated	 12/31/2003	Happy New Year

-----------------------------------------------------------------------------------------
*/
var winModalWindow=null;
var _message;
var _title;
var _type;
var  _button1;
var  _button2;
var  _button3;
var  _dir;
var _sCourse;
var _sStatus;
var	_sGreeting;
var	_sName;
var	_sReason;
var	_sDate;
var	_sTitle;
var	_sWelcome;
var	_sAlt1;
var	_sTitle1;
var	_sAlt2;
var	_sTitle2;
var	_sAlt3;
var	_sTitle3;
var	_sAlt4;
var	_sTitle4;

var rspn_alert = 0;
var rspn_confirm=0;
var rspn_3button=0;
var rspn_print=0;
var inform_icon=0;
var exclam_icon =1;
var critical_icon =2;
var question_icon =3;
var stop_icon =4;
var aValue;


function AutoFocusForm() {
  // If there is a form in the doc...
  if ((document.forms)&&(document.forms[1])) {
	
    var theElems = document.forms[1].elements

    // loop over the elements until finding a non-hidden one
    for (i = 0; i < theElems.length; i++) {
      var theElem = theElems[i];
      if (theElem.type && theElem.type == "hidden" ) {
        continue;
      }
      // focus on the first non-hidden element
      theElem.focus();
      
      break;
    }
  }
}

function Alert(sValue,nIndex)
{_alert(sValue,"::","     Ok    ", exclam_icon,nIndex)
}
function Confirm(sValue,nIndex)
{
_confirm2(sValue,"::","    Yes    ","     No     ", question_icon,nIndex)
}

function set508Value(sValue11,sValue12,sValue21,sValue22,sValue31,sValue32,sValue41,sValue42)
{	_sAlt1=sValue11
	_sTitle1=sValue12
	_sAlt2=sValue21
	_sTitle2=sValue22
	_sAlt3=sValue31
	_sTitle3=sValue32
	_sAlt4=sValue41
	_sTitle4=sValue42
	
}
function ckrspn_alert(val,nIndex){
	rspn_alert = val;
	sValue='shwval_alert'+nIndex+'()'
	setTimeout(sValue,100);
}
function ckrspn_confirm(val,nIndex){
	rspn_confirm = val;
	sValue='shwval_confirm'+nIndex+'()'
	setTimeout(sValue,100);
}	
function ckrspn_3button(val,nIndex){
	rspn_3button = val;
	sValue='shwval_3button'+nIndex+'()'
	setTimeout(sValue,100);
}
function _alert(sMessage,sTitle,sButton1,nIcon,nIndex,sDir)
{
	set508Value(sButton1,sButton1,"","","","","","");
	setValue(sMessage,sTitle,sButton1,'','',nIcon,nIndex,sDir)  
	return rspn_alert;
}
function _confirm2(sMessage,sTitle,sButton1,sButton2,nIcon,nIndex,sDir)
{
	set508Value("","",sButton1,sButton1,sButton2,sButton2,"","");
	setValue(sMessage,sTitle,sButton1,sButton2,'',nIcon,nIndex,sDir)
	return rspn_confirm;
}
function _confirm3(sMessage,sTitle,sButton1,sButton2,sButton3,nIcon,nIndex,sDir)
{	
	set508Value("","",sButton1,sButton1,sButton2,sButton2,sButton3,sButton3);
	setValue(sMessage,sTitle,sButton1,sButton2,sButton3,nIcon,nIndex,sDir)
	return rspn_3button;
  }
function setValue(sMessage,sTitle,sButton1,sButton2,sButton3,nIcon,nIndex,sDir)
{
	
	sRoot=window.location.pathname.split("/")[0]+"/"+window.location.pathname.split("/")[1]+"/"+"elm/"
	
  _message=sMessage 
  _title=	sTitle
  _type=nIndex
  _button1=sButton1
  _button2=sButton2
  _button3=sButton3
  _dir=sDir
  switch (nIcon){
  case 0:_icon=	"W95MBX04.jpg";break;
  case 1:_icon=	"W95MBX03.jpg";	break;
  case 2:_icon=	"W95MBX01.jpg";	break;
  case 3:_icon=	"W95MBX02.jpg";	break;
  case 4:_icon=	"MSGBOX01.jpg";	break;
	}	
	popwidth=320;			
	
	if (sMessage.length>50) 
		popheight=80+sMessage.length
	else
		popheight=127;		
	leftpos=screen.width/2 - 200;
	toppos=screen.height/2 - 75;	
	
		aValue=new Array();
		 aValue[0]=_message
		 aValue[1]=_title
		 aValue[2]=_type
		 aValue[3]=_button1
		 aValue[4]=_button2
		 aValue[5]=_button3
		 aValue[6]=_icon		 
		 aValue[7]=_dir
		 
		 aValue[8]=_sAlt1
		 aValue[9]=_sTitle1
		 
		 aValue[10]=_sAlt2
		 aValue[11]=_sTitle2
		 
		 aValue[12]=_sAlt3
		 aValue[13]=_sTitle3
		 
		 aValue[14]=_sAlt4
		 aValue[15]=_sTitle4	
	
	if (!window.showModalDialog)
	{
				 
		window.captureEvents (Event.CLICK|Event.FOCUS)		
		window.onclick=IgnoreEvents
		window.onfocus=HandleFocus	
		var winattributes='z-lock=1'+',width='+popwidth+',height='+popheight+',scrollbars=no,resizable=no,left='+leftpos+',top='+toppos+",scrollbars=no,status=0";
		winModalWindow=window.open(sRoot+"dialog/YesNoCancel.htm",'Yes No Question',winattributes)
		
		// Quang Luong: in case browser can not popup a new window, use alert function instead.
		// there are several reason, ex: some software block the advertise popup on browser.
		// this will fix for bug 1597
		if (winModalWindow==null) {
			alert(sMessage);
			rspn_confirm=1;
			if (sButton2=="" ){
			sValue="shwval_alert"+nIndex+"()";
			eval(sValue)
			}
			else
			if (sButton3=="" )		{
			  sValue="shwval_confirm"+nIndex+"()";
			  eval(sValue)
			  }
			else{
				sValue="shwval_3button"+nIndex+"()";
				eval(sValue)
				}	
		} else {
			winModalWindow.document.close()
			winModalWindow.focus()	
		}
		// Quang Luong
				
	}
	else
		{ 
		 
		 var winattributes="dialogHeight:"+popheight+"px; dialogWidth:"+popwidth+"px; status:no; help:no; scroll:no;"		 
		 if (sButton2=="" ){
			rspn_alert=window.showModalDialog(sRoot+"dialog/YesNoCancel.htm",aValue,winattributes)
			sValue="shwval_alert"+nIndex+"()";
			eval(sValue)
			}
		else
			if (sButton3=="" )		{
			  rspn_confirm=window.showModalDialog(sRoot+"dialog/YesNoCancel.htm",aValue,winattributes)	
			  sValue="shwval_confirm"+nIndex+"()";
			  eval(sValue)
			  }
			else{
				rspn_3button=window.showModalDialog(sRoot+"dialog/YesNoCancel.htm",aValue,winattributes)	
				sValue="shwval_3button"+nIndex+"()";
				eval(sValue)
				}		 				
		}	
		
}
function ckrspn_print(val,nIndex){
	rspn_print = val;
	sValue='shwval_print'+nIndex+'()'
	setTimeout(sValue,100);
}
function _print(sMessage,sOption1,sOption2,sTitle,sButton1,sButton2,nIndex,sDir)
{	setPrintDialog(sMessage,sOption1,sOption2,sTitle,sButton1,sButton2,nIndex,sDir)
	return rspn_print;
  }
function setPrintDialog(sMessage,sOption1,sOption2,sTitle,sButton1,sButton2,nIndex,sDir)
{ sRoot=window.location.pathname.split("/")[0]+"/"+window.location.pathname.split("/")[1]+"/"+"elm/"
  _message=sMessage 
  _option1=sOption1 
  _option2=sOption2 
  _title=	sTitle
  _type=nIndex
  _button1=sButton1
  _button2=sButton2  
  _dir=sDir
	popwidth=280;			
	popheight=220+sMessage.length
	leftpos=screen.width/2 - 200;
	toppos=screen.height/2 - 75;		
	if (!window.showModalDialog)
		{window.captureEvents (Event.CLICK|Event.FOCUS)
		window.onclick=IgnoreEvents
		window.onfocus=HandleFocus	
		var winattributes='width='+popwidth+',height='+popheight+	',scrollbars=no,resizable=no,left='+leftpos+',top='+toppos+"scrollbars =no;status=0";	
		winModalWindow =window.open (sRoot+"dialog/Print.htm",null,winattributes)		
		winModalWindow.document.close()
		winModalWindow.focus()	
		}
	else
		{ aValue=new Array();
		 aValue[0]=_message
		 aValue[1]=_title
		 aValue[2]=_type		 
		 aValue[3]=_option1
		 aValue[4]=_option2
		 aValue[5]=_button1
		 aValue[6]=_button2
		 aValue[7]=_dir
		 var winattributes="dialogHeight:"+popheight+"px; dialogWidth:"+popwidth+"px; status:no; help:no; scroll:no;"		 
		 rspn_print=window.showModalDialog(sRoot+"dialog/Print.htm",aValue,winattributes)	
 		 sValue="shwval_print"+nIndex+"()";
		 eval(sValue)		
		}	
}

function IgnoreEvents(e)
{if (window.showModalDialog)
		if (!winModalWindow.closed)
		  winModalWindow.focus()
 return false;
} 
 function HandleFocus()
{ if (winModalWindow)
  {	if (!winModalWindow.closed)
    {
      winModalWindow.focus()
   }
  else
	if (!window.showModalDialog)
    {  window.releaseEvents (Event.CLICK|Event.FOCUS)
       window.onclick = ""
      return true;
    }
  } 
}
function createCert(sDir,sCourse,sStatus,sGreeting,sWelcome,sName,sReason,sDate,sTitle,sRoot,frame)
{	_dir=sDir;
	_sCourse=sCourse
	_sStatus=sStatus 
	_sGreeting=sGreeting
	_sWelcome=sWelcome
	_sName=sName
	_sReason=sReason
	_sDate=sDate
	_sTitle=sTitle
	frame.location=sRoot+"elm/dialog/Certificate.htm"
}

