// JavaScript Document
function verify(f)
{


 	var AtSym    = f.email.value.indexOf('@')
    var Period   = f.email.value.lastIndexOf('.')
    var Space    = f.email.value.indexOf(' ')
    var Length   = f.email.value.length - 1   // Array is from 0 to length-1
	

if (f.full_name.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
alert("You have not entered a  name");f.full_name.focus();return false;
}
if (f.enquiry.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
//alert("You have not entered an enquiry");f.enquiry.focus();return false;
}

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
 {  
   alert('Please enter a valid Email address!')
   f.email.focus();
   return (false) ;
 }

return  (confirm("Do you wish to send this form?")) 
 }
function verifylogin(f)
{


 	var AtSym    = f.user.value.indexOf('@')
    var Period   = f.user.value.lastIndexOf('.')
    var Space    = f.user.value.indexOf(' ')
    var Length   = f.user.value.length - 1   // Array is from 0 to length-1
	
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
 {  
   alert('The email address is invalid !')
   f.user.focus();
   return (false) ;
 }

if (f.user.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
alert("You have not entered an email address");f.user.focus();return false;
}
if (f.pw.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
alert("You have not entered a password");f.pw.focus();return false;
}

return  (true);	
 }
 
 
 function verifyuser(f)
{


 	var AtSym    = f.user.value.indexOf('@')
    var Period   = f.user.value.lastIndexOf('.')
    var Space    = f.user.value.indexOf(' ')
    var Length   = f.user.value.length - 1   // Array is from 0 to length-1
	
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
 {  
   alert('The email address is invalid !')
   f.user.focus();
   return (false) ;
 }

if (f.user.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
alert("You have not entered an email address");f.user.focus();return false;
}
if (f.companyname.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
alert("You have not entered a company name");f.companyname.focus();return false;
}
if (f.clientname.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
alert("You have not entered a contact name");f.clientname.focus();return false;
}

if (f.axos_pw.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
//alert("You have not entered a password");f.pw.focus();return false;
}

return  (confirm("Confirm save")) 
 }
 //
function verifyprice(f)
{ 
if(f.selitemid.selectedIndex==0)
{ 
alert("Please select an item.");
f.selitemid.focus();
return false;
}
	
OK=isDate(f.fromdate.value);
if (!OK){alert("From date is invalid. Correct format is DD/MM/YYYY.");
f.fromdate.focus(); return false; }
	
	
if (f.price.value.replace(/^\s+/g, '').replace(/\s+$/g, '')   =="" )
{
alert("You have not entered a price");f.price.focus();return false;
}
OK=isDec(f.price.value);
if (!OK){alert("Price must be a decimal");return false;}

if(f.remote_site.selectedIndex==0)
{
alert("Please select whether this is on site or remote price.");
f.remote_site.focus();
return false;
}

return  (confirm("Confirm save")) 


}


function isDate(sDate) {
if (sDate.indexOf('/')==-1){return false}
if (sDate.replace(/^\s+/g, '').replace(/\s+$/g, '')!="")
 {  dArr=sDate.split("/");
   if (dArr[0].length==1){dArr[0]="0" +dArr[0]}
   if (dArr[1].length==1){dArr[1]="0" +dArr[1]}
   sDate = dArr[1]+ "/" + dArr[0]+ "/" + dArr[2];
   var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
   if (re.test(sDate)) {
      var dArr = sDate.split("/");
      var d = new Date(sDate);
	//  return true;
    return d.getMonth() + 1 == dArr[0] && d.getDate() == dArr[1] && d.getFullYear() == dArr[2];
   }
   else {
      return false;
   }
   }
}
function isNum(num) {
var PNum = new String(num);	var regex = /[^0-9]/;
return !regex.test(PNum);
}
function isDec(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
   
  function additem(RS)
{ 	    c=parseFloat(document.getElementById('counter'+RS).innerHTML);
		alert(c);
		c=c+1;
		document.getElementById('counter'+RS).innerHTML=c;
		newInput= "row"+RS+"_"+c;
		document.getElementById(newInput).style.display="block";
		el=document.getElementById(newInput);
		el.focus();
}
function verifypackage(f)
{
if (f.clientid.selectedIndex=="0")
{
alert("Please select a client.") 
}
	
//check that the contract details have been entered
if (f.contractname.value=="")
{alert("please enter a name for this package") }
if (f.contract_date.value=="")
{alert("please enter a start date for this package") }


}

function confirmdelete(prod)
{
return  (confirm("Are you sure you want to delete "+prod+"?. The record will be permanently removed from the system.")) 
}


