// Define Form Object
var obj
obj = "document.form1."

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;
} 

//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 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;
	}
	
}

//Function to validate Call Type
function  Validate_CallType(x)
{
	x = "document." + x;
	if(eval(x+".txtCalltype.value")=="")
	{
		alert("Please enter Call Type name !!");
		eval(x+".txtCalltype.focus()");
		return false;
	}
}

//Function to validate Category Type
function  Validate_categoryType(x)
{
	x = "document." + x;
	if(eval(x+".txtCategoryType.value")=="")
	{
		alert("Please enter Name !!");
		eval(x+".txtCategoryType.focus()");
		return false;
	}
}

//Function to validate Crm of task status

function  validate_taskstatus(x)
{
	x = "document." + x;
	if(eval(x+".txtTaskstatus.value")== "")
	{
		alert("Please enter Task Status name !!");
		eval(x+".txtTaskstatus.focus()");
		return false;
	}
}
// function to validate potential category of CRMSETUP
/*function validate_category(x)
{
	x = "document." + x;
	arrFlds  = "txtCategoryNM:Category Name,txtProbability:Probability %,txtColorCode:Color Code"
	errFlds  = validate(arrFlds);
	if(errFlds!="")
	{
		arrLen = errFlds.split(":");
		alert(arrLen[1] + " cannot be blank!!");
		eval(x+arrLen[0]+".focus()");
		return false;
	}
}*/

//Function to validate Crm of Event Disc
function  validate_eventdisc(x)
{
	x = "document." + x;
	if(eval(x+".txtEventdisc.value")== "")
	{
		alert("Please enter Event Description name !!");
		eval(x+".txtEventdisc.focus()");
		return false;
	}
}

//Function to validate Certificate Master

function  validate_CertificateMaster(x)
{
	x = "document." + x;
	if(eval(x+".txtCertificatemaster.value")=="")
	{
		alert("Please enter Certificate Master name !!");
		eval(x+".txtCertificatemaster.focus()");
		return false;
	}
}
//Function to validate Competency Master

function  Validate_CompetencyMaster(x)
{
	x = "document." + x;
	if(eval(x+".txtCompetencymaster.value")=="")
	{
		alert("Please enter Competency Master name !!");
		eval(x+".txtCompetencymaster.focus()");
		return false;
	}
}
//Function to validate Contract Type

function  Validate_ContractType(x)
{
	x = "document." + x;
	if(eval(x+".txtContractType.value")=="")
	{
		alert("Please enter Contract Type name !!");
		eval(x+".txtContractType.focus()");
		return false;
	}
}

//Function to validate Coverage Type
function  Validate_CoverageType(x)
{
	x = "document." + x;
	if(eval(x+".txtCoverageType.value")=="")
	{
		alert("Please enter Coverage Type name !!");
		eval(x+".txtCoverageType.focus()");
		return false;
	}
}

//Function to validate Response Time
function  Validate_ResponseTime(x)
{
	x = "document." + x;
	if(eval(x+".txtResponseTime.value")=="")
	{
		alert("Please enter Response Time name !!");
		eval(x+".txtResponseTime.focus()");
		return false;
	}
}
//Function to validate Financial Category Type

function  Validate_FinancialType(x)
{
	x = "document." + x;
	if(eval(x+".txtFinaceType.value")=="")
	{
		alert("Please enter Financial Category Type name !!");
		eval(x+".txtFinaceType.focus()");
		return false;
	}
}
//Function to validate Standard Tool Set

function  Validate_ToolType(x)
{
	x = "document." + x;
	if(eval(x+".txtToolType.value")=="")
	{
		alert("Please enter Standard Tool Set name !!");
		eval(x+".txtToolType.focus()");
		return false;
	}
}
//Function to validate High End Test Equipment

function  Validate_Equipment(x)
{
	x = "document." + x;
	if(eval(x+".txtEquipmentType.value")=="")
	{
		alert("Please enter Equipment name !!");
		eval(x+".txtEquipmentType.focus()");
		return false;
	}
}
//Function to validate Credit Status

function  Validate_CreditStatus(x)
{
	x = "document." + x;
	if(eval(x+".txtCreditstatus.value")=="")
	{
		alert("Please enter Credit Status name !!");
		eval(x+".txtCreditstatus.focus()");
		return false;
	}
}
//Function to validate Department

function  validate_Department(x)
{
	x = "document." + x;
	if(eval(x+".txtDepartment.value")=="")
	{
		alert("Please enter Department name !!");
		eval(x+".txtDepartment.focus()");
		return false;
	}
}

//Function to validate Industry

function  validate_Industry(x)
{
	x = "document." + x;
	if(eval(x+".txtIndustry.value")=="")
	{
		alert("Please enter Industry name !!");
		eval(x+".txtIndustry.focus()");
		return false;
	}
}
// function to validate Work Order Category
function  validate_WorkCategory(x)
{
	x = "document." + x;
	if(eval(x+".txtWorkCategory.value")=="")
	{
		alert("Please enter Work Category !!");
		eval(x+".txtWorkCategory.focus()");
		return false;
	}
}
// function to validate Work Task Type
function  validate_WorkTask(x)
{
	x = "document." + x;
	if(eval(x+".txtWorkTask.value")=="")
	{
		alert("Please enter Work Task Type !!");
		eval(x+".txtWorkTask.focus()");
		return false;
	}
}
/* function to validate email setup*/
function  validate_emailsetup5(x)
{
	x = "document." + x;
	alert(x);
	if(eval(x+".txtSection.value")=="")
	{
		alert("Please enter the section name !!");
		eval(x+".txtSection.focus()");
		return false;
	}
	if(eval(x+".txtEmail.value")=="")
	{
		alert("Please enter email address !!");
		eval(x+".txtEmail.focus()");
		return false;
	}
	 if(!chkEmail("txtEmail"))
	{
		alert("hi");
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}	
}
//Function to validate Network

function  validate_Network(x)
{
	x = "document." + x;
	if(eval(x+".txtNetwork.value")=="")
	{
		alert("Please enter Network name !!");
		eval(x+".txtNetwork.focus()");
		return false;
	}
}
//Function to validate Priority

function  validate_Priority(x)
{
	x = "document." + x;
	if(eval(x+".txtPriority.value")=="")
	{
		alert("Please enter Priority name !!");
		eval(x+".txtPriority.focus()");
		return false;
	}
}

//Function to validate State

function  Validate_State1(x)
{
	x = "document." + x;
	if(eval(x+".selCountry.value")=="")
	{
		alert("Please select country name !!");
		eval(x+".selCountry.focus()");
		return false;
	}
	if(eval(x+".txtState.value")=="")
	{
		alert("Please enter State name !!");
		eval(x+".txtState.focus()");
		return false;
	}
}
function  Validate_State(x)
{
	x = "document." + x;	
	if(eval(x+".txtState.value")=="")
	{
		alert("Please enter State name !!");
		eval(x+".txtState.focus()");
		return false;
	}
}
// function to validate NDA and MSA attachment files
function validate_filename()
{
	if(eval(obj+"strFileNM.value")=="")
	{
		alert("Select a file to be uploaded!!");
		return false;
	}
}
/***********************************
Function to validate Add New user
************************************/ 
function validate_addNewUsers(val,chtype)
{
if (val==3)
{
	if(chtype=='n')
	{ 
		arrFlds = "selSalutation:Salutation,txtFName:First Name,txtLName:Last Name,selDept:Department,txtAddress1:Address,txtCity:City,selCountry:Country,txtZip:Zip,Phone1AreaCode:Phone Area Code";
	}
	else
	{
		arrFlds = "selSalutation:Salutation,txtFName:First Name,txtLName:Last Name,txtAddress1:Address,txtCity:City,selCountry:Country,txtZip:Zip,Phone1AreaCode:Phone Area Code";
	}
 
  
errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	Field="Phone1AreaCode:Phone Area Code,Phone1Prefix:Phone Prefix Number";
		errlength = validateField_length(Field);
		if (errlength!="")
			{
			indFields = errlength.split(":");
			alert("Length of " + indFields[1] + " cannot be Less than 3!");
			eval(obj+indFields[0]+".focus()");					
			return false;
			}
				
		if(eval(obj+"Phone1Post.value").length < 4)
			{
				alert("length of Phone Post number can not be less than 4 ");
				eval(obj+"Phone1Post.focus()");
				return false;
			}
		
		if(eval(obj+"CellAreaCode.value") !="")
			{
				faxField="CellAreaCode:Fax Area Code,CellPrefix:Fax Prefix Number";
				{
				errlength = validateField_length(faxField);
					if (errlength!="")
						{
							indFields = errlength.split(":");
							alert("Length of " + indFields[1] + " cannot be Less than 3!");
							eval(obj+indFields[0]+".focus()");
							return false;
						}
				}	
				if(eval(obj+"CellPost.value").length < 4)
					{
						alert("length of Fax Post number can not be less than 4 ");
						eval(obj+"CellPost.focus()");
						return false;
					}	
			}
}
else
{
arrFlds = "selSalutation:Salutation,txtFName:First Name,txtLName:Last Name,selDept:Department,selUserType:User Type,txtAddress1:Address,txtCity:City,selCountry:Country,txtZip:Zip,Phone1AreaCode:Phone Area Code,txtEmail:Email,txtEmail:Email,txtusername:Username,txtPassword:Password,txtCPassword:Confirm Password";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	Field="Phone1AreaCode:Phone Area Code,Phone1Prefix:Phone Prefix Number";
		errlength = validateField_length(Field);
		if (errlength!="")
			{
			indFields = errlength.split(":");
			alert("Length of " + indFields[1] + " cannot be Less than 3!");
			eval(obj+indFields[0]+".focus()");					
			return false;
			}
				
		if(eval(obj+"Phone1Post.value").length < 4)
			{
				alert("length of Phone Post number can not be less than 4 ");
				eval(obj+"Phone1Post.focus()");
				return false;
			}
		
		if(eval(obj+"CellAreaCode.value") !="")
			{
				faxField="CellAreaCode:Fax Area Code,CellPrefix:Fax Prefix Number";
				{
				errlength = validateField_length(faxField);
					if (errlength!="")
						{
							indFields = errlength.split(":");
							alert("Length of " + indFields[1] + " cannot be Less than 3!");
							eval(obj+indFields[0]+".focus()");
							return false;
						}
				}	
				if(eval(obj+"CellPost.value").length < 4)
					{
						alert("length of Fax Post number can not be less than 4 ");
						eval(obj+"CellPost.focus()");
						return false;
					}	
			}
	
	 if(!chkEmail("txtEmail"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}	
	
	/*if (eval(obj+"txtusername.value").length >10 || eval(obj+"txtusername.value").length < 4)
	{
		alert("User name should be  greater than 4 characters");
		eval(obj+"txtusername.focus()");
		return false;
	}*/
	
	if(eval(obj+"txtusername.value").indexOf("<")> 1 || eval(obj+"txtusername.value").indexOf(">")>1 )
	{
	    alert("special characters are not allow here!")
		eval(obj+"txtusername.focus()");
		return false;
	}
	
	if (eval(obj+"txtPassword.value") != eval(obj+"txtCPassword.value"))
	{
		alert("Confirm password must be same!");
		eval(obj+"txtCPassword"+".focus()");
		return false;
	}
  }
}




/***********************************
Function to validate Edit  user
************************************/ 

function validate_EditUsers()
{

arrFlds = "selSalutation:Salutation,txtFName:First Name,txtLName:Last Name,selDept:Department,txtAddress1:Address,txtCity:City,selCountry:Country,txtZip:Zip,Phone1AreaCode:Phone Area Code,txtEmail:Email";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	Field="Phone1AreaCode:Phone Area Code,Phone1Prefix:Phone Prefix Number";
		errlength = validateField_length(Field);
		if (errlength!="")
			{
			indFields = errlength.split(":");
			alert("Length of " + indFields[1] + " cannot be Less than 3!");					
			eval(obj+indFields[0]+".focus()");
			return false;
			}
				
		if(eval(obj+"Phone1Post.value").length < 4)
			{
				alert("length of Phone Post number can not be less than 4 ");
				eval(obj+"Phone1Post.focus()");
				return false;
			}
		
		if(eval(obj+"CellAreaCode.value") !="")
			{
				faxField="CellAreaCode:Cell Area Code,CellPrefix:Cell Prefix Number";
				{
				errlength = validateField_length(faxField);
					if (errlength!="")
						{
							indFields = errlength.split(":");
							alert("Length of " + indFields[1] + " cannot be Less than 3!");
							eval(obj+indFields[0]+".focus()");
							return false;
						}
				}	
				if(eval(obj+"CellPost.value").length < 4)
					{
						alert("length of Fax Post number can not be less than 4 ");
						eval(obj+"CellPost.focus()");
						return false;
					}	
			}
	
	 if(!chkEmail("txtEmail"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"txtEmail.focus()");
		eval(obj+"txtEmail.select()");
		return false;
	}	
	
	//CHECK FOR PASSWORD
	
	
	opwd = eval(obj+"txtOPassword.value");
	pwd  = eval(obj+"txtPassword.value");
	cpwd = eval(obj+"txtCPassword.value");
	if (opwd!="")
	{
		if (pwd!==cpwd)
		{
		alert('Confirm Password must be same !!');
		eval(obj+"txtCPassword.focus()");
		return false;
		}
		else
		{
			if(pwd=="")
			{
			alert('Please enter the new password.');
			eval(obj+"txtPassword.focus()");
			return false;
			}
		}
	}
	else
	{
		if(pwd==cpwd)
		{
			if (pwd!="")
			{
			alert('Please enter the old password.');
			eval(obj+"txtOPassword.focus()");
			return false;
			}
		}
		else
		{
		alert('Confirm Password must be same !!');
		eval(obj+"txtCPassword.focus()");
		return false;
		}
	}
	
}


function validate(arrFields)
{
	var FieldsArr = arrFields.split(",");
	var arrLen = FieldsArr.length;
	returnStr = "";
	
	for (i=0;i<arrLen;i++)
	{
		indFields = FieldsArr[i].split(":");
		if(eval(obj+indFields[0]+".value")=="")
		{
			returnStr = FieldsArr[i];
			break;
		}
	}
	return returnStr;
}

/************************
	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;
}	

//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_customer()
{
	obj1 = "document.form2.";
	if (eval(obj1+"poll_cust.checked"))
		eval(obj1+"cblCustomer.disabled=false");
	else
	{
		eval(obj1+"cblCustomer.disabled=true");
		eval(obj1+"cblCustomer.selectedIndex=-1");
	}
} */

function dis_dept1()
{
	obj1 = "document.form2.";
	if (eval(obj1+"poll_type[0].checked"))
	{
		eval(obj1+"cblDept.disabled=true");
		eval(obj1+"cblDept.selectedIndex=-1");
		eval(obj1+"cblCustomer.disabled=true");
		eval(obj1+"cblCustomer.selectedIndex=-1");
	}
	if (eval(obj1+"poll_type[1].checked")) 
	{
		eval(obj1+"cblDept.disabled=false");
		eval(obj1+"cblCustomer.disabled=true");
		eval(obj1+"cblCustomer.selectedIndex=-1");
	}
	if (eval(obj1+"poll_type[2].checked")) 
	{
		eval(obj1+"cblCustomer.disabled=false");
		eval(obj1+"cblDept.disabled=true");
		eval(obj1+"cblDept.selectedIndex=-1");
	}
}

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 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 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");
	}
}

// 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 checkAllnew(chkNM)
{
	//Find the Length of the Checkbox for View Open Sites
	
	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)
{
	//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+"ckhALL1.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"); 
	}	
}
//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 selected records? this will delete all the related information"))
		{   
			strUrl = strPage + "?IDs=" + strIDs;
			window.open(strUrl,"delwin","width=500,height=200");
		}
	}	
}

function deleteAllRecord(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 records to delete !");
	}
	else
	{
		strIDs = strIDs.substring(0,strIDs.length-1);
		if(confirm("Warning: Are you sure you want to delete the selected records? This will delete all the related information"))
		{   
			strUrl = strPage + "&IDs=" + strIDs;
			window.open(strUrl,"delwin","width=500,height=200");
		}
	}	
}

//Function to validate FileCategory

function Validate_FileCategory()
{
	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;
	}
	
}

// function validate File
function validate_File()
{
	obj1 = "document.form2."
	var flag = false
	arrFlds = "selCat:Select Category,txtFileDesc:File Description";
	errMsg = validate(arrFlds);
	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 if (eval(obj1+"poll_type[2].checked"))
	{
		if (eval(obj1+"cblCustomer.selectedIndex")< 0)
		{
			alert("Please select Customer for file !!");
			flag = true;
		}
	}
	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 if (eval(obj1+"poll_type[2].checked==true"))
			pollVal = "customer";	
		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)
		
		custLen = eval(obj1 + "cblCustomer.length");		
		custIDs = ""
		for(i=0;i<custLen;i++)
		{
			if (eval(obj1+"cblCustomer[i].selected"))
			custIDs = custIDs + eval(obj1+"cblCustomer[i].value") + ","
		}	
		if(custIDs!="")
			custIDs = custIDs.substring(0,custIDs.length-1)		
		
		//alert("hi");
		eval(obj+"poll_type.value=pollVal");
		eval(obj+"cblDept.value=deptIDs");	
		eval(obj+"cblCustomer.value=custIDs");
		return true;
	}	
	
	
}
//function to validate addVendorEsc.asp

function addVenEsc_validate()
{
	arrFlds = "strSalutation:Salutation,strFname:First Name,strLname:Last Name,strEmail:Email Address"
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if(!(chkEmail("strEmail")))
	{
		alert("Email address should be somename@hostname.com");
		return false;
	}
	Fields    = "PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix Number"
	FieldsLen = validateField_length(Fields)
	if (FieldsLen!="")
	{
		indFields = FieldsLen.split(":");
		alert("Length of " + indFields[1] + " cannot be less than 3 !!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if (eval(obj+"PhPost.value").length < 4)
	{
		alert("Phone Post Number Cannot Be Less Than 4");
		eval(obj+"PhPost.focus()");
		return false;
	}
	if(eval(obj+"selType.value")=="")
	{
		alert("Type cannot be blank!! Please select one.");
		eval(obj+"selType.focus()");
		return false;
	}
}
//function to validate addVendorAR.asp

function addVenAR_validate()
{
	arrFlds = "strSalutation:Salutation,strFname:First Name,strLname:Last Name"
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	Fields    = "PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix Number"
	FieldsLen = validateField_length(Fields)
	if (FieldsLen!="")
	{
		indFields = FieldsLen.split(":");
		alert("Length of " + indFields[1] + " cannot be less than 3 !!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if (eval(obj+"PhPost.value").length < 4)
	{
		alert("Phone Post Number Cannot Be Less Than 4");
		eval(obj+"PhPost.focus()");
		return false;
	}
	if (eval(obj+"FaxAreaCode.value")!="")
	{
		faxField  = "FaxAreaCode:Fax Area Code,FaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3!!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"FaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number Cannot Be Less Than 4!!");
			eval(obj+"FaxPost.focus()");
			return false;
		}
	}
}
// function to validate addVendorContact.asp
function addVenContact_validate()
{
	arrFlds = "contactType:Select Contact Type,strSalutation:Salutation,strFname:First Name,strLname:Last Name,PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix Number,PhPost:Phone Post Number,strUrl:Email Address"
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}	
	
	Fields    = "PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix Number"
	FieldsLen = validateField_length(Fields)
	if (FieldsLen!="")
	{
		indFields = FieldsLen.split(":");
		alert("Length of " + indFields[1] + " cannot be less than 3 !!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if (eval(obj+"PhPost.value").length < 4)
	{
		alert("Phone Post Number Cannot Be Less Than 4");
		eval(obj+"PhPost.focus()");
		return false;
	}
	if (eval(obj+"FaxAreaCode.value")!="")
	{
		faxField  = "FaxAreaCode:Fax Area Code,FaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3!!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"FaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number Cannot Be Less Than 4!!");
			eval(obj+"FaxPost.focus()");
			return false;
		}
	}
	if(!chkEmail("strUrl"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"strUrl.focus()");
		eval(obj+"strUrl.select()");
		return false;
	}	
}

// function to validate addengineer.asp file

function addEngineer_validate()
{
	arrFlds = "strSalutation:Salutation,strFname:First Name ,strLname:Last Name,PhAreaCode:Phone Area Code"	
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	Fields    = "PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix Number"
	FieldsLen = validateField_length(Fields)
	if (FieldsLen!="")
	{
		indFields = FieldsLen.split(":");
		alert("Length of " + indFields[1] + " cannot be less than 3 !!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if (eval(obj+"PhPost.value").length < 4)
	{
		alert("Phone Post Number Cannot Be Less Than 4");
		eval(obj+"PhPost.focus()");
		return false;
	}
	
	if (eval(obj+"CellAreaCode.value")!="")
	{
		faxField  = "CellAreaCode:Cell Area Code,CellPrefix:Cell Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3!!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"CellPost.value").length < 4)
		{
			alert("Length of Cell Post Number Cannot Be Less Than 4!!");
			eval(obj+"CellPost.focus()");
			return false;
		}
	}
	
	if (eval(obj+"FaxAreaCode.value")!="")
	{
		faxField  = "FaxAreaCode:Fax Area Code,FaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3!!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"FaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number Cannot Be Less Than 4!!");
			eval(obj+"FaxPost.focus()");
			return false;
		}
	}
	if(eval(obj+"strEmail.value")=="")
	{
		alert("Email cannot be blank!!");
		eval(obj+"strEmail.focus()");
		return false;
	}
	if(!(chkEmail("strEmail")))
	{
		alert("Invalid Email Address ! Should be in somename@hostname.com");
		eval(obj+"strEmail.focus()");
		return false;
	}
	// checks after hour reach no if not blank
	if (eval(obj+"afterHrAreaCode.value")!="")
	{
		afterHrField  = "afterHrAreaCode:After Hours Area Code,afterHrPrefix:After Hours Prefix Number"
		afterHrFldLen = validateField_length(afterHrField);
		if (afterHrFldLen!="")
		{
			indAfterHrFld = afterHrFldLen.split(":");
			alert("Length of " + indAfterHrFld[1] + " cannot be less than 3!!");
			eval(obj+indAfterHrFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"afterHrPost.value").length < 4)
		{
			alert("Length of After Hours Post Number Cannot Be Less Than 4!!");
			eval(obj+"afterHrPost.focus()");
			return false;
		}
	}
}
/*
function submit_addvendor(strNav,strPg)
{
	eval(obj+"action='addVendor.asp?"+strNav+"&pg="+strPg+"'");
	eval(obj+"submit()");
	return false;	
}*/
// Function to add attachments from registration page
function add_Attachment1(type)
{
	if(type=='n')
	{
//		alert(type);
		strUrl="vendor/add_attachment.asp?strType="+type+"";
		window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
	}
	if(type=='m')
	{
		strUrl="vendor/add_attachment.asp?strType="+type+"";
		window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
	}
}

// Function to add attachments
function add_Attachment(type)
{
	if(type=='n')
	{
//		alert(type);
		strUrl="add_attachment.asp?strType="+type+"";
		window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
	}
	if(type=='m')
	{
		strUrl="add_attachment.asp?strType="+type+"";
		window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
	}
}
// Function to add new Department

function open_addDepartment()
{
	strUrl = "add_department.asp";	
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
} 

// Function to add new engineer certificates
function open_addvendorEnggCertificate(enggid,venderid,sessionid,uid)
{
	strUrl = "viewEngCertificate.asp?enggID=" + enggid + "&venderID=" + venderid + "&sessionID="+ sessionid + "&userid=" + uid;
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
}
//function to validate engineer competancies
function addEngCompete_Validate()
{	
	
	arrFlds = "intEnggComp:Engineer Competancies,intContractType:Contract Type,intGrade:Engineer Grade,strOriginationDT:Origination Date";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}	
}
// validate add new department
function addDepartment_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;
	}	
}

//function to delete engineer certification
function DeleteCertifications(sessionid,userid,serialid,enggid,strtyp)
{
	if(confirm("Are You Sure to Delete This Record ?"))
	{		
		if (strtyp =="c")
		{
			window.location.href = "../vendor/delEngCertification.asp?sessionID=" + sessionid + "&userid=" + userid + "&serialID=" + serialid + "&enggID=" + enggid;
		}
				
	}
}
//function to delete vendor contact

function DeleteContact(sessionid,userid,contactid,vendorid,strtyp)
{
	if(confirm("Are You Sure to Delete This Record ?"))
	{		
		if (strtyp =="c")
		{
			window.location.href = "../vendor/delete_venContact.asp?sessionID=" + sessionid + "&userID=" + userid + "&IDs=" + contactid + "&venID=" + vendorid;
		}
				
	}
}

//  function to delete site information
function delete_site(sessionid,userid,siteid)
{
	if(confirm("Are You Sure to Delete This Record ?"))
	{		
		window.location.href = "../site/delete_site.asp?sessionID=" + sessionid + "&userID=" + userid +  "&id=" + siteid;
	}
}
// function to delete vendor escalation
function DeleteEscalation(sessionid,userid,venescid,vendorid,strtyp)
{
	if(confirm("Are You Sure to Delete This Record ?"))
	{		
		if (strtyp =="e")
		{
		window.location.href = "../vendor/delete_venEscalaiton.asp?sessionID=" + sessionid + "&userID=" + userid + "&IDs=" + venescid + "&venID=" + vendorid;
		}
				
	}
}
// function to delete engineer profile
function DeleteEngProfile(sessionid,userid,venengid,vendorid)
{
	if(confirm("Are You Sure to Delete This Record ?"))
	{		
		window.location.href = "../vendor/delete_venEngineer.asp?sessionID=" + sessionid + "&userID=" + userid + "&IDs=" + venengid + "&venID=" + vendorid;
	}
}
// function to delete user information from userdetail.asp
function deleteUserDetail(sessionid,userid,uid)
{
	if(confirm("Are You Sure to Delete This Record ?"))
	{		
		window.location.href = "../crm/delete_user1.asp?sessionID=" + sessionid + "&userID=" + userid + "&IDs=" + uid;
	}
}

// function to delete all the vendor information

function delete_vendor(sessionid,userid,vendorid)
{
	if(confirm("Are You Sure to Delete This Record ?"))
	{		
		window.location.href = "../vendor/delete_vendor.asp?sessionID=" + sessionid + "&userID=" + userid + "&venID=" + vendorid;
	}
}

function DeleteRecord(strUserID,strsess,DelID,strtyp)
{
	if(confirm("Are You Sure to Delete this Record ?"))
	{		
		if (strtyp =="c")
		{
		window.location.href = "../customer/delete_customer1.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID;
		}
				
	}
}


function DeleteRecord1(strUserID,strsess,DelID,CusID,strtyp)
{
	if(confirm("Are You Sure to Delete this Record ?"))
	{		
		if (strtyp =="co")
		{
		window.location.href = "../customer/delete_contact.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID+ "&CID=" + CusID;
		}
		else if (strtyp =="s")
		{
		window.location.href = "../customer/delete_site.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID+ "&CID=" + CusID;
		}
				
	}
}

function DeleteRecord2(strUserID,strsess,DelID,CusID,strtyp)
{
	if(confirm("Are You Sure to Delete this Record ?"))
	{		
		if (strtyp =="co")
		{
		window.location.href = "../customer/delete_contact.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID + "&CID=" + CusID + "&type=" + strtyp;
		}
		else if (strtyp =="s")
		{
		window.location.href = "../customer/site_delete.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID+ "&CID=" + CusID +"&type=" + strtyp;
		}
				
	}
}

// Function delete contact site
function DeleteSiteContact(strUserID,strSess,DelID,CusID,SiteID,strtyp)
{
	if(confirm("Are You Sure to Delete this Record ?"))
	{		
		if (strtyp =="ca")
		{
		window.location.href = "../site/delete_contactsite.asp?userid=" + strUserID + "&sessionID=" + strSess +"&ID=" + DelID + "&CID=" + CusID + "&siteID=" + SiteID + "&type=" + strtyp;
		}
		else if (strtyp =="cs")
		{
		window.location.href = "../site/delete_contactsite.asp?userid=" + strUserID + "&sessionID=" + strSess +"&ID=" + DelID+ "&CID=" + CusID + "&siteID=" + SiteID;
		}
				
	}
}

// Function validate Add New Site
function addSite_validate()
{
	arrFlds = "selCustID:Customer Name,txtTitle:Site Title";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}	
	if(eval(obj+"txtNote.value").length >=500)
	{
		alert("Notes should not exceed 500 characters");
		eval(obj + "txtNote.focus()");
		return false;
	}	 	
	// ************ this part works for contact fields  *********************
	arrFlds1 = "str_Salutation:Salutation,str_FirstName:First Name,str_LastName:Last Name";
	errMsg1 = validate(arrFlds1);
	if (errMsg1!="")
	{
		indFields1 = errMsg1.split(":");
		alert(indFields1[1] + " cannot be Blank!");
		eval(obj+indFields1[0]+".focus()");
		return false;
	}	 	
	//checks phone number if the fields are not blank
	if (eval(obj+"PhAreaCode.value")!="")
	{
		faxField  = "PhAreaCode:Phone Area Code,Phprefix:Phone Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"PhPost.value").length < 4)
		{
			alert("Length of Phone Post Number cannot be less than 4 !!");
			eval(obj+"PhPost.focus()");
			return false;
		}
	}
	//checks cell number if the fields are not blank
	if (eval(obj+"CellAreaCode.value")!="")
	{
		faxField  = "CellAreaCode:Cell Area Code,Cellprefix:Cell Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"CellPost.value").length < 4)
		{
			alert("Length of Cell Post Number cannot be less than 4 !!");
			eval(obj+"CellPost.focus()");
			return false;
		}
	}
	//checks fax number if the fields are not blank
	if (eval(obj+"FaxareaCode.value")!="")
	{
		faxField  = "FaxareaCode:Fax Area Code,FaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"FaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number cannot be less than 4 !!");
			eval(obj+"FaxPost.focus()");
			return false;
		}
	}
	//checks after hours reach number if the fields are not blank
	if (eval(obj+"AHareaCode.value")!="")
	{
		faxField  = "AHareaCode:After Hours Area Code,AHPrefix:After Hours Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"AHPost.value").length < 4)
		{
			alert("Length of After Hours Post Number cannot be less than 4 !!");
			eval(obj+"AHPost.focus()");
			return false;
		}
	}
	if(eval(obj + "str_Email.value")=="")
	{
		alert("Email address cannot be blank !");
		eval(obj + "str_Email.focus()");
		return false;
	}
	if(!chkEmail("str_Email"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"str_Email.focus()");
		eval(obj+"str_Email.select()");
		return false;
	}	
	if(eval(obj+"txtNote.value").length >= 500)
	{
		alert("Notes should not exceed 500 characters");
		return false;
	}
}

// Function validate edit Site
function addSite_validate1()
{
	arrFlds = "txtTitle:Site Title";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}	
	if(eval(obj+"txtNote.value").length >=500)
	{
		alert("Notes should not exceed 500 characters");
		eval(obj + "txtNote.focus()");
		return false;
	}	 	
}
// Function validate Add Site
function addSite_validate()
{
	arrFlds = "txtTitle:Site Title";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}	
	if(eval(obj+"txtNote.value").length >=500)
	{
		alert("Notes should not exceed 500 characters");
		eval(obj + "txtNote.focus()");
		return false;
	}	 	
	// ************ this part works for contact fields  *********************
	arrFlds1 = "str_Salutation:Salutation,str_FirstName:First Name,str_LastName:Last Name";
	errMsg1 = validate(arrFlds1);
	if (errMsg1!="")
	{
		indFields1 = errMsg1.split(":");
		alert(indFields1[1] + " cannot be Blank!");
		eval(obj+indFields1[0]+".focus()");
		return false;
	}	 	
	//checks phone number if the fields are not blank
	if (eval(obj+"PhAreaCode.value")!="")
	{
		faxField  = "PhAreaCode:Phone Area Code,Phprefix:Phone Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"PhPost.value").length < 4)
		{
			alert("Length of Phone Post Number cannot be less than 4 !!");
			eval(obj+"PhPost.focus()");
			return false;
		}
	}
	//checks cell number if the fields are not blank
	if (eval(obj+"CellAreaCode.value")!="")
	{
		faxField  = "CellAreaCode:Cell Area Code,Cellprefix:Cell Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"CellPost.value").length < 4)
		{
			alert("Length of Cell Post Number cannot be less than 4 !!");
			eval(obj+"CellPost.focus()");
			return false;
		}
	}
	//checks fax number if the fields are not blank
	if (eval(obj+"FaxareaCode.value")!="")
	{
		faxField  = "FaxareaCode:Fax Area Code,FaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"FaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number cannot be less than 4 !!");
			eval(obj+"FaxPost.focus()");
			return false;
		}
	}
	//checks after hours reach number if the fields are not blank
	if (eval(obj+"AHareaCode.value")!="")
	{
		faxField  = "AHareaCode:After Hours Area Code,AHPrefix:After Hours Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"AHPost.value").length < 4)
		{
			alert("Length of After Hours Post Number cannot be less than 4 !!");
			eval(obj+"AHPost.focus()");
			return false;
		}
	}
	if(eval(obj + "str_Email.value")=="")
	{
		alert("Email address cannot be blank !");
		eval(obj + "str_Email.focus()");
		return false;
	}
	if(!chkEmail("str_Email"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"str_Email.focus()");
		eval(obj+"str_Email.select()");
		return false;
	}	
	if(eval(obj+"txtNote.value").length >= 500)
	{
		alert("Notes should not exceed 500 characters");
		return false;
	}
}


// function validate Add Contact Site

function addSiteContact_validate()
{
	arrFlds = "str_Salutation:Salutation,str_FirstName:First Name,str_LastName:Last Name";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	//checks Phone number if the fields are not blank
	if (eval(obj+"PhAreaCode.value")!="")
	{
		faxField  = "PhAreaCode:Phone Area Code,Phprefix:Phone Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"PhPost.value").length < 4)
		{
			alert("Length of Phone Post Number cannot be less than 4 !!");
			eval(obj+"PhPost.focus()");
			return false;
		}
	}
	//checks cell number if the fields are not blank
	if (eval(obj+"CellAreaCode.value")!="")
	{
		faxField  = "CellAreaCode:Cell Area Code,Cellprefix:Cell Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"CellPost.value").length < 4)
		{
			alert("Length of Cell Post Number cannot be less than 4 !!");
			eval(obj+"CellPost.focus()");
			return false;
		}
	}
	//checks fax number if the fields are not blank
	if (eval(obj+"FaxareaCode.value")!="")
	{
		faxField  = "FaxareaCode:Fax Area Code,FaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"FaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number cannot be less than 4 !!");
			eval(obj+"FaxPost.focus()");
			return false;
		}
	}
	//checks after hours reach number if the fields are not blank
	if (eval(obj+"AHareaCode.value")!="")
	{
		faxField  = "AHareaCode:After Hours Area Code,AHPrefix:After Hours Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3 !!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"AHPost.value").length < 4)
		{
			alert("Length of After Hours Post Number cannot be less than 4 !!");
			eval(obj+"AHPost.focus()");
			return false;
		}
	}
	if(eval(obj + "str_Email.value")=="")
	{
		alert("Email address cannot be blank !");
		eval(obj + "str_Email.focus()");
		return false;
	}
	if(!chkEmail("str_Email"))
	{
		alert("Invalid Email Format ! Should be in somename@hostname.com");
		eval(obj+"str_Email.focus()");
		eval(obj+"str_Email.select()");
		return false;
	}	
	if(eval(obj+"txtNote.value").length >= 500)
	{
		alert("Notes should not exceed 500 characters");
		return false;
	}
}

// Function to validate add Site Voice 

function addSiteVoice_validate()
{
	arrFlds = "";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	 
}

// Function to validate Edit of Customer's Generl info and for Customer Clone

function Editcustomer_validate()
{

		arrFlds = "str_clientname:Client Name,str_address1:Address1,str_city:City,intCountry:Country,str_zipcode:ZipCode,intIndustry:Industry,intAccountStatus:Account Status,intCreditStatus:Credit Status,str_noofsites:No of Sites,str_dbnumber:DB Number";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}	
	Fields    = "clientPhoneAreaCode:Phone Area Code,clientPhoneprefix:Phone Prefix Number"
	FieldsLen = validateField_length(Fields)
	if (FieldsLen!="")
	{
		indFields = FieldsLen.split(":");
		alert("Length of " + indFields[1] + " cannot be less than 3 !!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if (eval(obj+"clientPhonePost.value").length < 4)
	{
		alert("Phone Post Number Cannot Be Less Than 4");
		eval(obj+"clientPhonePost.focus()");
		return false;
	}
	if (eval(obj+"ClientFaxareaCode.value")!="")
	{
		faxField  = "ClientFaxareaCode:Fax Area Code,ClientFaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3!!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"ClientFaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number Cannot Be Less Than 4!!");
			eval(obj+"ClientFaxPost.focus()");
			return false;
		}
	}
	strval=eval(obj+"str_noofsites.value");
		if (strval!='')
		{
			if(isNaN(strval))
			{
				alert("Please enter numeric value for Sites");
				eval(obj+"str_noofsites"+".focus()");					
				return false;
			}		
		}	
}

// function to validate vendor's & its general information

function Editvendor_validate(dispvalues)
{
      

		arrFlds = "strVendorNM:Vendor Name,strVendorAddress1:Address1,strCity:City,intCountry:Country,strVendorZip:Zip Code,PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix,PhPost:Phone Post,intVendorStatus:Status,strDBNo:DB Number,fedTaxID:Fed Tax ID,saleTaxNo:Sale Tax Number,intPPMRate:Busines Day Rate,intAfterHrRate:After Hours Rate,intTopology:Toplogies,noofEngineer:Number of Engineer";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}	
	
	//Check whether consent date is fillup or not
	/*	if(eval(obj+"btConsent[0].checked"))
        {
			dtConsent = eval(obj+"dtConsent.value");
			if(dtConsent=='') 
			{
            	alert("Consent Date can not be Blank !!!");
            	eval(obj+"dtConsent.focus()");
            	return false;
			}	
        } */
		
	Fields    = "PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix Number"
	FieldsLen = validateField_length(Fields);
	if (FieldsLen!="")
	{
		indFields = FieldsLen.split(":");
		alert("Length of " + indFields[1] + " cannot be less than 3 !!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if (eval(obj+"PhPost.value").length < 4)
	{
		alert("Phone Post Number Cannot Be Less Than 4");
		eval(obj+"PhPost.focus()");
		return false;
	}
	if (eval(obj+"FaxAreaCode.value")!="")
	{
		faxField  = "FaxAreaCode:Fax Area Code,FaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3!!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"FaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number Cannot Be Less Than 4!!");
			eval(obj+"FaxPost.focus()");
			return false;
		}
	}
	// checks integer fields of general info		
	intFields ="intPPMRate:Busines Day Rate,intAfterHrRate:After Hours Rate,intEmergencyRate:Emergency Rate,intHolidayRate:Holiday Rate,noofEngineer:Number of Engineer" 
		
			var FieldsArr = intFields.split(",");
			var arrLen = FieldsArr.length;
			for (i=0;i<arrLen;i++)
			{
				indFields = FieldsArr[i].split(":");
				strVal = eval(obj+indFields[0]+".value")
				if (strVal!="")
				{
					if(isNaN(strVal))
					{
						alert("Please enter numeric value in " + indFields[1]);
						eval(obj + indFields[0] + ".focus()"); 
						return false;
					}
				}
			}
		
	if (dispvalues=="True")
	
		{
			
			if(eval(obj+"btChoice.value")=="")
			{
		  	alert("Please select Registration type!!");
eval(obj+"btChoice.focus()");
return false;
			}
		} 		
			
} 

function Editvendor_General(dispval)
{
  arrFlds = "txtFname:Vendor Frist Name,txtLname:Vendor Last Name,strVendorAddress1:Address1,strCity:City,intCountry:Country,strVendorZip:Zip Code,PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix,PhPost:Phone Post,intVendorStatus:Status,socialSecurityNo:Social Security Number,txtEmailAdd:Email Address,intPPMRate:Busines Day Rate,intAfterHrRate:After Hours Rate,intTopology:Toplogies";

	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + "cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	
	Fields    = "PhAreaCode:Phone Area Code,PhPrefix:Phone Prefix Number"
	FieldsLen = validateField_length(Fields);
	if (FieldsLen!="")
	{
		indFields = FieldsLen.split(":");
		alert("Length of " + indFields[1] + " cannot be less than 3 !!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if (eval(obj+"PhPost.value").length < 4)
	{
		alert("Phone Post Number Cannot Be Less Than 4");
		eval(obj+"PhPost.focus()");
		return false;
	}
	
	if (eval(obj+"FaxAreaCode.value")!="")
	{
		faxField  = "FaxAreaCode:Fax Area Code,FaxPrefix:Fax Prefix Number"
		FaxFldLen = validateField_length(faxField);
		if (FaxFldLen!="")
		{
			indFaxFld = FaxFldLen.split(":");
			alert("Length of " + indFaxFld[1] + " cannot be less than 3!!");
			eval(obj+indFaxFld[0]+".focus()");
			return false;
		}
		if (eval(obj+"FaxPost.value").length < 4)
		{
			alert("Length of Fax Post Number Cannot Be Less Than 4!!");
			eval(obj+"FaxPost.focus()");
			return false;
		}
	}
	
	
	// checks integer fields of general info		
	intFields ="intPPMRate:Busines Day Rate,intAfterHrRate:After Hours Rate,intEmergencyRate:Emergency Rate,intHolidayRate:Holiday Rate" 
		
			var FieldsArr = intFields.split(",");
			var arrLen = FieldsArr.length;
			for (i=0;i<arrLen;i++)
			{
				indFields = FieldsArr[i].split(":");
				strVal = eval(obj+indFields[0]+".value")
				if (strVal!="")
				{
					if(isNaN(strVal))
					{
						alert("Please enter numeric value in " + indFields[1]);
						eval(obj + indFields[0] + ".focus()"); 
						return false;
					}
				}
			}
	

}


function deleteAllID(chkNM,strPage,strtype,strUserID,strsess)
{
	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 +"&type=" +strtype +"&userid=" + strUserID + "&sessionID=" + strsess ;
			window.location.href=strUrl;
		}
	}	
	
}


function DeleteClient(strUserID,strsess,DelID,strtyp)
{
	if(confirm("Are You Sure to Delete this Record ?"))
	{		
		if (strtyp =="c")
		{
		window.location.href = "../crm/delete_potentialclient.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID +"&type=" +strtyp;
		}
				
	}
}



// Delete Potential Contact

function DeletePotentialContact(strUserID,strsess,DelID,potID,strtyp)
{
	if(confirm("Are You Sure to Delete this Record ?"))
	{		
		if (strtyp =="co")
		{
		
		window.location.href = "../crm/delete_potentialcontact.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID + "&potId=" + potID + "&type=" + strtyp;
		}
		if (strtyp =="c")	
		{
		window.location.href = "../crm/delete_potentialcontact.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID + "&potId=" + potID;
		}
				
	}
}

function open_addFiles(id)
{
	strUrl = "add_downloadfile.asp?id="+id;	
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes,resizable=yes");
} 
function open_addFiles1(id)
{
	strUrl = "add_downloadfile.asp?id="+id;	
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
} 
function open_uploadnewesFiles(id)
{
	strUrl = "view_publicnews.asp?id="+id;	
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes,resizable=yes");
} 

// Function  delete Potential Events

function DeletePotentialEvent(strUserID,strsess,DelID,potID,strtyp,typeFile)
{
	if(confirm("Are You Sure to Delete this Record ?"))
	{		
		if(typeFile="E")		// " E " refers Potential Events
		{
			if (strtyp =="co")
			{
		
				window.location.href = "../crm/delete_potentialevents.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID + "&potId=" + potID + "&type=" + strtyp;
			}
			if (strtyp =="c")	
			{
				window.location.href = "../crm/delete_potentialevents.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID + "&potId=" + potID;
			}
		}				
		
		if(typeFile="T")			// " T " refers Potential task
		{
			if (strtyp =="co")
			{
		
				window.location.href = "../crm/delete_potentialtask.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID + "&potId=" + potID + "&type=" + strtyp;
			}
			if (strtyp =="c")	
			{
				window.location.href = "../crm/delete_potentialtask.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID + "&potId=" + potID;
			}
		}	
	}
}

// functon Delete projects

function DeleteProject(strUserID,strsess,DelID)
	{
		if (confirm("Are you sure to delete this record ?"))
			{
				window.location.href = "../crm/delete_project.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID ;
			}
	}
	
	
function RecordType(id,userID,strsess,ptype)
{
	if (ptype=="a")
	{
		window.location.href = "../workorder/addworkorder.asp?userid=" + userID + "&sessionID=" + strsess + "&custID=" + id;		
	}	
}
function RecordType1(id,userID,strsess,custID,ptype)
{
	if (ptype=="s")
	{
		window.location.href = "../workorder/addworkorder.asp?userid=" + userID + "&sessionID=" + strsess + "&custID="+custID +"&siteID="+id;		
	}	
}		

// function to return the id of project

function change_project(uid,sess)
{	
	obj1 = "document.form2.";
	pid = eval(obj1+"SelProjectTitle.value");	
	url = "addprojecttask.asp?pid="+pid +"&userid=" + uid + "&sessionID=" +sess;
	window.location.href=url;
}

function addProjectTask_validate()
	{
	obj1 = "document.form2."
	var eDate = new Date(eval(obj+"dtEndDate.value"));
	var sDate = new Date(eval(obj+"dtStartDate.value"));
	arrFlds = "txtTitle:Task Title,txtDescription:Task Description,dtStartDate:Start Date";
	errMsg = validate(arrFlds);	
	if (eval(obj1+"SelProjectTitle.value")=="")
	{
		alert("Please select Project !!");
		eval(obj1+"SelProjectTitle.focus()");
		return false;
	}
	else if (eval(obj1+"selTeam.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+"dtEndDate.value=''");
		return false;
	}
	else
	{
		pid = eval(obj1+"SelProjectTitle.value");
		lvl = eval(obj1+"selTaskLevel.value");
		
		userLen = eval(obj1+"selTeam.length");
		userIDs = ""
		for(i=0;i<userLen;i++)
		{
			if(eval(obj1+"selTeam[i].selected"))
			userIDs = userIDs + eval(obj1+"selTeam[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;
	}
}	

function editProjectTask_validate()
	{
	var obj1
	obj1 = "document.form2."
	var eDate = new Date(eval(obj+"dtEndDate.value"));
	var sDate = new Date(eval(obj+"dtStartDate.value"));
	arrFlds = "txtTitle:Task Title,txtDescription:Task Description,dtStartDate:Start Date";
	errMsg = validate(arrFlds);
	if (eval(obj1+"selTeam.value")=="")
	{
		alert("Please select Users ! There should be one User for Task !!");
		eval(obj1+"selTeam.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+"dtEndDate.value=''");
		return false;
	}
	else
	{
		userLen = eval(obj1+"selTeam.length");
		userIDs = ""
		for(i=0;i<userLen;i++)
		{
			if(eval(obj1+"selTeam[i].selected"))
			userIDs = userIDs + eval(obj1+"selTeam[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;
	}
}

// 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;
	}
	
}		
function DeleteProjectTask(strUserID,strsess,DelID)
	{
		if (confirm("Are you sure to delete this record ?"))
			{
				window.location.href = "../crm/delete_projecttask.asp?userid=" + strUserID + "&sessionID=" + strsess +"&IDs=" + DelID ;
			}
	}
	
	
function category(uid,sess)
{
	pid = eval(obj+"selcat.value");	
	url = "potentialclient.asp?cid="+pid +"&userid=" + uid + "&sessionID=" +sess;
	window.location.href=url;
}

function validateField_length(arrfld)
{
	
	var FieldsArr = arrfld.split(",");
	var arrLen = FieldsArr.length;
	returnStr = "";
	for (i=0;i<arrLen;i++)
	{
		indFields = FieldsArr[i].split(":");
		if((eval(obj+indFields[0]+".value").length)<3)
		{
			returnStr = FieldsArr[i];
			break;
		}
	}
	return returnStr;
}

function validateLastField_length(arrfld)
{
	
	var FieldsArr = arrfld.split(",");
	var arrLen = FieldsArr.length;
	returnStr = "";
	for (i=0;i<arrLen;i++)
	{
		indFields = FieldsArr[i].split(":");
		if((eval(obj+indFields[0]+".value").length)<4)
		{
			returnStr = FieldsArr[i];
			break;
		}
	}
	return returnStr;
}

function showContact(fld,nav)
{
	if (fld.value!="")
	{
		url = "adduser.asp?" + nav + "&companyID=" + fld.value;
		window.location.href=url;
	}	
	
}

function fillContact(fld,nav,compID)
{
	if (fld.value!="")
	{
		url = "adduser.asp?" + nav + "&companyID=" + compID + "&contactID=" + fld.value;
		window.location.href=url;
	}	
	
}


// function to validate addengineer.asp file

function validate_adduser()
{
   
	arrFlds = "cblCompany:Company Name,str_Salutation:Salutation,str_FirstName:First Name,str_LastName:Last Name,str_Title:Title,str_usertype:User Type,str_Email:Email Address,str_username:User Name,txtPassword:Password,txtCPassword:Confirm Password"	

    
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
		
	if(!(chkEmail("str_Email")))
	{
		alert("Invalid Email Address ! Should be in somename@hostname.com");
		eval(obj+"str_Email.focus()");
		return false;
	}
	
	/*if (eval(obj+"str_username.value").length >10 || eval(obj+"str_username.value").length < 4)
	{
		alert("User name should greater than 4 characters");
		eval(obj+"str_username.focus()");
		return false;
	}
	
	if(eval(obj+"str_username.value").indexOf("<")> 1 || eval(obj+"str_username.value").indexOf(">")>1 )
	{
	    alert("special characters are not allow here!")
		eval(obj+"str_username.focus()");
		return false;
	}
	*/

	if (eval(obj+"txtPassword.value") != eval(obj+"txtCPassword.value"))
	{
		alert("Confirm password must be same!");
		eval(obj+"txtCPassword"+".focus()");
		return false;
	}
 
	if (eval(obj+"passwordExpire(1).checked"))
	{
	
		if (eval(obj+"txtPasswordDate.value==''"))
		{
		alert("Please fill the date of password expires!");
		return false;
		}
	}

}	

//function to delete user

function delete_user(sessionid,userid,deluserid)
{
	if(confirm("Are You Sure to Delete This Record ?"))
	{		
		window.location.href = "../user/delete_user.asp?sessionID=" + sessionid + "&userID=" + userid + "&IDs=" + deluserid ;
				
	}
}



// function to validate addengineer.asp file

function validate_edituser()
{
	arrFlds = "str_Salutation:Salutation,str_FirstName:First Name,str_LastName:Last Name,str_Email:Email Address,txtPassword:Password,txtCPassword:Confirm Password"	
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
		
	if(!(chkEmail("str_Email")))
	{
		alert("Invalid Email Address ! Should be in somename@hostname.com");
		eval(obj+"str_Email.focus()");
		return false;
	}

	if (eval(obj+"txtPassword.value") != eval(obj+"txtCPassword.value"))
	{
		alert("Confirm password must be same!");
		eval(obj+"txtCPassword"+".focus()");
		return false;
	}
 
	if (eval(obj+"passwordExpire(1).checked"))
	{
	
		if (eval(obj+"txtPasswordDate.value==''"))
		{
		alert("Please fill the date of password expires!");
		return false;
		}
	}

}	

function validate_upload()
{
   	arrFlds = "intchannelpartnerID:Channel Partner,txtFile:Image Upload";	
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}

}
function editPotentialClient_validate()
{
arrFlds = "txtCompanyName:Company Name, txtAddress1:Address1,txtCity:City,txtZip:Zip";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	
	var boolph;
		boolph=false;
		
		if (eval(obj+"Phone1AreaCode.value")=="")
		{
		boolph=true
		}
		if (eval(obj+"Phone1Prefix.value")=="")
		{
		boolph=true
		}
		if (eval(obj+"Phone1Post.value")=="")
		{
		boolph=true
		}
		
		if (boolph== true)
		{
		alert("Please enter complete Phone  Number");		
		return false;		
		}		
		if(eval(obj+"Phone1AreaCode.value").length < 3)
		{
		alert("the code should not be less than 3 digits");
		return false;
		}
		
		if(eval(obj+"Phone1Prefix.value").length < 3)
		{
		alert("the code should not be less than 3 digits");
		return false;
		}		
		
		if(eval(obj+"Phone1Post.value").length < 4)
		{
		alert("the number should not be less than 4 digits");
		eval(obj+"Phone1Post.focus()");
		return false;
		}	
		strval=eval(obj+"txtRevenue.value");
		if (strval!='')
		{
			if(isNaN(strval))
			{
				alert("Please enter numeric value for Revenue");
				eval(obj+"txtRevenue"+".focus()");	
				
				return false;
			}		
		}
		strval=eval(obj+"txtSites.value");
		if (strval!='')
		{
			if(isNaN(strval))
			{
				alert("Please enter numeric value for Sites");	
				eval(obj+"txtSites"+".focus()");			
				return false;
			}		
		}					
}

//On Change Date Command
function CMonth(dtDay,seesion,userid)
{	
	intMonth = eval(obj+"SelMonth.value");
	intYear = eval(obj+"SelYear.value");
	if 	(intMonth==2)
		cdate = intMonth+"/01/"+intYear;
	else
		cdate = intMonth+"/"+ dtDay +"/"+intYear;
	strUrl = "calender.asp?cdate="+cdate+"&userid="+userid+"&sessionID="+seesion;
	window.location.href=strUrl;
}
function add_userattachment()
{
		strUrl= "add_userattachment.asp";
		window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");	
}
// Function to add attachments
function add_customerAttachment(type)
{
	if(type=='n')
	{
//		alert(type);
		strUrl="add_attachment.asp?strType="+type+"";
		window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
	}
	if(type=='m')
	{
		strUrl="add_attachment.asp?strType="+type+"";
		window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
	}
}
// Function to add new Department

// Function to view notes
function view_salesnotes(salesid,sl)
{
	strUrl="view_salesadminnotes.asp?id="+salesid+"&sl=" + sl;
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");	
}

// Function to view notes with view,edit options
function view_salesnotes1(salesid)
{
	strUrl="view_salesadminnotes1.asp?id="+salesid+"";
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");	
}
function change_emailcustomer(uid,sess)
{	
	obj1 = "document.form2.";
	pid = eval(obj1+"selCustID.value");	
	url = "../workorder/customeremail.asp?pid="+pid +"&userid=" + uid + "&sessionID=" +sess;
	window.location.href=url;
}

// Function to edit notes
function edit_salesnotes(salesid,sl)
{
	strUrl="edit_salesadminnotes.asp?id="+salesid+"&sl=" + sl;
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");	
}
// Function to edit notes
function add_salesnotes(salesid)
{
	strUrl="add_salesadminnotes.asp?id="+salesid+"";
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");	
}
function add_vendorlogin(id)
{	
	strUrl="add_vendorlogin.asp?id="+id+"";
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");	
}
function vendorapproval(id,sessid,uid)
{	
	strUrl="approvedsubmit.asp?id="+id+"&sessionID="+sessid+"&userid="+uid;
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");	
}
function validate_vendorlogindetails()
{
	arrFlds = "txtEmailAdd:Email-Address,txtPassword:Password,txtCPassword:Confirm PAssword,str_Salutation:Salutation,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;
	}
	if(!(chkEmail("txtEmailAdd")))
	{
		alert("Invalid Email Address ! Should be in somename@hostname.com");
		eval(obj+"txtEmailAdd.focus()");
		return false;
	}

	if (eval(obj+"txtPassword.value") != eval(obj+"txtCPassword.value"))
	{
		alert("Confirm password must be same!");
		eval(obj+"txtCPassword"+".focus()");
		return false;
	}
}

function CallCustomerName(uid,sess)
{	
	cid = eval(obj+"selCustID.value");	
	url = "imagemanager.asp?cid="+cid +"&userid=" + uid + "&sessionID=" +sess;
	window.location.href=url;
}

function CallSiteID(cid,uid,sess)
{	
	sid = eval(obj+"selSiteID.value");	
	url = "imagemanager.asp?cid="+cid + "&sid=" + sid + "&userid=" + uid + "&sessionID=" +sess;
	window.location.href=url;
}

function Imagepage(uid,sess)
{	
	url = "imagemanager.asp?userid=" + uid + "&sessionID=" +sess;
	window.location.href=url;
}

function editCustomerImageName(imgId,uid,sess)
{	
	cid = eval(obj+"selCustID.value");	
	url = "edit_imagemanager.asp?cid="+cid +"&imageID=" +imgId + "&userid=" + uid + "&sessionID=" +sess;
	window.location.href=url;
}

function validate_ImageManager()
{	
	arrFlds = "txtImageTitle:File Title,txtImage:File"	
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
}


function validate_EditImageManager()
{	
	arrFlds = "selCustID:Customer Name,selSiteID:Site,txtImageTitle:Image Title"	
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
		img		=	eval(obj+"txtImage.value");	
		if (img=="") 
			{
				hidimg	=	eval(obj+"hidstrImage.value");	
				if (hidimg=="") 
					{
					alert("Image can not be Blank");
					eval(obj+"txtImage.focus()");
					return false;
					}
			}
}


function open_popupImage(id,siteID,ticketID)
{
	strUrl = "..\\misc\\popup_image.asp?id=" + id + "&siteID=" + siteID+ "&ticketID="+ticketID;	
	window.open(strUrl,"image","width=750,height=400,left=150,top=10,scrollbars=yes");
}

 


function popup_searchimage(id)
{
	strUrl = "..\\misc\\popup_searchimage.asp?id=" + id  ;	
	window.open(strUrl,"image","width=750,height=400,left=150,top=10,scrollbars=yes");
}
function forgot_validate()
{
	arrFlds = "txtUsername:Email ID";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
	if(!(chkEmail("txtUsername")))
	{
		alert("Invalid Email Address ! Should be in somename@hostname.com");
		eval(obj+"txtUsername.focus()");
		return false;
	}
	
}
// Function to add new engineer certificates
function open_viewvendorCertificate(venderid,sessionid,uid)
{
	strUrl = "viewvendorcertificate.asp?venderID=" + venderid + "&sessionID="+ sessionid + "&userid=" + uid;
	window.open(strUrl,"dept","width=750,height=400,left=150,top=10,scrollbars=yes");
}

function workorderreport_validate()
{
	arrFlds = "txtitleNM:Report Title";
	errMsg = validate(arrFlds);
	if (errMsg!="")
	{
		indFields = errMsg.split(":");
		alert(indFields[1] + " cannot be Blank!");
		eval(obj+indFields[0]+".focus()");
		return false;
	}
		
for (i=1;i<6;i++)
	{
	var field = eval(obj + "selCrietria"+[i]+"A.value");
	var checkval = eval(obj + "txtCrietria"+[i]+"C.value");	
		if ((field=="a.ticket_id") || (field=="a.user_id"))
		{
			if (checkval!='')
			{
				if(isNaN(checkval))
				{
				alert("Please Enter Numeric Value !! ")
				eval(obj+"txtCrietria"+[i]+"C.value=''")
				eval(obj+"txtCrietria"+[i]+"C.focus()")
				return false;
				}				
			}							
		}
	}

}


function changeStyle(xobj,xStyle) 
{
	xobj.className = xStyle;
}


// For  Update of Site Notes
function CloseAllnewparrent(chkNM,strPage,ticketid)
{	
 obj = "parent.window.frames.frmNew11.document.form1."	
	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 Close the issue !");
	}
	else
	{
		strIDs = strIDs.substring(0,strIDs.length-1);
		if(confirm("Warning: Are You Sure you want to Update Selected Records."))
		{
			strUrl = strPage + "?IDs=" + strIDs +"&ticketid=" +ticketid;							
			window.open(strUrl,"delwin","width=500,height=200");
		}
	}	
}
// FOR SEARCHING OF COLOR
 function vendorhelp(strNav)
    {
    window.open('../common/vendorhelp.asp?'+strNav+'',"","width=600,height=400,left=100,top=50,resizable=yes,scrollbars=yes,status=yes");
    }  
	
function validateemail()
{
	obj1 = "document.form1.";
	if (eval(obj+"fromemail.value")!="")
	{
		if(!(chkEmail("fromemail")))
		{
		alert("Invalid Email Address ! Should be in somename@hostname.com");
		eval(obj+"fromemail.focus()");
		return false;
		}
	}
}
