//Function to clear text in the status bar
function fStat(){
	window.status='';
	return true;
}

if(document.layers){
	document.captureEvents(Event.MOUSEOVER,Event.MOUSEOUT);
}
document.onmouseover = fStat;
document.onmouseout = fStat;
//Function to clear text in the status bar

//Function to set/get current window heights and widths
PwinWidth = 0;
PwinHeight = 0;
function fUpdWinDims(){
	$('ixPageContent').setProperties({'width': window.getScrollWidth(), 'height': window.getScrollHeight()});
	PwinWidth = $('ixPageContent').getProperty('width').toInt();
	PwinHeight = $('ixPageContent').getProperty('height').toInt();
}
//Function to set/get current window heights and widths

//Functions to control page body actions
function fDoBodyOnLoad(){}
function fDoBodyOnUnload(){}
function fDoBodyOnResize(){}
//Functions to control page body actions

//CONFIRMATION CHECK
function fConfirmThis(ConfirmText){
	if(confirm(ConfirmText)){
		return true;
	}
	else{
		return false;
	}	
}

//Function to verify required form fields
function fVerifyRequiredFields(FormName, RequiredText){
	for(var i=0;i<document.forms[FormName].length;i++){
		var el, elid, eltyp, req, val, nel, eltrgt;
		el = document.forms[FormName].elements[i].name;
		elid = document.forms[FormName].elements[i].id;
		eltyp = document.forms[FormName].elements[i].type;
		if(el != '' && elid != ''){
			val = document.forms[FormName].elements[el].value;
			if(el != elid){
				nel = el+'_'+val;
				req = $(nel) ? $(nel).getProperty('req') : '';
				eltrgt = el;
			}
			else{
				req = $(el) ? $(el).getProperty('req') : '';
				eltrgt = el;
			}
			if(req == 'req' && (val == '' || val.length <= 0)){
				alert(RequiredText);
				document.forms[FormName].elements[el].focus();
				return false;
			}
		}
	}
	return true;
}

//Function to clear message blocks
function fClearMSG(MSGTarget){
	msg = MSGTarget+'MSG';
	$(msg).setHTML('');
}

//OPEN POPUP WINDOW
function fPopup(p,n,h,w){
	window.open(p, n, 'height='+h+',width='+w+',scrollbars=yes,location=no,menubar=no,toolbar=no,resizable=yes');
}

//Function to display a custom Loader Image and Text String
function fShowCustomLoader(LoaderImage, LoaderText){
	var CustomLoaderTxt = '';
	CustomLoaderTxt += '<img src="'+LoaderImage+'" border="0" /> '+LoaderText;
	return CustomLoaderTxt;
}
//Function to display a custom Loader Image and Text String

//Function to strip pipes from strings
function fStripPipes(strString){
	var strStripped = strString.replace(/\|/g, '');
	return strStripped;
}
//Function to strip pipes from strings

//Function to switch from a select to an input field
//similar to a combination select field...
function fSelectToInputSwitch(IMode, FldName){
	var FldSel = document.getElementById(FldName);
	var FldText = document.getElementById(FldName+'_other');
	
	if(FldSel && FldText){
		var ValSel;
		var ValText = FldText.value;
		
		ValSel = '';
		for(var i=0;i<FldSel.length;i++){
			if(FldSel.options[i].selected){
				ValSel = FldSel.options[i].value;
			}
		}
		
		if(IMode == 'select'){
			if(ValSel == 'other'){
				$(FldName+'__DIVselect').setStyles({display: 'none'});
				$(FldName+'__DIVother').setStyles({display: 'block'});
				FldText.focus();
			}
		}
		else{
			for(var i=0;i>FldSel.length;i++){
				FldSel.options[i].selected = false;	
			}
			FldSel.options[0].selected = true;
			
			$(FldName+'__DIVother').setStyles({display: 'none'});
			$(FldName+'__DIVselect').setStyles({display: 'block'});
		}
	}
}
//Function to switch from a select to an input field

//Function to set a DropDown's Option to Selected
function fSetDDOption(DDID, OptID){
	var DD = document.getElementById(DDID);
	if(OptID == ''){
		OptID = 0;
	}
	var intOptID = OptID.toInt();
	if(intOptID == '' || intOptID <= 0){
		intOptID = 0;
	}
	
	if(DD){
		for(var i=0;i<DD.length;i++){
			DD.options[i].selected = false;
		}
		DD.options[intOptID].selected = true;
	}
}
//Function to set a DropDown's Option to Selected

//Function to get a DropDown's Selected Option's parts
function fGetDDSelOption(DDID){
	var DD = document.getElementById(DDID);
	var DDval = new Array(3);
	
	if(DD){
		for(var i=0;i<DD.length;i++){
			if(DD.options[i].selected){
				DDval[0] = i;
				DDval[1] = DD.options[i].value;
				DDval[2] = DD.options[i].text;
			}
		}
	}
	
	return DDval;
}
//Function to get a DropDown's Selected Option's parts

//Function to get a DropDown's Selected Option ID
function fGetDDSelOptID(DDID){
	var DD = document.getElementById(DDID);
	var DDval = new Array(3);
	
	if(DD){
		DDval = fGetDDSelOption(DDID);
	}
	
	return DDval[0];
}
//Function to get a DropDown's Selected Option ID

//Function to get a DropDown's Selected Value
function fGetDDSelOptValue(DDID){
	var DD = document.getElementById(DDID);
	var DDval = new Array(3);
	
	if(DD){
		DDval = fGetDDSelOption(DDID);
	}
	
	return DDval[1];
}
//Function to get a DropDown's Selected Value

//Function to get a DropDown's Selected Text
function fGetDDSelOptText(DDID){
	var DD = document.getElementById(DDID);
	var DDval = new Array(3);
	
	if(DD){
		DDval = fGetDDSelOption(DDID);
	}
	
	return DDval[2];
}
//Function to get a DropDown's Selected Text

//Function to get a DropDown's Options seperated in parts
function fGetDDOptions(DDID){
	var DD = document.getElementById(DDID);
	var DDopts = new Array();
	
	if(DD){
		for(var i=0;i<DD.length;i++){
			DDopts[i] = new Array(3);
			DDopts[i][0] = i;
			DDopts[i][1] = DD.options[i].value;
			DDopts[i][2] = DD.options[i].text;
		}
	}
	
	return DDopts;
}
//Function to get a DropDown's Options seperated in parts

//Function to add a new DropDown Option
function fAddDDOption(DDID, OptArray){
	var DD = document.getElementById(DDID);
	var NewDDopt = new Array(3);
	
	if(DD){
		var NewOptionIndx = DD.length;
		DD.options[NewOptionIndx] = new Option('','',false,false);
		DD.options[NewOptionIndx].value = OptArray[1];
		DD.options[NewOptionIndx].text = OptArray[2];
		
		NewDDopt[0] = NewOptionIndx;
		NewDDopt[1] = OptArray[1];
		NewDDopt[2] = OptArray[2];
	}
	
	return NewDDopt;
}
//Function to add a new DropDown Option

//Function to remove a DropDown Option
function fRemoveDDOption(DDID, OptArray){
	var DD = document.getElementById(DDID);
	var OrgDDopts = new Array();
	
	if(DD){
		OrgDDopts = fGetDDOptions(DDID);
		DD.options.length = 0;
		for(var i=0;i<OrgDDopts.length;i++){
			if(i != OptArray[0]){
				var AddOrgOption = fAddDDOption(DDID, OrgDDopts[i]);
			}
		}
	}
}
//Function to remove a DropDown Option



//Function to get Actual numeric ID
function fGetAID(CID){
	if(CID == ''){
		CID = 1;
	}
	var AID = CID.toInt();
	if(AID == '' || AID <= 1){
		AID = 1;
	}
	
	return AID;
}
//Function to get Actual numeric ID

//Function to display blocker div
function fBlock(){
	$('ixPageBlocker').setStyles({'display': 'block', 'opacity': '0.6'});
	$('ixPageBlocker').setProperties({'isblocked': 1});
}
//Function to display blocker div

//Function to display SPECIFIC FRAME blocker div
function fBlockHeader(){
	if(top.frames['frmHeader'].fBlock){
		top.frames['frmHeader'].fBlock();
	}
}
function fBlockMenu(){
	if(top.frames['frmMain'].frames['frmMenu'].fBlock){
		top.frames['frmMain'].frames['frmMenu'].fBlock();
	}
}
function fBlockBar(){
	if(top.frames['frmMain'].frames['frmBar'].fBlock){
		top.frames['frmMain'].frames['frmBar'].fBlock();
	}
}
function fBlockContent(){
	if(top.frames['frmMain'].frames['frmContent'].fBlock){
		top.frames['frmMain'].frames['frmContent'].fBlock();
	}
}
function fBlockALL(){
	fBlockHeader();
	fBlockMenu();
	fBlockBar();
	fBlockContent();
	fBlock();
}
//Function to display SPECIFIC FRAME blocker div

//Function to hide blocker div
function fUnBlock(){
	$('ixPageBlocker').setStyles({'display': 'none', 'opacity': '0'});
	$('ixPageBlocker').setProperties({'isblocked': 0});
}
//Function to hide blocker div

//Function to hide SPECIFIC FRAME blocker div
function fUnBlockHeader(){
	if(top.frames['frmHeader'].fUnBlock){
		top.frames['frmHeader'].fUnBlock();
	}
}
function fUnBlockMenu(){
	if(top.frames['frmMain'].frames['frmMenu'].fUnBlock){
		top.frames['frmMain'].frames['frmMenu'].fUnBlock();
	}
}
function fUnBlockBar(){
	if(top.frames['frmMain'].frames['frmBar'].fUnBlock){
		top.frames['frmMain'].frames['frmBar'].fUnBlock();
	}
}
function fUnBlockContent(){
	if(top.frames['frmMain'].frames['frmContent'].fUnBlock){
		top.frames['frmMain'].frames['frmContent'].fUnBlock();
	}
}
function fUnBlockALL(){
	fUnBlockHeader();
	fUnBlockMenu();
	fUnBlockBar();
	fUnBlockContent();
	fUnBlock();
}
//Function to hide SPECIFIC FRAME blocker div

//Function to hide Dialogue div
function fHideDialog(){
	$('ixPageDialogue').setStyles({'display': 'none'});
	fUnBlockALL();
}
//Function to hide Dialogue div

//Function to return the general parameters of the current page
function fGetGParams(){
	var gParam, vUseLang, vDB, vEnv, vArea, vAct, vLvl, vConRef;
	vUseLang = $('ixPageContent').getProperty('UseLang');
	vDB = $('ixPageContent').getProperty('UseDB');
	vEnv = $('ixPageContent').getProperty('UseEnv');
	vArea = $('ixPageContent').getProperty('UseArea');
	vAct = $('ixPageContent').getProperty('UseAct');
	vLvl = $('ixPageContent').getProperty('UseLvl');
	vConRef = $('ixPageContent').getProperty('UseConRef');
	
	gParam = 'UseLang='+vUseLang+'&UseDB='+vDB+'&UseEnv='+vEnv+'&UseArea='+vArea+'&UseAct='+vAct+'&UseLvl='+vLvl+'&UseConRef='+vConRef+'';
	
	return gParam;
}
//Function to return the general parameters of the current page




//Functions for Listing Data
function fSetRowColor(TblRowID){
	var TblCB = document.getElementById('CB'+TblRowID);
	var TblRow = document.getElementById('tblRow'+TblRowID);
	if(TblCB){
		if(TblCB.checked){
			$('tblRow'+TblRowID).setProperties({'CurrBGClr': '#ededed'});
		}
		else{
			$('tblRow'+TblRowID).setProperties({'CurrBGClr': $('tblRow'+TblRowID).getProperty('OrgBGClr')});
		}
	}
}
function fSetRowCB(TblRowID){
	var TblCB = document.getElementById('CB'+TblRowID);
	var TblRow = document.getElementById('tblRow'+TblRowID);
	if(TblCB){
		if(TblCB.checked){
			TblCB.checked = false;
			fSetRowColor(TblRowID);
			fSetDDOption('selcb', '0');
		}
		else{
			TblCB.checked = true;
			fSetRowColor(TblRowID);
		}
	}
}

function fSetCBsOnChange(tblID){
	var table = document.getElementById(tblID);
	var scb = document.getElementById('selcb');
	var scbval = '';
	if(scb){
		scbval = fGetDDSelOptValue('selcb');
		switch(scbval){
		case '2':
		case '3':
			for(var i=1;i<table.rows.length;i++){
				var row = table.rows[i];
				var aCB = row.id.split('tblRow');
				var cb = document.getElementById('CB'+aCB[1]);
				if(cb){
					cb.checked = true;
					fSetRowColor(aCB[1]);
					$('tblRow'+aCB[1]).setStyles({'background-color': '#ededed'});
				}
			}
			break
		case '4':
			for(var i=1;i<table.rows.length;i++){
				var row = table.rows[i];
				var aCB = row.id.split('tblRow');
				var cb = document.getElementById('CB'+aCB[1]);
				if(cb){
					cb.checked = false;
					fSetRowColor(aCB[1]);
					$('tblRow'+aCB[1]).setStyles({'background-color': $('tblRow'+aCB[1]).getProperty('OrgBGClr')});
				}
			}
			fSetDDOption('selcb', '0');
		default:
			break
		}
	}
}
function fInitDataList(tblID){
	TblRow = $$('.tblRowClrChange');
	TblRow.each(function(element) {
		element.setProperties({'OrgBGClr': element.getStyle('background-color')});
		element.setProperties({'CurrBGClr': element.getStyle('background-color')});
		element.addEvent('mouseenter', function(){
			element.setStyles({'background-color': '#ffff00'});
		});
	 
		element.addEvent('mouseleave', function(){
			element.setStyles({'background-color': element.getProperty('CurrBGClr')});
		});
	});


	var table = document.getElementById(tblID);
	if(table){
		for(var i=1;i<table.rows.length;i++){
			var row = table.rows[i];
			var aCB = row.id.split('tblRow');
			var cb = document.getElementById('CB'+aCB[1]);
			if(cb){
				fSetRowColor(aCB[1]);
				if(cb.checked){
					$('tblRow'+aCB[1]).setStyles({'background-color': '#ededed'});
				}
				else{
					$('tblRow'+aCB[1]).setStyles({'background-color': $('tblRow'+aCB[1]).getProperty('OrgBGClr')});
				}
			}
		}
	}
}
//Functions for Listing Data



//Functions for a Multi-Select box move over
function fClearList(OptionList, TitleName){
	OptionList.length = 0;
}
			
function fMoveDirection(side,vel1,vel2,vel2Empty,vel2HasContent,currentUserID)
{
	var temp1 = new Array();
	var temp2 = new Array();
	var tempa = new Array();
	var tempb = new Array();
	var current1 = 0;
	var current2 = 0;
	var y=0;
	var attribute1;
	var attribute2;	
	var SelVel2Empty = null;
	var SelVel2HasContent = null;
	var ContentLength = 0;	
	//assign what select attribute treat as attribute1 and attribute2
	if (side == "right"){
		attribute1 = document.getElementById(vel1);
		attribute2 = document.getElementById(vel2);
	}
	else{
		attribute1 = document.getElementById(vel2);
		attribute2 = document.getElementById(vel1);
	}
	
    if ( vel2Empty != null )
	    SelVel2Empty = document.getElementById(vel2Empty);
	    
	if ( vel2HasContent != null )
	    SelVel2HasContent = document.getElementById(vel2HasContent);
	    		
	//fill an array with old values
	for (var i = 0; i < attribute2.length; i++){
		y=current1++
		temp1[y] = attribute2.options[i].value;
		tempa[y] = attribute2.options[i].text;
	}
			
	//assign new values to arrays
	for (var i = 0; i < attribute1.length; i++){
		if ( attribute1.options[i].selected ){
			y=current1++
			temp1[y] = attribute1.options[i].value;
			tempa[y] = attribute1.options[i].text;
		}
		else{
			y=current2++
			temp2[y] = attribute1.options[i].value; 
			tempb[y] = attribute1.options[i].text;
		}
	}
				
	//generating new options 
	for (var i = 0; i < temp1.length; i++){
		if(temp1[i] != ''){
			attribute2.options[i] = new Option();
			attribute2.options[i].value = temp1[i];
			attribute2.options[i].text =  tempa[i];
			attribute2.options[i].selected = true;
		}
	}
	
	
				
	//generating new options
	fClearList(attribute1,attribute1);
	if (temp2.length>0){
		for (var i = 0; i < temp2.length; i++){
			if(temp2[i] != ''){
				attribute1.options[i] = new Option();
				attribute1.options[i].value = temp2[i];
				attribute1.options[i].text =  tempb[i];
			}
		}
	}
	
	if (side == "right")
	    ContentLength = temp1.length;
	else
	    ContentLength = temp2.length;

	if (ContentLength <= 0)
	{
	    if(SelVel2Empty != null)
	        SelVel2Empty.checked = true;
        if(SelVel2HasContent != null)
            SelVel2HasContent.checked = false;
    }
    else
    {
        var txt; 
        
        if (side == "right")
	        txt = attribute2.options[0].value;
	    else
	        txt = attribute1.options[0].value;

        if (ContentLength == 1 &&  txt.length > 2 && txt.substring(txt.indexOf(':') + 1, txt.length ) == currentUserID )
        {
            if(SelVel2Empty != null)
	            SelVel2Empty.checked = true;
            if(SelVel2HasContent != null)
                SelVel2HasContent.checked = false;
        }
        else
        {
            if(SelVel2Empty != null)
	            SelVel2Empty.checked = false;
            if(SelVel2HasContent != null)
                SelVel2HasContent.checked = true;
        }
    }
}

function fSelAllSelectOptions(SelBoxID)
{
    if ( SelBoxID == null )
        return;
        
    var SelBox = document.getElementById(SelBoxID);    
    
    for (var i = 0; i < SelBox.options.length; i++)
    {
        SelBox.options[i].selected = true;
	}
}


function fConfirmLister(Fn){
	var FNele = document.getElementById(Fn);
	var ConfirmFNbtn = document.getElementById('Confirm__'+Fn);
	var ClearFNbtn = document.getElementById('Clear__'+Fn);
	if(FNele){
		if(FNele.length > 0){
			for(var i=0;i<FNele.length;i++){
				FNele.options[i].selected = true;
			}
		}
		else{
			FNele.options.length = 0;
		}
	}
	if(ConfirmFNbtn){
		ConfirmFNbtn.disabled = true;
	}
}

function fClearLister(Fn){
	var FNele = document.getElementById(Fn);
	var ConfirmFNbtn = document.getElementById('Confirm__'+Fn);
	var ClearFNbtn = document.getElementById('Clear__'+Fn);
	if(FNele){
		for(var i=0;i>FNele.length;i++){
			fMoveDirection('left',Fn+'__Lister',Fn);
		}
		fClearList(FNele,FNele);
		
		FNele.length = 0;
		//FNele.options[0] = new Option();
		//FNele.options[0].value = '';
		//FNele.options[0].text =  '';
		//FNele.options[0].selected = true;
	}
	if(ConfirmFNbtn){
		ConfirmFNbtn.disabled = false;
	}
}
//Functions for a Multi-Select box move over






