function stopEnterKeyEvent(evt){
	if (!evt) evt = window.event;
	var srcElm = null;
	if(evt.keyCode == 13) {
		try { 
			if(evt.srcElement) {
				srcElm = evt.srcElement;
			} else {
				srcElm = evt.target;
			}
		} catch(err) {}
		
		if(!(srcElm.type == "textarea")){
			evt.cancelBubble = true;
			if (evt.stopPropagation) evt.stopPropagation();
			try {
				evt.preventDefault = new Function("this.returnValue = false");
				evt.stop(evt);
			}catch(err){
			}
			return false;
		}
	}
	return true;
}

function stopAnyKeyEvent(evt){
	if (!evt) evt = window.event;
	var srcElm = null;
	
	try { 
		if(evt.srcElement) {
			srcElm = evt.srcElement;
		} else {
			srcElm = evt.target;
		}
	} catch(err) {}
	
	evt.cancelBubble = true;
	if (evt.stopPropagation) evt.stopPropagation();
	try {
		evt.preventDefault = new Function("this.returnValue = false");
		evt.stop(evt);
	}catch(err){
	}
	return false;
	
}


function stopEnterKeyEventWithSubmit(evt){
	if (!evt) evt = window.event;
	if(evt.keyCode == 13) {
		submit_form();
		
		evt.cancelBubble = true;
		if (evt.stopPropagation) evt.stopPropagation();
		try {
			evt.preventDefault = new Function("this.returnValue = false");
			evt.stop(evt);
		}catch(err){
		}
		//return false;
	}
	return true;
}

function stopEnterKeyEventWithResultSubmit(evt){
	if (!evt) evt = window.event;
	
	if(evt.keyCode == 13) {
		submit_form("result");
		
		evt.cancelBubble = true;
		if (evt.stopPropagation) evt.stopPropagation();
		try {
			evt.preventDefault = new Function("this.returnValue = false");
			evt.stop(evt);
		}catch(err){
		}
		//return false;
	}
	return true;
}

function attachToID(destID, evtType, func, submitAfter){
	//alert(destID);
	try { 
		document.getElementById(destID).attachEvent(evtType,eval(func),submitAfter); 
	} catch (err) {
		try {
			evtType = evtType.replace(/on/i, "");
			document.getElementById(destID).addEventListener(evtType,eval(func),submitAfter);
		} catch (err) {
		}
	}
	
}

function attachToElm(elm, evtType, func, submitAfter){
	//alert(elm.id + " - " + elm.name)
	try { 
		elm.attachEvent(evtType,eval(func),submitAfter); 
	} catch (err) {
		try {
			evtType = evtType.replace(/on/i, "");
			elm.addEventListener(evtType,eval(func),submitAfter);
		} catch (err) {
		}
	}
}


function checkForNoNumbers(obj){
	if(obj.value.search(/[^0-9]/) != -1){
		obj.value = obj.value.replace(/[^0-9]/g,'')
	}
}

/////////////////////////////////////////


/*function stopEnterKeyEvent(evt){
	if (!evt) evt = window.event;
	if(evt.keyCode == 13) {
		evt.cancelBubble = true;
		if (evt.stopPropagation) evt.stopPropagation();
		try {
			evt.preventDefault = new Function("this.returnValue = false");
			evt.stop(evt);
		}catch(err){
		}
		return false;
	}
}*/

/*function stopEnterKeyEventWithSubmit(evt){
	if (!evt) evt = window.event;
	//window.status = evt.keyCode;
	if(evt.keyCode == 13) {
		submit_form();
		
		evt.cancelBubble = true;
		if (evt.stopPropagation) evt.stopPropagation();
		try {
			evt.preventDefault = new Function("this.returnValue = false");
			evt.stop(evt);
		}catch(err){
		}
		//return false;
	}
}*/

/*function stopEnterKeyEventWithResultSubmit(evt){
	if (!evt) evt = window.event;
	//window.status = evt.keyCode;
	if(evt.keyCode == 13) {
		submit_form("result");
		
		evt.cancelBubble = true;
		if (evt.stopPropagation) evt.stopPropagation();
		try {
			evt.preventDefault = new Function("this.returnValue = false");
			evt.stop(evt);
		}catch(err){
		}
		//return false;
	}
}*/


function show_cursor( pvThis, pvCursor )
{
  if( top.frames != undefined )  
    for( var i=0; i<top.frames.length; i++ )
    {
      top.frames[i].document.body.style.cursor = pvCursor;
    }

  with( pvThis )
  {
    document.body.style.cursor = pvCursor
    for( var i=0; i<document.all.length; i++ )
    {
      divTag = document.all[i]
      if ( ( pvCursor == 'auto' || pvCursor == 'default' || pvCursor == 'normal' ) && ( divTag.id.indexOf( 'TAB' ) != -1 || divTag.id.indexOf( 'BTN' ) != -1 ) )
        divTag.style.cursor = 'hand'
      else
        divTag.style.cursor = pvCursor
    }
  }
}

function callURL( vUrl )  // // Modified by Bhavna on 8/19/2003: changed the function for "undefined" checks on formfields
{
  document.all ? document.body.style.cursor= 'wait' : "" ;	
  with( top.userFrame.document.forms[0])
  {
    action = vUrl;
    target = "_self"
    submit();
  }
}

function isFieldNull( pvField )
{ 
  var nCount = 0
  if ( pvField == "0" )
    return true;
  if ( pvField == "" )
    return true;
  if ( pvField == null )
    return true;
  if ( pvField == "null" )
    return true;
  else  
  {
    for( var nCnt=0; nCnt<pvField.length; nCnt++ )
    {
      if ( pvField.charAt(nCnt) == " " )
        nCount++
    }
    if ( nCount == pvField.length )
      return true;

    for( var nCnt=0; nCnt<pvField.length; nCnt++ )
    {
      if ( pvField.charAt(nCnt) == "0" )
        nCount++
    }
    if ( nCount == pvField.length )
      return true;
    else
      return false;
  } 
}

function isNum( pnNum ) 
{
  var nCnt
  var cCharCode;
  if ( !isFieldNull( pnNum ) ) 
  {
    for( var nCnt=0; nCnt<pnNum.length; nCnt++ ) 
    {
      cCharCode = pnNum.charCodeAt(nCnt)
      if( cCharCode<48 || cCharCode>57 ) 
      {
      	  return false;
      } 
    } 
  }
  return true;
}

function isAlphaNumOnly( pnNum )
{
  var nCnt
  if ( isFieldNull( pnNum ) ) 
  {
    return false;
  }
  else
  {
    var vStr = pnNum;
    while (vStr.substring(0,1) == ' ')      // For removing leading blanks
      vStr = vStr.substring(1);
    while (vStr.substring(vStr.length-1,vStr.length) == ' ')  // For removing trailing blanks
      vStr = vStr.substring(0,vStr.length-1);
    pnNum = vStr;
    for( var nCnt=0; nCnt<pnNum.length; nCnt++ ) 
    {
      if ( pnNum.charCodeAt(0) < 65 || (pnNum.charCodeAt(0) > 90 && pnNum.charCodeAt(0) < 97) || pnNum.charCodeAt(0) > 122)
      {
        return false;
      }
      else
      {
        cCharCode = pnNum.charCodeAt(nCnt)
        if ( cCharCode == 32 )
        {
          return false;
        }
        if( cCharCode < 48 || (cCharCode > 57 && cCharCode < 65) || (cCharCode > 90 && cCharCode < 95) || (cCharCode > 95 && cCharCode < 97) ||cCharCode > 122 ) 
        {
          return false;
        } 
      }
    } 
  }
  return true;
}

  function sign_out()
  {
    with( document.forms[0] )
    {
      action = "./login.do?mode=logout";
      try 
      {
      	mode.value = "logout"; 
      }
      catch(err) 
      {
      }
  	  //target = this.name;
      submit();
    }
  } 

function show_calender( pDateField )
{ 
  var nd = new Date()
  var dd = nd.getDate()
  var mm = nd.getMonth()
  var yy = nd.getYear()
  var date

  var formname = top.userFrame.document.forms[0].name;                
  var str = "top.userFrame.document." + formname + "." + pDateField.name;
  top.topFrame.document.APPLE1.m_calender.setParent(str) 

  if( pDateField.value == "" ) {
    date = dd + "." + mm + "." + yy
    top.topFrame.document.APPLE1.m_calender.showCalender( date, 1 )
  }
  else {
    date = pDateField.value
    top.topFrame.document.APPLE1.m_calender.showCalender( date, 0)
  } 
  top.topFrame.document.APPLE1.m_calender.initialize( 0 )
}

function arrange_table( pvRef )
{
  var i, j, max=0, wt=0;
  with( pvRef )
  {
    var topTable = document.all ? document.all['tblTop'] : document.getElementById('tblTop');
    var bottomTable = document.all ? document.all['tblBottom'] : document.getElementById('tblBottom');
  
    if ( ( bottomTable.rows(1) != null ) && ( bottomTable.rows(1).cells.length == 1 ) )
    {
      return;
    }

    for ( i=0; i < topTable.rows(0).cells.length; i++ )
    {
      if ( typeof(tblTop.rows(0).cells(i)) != 'undefined' || typeof(tblTop.rows(0).cells(i)) != null )
      {
        max = tblTop.rows(0).cells(i).clientWidth;
        for(j=1; j<tblBottom.rows.length; j++)
        {
          if ( typeof(tblBottom.rows(j).cells(i)) != 'undefined' && typeof(tblBottom.rows(j).cells(i)) != null )
          {
            wt = tblBottom.rows(j).cells(i).clientWidth;
            if( wt > max ) max = wt;
          }
        }
        tblTop.rows(0).cells(i).style.width = (max-6);
        for( j=1; j<tblBottom.rows.length; j++ )
        {
          tblBottom.rows(j).cells(i).style.width = (max-6);
        }
        document.all['tblTop'].width = document.all['tblBottom'].clientWidth-1
      }
    }
  }
}

function call_lov_window()
{
  var lovWin = window.open( "", "lovWin", "left=280,top=175,width=600,height=465,resizable=1,toolbar=no" );
  return lovWin;
}

function BrowserConfig()
{
  this.appName = navigator.userAgent;
  this.appVer  = navigator.appVersion;
  this.dom  = document.getElementById ? 1 : 0;
  this.ostype = "UN";
  this.bwinfo = "";
  this.flashInfo = "";
  this.audInfo = "";

  this.type = ( this.appName.indexOf( 'MSIE' ) != -1 ? 'IE' : ( this.appName.indexOf( 'Netscape' ) != -1 || this.appName.indexOf( 'Navigator' ) != -1 )? 'NN' : this.appName.indexOf( 'Firefox' ) != -1 ? 'FF': this.appName.indexOf( 'Safari' ) != -1 ? 'SF' : 'UN' );

  if( this.type == 'IE' )
  {
    this.verno = this.appVer.indexOf( "MSIE 5.5" ) > -1 ? '5.5' : this.appVer.indexOf( "MSIE 6.0" ) > -1 ? '6.0' : this.appVer.indexOf( "MSIE 7.0" ) > -1 ? '7.0' : '0.0';
    this.bwinfo = "Microsoft Internet Explorer ( Version " + this.verinfo + " )";
    this.verinfo = this.verno;
  }
  else if( this.type == 'NN' ) 
  {
    this.verinfo = navigator.userAgent.split('/')[4];
    this.bwinfo = "Netscape Navigator ( Version " + this.verinfo + " )";
    this.verno = parseInt( this.verinfo );
  }
  else if( this.type == 'FF' ) 
  {
    this.verinfo = navigator.userAgent.split('/')[3];
    this.bwinfo = "Mozilla Firefox ( Version " + this.verinfo + " )";
    this.verno = parseInt( this.verinfo );
  }
  else if( this.type == 'SF' ) 
  {
    this.verinfo = navigator.userAgent.split('/')[3];
    this.verinfo = this.verinfo.replace( " Safari", "" );
    this.bwinfo = "Safari ( Version " + this.verinfo + " )";
    this.verno = parseInt( this.verinfo );
  }

  if ( this.appVer.indexOf( "Win" ) != -1 )
  {
    this.osname = "Microsoft Windows";
    this.ostype = "WIN";
  }

  if ( this.appVer.indexOf( "Mac" ) != -1 )
  {
    this.osname = "Macintosh";
    this.ostype = "MAC";
  }

  if ( this.ostype == 'WIN' )
  {
	  this.ie = this.type == 'IE' && parseFloat( this.verno ) >= 5.5 && parseFloat( this.verno ) <= 7.0 && this.dom ? 1 : 0;
	  this.ns = this.type == 'NN' && parseFloat( this.verno ) >  4.0 && parseFloat( this.verno ) <= 7.2 && this.dom ? 1 : 0;
	  this.ff = this.type == 'FF' && parseFloat( this.verno ) >= 1.0 && parseFloat( this.verno ) <= 3.0 && this.dom ? 1 : 0;
	  this.sf = 0
  }
  else if ( this.ostype == 'MAC' )
  {
      this.ie = 0
      this.ns = 0 
	  this.ff = this.type == 'FF' && parseFloat( this.verno ) >= 2.0 && parseFloat( this.verno ) <= 3.0 && this.dom ? 1 : 0;
	  this.sf = this.type == 'SF' && parseFloat( this.verno ) >= 3.0 && parseFloat( this.verno ) <= 3.0 && this.dom ? 1 : 0;
  }
  
  return this
}

var bw = new BrowserConfig();

function show_object( pvLayerID )
{
  if ( isObjectExists( pvLayerID ) )
  {
    if ( bw.dom )
    {
      document.getElementById(pvLayerID).style.visibility = "visible"
    }
  }
}

function hide_object( pvLayerID )
{
  if ( isObjectExists( pvLayerID ) )
  {
    if ( bw.dom )
    {
      document.getElementById(pvLayerID).style.visibility = "hidden";
    }
  }
}

function isObjectExists( pvLayerID )
{
  var bExistFlag = true;

  if ( bw.dom )
  {
    if ( document.getElementById( pvLayerID ) == undefined || document.getElementById( pvLayerID ) == "undefined" || document.getElementById( pvLayerID ) == null )
    {
      bExistFlag = false
    }
  }

  return bExistFlag;
}


//added by tschroeder at 08.04.2008
function pack( object ){
	object.setVirtualMode(true);
	headerHeight = object.getHeaderHeight();
	rowHeight = 21; //object.getRowHeight();
	rowCount = object.getRowCount();
	windowHeight =  document.body.clientHeight - 300; //document.body.clientHeight; //was - 300
	var newHeight = (headerHeight + (rowHeight * rowCount));
	if(newHeight < windowHeight){ try { object.setStyle("height", newHeight+75); } catch(err){} } //was newHeight+25
	else { object.setStyle("height", "100%"); }
    object.refresh(); 
}

function resizeColumns( awObject ){
	//alert(1);
	//alert(awObject.width)
	//awObject.setVirtualMode(true);
//	clientWidth = window.innerWidth;
	var windowWidth = window.innerWidth;
	if(windowWidth == undefined) {
		windowWidth = document.documentElement.clientWidth;
		if(windowWidth == 0){
			windowWidth = document.body.clientWidth;  
		}
	}
	var clientWidth = ((windowWidth/100)*85);
	/*if(clientWidth == undefined || clientWidth == 0 || clientWidth == null){
		document.body.clientWidth - 400;
	}*/
	colCount = awObject.getColumnCount();
	
	newWidth = (clientWidth/colCount);
	
	for(i=0;i<colCount;i++){
		/*alert(newWidth);*/
		awObject.setColumnWidth(newWidth, i); 
	}
	
	awObject.refresh();
	
}

function function_setFocus(){
	try {
		for(i=0;i<document.forms[0].elements.length;i++){
			if((document.forms[0].elements[i].type == 'text' 
					|| document.forms[0].elements[i].type == 'textarea' 
					|| document.forms[0].elements[i].type == 'select-one') 
				&& document.forms[0].elements[i].name != 'goto' 
				&& !document.forms[0].elements[i].disabled){
				try {
					document.forms[0].elements[i].focus();
					break;
				} catch(err){
					
				}
			}
		}
	} catch(err){
		
	}
}

function chkFuncCode(result, code) {
	var newCode = "";
	if(code.split(/ /gi).length > 1) {
		for(i=0;i<code.split(/ /gi).length; i++) {
			var tmpCode = code.split(/ /gi)[i];
			var onEnd = "";
			if(tmpCode.search(/\(/) == 0) {
				newCode += "(";
				tmpCode = tmpCode.substring(1,tmpCode.length);
			}
			if(tmpCode.search(/\)/) == tmpCode.length-1) { 
				onEnd = ")";
				tmpCode = tmpCode.substring(0,tmpCode.length-1);
			}
			if(tmpCode.search(/\"/gi) != -1 || tmpCode.search(/\'/gi) != -1) {
				newCode += tmpCode;
			} else {
				if(tmpCode == "{RESULT}") {
					newCode += "\""+result+"\"";
				} else if(tmpCode.search(/{/) == 0 && tmpCode.search(/}/) == (tmpCode.length-1)) {
					tmpCode = tmpCode.replace(/{/, "").replace(/}/, "");
					newCode += "\""+eval(tmpCode)+"\"";
				} else if(tmpCode == "||") {
					newCode += "||";
				} else if(tmpCode == "&&") {
					newCode += "&&";
				} else if(tmpCode == "==") {
					newCode += "==";
				} else if(tmpCode == "!=") {
					newCode += "!=";
				} else if(tmpCode == ">=") {
					newCode += ">=";
				} else if(tmpCode == ">") {
					newCode += ">";
				} else if(tmpCode == "<=") {
					newCode += "<=";
				} else if(tmpCode == "<") {
					newCode += "<";
				} else {
					newCode += "\""+tmpCode+"\"";
				}
			}
			newCode += onEnd+" ";
		}
	} else {
		if(code == "{RESULT}") {
			newCode += "\""+result+"\" == \""+result+"\"";
		} else if(code.search(/{/) == 0 && code.search(/}/) == (code.length-1)) {
			code = code.replace(/{/, "").replace(/}/, "")
			newCode = "\""+result+"\" == \""+eval(code)+"\"";
		} else { 
			newCode = "\""+result+"\" == \""+code+"\"";
		}
		
	}
	return eval(newCode);
}

function getTextareaValue(nameOrID) {
	var textareaObj = null;
	var value = "";
	if(document.getElementsByName(nameOrID)[0]) {
		textareaObj = document.getElementsByName(nameOrID)[0];
	} else if(document.getElementById(nameOrID)) {
		textareaObj = document.getElementById(nameOrID);
	}
	
	if(textareaObj) {
		if(textareaObj.value) {
			value = textareaObj.value;
		} else if(textareaObj.innerHTML) {
			value = textareaObj.innerHTML;
		}
	}
	return value;
}

function setTextareaValue(nameOrID, value) {
	var textareaObj = null;
	if(document.getElementsByName(nameOrID)[0]) {
		textareaObj = document.getElementsByName(nameOrID)[0];
	} else if(document.getElementById(nameOrID)) {
		textareaObj = document.getElementById(nameOrID);
	}
	
	if(textareaObj) {
		if(textareaObj.value) {
			textareaObj.value = value;
		} else if(textareaObj.innerHTML) {
			textareaObj.innerHTML = value;
		}
	}
}

function getValidatedText(result, text) {
	var resultText = "";
	var tmpText = "";
	//text = text.replace(/</gi, "&lt;").replace(/>/gi, "&gt;")
	for(i=0;i<text.split(/ /gi).length; i++) {
		/*var onEnd = "";
		if(tmpText.search(/\(/) == 0) {
			resultText += "(";
			tmpText = tmpText.substring(1,tmpText.length);
		}
		if(tmpText.length>1 && tmpText.search(/\)/) == tmpText.length-1) { 
			onEnd = ")";
			tmpText = tmpText.substring(0,tmpText.length-1);
		}
		tmpText = text.split(/ /gi)[i];*/
		/*
		alert(1);
		if(tmpText == "{RESULT}") {
			resultText += ""+result+"";
		}  else if(tmpText.search(/{/) == 0 && tmpText.search(/}/) == (tmpText.length-1)) {
			tmpText = tmpText.replace(/{/, "").replace(/}/, "");
			resultText += ""+eval(tmpText)+"";
		}  else {
			resultText += ""+tmpText+"";
		}*/
		text = text.replace(/\r/g, "").replace(/\n/g,"&#13;").replace(/ /g, "#SCE#");
		if(text.search(/{RESULT}/g) != -1) text = text.replace(/{RESULT}/g, result);
		if(text.search(/{/g) != -1 && text.search(/}/g) != -1) {
			var tmpText0 = "";
			for(i=0;i<text.split(/{/g).length;i++) {
				var tmpText1 = text.split(/{/g)[i];
				if(tmpText1.search(/}/g) != -1) {
					for(j=0;j<tmpText1.split(/}/g).length;j++) {
						var tmpText2 = tmpText1.split(/}/g)[j];
						try {
							tmpText0 += eval(tmpText2);
						} catch(err) {
							tmpText0 += tmpText2;
						}
					}
				} else {
					tmpText0 += tmpText1;
				}
			}
			text = tmpText0;
		}
		
		resultText = text;
		
		//resultText += onEnd+" ";
		//alert("full: " + resultText);
	}
	return resultText.replace(/#SCE#/g, " ");
}

function checkForNormalCases(obj){
	try {
		if(obj.value.search(/ /) != -1) obj.value = obj.value.replace(/ /g,'_');
		if(obj.value.search(/=/) != -1) obj.value = obj.value.replace(/=/g,'_');
		//if(obj.value.search(/\?/) != -1) obj.value = obj.value.replace(/?/g,'_');
		if(obj.value.search(/[^0-z]/) != -1){
			obj.value = obj.value.replace(/[^0-z]/g,'')
		}
		obj.value = (obj.value+"").toUpperCase();
	} catch(err) {
	
	}
}

/*function textAreaTabulator(evt) {
	if (!evt) evt = window.event;
	var srcElm = null;
	var keyCode = evt.keyCode;
	
	
	try { 
		if(evt.srcElement) {
			srcElm = evt.srcElement;
		} else {
			srcElm = evt.target;
		}
	} catch(err) {
		alert("e01 -> " + err.message);	
	}
	
	^//alert(keyCode);
	if(keyCode == 9 /0*220*0/) {
		srcElm.style.color = "red";
		var selection = 0;
		if(srcElm.selection) selection = srcElm.selection;
		else if(srcElm.selectionStart) selection = srcElm.selectionStart;
		else return;
		
		srcElm.style.color = "blue";
		var idOrName = srcElm.id;
		if(!idOrName) idOrName = srcElm.name;
		
		srcElm.style.color = "green";
		var actValue = getTextareaValue(idOrName);
		var newValue = actValue.substr(0,selection) + "    " + actValue.substr(selection,actValue.length)
		
		srcElm.style.color = "orange";
		setTextareaValue(idOrName, newValue);
		
		srcElm.style.color = "black";
		
		evt.cancelBubble = true;
		if (evt.stopPropagation) evt.stopPropagation();
		try {
			evt.preventDefault = new Function("this.returnValue = false");
			evt.stop(evt);
		}catch(err){
		}
		return false;
	}
}*/


function openExportWindow(lobjID, lobjType) {
	showDivFrame('export.do?mode=export&lobjectID='+lobjID+'&lobjectType='+lobjType, "Export", 400, 200);
}

function isBlank(value) {
	if(value == null || value == undefined || value == 'undefined' || value == '') {
		return true;
	}
	return false;
}	

function getWindowWidth() {
	var windowWidth = window.innerWidth;
	if(isBlank(windowWidth)) {
		windowWidth = document.documentElement.clientWidth;
		if(windowWidth == 0) {
			windowWidth = document.body.clientWidth;  
		}
	}
	return parseInt(windowWidth);
}

function getWindowHeight() {
	var windowHeight = window.innerHeight;
	if(isBlank(windowHeight)) {	
		windowHeight = document.documentElement.clientHeight;
		if(windowHeight == 0) {
			windowHeight = document.body.clientHeight;                
		}
	}
	return parseInt(windowHeight);
}

function ajaxCall(url, parameter, wait, method) {
	if(url == undefined || url == "") return;
	//if(parameter == undefined) parameter = "";
	if(!method || method == "") method = "POST";
	if(!wait) wait = false; 
	var ajax = null;
	try {
		ajax = new XMLHttpRequest();
	} catch(err) {
		ajax = new ActiveXObject('Microsoft.XMLHTTP');
	}
	ajax.open(method, url, wait);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(parameter);
	return ajax.responseText;
}
