
function GetTextBoxValue(id)
{
	var ele = document.getElementById(id);
	
	var str = ele.value;
	
	return str;
}

function GetComboBoxValue(id)
{
	var ele = document.getElementById(id);
	
	var str = ele.options[ele.selectedIndex].value;
	
	return str;
}

function GetComboBoxText(id)
{
	var ele = document.getElementById(id);
	
	var str = ele.options[ele.selectedIndex].text;
	
	return str;
}

function MakeTextBoxEqual(srcID, destID)
{
	var src = document.getElementById(srcID);
	var dest = document.getElementById(destID);

	dest.value = src.value;
}

function MakeComboBoxEqual(srcID, destID)
{
	var src = document.getElementById(srcID);
	var dest = document.getElementById(destID);

	dest.selectedIndex = src.selectedIndex;
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");     
}

function Trim(str)
{
   return trim(str);
}


function Mid(str, start, len)
{
    if (start < 0 || len < 0) return "";

    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
            iEnd = iLen;
    else
            iEnd = start + len;

    return String(str).substring(start,iEnd);
}

function Len(str)
{
	return String(str).length;
}


function InStr(strSearch, charSearchFor)
{
	if(Len(strSearch) == Len(charSearchFor))
	{
		if(strSearch == charSearchFor)
			return 0;
	}
	
	if(Len(strSearch) < Len(charSearchFor))
	{
		return -1;
	}
	
	for (i=0; i < (Len(strSearch) - Len(charSearchFor))+1 ; i++)
	{
	    if (charSearchFor == Mid(strSearch, i, Len(charSearchFor)))
	    {
			return i;
	    }
	}
	return -1;
}

function OpenChild(url, childName, width, height, style)
{
		var opWin;
		var left = (screen.width/2) - width/2;
		var top = (screen.height/2) - height/2;
		var styleStr = style + ',width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
		  
		opWin = window.open(url, childName, styleStr);
		
}

function AllowDecimalNumOnly(e)
{
	var unicode = e.charCode ? e.charCode : e.keyCode;
    
   if(unicode < 48)
   {
        if(unicode == 37 || unicode == 39 || unicode == 8 || unicode == 9 || unicode == 46)
        {
            return true;
        }
        else
        {
            return false;
        }
   }
   else
   {
     if(unicode < 58)
     {
        return true;
     }
     else
     {
        return false;
     }
   }
}

function FilterCC(e)
{
    var unicode = e.charCode ? e.charCode : e.keyCode;
    
   if(unicode < 48)
   {
        if(unicode == 37 || unicode == 39 || unicode == 8 || unicode == 9 ||unicode == 46)
        {
            return true;
        }
        else
        {
            return false;
        }
   }
   else
   {
     if(unicode < 58)
     {
        return true;
     }
     else
     {
        return false;
     }
   }
}

function AllowInteger(e)
{
	var unicode = e.charCode ? e.charCode : e.keyCode;
   
    if(unicode < 48)
   {
        if(unicode == 39 || unicode == 8 || unicode == 9 || unicode == 46)
        {
            return true;
        }
        else
        {
            return false;
        }
   }
   else
   {
     if(unicode < 58)
     {
        return true;
     }
     else
     {
        return false;
     }
   }
   
}

function LimitLength(obj, length)
{
    var maxlength=length;
    
    if (obj.value.length > maxlength)
        obj.value = obj.value.substring(0, maxlength);
}

function MakeReadOnly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode != 9)
	{
		if (unicode != 37 && unicode != 39)
		{ 
			if(unicode > 0)
				return false //disable key press
		}
	}
	
}

function make_option(selobj, txt, val)
{
	selobj.options[selobj.options.length]= new Option(txt, val);
	
}

function FillBuiltCombo(cbo, data)
{
	
	var iniVal;
	var bSetInitVal;
	var ii;
	
	bSetInitVal = false;
	
	if(cbo.options.length > 0)
	{
		iniVal = cbo.options[cbo.selectedIndex].value;
		bSetInitVal = true;
		
		cbo.options.length = 0;
	}
	
	for(ii = 0; ii< data.length ; ii = ii + 2)
	{
		make_option(cbo,  data[ii] , data[ii+1] );
	}
	
	if(bSetInitVal)
	{
		for(ii=0;ii<cbo.options.length;ii++)
		{
			if(cbo.options[ii].value == iniVal)
			{
				cbo.selectedIndex = ii;
			}
		}
	}
}

function ApplyCSSStyle(ele, styleName)
{
  
    ele.className = styleName;
}

function isSelectedRadio(radioList)
{
    var options = radioList.getElementsByTagName('input');
    for(i=0;i<options.length;i++)
    {
        var opt = options[i];
        if(opt.checked){
            return true;
        }
    }
}    

function getRadioSelectedValue(radioList)
{
    var options = radioList.getElementsByTagName('input');
    for(i=0;i<options.length;i++)
    {
        var opt = options[i];
        if(opt.checked)
        {
            return opt.value;
        }
    }
}    

// Check whether string  is empty.
function isEmpty(s)
{   
return ((s == null) || (s.length == 0))
}

//Trimming a String
function  trimText(fldName)
{
	var name=fldName.value;
	while(name.charAt(0)==' ')
	{
		name=name.substring(1,name.length);
	}
	while(name.charAt((name.length)-1)==' ')
		name=name.substring(0,(name.length)-1);
	
	return name;
}

//Working but takes lot of time!
function checkEmail(field,msgx){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(field.value)) return true;
	alert(msgx);
	field.focus();
	field.select();
	return false;
}

//Checking for a valid number
function AllowInteger_new (s)

{   
	var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

//Checking for a valid Digit
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}