﻿// JScript File
function focusField(which)
{
    var ctl = getDOMObject(which);
    if(null != ctl)
        ctl.focus();
}
function checkUncheckAll(chk)
{
    
    var frm = document.forms[0];
	var	totalCtrl = frm.elements.length;
	var ctrl  = getDOMObject(chk);
	var currEl;//current element
	
	if(null != ctrl)
	{
		for(i=0;i<totalCtrl;i++)
		{
			currEl = frm.elements[i];
			if(currEl.type=="checkbox")
					currEl.checked = ctrl.checked;
		}
	}
}
function countSelection()
{
    var frm = document.forms[0];
    var totalCtrl = frm.elements.length;
    var currEl;
    var chkCount = 0;
    for(i=0;i<totalCtrl;i++)
	    {
		    currEl = frm.elements[i];
		    if(currEl.type=="checkbox")
		    {
			    if(currEl.checked)
				    chkCount = chkCount+1
		    }
	    }
    return chkCount;
}
function confirmSelection(which)
{
    if(countSelection() == 0)
    {
	    alert('No '+which+' is selected.');
	    return false
    }
}
function confirmDeletion(which)
{
    if(false != confirmSelection(which))
    {
	    return confirm('Sure to delete selected '+which+'(s)?');
    }
    return false;
}
function confirmEdit(which)
{
    if(false == confirmSelection(which))
	    return false;
    if(countSelection() != 1)
    {
	    alert("Multiple "+which+" can't be selected to Update!");
	    return false;
    }
    else if(countSelection() == 1)
	    return true;
    return true;
}

//To count the no. of characters typed in a multiline text box
function textCharCounter(activeForm, fieldToCountChars, counterField, maxChars)
{
	var strTemp = "";
	var strCharCounter = 0;
	for (var i = 0; i < activeForm.elements[fieldToCountChars].value.length; i++)
	{
		var strChar = activeForm.elements[fieldToCountChars].value.substring(i, i + 1);
		
			strTemp += strChar;
			strCharCounter ++;							
	}
	activeForm.elements[counterField].value = "Typed Chars = " + strTemp.length;
	
	if(strTemp.length > maxChars)
	{
		alert('Maximum limit of '+maxChars+' characters reached');
		activeForm.elements[fieldToCountChars].value = activeForm.elements[fieldToCountChars].value.substring(0, maxChars);
		activeForm.elements[counterField].value = "Typed = " + maxChars;
	}
}
//Div show hide
function toggleLayer(whichLayer, visibility)
{
	var ctl = getDOMObject(whichLayer);
	if(null != ctl)
	{
	    var style2 = ctl.style;
	    style2.display = visibility;
	}
}
function popUp(URL, width, height) 
{
	if(null == width)
	    width = 400;
	 if(null == height)
	    height = 500;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,location=0,directories=0,status=0,menubar=0,location=no,resizable=yes,scrollbars=yes,width="+width+",height="+height+"');");
	/*var winDim="center:yes;dialogwidth:500;dialogheight:500;scrollbars:yes;";
	var newWin=window.showModalDialog(URL,winDim);*/
}


//This is new implementation under processing
//var pop = null;
//function popUp(URL, width, height) 
//{
//	if (pop && !pop.closed)
//	    pop.location.href = URL;
//	day = new Date();
//	id = day.getTime();
//	pop = window.open(URL, 'popup', 'toolbar=0,location=0,directories=0,status=0,menubar=0,location=no,resizable=yes,scrollbars=yes,width='+width+',height='+height);
//	//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,location=0,directories=0,status=0,menubar=0,location=no,resizable=yes,scrollbars=yes,width="+width+",height="+height+"');");
//	/*var winDim="center:yes;dialogwidth:500;dialogheight:500;scrollbars:yes;";
//	var newWin=window.showModalDialog(URL,winDim);*/
//	pop.focus();
//	return false;
//}

//var bugRiddenCrashPronePieceOfJunk = (
//	navigator.userAgent.indexOf('MSIE 5') != -1
//	&&
//	navigator.userAgent.indexOf('Mac') != -1
//);

//var W3CDOM = (!bugRiddenCrashPronePieceOfJunk && 
//	document.getElementsByTagName && document.createElement);


//window.onload = initialize; 
//function initialize () {

//	
///* Hide nifty stuff from old browsers */

//	if (W3CDOM)
//	
//	{

///* Go through all links. If any has a type="popup" write the popup function into its onclick
//   Any external link gets a target='ppk'. 
//   Any link with a hreflang attribute gets an extra note with its value.   
//   */
//	var langspan = document.createElement('span');
//	langspan.className = 'smaller lang';
//	
//	var x = document.getElementsByTagName('a');
//	    for (var i=0;i<x.length;i++)
//	    {
//		    if (x[i].getAttribute('type') == 'popup')
//		    {
//			    x[i].onclick = function () {return popUp(this.href)}
//    			
//		    }		
//	    }
//	}
//}