var enableHTMLArea = 0;
var enableSubmitExam = 0;

function objectWalk(inObj) {
 for (var prop in inObj) {
  var strtemp = strtemp + 'name: ' + prop + '= ' + inObj[prop] + '\n';
 }
 return strtemp;
}

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_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_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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function ShowTip(fArg)
{
	var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");
	if (tooltipOBJ != null) {
		var tooltipLft = (document.body.offsetWidth?document.body.offsetWidth:document.body.style.pixelWidth) - (tooltipOBJ.offsetWidth?tooltipOBJ.offsetWidth:(tooltipOBJ.style.pixelWidth?tooltipOBJ.style.pixelWidth:380)) - 30;
		if (navigator.appName == 'Netscape') {
			var tooltipTop = 10;
			tooltipOBJ.style.left = tooltipLft; tooltipOBJ.style.top = tooltipTop;
		}
		else {
			var tooltipTop = (document.body.scrollTop>=0?document.body.scrollTop+10:event.clientY+10);
			if ((event.clientX > tooltipLft) && (event.clientY < (tooltipOBJ.scrollHeight?tooltipOBJ.scrollHeight:tooltipOBJ.style.pixelHeight) + 10)) {
				tooltipTop = (document.body.scrollTop?document.body.scrollTop:document.body.offsetTop) + event.clientY + 20;
			}
			tooltipOBJ.style.pixelLeft = tooltipLft; tooltipOBJ.style.pixelTop = tooltipTop;
		}
		tooltipOBJ.style.visibility = "visible";
	}
};

function HideTip(fArg)
{
	var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");
	if (tooltipOBJ != null) {
		tooltipOBJ.style.visibility = "hidden";
	}
};

function mOvr(src)
	{{ src.style.cursor = 'pointer'; }}

function mOut(src)
	{{ src.style.cursor = 'default'; }}
	
function TopLeftopenWindow(theURL,winName,features) 
{ 
  var _W=window.open(theURL,winName,features);
  _W.focus();
  _W.moveTo(0,0); 
}

function addbookmark(argVal){
  var bookData = new Array();
  bookData = argVal.split("|");
  if (document.all)
	window.external.AddFavorite(bookData[0], bookData[1]);
}

function MoveSelected(frmObj,src,quotes,onChange){
	s = frmObj.elements[src];
	source = s.options.length;
	//t = frmObj.elements[tgt];
	//target = t.options.length;
	changed = false;
	for(i=0;i<source;i++){
		if(s.options[i].selected){
			tx = s.options[i].text;
			vl = s.options[i].value;
			newOpt = new Option(tx, vl, false, false);

			s.options[i] = null;
			source--;
	//		target++;
			i--;
			changed = true;
		}
	}
	if ((onChange != "") && changed)
		eval(onChange);
}

function addToParentList(sourceList) {
	destinationList = window.document.forms[0].SR;
	for(var count = destinationList.options.length - 1; count >= 0; count--) {
		destinationList.options[count] = null;
	}
	for(var i = 0; i < sourceList.options.length; i++) {
		if (sourceList.options[i] != null)
			destinationList.options[i] = new Option(sourceList.options[i].text, sourceList.options[i].value );
	}
}

function addSelectedItemsToParent() {
self.opener.addToParentList(window.document.forms[0].destList);
window.close();
}
// Fill the selected item list with the items already present in parent.
function fillInitialDestList() {
var destList = window.document.forms[0].destList;
var srcList = self.opener.window.document.forms[0].SR;
for (var count = destList.options.length - 1; count >= 0; count--) {
destList.options[count] = null;
}
for(var i = 0; i < srcList.options.length; i++) {
if (srcList.options[i] != null)
destList.options[i] = new Option(srcList.options[i].text, srcList.options[i].value, false, false);
   }
}
// Add the selected items from the source to destination list
function addSrcToDestList() {
destList = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[i].selected)) {
//Check if this value already exist in the destList or not
//if not then add it otherwise do not add it.
var found = false;
for(var count = 0; count < len; count++) {
if (destList.options[count] != null) {
if (srcList.options[i].text == destList.options[count].text) {
found = true;
break;
      }
   }
}
if (found != true) {
newoption = new Option(srcList.options[i].text, srcList.options[i].value, false, false);
document.FrmSelectNews.destList.options[len] = newoption;
len++;
         }
      }
   }
}
// Deletes from the destination list.
function deleteFromDestList() {
var destList  = window.document.forms[0].destList;
var len = destList.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList.options[i] != null) && (destList.options[i].selected == true)) {
destList.options[i] = null;
      }
   }
}

function SelectAllEdit(){
	for (i=0; i<document.FrmEdit.SR.length; i++) {
		document.FrmEdit.SR.options[i].selected = true;
	}
}

function SelectAllAdd(){
	for (i=0; i<document.FrmAdd.SR.length; i++) {
		document.FrmAdd.SR.options[i].selected = true;
	}
}

function trimAll( strValue ) {
 var objRegExp = /^(\s*)$/;
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function validateDate( strValue ) {
  var objRegExp = /^\d{4}(\-|\/|\.)\d{2}\1\d{2}$/

  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(4,5) //find date separator
    var arrayDate = strValue.split(strSeparator); //split date into month, day, year
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[2]);

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0 && parseInt(arrayDate[1]) <= 12){
				return true; //found in lookup table, good date
			} else {
			  return false;
			}
    }

    //check for February
    var intYear = parseInt(arrayDate[0]);
    var intMonth = parseInt(arrayDate[1]);
    if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0 && intMonth == 02)
      return true; //Feb. had valid number of days
  }
  return false; //any other values, bad date
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]+$/) != -1)
        return true;
    else
        return false;
}

function isValidEmail(email) {
	if (email=="") {
		return false;
	}
	if (email.indexOf('@')<1) {
		return false;
	}
	if (email.indexOf('.')==-1) {
		return false;
	}
	if (email.indexOf('.')==(email.length -1)) {
		return false;
	}
	if (email.indexOf('.')==(email.indexOf('@')+1)) {
		return false;
	}
	return true;
}

function isValidDomain(email) {
	if (email.indexOf('.')==-1) {
		return false;
	}
	if (email.indexOf('.')==(email.length -1)) {
		return false;
	}
	if (email.indexOf('.')==(email.indexOf('@')+1)) {
		return false;
	}
	return true;
}

var win= null;

function CenterOpenWindow(mypage,myname,w,h,scroll) {
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=yes';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
};


var openImg = new Image();
openImg.src = "/portal/images/minus.gif";
var closedImg = new Image();
closedImg.src = "/portal/images/plus.gif";

function showBranch(branch){
	var objBranch = document.getElementById(branch).style;
	if(objBranch.display=="block")
		objBranch.display="none";
	else
		objBranch.display="block";
};

function swapFolder(img){
	objImg = document.getElementById(img);
	if(objImg.src.indexOf('plus.gif')>-1)
		objImg.src = openImg.src;
	else
		objImg.src = closedImg.src;
};

// 
// type 1 = Popup
// type 2 = Alert
// type "" = Nothing
function MM_jumpMenu(targ,selObj,restore){ //v3.0
if (selObj.options[selObj.selectedIndex].value != "") {
var linkType = new Array();
linkType = selObj.options[selObj.selectedIndex].value.split("|");
	if (linkType[2] == "1"){
		eval(linkType[1]);
	} else if (linkType[2] == "2"){
		if (confirm(linkType[0]))
		location.replace(linkType[1]);
	} else {
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
		}
	}
};

function GenFn() {
if (enableHTMLArea == 1) {
	 initDocument();
}
};

function GenUnloadFn(){
if (enableSubmitExam == 1){
//  document.forms['FrmCert'].time_left.value = document.forms['FrmCert'].clock.value;
document.forms['FrmCert'].time_left.value = x;
	document.forms['FrmCert'].submit();
}
};
