function ChkBoxSelected(fldName)
	{
			
			var elementLength = 0;
			var totalElements = 0;
			totalElements = document.forms[0].elements.length;
			//alert(totalElements);
			
				for(i = 0; i < totalElements; i++)
					{
						if(document.forms[0].elements[i].name == fldName)
					  		{
								if(document.forms[0].elements[i].checked != 0)
						 		   {
									elementLength++;
						        	}
							}			
				     }
			
				if(elementLength <= 0)
					{
						alert("Please select at least one checkBox.");
						return false;
					}
	return true;		
			
        
}

function deleteItem(strForm, intValue) {
	objForm = eval("document." + strForm);
	
	if(confirm("Do you want to delete the selected item?")) {
		objForm.deleteId.value = intValue;
		objForm.frmAction.value = "delete"
		objForm.submit();
	}
}// deleteItem()


function deleteItem1(fldName)
	{
		if(ChkBoxSelected(fldName))
		{
				
				if(confirm("Are you sure you want to delete the selected item(s)?"))
						{
							document.forms[0].frmAction.value = "delete";
							document.forms[0].submit();
							return true;
						}
						else
						{
						   
							return false;
						}
				
		 }	
		 else
		 {
		 		return false;
		 }
					
		
	}
												
		
function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}
													
/////////////////////////////////////////////////////////////////////////////////////////
// Check whether a string contain permitted characters only
/////////////////////////////////////////////////////////////////////////////////////////
function checkAllowedChars(strToCheck, allowedChars)
{
     var acLen     = allowedChars.length;
     var stcLen     = strToCheck.length;
     strToCheck     = strToCheck.toLowerCase();
     var i;
     var j;
     var rightCount = 0;
     for(i = 0; i < acLen; i++)
     {
          switch(allowedChars.charAt(i))
          {
          case 'A':
               for(j = 0; j< stcLen; j++)
               {
                    rightCount += strToCheck.charAt(j) >= 'a' && strToCheck.charAt(j) <= 'z';
               }
               break;
          case 'N':
               for(j = 0; j< stcLen; j++)
               {
                    rightCount += strToCheck.charAt(j) >= '0' && strToCheck.charAt(j) <= '9';
               }
               break;
          default:
               for(j = -1; -1 != (j = strToCheck.indexOf(allowedChars.charAt(i), j + 1)); rightCount++);
               break;
          }
     }
     if(rightCount == stcLen)
     {
          return true;
     }
     return false;
}
function checkEmail(emailString) {
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid email address");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}

function ChkBoxSelectedNew(frm,fldName)
  {
	var elementLength = 0;
	var totalElements = 0;
	totalElements = frm.elements.length;
	for(i = 0; i < totalElements; i++)
	{
		if(frm.elements[i].name == fldName)
		  {
			if(frm.elements[i].checked != 0)
			{
				elementLength++;
				break;
			}
		 }			
	}
	if(elementLength <= 0){
		return false;
	}
	return true;		
}

function clearSelectBox(frmObject)
{
	eval("document.forms[0]." + frmObject + ".selectedIndex = -1");
	//document.forms[0].submit();
}

function checkIfElementExists(fldName)
{
	var elementLength = 0;
	var totalElements = 0;
	totalElements = document.forms[0].elements.length;
	for(i = 0; i < totalElements; i++)
	{
		if(document.forms[0].elements[i].name == fldName)
		  {
			elementLength++;
		 }			
	}
	if(elementLength <= 0)
	{
		return false;
	}
	return true;
	
}

function getCurrentDateTime()
{
	var d=new Date()
	var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
	//document.write(weekday[d.getDay()] + " ")
	//document.write(d.getDate() + ". ")
	//document.write(monthname[d.getMonth()] + " ")
	//document.write(d.getFullYear())
	//document.write(" ")	
	document.write(d.getHours())
	document.write(".")
	document.write(d.getMinutes())
	//document.write(".")
	//document.write(d.getSeconds())
}

function checkFileExtension(fName,reqExtension)
{
	if(reqExtension.length <= 0)
	{
		alert("Extension not specified. Please contact administrator.");
		return false;
	}
	
	if(fName.length > 0)
	{
		fPos = 1;
		lPos = 0;
		while(fPos > 0)
		{
			lPos = fPos;
			fPos += 1;
			fPos = fName.indexOf("\\", fPos);
		}
		fName = fName.substring(lPos + 1);
		
		fileExtension=fName.substring(fName.indexOf(".") + 1)
		
		fileExtension = fileExtension.toLowerCase()
		reqExtension = reqExtension.toLowerCase()
		if(fileExtension == reqExtension)
		{
			return true;
		}
		else
		{
			alert("Only (*." + reqExtension + ") files allowed.");
			return false;
		}
	}
}// function checkFileExtension()
/////////////////////////////////////////////////////////////////////////////////////////
// Checks whether the first date argument is less than the second date argument
// Date arguments should be in the format - dd/mm/yyyy
/////////////////////////////////////////////////////////////////////////////////////////
function checkDateDifference(lowDate, highDate, operator) {
//alert(lowDate);
//alert(highDate);
	lowDateSplit = lowDate.split('/');
	highDateSplit = highDate.split('/');

	date1 = new Date();
	date2 = new Date();

	date1.setDate(lowDateSplit[0]);
	date1.setMonth(lowDateSplit[1] - 1);
	date1.setYear(lowDateSplit[2]);

	date2.setDate(highDateSplit[0]);
	date2.setMonth(highDateSplit[1] - 1);
	date2.setYear(highDateSplit[2]);

	if(operator == "=="){
		if(date1.getTime() == date2.getTime()) {
			return true;
		}
		else {
			return false;
		}
	}else if(operator == "<"){
		if(date1.getTime() < date2.getTime()) {
			return true;
		}
		else {
			return false;
		}
	}else if(operator == "<="){
		if(date1.getTime() <= date2.getTime()) {
			return true;
		}
		else {
			return false;
		}
	}
}
function closeWindow() {
	parent.window.opener.window.focus();
	parent.window.close();
}
function getSelBoxText(frmName,objName) // return text in a select box
{
	selItemPos = eval("document." + frmName + "." + objName + ".selectedIndex");
	selText = eval("document." + frmName + "." + objName +".options[" + selItemPos + "].text");
	return selText;
}
function writeDate() 
{
	var monthNames = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var dayNames = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var now = new Date();
	var amPm = (now.getHours() < 12) ? "am" : "pm";
	var hour = (now.getHours() > 12) ? (now.getHours() - 12) : (hour == 0) ? "12" : now.getHours();
	var min = (now.getMinutes() < 10) ? ("0" + now.getMinutes()) : (now.getMinutes());
	document.write (now.getDate()+" - "+monthNames[now.getMonth()] + " - " +now.getYear() );
}

function openWindow(fileStr,winWidth,winHeight) 
{
	
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;	
	sTop = (sHeight - winHeight) / 2;
	sLeft = (sWidth - winWidth) / 2;	
	window.open(fileStr, "File", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=0,resizable=1");
	return;
}
function openNewWindow(fileStr,winWidth,winHeight) 
{
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;	
	sTop = (sHeight - winHeight) / 2;
	sLeft = (sWidth - winWidth) / 2;	
	window.open("showPicture.asp?filename=" + fileStr, "File", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=1");
	//window.open(fileStr, "File","top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=0,resizable=1");
	return;
}
	function showPicture(imgStr, imgType, imgPath) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	if(imgType == "icon"){
		imgwidth = 150;
		imgheight = 170;
	}
	else{
		imgwidth = 670;
		imgheight = 500;
	}
	sTop = (sHeight - imgheight) / 2;
	sLeft = (sWidth - imgwidth) / 2;
	
	window.open(imgPath + imgStr, "banner", "width=" + imgwidth + ",height=" + imgheight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}// showPicture()
function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (trimSpaces(formField.value) == "")
	{
		alert("Kindly enter a value for the '" + fieldLabel + "' field.");
		formField.focus();
		result = false;
	}
	
	return result;
}

function deleteItems(formName,fldName)
{
	if(ChkBoxSelected(fldName))
	{
		objForm = eval("document." + formName);
		if(confirm("Are you sure you want to delete the selected item(s)?"))
		{
			objForm.frmAction.value = "deleteitems";
			objForm.submit();
		}
	}
}// deleteItems()


function checkAll(strForm, strCheckBox) {
	var objForm = eval("document." + strForm);
	var objElement = eval("document." + strForm + "." + strCheckBox);
	var elementLen = objElement.length;
	var counter;
	
	if(elementLen > 1) {
		for(counter = 0; counter < elementLen; counter++) {
			objElement[counter].checked = true;
		}
	}
	else objElement.checked = true;
}// checkAll()

function clearAll(strForm, strCheckBox) {
	var objForm = eval("document." + strForm);
	var objElement = eval("document." + strForm + "." + strCheckBox);
	var elementLen = objElement.length;
	var counter;
	
	if(elementLen > 1) {
		for(counter = 0; counter < elementLen; counter++) {
			objElement[counter].checked = false;
		}
	}
	else objElement.checked = false;
}// clearAll()

function getMultiSelValue(frmName,fldName)
{				
	
	selBox = eval("document." + frmName + "." + fldName);
	selItemCount = selBox.length;
	retVal='';
	for(i=0;i<selItemCount;i++)
	{
		if(selBox.options[i].selected)
		{
			//alert(document.forms[0].user_Name.options[i].text);
			if(retVal.length>0)
			{
				retVal = retVal + ",";
			}
			retVal = retVal + selBox.options[i].value;
		}
		
	}	
	return retVal;
}	

function checkDelete()
{
	dml=document.forms[0];
	var len;
	var q=0;
	var i;
	var mylen;
	len=dml.elements.length;
	for(i=0;i<len;i++)
	{
		
			mylen+=1;
			if(mylen!=0)
			{
			if(dml.elements[i].checked!=0)
				q+=1;
			}	
	}
	if (q==0)
	{
		alert("You have to select atleast one item")
		return false;
	}
	else
	{
		p = confirm("Are you sure you want to delete these entries?")
		if (p)
		{
			document.forms[0].frmAction.value = "delete";
			return;
		}
	}
}



function getEditorValue( instanceName ) 
{  
  // Get the editor instance that we want to interact with.
  var oEditor = FCKeditorAPI.GetInstance( instanceName ) ;
  
  // Get the editor contents as XHTML.
  return oEditor.GetXHTML( true ) ;  // "true" means you want it formatted.
}
function checkAll(strForm, strCheckBox) {
	var objForm = eval("document." + strForm);
	var objElement = eval("document." + strForm + "." + strCheckBox);
	var elementLen = objElement.length;
	var counter;
	
	if(elementLen > 1) {
		for(counter = 0; counter < elementLen; counter++) {
			objElement[counter].checked = true;
		}
	}
	else objElement.checked = true;
}// checkAll()

function clearAll(strForm, strCheckBox) {
	var objForm = eval("document." + strForm);
	var objElement = eval("document." + strForm + "." + strCheckBox);
	var elementLen = objElement.length;
	var counter;
	
	if(elementLen > 1) {
		for(counter = 0; counter < elementLen; counter++) {
			objElement[counter].checked = false;
		}
	}
	else objElement.checked = false;
}// clearAll()