
function trim(st)
{
	if(st.length > 0)
	{
		re = / +$/g; 
		newval = st.replace(re,"");
		re = /^ +/g;
		newvala = newval.replace(re,"");
		return newvala;
	}
	return "";
}
function IsDate(mMonth, mDay, mYear)
{
	mMonth = parseInt(mMonth);
	mDay = parseInt(mDay);
	mYear = parseInt(mYear);
	var mLeap = false;
	if ( mYear%4 == 0 )
		mLeap = true;
	if ( mMonth == 1 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 2 )
	{
		if ( mLeap )
		{
			if ( mDay < 1 || mDay > 29 )
				return false;
			else
				return true;
		}
		else
		{
			if ( mDay < 1 || mDay > 28 )
				return false;
			else
				return true;
		}
	}
	else if ( mMonth == 3 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 4 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 5 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 6 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 7 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 8 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 9 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 10 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 11 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 12 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else
	{
		return false;
	}
}
// this function opens the popoup window
function WinOpenS(winname,w,h,leftcor,topcor,pname)
{
	window.open( pname , winname, "scrollbars=1,statusbar=no,menubar=no,toolbar=no,resize=null,top=" + topcor + ",left=" + leftcor + ",width=" + w + ",height="+h ).focus();
}

function confirm_delete()
{
	var ans = confirm("Do you want to delete Item(s)?");
	return ans;
}

function IsEmailValid(email)
{
	email = trim(email);
	valid_chars_for_email = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.";
	if ( email == "" )			// pending Email validation
	{
		return false;
	}
	for ( i=0; i < email.length; i++ )
	{
		ch =  "" + email.charAt(i);
		num = valid_chars_for_email.indexOf(ch);
		if ( num == -1 )
		{
			return false;
		}
	}
	if ( email.indexOf('@') == -1 )
	{
		return false;
	}
	if ( email.indexOf('.') == -1 )
	{
		return false;
	}
	return true;
}

function CompareDate(day1, month1, year1, day2, month2, year2)
{
	day1 = day1 * 1;
	month1 = month1 * 1;
	year1 = year1 * 1;
	day2 = day2 * 1;
	month2 = month2 * 1;
	year2 = year2 * 1;
	if ( (year2 == year1) && (month2 == month1) && (day2 == day1) )
	{
		return 0;			// Equal
	}
	else if ( ((year2 > year1)) || ( (year2 == year1) && (month2 > month1) ) || ( (year2 == year1) && (month2 == month1) && (day2 > day1)) )
	{
		return 2;			//  The second date is greater
	}
	else
	{
		return 1;			// The First Date is greater
	}
}


function ValidateNumeric( ctrl )
{
	var mVal = ctrl.value;
	mVal = trim(mVal);
	if ( isNaN(mVal) || mVal == "" )
	{
		alert (ctrl.title + " should be a numeric value.");
		ctrl.focus();
		return false;
	}
	else 
	{
		return true;
	}
}

function ValidateEmpty(ctrl)
{
	//alert(ctr1);
	var mVal = ctrl.value;
	//alert(mVal);
	mVal = trim(mVal);
	if ( mVal == "" )
	{
		alert (ctrl.title + " can not be blank.");
		ctrl.focus();
		return false;
	}
	else 
	{
		return true;
	}
}
function ValidateImage(ctrl)
{
	if (ctrl.value.length)
	{
		var iPos = ctrl.value.lastIndexOf(".")
		var sExt = ctrl.value.substring(iPos);
		if((sExt.toUpperCase()=='.JPEG') || (sExt.toUpperCase()=='.JPG') || (sExt.toUpperCase()=='.GIF') || (sExt.toUpperCase()=='.BMP') || (sExt.toUpperCase()=='.PNG') )
		{
			return true;
		}
		else
		{
			alert("Please enter valid image.");
			ctrl.focus();
			ctrl.select();
			return false;
		}                       
	}
	else
	{
		alert("Please select the file to be uploaded");
		ctrl.focus();
		ctrl.select();
		return false;
	}
}

	//   This function moves selected Item from List to Another
function MoveSelectedItem ( lstSource, lstTarget )
{
	if (lstSource.selectedIndex != -1)
	{
		var value = lstSource.options[lstSource.selectedIndex].value;
		var text =  lstSource.options[lstSource.selectedIndex].text;
		lstSource.options[lstSource.selectedIndex] = null;
		lstTarget.options[lstTarget.options.length] = new Option(text, value, null ,null );
	}
	else
	{
		alert("First select an Item");
	}
}

		//  This function moves all the items from a list to another
function MoveAllItems ( lstSource, lstTarget )
{
	var Slen = lstSource.options.length;
	var Tlen = lstTarget.options.length;
	if ( Slen )
	{
		for ( i=0; i < Slen; i++ )
		{
			var value = lstSource.options[0].value;
			var text =  lstSource.options[0].text;
			lstSource.options[0] = null;
			lstTarget.options[Tlen + i] = new Option(text, value, null ,null );
		}
	}
	else
	{
		alert("Source List doesnt have any Item");
	}
}

function GetListValues( lstctrl  )
{
  var len = lstctrl.options.length;
   var str = "";
   for( i=0; i < len; i++ )
   {
      str = str + lstctrl.options[i].value + ",";
   }
   return str;
}


