/**
 *  As part Asyn messaging the returning string is 
 *  multi-dimensional or expanded delimeter string.
 */
var eEngDel0='e175;';
var eEngDel1='e176;';
var eEngAsynLoc='eEngArea51';
var eEngAsynWaiting=false;

function eEngWindowOpen(aPath, aName, aAttrSet) {
   /*window.open(aPath,aName,'toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes');*/
  var w=900;
  var h=800;

   var left = (screen.width/2)-(800/2);
   var top = (screen.height/2)-(600/2);
   var targetWin = window.open (aPath, "title", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);

}
function eEngOpenPrintWindow(){
    alert('Would you like to print and generate a printer friendly version?');
     var wk = document.URL + "&r=eEngPrintVersion";
    eEngWindowOpen(wk,'','');
}

/**/
/** -Start of Form Object eFormObjects[] -----------*/
/**/
/* Used in the Asyn loop for the form post. ie: Checkbox*/
var eEngFrmWk1='';
/* This is the resonse from the eAsyn post for aja{x}*/
var eEngFrmResponse='';
/**
 *This is is only for forms. It already has been moved to the eng_sys_jscript table.
 * */
var http_request = false;
/**
 * This is the first test for asyn. It is used for the login form only at this time.
 *
 * @param obj The form object pointer
 * @param loc The url to do the post.
 */
function eEngGet(obj,loc) {
	var poststr=eEngGetFormValues(obj,'');
	eEngMakePOSTRequest(loc, poststr);
}
/** 
 * This does the dom post to the application server.
 *
 * @param url The location of the post
 * @param parameters Parameters to ammend for the post.
 */
function eEngMakePOSTRequest(url, parameters) {
    //alert('at post' + url + " " + parameters);
	eEngAsynWaiting=false;
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			http_request.overrideMimeType('text/html');
		} catch (e) {
			try {

				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = eEngAlertContents;
	http_request.open('POST', url, true);

	http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function eEngAlertContents() {
	//alert('wait');
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			eEngAsynWaiting=true;
			//alert(http_request.responseText);
            //eEngFrmResponse = http_request.responseText;
			document.getElementById(eEngAsynLoc).innerHTML = http_request.responseText;
			//document.getElementById(eEngAsynLoc).innerHTML = "";
			//alert("a: " + " " + eEngAsynLoc);
			//document.getElementById(eEngAsynLoc).innerHTML = eEngFrmResponse;
		} else {
			eEngFrmResponse="error";
			eEngAsynWaiting=true;
			alert('There was a problem with the request.' + ' State' + http_request.readyState + ' status:' + http_request.status );
		}
	}
}
function eEngPopulateObject(aLoc,aStr){
	//document.getElementById(aLoc).innerHTML = '';
	document.getElementById(aLoc).innerHTML = aStr;
}
function eEngGetFormValues(fobj, valFunc){
	var str = "";
	var valueArr = null;
	var val = "";
	var cmd = "";
	eEngFrmWk1='';

	for (var i = 0;i < fobj.elements.length;i++) {


		switch (fobj.elements[i].type) {

		case "text":
			if (valFunc) {
				//use single quotes for argument so that the value of
				//fobj.elements[i].value is treated as a string not a literal
				cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
				val = eval(cmd)
			}
			str += fobj.elements[i].name +
				   "=" + escape(fobj.elements[i].value) + "&";
			break;
		case "password":
			str += fobj.elements[i].name +
				   "=" + escape(fobj.elements[i].value) + "&";
			break;
		case "select-one":
			str += fobj.elements[i].name +
				   "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
			break;
		}
	}
	str = str.substr(0,(str.length - 1));
	return str;
}
function eEngAsynOptionBoxes(fobj, valFunc){
	var str = "";
	for (var i = 0;i < fobj.elements.length;i++) {
		//alert(fobj.elements[i].type);
		switch (fobj.elements[i].type) {
		case "checkbox":
			//str += fobj.elements[i].name +
			//"=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
			//alert("Checkbox");
			if (fobj.elements[i].checked == true) {
				if (str.length > 0) {
					str += eEngDel1;
				}
				str += fobj.elements[i].value;
				//str += fobj.elements[i].name + "= 1" + "&";
				//alert("C: " + str);


			} else {
				//alert("Checkbox is not checked");
			}
			break;

		}
		//alert(str);eEngDel1
	}
	return str;
}

/**/
/** ---- End Of Form Object -----------*/
/**/

/*
  The user interface has a debugging window to assist in the writing of
  javascript. It can be activated with proper permission in the user controls.
*/
function writeDebugElement(msg, element) {
	writeElement(msg, element);
}
/*

*/
function writeElement(msg, element) {
	//eEle = document.getElementById(element);
	//eEle.innerHTML = eEle.innerHTML + msg + '<br>';
}

/*
  This function turns on displays for objects (span/div). It is called
  throughout the overall system and is included in all generated pages.
*/
function eHideAndExpand(which, the_change){
//alert(which + " " + the_change);

	var wk = which + " - " + the_change + " Made It To Hide and Expand"
	var the_style = getStyleObject(which);
	if (the_style != false) {
		the_style.display = the_change;
	}
}
function eEngHAE(which, the_change){
//alert(which + " " + the_change);

	var wk = which + " - " + the_change + " Made It To Hide and Expand"
	var the_style = getStyleObject(which);
	if (the_style != false) {
		the_style.display = the_change;
	}
}
/*
  This function get the object from the browser stack.
*/
function getStyleObject(objectId) {
	if (document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else {
		return false;
	}
}
/*
  This set of functions are only included for forms generation. There
  is an object in the engine to forse these to get loaded. eFormsBaseFieldValidators
*/
function valFormField(aObj, aId, aFlg, aRule, aType,  aMin, aMax, aMsg) {
	//alert ('tjos os a test');
	doValFormField( aRule, aType);
	aObj.focus;

}
function doValFormField(aRule, aType){
	var ok=0;
	switch (aType) {
	case 'string': ok=1;
		valFormFieldString();
	case 'int': ok=1;
		break;
	case 'short':ok=1;
		break;
	case 'boolean': ok=1;                                                                               
	default: result = 'unknown';
		alert ('Unknow aType(' + aType + ') - doValFormFields');

		if (ok==1) {
		}
	}

}
function valFormFieldString(aRule, aType, aMin, aMax, aMsg) {

}
function checkNotNull(aRule) {
}
/*
  ***
  This area is for testing misc javascript inserts to add to the visual
  majic. Specific objects rule names will be assigned to tell the generator
  to insert this object during the generation.
  ***
*/

/*
  updateClock manages a realtime clock.
  <span id="eEngClock">&nbsp;</span>

  syn: eEngJSRealTimeClock

*/


function xx(id, aAction, msg){
// Testing For Matrix Form
	//alert("A properties block should appear" + " " +id + aAction);
	eHideAndExpand("eEngMatrix-basic","none");
	eHideAndExpand("eEngHd0-basic","none");
	eHideAndExpand("eEngHd1-basic","none");
	eHideAndExpand("eEngHd0Lnk-basic","none");
	eHideAndExpand("eEngLm0-basic","none");
	eHideAndExpand("eEngUsrCtrl-basic","none");
	eHideAndExpand("eEngArea51-basic","none");
	eHideAndExpand("eEngRm0-basic","none");
	eHideAndExpand("eEngFt0-basic","none");
	eHideAndExpand("eEngSg0-basic","none");

	eHideAndExpand(id,aAction);
}



/**
 * This does an asyn call to the application server.
 *
 * @param aStr
 * @param aLoc
 */
function eDoAsyn(loc, poststr, where){
	eEngMakePOSTRequest(loc, poststr);
}
/**
 * This parses a string and ruturns the value that was parsed.
 * 
 * @param aRle
 * @param aInStr
 * @param aLoc
 * @param aDel
 */
function eEngField(aRle, aInStr, aLoc, aDel){

}








