function setControlDisabled(id,disabled)
    {
        currentControl = document.getElementById(id);
        if(currentControl)
            currentControl.disabled = disabled; 
            
    }
function copyControlContents(source,destination)
    {
        currentControlSource  = document.getElementById(source);  
        currentControlDestination  = document.getElementById(destination); 
        if(currentControlSource != null && currentControlDestination != null)
            currentControlDestination.value =  currentControlSource.value;
    }
    
    function setControlContents(name,textToSet)
    {
        currentControl  = document.getElementById(name);  
        if(currentControl != null)
            currentControl.value =  textToSet;
    }
    
    function getControlContents(name)
    {
        currentControl  = document.getElementById(name);  
        if(currentControl != null)
            return(currentControl.value);
    }  

function NoTyping(e)
    {
       return(false);
    }
    
function GetSelectText(txtBox)
{
    txtBox.select();
}

function checkSave()
{
	var rtValue=confirm('Page Contents Modified – Do you want to Save?');
		return rtValue;
	//else return false;
}
//
function round(amount) {
// returns the amount in the .99 format 
    amount -= 0;
    amount = (Math.round(amount*100))/100;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10  == Math.floor(amount*10)) ? amount + '0' : amount);
}

//date of creation = 22/12/05

//we can user this function to trim the string in javascript
function trimString (str) 
{ 
	str = this != window? this : str;
	 return str.replace(/^\s+/g, '').replace(/\s+$/g, ''); 
}
//use to validate Double
function ValidateDouble(cntrl)
{	
	//alert(parseFloat(cntrl.value));//
	if(cntrl.value == '' || isNaN(parseFloat(cntrl.value)))
	{
		cntrl.value='0.00';
		cntrl.focus();
		return false;	
	}
	if(cntrl.value.indexOf('-',1)> -1 || cntrl.value.indexOf('+',1)> -1)
	{
		alert('Entered Value is not correct, System will change the value to 0.00');
		cntrl.value='0.00';	
		cntrl.focus();
		return false;	
	}
	if (cntrl.value.indexOf('.',1)> -1 && cntrl.value.indexOf('.',cntrl.value.indexOf('.',0)+1)> -1)
	{
		alert('Entered Value is not correct, System will change the value to 0.00');
		cntrl.value='0.00';	
		cntrl.focus();
		return false;
	}
	
}
// use to validate integer
function ValidateInteger(cntrl)
{	
	//alert(cntrl.value);
	if(cntrl.value == '' || isNaN(parseInt(cntrl.value)) )
	{
		cntrl.value='0';
		cntrl.focus();
		return false;	
	}
	if(cntrl.value.indexOf('-',1)> -1 || cntrl.value.indexOf('+',1)> -1 || cntrl.value.indexOf('.',0)> -1)
	{
		alert('Entered Value is not correct, System will change the value to 0');
		cntrl.value='0';
		cntrl.focus();
		return false;
	}		
}
//We can use this function to validate number only to textboxes.
function AlphabetsOnly(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /[A-Za-z\s]/;	
	if (reg.test(keychar)==false)
		alert('Enter Alphabets Only');
	return reg.test(keychar);
}

function NumbersOnly(e)
{
	
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /[^-+\d]/;	
	if (!reg.test(keychar)==false)
		alert('Enter Numbers Only');
	return !reg.test(keychar);
} 

function Email(e)
{
	reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if (reg.test(e)==false)
	{
		alert('This Is Not a Valid Email Address');
		this.focus();
		return !reg.test(e);

	}

}
function Double(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /[^-+\d\.]/;	
	if (!reg.test(keychar)==false)
		alert('Enter Numbers Only');
	return !reg.test(keychar);

}
function IgnoreSpecialCharacter(e)
{
	
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /\W/;	
	if (!reg.test(keychar)==false)
		alert('Special Characters Are Not Allowed');
	return !reg.test(keychar);
}
function CheckDate(cntrl)
{
	if (cntrl.value!='')
	{
		if (!cntrl.value.match(/\b(0?[1-9]|1[012])[- \/.](0?[1-9]|[12][0-9]|3[01])[- \/.](19|20)?[0-9]{2}\b/)) 		 
		{
			alert('Invalid Date');
			cntrl.value='';
			cntrl.focus();
			return false;
			
		}
	}

	
}


// Following script checks for masking of Textbox

// [dFilter] - A Numerical Input Mask for JavaScript
// Written By Dwayne Forehand - March 27th, 2003
// Please reuse & redistribute while keeping this notice.

var dFilterStep

function dFilterStrip (dFilterTemp, dFilterMask)
{
	
    dFilterMask = replace(dFilterMask,'#','');
    for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++)
		{
		    dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
		   
		}
		return dFilterTemp;
}
function MakeBlank(tempValue)

{
	txtValue = tempValue.value;
	
	if((txtValue.length==2)&&(txtValue=='--')) {
		tempValue.value="";
	}
}
function dFilterMax (dFilterMask)
{
 		
 		dFilterTemp = dFilterMask;
    for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++)
		{
		 		if (dFilterMask.charAt(dFilterStep)!='#')
				{
		        dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),'');
				}
		}
		return dFilterTemp.length;
}

function dFilter (key, textbox, dFilterMask)
{
		dFilterNum = dFilterStrip(textbox.value, dFilterMask);
		 
		if (key==9)
		{
		    return true;
		}
		else if (key==8&&dFilterNum.length!=0)
		
		{
			 	dFilterNum = dFilterNum.substring(0,dFilterNum.length-1);
			}
		//else if ( ((key>47&&key<58)||(key>95&&key<106)) && dFilterNum.length<dFilterMax(dFilterMask) ) **Commented by Ram
 	  else if ( ((key>47&&key<58)) && dFilterNum.length<dFilterMax(dFilterMask) )
		{
        dFilterNum=dFilterNum+String.fromCharCode(key);
		}
		 else if ( ((key>95&&key<106)) && dFilterNum.length<dFilterMax(dFilterMask) ) // Added by ram to Handle Numeric Key pad
{
        dFilterNum=dFilterNum+String.fromCharCode(key-48);
		}																									                            // End new code
		var dFilterFinal='';
    for (dFilterStep = 0; dFilterStep < dFilterMask.length; dFilterStep++)
		{
        if (dFilterMask.charAt(dFilterStep)=='#')
				{
					  if (dFilterNum.length!=0)
					  {
				        dFilterFinal = dFilterFinal + dFilterNum.charAt(0);
					      dFilterNum = dFilterNum.substring(1,dFilterNum.length);
					  }
				    else
				    {
				        dFilterFinal = dFilterFinal + "";
				    }
				}
		 		else if (dFilterMask.charAt(dFilterStep)!='#')
				{
				    dFilterFinal = dFilterFinal + dFilterMask.charAt(dFilterStep); 			
				}
//		    dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
		}


		textbox.value = dFilterFinal;
    return false;
}

function replace(fullString,text,by) {
// Replaces text with by in string

    var strLength = fullString.length, txtLength = text.length;

    if ((strLength == 0) || (txtLength == 0)) return fullString;

    var i = fullString.indexOf(text);
    if ((!i) && (text != fullString.substring(0,txtLength))) return fullString;
    if (i == -1) return fullString;

    var newstr = fullString.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(fullString.substring(i+txtLength,strLength),text,by);

    return newstr;
}

