//var specchar1 = new Array(" ","`","~","!","#","$","%","^","&","*","(",")","+","=","|","\"","{","}","[","]",":",";","\\","'","<",">","?","/",",");
var leading = /^\s*/g;
var trailing =/\s*$/g;

function emailCheckDuplicate(email)
{

	var str = email;
	if(str=="")
	{
		alert(geti18nString("sdp.reports.report.emailid"));//No I18N
		return false;
	}

	leadingremoved = str.replace(leading,"");
	str = leadingremoved.replace(trailing,"");

	if (str.length > 0)
	{
		var posadr1 = 0;
		var posdot = str.indexOf(".");
		var posadr = str.indexOf("@");
		posadr1=str.lastIndexOf("@");
		if ( (posdot < 0) || (posadr < 0) || (posadr1 != posadr) )
		{
			alert(geti18nString("sdp.reports.report.emailid"));//No I18N
			return false;
		}
	}
	var j = str.length;
	var strobj = new String(str);
	if (strobj.charAt(j-1)=="." || strobj.charAt(0)=="@" || strobj.charAt(j-1)=="@" || strobj.charAt(0)=="." || strobj.charAt(0)=="-" || strobj.charAt(0)=="_" || strobj.charAt(j-1)=="-" || strobj.charAt(j-1)=="_" || strobj.charAt(j-2)=="." || strobj.charAt(j-2)=="-" || strobj.charAt(j-2)=="_")
	{
		alert(geti18nString("sdp.reports.report.emailid"));//No I18N
		return false;
	}
	return true;
}
function emailCheck(email)
{
	var str = email.value;
	if(str=="")
	{
		alert(geti18nString("sdp.emailcheck.invalidmailjserror"));//No I18N
		email.focus();
		return false;
	}

	leadingremoved = str.replace(leading,"");
	str = leadingremoved.replace(trailing,"");

	if (str.length > 0)
	{
		var posadr1 = 0;
		var posdot = str.indexOf(".");
		var posadr = str.indexOf("@");
		posadr1=str.lastIndexOf("@");
		if ( (posdot < 0) || (posadr < 0) || (posadr1 != posadr) )
		{
			alert(geti18nString("sdp.emailcheck.invalidmailjserror"));//No I18N
			email.focus();
			return false;
		}
	}
	var j = str.length;
	var strobj = new String(str);
	if (strobj.charAt(j-1)=="." || strobj.charAt(0)=="@" || strobj.charAt(j-1)=="@" || strobj.charAt(0)=="." || strobj.charAt(0)=="-" || strobj.charAt(0)=="_" || strobj.charAt(j-1)=="-" || strobj.charAt(j-1)=="_" || strobj.charAt(j-2)=="." || strobj.charAt(j-2)=="-" || strobj.charAt(j-2)=="_")
	{
		alert(geti18nString("sdp.emailcheck.invalidmailjserror"));//No I18N
		email.focus();
		return false;
	}
	return true;
}

function validateEMailIDs(varEMail)
{

	var email = trimAll(varEMail.value);
	if(email == "" || email==null)
	{
		alert(geti18nString("sdp.emailcheck.invalidmailjserror"));//No I18N
		varEMail.value = email;
		varEMail.focus();
		return false;
	}
	if(email.indexOf(";") > 0) {
		email = email.replace(/\;/g,",");
	}
	var mailids = email.split(",");
	for(var i = 0; i < mailids.length; i++) {
		var id = mailids[i];
		if(trimAll(id) != "")
		{
		var result = emailCheckDuplicate(trimAll(mailids[i]));
		if(!result) {
			//alert(document.getElementById('enteremail').value);
			varEMail.value = email;
			varEMail.focus();
			return false;
		}
		}
	}
	varEMail.value = email;
	return true;
}

function checkMailId(str)
{
  str = trimAll(str);
  var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]*(\.[a-z]*){0,2})$/i;
  return objRegExp.test(str);
}

function multipleEmailCheck(email,emailid)
{
	var str = emailid;
	if(str=="")
	{
		alert(geti18nString("sdp.emailcheck.invalidmailjserror"));//No I18N
		email.focus();
		return false;
	}

	leadingremoved = str.replace(leading,"");
	str = leadingremoved.replace(trailing,"");
	//var possp = 0;
	/*for(var i=0;i<specchar1.length;i++)
	{
		possp = str.indexOf(specchar1[i]);
		if (possp!=-1)
		{
			alert("Invalid character in e-mail id");
			email.focus();
			return false;
		}
	}*/

	if (str.length > 0)
	{
		var posadr1 = 0;
		var posdot = str.indexOf(".");
		var posadr = str.indexOf("@");
		posadr1=str.lastIndexOf("@");
		if ( (posdot < 0) || (posadr < 0) || (posadr1 != posadr) )
		{
			alert(geti18nString("sdp.emailcheck.invalidmailjserror"));//No I18N
			email.focus();
			return false;
		}
	}
	var j = str.length;
	var strobj = new String(str);
	if (strobj.charAt(j-1)=="." || strobj.charAt(0)=="@" || strobj.charAt(j-1)=="@" || strobj.charAt(0)=="." || strobj.charAt(0)=="-" || strobj.charAt(0)=="_" || strobj.charAt(j-1)=="-" || strobj.charAt(j-1)=="_" || strobj.charAt(j-2)=="." || strobj.charAt(j-2)=="-" || strobj.charAt(j-2)=="_")
	{
		alert(geti18nString("sdp.emailcheck.invalidmailjserror"));//No I18N
		email.focus();
		return false;
	}
	return true;
}

function validateFullName(fullName)
{
	if(trimAll(fullName.value) == "")
	{
		alert(document.getElementById("entername").value);
		fullName.focus();
		return false;
	}
	fullName.value=trimAll(fullName.value);
	return true;
}

function validateUserName(userName)
{
	if(isEmpty(userName.value))
	{
		alert(document.getElementById("enterloginname").value);
		userName.focus();
		return false;
	}
	userName.value=trimAll(userName.value);
	return true;
}

function validatePwd(userPwd,confirmUserPwd)
{
	if(userPwd.value == "")
	{
		alert(document.getElementById('enterpassword').value);
		userPwd.focus();
		return false;
	}
	if((userPwd.value != "") && (userPwd.value != confirmUserPwd.value))
	{
		alert(document.getElementById("incorrectretypepwd").value);
		confirmUserPwd.focus();
		return false;
	}
	return true;
}

function disableLoginForTech(thisForm)
{
	disableLogin = true;
	if(thisForm.provideLogin!=null)
	{
		if(thisForm.provideLogin.checked)
		{
			disableLogin= false;
			thisForm.userName.disabled = disableLogin;
			thisForm.userPwd.disabled = disableLogin;
			thisForm.confirmUserPwd.disabled = disableLogin;
		}
		else
		{
			disableLogin= true;
			thisForm.userName.disabled = disableLogin;
			thisForm.userPwd.disabled = disableLogin;
			thisForm.confirmUserPwd.disabled = disableLogin;

		}
	}
	return disableLogin;
}

function disableGlobalLoginForTech(thisForm)
{
	disableLogin = true;
	if(thisForm.provideLogin!=null)
	{
		if(thisForm.provideLogin.checked)
		{
			disableLogin= false;
		}
		else
		{
			disableLogin= true;
		}
		thisForm.userName.disabled = disableLogin;
		thisForm.userPwd.disabled = disableLogin;
		thisForm.confirmUserPwd.disabled = disableLogin;
		thisForm.accessLevel[0].disabled = disableLogin;
		thisForm.accessLevel[1].disabled = disableLogin;
	}
	return disableLogin;
} 

function validateUserForm(userForm)
{
	var userID = userForm.userID.value;
//	var phoneNo = userForm.phone.value;
//	var mobileNo = userForm.mobile.value;
	
	if(!validateFullName(userForm.fullName))
	{
		return false;	
	}
	/*if(phoneNo != '' && !checkPhone(phoneNo))
	{
		alert(geti18nString("scp.accounts.validphonenoalert"));//No I18N
		userForm.phone.focus();
		return false;
	}*/
	/*if(mobileNo != '' && !checkPhone(mobileNo))
	{
		alert(geti18nString("scp.contacts.validmobilenoalert"));//No I18N
		userForm.mobile.focus();
		return false;
	}*/
	if(!isEmpty(userForm.email.value))
	{
		if(!emailCheck(userForm.email))
		{
			return false;	
		}
		userForm.email.value = trimAll(userForm.email.value);
	}

	if(!checkForUDFNumeric())
	{
		alert(document.getElementById("invalidcustomfields").value);
		return false;
	}

	// Check if both username and userpwd are not null
 	// Then login has not been provided for requester
	// Else if username is not null and userpwd is null
	// Then login has been provided for requester
	if(isPortalEnabled == "true")//No I18N
	{
	if(userForm.userPwd != null)
	{	
		if(!isEmpty(userForm.userPwd.value) || !isEmpty(userForm.confirmUserPwd.value))
		{
			if(!validateUserName(userForm.userName))
			{
				return false;	
			}
		}
		if(!isEmpty(userForm.userName.value))
		{
				if(!validatePwd(userForm.userPwd,userForm.confirmUserPwd))
				{
					return false;	
				}
		}
	}
	else
	{
		// Then login has not been provided for requester
		if(!validateUserName(userForm.userName))
		{
			return false;	
		}
	}
	}
	if(!isEmpty(userForm.email.value))
	{
		if(userID != null)
		{
			url = "/servlet/ClientUtilServlet?action=checkForEmail&contactEmail="+userForm.email.value+"&contactID="+userID;
		}
		else
		{
			url = "/servlet/ClientUtilServlet?action=checkForEmail&contactEmail="+userForm.email.value;
		}
		var checkemailresult = AjaxValidate(url);
		if(checkemailresult == "true")
		{
			alert(document.getElementById('contactexists').value);
			return false;
		}
	}
	if(!isEmpty(userForm.secondEmail.value))
	{
		if(userID != null)
		{
			url = "/servlet/ClientUtilServlet?action=checkForEmail&contactEmail="+userForm.secondEmail.value+"&contactID="+userID;
		}
		else
		{
			url = "/servlet/ClientUtilServlet?action=checkForEmail&contactEmail="+userForm.secondEmail.value;
		}
		var checkemailresult = AjaxValidate(url);
		if(checkemailresult == "true")
		{
			alert(document.getElementById('contactexists').value);
			return false;
		}
	}
	if(isPortalEnabled == "true")//No I18N
	{
	if(!isEmpty(userForm.userName.value))
	{
		if(userID != null)
		{
			url = "/servlet/ClientUtilServlet?action=checkForLoginName&loginNameCheck="+userForm.userName.value+"&contactID="+userID;
		}
		else
		{
			url = "/servlet/ClientUtilServlet?action=checkForLoginName&loginNameCheck="+userForm.userName.value;
		}
		var checkloginnameresult = AjaxValidate(url);		
		if(checkloginnameresult == "true")
		{
			alert(document.getElementById('loginexists').value);
			return false;
		}
	}
	}
	if(!isEmpty(userForm.customerID.value) && userForm.customerID.value != "0")
	{
		if(userID != null)
		{
			var url = "RequesterDef.do?action=checkAccDepartment&accID="+userForm.customerID.value;
			var accDepResult = AjaxValidate(url);
			if(accDepResult != null && accDepResult == "anotherDepartment")
			{
				if(confirm(document.getElementById('accountcheck').value))
				{
					return true;
				}
				else
				{
					return false;
				}	
			}

		}
	}
	return true;
}

function AjaxValidate(url)
{		
	if (window.XMLHttpRequest)
	{ // Non-IE browsers
		AJAX = new XMLHttpRequest();
	}
	else 
	{                                  
    		AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	if (AJAX)
	{
		AJAX.open("GET", url, false);                             
    		AJAX.send(null);
     		return AJAX.responseText;                                         
  	} 
	else 
	{
     		return "false";
  	}
}


function validateGlobalTechnicianForm(techForm,from)
{
	var technicianID= document.getElementById("technicianID").value;
	if(!validateFullName(techForm.fullName))
	{
		return false;	
	}
	if(!isEmpty(techForm.email.value))
	{
		if(!emailCheck(techForm.email))
		{
			return false;	
		}
		else 
		{
			var techEmail = trimAll(techForm.email.value);
			if(from == 'edit')
			{
				url = "/servlet/ClientUtilServlet?action=checkForEmail&contactEmail="+techEmail+"&contactID="+technicianID;//No I18N
			}
			else
			{
				url = "/servlet/ClientUtilServlet?action=checkForEmail&contactEmail="+techEmail;//No I18N
			}
			var checkemailresult = AjaxValidate(url);
			if(checkemailresult == "true")
			{
				alert(document.getElementById('existingemail').value);
				return false;
			}
		}
	}
	else
	{
		techForm.email.value = trimAll(techForm.email.value);
	}
	if(!checkForUDFNumeric())
	{
		alert(document.getElementById("invalidcustomfields").value);
		return false;
	}
	if(!isDouble(techForm.cost.value))
    {
            alert(document.getElementById("invalidcost").value);
            return false;
    }
	if(techForm.provideLogin.checked)
	{
		var usernameclass = document.getElementById("userName").className
		if(usernameclass == "showtemp")
		{
		if(!validateUserName(techForm.userName))
		{
			return false;	
		}
		if(from == 'edit')
		{
			url = "/servlet/ClientUtilServlet?action=checkForLoginName&loginNameCheck="+techForm.userName.value+"&contactID="+technicianID;//No I18N
		}
		else
		{
			url = "/servlet/ClientUtilServlet?action=checkForLoginName&loginNameCheck="+techForm.userName.value;//No I18N
		}
		var checkloginNameresult = AjaxValidate(url);
		if(checkloginNameresult == "true")
		{
			alert(document.getElementById('existingloginName').value);
			return false;
		}
		if(!validatePwd(techForm.userPwd,techForm.confirmUserPwd))
		{
			return false;	
		}
		}
		if(techForm.accessLevel[0].checked == false && techForm.accessLevel[1].checked == false)
		{
			alert(document.getElementById('provideaccesslevel').value);
			return false;
		}
		if(techForm.accessLevel[1].checked == true)
		{
			var deptlength = techForm.allAssignedBU.options.length;
			if(deptlength < 1)
			{
				alert(document.getElementById('selectbu').value);
				return false;
			}
			if(deptlength == 1)
			{
				if(techForm.roleType[0].checked == false || techForm.roleType[1].checked == true)
				{
					techForm.roleType[0].checked = true;
				}
				var globalrole = techForm.assignedGlobalRole.value;
				if(globalrole == null || globalrole == 0)
				{
					alert(document.getElementById('providerole').value);
					return false;
				}
			}
			if(deptlength > 1)
			{
				if(techForm.roleType[0].checked == false && techForm.roleType[1].checked == false)
				{
					alert(document.getElementById('provideroletype').value);
					return false;
				}
				if(techForm.roleType[0].checked == true)
				{
					var globalrole = techForm.assignedGlobalRole.value;
					if(globalrole == null || globalrole == "" || globalrole == 0)
					{
						alert(document.getElementById('providerole').value);
						return false;
					}
				}
				if(techForm.roleType[1].checked == true)
				{
					var listval = techForm.allAssignedBU;
					var assignedBURoles = null;
					for (i=0;i<listval.length;i++)
					{
						var deptID = listval.options[i].value;
						var divID = "roles_"+deptID;//No I18N
						var roleID = eval("document.getElementById('"+divID+"').value;");
						var str = deptID + "=" + roleID;
						if(roleID != null && roleID != "" && roleID != "0")
						{
							if(assignedBURoles != null)
							{
								assignedBURoles = assignedBURoles + "&&" + str;
							}
							else
							{
								assignedBURoles =  str;
							}
						}
						else
						{
							alert(document.getElementById('provideroleallbu').value);
							return false;
						}
					}
					techForm.buRoles.value = assignedBURoles;
				}
			}
			for (i=0;i<deptlength;i++)
			{
				techForm.allAssignedBU.options[i].selected = true;
			}
		}
	}
	return true;
}
function isDouble(str)
{
        var objRegExp = /^\d\d*(.\d\d*)?$/;
        return objRegExp.test(str);
}
/*function validateEditTechnicianForm(techForm)
{
	if(!validateFullName(techForm.fullName))
	{
		return false;	
	}
	if(!isEmpty(techForm.email.value))
	{
		if(!emailCheck(techForm.email))
		{
			return false;	
		}
	}
	else
	{
		techForm.email.value = trimAll(techForm.email.value);
	}*/
	/*if(!validateOrgName(techForm.organizationName))
	  {
	  return false;	
	  }
	  if(!validateDeptName(techForm.deptName))
	  {
	  return false;	
	  }
	  techForm.organizationName.disabled=false;*/
/*	techForm.submit();
	return true;
}*/

function validateEditUserForm(userForm)
{
	if(!validateFullName(userForm.fullName))
	{
		return false;	
	}
	if(!isEmpty(userForm.email.value))
	{
		if(!emailCheck(userForm.email))
		{
			return false;	
		}
	}
	else
	{
		userForm.email.value = trimAll(userForm.email.value);
	}		
	if(userForm.userName != null)
	{
		if(userForm.userName.value == "")	
		{
			userForm.userName.value = userForm.email.value;
		}
		if(!validateUserName(userForm.userName))
		{
			return false;	
		}
		if(!validatePwd(userForm.userPwd,userForm.confirmUserPwd))
		{
			return false;	
		}
	}

	if(!checkForUDFNumeric())
	{
		alert(document.getElementById('invalidcustomfields').value);
		return false;
	}

	/*if(!validateOrgName(userForm.organizationName))
	  {
	  return false;	
	  }
	  if(!validateDeptName(userForm.deptName))
	  {
	  return false;	
	  }
	  userForm.organizationName.disabled=false;*/
	userForm.submit();
	return true;
}

function selectCompWithName(compName, theForm)
{
	for(var i=0; i<theForm.elements.length; i++)
	{
		if(theForm.elements[i].name == compName)
		{
			theForm.elements[i].checked = true;
		}
	}
}

function deselectCompWithName(compName, theForm)
{
	for(var i=0; i<theForm.elements.length; i++)
	{
		if(theForm.elements[i].name == compName)
		{
			theForm.elements[i].checked = false;
		}
	}
}

function selectViewPermission(compName,compToBeSelected, fullControlComp,theForm)
{
	if(compName.checked)
	{
		for(var i=0; i<theForm.elements.length; i++)
		{
			if(theForm.elements[i].type == "checkbox")
			{
				if(theForm.elements[i].value == compToBeSelected)
				{
					theForm.elements[i].checked = true;
				}
			}
		}
	}
	if(!compName.checked)
	{
		fullControlComp.checked=false;
	}
}

function deselectViewPermission(compName,compToBeDeselected, fullControlComp, theForm)
{
	if(!compName.checked)
	{
		for(var i=0; i<theForm.elements.length; i++)
		{
			if(theForm.elements[i].type == "checkbox")
			{
				if(theForm.elements[i].name == compToBeDeselected)
				{
					theForm.elements[i].checked = false;
				}
			}
		}
		fullControlComp.checked=false;
	}
}

function deselectEditPermission(compName,compToBeDeselected,theForm)
{
	if(!compName.checked)
	{
		for(var i=0; i<theForm.elements.length; i++)
		{
			if(theForm.elements[i].type == "checkbox")
			{
				if(theForm.elements[i].value == compToBeDeselected)
				{
					theForm.elements[i].checked = false;
				}
			}
		}
	}
}

function selectAllPermission(component, checkboxComp,thisForm)
{
	if((component.name == "woFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "woFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "prFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "prFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "chFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "chFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "wsFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "wsFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "purchaseFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "purchaseFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "servicecontractsFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "servicecontractsFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "solutionFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "solutionFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "reportsFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "reportsFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "accountsFullControl" ) && (component.checked))
	{
		selectCompWithName(checkboxComp,thisForm);
	}
	else if((component.name == "accountsFullControl" ) && (!component.checked))
	{
		deselectCompWithName(checkboxComp,thisForm);
	}
	/*else if((component.name == "orgFullControl" ) && (component.checked))
	  {
	  selectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "orgFullControl" ) && (!component.checked))
	  {
	  deselectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "userFullControl" ) && (component.checked))
	  {
	  selectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "userFullControl" ) && (!component.checked))
	  {
	  deselectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "priorityFullControl" ) && (component.checked))
	  {
	  selectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "priorityFullControl" ) && (!component.checked))
	  {
	  deselectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "levelFullControl" ) && (component.checked))
	  {
	  selectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "levelFullControl" ) && (!component.checked))
	  {
	  deselectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "modeFullControl" ) && (component.checked))
	  {
	  selectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "modeFullControl" ) && (!component.checked))
	  {
	  deselectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "categoryFullControl" ) && (component.checked))
	  {
	  selectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "categoryFullControl" ) && (!component.checked))
	  {
	  deselectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "techFullControl" ) && (component.checked))
	  {
	  selectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "techFullControl" ) && (!component.checked))
	  {
	  deselectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "slaFullControl" ) && (component.checked))
	  {
	  selectCompWithName(checkboxComp,thisForm);
	  }
	  else if((component.name == "slaFullControl" ) && (!component.checked))
	  {
	  deselectCompWithName(checkboxComp,thisForm);
	  }*/
}

function checkFullControl(theForm,val)
{
	var countWo =0;
	var countWs =0;
	var countPurchase =0;
	var countContract =0;
	   var countServiceContract =0;
	var countSolution =0;
	var countReports = 0;
	var countProblems = 0;
	var countChanges = 0;
	var countAccounts =0;
	for(var i=0; i<theForm.elements.length; i++)
	{
		if(theForm.elements[i].name == "woControl")
		{
			if(theForm.elements[i].checked)
			{
				countWo++;
			}
		}
		if(theForm.elements[i].name == "prControl")
		{
			if(theForm.elements[i].checked)
			{
				countProblems++;
			}
		}
		if(theForm.elements[i].name == "chControl")
		{
			if(theForm.elements[i].checked)
			{
				countChanges++;
			}
		}
		if(theForm.elements[i].name == "wsControl")
		{
			if(theForm.elements[i].checked)
			{
				countWs++;
			}
		}
		if(theForm.elements[i].name == "purchaseControl")
		{
			if(theForm.elements[i].checked)
			{
				countPurchase++;
			}
		}
		if(theForm.elements[i].name == "contractControl")
		{
			if(theForm.elements[i].checked)
			{
				countContract++;
			}
		}
		if(theForm.elements[i].name == "servicecontractsControl")
		{
			if(theForm.elements[i].checked)
			{
				countServiceContract++;
			}
		}
		if(theForm.elements[i].name == "solutionControl")
		{
			if(theForm.elements[i].checked)
			{
				countSolution++;
			}
		}
		if(theForm.elements[i].name == "reportsControl")
		{
			if(theForm.elements[i].checked)
			{
				countReports++;
			}
		}
		if(theForm.elements[i].name == "accountsControl")
		{
			if(theForm.elements[i].checked)
			{
				countAccounts++;
			}
		}
	}
	if(countWo == '5')
	{
		theForm.woFullControl.checked=true;
	}
	if(countWs == '4')
	{
		theForm.wsFullControl.checked=true;
	}
	if(countPurchase == '4')
	{
		theForm.purchaseFullControl.checked=true;
	}
	if(countContract == '4')
	{
		theForm.contractFullControl.checked=true;
	}
	if(countServiceContract == '4')
	{
		theForm.servicecontractsFullControl.checked=true;
	}


	if(countSolution == '5')
	{
		theForm.solutionFullControl.checked=true;
	}
	if(countReports == '4')
	{
		theForm.reportsFullControl.checked=true;
	}
	if(countProblems == '4')
	{
		theForm.prFullControl.checked=true;
	}
	if(countChanges == '4')
	{
		theForm.chFullControl.checked=true;
	}
	if(countAccounts == '4')
	{
		theForm.accountsFullControl.checked=true;
	}

	if(val!=null && val=='All')
	{
		theForm.showAssignedRequests[0].checked=true;
	}
	else if(val!=null && val=='Queue')
	{
		theForm.showAssignedRequests[1].checked=true;
	}
	else if(val!=null && val=='Owned')
	{
		theForm.showAssignedRequests[2].checked=true;
	}
}

function copyToList(theForm,from,to,forCutOnly)
{
	if(forCutOnly == 'forCutOnly')
	{
		forCutOnly = true;
	}
	var sel = false;
	var fromList = eval(theForm +'.'+ from);
	
	var toList = eval(theForm +'.'+ to);
	if(forCutOnly)
	{
		if (toList.options.length > 0 && toList.options[0].value == '0')
		{
			toList.options.length = 0;
		}
	}
	for (var i=0;i<fromList.options.length;i++)
	{
		var current = fromList.options[i];
		if (current.selected)
		{
			sel = true;
			if (current.value == '0')
			{
				alert (document.getElementById('invalidselection').value);
				return;
			}
			var txt = current.text;
			var val = current.value;
			var len = toList.length;
			var present = false;
			for (var role=0;role<len;role++)
			{
				if(current.value == toList.options[role].value)
				{
					present = true;
					break;
				}
				else
				{
					continue;
				}
			}
			if(!present)
			{
				toList.options[toList.length] = new Option(txt,val);
			}
			if(forCutOnly)
			{
				fromList.options[i] = null;
				i--;
			}
		}
	}
	if(forCutOnly)
	{
		if (!sel) {alert (document.getElementById('noselection').value)};
	}

}

function validateVendorForm(theForm)
{
	if(trimAll(theForm.organizationName.value) == "")
	{
		alert(document.getElementById('entervendorname').value);
		theForm.organizationName.focus();
		return false;
	}
	/*if(theForm.organizationEmail.value == "")
	  {
	  alert("Please provide Vendor E-Mail  and proceed.");
	  theForm.organizationEmail.focus();
	  return false;
	  }*/
	if(theForm.organizationEmail.value != "")
	{
		if(!emailCheck(theForm.organizationEmail))
		{
			theForm.organizationEmail.focus();
			return false;
		}
	}
	theForm.organizationName.value = trimAll(theForm.organizationName.value);
	return true;
}

function ShowEMailTab(divIdToShow)
{
	var idToShow = document.getElementById(divIdToShow);
	idToShow.style.display = 'block';
	if(divIdToShow=="incoming")
	{
		document.EMailDefForm.incomingHost.focus();
		var idToHide1 = document.getElementById("filter");
		idToHide1.style.display = 'none';
		var idToHide2 = document.getElementById("outgoing");
		idToHide2.style.display = 'none';
		document.EMailDefForm.mailConfig.value = 'incoming';
	}
	else if(divIdToShow=="outgoing")
	{
		document.EMailDefForm.outgoingHost.focus();
		var idToHide1 = document.getElementById("incoming");
		idToHide1.style.display = 'none';
		var idToHide2 = document.getElementById("filter");
		idToHide2.style.display = 'none';
		document.EMailDefForm.mailConfig.value = 'outgoing';
	}
	else if(divIdToShow=="filter")
	{
		//document.FilterDefForm.selectCriteria.focus();
		var idToHide1 = document.getElementById("incoming");
		idToHide1.style.display = 'none';
		var idToHide2 = document.getElementById("outgoing");
		idToHide2.style.display = 'none';
	}
}


function valIncomingEmail(theForm)
{
	document.EMailDefForm.autoReplyFrequency.value = document.EMailDefForm.autoReply.value;
	document.EMailDefForm.mailFetchingFrequency.value = document.EMailDefForm.mailFetching.value;

	var arf = document.EMailDefForm.autoReplyFrequency.value;
	var ari = document.EMailDefForm.autoReplyInterval.value;
	var mff = document.EMailDefForm.mailFetchingFrequency.value;
	var mfi = document.EMailDefForm.mailFetchingInterval.value;
	
	if(!isNumeric(arf) || !isNumeric(ari) || !isNumeric(mff) || !isNumeric(mfi))
	{
		alert("Please enter numeric values for Mail Fetching Settings");//No I18N
		return false;
	}

	var idToHide = document.getElementById("outgoing");

	if (idToHide.style.display != 'block')
	{
		if(trimAll(theForm.incomingHost.value) == "")
		{
			alert(document.getElementById("enterincomingserver").value);
			ShowEMailTab("incoming");
			theForm.incomingHost.focus();
			return false;
		}
		theForm.incomingHost.value = trimAll(theForm.incomingHost.value);
		if(trimAll(theForm.userName.value) == "")
		{
			alert(document.getElementById("enterusername").value);
			ShowEMailTab("incoming");
			theForm.userName.focus();
			return false;
		}
		theForm.userName.value = trimAll(theForm.userName.value);
		if(theForm.userPwd.value == "")
		{
			alert(document.getElementById("enterpwd").value);
			ShowEMailTab("incoming");
			theForm.userPwd.focus();
			return false;
		}
		if(theForm.incomingPort.value == "")
		{
			alert(document.getElementById("enterincomingport").value);
			ShowEMailTab("incoming");
			theForm.incomingPort.focus();
			return false;
		}
		if(!checknumber(theForm.incomingPort))
		{
			ShowEMailTab("incoming");
			theForm.incomingPort.focus();
			return false;
		}	
		if(theForm.fetchInterval.value == "")
		{
			alert(document.getElementById("entermailfetch").value);

			ShowEMailTab("incoming");
			theForm.fetchInterval.focus();
			return false;
		}
		if(!checkForIntegerZero(theForm.fetchInterval))
		{
			alert(document.getElementById("invalidinterval").value);
			ShowEMailTab("incoming");
			theForm.fetchInterval.focus();
			return false;
		}	
		theForm.mailConfig.value="incoming";
		return true;
	}
	else
	{
		return valOutgoingEmail(theForm);
	}
}

function valOutgoingEmail(theForm)
{
	if(trimAll(theForm.outgoingHost.value) == "")
	{
		alert(document.getElementById("enteroutgoingserver").value);
		ShowEMailTab("outgoing");
		theForm.outgoingHost.focus();
		return false;
	}
	theForm.outgoingHost.value = trimAll(theForm.outgoingHost.value);
	

	if(theForm.outgoingPort.value == "")
	{
		alert(document.getElementById("enteroutgoingport").value);
		ShowEMailTab("outgoing");
		theForm.outgoingPort.focus();
		return false;
	}
	if(!checknumber(theForm.outgoingPort))
	{
		ShowEMailTab("outgoing");
		theForm.outgoingPort.focus();
		return false;
	}
	
	if(theForm.requireAuthentication.checked)
	{
		theForm.smtpUserName.value = trimAll(theForm.smtpUserName.value);
		if(trimAll(theForm.smtpUserName.value) == "")
		{
			alert(document.getElementById("enterusername").value);
			ShowEMailTab("outgoing");
			theForm.smtpUserName.focus();
			return false;
		}
		theForm.smtpPassword.value = trimAll(theForm.smtpPassword.value);
		if(trimAll(theForm.smtpPassword.value) == "")
		{
			alert(document.getElementById("enterpwd").value);
			ShowEMailTab("outgoing");
			theForm.smtpPassword.focus();
			return false;
		}
	}
	
	theForm.mailConfig.value="outgoing";
	return true;
}


function changePassword(theForm)
{
	if(theForm.oldPwd.value == "")
	{
		alert(document.getElementById("entercurrentpassword").value);
		theForm.oldPwd.focus();
		return false;
	}
	if(theForm.newPwd.value == "")
	{
		alert(document.getElementById("enternewpassword").value);
		theForm.newPwd.focus();
		return false;
	}
	/*if(theForm.newPwd.value.length < 5)
	{
		alert("The new password must contain atleast 5 characters.");
		theForm.newPwd.focus();
		return false;
	}*/
	if(!validatePwd(theForm.newPwd,theForm.confirmNewPwd))
	{
		return false;
	}
	return true;
}

function validateAssociateWS(assignedWS)
{
	List = assignedWS;
	if(List.length && List.options[0].value == '0')
	{
		alert(document.getElementById("chooseworkstation").value);
		return false;
	}
	for (i=0;i<List.length;i++)
	{
		List.options[i].selected = true;
	}
	document.forms[0].submit();
	return true;
}

function copyWSToList(from,to)
{
	fromList = eval('document.forms[0].' + from);
	toList = eval('document.forms[0].' + to);
	if (toList.options.length > 0 && toList.options[0].value == '0')
	{
		toList.options.length = 0;
	}
	var sel = false;
	for (i=0;i<fromList.options.length;i++)
	{
		var current = fromList.options[i];
		if (current.selected)
		{
			sel = true;
			if (current.value == '0')
			{
				alert (document.getElementById('invalidselection').value);
				return;
			}
			txt = current.text;
			val = current.value;
			len = toList.length;
			var present = false;
			for (role=0;role<len;role++)
			{
				if(current.value == toList.options[role].value)
				{
					present = true;
					break;
				}
				else
				{
					continue;
				}
			}
			if(!present)
			{
				toList.options[toList.length] = new Option(txt,val);
			}
			fromList.options[i] = null;
			i--;
		}
	}
	if (!sel) alert (document.getElementById('noselection').value);
}

function trimAll(str)
{
	/*************************************************************
	  Input Parameter :str
Purpose         : remove all white spaces in front and back of string
Return          : str without white spaces    
	 ***************************************************************/

	//check for all spaces
	var objRegExp =/^(\s*)$/;
	if (objRegExp.test(str))
	{
		str = str.replace(objRegExp,''); 
		if (str.length == 0)
			return str; 
	} 

	//  check for leading and trailling spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(str))
	{
		str = str.replace(objRegExp, '$2');
	}
	return str;
}

function callRequesterDefFormFunction()
{
	var divToShow = $('divToShowId').value;    //document.RequesterDefForm.divToShow.value;
    //console.debug("divToShow ", $('divToShowId'));
    //console.debug("divToShow.value ", $('divToShowId').value);
	if(divToShow!=null && divToShow!="" )
    {
        if(divToShow=="detView")
        {
            swapLayer('sform','listview');
        }
        else
        {
            swapLayer('listview','sform');
        }
    }
    //loadmeadmin();
}

function swapLayerAndSetFocusReqDefForm()
{
	onClickSwapLayer('sform','listview');
	document.RequesterDefForm.fullName.focus();
}

function setIsDeptManager(selection)
{
    var selectBox = document.getElementById(selection);
    var selectValue = selectBox.value;
    //alert(selectValue);
    var cbox = document.getElementById("deptManager");
    var tdata = document.getElementById("deptManText");
    if(selectValue == "0" || selectValue == 'None')
    {
        cbox.disabled = true;
        tdata.className="fontgray";
    }
    else
    {
        cbox.disabled = false;
        tdata.className="fontBlackBold";
    }
}

function submitRequesterListjspfForm(form, additionalParams)
{
	form.action = form.action + additionalParams;
	handleStateForForm(form);
	form.submit();
	return true;
}
////////for supportcenter
function validateCustomerName(name)
{
	if(trimAll(name.value) == "")
	{
		alert(document.getElementById("entername").value);
		name.focus();
		return false;
	}
	name.value=trimAll(name.value);
	return true;
}
function validateCustomerForm(customerForm)
{
	//var phoneNo = customerForm.customerPhone.value;
	//var faxNo =  customerForm.customerFax.value;
	if(!validateCustomerName(customerForm.customerName))
	{
		return false;
	}
	if(!isEmpty(customerForm.customerAnnualRevenue.value))
	{
		if(!isDouble(customerForm.customerAnnualRevenue.value))
		{
			alert(document.getElementById("invalidannualrevenue").value);
			return false;
		}
	}
	if(!isEmpty(customerForm.customerEmail.value))
	{
		if(!emailCheck(customerForm.customerEmail))
		{
			return false;
		}
	}
	/*if(phoneNo != '' && !checkPhone(phoneNo))
	{
		alert(geti18nString("scp.accounts.validphonenoalert"));//No I18N
		customerForm.customerPhone.focus();
		return false;
	} */
	/*if(faxNo != '' && !checkFax(faxNo))
	{
		alert(geti18nString("scp.accounts.validfaxnoalert"));//No I18N
		customerForm.customerFax.focus();
		return false;
	} */
	else
	{
		customerForm.customerEmail.value = trimAll(customerForm.customerEmail.value);
	}
	if(!checkForUDFNumeric())
	{
		alert(document.getElementById("invalidcustomfields").value);
		return false;
	}
	if(!isEmpty(customerForm.domainName.value))
	{
		if(!domainNameCheck(customerForm.domainName))
		{
			return false;
		}
	}
	else
	{
		customerForm.domainName.value = trimAll(customerForm.domainName.value);
	}
	//check for same name
	var accID = customerForm.id.value;
	var masterAccId = customerForm.masterAccountID.value;
	//alert(accID); alert("masterAccId" + masterAccId);
	if(!isEmpty(customerForm.customerName.value))
	{
		
		var name = customerForm.customerName.value;
		name = encodeURIComponent(name);
		if(accID != null && accID != "" && (masterAccId == null || masterAccId == ""))
		{
			
			var url = "/CustomerDef.do?checkForAccountName="+name+"&accoutID="+accID;
		}
		else
		{
			var url = "/CustomerDef.do?checkForAccountName="+name;
		}
		//alert(url);	
		var checkAccountNameResult = AjaxValidate(url);
		//alert(checkAccountNameResult);
		if(checkAccountNameResult == "true")
		{

			alert(document.getElementById("samenamealert").value);
			return false;
		}
	}
	if(!isEmpty(customerForm.domainName.value))
	{
		var domain = customerForm.domainName.value;
		domain = encodeURIComponent(domain);
		if(accID != null && accID != "" )
		{
			
			var url = "/CustomerDef.do?checkForDomainName="+domain+"&accoutID="+accID; //No I18N
		}
		else
		{
			var url = "/CustomerDef.do?checkForDomainName="+domain;//No I18N
		}
		var checkDomainNameResult = AjaxValidate(url);
		if(checkDomainNameResult == "true")
		{

			alert(geti18nString("scp.accounts.samedomain.name.errmsg"));//No I18N
			return false;
		}

	}
}
function validateEditCustomerForm(customerForm)
{
	if(!validateCustomerName(customerForm.customerName))
	{
		return false;
	}
	if(!isEmpty(customerForm.customerEmail.value))
	{
		if(!emailCheck(customerForm.customerEmail))
		{
			return false;
		}
	}
	else
	{
		customerForm.customerEmail.value = trimAll(customerForm.customerEmail.value);
	}
	if(!checkForUDFNumeric())
	{
		alert(document.getElementById('invalidcustomfields').value);
		return false;
	}
	customerForm.submit();
	return true;
}
function validateRes()
{
	var descVal = resEditor.getContent();//No I18N
	document.getElementById('HTMLDesc').value = descVal;

	if(document.addResolutionForm.timeSpent.checked)
	{
		var result= validatingTimeEntry();
		return result;
	}
	return true;
}
function domainNameCheck(domainName)
{
	var name = domainName.value;
	name = trimAll(name);
	name = name.replace(" ","");
	if(name != null && name != "")
	{
		var arr = new Array();
		var arr = name.split(",");
		for(var i=0; i<arr.length; i++)
		{
			var str = arr[i];
			str = trimAll(str);
			var dot = str.indexOf(".");
			var dname = str.substring(0,dot);
			var extension = str.substring(dot+1,str.length)
			if(dname == null || dname == "" || dot < 0 || extension == null || extension == "")
			{
				alert(geti18nString("scp.admin.settings.domainname.jserrormsg"));//No I18N
				return false;
			}
			//domain name before the '.' shoud has a max length of 63.
			if(dot>1 && dot<64)
			{
				for(var j=0; j<dname.length; j++)
				{
					var dchar = dname.charAt(j);
					var charCode = dchar.charCodeAt(0);
					//domain names should have only alpha numeric values and '-', should not begin/end with '-',
					if((charCode > 47 && charCode<58) || (charCode > 64 && charCode<91) || (charCode > 96 && charCode<123) || charCode==45)
					{
						if((j==0 || j==dname.length-1) && charCode == 45)	
						{
							alert(geti18nString("scp.admin.settings.domainname.specialcharmsg1"));//No I18N
							return false;
						}
					}
					else	
					{
						alert(geti18nString("scp.admin.settings.domainname.specialcharmsg2"));//No I18N
						return false;
					}
				}
			}
			else
			{
				alert(geti18nString("scp.admin.settings.domainname.lengthmsg"));//No I18N
				return false;
			}

		}
	}
	domainName.value = name; 
	return true;
}

/*function checkPhone(phoneNo) 
{	
	var phone = /^[\*\-\#\(\)\{\}\[\]\+\ 0-9]*$/;	
	if (phoneNo.match(phone)) {
   		return true;
 	} else {
 		return false;
 	}
} */

/*function checkFax(faxNo) 
{    
        var fax =/^[^a-zA-Z\s]*$/;
	if (faxNo.match(fax)) {
   		return true;
 	} else {
 		return false;
 	}
} */



