function trim(stringToTrim)		{	return stringToTrim.replace(/^\s+|\s+$/g,"");	}
function ltrim(stringToTrim)	{	return stringToTrim.replace(/^\s+/,"");			}
function rtrim(stringToTrim)	{	return stringToTrim.replace(/\s+$/,"");			}
function isDigit(c)				{	return ((c >= "0") && (c <= "9"));				}
function isObject(o)			{	return (o && "object" == typeof o);				}   
function isArray(o)				{	return isObject(o) && o.constructor == Array;	}   
function isBlank(str)			{	if ("" == trim(str))return true;return false;	}

function isInteger(s)
{
	if (isBlank(s))
		return false;

	for (i = 0; i < s.length; i++)
		if (!isDigit(s.charAt(i))) return false;

	return true;
}

function setTextById(str, nodeId)
{
//	alert(str);
//	alert(nodeId);
//	alert(document.getElementById(nodeId));
	document.getElementById(nodeId).innerHTML = str;
//	eval(nodeId).childNodes(0).replaceNode(document.createTextNode(str))
//	(document.getElementById(nodeId).childNodes(0)).replaceNode(document.createTextNode(str));

}

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

function capsLock(e, nodeId)
{
	kc = e.keyCode ? e.keyCode : e.which;
	sk = e.shiftKey ? e.shiftKey : ((kc == 16)?true:false);

	if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
		document.getElementById(nodeId).style.visibility = 'visible';
	else
		document.getElementById(nodeId).style.visibility = 'hidden';
}

function Toggle(id) 
{
	if(document.getElementById(id).style.display == '')
		document.getElementById(id).style.display='none';
	else
		document.getElementById(id).style.display='';
}

function setAllCheckbox(objChk, check) 
{
	if (isObject(objChk))
	{
		if ("undefined" != typeof(objChk.length))
			for (i=0; i<objChk.length; i++)	objChk[i].checked = check;
		else
			objChk.checked = check;
	} 
}

function getCheckedIdx(objChk) 
{
	var strCheckedIndex	=	"";

	if (isObject(objChk))
	{
		if ("undefined" != typeof(objChk.length))
			for (i=0; i<objChk.length; i++)	if (true == objChk[i].checked)	strCheckedIndex	=	strCheckedIndex	+ i + ",";
		else
			strCheckedIndex	=	"0";
	} 

	return strCheckedIndex;
}

function getCheckedValue(objChk) 
{
	var strCheckValue	=	"";

	if (isObject(objChk))
	{
		if ("undefined" != typeof(objChk.length))
		{
			for (i=0; i<objChk.length; i++)	
				if (true == objChk[i].checked)	strCheckValue	=	strCheckValue	+ objChk[i].value + ",";
		}
		else
		{
			if (true == objChk.checked)	strCheckValue	=	objChk.value;
		}
	} 

	return strCheckValue;
}

function isAllChecked(objChk) 
{
	if (isObject(objChk))
	{
		if ("undefined" != typeof(objChk.length))
		{
			for (i=0; i<objChk.length; i++)	
				if (false == objChk[i].checked)
					return false;
		}
		else
		{
			if (false == objChk.checked)	
				return false;
		}

		return true;
	} 
}

function isAllUnChecked(objChk) 
{
	if (isObject(objChk))
	{
		if ("undefined" != typeof(objChk.length))
		{
			for (i=0; i<objChk.length; i++)	
				if (true == objChk[i].checked)
					return false;
		}
		else
		{
			if (true == objChk.checked)	
				return false;
		}

		return true;
	} 
}

function getObjValues(txtBox) 
{
	var strCheckValue	=	"";

	if (isObject(txtBox))
	{
		if ("undefined" != typeof(txtBox.length))
		{
			for (i=0; i<txtBox.length; i++)	
				strCheckValue	=	strCheckValue	+ txtBox[i].value + ",";
		}
		else
		{
			strCheckValue	=	txtBox.value;
		}
	} 

	return strCheckValue;
}

function validateEmail(strEmail)
{
	var rgx = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	if (!rgx.test(strEmail))
	{
//		alert('Invalid Email Address');
		return false;
	}
	
	return true;
}




// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
//var validWorldPhoneChars = phoneNumberDelimiters;
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function validatePhoneNumber(strPhone)
{
	var bracket=3;
	strPhone=trim(strPhone);

	if(strPhone.indexOf("+")>1)										return false;
	if(strPhone.indexOf("-")!=-1)									bracket=bracket+1;
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)	return false;
	
	var brchr=strPhone.indexOf("(");

	if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")	return false;
	if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)		return false;

	s=stripCharsInBag(strPhone,validWorldPhoneChars);

	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


