
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function openpopup(popurl){
var winpops=window.open(popurl,"","width=,height=,status,menubar,resizable")
}

function confirmSubmitTimesheet()
{
var ok=confirm('Are you sure you want to submit your Timesheet including your expenses?')
if (ok)
   return true
else
   return false;
}

function confirmSecureAccess()
{
var ok=confirm('You have read the agreement and agree to pay the amount for Secure Access?')
if (ok)
   return true
else
   return false;
}

function confirmVerify()
{
var ok=confirm('Do you approve the Timesheet?')
if (ok)
   return true
else
   return false;
}

function confirmDeleteRetailer()
{
var ok=confirm('Do you want to delete the Retailer?')
if (ok)
   return true
else
   return false;
}

function confirmDelete()
{
var ok=confirm('Do you want to delete this User?')
if (ok)
   return true
else
   return false;
}

function confirmUnsubscibeInvoice()
{
var ok=confirm('Do you want to UnSubscribe this Invoice?')
if (ok)
   return true
else
   return false;
}

function confirmUnSubmitTimesheet()
{
var ok=confirm('Do you want to Un-Submit this Timesheet?')
if (ok)
   return true
else
   return false;
}

function goToURL(URL) 
{	
	window.location = URL;

}

function verifyTimesheetDet(theForm)
{
	if (theForm.txtStore.value=="") {
		alert("You must enter Store")
		theForm.txtStore.focus()
		theForm.txtStore.select()
		return false
	}

	if (theForm.txtHours.value=="") {
		alert("You must enter Hours")
		theForm.txtHours.focus()
		theForm.txtHours.select()
		return false
	}
	
	if (theForm.txtMileage.value=="") {
		alert("You must enter Mileage")
		theForm.txtMileage.focus()
		theForm.txtMileage.select()
		return false
	}
	if (theForm.txtComments.value=="") {
		alert("You must enter Comments")
		theForm.txtComments.focus()
		theForm.txtComments.select()
		return false
	}

	return true
}

function checkDate(fld) {
    var mo, day, yr;
    var entry = fld.value;
    var re = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
    if (re.test(entry)) {
        var delimChar = (entry.indexOf("/") != -1) ? "/" : "-";
        var delim1 = entry.indexOf(delimChar);
        var delim2 = entry.lastIndexOf(delimChar);
        mo = parseInt(entry.substring(0, delim1), 10);
        day = parseInt(entry.substring(delim1+1, delim2), 10);
        yr = parseInt(entry.substring(delim2+1), 10);
        var testDate = new Date(yr, mo-1, day);
        alert(testDate)
        if (testDate.getDate() == day) {
            if (testDate.getMonth() + 1 == mo) {
                if (testDate.getFullYear() == yr) {
                    return true;
                } else {
                    alert("There is a problem with the year entry.");
                }
            } else {
                alert("There is a problem with the month entry.");
            }
        } else {
            alert("There is a problem with the date entry.");
        }
    } else {
        alert("Incorrect date format. Enter as mm/dd/yyyy.");
    }
    return false;
}

function validateDate(fld) {
    if (!checkDate(fld)) {
        // focus if validation fails
        fld.focus();
        fld.select();
    }
}



