// Define Form Object
var obj
obj = "document.form1."

//Common Validate Function to Check Blank Values
function validate(arrFields)
{
	var FieldsArr = arrFields.split(",");
	var arrLen = FieldsArr.length;
	returnStr = "";
	
	for (i=0;i<arrLen;i++)
	{
		indFields = FieldsArr[i].split(":");
		//indFields = trim(FieldsArr[i]);
		if(trim(eval(obj+indFields[0]+".value"))=="")
		{

			returnStr = FieldsArr[i];
			break;
		}
	}
	return returnStr;
}


function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 



function searchSite_validate()
{
len=eval(obj+"txtSearch.value").length;
if (len<4)
{
alert("Please fill atleast four characters for performing a valid search");
return false;
}
}

// Open Department Pops
function view_dept()
{
	strUrl = "dept.asp";
	
	window.open(strUrl,"dept","width=750,height=400,resizable=yes,left=150,top=100,scrollbars=yes,,toolbar=no");
}
function open_addgroup()
{
	strUrl = "add_group.asp";
	
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");

}
function open_help(strVal)
{
	strUrl = "../intranet/help.asp#"+ strVal;
	window.open(strUrl,"dept","width=800,height=600,left=150,top=10,resizable=yes,scrollbars=yes");
}

function open_adddept()
{
	strUrl = "add_dept.asp";
	
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");

}
function winclose()
{
	opener.window.location.reload();
	window.close();

}
function open_attendance()
{

	strUrl = "../intranet/Attd_Customize.asp";
	window.open(strUrl,"attendance","width=750,height=400,left=150,top=10,scrollbars=no");

}

function open_attendanceRegister()
{
strUrl = "../intranet/attendance.asp";
	window.open(strUrl,"attendance","width=750,height=400,left=150,top=10,scrollbars=no");
}

function winopen()
	{
	window.open("admin_forgotPassword.asp","win","location=0,menubar=0,resizable=no,height=200,width=450,left=150,top=100");
	}
	
	function ForgetPassword()
{
	arrFlds = "txtEmail:E-mail ";
	errMsg = validate(arrFlds);
	
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	
	else if(!chkEmail("txtEmail"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}
	
}

// function to validate address book
 function contact_validate()
 {
 	arrFlds = "cblGroup:Group Name,txtFName:First Name,txtLName:Last Name";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
 }
 
 
function  announce_validate()
{
	arrFlds = "txtATitle:Announcement Heading,txtAnouncement:Announcement details";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}

function job_validate()
{
arrFlds = "txttitle:Title of job,cblDept:Department Name,txtDesc:Job Description";
errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	var flag = checkDates("txtSDt","txtEDt")
	 if (flag==false)
			{
				alert("Closing Date of Job cannot be before opening date.");
				eval(obj+"txtEDt.value=''");
				return false;
			}
	if(isNaN(eval(obj+"txtSal.value")))
	{
			alert("Please Enter only numbers for salary.");
			eval(obj+"txtSal.value=''");
			eval(obj+"txtSal.focus()");
			return false;
	}
}
//Edit Employee Details
function employee_editvalidate()
{
	arrFlds = "txtFName:First Name,txtLName:Last Name,cblDept:Department Name,txtDesgn:Designation,txtEmail:Email Address";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if(!chkEmail("txtEmail"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}
	else if (eval(obj+"txtPassword.value")!="")
	{
		if (!chkEquality("txtPassword","txtCPassword"))
		{
		alert("New Password Do Not match ! Please Re-Enter");
		eval(obj+"txtPassword.focus()");
		eval(obj+"txtPassword.select()");
		return false;
		}
		if (eval(obj+"txtOPassword.value")=="") 
		{
		alert("You Have to Enter Old Password to Incorporate New Change in Password");
		eval(obj+"txtOPassword.focus()");
		eval(obj+"txtOPassword.select()");
		return false;	
		}
	}	
}
//function to check edit profile
function profile_editvalidate()
{
	arrFlds = "txtFName:First Name,txtLName:Last Name,txtEmail:Email Address";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if(!chkEmail("txtEmail"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}
	else if (eval(obj+"txtPassword.value")!="")
	{
		if (!chkEquality("txtPassword","txtCPassword"))
		{
		alert("New Password Do Not match ! Please Re-Enter");
		eval(obj+"txtPassword.focus()");
		eval(obj+"txtPassword.select()");
		return false;
		}
		if (eval(obj+"txtOPassword.value")=="") 
		{
		alert("You Have to Enter Old Password to Incorporate New Change in Password");
		eval(obj+"txtOPassword.focus()");
		eval(obj+"txtOPassword.select()");
		return false;	
		}
	}	
}

//function to check email
function chkEmail(strEmail)
{

	strIndex= eval(obj+strEmail+".value").indexOf("@");
	strVal=eval(obj+strEmail+".value")
	len=(eval(obj+strEmail+".value").length);
	strFind = strVal.substring(strIndex,len);
	if(eval(obj+strEmail+".value").indexOf("@")< 1 || eval(obj+strEmail+".value").indexOf(".")< 1 || eval(obj+strEmail+".value").length < 5)
	{
		return false;
	}
	if  (strFind.indexOf(".")< 3) 
		return false;
	else
		return true;
}	

//Function to Check Login Characters
function chkLogin(strLogin)
{
	blnflag = true;
	strLen = strLogin.length;
	for(i=0;i<strLen;i++)
	{
		theChar="";
		theChar=strLogin.substring(i,i+1)
		theChar=theChar.toLowerCase();
		if((theChar < "0" || theChar > "9") && (theChar < "a" || theChar > "z") && (theChar!="_"))
		{
			blnflag = false;
			break;
		}
	}
	return blnflag;
}

//Function to Check Equality 
function chkEquality(firstVal,secondVal)
{
	if (eval(obj+firstVal+".value")!=eval(obj+secondVal+".value"))
		return false;
	else
		return true;	
}


// admin login Page Validations
function login_validate()
{
	arrFlds = "txtUsername:UserName,txtPassword:Password";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}

// Add New Employee Validations
function employee_validate()
{
	arrFlds = "txtFName:First Name,txtLName:Last Name,cblDept:Department Name,txtDesgn:Designation,txtEmail:Email Address,txtUserNM:User Name,txtPassword:Password";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if(!chkEmail("txtEmail"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}
	else if (!chkLogin(eval(obj+"txtUserNM.value")))
	{
		alert("Invalid Username ! \n Should be consisting of only alphabets,numbers and underscore");
		eval(obj+"txtUserNM.focus()");
		eval(obj+"txtUserNM.select()");
		return false;
	}
	else if (!chkEquality("txtPassword","txtCPassword"))
	{
		alert("Password Do Not match ! Please Re-Enter");
		eval(obj+"txtPassword.value=''");
		eval(obj+"txtCPassword.value=''");
		eval(obj+"txtPassword.focus()");
		eval(obj+"txtPassword.select()");
		return false;
	}
}

//Edit Employee Details
function employee_editvalidate()
{
	arrFlds = "txtFName:First Name,txtLName:Last Name,cblDept:Department Name,txtDesgn:Designation,txtEmail:Email Address";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if(!chkEmail("txtEmail"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}
	else if (eval(obj+"txtPassword.value")!="")
	{
		if (!chkEquality("txtPassword","txtCPassword"))
		{
		alert("New Password Do Not match ! Please Re-Enter");
		eval(obj+"txtPassword.focus()");
		eval(obj+"txtPassword.select()");
		return false;
		}
		if (eval(obj+"txtOPassword.value")=="") 
		{
		alert("You Have to Enter Old Password to Incorporate New Change in Password");
		eval(obj+"txtOPassword.focus()");
		eval(obj+"txtOPassword.select()");
		return false;	
		}
	}	
}

//Chech Add File Category 
function addcat_validate()
{
	arrFlds = "txtCatNM:Category Name";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}

//Chech Add Board
function addboard_validate()
{
	arrFlds = "txtBoardNM:Board Name";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if (eval(obj+"poll_type[1].checked"))
	{
		if (eval(obj+"cblDept.selectedIndex")< 0)
		{
			alert("Please select Department for File !!");
			return false;
		}
		else
			eval(obj+"cblDept.disabled=false");
	}
}

//Check File Upload Program
function uploadFile_validate()
{
	obj1 = "document.form2.";
	arrFlds = "cblCat:Category Name,txtFileDesc:Field Description,txtFileNM: File Name";
	errMsg = validate(arrFlds);
	flag = false
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		flag = true;
	}
	else if (eval(obj1+"poll_type[1].checked"))
	{
		if (eval(obj1+"cblDept.selectedIndex")< 0)
		{
			alert("Please select Department for File !!");
			flag = true;
		}
		else
			eval(obj+"cblDept.disabled=false");
	}
	
	strIndex= eval(obj+"txtFileNM.value").indexOf(".");
	strVal=eval(obj+"txtFileNM.value");
	len=(eval(obj+"txtFileNM.value").length);
	strFind = strVal.substring(strIndex,len);
	arrFiles = new Array
	arrFiles=['asp','php','aspx','cgi','jsp','pl'];
	for(i=0;i<arrFiles.length;i++)
	{
		if  (strFind.indexOf(arrFiles[i])> 0) 
		{
		alert("Files with following extension are not allowed \n\n Extension : .asp,.php,.aspx,.cgi,.jsp,.pl");
		flag = true;
		break;
		}
	}	
	if (flag)
		return false;
	else
	{
		if (eval(obj1+"poll_type[1].checked==true"))
			pollVal = "private";
		else
			pollVal = "public";
		deptLen = eval(obj1+"cblDept.length");
		deptIDs = ""
		for(i=0;i<deptLen;i++)
		{
			if(eval(obj1+"cblDept[i].selected"))
			deptIDs = deptIDs + eval(obj1+"cblDept[i].value") + ","
		}	
		if (deptIDs!="")
			deptIDs = deptIDs.substring(0,deptIDs.length-1)
					
		eval(obj+"poll_type.value=pollVal");
		eval(obj+"cblDept.value=deptIDs");
		return true;
	}
	
}

//Edit File Upload Program
function editFile_validate()
{
	obj1 = "document.form2.";
	arrFlds = "cblCat:Category Name,txtFileDesc:Field Description";
	errMsg = validate(arrFlds);
	flag = false
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		flag = true;
	}
	else if (eval(obj1+"poll_type[1].checked"))
	{
		if (eval(obj1+"cblDept.selectedIndex")< 0)
		{
			alert("Please select Department for File !!");
			return false;
		}
	}
	
	if (flag)
		return false;
	else
	{
		if (eval(obj1+"poll_type[1].checked==true"))
			pollVal = "private";
		else
			pollVal = "public";
		deptLen = eval(obj1+"cblDept.length");
		deptIDs = ""
		for(i=0;i<deptLen;i++)
		{
			if(eval(obj1+"cblDept[i].selected"))
			deptIDs = deptIDs + eval(obj1+"cblDept[i].value") + ","
		}	
		if (deptIDs!="")
			deptIDs = deptIDs.substring(0,deptIDs.length-1)
					
		eval(obj+"poll_type.value=pollVal");
		eval(obj+"cblDept.value=deptIDs");
		return true;
	}
	
}

// Check Add News Function
function news_validate()
{
	obj1 = "document.form2."
	var eDate = new Date(eval(obj+"txtEDate.value"));
	var sDate = new Date(eval(obj+"txtSDate.value"));
	var flag = false
	arrFlds = "txtNTitle:News Title,txtNews:News,txtSDate:Start Date,txtEDate:End Date";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		flag = true;
	}
	else if (eDate-sDate < 0)
	{
		alert("News Start Date should be less than or equal to the News End date !!");
		flag = true;
	}
	else if (eval(obj1+"poll_type[1].checked"))
	{
		if (eval(obj1+"cblDept.selectedIndex")< 0)
		{
			alert("Please select Department for News !!");
			flag = true;
		}
	}
	
	if (flag)
		return false;
	else
	{
		if (eval(obj1+"poll_type[1].checked==true"))
			pollVal = "private";
		else
			pollVal = "public";
		deptLen = eval(obj1+"cblDept.length");
		deptIDs = ""
		for(i=0;i<deptLen;i++)
		{
			if(eval(obj1+"cblDept[i].selected"))
			deptIDs = deptIDs + eval(obj1+"cblDept[i].value") + ","
		}	
		if (deptIDs!="")
			deptIDs = deptIDs.substring(0,deptIDs.length-1)
					
		eval(obj+"poll_type.value=pollVal");
		eval(obj+"cblDept.value=deptIDs");
		return true;
	}
	
	
}

// Check Add Poll Function
function pollAdd_validate()
{
	var eDate = new Date(eval(obj+"txtEDate.value"));
	var sDate = new Date(eval(obj+"txtSDate.value"));
	arrFlds = "txtPoll:Poll Question,txtChoice1:Choice 1,txtChoice2:Choice 2,txtSDate:Publish Date";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if (eval(obj+"txtChoice4.value")!="")
	{
		if (eval(obj+"txtChoice3.value")=="")
		{
		alert("Choice 3 cannot be blank if Choice 4 is entered !!");
		eval(obj+"txtChoice3.focus()");
		return false;
		}
	}
	if (eDate-sDate < 0)
	{
		alert("Poll Start Date should be less than or equal to the Poll End date !!");
		return false;
	}
	else if (eval(obj+"poll_type[1].checked"))
	{
		if (eval(obj+"cblDept.selectedIndex")< 0)
		{
			alert("You have chosen Department Poll ! Please select atleast one department");
			return false;
		}
		else
			eval(obj+"cblDept.disabled=false");
	}
	
	
}


// check poll clicks
function poll_validate()
{
	obj1 = "document.pollform.";
	flag = false;
	ch_len = eval(obj1+"Chpoll.length");
	for (i=0;i<ch_len;i++)
	{
		if (eval(obj1+"Chpoll[i].checked"))
		{
			flag = true;
			break;
		}
	}
	if (flag)
		return true;
	else
	{
		alert("Please select one Option !!");
		return false;
	}
}

// On Change Event, show poll question and choices
function show_question()
{
	strVal = eval(obj+"cblQuestion.value");
	if (strVal!="")
	{
		strArr = strVal.split("##");
	//eval(obj+"txtPoll.value="+obj+"cblQuestion.options["+obj+"cblQuestion.selectedIndex].text");
	eval(obj+"txtPoll.value=strArr[1]");
	eval(obj+"txtChoice1.value=strArr[2]");
	eval(obj+"txtChoice2.value=strArr[3]");
	if (strArr.length > 3)
		eval(obj+"txtChoice3.value=strArr[4]");
	if (strArr.length > 4)
		eval(obj+"txtChoice4.value=strArr[5]");	
	}
	else
	{
		strVar = "Can't Say"
		eval(obj+"txtPoll.value=''");
		eval(obj+"txtChoice1.value='Yes'");
		eval(obj+"txtChoice2.value='No'");
		eval(obj+"txtChoice3.value=strVar");
		eval(obj+"txtChoice4.value=''");
	}
}

// CheckALL Function Needs CheckBox Name
function checkAll(chkNM)
{
	//Find the Length of the Checkbox
	
	intLen = eval(obj+chkNM+".length");
	if(intLen==null || intLen == "undefined")
		eval(obj+chkNM+".checked=true");
	else
	{
		for(i=0;i<intLen;i++)
		{
			eval(obj+chkNM+"["+i+"].checked=true");
		}
	}
		eval(obj+"ckhALL.checked=true");
		
}


function checkAll1(chkNM,strChk)
{
	//Find the Length of the Checkbox
	intLen = eval(obj+chkNM+".length");
	if(intLen==null || intLen == "undefined")
		eval(obj+chkNM+".checked=true");
	else
	{
		for(i=0;i<intLen;i++)
		{
			eval(obj+chkNM+"["+i+"].checked=true");
		}
	}
		eval(obj+strChk+".checked=true");
		
}

//Check & Remove ALL
function ChkRemoveAll(chk)
{
	intLen = eval(obj+chk+".length");
	if (eval(obj+"ckhALL.checked"))
	{
		checkAll(chk);
	}
	else
	{
		if(intLen==null || intLen == "undefined")
			eval(obj+chk+".checked=false");
		else
		{
			for(i=0;i<intLen;i++)
			{
				eval(obj+chk+"["+i+"].checked=false");
			}	
		}
			eval(obj+"ckhALL.checked=false"); 
	}	
}
//Check Section
function chk_section(strField,strType)
{
	var arr = new Array(5);
	arr[0] = "Oadd";
	arr[1] = "Oedit";
	arr[2] = "Odelete";
	arr[3] = "Oview";
	arr[4] = "Oother";
	
	flag = true
	
	if (strType=="clear")
		flag = false;
	
	for(i=0;i<5;i++)
	{
		eval(obj+strField+"_"+arr[i]+".checked=flag");
	}
}

//Check & Remove ALL
function ChkRemove1All(chk,allChk)
{
	intLen = eval(obj+chk+".length");
	if (eval(obj+allChk+".checked"))
	{
		checkAll1(chk,allChk);
	}
	else
	{
		if(intLen==null || intLen == "undefined")
			eval(obj+chk+".checked=false");
		else
		{
			for(i=0;i<intLen;i++)
			{
				eval(obj+chk+"["+i+"].checked=false");
			}	
		}
			eval(obj+allChk+".checked=false"); 
	}	
}

//Delete Checked IDs,need to pass CheckBox Name,DeletePage Name, User & Session Values

function deleteAll(chkNM,strPage)
{
	intLen = eval(obj+chkNM+".length");
	strIDs = "";
	if(intLen==null || intLen == "")
	{
		if(eval(obj+chkNM+".checked"))
		{
			strIDs = eval(obj+chkNM+".value") + ",";
		}
	}
	else
	{
		for(i=0;i<intLen;i++)
		{
			if(eval(obj+chkNM+"["+i+"].checked"))
			{
				strIDs = strIDs + eval(obj+chkNM+"["+i+"].value") + ","
			}
		}
	}
	if(strIDs=="")
	{
		alert("Please select IDs to Delete !");
	}
	else
	{
		strIDs = strIDs.substring(0,strIDs.length-1);
		if(confirm("Warning: Are You Sure you want to Delete the Checked Records ?This will delete all the related information ."))
		{
			strUrl = strPage + "?IDs=" + strIDs;
			window.open(strUrl,"delwin","width=500,height=200");
		}
	}	
}

function change_attd(chkNM,strPage,strval)
{
	intLen = eval(obj+chkNM+".length");
	strIDs = "";
	if(intLen==null || intLen == "")
	{
		if(eval(obj+chkNM+".checked"))
		{
			strIDs = eval(obj+chkNM+".value") + ",";
		}
	}
	else
	{
		for(i=0;i<intLen;i++)
		{
			if(eval(obj+chkNM+"["+i+"].checked"))
			{
				strIDs = strIDs + eval(obj+chkNM+"["+i+"].value") + ","
			}
		}
	}
	if(strIDs=="")
	{
		alert("Please select checkbox to update attendance !");
	}
	else
	{
		strIDs = strIDs.substring(0,strIDs.length-1);
		if(confirm("Warning: Are You Sure you want to make changes to the selected Record ."))
		{
			strUrl = strPage + "?IDs=" + strIDs + "&update=" + strval;
			
			window.open(strUrl,"update_attendance","width=500,height=200");
		}
	}	
}

//Check Section
function chk_section(strField,strType)
{
	var arr = new Array(5);
	arr[0] = "Oadd";
	arr[1] = "Oedit";
	arr[2] = "Odelete";
	arr[3] = "Oview";
	arr[4] = "Oother";
	
	flag = true
	
	if (strType=="clear")
		flag = false;
	
	for(i=0;i<5;i++)
	{
		eval(obj+strField+"_"+arr[i]+".checked=flag");
	}
}

//Open Attachment Pop-Up
function attachments()
{
	window.open("attachment.asp","attach","width=450,height=400");
}

//Delete Message
function delete_message(id)
{
	if (confirm("Are you Sure you want to Delete this Message ?"))
	{
		strUrl = "delete_message.asp?ids="+id;
		window.open(strUrl,"delwin","width=150,height=150");
	}	
}

//Send Message Validations
function sendmessage_validate()
{
	arrFlds = "txtSubject:Subject,txtMessage:Message";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		if (indFields[0]=='txtTo')
			eval(obj+"txtTo.focus()");
		else
			eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if (!eval(obj+"txtTo==undefined"))
	{
		if (eval(obj+"txtTo.value==''"))
		{
			alert("Please select one Receiver");
			eval(obj+"txtTo.focus()");
		}
	}
}

//To Disable Department Select when Public Option is choosen
function dis_dept()
{
	if (eval(obj+"poll_type[0].checked"))
	{
		eval(obj+"cblDept.disabled=true");
		eval(obj+"cblDept.selectedIndex=-1");
	}
	else
		eval(obj+"cblDept.disabled=false");
}

function dis_dept1()
{
	obj1 = "document.form2.";
	if (eval(obj1+"poll_type[0].checked"))
	{
		eval(obj1+"cblDept.disabled=true");
		eval(obj1+"cblDept.selectedIndex=-1");
	}
	else
		eval(obj1+"cblDept.disabled=false");
}

function dis_dept2()
{
	if (eval(obj+"radUserType[1].checked"))
	{
		eval(obj+"cblDept.disabled=false");
		
	}
	else
	{
		eval(obj+"cblDept.disabled=true");
		eval(obj+"cblDept.selectedIndex=-1");
	}

}
function attd_Validate()
{
	flag = false;
	if (eval(obj+"radUserType[1].checked"))
	{
		if (eval(obj+"cblDept.selectedIndex")< 0)
			{
			flag = true;
			alert("Please select Department !!");
			}
		else
		flag=false;	
	}		
	if (flag)
	{
	return false;
	}

}
// Check Add Topic Form
function addTopic_validate()
{
	arrFlds = "txtTopicHD:Topic Heading,txtTopic:Topic ";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}

// Check Add Reply Form
function addReply_validate()
{
	arrFlds = "txtReplyHD:Reply Heading,txtReply:Reply ";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}

// Delete Function
function fdelete(tid,rid,typ,fid,pid)
{
	flag = true;
	if(typ=="topic")
	{
		if (!confirm("Warning: Are you Sure you want to delete this Topic ? \n\n All Corresponding Replies would be deleted!!"))
			flag = false;
	}
	else
	{
	if (!confirm("Are you Sure you want to delete this Reply!!"))
			flag = false;
	}
	if(flag)
	{
		strUrl = "delete_forum.asp?topicid="+tid+"&replyID="+rid+"&type="+typ+"&forumID="+fid+"&parentID="+pid;
		//alert(strUrl);
		window.open(strUrl,"delete","width=500,height=400");
	}
}

// Add Project Validate 
function addProject_validate()
{
	var eDate = new Date(eval(obj+"txtEDate.value"));
	var sDate = new Date(eval(obj+"txtSDate.value"));
	arrFlds = "txtPTitle:Project Title,txtProject:Project Description,cblMngr:Project Manager,txtSDate:Start Date";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if (eDate!="" && eDate-sDate < 0)
	{
		alert("Project Start Date should be less than Project End date !!\n\nPlease leave Blank in case you want to enter at later date");
		eval(obj+"txtEDate.value=''");
		return false;
	}
	else if (eval(obj+"cblDept.selectedIndex")< 0)
	{
		alert("Please select Team Department for Project !!");
		return false;
	}
}

// Add Task Validate 
function addTask_validate()
{
	obj1 = "document.form2."
	var eDate = new Date(eval(obj+"txtEDate.value"));
	var sDate = new Date(eval(obj+"txtSDate.value"));
	arrFlds = "txtTTitle:Task Title,txtTask:Task Description,txtSDate:Start Date";
	errMsg = validate(arrFlds);
	if (eval(obj1+"cblProject.value")=="")
	{
		alert("Please select Project !!");
		eval(obj1+"cblProject.focus()");
		return false;
	}
	else if (eval(obj1+"cblUser.value")=="")
	{
		alert("Please select Users ! There should be one User for Task !!");
		//eval(obj1+"cblUser.focus()");
		return false;
	}
	else if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if (eDate!="" && eDate-sDate < 0)
	{
		alert("Task Start Date should be less than Task End date !!\n\nPlease leave Blank in case you want to enter at later date");
		eval(obj+"txtEDate.value=''");
		return false;
	}
	else
	{
		pid = eval(obj1+"cblProject.value");
		lvl = eval(obj1+"cblTask.value");
		
		userLen = eval(obj1+"cblUser.length");
		userIDs = ""
		for(i=0;i<userLen;i++)
		{
			if(eval(obj1+"cblUser[i].selected"))
			userIDs = userIDs + eval(obj1+"cblUser[i].value") + ","
		}	
		if (userIDs!="")
			userIDs = userIDs.substring(0,userIDs.length-1)
					
		eval(obj+"taskUsers.value=userIDs");
		eval(obj+"task_level.value=lvl");
		eval(obj+"PID.value=pid");
		return true;
	}
}

// Edit Task Validate 
function editTask_validate()
{
	obj1 = "document.form2."
	var eDate = new Date(eval(obj+"txtEDate.value"));
	var sDate = new Date(eval(obj+"txtSDate.value"));
	arrFlds = "txtTTitle:Task Title,txtTask:Task Description,txtSDate:Start Date";
	errMsg = validate(arrFlds);
	if (eval(obj1+"cblUser.value")=="")
	{
		alert("Please select Users ! There should be one User for Task !!");
		eval(obj1+"cblUser.focus()");
		return false;
	}
	else if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if (eDate!="" && eDate-sDate < 0)
	{
		alert("Task Start Date should be less than Task End date !!\n\nPlease leave Blank in case you want to enter at later date");
		eval(obj+"txtEDate.value=''");
		return false;
	}
	else
	{
		userLen = eval(obj1+"cblUser.length");
		userIDs = ""
		for(i=0;i<userLen;i++)
		{
			if(eval(obj1+"cblUser[i].selected"))
			userIDs = userIDs + eval(obj1+"cblUser[i].value") + ","
		}	
		if (userIDs!="")
			userIDs = userIDs.substring(0,userIDs.length-1)
					
		eval(obj+"taskUsers.value=userIDs");
		if (eval(obj+"chkHide1.checked"))
			eval(obj+"chkHide.value='on'");
		else
			eval(obj+"chkHide.value='off'");	
		return true;
	}
}

// Delete Task
function delete_task(str,id)
{
	if (confirm("Warning: Are you sure you want to delete this task ? \n\nThis will delete all the sub-Task associated with it ?"))
	{
		strUrl = "delete_task.asp?ids="+id;
		window.open(strUrl,"del","width=500,height=400");
	}
}

function change_project(str)
{
	obj1 = "document.form2.";
	pid= eval(obj1+"cblProject.value");
	url = "add_task.asp?pid="+pid;
	window.location.href=url;
}


// Validate Department
function addDept_validate()
{
	arrFlds = "txtDept:Department Name";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}

// Validate Task Completion
function CTask_validate()
{
	obj = "document.form3.";
	if (!eval(obj+"chkComplete.checked"))
	{
		alert("Please check the Status Complete Checkbox to register completion !");
		return false;
	}
	
}

//To Disable Department for Event Area
function dis_Edept()
{
	if (eval(obj+"chkShow[2].checked"))
		eval(obj+"cblDept.disabled=false");
	else	
	{
		eval(obj+"cblDept.disabled=true");
		eval(obj+"cblDept.selectedIndex=-1");
	}	
}

//To Validate Add Event
function addEvent_validate()
{
	errTim = chkTime();
	arrFlds = "txtTitle:Event Title,txtEvent:Event Description";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if (errTim)
	{
		alert("Starting Event Time cannot be greater than End Event Time");
		eval(obj+"STimeh.focus()");
		return false;
	}
	else if (eval(obj+"chkShow[2].checked"))
	{
		if (eval(obj+"cblDept.selectedIndex")< 0)
		{
			alert("Please select Department !!");
			return false;
		}
	}
	
}

//On Change Date Command
function CMonth(dtDay)
{
	intMonth = eval(obj+"SelMonth.value");
	intYear = eval(obj+"SelYear.value");	
	cdate = intMonth+"/"+dtDay+"/"+intYear;
	strUrl = "view_calendar.asp?cdate="+cdate;
	window.location.href=strUrl;
}

//View Calendar Validate
function view_scheduler()
{
	if (eval(obj+"cblUser.value")=="")
	{
		alert("Please select User");
		eval(obj+"cblUser.focus");
		return false;
	}
}

//Function to delete Forums
function delete_board(id,parent_id)
{
	if(confirm("Are you sure you want to delete this forum ?"))
	{
		strUrl = "delete_board.asp?id="+id+"&pid="+parent_id;
		//alert(strUrl);
		window.open(strUrl,"delwin","width=500,height=450");
	}
}

//Function to delete Forums
function delete_event(id,cdate)
{
	if(confirm("Are you sure you want to delete this Event ?"))
	{
		strUrl = "delete_event.asp?id="+id+"&cdate="+cdate
		//alert(strUrl);
		window.open(strUrl,"delwin","width=650,height=450");
	}
}

function startMsg(str)
{
	strUrl = "../intranet/instantMsg.asp";
window.open(strUrl,"instant","width=400,height=180,scrollbars=no,resizable=no,menubar=no,location=no,status=no");
}

function turnOff()
{
	window.open("../intranet/instantOff.asp","off","width=10,height=10,scrollbars=no,resizable=no,menubar=no,location=no,status=no");
}

function project_report()
{
	if (eval(obj+"SelProject.value")=="")
	{
		alert("Please select Project");
		eval(obj+"SelProject.focus");
		return false;
	}
}

//Sign up Form Validation
function signup_validate()
{
	arrFlds = "txtUsername:User Name,txtPassword:Password,txtFname:First Name,txtLname:Last Name,txtEmail:Email Address";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert("Warning : " + indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if(!chkEmail("txtEmail"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}
	else if (!chkLogin(eval(obj+"txtUsername.value")))
	{
		alert("Invalid Username ! \n Should be consisting of only alphabets,numbers and underscore");
		eval(obj+"txtUsername.focus()");
		eval(obj+"txtUsername.select()");
		return false;
	}
	else if (!chkEquality("txtPassword","txtCPassword"))
	{
		alert("Password Do Not match ! Please Re-Enter");
		eval(obj+"txtPassword.value=''");
		eval(obj+"txtCPassword.value=''");
		eval(obj+"txtPassword.focus()");
		eval(obj+"txtPassword.select()");
		return false;
	}
	else if (!chkLogin(eval(obj+"txtPassword.value")))
	{
		alert(" Invalid Password ! \n Should be consisting of only alphabets,numbers and underscore");
		eval(obj+"txtUserNM.focus()");
		eval(obj+"txtUserNM.select()");
		return false;
	}
}

function checkDates(firstVal,SecondVal)
{
var dateOne = new Date(eval(obj+firstVal+".value"));
//alert(dateOne);
var dateSecond = new Date(eval(obj+SecondVal+".value"));
//alert(dateSecond);
if (dateSecond-dateOne<0)
	return false;
else
	return true;
}


// Add Expense Report Validate 
function addExpense_validate()
{
	var FromDate = new Date(eval(obj+"txtExpFromDate.value"));
	var ToDate = new Date(eval(obj+"txtExpToDate.value"));
	arrFlds = "cblExpGrp:Expense Group,txtAmount:Expense Amount,cblForwardTo:Forward To";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}

	var flag = checkDates("txtExpFromDate","txtExpToDate")
		 if (flag==false)
			{
				alert("Expense From Date should be less than Expense To date !!\n\nPlease leave Blank in case you want to enter at later date");
				eval(obj+"txtExpToDate.value=''");
				return false;
			}
			
	else if (eval(obj+"cblExpGrp.selectedIndex")< 0)
	{
		alert("Please select Expense Group !!");
		return false;
	}
	else if (isNaN(eval(obj+"txtAmount.value")))
	{
		alert("Expense amount should be in numbers only !!");
		eval(obj+"txtAmount.value=''");
		eval(obj+"txtAmount.focus()");
		return false;

	}

	else if (eval(obj+"cblForwardTo.selectedIndex")< 0)
	{
		alert("Please select To Forward !!");
		return false;
	}
}

//To Show the History Or Approve expense report

function ExpAction(Opt,GrpID,strPage)
{
	switch (Opt)
		{
		case 'History':
			sUrl = strPage + "?GrpID=" + GrpID;
			window.open(sUrl,"archive","width=800,height=400");
			break
		case 'Forward':
			sUrl = strPage + "?GrpID=" + GrpID;
			window.open(sUrl,"archive","width=800,height=300");
			break
		case 'View_Archieve':
			sUrl = strPage + "?GrpID=" + GrpID;
			window.location.href=sUrl;
			break
		case 'Return':
			if(confirm("Warning: Are You Sure you want to Return this Expense ?"))
			{
				sUrl = strPage + "?GrpID=" + GrpID + "&Opt=" + Opt;
				window.location.href=sUrl
			}
			break
		case 'Archieve':
			if(confirm("Warning: Are You Sure you want to Archieve this Expense ?"))
			{
				sUrl = strPage + "?GrpID=" + GrpID + "&Opt=" + Opt;
				window.location.href=sUrl
			}
			break
		case 'Approve':
			if(confirm("Warning: Are You Sure you want to Approve this Expense ?"))
			{
				sUrl = strPage + "?GrpID=" + GrpID + "&Opt=" + Opt;
				window.location.href=sUrl
			}
		}
}

// Forward Expense Report Validate 
function Forward_validate()
{
	arrFlds = "cblForwardTo:Forward To";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	else if (eval(obj+"cblForwardTo.selectedIndex")< 0)
	{
		alert("Please select To Forward !!");
		return false;
	}
}

// function to validate Mytask
 function mytask_validate()
 {
 	arrFlds ="txtTitle:Title,txtDescription:Discription" 
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	var flag = checkDates("txtSDate","txtDDate")
	 if (flag==false)
			{
				alert("Due Date of Task cannot be before Start date.");
				eval(obj+"txtDDate.value=''");
				return false;
			}
 }
 
function viewDetails(intID)
{
	strUrl = "../intranet/viewContact_Details.asp?id="+intID;
window.open(strUrl,"instant","width=730,height=320,scrollbars=no,resizable=no,menubar=no,location=no,status=no");
}

// Add New Customer Validations
function customer_validate()
{
	arrFlds = "txtCompname:Company Name,txtCPername:Contact Person Name,txtAdd1:Address 1,txtCity:City,txtPhone1:Phone 1";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}
function creditor_validate()
{
arrFlds = "txtCompname:Company Name,txtAdd1:Address,txtCity:City,txtPhone1:Phone";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}

function add_Recv(strtype)
{
var userVal,showVal;
showVal='';
if (strtype=='a')
{
	len = eval(obj+"cblReceiver.length");
		for(i=0;i<len;i++)
		{
		if (eval(obj+"cblReceiver["+ i +"].selected")==true)
			{
			userVal = eval(obj+"cblReceiver["+ i +"].value")
			showVal = showVal + userVal +",";
			}
		}
		if (showVal=='')
			{
			alert("Please select atleast one Receiver")
			//eval(obj+"cblReceiver.focus()")
			}
		else
			{
			showVal = showVal.substring(0,showVal.length-1)
			eval(obj+"txtTo.value=showVal");
			}
}
else
{
	eval(obj+"txtTo.value=''");
	eval(obj+"cblReceiver.selectedIndex=0")
}
	
}
function net_sales()
{
//selCust,txtRef,txtDate,txtDetail,
//txtGAmount,txtDiscount,txtTax,txtFreight,txtOCharges,txtNet
var GrossVal,DisVal,TaxVal,FrgVal,OtherVal,showVal;

GrossVal 	= eval(obj+"txtGAmount.value");
if (GrossVal=='')
GrossVal=0;
GrossVal	= parseFloat(GrossVal);

DisVal		= eval(obj+"txtDiscount.value")	
if (DisVal=='')
DisVal=0;
DisVal	= parseFloat(DisVal);

TaxVal		= eval(obj+"txtTax.value")
if (TaxVal=='')
TaxVal=0;
TaxVal	= parseFloat(TaxVal);

FrgVal		= eval(obj+"txtFreight.value")
if (FrgVal=='')
FrgVal=0;
FrgVal	= parseFloat(FrgVal);

OtherVal	= eval(obj+"txtOCharges.value")
if (OtherVal=='')
OtherVal=0;
OtherVal	= parseFloat(OtherVal);
	if (DisVal>GrossVal)
		{
		alert("Discount cannot be more than gross value.");
		eval(obj+"txtDiscount.value=''");
		eval(obj+"txtDiscount.focus()");
		}
	else
	{
		showVal	= (GrossVal-DisVal)+(TaxVal+FrgVal+OtherVal);
		eval(obj+"txtNet.value=showVal")
	}
}
//Numeric and zero lenth check
function isNumber(numObj)
	{
		var numValue = eval(obj+numObj+".value");
		if(isNaN(numValue))
		{
			alert("Please enter a numberic value.");
			eval(obj+numObj+".value=''");
			eval(obj+numObj+".focus()");
			
		}	
	}
function validate_Sales()
{
arrFlds = "selCust:Company Name,txtGAmount:Gross Amount";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	NetVal 	= eval(obj+"txtNet.value");
	if (NetVal=='')
	{
	alert("Click calculate button to have net amount");
	eval(obj+"calbtn.focus()");
	return false;
	}
	else
	{
		NetVal	= parseFloat(NetVal);
		PayVal 	= eval(obj+"txtPAmount.value");
		if (PayVal!='')
		PayVal	= parseFloat(PayVal);
		if (PayVal>NetVal)
		{
			alert("Payment Value cannot be more than Net Value");
			eval(obj+"txtPAmount.value=''")
			eval(obj+"txtPAmount.focus()")
			return false;
		}
	}	

}

// function for chnaging company name
function chg_Compname(intcustid)
{ var strurl;
//alert("hi");
	if(confirm("sure to change company name"))
		{
			strurl ="acct_receivable.asp?id=" + intcustid;
			alert(strurl);
			window.location.href=strurl
	    }
}

// function for additional payments bill

function addl_Payment()
{
var BillNo;
BillNo='';
len = eval(obj+"selBillno.length");
		for(i=0;i<len;i++)
			{
				if (eval(obj+"selBillno["+ i +"].selected")== true)
				{
					BillNo = BillNo + eval(obj+"selBillno["+ i +"].value") + ",";
					//showBill = BillNo;
				}
			}
		if (BillNo=='')
			{
			alert("select atleast one Bill for Payment");
			return false;
			}

}

// function to check aomount paid should not greater than Due Balance
 function paidamt_check()
{ 
var paidBillAmt;
paidBillAmt='';
len = eval(obj+"txtpayment.length");
var chkflag= false
//alert(len);
	for(i=0;i<len;i++)
	{
		paidBillAmt = eval(obj+"txtpayment["+ i +"].value");	
		if (isNaN(paidBillAmt))
		{
			break;
			alert("Pls. enter valid numeric value");
			eval(obj+"txtpayment["+ i +"].value=''")
			eval(obj+"txtpayment["+ i +"].focus()")
			return false;
		} 												 
		if(paidBillAmt != "" && paidBillAmt != 0)
		{
			chkflag=true
			break;
		}				
	}		
	if(chkflag)	
	{
		//alert("inside flag is true")
	}
	else
	{
		alert("Please pay atleast one Bill-Enter valid numeric value");
		return false;
	}
var Balance,Payment;
len = eval(obj+"hidtxtbalance.length");
	for(i=0;i<len;i++)
		{
			Balance	= eval(obj+"hidtxtbalance["+ i +"].value");
			Balance	= parseFloat(Balance);
			Payment	= eval(obj+"txtpayment["+ i +"].value");
			Payment	= parseFloat(Payment);
			if (Payment>Balance)
				{
					alert("Payment cannot be more than Balance");
					eval(obj+"txtpayment["+ i +"].value=''")
					eval(obj+"txtpayment["+ i +"].focus()")
					return false;
				}
			
		}		
}