//
//102 added _QuerySearchClick
//103 added _VWrite
//104 added _BitMap2Array and Array2Bitmap (called by Maptoc)
//105 'JS Enc
//106 'Arr to _Arr but redirected Arr to _Arr -removed an apparently spurious SetMapMode
//107 Look for _EL before postback  
//108 Fix Moz sniffer
//109 Force -EL to true in postbacktonamedtarget -adds _NullArr
//110 Translucent shading on VML poly
//111 EWrite
//112 _GSel 
//113 postback image
//114 -delete extra semi-colons from try-catch blocks 


function _PostBack(sSource,sName,aArgs){
if(window._EL){
//alert('_PostBack=' + sSource + ' ev=' + sName);
try{document.getElementById('elPB').style.visibility='visible';}catch(ex){}
try{document.getElementById('txPB').innerHTML = 'Working. Please Wait...';}catch(ex){}
_BuildPostBack(sSource,sName,aArgs);
_GetTargetForm().submit();
}
else{
	alert('Sorry, the page has not yet loaded. Please wait a few moments and try this operation again.');
    }
}



function _BuildPostBack(sSource,sName,aArgs){
//var frm = document.forms[0];
_GetTargetForm().elements['app-e'].value = _BuildEventXml(sSource,sName,aArgs);
}

function _BuildEventXml(sSource,sName,aArgs){
var sXML = '<emaml_event source="' + sSource + '" name="' + sName + '"';
if(aArgs+ '' != 'undefined'){
	var i=0;
	//alert('arglen=' + aArgs.length + ' 0=' + aArgs[0]);
	for(i=0;i<aArgs.length;i++)
		sXML = sXML + ' a' + i + '="' + aArgs[i] + '"';
}
return sXML + '/>';
}

function _PBS(objID, elName, bUseText)
//pbs=postbackselection 
{
var sValue = _GSel(objID + '_' + elName,bUseText)
//alert('PostBackSelection ' + objID + elName + '  value=' + sValue);
_PostBack(objID,elName + '_onchange', Arr(sValue));
}


function _GetTargetForm(){
if(('undefined' != window.opener + '') && ('null' != window.opener + ''))
	return window.opener.document.forms[0];
else
	return document.forms[0];
}


function _PopForm(sFormID){
var winPop = _OpenWin(sFormID);
_PostBackToNamedTarget(sFormID,'App','ShowForm',Arr(sFormID));
}

function _Arr(Item){
var arrayNew = new Array(1);
arrayNew[0] = Item;
return arrayNew;
}

//will migrate to _Arr as other libs are updated so we need this for a while
function Arr(Item){
return _Arr(Item);

}

function _QueryTxKeyDown(sSource,sName,fPopUp){
var ev = window.event;
if(ev.keyCode==13){
	ev.returnValue=false;
	if(fPopUp){
		var winPopUp = _OpenWin('PopUp');
		_PostBackToNamedTarget('PopUp',sSource,sName);
	}
	else
		_PostBack(sSource,sName);
	}
}

function _QuerySearchClick(sSource, sName, fPopUp){
	if(fPopUp){
		var winPopUp = _OpenWin('PopUp');
		_PostBackToNamedTarget('PopUp',sSource,sName);
	}
	else
		_PostBack(sSource,sName);

}

function _OpenWin(sName){
	var winOpen = window.open('',sName,'left=100,top=100,height=200,width=300,menubar=no,toolbar=no,resizeable=yes,scrollbars=yes');
	var doc = winOpen.document;
	doc.open();
	doc.write('<html><body><font face="arial" size="1">Loading...</font></body></html>');
	doc.close();
	return winOpen;
}

function _PostBackToNamedTarget(sTarget,sSource,sName,aArgs){
window._EL = true; //@109
document.forms[0].target=sTarget;
_PostBack(sSource,sName,aArgs);
document.forms[0].target = '';
}

function _CopyForm(doc){
var frm = document.forms[0];
var el = null;

for(var i = 0; i < frm.elements.length ; i++){
	el = frm.elements[i];
	if(el.name.indexOf('-')>0)
		doc.write('name=' + el.name + '<input name="' + el.name + '" type="xhidden" value="' + el.value + '"><br>');
	}
}

function _GetElName(objEL,ChildName){
return objEL.ID + '_' + ChildName;
}


function _VWrite(sName){
//document.write('<script'  + '>alert("hello")<' + '/script>' );
document.write('<' + 'XML:NAMESPACE NS="urn:schemas-microsoft-com:vml" PREFIX="v"/' + '>');
document.write('<' + 'v:shape id="' + sName + '"  fillcolor="yellow" strokecolor="blue"  coordorigin="0 0" coordsize="992 799" Style ="position:absolute;top:1;left:1;width:992;height:799" z-order="100" '  + '>')
document.write('<' + 'v:fill opacity="50%" /' + '>');  
document.write('<' + '/v:shape' + '>'); 
}

function _BitMap2Array(sData){
var arr = new Array(sData.length-1);
for(var i=0;i<sData.length;i++)
	arr[i] = (sData.charAt(i)=='1')
return arr;
}
function _Array2BitMap(arr){
var sBitMap = '';
for(var i=0;i<arr.length;i++)
	sBitMap = sBitMap + arr[i]*1;
return sBitMap;
}

function _NullArr(lLength){
var arr = new Array(lLength);
for(var i=0;i<lLength;i++)
	arr[i] = '';
return arr;
}

function _EWrite(sEnt,iRepeat){
for(var i = 0;i<iRepeat;i++)document.write('&' + sEnt + ';');
}

function _GSel(sName,bUseText){
var el = document.forms[0].elements[sName];
if(bUseText)
	return el.options[el.selectedIndex].text;	
else
	return el.options[el.selectedIndex].Value;
}





