﻿var applicationPath='';

// Show and hide left menu.
function ShowHideLeftMenu(TDid, imgID){

    var LeftCol = this.document.getElementById(TDid);
    var ShowHideImg = this.document.getElementById(imgID);

    if(LeftCol != null && ShowHideImg != null)
    {
	    if(LeftCol.style.display=='none'){
		    LeftCol.style.display='inline';

		    Set_Cookie('ShowHideLeftCol','true',30,'/','','');
		    var show = Get_Cookie('ShowHideLeftCol');
		    ShowHideImg.src = applicationPath + 'images/hide_leftcol.gif';
	    }else{
		    LeftCol.style.display='none';

		    Set_Cookie('ShowHideLeftCol','false',30,'/','','');
		    var show = Get_Cookie('ShowHideLeftCol');
		    ShowHideImg.src = applicationPath + 'images/show_leftcol.gif';
	    }
	 }
}


// Sets left menu last settings.
function setLeftMenu(TDid, imgID)
{
    var LeftCol = this.document.getElementById(TDid);
    var ShowHideImg = this.document.getElementById(imgID);

    if(LeftCol != null && ShowHideImg != null)
    {
        if (!Get_Cookie("ShowHideLeftCol")) {
	        Set_Cookie('ShowHideLeftCol','true',30,'/','','');
        }

        var show = Get_Cookie('ShowHideLeftCol');

        if (show == "true") {
	        LeftCol.style.display='inline';
	        ShowHideImg.src = applicationPath + 'images/hide_leftcol.gif';
        } else {
	        LeftCol.style.display='none';
	        ShowHideImg.src = applicationPath + 'images/show_leftcol.gif';
        }
    }
}

//set default postback button

function AnyInput_KeyDown ( e, target ) 
	{ 
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) 
		{ 
			document.getElementById(target).focus();
			return false; 
		} 
			return true; 
	} 

 function SetUniqueRadioButton(name, current) 
 {
            
            for (i = 0; i < document.forms[0].elements.length; i++) 
            {
                elm = document.forms[0].elements[i]
                if (elm.type == 'radio') 
                {
                    if (elm.name.indexOf(name) != -1 ) 
                        elm.checked = false;
                }
            }
            current.checked = true;
 }


 function deleteConfirm() {
     return confirm('Are you sure to Delete');
 }
 
 function CheckUncheckAll(GridViewId,CheckBoxId)
{
	var selectAllCheckBox = document.getElementById(CheckBoxId);

	var grid = document.getElementById(GridViewId);

	if (selectAllCheckBox && grid)
	{
		var inputs = grid.getElementsByTagName("input")

		if (inputs.length)
		{
			for (i=1; i<inputs.length; i++)
			{
				if (inputs[i].type =="checkbox")
					inputs[i].checked = selectAllCheckBox.checked;
			}
		}
	}
}


function SetCheckboxStatus(GridViewId,CheckBoxId)
{            
	var grid = document.getElementById(GridViewId);
	var cell;
	
	var statusCheck = true;
	if (grid.rows.length)
	{
		//loop starts from 1. rows[0] points to the header.
		for (i=1; i<grid.rows.length; i++)
		{
			cell = grid.rows[i].cells[0];
			
			for (j=0; j<cell.childNodes.length; j++)
			{
				if (cell.childNodes[j].type =="checkbox")
				{
					if (!cell.childNodes[j].checked)
					{
						statusCheck = false;
						break;
					}
				}
			}
		}
		
		document.getElementById(CheckBoxId).checked = statusCheck;
	}
}


/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj, maxlength) {
    //var mlength = obj.getAttribute ? parseInt(obj.getAttribute("MaxLength")) : ""
    //var mlength = parseInt(obj.getAttribute("MaxLength"));
    if (obj.value.length > maxlength)
        obj.value = obj.value.substring(0, maxlength)
//alert('hello: ' + obj.getAttribute("MaxLength"));
}



