﻿
var stringEmpty = "";

function SetEnxGrid_CkAll(obj, checked)
{
    var cellOwner = obj.parentNode.parentNode.parentNode.parentNode;
    var tableOwner = cellOwner.parentNode.parentNode.parentNode;
    tableOwner.__EnxGrid.SetSelectedAll(checked)      
}

function SetEnxGrid(gridID)
{
    var _grid = document.getElementById(gridID);
    var _gridH = document.getElementById(gridID+"_H");
    
    _grid.__EnxGrid = this;
    _gridH.__EnxGrid = this;
    
    this.GetSelected = function()
    {
        var ids= "";
        for(var i=0;i<_grid.rows.length;i++)
        {
            var row = _grid.rows[i];
            var ck = row._ck;
            if(ck.checked)
            {
                var hfid = ck.id.replace("ckSelect","hfSelect");
                var hf = document.getElementById(hfid);
                ids += hf.value.toString()+",";
            }
        }
        if(ids!="")
            ids = ids.substring(0,ids.length-1);
        
        return ids;
    }
    
    this.SetSelectedAll = function(selected)
    {
        for(var i=0;i<_grid.rows.length;i++)
        {
            var row = _grid.rows[i];
            var ck = row._ck;
            if(!ck.disabled)
            {
                ck.checked = selected;
                setSelected(row, ck);
            }
        }
    }

    for(var i=0;i<_gridH.rows.length;i++)
    {
        var row = _gridH.rows[i];
        for(var j=0;j<row.cells.length;j++)
        {
            var cell = row.cells[j];
            cell.firstChild.className = "EnxGridScroll_H";
            
            cell.style.borderRight = "1px solid #696969";            
            cell.style.borderBottom = "1px solid #898989";            
        }
    }
    
    for(var i=0;i<_grid.rows.length;i++)
    {
        var row = _grid.rows[i];
        for(var j=0;j<row.cells.length;j++)
        {
            var cell = row.cells[j];
            cell.firstChild.className = "EnxGridScroll";
            
            cell.style.borderRight = "1px solid #696969";            
            cell.style.borderBottom = "1px solid #d4d4d4";            
        }
        
        var isAlterna = ((i % 2) > 0);
        if(isAlterna)
            row.style.backgroundColor = "#eeeeee";
        else
            row.style.backgroundColor = "#ffffff";
            
        
        
        row._ck = row.cells[0].firstChild.firstChild;
        
        if(row._ck.disabled)
            row.style.color = "#696969";
        
        row.onmousemove = function(){ return false;}
        
        
        row.onmousedown = function()
        {
            var ckBox = this._ck;
            if(ckBox.disabled)
                return;
                
	        ckBox.checked = !ckBox.checked;

	        document.onmouseup=__mouseUP;
	        document.__isMouseClickDwn = true;
	        document.__ck_action_checked = ckBox.checked;            
	        
            setSelected(this,ckBox);
	        
        }
        function setSelected(obj, ckBox)
        {
            if(ckBox.checked)
            {
                obj.style.fontWeight = "bold";
                obj.style.color = "#464646";
            }
            else
            {
                obj.style.fontWeight = "";	                
                obj.style.color = "#000000";
            }
        }
        
        row.onmouseover = function()
        {
             //CHECKBOX
            var ckBox = this._ck;
            if(ckBox.disabled)
                return;
            
            var obj = this;
            if(!obj.__bkColor)
                obj.__bkColor = obj.style.backgroundColor;

            obj.style.cursor = "pointer";
            if(obj.style.backgroundColor=="#eeeeee")
                obj.style.backgroundColor = "#e9e9e9";
            else
                obj.style.backgroundColor = "#f8f8f8";
                
            

            obj.onmouseout = function()
            {
                this.style.backgroundColor = this.__bkColor;
            }	

           
                            
            if(document.__isMouseClickDwn)
            {
                ckBox.checked = document.__ck_action_checked;		
            }
            setSelected(obj, ckBox);
                
            return false;            
        }
        
        
    }//end for i
}

function grid_tr_over(obj)
{

	//obj.__bkColor = obj.style.backgroundColor;
	obj.style.cursor = "pointer";
	
	//obj.style.backgroundColor = "#E1E1E1";
	//obj.style.borderTop = "1px solid black";
	//obj.style.borderBottom = "1px solid #000000";
	
	
	for(var i=0;i<obj.cells.length;i++)
	{
		
		obj.cells[i].__bkBorderB = obj.cells[i].style.borderBottom;
		obj.cells[i].__bkBorderT = obj.cells[i].style.borderTop;
			
		obj.cells[i].style.borderBottom = "1px dashed #000000";
		obj.cells[i].style.borderTop = "1px dashed #000000";
	}
	
	
	obj.onmouseout = function()
	{
	
	
		for(var i=0;i<this.cells.length;i++)
		{
			this.cells[i].style.borderBottom = this.cells[i].__bkBorderB;
			this.cells[i].style.borderTop = this.cells[i].__bkBorderT;			
		}
		
		
		//this.style.backgroundColor = this.__bkColor;
	}	
}

document.__isMouseClickDwn = false;
document.__ck_action_checked = false;
function __mouseUP()
{
	document.__isMouseClickDwn = false;
}


function GetSelectedOptions(options)
{
    for(var i=0;i<options.length;i++)
    {
        if(options[i].selected)
            return options[i];
    }
    return null;
}

function ImgOv(imageKey , obj)
{
    obj._bk_src = obj.src;
    obj.src = root+"Images/"+imageKey+"_ov.gif";
    obj.onmouseout = function()
    {
        this.src = this._bk_src;
    }
}

function IsEndWith(str1, str2)
{
    if(str1.substring(str1.length-str2.length)==str2)
        return true

    return false;            
}
function IsVisible(obj)
{

	var item = obj;
	while( !isUndefined(item) && item!=null )
	{
		if(item.style.display.toLowerCase() == "none" || item.style.visibility.toLowerCase() == "hidden")
			return false;

		item = item.parentElement;			
	}
	return true;
}

function onMouseOvUnderline(obj)
{
	obj.style.textDecoration = "underline";
	obj.onmouseout = function()
	{
		this.style.textDecoration = "";
	}
}
function onMouse_ov(obj, ov_path)
{
	if(isUndefined(obj.__backupSrc))
		obj.__backupSrc = obj.src;
		
	obj.src = ov_path;
	
	obj.onmouseout = function()
	{
		obj.src = obj.__backupSrc;
	}
}



function RemoveChar(text, charToRemove)
{
	var result = "";
	for(var i=0;i<text.length;i++)
	{
		var c = text.substr(i,1);
		if(c != charToRemove)
			result += c;
	
	}
	return result;
}

function ltrim(str)
{

	var result = "";
	for(var i=0;i<str.length;i++)
	{
		if(str.substr(i,1) != " ")
		{
			result = str.substr(i, str.length);
			break;
		}
	}
	return result;
}
function rtrim(str)
{

	var result = "";
	for(var i=str.length-1;i>=0;i--)
	{
	
		if(str.substr(i,1) != " ")
		{
			result = str.substr(0, i+1);
			break;
		}
	}
	return result;
}
	
function trim(str)
{
	return rtrim(ltrim(str))
}



function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}	



function padr(str, pad, cnt)
{
	for(i=str.length;i<cnt;i++)
	{
		str += pad;
	}
	return str;
}
function padl(str, pad, cnt)
{
	var result = str;
	for(i=str.length;i<cnt;i++)
	{
		result = pad+result;
	}
	return result;
}		

function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isUndefined(a) {
    return typeof a == 'undefined';
} 

function validateDate( strValue ) 
{

 var objRegExp = /\d{2}-\d{2}-\d{2}/


  if(!objRegExp.test(strValue))
    return false;
  else
  {
    var strSeparator = strValue.substring(2,3) //find date separator
    var arrayDate = strValue.split(strSeparator); //split date into day, month, year
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31};
                        

	var newDay = arrayDate[0].replace("0","");
	
    var intDay = parseInt(newDay);

    //check if month value and day value agree
    if(arrayLookup[arrayDate[1]] != null) 
    {
      if(intDay <= arrayLookup[arrayDate[1]] && intDay != 0)
        return true; //found in lookup table, good date
    }

    //check for February (bugfix 20050322)
    var newYear = arrayDate[1].replace("0","");
    var intMonth = parseInt(newYear);
    if (intMonth == 2) 
    { 
       var intYear = parseInt(arrayDate[2]);
       if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
          return true; //Feb. had valid number of days
    }
  }
  return false; //any other values, bad date
}














function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}


function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}
