function showdate(fieldx,dateformat) {
  var date = new Date();
  var d  = date.getDate();
  var day = (d <10) ? '0' + d : d;
  var m = date.getMonth() + 1;
  var month = (m <10) ? '0' + m : m;
  var yy = date.getYear();
  var year = (yy <1000) ? yy + 1900 : yy;
  if (dateformat=="mm/dd/yyyy")
    fieldx.value = month + "/" + day + "/" + year;
  else
    fieldx.value = day + "/" + month + "/" + year;
}

function showNextdate(fieldx,dateformat,NDay) {
  var predate = new Date();
  var date = new Date(predate.getTime() + NDay * 24 * 60 * 60 * 1000); 
  var d  = date.getDate();
  var day = (d <10) ? '0' + d : d;
  var m = date.getMonth() + 1;
  var month = (m <10) ? '0' + m : m;
  var yy = date.getYear();
  var year = (yy <1000) ? yy + 1900 : yy;
  if (dateformat=="mm/dd/yyyy")
    fieldx.value = month + "/" + day + "/" + year;
  else
    fieldx.value = day + "/" + month + "/" + year;
}

function showtime(fieldx){
  var now = new Date()
  var hours = now.getHours()
  var minutes = now.getMinutes()
  var timevalue="";
  
  if (hours < 10) 
    timevalue = "0" + hours
  else
    timevalue = hours;
  if (minutes < 10)
    timevalue += "0" + minutes
  else 
    timevalue += "" + minutes;       

  fieldx.value = timevalue;
}

function VDate(fieldx,title,dateformat){
  var TheValue,dateString,dateString1,error="";
  TheValue = fieldx.value;
  if (fieldx.value!="")
  {
    if (TheValue.charAt(1)=='/')
    {
      var correctdate;
      correctdate = '0' + TheValue.substring(0,1) + TheValue.substring(1,(TheValue.length));
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (TheValue.charAt(4)=='/')
    {
      var correctdate;
      correctdate = TheValue.substring(0,3) + '0' + TheValue.substring(3,9);
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (TheValue.charAt((TheValue.length-3))=='/')
    {
      var correctdate;
      correctdate = TheValue.substring(0,(TheValue.length-2)) + '20' + TheValue.substring((TheValue.length-2),(TheValue.length));
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (dateformat=="mm/dd/yyyy"){
      if (TheValue.charAt(2)!='/' || TheValue.charAt(5)!='/' || TheValue.length != 10 || parseFloat(TheValue.substring(0,2))>12 || parseFloat(TheValue.substring(3,5))==0 || parseFloat(TheValue.substring(0,2))==0 ||
      ((TheValue.indexOf('01/')==0 || TheValue.indexOf('03/')==0 || TheValue.indexOf('05/')==0 || TheValue.indexOf('07/')==0 || 
      TheValue.indexOf('08/')==0 || TheValue.indexOf('11/')==0 || TheValue.indexOf('12/')==0) && parseFloat(TheValue.substring(3,5)) > 31) || 
      ((TheValue.indexOf('04/')==0 || TheValue.indexOf('06/')==0 || TheValue.indexOf('09/')==0 || TheValue.indexOf('11/')==0 ) && parseFloat(TheValue.substring(3,5)) > 30) || 
      ((TheValue.indexOf('02/')==0) && TheValue.substring(6,10)%4==0 && parseFloat(TheValue.substring(3,5)) > 29) || 
      ((TheValue.indexOf('02/')==0) && TheValue.substring(6,10)%4!=0 && parseFloat(TheValue.substring(3,5)) > 28)){
        error = title + " contains invalid date format.";
      }
    }else{
      if (TheValue.charAt(2)!='/' || TheValue.charAt(5)!='/' || TheValue.length != 10 || parseFloat(TheValue.substring(3,5))>12 || parseFloat(TheValue.substring(0,2))==0 || parseFloat(TheValue.substring(3,5))==0 ||
      ((TheValue.indexOf('01/')==3 || TheValue.indexOf('03/')==3 || TheValue.indexOf('05/')==3 || TheValue.indexOf('07/')==3 || 
      TheValue.indexOf('08/')==3 || TheValue.indexOf('11/')==3 || TheValue.indexOf('12/')==3) && parseFloat(TheValue.substring(0,2)) > 31) || 
      ((TheValue.indexOf('04/')==3 || TheValue.indexOf('06/')==3 || TheValue.indexOf('09/')==3 || TheValue.indexOf('11/')==3 ) && parseFloat(TheValue.substring(0,2)) > 30) || 
      ((TheValue.indexOf('02/')==3) && TheValue.substring(6,10)%4==0 && parseFloat(TheValue.substring(0,2)) > 29) || 
      ((TheValue.indexOf('02/')==3) && TheValue.substring(6,10)%4!=0 && parseFloat(TheValue.substring(0,2)) > 28)){
        error = title + " contains invalid date format.";
      }
    } 
    if (error){
      alert(error);
      fieldx.value="";
      fieldx.focus();
    }
  }
}

function VRequestDate(fieldx,title,datetype,dateformat){
  var TheValue,dateString,dateString1,error="";
  TheValue = fieldx.value;
  if (fieldx.value!="")
  {
    if (TheValue.charAt(1)=='/')
    {
      var correctdate;
      correctdate = '0' + TheValue.substring(0,1) + TheValue.substring(1,(TheValue.length));
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (TheValue.charAt(4)=='/')
    {
      var correctdate;
      correctdate = TheValue.substring(0,3) + '0' + TheValue.substring(3,9);
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (TheValue.charAt((TheValue.length-3))=='/')
    {
      var correctdate;
      correctdate = TheValue.substring(0,(TheValue.length-2)) + '20' + TheValue.substring((TheValue.length-2),(TheValue.length));
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (dateformat=="mm/dd/yyyy"){ 
      if (TheValue.charAt(2)!='/' || TheValue.charAt(5)!='/' || TheValue.length != 10 || parseFloat(TheValue.substring(0,2))>12 || parseFloat(TheValue.substring(3,5))==0 || parseFloat(TheValue.substring(0,2))==0 ||
      ((TheValue.indexOf('01/')==0 || TheValue.indexOf('03/')==0 || TheValue.indexOf('05/')==0 || TheValue.indexOf('07/')==0 || 
      TheValue.indexOf('08/')==0 || TheValue.indexOf('11/')==0 || TheValue.indexOf('12/')==0) && parseFloat(TheValue.substring(3,5)) > 31) || 
      ((TheValue.indexOf('04/')==0 || TheValue.indexOf('06/')==0 || TheValue.indexOf('09/')==0 || TheValue.indexOf('11/')==0 ) && parseFloat(TheValue.substring(3,5)) > 30) || 
      ((TheValue.indexOf('02/')==0) && TheValue.substring(6,10)%4==0 && parseFloat(TheValue.substring(3,5)) > 29) || 
      ((TheValue.indexOf('02/')==0) && TheValue.substring(6,10)%4!=0 && parseFloat(TheValue.substring(3,5)) > 28)){
        error = title + " contains invalid date format.";
      }
      else {
        dateString=fieldx.value;
        var date = new Date(dateString.substring(6,10),dateString.substring(0,2)-1,dateString.substring(3,5));
        var now = new Date();
        var today = new Date(now.getYear(),now.getMonth(),now.getDate());  
        if (datetype==1){      
          if (date<today)
            error="Closing Date should not be earlier than Request Date";
        }    
        else{
          if (date<today)
            error="Item Required Date should not be earlier than Request Date";
        }
      }
    }
    else{
      if (TheValue.charAt(2)!='/' || TheValue.charAt(5)!='/' || TheValue.length != 10 || parseFloat(TheValue.substring(3,5))>12 || parseFloat(TheValue.substring(3,5))==0 || parseFloat(TheValue.substring(0,2))==0 ||
      ((TheValue.indexOf('01/')==3 || TheValue.indexOf('03/')==3 || TheValue.indexOf('05/')==3 || TheValue.indexOf('07/')==3 || 
      TheValue.indexOf('08/')==3 || TheValue.indexOf('11/')==3 || TheValue.indexOf('12/')==3) && parseFloat(TheValue.substring(0,2)) > 31) || 
      ((TheValue.indexOf('04/')==3 || TheValue.indexOf('06/')==3 || TheValue.indexOf('09/')==3 || TheValue.indexOf('11/')==3 ) && parseFloat(TheValue.substring(0,2)) > 30) || 
      ((TheValue.indexOf('02/')==3) && TheValue.substring(6,10)%4==0 && parseFloat(TheValue.substring(0,2)) > 29) || 
      ((TheValue.indexOf('02/')==3) && TheValue.substring(6,10)%4!=0 && parseFloat(TheValue.substring(0,2)) > 28)){
        error = title + " contains invalid date format.";
      }
      else {
        dateString=fieldx.value;
        var date = new Date(dateString.substring(6,10),dateString.substring(3,5)-1,dateString.substring(0,2));
        var now = new Date();
        var today = new Date(now.getYear(),now.getMonth(),now.getDate());  
        if (datetype==1){      
          if (date<today)
            error="Closing Date should not be earlier than Request Date";
        }    
        else{
          if (date<today)
            error="Item Required Date should not be earlier than Request Date";
        }
      }
    }
    if (error){
      alert(error);
      fieldx.value="";
      fieldx.focus();
    }
  }
}


function VEmail(fieldx,title){
  var atPos;
  if (fieldx.value!=""){
    TheValue = fieldx.value;
    atPos = TheValue.indexOf('@');
    if (atPos <1 || atPos == (TheValue.length - 1)){
      alert(title+" must contain valid email format.");
      fieldx.value="";
      fieldx.focus();
    }      
  } 
}

function VMEmail(fieldx,title){
  var atPos;
  if (fieldx.value!=""){
    TheValue = fieldx.value;
    atPos = TheValue.indexOf('@');
    if (atPos <1 || atPos == (TheValue.length - 1))
      return "- " + title +" must contain valid email format.\n";
    else
      return '';
  }
}

function VMQty(fieldx,title){
  var theNum;
  if (fieldx.value!=""){
    theNum = parseFloat(fieldx.value);
    if (fieldx.value != theNum)
      return "- " + title + " must contain a number\n";
    else{
      if (theNum<=0)
        return "- " + title + " is either blank or greater than 0\n";
      else
        return "";
    }
  }
}



function VMDate(fieldx,title,dateformat){
  var TheValue,dateString,dateString1,error="";
  TheValue = fieldx.value;
  if (fieldx.value!="")
  {
    if (TheValue.charAt(1)=='/')
    {
      var correctdate;
      correctdate = '0' + TheValue.substring(0,1) + TheValue.substring(1,(TheValue.length));
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (TheValue.charAt(4)=='/')
    {
      var correctdate;
      correctdate = TheValue.substring(0,3) + '0' + TheValue.substring(3,9);
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (TheValue.charAt((TheValue.length-3))=='/')
    {
      var correctdate;
      correctdate = TheValue.substring(0,(TheValue.length-2)) + '20' + TheValue.substring((TheValue.length-2),(TheValue.length));
      fieldx.value = correctdate;
      TheValue = fieldx.value;
    }
    if (dateformat=="mm/dd/yyyy"){
      if (TheValue.charAt(2)!='/' || TheValue.charAt(5)!='/' || TheValue.length != 10 || parseFloat(TheValue.substring(0,2))>12 || parseFloat(TheValue.substring(3,5))==0 || parseFloat(TheValue.substring(0,2))==0 ||
      ((TheValue.indexOf('01/')==0 || TheValue.indexOf('03/')==0 || TheValue.indexOf('05/')==0 || TheValue.indexOf('07/')==0 || 
      TheValue.indexOf('08/')==0 || TheValue.indexOf('11/')==0 || TheValue.indexOf('12/')==0) && parseFloat(TheValue.substring(3,5)) > 31) || 
      ((TheValue.indexOf('04/')==0 || TheValue.indexOf('06/')==0 || TheValue.indexOf('09/')==0 || TheValue.indexOf('11/')==0 ) && parseFloat(TheValue.substring(3,5)) > 30) || 
      ((TheValue.indexOf('02/')==0) && TheValue.substring(6,10)%4==0 && parseFloat(TheValue.substring(3,5)) > 29) || 
      ((TheValue.indexOf('02/')==0) && TheValue.substring(6,10)%4!=0 && parseFloat(TheValue.substring(3,5)) > 28)){
        error = "- " + title + " contains invalid date format.\n";
      }
    }else{
      if (TheValue.charAt(2)!='/' || TheValue.charAt(5)!='/' || TheValue.length != 10 || parseFloat(TheValue.substring(3,5))>12 || parseFloat(TheValue.substring(0,2))==0 || parseFloat(TheValue.substring(3,5))==0 ||
      ((TheValue.indexOf('01/')==3 || TheValue.indexOf('03/')==3 || TheValue.indexOf('05/')==3 || TheValue.indexOf('07/')==3 || 
      TheValue.indexOf('08/')==3 || TheValue.indexOf('11/')==3 || TheValue.indexOf('12/')==3) && parseFloat(TheValue.substring(0,2)) > 31) || 
      ((TheValue.indexOf('04/')==3 || TheValue.indexOf('06/')==3 || TheValue.indexOf('09/')==3 || TheValue.indexOf('11/')==3 ) && parseFloat(TheValue.substring(0,2)) > 30) || 
      ((TheValue.indexOf('02/')==3) && TheValue.substring(6,10)%4==0 && parseFloat(TheValue.substring(0,2)) > 29) || 
      ((TheValue.indexOf('02/')==3) && TheValue.substring(6,10)%4!=0 && parseFloat(TheValue.substring(0,2)) > 28)){
        error = "- " + title + " contains invalid date format.\n";
      }
    } 
  }
  return error;
}

function VMvalidateinteger(fieldx,title,validatetype,minimumorderqty){
  var theNum,error="";
  if (fieldx.value!=""){
    theNum = parseFloat(fieldx.value);
    if (fieldx.value != theNum)
      error = "- " + title + " must contain a number\n";
    else{
      if (validatetype==1){
        if (theNum <= 0)
          error= "- " + title + " should be greater than 0\n";
      }
      else if (validatetype==2){
        if (theNum<=0)
	  error = "- " + title + " is either blank or greater than 0\n";
        else if (minimumorderqty !=""){
          if (theNum < eval(minimumorderqty))
    	    error = "- " + "Minimum Order Qty for " + title + " is " + minimumorderqty +"\n"
        } 
      }
      else{
        if (theNum < 0)
          error = "- " + title + " should be equal or greater than 0\n";
      }
    }
    if (error !="")
      return error
    else
      return "";
  }
}

function FillInDate(fieldxyear,fieldxmonth,fieldxday,NDay) {
  var predate = new Date();
  var date = new Date(predate.getTime() + NDay * 24 * 60 * 60 * 1000);
  var d  = date.getDate();
  var day = (d <10) ? '0' + d : d;
  var m = date.getMonth() + 1;
  var month = (m <10) ? '0' + m : m;
  var yy = date.getYear();
  var year = (yy <1000) ? yy + 1900 : yy;
  fieldxyear.value = year;
  fieldxmonth.value=month;
  fieldxday.value=day;
}

function checkFloat(fieldx,title){
  var theNum,subvalue,num;
  if (fieldx.value!=""){
    theNum = parseFloat(fieldx.value);
    if (fieldx.value != theNum){ 
      alert(title + " must contain a number");
      fieldx.value="";
      fieldx.focus();
    }
    else {
      if (theNum<0){
        alert(title + " should be equal or greater than 0"); 
        fieldx.value="";
        fieldx.focus();
      }
      else{
        fieldx.value = Math.round(fieldx.value*100)/100;
        fieldx.value = roundall(fieldx.value);  
      }
    }
  }
}

function VcheckFloat(fieldx,title){
  var theNum,subvalue,num;
  if (fieldx.value!=""){
    theNum = parseFloat(fieldx.value);
    if (fieldx.value != theNum)
      return "- " + title + " must contain a number\n";
    else {
      if (theNum<0)
        return "- " + title + " should be equal or greater than 0\n"; 
      else
        return "";
    }
  }
}

function VCPrice(fieldx,title){
  var theNum,subvalue,num;
  if (fieldx.value!=""){
    theNum = parseFloat(fieldx.value);
    if (fieldx.value != theNum)
      return "- " + title + " must contain a number\n";
    else {
      if (theNum<=0)
        return "- " + title + " should be equal or greater than 0\n"; 
      else
        return "";
    }
  }
}

function roundall(sValue){
  num = sValue.indexOf('.');
  if (num==-1)
    return (sValue + ".00");
  else{
    if (sValue.charAt(num+2)=="")
      return (sValue + "0");
    else 
      return sValue;
  } 
}

function checkInt(fieldx,title){
  var theNum,subvalue,num;
  if (fieldx.value!=""){
    theNum = parseInt(fieldx.value);
    if (fieldx.value != theNum){ 
      alert(title + " must be an integer");
      fieldx.value="";
      fieldx.focus();
    }
  }
}

function VcheckInt(fieldx,title){
  var theNum,subvalue,num;
  if (fieldx.value!=""){
    theNum = parseInt(fieldx.value);
    if (fieldx.value != theNum)
      return "- " + title + " must be an integer\n";
    else
      return "";
  }
}


function verifyIntTime(fieldx,title){
  if (fieldx.value!=""){
    theValue=fieldx.value;
    if (theValue.length < 4){ 
      alert(title + " must contain 4 digit number");
      fieldx.value="";
      fieldx.focus();
    }
    else{    
      theNum = parseInt(theValue);
      if ((theValue != theNum) || (theNum <0)){ 
        alert(title + " must be a positive integer");
        fieldx.value="";
        fieldx.focus();
      }
      else{
        if ((parseInt(theValue.substring(0,2)) > 23) ||  (parseInt(theValue.substring(2,4)) > 59)){
          alert(title + " must contain valid time format (0000-2359)");
          fieldx.value="";
          fieldx.focus();
        }      
      }
    }
  }
}

function VDateRange(day1,month1,year1,day2,month2,year2){
  var error="";
  if (((month1=="04" || month1=="06" || month1=="09" || month1=="11") && day1=="31") || (year1%4==0 && month1=="02" && eval(day1)>29) || (year1%4!=0 && month1=="02" && eval(day1)>28)) 
    error += '- Invalid From Date Format.\n';
  if (((month2=="04" || month2=="06" || month2=="09" || month2=="11") && day2=="31") || (year2%4==0 && month2=="02" && eval(day2)>29) || (year2%4!=0 && month2=="02" && eval(day2)>28))
    error += '- Invalid To Date Format.\n';
  if (error){ 
    alert('The following error(s) occurred:\n'+error);  
    return false;  
  }
  else
    return;
}

function upperC(fieldx){
  if (fieldx.value!="")
    fieldx.value = fieldx.value.toUpperCase()
}

function listdate() {
  var date = new Date();
  var d  = date.getDate();
  var day = (d <10) ? '0' + d : d;
  var m = date.getMonth() + 1;
  var month = (m <10) ? '0' + m : m;
  var yy = date.getYear();
  var year = (yy <1000) ? yy + 1900 : yy;
  return year+""+month+""+day;
}

function toggle(theDiv,state){
     var obj = getBrowserType(theDiv);
     if(obj){
          obj.visibility = state;
     } else {
          return false;
     }
}

function getBrowserType(theDiv){
     if(document.getElementById){ // DOM
          return document.getElementById(theDiv).style;
     } else if(document.all){ // IE4
          return document.all(theDiv).style;
     } else if(document.layers){ // NS4
          return document.layers[theDiv];
     } else {
          return false; //No browser supported
     }
}

function makeArray() {
     for (i = 0; i<makeArray.arguments.length; i++)
          this[i + 1] = makeArray.arguments[i];
}

function getmonthdate(NDay){
var months = new makeArray('Jan','Feb','Mar',
    'Apr','May','Jun','Jul','Aug','Sep',
    'Oct','Nov','Dec');

var daysofweek = new makeArray('Sun',
                               'Mon',
                               'Tue',
                               'Wed',
                               'Thu',
                               'Fri',
                               'Sat');



var predate = new Date();
var date = new Date(predate.getTime() + NDay * 24 * 60 * 60 * 1000); 
var d  = date.getDate();
var day = (d <10) ? '0' + d : d;
var month = date.getMonth() + 1;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
 return daysofweek[DayOfWeek(d,month,year)] + " " + day + "-" + months[month] + "-" + year;
}

function DayOfWeek(day,month,year) {
    var a = Math.floor((14 - month)/12);
    var y = year - a;
    var m = month + 12*a - 2;
    var d = (day + y + Math.floor(y/4) - Math.floor(y/100) +
             Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
    return d + 1;
}

function getwholeweek(oList,datevalue,datestring){
  var i,datestr;
  if (datevalue!=""){
    var pickupdate = new Date(datestring.substring(6,10),datestring.substring(0,2)-1,datestring.substring(3,5));
    var now = new Date();
    var today = new Date(now.getYear(),now.getMonth(),now.getDate());  
    if (pickupdate<today)
      oList.options[oList.options.length] = new Option(datevalue,datevalue);
  }
  for (i=0;i<=6;i++){
    datestr = getmonthdate(i);
    oList.options[oList.options.length] = new Option(datestr,datestr);    
    if (datevalue==datestr)
      oList.selectedIndex = oList.options.length -1;      
  }
}

function VSearch(fieldx){
  var filter = /^([a-zA-Z0-9])+$/;
  var xName=fieldx.value;
  if (xName==""){
    alert("You have to enter keyword for searching");
    fieldx.focus();
    return false;
  }
  else{
    i=0;
    while (i <= xName.length - 1)
    {
      if (xName.charAt(i)== " "){
        x1=xName.substr(0,i);
        x2=xName.substr(i+1, xName.length-i-1);
        xName=x1+x2;
      } 
      else {
        i++;
      }
    }
    if ( ! filter.test(xName)) {
      alert('Only the letters A-Z, a-z, 0-9 are allowed for searching.');
      return false;
    }
    else
      return true;
  }
}

function VSearchP(fieldx){
  var xName=fieldx.value;
  if (xName==""){
    alert("You have to enter keyword for searching");
    fieldx.focus();
    return false;
  }
  else{
    return true;
  }
}

function VQty(fieldx,title){
  var theNum;
  if (fieldx.value!=""){
    theNum = parseFloat(fieldx.value);
    if (fieldx.value != theNum){ 
      alert(title + " must contain a number");
      fieldx.value="";
      fieldx.focus();
    }
    else{
      if (theNum<=0){
        alert(title + " is either blank or greater than 0");
        fieldx.value="";
        fieldx.focus(); 
      }
      else{ 
        fieldx.value = Math.round(fieldx.value*100)/100;
        fieldx.value = roundall(fieldx.value);
      }
    }
  }
}


function VDisplayOrder(fieldx){
  var theNum;
  if (fieldx.value!=""){
    theNum = parseInt(fieldx.value);
    if (fieldx.value != theNum){ 
      alert("Display Order must contain a integer number to indicate the priority in displaying order.");
      fieldx.value="";
      fieldx.focus();
    }    
  }
}

function VMDisplayOrder(fieldx,title){
  var theNum;
  theNum = parseInt(fieldx.value);
  if (fieldx.value != theNum){
    if (title!="") 
      return "- " + "Display Order " + title + " must contain a integer number to indicate the priority in displaying order.\n"
    else
      return "- " + "Display Order must contain a integer number to indicate the priority in displaying order.\n"   
  }
  else
    return "";     
}

function restorecolor(oList,dcolor,fieldx){
  var rfound=false;
  oList.selectedIndex = 0;
  fieldx.value="";
  for (var i = oList.options.length - 1; i >= 0; i--){
    longstr = oList.options[i].value;
    if (longstr == dcolor){
      oList.selectedIndex = i;
      rfound = true;
      break;
    }
  }
  if (rfound == false)
    fieldx.value = dcolor;   
}


function validateinteger(fieldx,title,validatetype,gotloadvalue,loadvalue,minimumorderqty){
  var theNum,error;
  if (fieldx.value!=""){
    theNum = parseFloat(fieldx.value);
    if (fieldx.value != theNum){ 
      alert(title + " must contain a number");
      fieldx.value="";
      fieldx.focus();
    }
    else{
      if (validatetype==1){
        if (gotloadvalue=='T')
        {
          if (loadvalue==""){
            if (theNum <= 0){
              alert(title + " should be greater than 0");
              error=true;
            } 
          }
        }
        else{
          if (theNum <= 0){
            alert(title + " should be greater than 0");
            error=true;
          } 
        }
      }
      else if (validatetype==2){
        if (theNum<=0){
	  alert(title + " is either blank or greater than 0");
    	  if ((minimumorderqty!="") && (minimumorderqty!="0.00"))
      	    fieldx.value=minimumorderqty
    	  else
      	    error = true;
          //alert('hi');
        }
        else if ((theNum < eval(minimumorderqty)) && (minimumorderqty!=""))
  	{
    	  alert("Minimum Order Qty for " + title + " is " + minimumorderqty);
    	  fieldx.value=minimumorderqty;
        }  
      }
      else{
        if (theNum < 0){
          alert(title + " should be equal or greater than 0");
          error=true;
        }
      }
      if (error){
        fieldx.value="";
        fieldx.focus(); 
      }
      else{
        fieldx.value = Math.round(fieldx.value*100)/100;
        fieldx.value = roundall(fieldx.value);  
      }
    }
  }
}


function VSQPrice(gotCBox,fieldprice,totalvalue,qtyvalue,taxvalue,discountvalue,gotloadvalue,loadvalue,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal){
 
  validateinteger(fieldprice,'U.Price',1,gotloadvalue,loadvalue,'');

  fieldx = eval(totalvalue);
  if (fieldprice.value != "")
  {
    if (qtyvalue=="")
      fieldx.value = fieldprice.value;
    else
      fieldx.value = (qtyvalue) * fieldprice.value; 
    if (taxvalue!="")
      fieldx.value = fieldx.value * (1 + taxvalue/100);
    if (discountvalue!="")
      fieldx.value = fieldx.value * (1 - discountvalue/100);
  }
  else   
    fieldx.value = fieldprice.value;
  if (fieldx.value!=""){
    fieldx.value = Math.round(fieldx.value*100)/100 ;
    fieldx.value = roundall(fieldx.value);
  }
  if (gotCBox == 'X')  
    getEntireOverall(startitemno,enditemno,formname)
  else
    getOverall(gotCBox,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal);
}


function VSQQty(gotCBox,pricevalue,totalvalue,fieldqty,taxvalue,discountvalue,minimumorderqty,gotloadvalue,loadvalue,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal){
  validateinteger(fieldqty,'Qty',2,gotloadvalue,loadvalue,minimumorderqty);
  fieldx = eval(totalvalue);
  if (fieldqty.value != "")
  {
    if (pricevalue=="")
      fieldx.value=pricevalue;   
    else
      fieldx.value = (fieldqty.value) * pricevalue; 
  }
  else
    fieldx.value = pricevalue;
  
  if (fieldx.value!="")
  {
    if (taxvalue!="")
      fieldx.value = fieldx.value * (1 + taxvalue/100);
    if (discountvalue!="")
      fieldx.value = fieldx.value * (1 - discountvalue/100);
    fieldx.value = Math.round(fieldx.value*100)/100 ;
    fieldx.value = roundall(fieldx.value);
  } 
  if (gotCBox == 'X')  
    getEntireOverall(startitemno,enditemno,formname)
  else 
    getOverall(gotCBox,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal);
}


function VSQTax(gotCBox,pricevalue,totalvalue,qtyvalue,fieldtax,discountvalue,gotloadvalue,loadvalue,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal){
  validateinteger(fieldtax,'Tax',3,gotloadvalue,loadvalue,'');
  fieldx = eval(totalvalue);
  if (fieldtax.value != "")
  {
    if (pricevalue=="")
      fieldx.value=pricevalue;
    else 
      fieldx.value = pricevalue * (1 + fieldtax.value/100);
  }
  else
    fieldx.value = pricevalue;
  if (fieldx.value!=""){
    if (qtyvalue!="")
      fieldx.value = fieldx.value * qtyvalue;
    if (discountvalue!="")
      fieldx.value = fieldx.value * (1 - discountvalue/100);
    fieldx.value = Math.round(fieldx.value*100)/100 ;
    fieldx.value = roundall(fieldx.value);
  }
  if (gotCBox == 'X')  
    getEntireOverall(startitemno,enditemno,formname)
  else
    getOverall(gotCBox,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal);
}


function VSQDisc(gotCBox,pricevalue,totalvalue,qtyvalue,taxvalue,fielddiscount,gotloadvalue,loadvalue,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal){
  validateinteger(fielddiscount,'Discount',3,gotloadvalue,loadvalue,'');
  
  fieldx = eval(totalvalue);
  fieldx.value = pricevalue;
  if (fieldx.value!=""){
    if (qtyvalue!="")
      fieldx.value = fieldx.value * qtyvalue;
    if (taxvalue!="")
      fieldx.value = fieldx.value * (1 + taxvalue/100);
    if (fielddiscount.value!="")
      fieldx.value = fieldx.value * (1 - fielddiscount.value/100);
    fieldx.value = Math.round(fieldx.value*100)/100 ;
    fieldx.value = roundall(fieldx.value);
  }
  if (gotCBox == 'X')  
    getEntireOverall(startitemno,enditemno,formname)
  else
    getOverall(gotCBox,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal);
}

function VSQGST(fieldgst,subtotalvalue,shippingvalue,globaldiscountvalue,gotloadvalue,loadvalue,fieldgtotal){

  validateinteger(fieldgst,'Whole Tax',3,gotloadvalue,loadvalue,'');

  fieldgtotal.value = subtotalvalue;
  if (fieldgtotal.value!="")
  {
    if (globaldiscountvalue!="")
      fieldgtotal.value = fieldgtotal.value * (1 - globaldiscountvalue/100);
    if (fieldgst.value!="")
      fieldgtotal.value = fieldgtotal.value * (1 + fieldgst.value/100);
    if (shippingvalue!="")
      fieldgtotal.value = eval(fieldgtotal.value) + eval(shippingvalue);  
    fieldgtotal.value = Math.round(fieldgtotal.value*100)/100 ;
    fieldgtotal.value = roundall(fieldgtotal.value);
  }
}

function VSQShipping(fieldshipping,subtotalvalue,gstvalue,globaldiscountvalue,gotloadvalue,loadvalue,fieldgtotal){
  
  validateinteger(fieldshipping,'Shipping Cost',3,gotloadvalue,loadvalue,'');

  fieldgtotal.value = subtotalvalue;
  if (fieldgtotal.value!="")
  {
    if (globaldiscountvalue!="")
      fieldgtotal.value = fieldgtotal.value * (1 - globaldiscountvalue/100);
    if (gstvalue!="")
      fieldgtotal.value = fieldgtotal.value * (1 + gstvalue/100);
    if (fieldshipping.value!="")
      fieldgtotal.value = eval(fieldgtotal.value) + eval(fieldshipping.value);  
    fieldgtotal.value = Math.round(fieldgtotal.value*100)/100 ;
    fieldgtotal.value = roundall(fieldgtotal.value);
  }
}

function VSQGDisc(fieldglobaldiscount,subtotalvalue,gstvalue,shippingvalue,gotloadvalue,loadvalue,fieldgtotal){

  validateinteger(fieldglobaldiscount,'Global Discount',3,gotloadvalue,loadvalue,'');
  
  fieldgtotal.value = subtotalvalue;
  if (fieldgtotal.value!="")
  {
    if (fieldglobaldiscount.value!="")
      fieldgtotal.value = fieldgtotal.value * (1 - fieldglobaldiscount.value/100);
    if (gstvalue!="")
      fieldgtotal.value = fieldgtotal.value * (1 + gstvalue/100);
    if (shippingvalue!="")
      fieldgtotal.value = eval(fieldgtotal.value) + eval(shippingvalue);  
    fieldgtotal.value = Math.round(fieldgtotal.value*100)/100 ;
    fieldgtotal.value = roundall(fieldgtotal.value);
  }
}


function getOverall(gotCBox,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal)
{
  var subtotal,startitemno,enditemno,i,j,subvalue;
  subtotal = 0;
  for (var i = startitemno; i <= enditemno; i++){
    fieldx1 = eval('document.'+ formname + '.numrecord_' + i)
    j = fieldx1.value; 
    fieldx1 = eval('document.'+ formname + '.total_' + j);
    if (gotCBox=='T'){
      fieldx2 = eval('document.'+ formname +'.selecteditem_' + j);
      if ((fieldx1.value!="") && (fieldx2.checked))
        subtotal = subtotal + eval(fieldx1.value);
    }    
    else{
      if (fieldx1.value!="")
        subtotal = subtotal + eval(fieldx1.value);
    }
  }
  if (fieldoldsubtotal!='null'){
    if (fieldoldsubtotal.value !="")
      subtotal = subtotal + eval(fieldoldsubtotal.value);
  }
  fieldsubtotal.value = Math.round(subtotal*100)/100 ;  
  fieldsubtotal.value = roundall(fieldsubtotal.value); 
  if ((fieldsubtotal.value!="0.00") && (fieldsubtotal.value!="")){  
    if (fieldgdiscount.value!="")
      fieldgtotal.value = fieldsubtotal.value * ( 1 - fieldgdiscount.value/100); 
    else 
      fieldgtotal.value = fieldsubtotal.value;
    if (fieldshipping.value!="")
      fieldgtotal.value = eval(fieldgtotal.value * (1 + fieldgst.value/100)) + eval(fieldshipping.value); 
    else 
      fieldgtotal.value = fieldgtotal.value * (1 + fieldgst.value/100); 
    fieldgtotal.value = Math.round(fieldgtotal.value*100)/100 ;   
    fieldgtotal.value = roundall(fieldgtotal.value);  
  }
  else {
    fieldgtotal.value="";
    fieldsubtotal.value="";
  }
}





function getEntireOverall(startitemno,enditemno,formname)
{
  var subtotal,startitemno,enditemno,i,j,subvalue,vendorid, tmp;
  subtotal = 0;
  vendorCnt=0;
  vendorid = eval('document.'+formname+'.vendorid_'+1);
  fieldx1 = eval('document.'+formname+'.total_' + 1);
          
  if (fieldx1.value!="")
    subtotal = eval(fieldx1.value);

  for (var i = startitemno; i <= enditemno; i++){
    tmp = eval('document.'+formname+'.vendorid_'+i);
    if (vendorid.value != tmp.value || i == enditemno) {
      if (vendorid.value != tmp.value) {              // put footer for previous trans
        vendorCnt++;
        theSubTotal=eval('document.'+formname+'.subtotal_'+vendorCnt);
        theGlobalDisc = eval('document.'+formname+'.globaldiscount_'+ vendorCnt);
        theGrandTotal = eval('document.'+formname+'.grandtotal_'+vendorCnt);
        theShipping = eval('document.'+formname+'.shipping_'+ vendorCnt);
        theGst = eval('document.'+formname+'.gst_'+ vendorCnt);
        theSubTotal.value = Math.round(subtotal*100)/100 ;
        theSubTotal.value = roundall(theSubTotal.value);
        if ((theSubTotal.value != "0.00") && (theSubTotal.value != "")) {
          if (theGlobalDisc.value !="")
            theGrandTotal.value = theSubTotal.value * ( 1 - theGlobalDisc.value/100);
          else
             theGrandTotal.value = theSubTotal.value;

          if (theShipping.value != "")
            theGrandTotal.value = eval(theGrandTotal.value * ( 1 +  theGst.value/100)) + eval(theShipping.value);
          else
             theGrandTotal.value = theGrandTotal.value * ( 1 + theGst.value/100);

          theGrandTotal.value = Math.round(theGrandTotal.value * 100)/100;
          theGrandTotal.value = roundall(theGrandTotal.value);
        }
        else
        {  // end if subtotal = ""
          theGrandTotal.value = "";
          theSubTotal.value = "";
        }
        fieldx1 = eval('document.'+formname+'.total_' + i);

        if (fieldx1.value!="" && i != enditemno){
          subtotal = eval(fieldx1.value);
        }else
          subtotal = 0;

        vendorid = eval('document.'+formname+'.vendorid_'+i);
      }  // end if vendorid <> tmpID

      if (i == enditemno) {
        if ( i != 1) {
          fieldx1 = eval('document.'+formname+'.total_' + i);
          if (fieldx1.value!="")
            subtotal = subtotal + eval(fieldx1.value);
        }

        vendorid = eval('document.'+formname+'.vendorid_' + i);
        vendorCnt++;

        theSubTotal=eval('document.'+formname+'.subtotal_'+vendorCnt);
        theGlobalDisc = eval('document.'+formname+'.globaldiscount_'+ vendorCnt);
        theGrandTotal = eval('document.'+formname+'.grandtotal_'+vendorCnt);
        theShipping = eval('document.'+formname+'.shipping_'+ vendorCnt);
        theGst = eval('document.'+formname+'.gst_'+ vendorCnt);

        theSubTotal.value = Math.round(subtotal*100)/100 ;
        theSubTotal.value = roundall(theSubTotal.value);

        if ((theSubTotal.value != "0.00") && (theSubTotal.value != "")) {
          if (theGlobalDisc.value !="")
            theGrandTotal.value = theSubTotal.value * ( 1 - theGlobalDisc.value/100);
          else
             theGrandTotal.value = theSubTotal.value;

          if (theShipping.value != "")
            theGrandTotal.value = eval(theGrandTotal.value * ( 1 +  theGst.value/100)) + eval(theShipping.value);
          else
             theGrandTotal.value = theGrandTotal.value * ( 1 + theGst.value/100);

          theGrandTotal.value = Math.round(theGrandTotal.value * 100)/100;
          theGrandTotal.value = roundall(theGrandTotal.value);
        }
        else
        {  // end if subtotal = ""
          theGrandTotal.value = "";
          theSubTotal.value = "";
        }
      }
    }   // end if vendorid <> tmpid or i = enditemno
    else
    {
      if (i != 1) {
        fieldx1 = eval('document.'+formname+'.total_' + i);
        if (fieldx1.value!="")
          subtotal = subtotal + eval(fieldx1.value);

      }
    }
  }
}


function SQClearItem(gotCBox,itemno,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal,fieldoldshipping)
{
  fieldx1 = eval('document.'+formname+'.categoryname_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
  fieldx1 = eval('document.'+formname+'.brand_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1 = eval('document.'+formname+'.modelno_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
  
  fieldx1 = eval('document.'+formname+'.partno_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1 = eval('document.'+formname+'.description_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1 = eval('document.'+formname+'.extendeddescription_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1 = eval('document.'+formname+'.qty_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1 = eval('document.'+formname+'.unit_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1 = eval('document.'+formname+'.unitprice_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1= eval('document.'+formname+'.total_'+itemno);  
  if (fieldx1!=null)
    fieldx1.value = "";
      
  fieldx1= eval('document.'+formname+'.includetax_'+itemno);    
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1= eval('document.'+formname+'.categoryid_'+itemno);  
  if (fieldx1!=null)
    fieldx1.value = "";

  fieldx1= eval('document.'+formname+'.productid_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
    
  fieldx1= eval('document.'+formname+'.discount_'+itemno);
  if (fieldx1!=null)
    fieldx1.value = "";
  
  fieldx1= eval('document.'+formname+'.shippingcost_'+itemno);
  if (fieldx1!=null){
    if (fieldx1.value!=""){
      fieldx1.value="";
      SQSumAllShipping(startitemno,enditemno,formname,fieldshipping,fieldoldshipping);
    }
  }
  getOverall(gotCBox,startitemno,enditemno,formname,fieldsubtotal,fieldgdiscount,fieldgst,fieldshipping,fieldgtotal,fieldoldsubtotal);
}


function SQSumAllShipping(startitemno,enditemno,formname,fieldshipping,fieldoldshipping){
  var j,fieldx1,allship=0,noship=0;
  for (var i = startitemno; i <= enditemno; i++){
    fieldx1 = eval('document.'+formname+'.numrecord_' + i)
    j = fieldx1.value; 
    fieldx1 = eval('document.'+formname+'.shippingcost_' + j)
    if (fieldx1.value!="")
      allship=allship+eval(fieldx1.value);
    else
      noship++;
  }
  if (noship!=(enditemno-startitemno+1)){
    if (fieldoldshipping.value!="")
      fieldshipping.value=eval(fieldoldshipping.value)+allship
    else
      fieldshipping.value=allship 
    fieldshipping.value=Math.round(fieldshipping.value*100)/100;
    fieldshipping.value = roundall(fieldshipping.value);

  }else{
    fieldshipping.value=fieldoldshipping.value;
  }
}


function SQVSubmit(startitemno,enditemno,formname)
{
  var i,j,fieldx,fieldx1,error="";

  fieldx = eval('document.'+formname+'.deliveryday');
  if (fieldx !=null){
    if (fieldx.value!="")
      error+= VcheckInt(fieldx,'Delivery Days') 
  }

  for (i=startitemno;i<=enditemno;i++){
    fieldx1 = eval('document.'+formname+'.numrecord_' + i)
    j = fieldx1.value; 
    fieldx = eval('document.'+formname+'.qty_'+j);
    if (fieldx.value!=""){
      fieldx1 = eval('document.'+formname+'.minimumorderqty_'+j);
      error+= VMvalidateinteger(fieldx,'Qty '+j,2,fieldx1.value);
    }

    fieldx = eval('document.'+formname+'.unitprice_'+j);
    if (fieldx.value!="")
      error+= VMvalidateinteger(fieldx,'U.Price '+j,1,'');
      
    fieldx = eval('document.'+formname+'.discount_'+j);
    if (fieldx.value!="")
      error+= VMvalidateinteger(fieldx,'Disc '+j,3,'');

    fieldx = eval('document.'+formname+'.includetax_'+j);
    if (fieldx.value!="")
      error+= VMvalidateinteger(fieldx,'Tax '+j,3,'');
  }

  fieldx = eval('document.'+formname+'.globaldiscount');
  if (fieldx.value!="")
    error+= VMvalidateinteger(fieldx,'Global Discount',3,'');
  
  fieldx = eval('document.'+formname+'.gst');
  if (fieldx.value!="")
    error+= VMvalidateinteger(fieldx,'Other Tax',3,'');

  fieldx = eval('document.'+formname+'.shipping');
  if (fieldx.value!="")
    error+= VMvalidateinteger(fieldx,'Shipping Cost',3,'');

  return error;

}
