//Printer Module

function printer_Validator(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }

	
//First Name
	theForm.firstName.value = LTrim(theForm.firstName.value);
	theForm.firstName.value = RTrim(theForm.firstName.value);
	if (!emptystring(theForm.firstName.value))
		 {
			alert("Please enter your First Name");
			theForm.firstName.focus();
			flag=false;
			return (false);
		}else {
           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .";
			if (!(validate(theForm.firstName.value,checkOk)))
				{
				alert("Please enter your valid First Name");
				theForm.firstName.value= "";
				theForm.firstName.focus();
				flag=false;
				return (false);
				}
		}
		
//Last Name
	theForm.lastName.value = LTrim(theForm.lastName.value);
	theForm.lastName.value = RTrim(theForm.lastName.value);
	if (!emptystring(theForm.lastName.value))
		 {
			alert("Please enter your Last Name");
			theForm.lastName.focus();
			flag=false;
			return (false);
		}else {
           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .";
			if (!(validate(theForm.lastName.value,checkOk)))
				{
				alert("Please enter your valid Last Name");
				theForm.lastName.value= "";
				theForm.lastName.focus();
				flag=false;
				return (false);
				}
		}

	
//E-Mail
	theForm.eMail.value = LTrim(theForm.eMail.value);
	theForm.eMail.value = RTrim(theForm.eMail.value);
	if (!emptystring(theForm.eMail.value))
		 {
			alert("Please enter E-Mail");
			theForm.eMail.focus();
			flag=false;
			return (false);
		}else {
	var flag  = true
	var Temp     = theForm.eMail
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

	if(theForm.eMail.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1))                    // No empty spaces permitted
			   {  
		      flag = false
		      alert("Please enter a valid E-Mail address!");
			      Temp.value="";
			      Temp.focus();
		      return flag;
   			}
		}
		}

//Password
	theForm.password.value = LTrim(theForm.password.value);
	theForm.password.value = RTrim(theForm.password.value);
	if (!emptystring(theForm.password.value))
		 {
			alert("Please enter Password");
			theForm.password.focus();
			flag=false;
			return (false);
		} else {
	var pWord = theForm.password.value;
	if (pWord.length > '8')
		{
		alert("Your Password should not exceed 8 characters");
				theForm.password.value="";
				theForm.password.focus();
				flag=false;
				return (false);
				}
		}
//Set this return value to true when you want to submit the form
	return (flag);
}


//Job Validator
function job_Validator(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }

//User Name
	theForm.uName.value = LTrim(theForm.uName.value);
	theForm.uName.value = RTrim(theForm.uName.value);
	if (!emptystring(theForm.uName.value))
		 {
			alert("Please Select User Name");
			theForm.uName.focus();
			flag=false;
			return (false);
		} 

//Company Name
	theForm.companyName.value = LTrim(theForm.companyName.value);
	theForm.companyName.value = RTrim(theForm.companyName.value);
	if (!emptystring(theForm.companyName.value))
		 {
			alert("Please Select Company Name");
			theForm.companyName.focus();
			flag=false;
			return (false);
		} 

//Jo Bag Name
	theForm.jbagName.value = LTrim(theForm.jbagName.value);
	theForm.jbagName.value = RTrim(theForm.jbagName.value);
	if (!emptystring(theForm.jbagName.value))
		 {
			alert("Please enter Job Bag Name");
			theForm.jbagName.focus();
			flag=false;
			return (false);
		} 
	//Set this return value to true when you want to submit the form
	return (flag);
}

//Date Validator
function date_Validator(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }

//From Date
	theForm.date_from.value = LTrim(theForm.date_from.value);
	theForm.date_from.value = RTrim(theForm.date_from.value);
	if (!emptystring(theForm.date_from.value))
		 {
			alert("Please Select From Date");
			theForm.date_from.focus();
			flag=false;
			return (false);
		}
		
//To Date
	theForm.date_to.value = LTrim(theForm.date_to.value);
	theForm.date_to.value = RTrim(theForm.date_to.value);
	if (!emptystring(theForm.date_to.value))
		 {
			alert("Please Select To Date");
			theForm.date_to.focus();
			flag=false;
			return (false);
		}
 
	//Set this return value to true when you want to submit the form
	return (flag);
}

//Index Validator
function login_Validator(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }

//E-Mail
	theForm.email.value = LTrim(theForm.email.value);
	theForm.email.value = RTrim(theForm.email.value);
	if (!emptystring(theForm.email.value))
		 {
			alert("Please enter E-Mail");
			theForm.email.focus();
			flag=false;
			return (false);
		}else {
	var flag  = true
	var Temp     = theForm.email
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

	if(theForm.email.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1))                    // No empty spaces permitted
			   {  
		      flag = false
		      alert("Please enter a valid E-Mail address!");
			      Temp.value="";
			      Temp.focus();
		      return flag;
   			}
		}
		}

//Password
	theForm.password.value = LTrim(theForm.password.value);
	theForm.password.value = RTrim(theForm.password.value);
	if (!emptystring(theForm.password.value))
		 {
			alert("Please enter Password");
			theForm.password.focus();
			flag=false;
			return (false);
		}

	//Set this return value to true when you want to submit the form
	return (flag);
}

//Change Password

function password(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
	
	//Current Password
	theForm.currentPassword.value = LTrim(theForm.currentPassword.value);
	theForm.currentPassword.value = RTrim(theForm.currentPassword.value);
	if (!emptystring(theForm.currentPassword.value))
		 {
			alert("Please enter the Current Password");
			theForm.currentPassword.focus();
			flag=false;
			return (false);
		}

	
	//New Password
	theForm.newPassword.value = LTrim(theForm.newPassword.value);
	theForm.newPassword.value = RTrim(theForm.newPassword.value);
	if (!emptystring(theForm.newPassword.value))
		 {
			alert("Please enter the New Password");
			theForm.newPassword.focus();
			flag=false;
			return (false);
		}
	 else 
		{
	var pWord = theForm.newPassword.value;
	if (pWord.length > '8')
		{
		alert("Your Password should not exceed 8 characters");
				theForm.newPassword.value="";
				theForm.newPassword.focus();
				flag=false;
				return (false);
				}
		}
	//Confirm Password
	theForm.confirmPassword.value = LTrim(theForm.confirmPassword.value);
	theForm.confirmPassword.value = RTrim(theForm.confirmPassword.value);
	if (!emptystring(theForm.confirmPassword.value))
		 {
			alert("Please enter the Confirm Password");
			theForm.confirmPassword.focus();
			flag=false;
			return (false);
		}
		
	
	//Compare password
	theForm.newPassword.value = LTrim(theForm.newPassword.value);
	theForm.newPassword.value = RTrim(theForm.newPassword.value);
	theForm.confirmPassword.value = LTrim(theForm.confirmPassword.value);
	theForm.confirmPassword.value = RTrim(theForm.confirmPassword.value);

	if (theForm.newPassword.value != theForm.confirmPassword.value)
		 {
			alert("Password mismatching....");
			theForm.newPassword.value="";
			theForm.confirmPassword.value="";
			theForm.newPassword.focus();
			flag=false;
			return (false);
		}
	
	//Set this return value to true when you want to submit the form
	return (flag);
}

//User alert Validator
function useralert_Validator(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
	 
	 //Username
	if(theForm.userName.selectedIndex==0)
		{
			alert("Please select User Name");
			theForm.userName.focus();
			return false;
		}
		
		 //Template
	if(theForm.tempName.selectedIndex==0)
		{
			alert("Please select Template Name");
			theForm.tempName.focus();
			return false;
		}

//Jo Bag Name
	theForm.TempDesc.value = LTrim(theForm.TempDesc.value);
	theForm.TempDesc.value = RTrim(theForm.TempDesc.value);
	if (!emptystring(theForm.TempDesc.value))
		 {
			alert("Please enter Template Description");
			theForm.TempDesc.focus();
			flag=false;
			return (false);
		} 
	//Set this return value to true when you want to submit the form
	return (flag);
}
//user  Validator
function profile_Validator(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
	 
	 //Username
	if(theForm.userName.selectedIndex==0)
		{
			alert("Please select User Name");
			theForm.userName.focus();
			return false;
		}

//userEmail
	theForm.userEmail.value = LTrim(theForm.userEmail.value);
	theForm.userEmail.value = RTrim(theForm.userEmail.value);
	if (!emptystring(theForm.userEmail.value))
		 {
			alert("Please enter Email id");
			theForm.userEmail.focus();
			flag=false;
			return (false);
		}else {
	var flag  = true
	var Temp     = theForm.userEmail
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

	if(theForm.userEmail.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1))                    // No empty spaces permitted
			   {  
		      flag = false
		      alert("Please enter a valid E-Mail address!");
			      Temp.value="";
			      Temp.focus();
		      return flag;
   			}
		}
		}


	//userPwd
	theForm.userPwd.value = LTrim(theForm.userPwd.value);
	theForm.userPwd.value = RTrim(theForm.userPwd.value);
	if (!emptystring(theForm.userPwd.value))
		 {
			alert("Please enter Password");
			theForm.userPwd.focus();
			flag=false;
			return (false);
		} 

	//Set this return value to true when you want to submit the form
	return (flag);
}
//Printer  Validator
function printerprofile_Validator(theForm)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
	 
 //Username
	theForm.firstname.value = LTrim(theForm.firstname.value);
	theForm.firstname.value = RTrim(theForm.firstname.value);
	if (!emptystring(theForm.firstname.value))
		 {
			alert("Please enter Name");
			theForm.firstname.focus();
			flag=false;
			return (false);
		} 

//userEmail
	theForm.userEmail.value = LTrim(theForm.userEmail.value);
	theForm.userEmail.value = RTrim(theForm.userEmail.value);
	if (!emptystring(theForm.userEmail.value))
		 {
			alert("Please enter Email id");
			theForm.userEmail.focus();
			flag=false;
			return (false);
		}else {
	var flag  = true
	var Temp     = theForm.userEmail
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

	if(theForm.userEmail.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1))                    // No empty spaces permitted
			   {  
		      flag = false
		      alert("Please enter a valid E-Mail address!");
			      Temp.value="";
			      Temp.focus();
		      return flag;
   			}
		}
		}


	//userPwd
	theForm.userPwd.value = LTrim(theForm.userPwd.value);
	theForm.userPwd.value = RTrim(theForm.userPwd.value);
	if (!emptystring(theForm.userPwd.value))
		 {
			alert("Please enter Password");
			theForm.userPwd.focus();
			flag=false;
			return (false);
		} 

	//Set this return value to true when you want to submit the form
	return (flag);
}


function company() {
	if(
	   document.form.existing.selectedIndex==0 &&
	   document.form.companyName.value==""
     ) {
	alert ('Please select existing company or fill in new one');
	return (false);
	}
	else
	{
	return (true);
	}
	}

//Checkbox validation
function findchk() {
 for(i=0;i<document.form.length;i++) { 
  if(document.form.elements[i].type=="checkbox") { 
   if(!document.form.elements[i].checked) { 
    a=0; 
   } 
   else { 
    a=1;break  
   } 
  } 
 } 
 if(a=='0') {
 alert("Please select any one of the checkbox");
 return (false);
 }
}

//Checkbox validation
function findchkjob() {
 for(i=0;i<document.form.length;i++) { 
  if(document.form.elements[i].type=="checkbox") { 
   if(!document.form.elements[i].checked) { 
    a=0; 
   } 
   else { 
    a=1;break  
   } 
  } 
 } 
 if(a=='0') {
 alert("Please select any one of the checkbox");
 return (false);
 } else {
	 var x = confirm("Are you sure you want to delete the selected files?");
	if(x) {
		return (true);
	} else {
		return (false);
     }
 }
}

//Checkbox validation
function findchkuser() {
 for(i=0;i<document.form.length;i++) { 
  if(document.form.elements[i].type=="checkbox") { 
   if(!document.form.elements[i].checked) { 
    a=0; 
   } 
   else { 
    a=1;break  
   } 
  } 
 } 
 if(a=='0') {
 alert("Please select any one of the checkbox");
 return (false);
 } else {
	 var x = confirm("Are you sure you want to delete the users?");
	if(x) {
		return (true);
	} else {
		return (false);
     }
 }
}


function joblength() {
	var jobbag=document.form.jbagName.value;
	if (jobbag.length > '40') {
		alert ('Job bag name is within 40 characters');
		document.form.jbagName.focus();
	}
}


function jobbagdesc() {
	var jobbag=document.form.jbagDesc.value;
	if (jobbag.length > '255') {
		alert ('Job bag description is within 255 characters');
		document.form.jbagDesc.focus();
		return (false);
	}
}


