//--------------Cookie Functions------------------------------
function SetCookie (name, value) { // Setting a cookie
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	}

function getCookieVal (offset) { // reading a cookie
     var endstr = document.cookie.indexOf (";", offset);
     if (endstr == -1)
       endstr = document.cookie.length;
     return unescape(document.cookie.substring(offset, endstr));
  }
function GetCookie (name)  { // Finding a cookie
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen)  {
   var j = i + alen;
   if (document.cookie.substring(i, j) == arg)
   return getCookieVal (j);i = document.cookie.indexOf(" ", i) + 1;
   if (i == 0) break;    
}
return null;
}

function DeleteCookie (name) {  // delete a cookie
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name); 
	document.cookie = name + "=" + cval + "; expires=Thu, 01-Jan-2006 00:00:01 GMT";
	//var expires = new Date();
	//expires.setUTCFullYear(expires.getUTCFullYear() - 1);
	//document.cookie = name + '=' + cval + '; expires=' + expires.toUTCString();
}

//---------------Navbar Formatting Script----------------------

function bg(what,color){
	what.style.backgroundColor=color
	}

function borderize_on(e){
	if (document.all)
		source3=event.srcElement
	else if (document.getElementById)
		source3=e.target
	if (source3.className=="nav"){
		bg(source3,"#6699CC")
	}
	else{
		while(source3.tagName!="TABLE"){
			source3=document.getElementById? source3.parentNode : source3.parentElement
			if (source3.className=="nav")
				bg(source3,"#6699CC")
			}
		}
	}

function borderize_off(e){
	if (document.all)
		source4=event.srcElement
	else if (document.getElementById)
		source4=e.target
	if (source4.className=="nav")
		bg(source4,"#0000FF")
	else{
		while(source4.tagName!="TABLE"){
			source4=document.getElementById? source4.parentNode : source4.parentElement
			if (source4.className=="nav")
				bg(source4,"#0000FF")
			}
		}
	}

//-----------------------End of Navbar script--------------------------------
//----------------Emailing Functions -------------------------
function emailer(who,chk,pg){ // open emailing page
	mypath=(pg=="new")? "../mail/" : "./mail/" ;
	window.open(mypath+"?who="+who+"&cmd="+chk,"","width=400,height=400,scrollbars=yes,status=0,resizable=0,location=no,directories=no,status=no,,top=50,left=200");
}

function UncheckAll() { // unchecks all emails checkboxes
	document.emails.reset();
}

function CheckAll() { // unchecks all emails checkboxes
	with (document.emails) {
		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'checkbox' && elements[i].name == 'email[]')
				elements[i].checked = true;
			}
		}
	}

function IsChecked() { // validates checked emails
	var chk=false;
	with (document.emails) {
		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'checkbox' && elements[i].name == 'email[]')
				 if(elements[i].checked==true) chk=true;
			}
		}
		if(!chk){
			alert("Select at least one recipient to proceed");
			return false
		}else return true;
		
	}


//-----------------------Start of validation Scripts------------------------------
//--------------- Selection functions---------------------
function itemSel(theForm,lim,str){ // Validates  selected items
 var i=0;
 var txt="";
 var boolchk;
 var found=false;
 while(i<lim && !found){
  	boolchk=(lim>1)?theForm.id[i].checked:theForm.id.checked;
  	if(boolchk){
    	found=true;
		txt=(lim>1)?theForm.id[i].value:theForm.id.value;		
	}
  i++;
 } 
 if(!found){
 	alert("You have not selected any "+str);
	return false;
 } 
 return txt;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ validates feedback input  +++++++++++++++++++++++++++++++++++++++++++++++++
function validcomment(){  
	name=document.feedback.names.value;
	email=document.feedback.email.value;
	ftype=document.feedback.ftype.value;
	subject=document.feedback.subject.value;
	comment=document.feedback.comment.value;
	if(name=="" || email=="" || subject=="" || comment==""){
		alert("Please provide all information before\nsending feedback\n");
		document.feedback.names.focus();
		return (false);
		}
	if(ftype=="none"){
		alert("Please select the type of feedback you are sending\n");
		document.feedback.ftype.focus();
		return (false);
		}
	if (email.indexOf("@")<3){
		alert("Please enter valid email address\n");
		document.feedback.email.focus();
		return (false);
		}
	if ((email.indexOf(".com")<5)&&(email.indexOf(".org")<5)
		&&(email.indexOf(".gov")<5)&&(email.indexOf(".net")<5)
		&&(email.indexOf(".co.")<5)&&(email.indexOf(".edu")<5)){
		alert("Please enter valid email address\n");
		document.feedback.email.focus();
		return (false);
		}	
	return (true);
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  validates email addresses +++++++++++++++++++++++++++++++++++++++++++++++++	
function isValidEmail(myemail){ 
	if (myemail.indexOf("@")<3){
		return (false);
		}
	if ((myemail.indexOf(".com")<5)&&(myemail.indexOf(".org")<5)
		&&(myemail.indexOf(".gov")<5)&&(myemail.indexOf(".net")<5)
		&&(myemail.indexOf(".co.")<5)&&(myemail.indexOf(".edu")<5)){
		return (false);
		}	
	return (true);
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ validates numeric entries  +++++++++++++++++++++++++++++++++++++++++++++++++	
function isNum(num){  
	var digits="0123456789"
	var temp
	for (var i=0;i<num.length;i++){
		temp=num.substring(i,i+1)
		if (digits.indexOf(temp)==-1){			
			return (false);
      	}
   	}
	return (true);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ validates dates  +++++++++++++++++++++++++++++++++++++++++++++++++
function isValidDate(day,month,year){  
	var now = new Date();
	d=now.getDate();
	m=now.getMonth()+1;
	//yr=now.getYear();
	yr=now.getYear();
	yr = yr % 100;
	yr = 2000 + yr;
	
	if(year<yr)
		return (false);
	if(year==yr && month<m)
		return (false);
	if(year==yr && month==m && day<d)
		return (false);	
	if(month<1 || month>12 )
		return (false);
	if(day<1 || day>31 )
		return (false);
	if(month==4 || month==6 || month==9 || month==11){
		 if(day>30) return (false);
		}		
	if(month==2){
		var g=parseInt(year/4)
		if (isNaN(g)) return (false);
		if (day>29) return (false);
		if (day==29 && ((year/4)!=parseInt(year/4))) return (false);
		}	
	return (true);
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ validates login form entry before submitting  +++++++++++++++++++++++++++++++++++++++++++++++++
function loginForm(){  
	uname=document.login.uname.value;
	pword=document.login.pword.value;	
	if(uname=="" || pword==""){
		alert("Please enter username and password");
		document.login.uname.focus();
		return false;
	}	
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates change of password entries  +++++++++++++++++++++++++++++++++++++++++++++++++	
function changePw(str,ulevel){  
	level=(str=="webmaster" || ulevel!="administrator")? "none" : document.changepass.level.value  ;
	//access=(str=="webmaster")? document.changepass : false ;
	oldpass=(str!="webmaster" && ulevel=="administrator")? "none" : document.changepass.oldpass.value;
	newpass=document.changepass.newpass.value;
	confpass=document.changepass.confpass.value;
	email=document.changepass.email.value;
	//alert(email);
	/*if(level=="none" && oldpass=="" && newpass=="" && confpass=="" && email==""){
		alert("Enter a new password or email to update.");
		if(str!="webmaster" && ulevel=="administrator")
			document.changepass.newpass.focus();
		else
			document.changepass.oldpass.focus();
		return false;
	}*/
	if(oldpass != "" && oldpass != "none"){
		if(oldpass=="" && oldpass!="none"){
			alert("Enter old password");
			document.changepass.oldpass.focus();
			return false;
			}
		if(newpass.length<6){
			alert("New password is too short");
			document.changepass.newpass.focus();
			return false;
			}
		if(newpass!=confpass){
			alert("New password and confirmation do not match");
			document.changepass.newpass.focus();
			return false;
		}		
	}	
	if(email!="" && !isValidEmail(email)){
		alert("Invalid email address.");
		document.changepass.email.focus();
		return false;
		}	
	if(!permissions(document.changepass) && document.changepass.news){
		alert("Please select permissions for the user");
		document.changepass.news.focus();
		return false;
		}
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ validates permissions selection  +++++++++++++++++++++++++++++++++++++++++++++++++
function permissions(myform){ 
	var chk=false;
	with (myform) {
		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'checkbox')
				 if(elements[i].checked==true) chk=true;
			}
		}
		if(!chk) return false
		else return true;
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates create user entries  +++++++++++++++++++++++++++++++++++++++++++++++++
function createUser(){  
	uname=document.createuser.username.value;	
	pword=document.createuser.pword.value;
	confpass=document.createuser.confpass.value;
	ulevel=document.createuser.level.value;
	email=document.createuser.email.value;
	if(uname=="" || pword=="" || confpass=="" || ulevel=="none"){
		alert("User details are incomplete");
		document.createuser.username.focus();
		return false;
	}
	if(pword.length<6){
		alert("Your password is too short");
		document.createuser.pword.focus();
		return false;
	}
	if(pword!=confpass){
		alert("Passwords do not match");
		document.createuser.pword.focus();
		return false;
	}
	if(email!="" && !isValidEmail(email)){
		alert("Invalid email address.");
		document.createuser.email.focus();
		return false;
		}
	if(!permissions(document.createuser) && ulevel!="Administrator"){
		alert("Please select permissions for the user");
		document.createuser.news.focus();
		return false;
		}
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  validates remove user command +++++++++++++++++++++++++++++++++++++++++++++++++
function removeUser(txt,ulevel){  
	if(ulevel!="administrator"){
		alert("You have insufficient privileges to delete users");
		return false;
		}
	if(txt=="webmaster"){
		alert("Webmaster account cannot be deleted");
		return false;
		}
	question = confirm("Are you sure you want to delete "+txt+"?")
	if (question !="0")
		window.location = "./?opt=users&id="+txt+"&action=true&cmd=removeuser";
	else
		return (false);	
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates create customer and supplier details  +++++++++++++++++++++++++++++++++++++++++++++++++
function createmkt(usr){  
	uname=document.addmkt.cname.value;
	pword=document.addmkt.pword.value;
	confpass=document.addmkt.confpass.value;
	email=document.addmkt.email.value;
	if(uname=="" && pword=="" && confpass==""){
		alert("Enter at least a name and password to continue");
		document.addmkt.cname.focus();
		return false;
	}
	if(pword!=confpass){
		alert("Passwords do not match");
		document.addmkt.pword.focus();
		return false;
	}
	if(email!="" && !isValidEmail(email)){
		alert("Invalid email address.");
		document.addmkt.email.focus();
		return false;
		}
	if(usr=="marketers"){
		if(!permissions(document.addmkt)){
			alert("Please select permissions for the user");
			document.addmkt.programs.focus();
			return false;
			}
		}
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates update customer and supplier details  +++++++++++++++++++++++++++++++++++++++++++++++++
function changemkt(usr){	  
	newval=document.updatemkt.newval.value;
	pword=document.updatemkt.pword.value;
	confpass=document.updatemkt.confpass.value;
	email=document.updatemkt.email.value;
	if(newval=="" && pword=="" && confpass=="" && email=="" && !permissions(document.updatemkt)){
		alert("Specify new name, password, email or permissions before you proceed");
		document.updatemkt.newval.focus();
		return false;
		}
	if(pword!=confpass){
		alert("Passwords do not match");
		document.updatemkt.pword.focus();
		return false;
	}
	if(email!="" && !isValidEmail(email)){
		alert("Invalid email address.");
		document.updatemkt.email.focus();
		return false;
		}
	if(usr=="marketers"){
		if(!permissions(document.updatemkt)){
			alert("Please select permissions for the user");
			document.updatemkt.programs.focus();
			return false;
			}
		}
	return (true);	
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates delete customer and supplier details  +++++++++++++++++++++++++++++++++++++++++++++++++
function removemkt(myid,txt,title){  
	question = confirm("Are you sure you want to delete "+txt+"?")
	if (question !="0")
		window.location = "./?opt="+title+"&id="+myid+"&action=true&cmd=removemkt";
	else
		return (false);
		
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates post program details  +++++++++++++++++++++++++++++++++++++++++++++++++	
function createprog(){  
	company=document.addprog.company.value;			
	fname=document.addprog.fname.value;	
	if(company=="none" || fname==""){
		alert("Please select the marketer and specify the program file");
		document.addprog.company.focus();
		return false;
	}
	showPBar();
	return (true);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates update program details  +++++++++++++++++++++++++++++++++++++++++++++++++
function changeprog(){	  
	nfile=document.updateprog.newfile.value;
	showPBar();
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates delete program details  +++++++++++++++++++++++++++++++++++++++++++++++++
function removeprog(myid,txt1,txt2){  
	question = confirm("Are you sure you want to delete "+txt1+" program for "+txt2+"?")
	if (question !="0")
		window.location = "./?opt=programs&id="+myid+"&action=true&cmd=removeprog";
	else
		return (false);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Validates post certificate details +++++++++++++++++++++++++++++++++++++++++++++++++
function createcert(){   
	company=document.addcert.company.value;	
	product=document.addcert.product.value;
	fname=document.addcert.fname.value;	
	if(company=="none" || product=="" || fname==""){
		alert("All fields are mandatory");
		document.addcert.company.focus();
		return false;
	}	
	showPBar();
	return (true);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates update certificate details  +++++++++++++++++++++++++++++++++++++++++++++++++
function changecert(){	   
	company=document.updatecert.company.value;	
	product=document.updatecert.product.value;
	if(company=="none" || product==""){
		alert("Specify product name or certificate to proceed");
		document.updatecert.product.focus();
		return false;
	}
	showPBar();
	return (true);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates delete certificate details  +++++++++++++++++++++++++++++++++++++++++++++++++
function removecert(myid,txt1,txt2){	 
	question = confirm("Are you sure you want to delete "+txt1+" certificate for "+txt2+"?")
	if (question !="0")
		window.location = "./?opt=certs&id="+myid+"&action=true&cmd=removecert";
	else
		return (false);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Validates create statement details +++++++++++++++++++++++++++++++++++++++++++++++++
function createstat(){					 
	fname=document.addstat.fname.value;	
	if(fname==""){
		alert("Please specify the statement file");
		document.addstat.fname.focus();
		return false;
	}	
	showPBar();
	return (true);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Validates update statement details +++++++++++++++++++++++++++++++++++++++++++++++++
function changestat(){		  
	nfile=document.updatestat.newfile.value;	
	showPBar();
	return true;	
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates delete statement details  +++++++++++++++++++++++++++++++++++++++++++++++++
function removestat(myid,txt2){	   
	question = confirm("Are you sure you want to delete statement for "+txt2+"?")
	if (question !="0")
		window.location = "./?opt=statements&id="+myid+"&action=true&cmd=removestat";
	else
		return (false);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++  Validates create HSE Document details +++++++++++++++++++++++++++++++++++++++++++++++++
function createhse(){					 
	fname=document.addhse.fname.value;
	title=document.addhse.title.value;
	if(title==""){
		alert("Please enter the HSE Document Title");
		document.addhse.title.focus();
		return false;
	}   
	if(fname==""){
		alert("Please specify the HSE Document file");
		document.addhse.fname.focus();
		return false;
	}	
	showPBar();
	return (true);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Validates update HSE Document details +++++++++++++++++++++++++++++++++++++++++++++++++
function changehse(){		  
	title=document.updatehse.title.value;
	nfile=document.updatehse.newfile.value;	
	if(title==""){
		alert("Please enter the HSE Document Title");
		document.updatehse.title.focus();
		return false;
	}   
	showPBar();
	return true;	
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates delete HSE Document details  +++++++++++++++++++++++++++++++++++++++++++++++++
function removehse(myid,txt2){	   
	question = confirm("Are you sure you want to delete HSE Document for "+txt2+"?")
	if (question !="0")
		window.location = "./?opt=hse&id="+myid+"&action=true&cmd=removehse";
	else
		return (false);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++  Validates create ERS Document details +++++++++++++++++++++++++++++++++++++++++++++++++
function createers(){					 
	fname=document.adders.fname.value;
	title=document.adders.title.value;
	if(title==""){
		alert("Please enter the ERS Document Title");
		document.adders.title.focus();
		return false;
	}   
	if(fname==""){
		alert("Please specify the ERS Document file");
		document.adders.fname.focus();
		return false;
	}	
	showPBar();
	return (true);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Validates update ERS Document details +++++++++++++++++++++++++++++++++++++++++++++++++
function changeers(){		  
	title=document.updateers.title.value;
	nfile=document.updateers.newfile.value;	
	if(title==""){
		alert("Please enter the ERS Document Title");
		document.updateers.title.focus();
		return false;
	}   
	showPBar();
	return true;	
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates delete HSE Document details  +++++++++++++++++++++++++++++++++++++++++++++++++
function removehse(myid,txt2){	   
	question = confirm("Are you sure you want to delete ERS Document "+txt2+"?")
	if (question !="0")
		window.location = "./?opt=ers&id="+myid+"&action=true&cmd=removeers";
	else
		return (false);
}


//+++++++++++++++++++++  Validates post careers details +++++++++++++++++++++++++++++++++++++++++++++++++
function postjob(){ 	
	title=document.addjob.title.value;
	vfile=document.addjob.vfile.value;
	strday=document.addjob.day.value;
	strmonth=document.addjob.month.value;
	stryr=document.addjob.year.value;
	if(title==""){
		alert("Please enter the Job Title");
		document.addjob.title.focus();
		return false;
	}    
 	if(vfile.indexOf(".pdf") == -1)
		{
   		alert("You have not selected a PDF file for the Vacancy position");
		document.addjob.vfile.focus();
		return false;
		}
	if(!isValidDate(strday,strmonth,stryr)){
		alert("Invalid due date!\nPlease ensure that you have entered a correct date\nand that it is not a past date");
		document.addjob.day.focus();
		return (false);
		}	
	showPBar();
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates update careers details   +++++++++++++++++++++++++++++++++++++++++++++++++
function editjob(){	
	title=document.updatejob.title.value;
	vfile=document.updatejob.vfile.value;
	d=document.updatejob.day.value;
	m=document.updatejob.month.value;
	y=document.updatejob.year.value;
	if(title == ""){
		alert("Please enter the Job Title");
		document.updatejob.title.focus();
		return false;
	}    
 	if(vfile.length > 0 && vfile.indexOf(".pdf") == -1)
		{
   		alert("You have not selected a PDF file for the Vacancy position");
		document.updatejob.vfile.focus();
		return false;
		}
	if(!isNum(d) || !isNum(m) || !isNum(y)){
		alert("Invalid due date!\nPlease ensure that you have entered the correct date\n");
		document.updatejob.day.focus();
		return (false);
	}
	if(!isValidDate(d,m,y)){
		alert("Invalid due date!\nPlease ensure that you have entered the correct date\n");
		document.updatejob.day.focus();
		return (false);
		}	
	showPBar();
	return (true);
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Validates delete careers details +++++++++++++++++++++++++++++++++++++++++++++++++
function removejob(myid,txt){   
	question = confirm("Are you sure you want to delete job number "+txt+"?")
	if (question !="0")
		window.location = "./?opt=jobs&id="+myid+"&action=true&cmd=deljob";
	else
		return (false);
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Validates delete message details +++++++++++++++++++++++++++++++++++++++++++++++++
function deletemsg(myid,txt){    
	question = confirm("Are you sure you want to delete the comment from "+txt+"?")
	if (question !="0")
		window.location = "./?opt=comments&id="+myid+"&action=true";
	else
		return (false);
	}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates post tender details  +++++++++++++++++++++++++++++++++++++++++++++++++
function postTender(){   
	tno=document.addtender.tNo.value;	
	title=document.addtender.title.value;
	fname=document.addtender.fname.value;
	claday=document.addtender.claday.value;
	clamonth=document.addtender.clamonth.value;
	clayr=document.addtender.clayr.value;
	strday=document.addtender.day.value;
	strmonth=document.addtender.month.value;
	stryr=document.addtender.year.value;
	ignore=document.addtender.ignore.checked;
	if(tno=="" || title=="" || fname.length<=0){
		alert("All fields are required");
		document.addtender.tNo.focus();
		return false;
	}	
	if(!ignore && !isValidDate(claday,clamonth,clayr)){
		alert("Invalid clarification date!\nPlease ensure that you have entered a correct date\nand that it is not a past date");
		document.addtender.claday.focus();
		return (false);
		}	
	if(!isValidDate(strday,strmonth,stryr)){
		alert("Invalid due date!\nPlease ensure that you have entered a correct date\nand that it is not a past date");
		document.addtender.day.focus();
		return (false);
		}	
	showPBar();
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Validates update tender details +++++++++++++++++++++++++++++++++++++++++++++++++
function editTender(){    
	tno=document.updatetender.tNo.value;	
	title=document.updatetender.title.value;
	//fname=document.updatetender.fname.value;
	claday=document.updatetender.claday.value;
	clamonth=document.updatetender.clamonth.value;
	clayr=document.updatetender.clayr.value;
	d=document.updatetender.day.value;
	m=document.updatetender.month.value;
	y=document.updatetender.year.value;
	ignore=document.updatetender.ignore.checked;
	if(tno=="" || title==""){
		alert("Tender number and Title are required");
		document.updatetender.tNo.focus();
		return false;
	}
	if(!isNum(claday) || !isNum(clamonth) || !isNum(clayr)){
		alert("Invalid clarification date!\nPlease ensure that you have entered the correct date\n");
		document.updatetender.claday.focus();
		return (false);
	}
	if(!isNum(d) || !isNum(m) || !isNum(y)){
		alert("Invalid due date!\nPlease ensure that you have entered the correct date\n");
		document.updatetender.day.focus();
		return (false);
	}
	if(!ignore && !isValidDate(claday,clamonth,clayr)){
		alert("Invalid clarification date!\nPlease ensure that you have entered a correct date\nand that it is not a past date");
		document.updatetender.claday.focus();
		return (false);
		}
	if(!isValidDate(d,m,y)){
		alert("Invalid due date!\nPlease ensure that you have entered the correct date\n");
		document.updatetender.day.focus();
		return (false);
		}
	showPBar();
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validates delete tender details+++++++++++++++++++++++++++++++++++++++++++++++++
function deltender(myid,txt){   
	question = confirm("Are you sure you want to delete tender number "+txt+"?")
	if (question !="0")
		window.location = "./?opt=tenders&id="+myid+"&action=true&cmd=deltender";
	else
		return (false);		
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++  Confirms deletion +++++++++++++++++++++++++++++++++++++++++++++++++
function confdel(myitem){  
	ask=confirm("Are you sure you want to delete "+myitem);
	if(ask!=0) return true; 
	else return false;
	}
//+++++++++++++++++++++ Validate Post News form +++++++++++++++++++++++++++++++++++++++++++++++++

function postNews(){
	title=document.addnews.title.value;
	contents=document.addnews.contents.value;	
	if(title=="" || contents==""){
		alert("All fields are required");
		document.addnews.title.focus();
		return false;
	}	
	showPBar();
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validate Update News form +++++++++++++++++++++++++++++++++++++++++++++++++

function updateNews(){		
	title=document.updatenews.title.value;
	contents=document.updatenews.contents.value;
	//pic=document.updatenews.pic.value;
	if(title=="" || contents==""){
		alert("All fields are required");
		document.updatenews.title.focus();
		return false;
	}
	//if(pic.length>0 && !is_pic(pic)){
		//alert("The picture you have selected is not valid");
		//document.updatenews.pic.focus();
		//return false;
	//}	
	showPBar();
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validate Remove News form +++++++++++++++++++++++++++++++++++++++++++++++++

function removeNews(myid,txt,q){	
	question = confirm("Are you sure you want to delete the "+q+" titled\n"+txt+"?")
	if (question !="0")
		window.location = "./?opt=events&q="+q+"&id="+myid+"&action=true&cmd=removeevent";
	else
		return (false);	
}
//+++++++++++++++++++++ Validate Post CSR form +++++++++++++++++++++++++++++++++++++++++++++++++

function postcsr(){
	title=document.addcsr.title.value;
	contents=document.addcsr.contents.value;
	pic=document.addcsr.photo.value;	
	if(title=="" || contents==""){
		alert("The title and contents fields are required before you proceed");
		document.addcsr.title.focus();
		return false;
	}	
	if(pic.length>0 && !is_pic(pic)){
		alert("The file in Photo is not a valid photo");
		document.addcsr.photo.focus();
		return false;
	}
	showPBar();
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validate Update CSR form +++++++++++++++++++++++++++++++++++++++++++++++++

function updatecsr(){		
	title=document.editcsr.title.value;
	contents=document.editcsr.contents.value;
	pic=document.editcsr.photo.value;
	if(title=="" || contents==""){
		alert("The title and contents are required before you proceed");
		document.editcsr.title.focus();
		return false;
	}
	if(pic.length>0 && !is_pic(pic)){
		alert("The picture you have chosen is not valid");
		document.editcsr.photo.focus();
		return false;
	}	
	showPBar();
	return true;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++ Validate Remove CSR form +++++++++++++++++++++++++++++++++++++++++++++++++

function removecsr(myid,txt){	
	question = confirm("Are you sure you want to delete the CSR titled\n"+txt+"?")
	if (question !="0")
		window.location = "./?opt=csr&id="+myid+"&action=true&cmd=removecsr";
	else
		return (false);	
}
//+++++++++++++++++++++ Validate Photo +++++++++++++++++++++++++++++++++++++++++++++++++


function is_pic(fname){	    
 	if(fname.indexOf(".gif")==-1 && fname.indexOf(".jpg")==-1)
   		return (false);
 	return(true);
}

//++++++++++++++++++++++ User Privileges ++++++++++++++++++++++++++++++++++++++++++++

function chkaccess(chk){
	switch(chk){
		case "Y":			
			return true;			
		break;	
		case "N":			
			alert("Your access level prohibits accessing this page.");
			return false;			
		break;					
		}
		//return true;
	}
	
//++++++++++++++++++++ Validate new LPO post for Order tracking +++++++++++++++++++++++++++++++++++++++++++++++++++
function neworder(){
	onum=document.addorder.ordernum.value;	
	fname=document.addorder.fname.value;
	supplier=document.addorder.supplier.value;	
	contact=document.addorder.contact.value;	
	if(onum=="" || fname=="" || supplier=="none" || contact==""){
		alert("All marked fields are mandatory");
		document.addorder.ordernum.focus();
		return false;
	}	
	showPBar();
	return true;
}
//++++++++++++++++++++ Validate edit LPO post for Order tracking +++++++++++++++++++++++++++++++++++++++++++++++++++
function editorder(){	
	onum=document.updateorder.ordernum.value;
	supplier=document.updateorder.supplier.value;	
	contact=document.updateorder.contact.value;	
	if(onum=="" || desc=="" || supplier=="none" || comments=="" || contact==""){
		alert("All marked fields are required");
		document.updateorder.ordernum.focus();
		return false;
	}	
	showPBar();
	return true;
	}
//++++++++++++++++++++ Validate update LPO status for Order tracking +++++++++++++++++++++++++++++++++++++++++++++++++++
function editstatus(){
	mystatus=document.updatestatus.mystatus.value;
	comments=document.updatestatus.comments.value;
	contact=document.updatestatus.contact.value;	
	if(mystatus=="" || comments=="" || contact==""){
		alert("All fields are required");
		document.updatestatus.mystatus.focus();
		return false;
	}	
	return true;
}
//++++++++++++++++++++ Validate delete LPO for Order tracking +++++++++++++++++++++++++++++++++++++++++++++++++++
function delorder(myid){
	question = confirm("Are you sure you want to delete order no. "+myid+"?")
	if (question !="0")
		window.location = "trackit.php?opt=delorder&id="+myid+"&action=true";
	else
		return (false);
	}
	
//++++++++++++++++++++++++++++++++++=Search Procedures++++++++++++++++++++++++++++++++++++++++++++++

function addsdata(){ // validates searching criteria
	keyword=document.tblsearch.keyword.value;
	pageid=document.tblsearch.pageid.value;
	content=document.tblsearch.content.value;	
	if(keyword=="" || pageid=="none" || content==""){
		alert("All fields are required");
		document.tblsearch.keyword.focus();
		return false;
		}	
	return true;	
	}
	
function addpref(){
	url=document.pref.url.value;
	title=document.pref.title.value;		
	if(url=="" || title==""){
		alert("All fields are required");
		document.pref.url.focus();
		return false;
		}	
	return true;	
	}
	
// Toggle between content and progress bar
function showPBar(){		
	document.getElementById("content").style.display = "none" ;
	document.getElementById("prog_bar").style.display = "block" ;
	}
