
function trim(str) 
{ 
   if (str == null)
   {
	   return;
   }
	return str.replace(/^\s+|\s+$/g,''); 
}

// Check whether the value of an object is empty/null 
function isEmpty(frm, ctrl, msg)
{
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (value == null || trim(value) == "")
		{
			alertMSG(msg, ctrl);
			return true;
		}
		return false;
	}
}

// Check whether the value of an object is numeric
function isNumeric(frm, ctrl, msg)
{	
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (isNaN(trim(value)) == true)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}

// Check whether the length of characters entered is equal to specified length
function isOfExactLength(frm, ctrl, num, msg)
{	
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (value.length < num || value.length > num)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}

// Check whether the length of characters entered is equal to or greater than specified length.
function isOfMinLength(frm, ctrl, num, msg)
{	
	var obj = levelInDep(frm,ctrl);
	
	with (obj)
	{
		if (value.length < num)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}

// Check whether the length of characters entered is equal to or less than specified length
function isOfMaxLength(level,entered, alertbox,num)
{	
	var obj = levelInDep(frm, ctrl);
	with (obj)
	{
		if (value.length > num)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}


// Check whether the value of either of the two control blank or not
function isAtleastOneNotEmpty(frm, ctrl1, ctrl2, msg)
{
	var obj1 = levelInDep(frm,ctrl1);
	var obj2 = levelInDep(frm,ctrl2);
	with (obj1)
	{
		if (trim(value) == "" && trim(obj2.value) == "")
		{
			alertMSG(msg, ctrl1);
			return false;
		}
		return true;
	}
}

// Check whether the value of two control equals or not
function isNotEqual(frm, ctrl1, ctrl2, msg)
{
	var obj1 = levelInDep(frm,ctrl1);
	var obj2 = levelInDep(frm,ctrl2);
	with (obj2)
	{
		if (trim(value) != trim(obj1.value))
		{
			alertMSG(msg, ctrl1);
			return true;
		}
		return false;
	}
}


// Check whether an Email address is valid
function isValidEmail(frm,ctrl,msg)
{	
	var obj = levelInDep(frm, ctrl);
	with (obj)
	{
		var regexp =  /^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+\.)+([A-Za-z0-9]{2,4})$/i;
		if (regexp.test(trim(value)) != true)
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}


// Check whether the something is selected in the list or not
function isSelected(frm, ctrl, msg) 
{ 
	var obj = levelInDep(frm, ctrl);
	with (obj)
	{
		if (selectedIndex != 0 || options.length == 1)
		{
			return true;
		}
		else 
		{
			alertMSG(msg, ctrl);
				return false;
	
		}
	}
} 


// Check whether the something is selected in the multi select list or not
function isMultipleSel(frm ,ctrl, msg) 
{ 
	//alert('document.'+ frm + '.elements[\'' + ctrl + '\']');
	var obj = eval('document.'+ frm + '.elements[\'' + ctrl + '\']');
	with (obj)
	{
		if (selectedIndex != -1)
		{
			return true;
		}
		else 
		{
			alertMSG(msg, ctrl);
			return false;
		}
	}
} 

function isValidURL(frm,ctrl, msg)
{ 
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
 		//var regexp =  /(http|ftp|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/i;
		var regexp =  /(http|ftp|https):\/\//i;
		if (regexp.test(trim(value)) != true && trim(value) != '#')
		{
			alertMSG(msg, ctrl);
			return false;
		}
		return true;
	}
}

function isChecked(frm, ctrl, msg)
{
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
 		if (checked == true)
		{
			return true;
		}
		else
		{
			alertMSG(msg, ctrl);
			return false;
		}
	}
}

function toggleCheckbox(element)
{
	if(document.getElementById(element).checked==true)
	{
		document.getElementById(element).checked=false;
	}
	else
	{
		document.getElementById(element).checked=true;
	}
}

function selectRadioButton(element)
{
	document.getElementById(element).checked=true;
}

function setFocus(element)
{
	document.getElementById(element).focus();
}

//Level indepenncy
function levelInDep(le,en)
{
	var res = eval('document.'+ le + '.' + en);
	return res;	
}

function alertMSG(message, ctrl)
{
	if (message == null || trim(message) == "") 
	{
		return;
	}
	alert(message);
	setFocus(ctrl);
}

//open small popup at center middle
var win_popup = null;

function skypePop(url)
{
	var ah = $(document.body).height();
	var aw = $(document.body).width();
	var cw = parseInt((aw-50)/4);

   // params = "?scrollbars=0,status=no,height=50,width=50";
	if (win_popup && win_popup.open && !win_popup.closed)
{
win_popup.close();
}
	win_popup = window.open(url,'','scrollbars=0,status=no,height=50,width=50');
  	
	//win_popup.location.href = url;
	win_popup.moveTo(cw, 250);
	win_popup.focus();
}

//open popup
function openWindow(url,name,params,w,h)
{
	var win = (window.opener) ? window.opener.document.body : document.body;
	var ah = $(win).height();
	var aw = $(win).width();
	aw = (w > 0) ? w : aw; ah = (h > 0) ? h : ah;
	params += params == "" ? "" : ",";
	params += "scrollbars=1,left=5,top=5,height="+ah+",width="+aw;
	win_popup = window.open("", name, params);
	win_popup.location.href = url;
	win_popup.focus();
}

var monthArray = new Array();
monthArray['01'] = "January"; monthArray['02'] = "February"; monthArray['03'] = "March"; monthArray['04'] = "April";
monthArray['05'] = "May"; monthArray['06'] = "June"; monthArray['07'] = "July"; monthArray['08'] = "August";
monthArray['09'] = "September"; monthArray['10'] = "October"; monthArray['11'] = "November"; monthArray['12'] = "December";