﻿// JScript File

function AlertMessage(CtrlValue, ErrNo, MinValue, MaxValue)
{
	var ErrStrg=new Array();
	ErrStrg[0]=CtrlValue;
	ErrStrg[1]=CtrlValue + ' ' + "should not be blank";
	ErrStrg[2]=CtrlValue + ' ' + "already exist, Duplicate not allowed";
	ErrStrg[3]=CtrlValue + ' ' + "should be between " + MinValue + " and " + MaxValue + "";
	ErrStrg[4]=CtrlValue + ' ' + "should be less than " + MinValue + "";
	ErrStrg[5]=CtrlValue + ' ' + "should be greater than " + MaxValue + "";
	ErrStrg[6]=CtrlValue + ' ' + "should be selected";	
	ErrStrg[7]="Invalid" + ' ' + CtrlValue;
	ErrStrg[8]=CtrlValue + ' ' + "record not found";
	ErrStrg[9]=CtrlValue + ' ' + ", Delete not allowed";
	ErrStrg[10]=CtrlValue + ' ' + ", Edit not allowed";
	ErrStrg[11]="Delete not allowed"; // Grid
	ErrStrg[12]="Edit not allowed"; //Grid
	ErrStrg[13]="Selected record does not exist, it may be already deleted"; // Grid
	ErrStrg[14]="Selected record does not exist, it may be already deleted, can not edit "; //Grid
	
	ErrStrg[15]=CtrlValue + ' ' + "should be less or equal to " + MinValue + "";
	ErrStrg[16]=CtrlValue + ' ' + "should be greater or equal to " + MaxValue + "";
	alert(ErrStrg[ErrNo]);
}

function SetFocus(c){
	document.getElementById(c).focus();
    return true;
}

 


function CheckNull(str)
{
	var s1=new String();
	var i,NoOfChars=0;
	s1=str;		    
	for(i=0;i<s1.length;i++)
	{
		if(s1.charAt(i)!=' ') 
			NoOfChars=NoOfChars+1;	
	}
	if(NoOfChars>0) 
		return true;
	return false;		
}

function OpenPopup(Path){           
           var strFeatures;          
           strFeatures = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=500px,width=650px,top=100px,left=200px';
           //window.showModalDialog(strURL,"","dialogHeight: "+Height+"px; dialogWidth: "+Width+"px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
           var win = window.open(Path,'EasyRules',strFeatures);
           if(win != null)
            win.focus();
           return false;
           }
           
function OpenNewPopup(Path){           
           var strFeatures; 
           if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
           { //test for MSIE x.x;
               var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
               if (ieversion>6)
                strFeatures = 'toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=500px,width=650px,top=100px,left=200px';
               else
                 strFeatures = 'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=500px,width=650px,top=100px,left=200px';
           }
           else
              strFeatures = 'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=500px,width=650px,top=100px,left=200px';

         
          // strFeatures = 'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=500px,width=650px,top=100px,left=200px';
           //window.showModalDialog(strURL,"","dialogHeight: "+Height+"px; dialogWidth: "+Width+"px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
           var win = window.open(Path,'_blank',strFeatures,false);
           if(win != null)
            win.focus();
           return false;
           }
function OpenNewLinkPopup(Path){           
           var strFeatures;          
           strFeatures = 'toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=500px,width=650px,top=100px,left=200px';
           //window.showModalDialog(strURL,"","dialogHeight: "+Height+"px; dialogWidth: "+Width+"px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
           var win = window.open(Path,'_self',strFeatures,false);
           if(win != null)
            win.focus();
           return false;
           }
function OpenHelpPopup(Path,FormName){
            var strURL;
           var strFeatures;
           strURL = Path + "?formname=" + FormName;
           strFeatures = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=400,width=600,top=100px,left=200px';
           var win = window.open(strURL,'Settings',strFeatures);
           if(win != null)
            win.focus();
           return false;
           }


function PressNumberInput(CurValue,Precision,Scale){
  var key;
  var mozilla=document.getElementById && !document.all
 var ie=document.all
   if (ie){
   
   key = event.keyCode;

       
	if(!(key >= 48 && key <= 57) && (key!=46))
    	{
		event.keyCode = 0;
		return true;
		}
     var a = new String();
	a = CurValue.value;
    if (a.length == parseInt(Precision))
	{
		event.keyCode = 0;
	}
	
	if (a.indexOf('.') >= 0 && key==46)
	{
		event.keyCode = 0;
	}
	
    if (a.indexOf('.')>=0)
    {
    var a=a.split(".");
    
    if (a[1].length>parseInt(Scale)-1 )
        {
        	event.keyCode = 0;
			return false;
        }
     }

   
   }
	     	return true;
}

function positionInfo(object) {

  var p_elm = object;

  this.getElementLeft = getElementLeft;
  function getElementLeft() {
    var x = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      x+= elm.offsetLeft;
      elm = elm.offsetParent;
    }
    return parseInt(x);
  }
  
  this.getElementWidth = getElementWidth;
  function getElementWidth(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetWidth);
  }

  this.getElementRight = getElementRight;
  function getElementRight(){
    return getElementLeft(p_elm) + getElementWidth(p_elm);
  }

  this.getElementTop = getElementTop;
  function getElementTop() {
    var y = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      y+= elm.offsetTop;
      elm = elm.offsetParent;
    }
    return parseInt(y);
  }

  this.getElementHeight = getElementHeight;
  function getElementHeight(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetHeight);
  }

  this.getElementBottom = getElementBottom;
  function getElementBottom(){
    return getElementTop(p_elm) + getElementHeight(p_elm);
  }
}



				
function getobjectstring(Fieldname,FieldType)
{
	//FieldType=1 = Object ID
	//FieldType=0 = Object Name
	var	ret;
	var	i;
	//alert('Fieldname: '+ Fieldname);
	//alert('FieldType: '+ FieldType);
	//alert('frmname: '+ document.forms[0].name);
	var length = document.forms[0].elements.length;
	
	
	for(i=1; i<=length;i++)
	{	
	          var obj=document.forms[0].elements[i];
	          
			  if(obj)
			  {
				if(FieldType == 0)
				{
					var isobj = obj.name.indexOf(Fieldname)
					if(isobj >= 0) 
					{   
						ret=obj.name;						
						break;
					}
				}
				else
				{
					
					
					var isobj = obj.id.indexOf(Fieldname);
					if(isobj >= 0) 
					{
						ret=obj.id;
						break;
					}
				}
			  }
		
	}
	
	return ret;
	
}
