﻿//Validate controls

function ValidateInfo(hdnTotalPayment,txtname,ddltype,txtccno,txtcvv,ddlmonth,ddlyear,ddlPeriod)
//,txtamt)hdnTotalPayment,
{
//    if(document.getElementById(txtamt).value=="")
//    {
//        alert('Please Enter Pay Amount')
//        return false;
//    }
    
    function isDigits(argvalue)
    {
    argvalue = argvalue.toString();
    var validChars = "0123456789.";
    if (argvalue.substring(0, 2) == "0x") {
    validChars = "0123456789abcdefABCDEF";
    startFrom = 2;
    } else if (argvalue.charAt(0) == "0") {
    validChars = "01234567.";
    startFrom = 1;
    }
    for (var n = 0; n < argvalue.length; n++) {
    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
    }
    return true;
    }
    ///////////////////////////////////
//    if(isDigits(document.getElementById(txtamt).value)==false)
//    {
//    alert("Amount Must be a Numeric Value.")
//    document.getElementById(txtamt).focus();
//    return false;
//    }
     if( document.getElementById(ddlPeriod).selectedIndex==0)
    {
        alert('Please Select no of Months')
        return false; 
    }
     if(document.getElementById(hdnTotalPayment).value=="")
    {   
        alert("Enter Amount")
        return false; 
    }
     if(document.getElementById(hdnTotalPayment).value=="0")
    {
    alert("Please Enter The Amount Greater Than 0")
    return false;
    }
    else
    {
     if(isDigits(document.getElementById(hdnTotalPayment).value)==false)
    {
    alert("Please Enter the  Valid Amount.")
    document.getElementById(hdnTotalPayment).focus();
    return false;
    }
    }
    if(document.getElementById(txtname).value=="")
    {
        alert('Please Enter Credit Card Name')
        return false;
    }
    if( document.getElementById(ddltype).selectedIndex==0)
    {
        alert('Please Select Card Type')
        return false; 
    }
     if(document.getElementById(txtccno).value=="")
    {
        alert('Please Enter Card Number')
        return false;
    }
   
    if(isDigits(document.getElementById(txtccno).value)==false)
    {
    alert("Credit Card No Must be a Numeric Value.")
    document.getElementById(txtccno).focus();
    return false;
    }
     if(document.getElementById(txtcvv).value=="")
    {
        alert('Please Enter Security code')
        return false;
    }
    if(isDigits(document.getElementById(txtcvv).value)==false)
    {
    alert("Security Code Must be a Numeric Value.")
    document.getElementById(txtcvv).focus();
    return false;
    }
    if( document.getElementById(ddlmonth).selectedIndex==0)
    {
        alert('Please Select Expiry date of  Month')
        return false; 
    }
    
      if( document.getElementById(ddlyear).selectedIndex==0)
    {
        alert('Please Select Expiry date of Year')
        return false; 
    }
    if(document.getElementById(txtccno).value.length<15)
    {
        alert('Please Enter  Valid Credit Card no');
        return false; 
    }
}

//////Script for Credit Card Number and Type 
 function CreditCardValidation(ddlctype,txt,cvvtxt)
 {
 if(document.getElementById(ddlctype).options[document.getElementById(ddlctype).selectedIndex].text=="American Express")
{
    document.getElementById(cvvtxt).value="";
    document.getElementById(txt).value="";
   document.getElementById(txt).maxLength=15;
   document.getElementById(cvvtxt).maxLength=4;
   
}
else
{
    document.getElementById(cvvtxt).value="";
    document.getElementById(txt).value="";
    document.getElementById(txt).maxLength=16;
    document.getElementById(cvvtxt).maxLength=3;
}
 
 }

function ReplaceAddress(chkSameAs,txtfname,txtbfname,txtlname,txtblname,txtblname,txtbCity,DDlState,DdlBState,txtcadd1,txtbadd1,txtcZip,txtbZip,txtcAdd2,txtbAdd2,txtcCompany,txtbcompany,txtmname,txtbmname)
{
    if(document.getElementById(chkSameAs).checked=true)
    {
        document.getElementById(txtbfname).value=document.getElementById(txtbfname).value;
        document.getElementById(txtblname).value=document.getElementById(txtlname).value;
        document.getElementById(txtbCity).value=document.getElementById(txtblname).value;
        document.getElementById(txtbadd1).value=document.getElementById(txtcadd1).value;
        document.getElementById(txtbZip).value=document.getElementById(txtcZip).value;
        
        
    }
} 
 function YearValidation(ddlexpmnth,ddlexpyear,nowmnth,nowyear)
 {
   if(parseInt(nowyear)==parseInt(document.getElementById(ddlexpyear).options[document.getElementById(ddlexpyear).selectedIndex].text))
    {
        if(parseInt(nowmnth)<=parseInt(document.getElementById(ddlexpmnth).options[document.getElementById(ddlexpmnth).selectedIndex].value))  
        {
          return true;
        }
        else
        {
          alert("Please Enter a Valid Expiry Date");
          //document.getElementById(ddlexpmnth).index="0";
          document.getElementById(ddlexpmnth).selectedIndex = 0;
          document.getElementById(ddlexpyear).selectedIndex = 0;
          return false;
        }
    }
  else if(parseInt(nowyear)!=parseInt(document.getElementById(ddlexpyear).options[document.getElementById(ddlexpyear).selectedIndex].text))
    {
       return true;
    }
 
 }
 
 function OpenChangeLocation(AccID)
{
var LocationID=AccID;
userWidth = screen.availWidth;
var userHeight = screen.availHeight;

var popW;
var popH;
var leftPos;
var topPos;

popW = 450;
popH = 350;

settings = 'modal,scrollBars=no,resizable=no,toolbar=no,menubar=no,location=no,directories=no,';


leftPos = (userWidth - popW) / 2,
topPos = (userHeight - popH) / 2;



settings += 'left=' + leftPos + ',top=' + topPos + ',width=' + popW + ', height=' + popH + '';


window.open ('ChangeLocation.aspx?LocationID='+LocationID,'MyWindow',settings,'true');
return false;

}






function validateReg(txtaccno,txtlname,txtfname,email,amount,type,ccno,cvv,ddlmonth,ddlyear,txtname,txtAddress,txtCity,ddlState,txtZip)
{
     function isDigits(argvalue)
    {
    argvalue = argvalue.toString();
    var validChars = "0123456789.";
    if (argvalue.substring(0, 2) == "0x") {
    validChars = "0123456789abcdefABCDEF";
    startFrom = 2;
    } else if (argvalue.charAt(0) == "0") {
    validChars = "01234567.";
    startFrom = 1;
    }
    for (var n = 0; n < argvalue.length; n++) {
    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
    }
    return true;
    }

    if(document.getElementById(txtaccno).value=="")
    {
     alert('Please Enter Account No');
     return false;
    } 
    if(document.getElementById(txtlname).value=="")
    {
        alert('Please Enter Last Name');
        return false;
     
    } 
    if(document.getElementById(txtfname).value=="")
    {
      alert('Please Enter First Name');
        return false;
    } 
    
    
    if(document.getElementById(txtAddress).value=="")
    {
      alert('Please Enter Address');
        return false;
    } 
    
    if(document.getElementById(txtCity).value=="")
    {
      alert('Please Enter City');
      return false;
    } 
    
    if(document.getElementById(ddlState).selectedIndex==0)
    {
      alert('Please Enter State');
        return false;
    } 
    
    if(document.getElementById(txtZip).value=="")
    {
      alert('Please Enter Zip');
        return false;
    }    
    if(document.getElementById(email).value=="")
    {
    alert('Please Enter Email');
        return false;
    }
    if(document.getElementById(amount).value=="")
    {
      alert('Please Enter Amount');
        return false;
    }
   
    if(document.getElementById(amount).value=="0")
    {
    alert("Please Enter The Amount Greater Than 0")
    return false;
    }
//    else
//    {
//     if(isDigits(document.getElementById(amount).value)==false)
//    {
//    alert("Please Enter the  Valid Amount.")
//    document.getElementById(amount).focus();
//    return false;
//    }
//    }

     if(document.getElementById(txtname).value=="")
    {
        alert('Please Enter Name')
        return false;
    }
    if(document.getElementById(type).selectedIndex == 0)
    {
     alert('Please Select Card Type');
        return false;
    }
    
    if(document.getElementById(ccno).value=="")
    {
      alert('Please Enter Credit Card No');
        return false;
    }
    if(isDigits(document.getElementById(ccno).value)==false)
    {
    alert("Credit Card No Must be a Numeric Value.")
    document.getElementById(ccno).focus();
    return false;
    }
    
    if(document.getElementById(cvv).value=="")
    {
      alert('Please Enter Security Code');
        return false;
    }
    if(isDigits(document.getElementById(cvv).value)==false)
    {
    alert("Security Code Must be a Numeric Value.")
    document.getElementById(cvv).focus();
    return false;
    }
    
    function isDigits(argvalue)
    {
    argvalue = argvalue.toString();
    var validChars = "0123456789";
    if (argvalue.substring(0, 2) == "0x") {
    validChars = "0123456789abcdefABCDEF";
    startFrom = 2;
    } else if (argvalue.charAt(0) == "0") {
    validChars = "01234567";
    startFrom = 1;
    }
    for (var n = 0; n < argvalue.length; n++) {
    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
    }
    return true;
    }    
    
     if( document.getElementById(ddlmonth).selectedIndex==0)
    {
        alert('Please Select Expiry date of  Month')
        return false; 
    }
    
      if( document.getElementById(ddlyear).selectedIndex==0)
    {
        alert('Please Select Expiry date of Year')
        return false; 
    }
}

function ValidatePayInfo(txtname,ddltype,txtccno,txtcvv,ddlmonth,ddlyear)
//,txtamt)
{
//    if(document.getElementById(txtamt).value=="")
//    {
//        alert('Please Enter Pay Amount')
//        return false;
//    }
    
    function isDigits(argvalue)
    {
    argvalue = argvalue.toString();
    var validChars = "0123456789";
    if (argvalue.substring(0, 2) == "0x") {
    validChars = "0123456789abcdefABCDEF";
    startFrom = 2;
    } else if (argvalue.charAt(0) == "0") {
    validChars = "01234567";
    startFrom = 1;
    }
    for (var n = 0; n < argvalue.length; n++) {
    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
    }
    return true;
    }
    ///////////////////////////////////
//    if(isDigits(document.getElementById(txtamt).value)==false)
//    {
//    alert("Amount Must be a Numeric Value.")
//    document.getElementById(txtamt).focus();
//    return false;
//    }


    
    
    if(document.getElementById(txtname).value=="")
    {
        alert('Please Enter Name')
        return false;
    }
    if( document.getElementById(ddltype).selectedIndex==0)
    {
        alert('Please Select Card Type')
        return false; 
    }
     if(document.getElementById(txtccno).value=="")
    {
        alert('Please Enter Card Number')
        return false;
    }
    if(isDigits(document.getElementById(txtccno).value)==false)
    {
    alert("Credit Card No Must be a Numeric Value.")
    document.getElementById(txtccno).focus();
    return false;
    }
     if(document.getElementById(txtcvv).value=="")
    {
        alert('Please Enter Security code')
        return false;
    }
    if(isDigits(document.getElementById(txtcvv).value)==false)
    {
    alert("Security Code Must be a Numeric Value.")
    document.getElementById(txtcvv).focus();
    return false;
    }
    if( document.getElementById(ddlmonth).selectedIndex==0)
    {
        alert('Please Select Expiry date of  Month')
        return false; 
    }
    
      if( document.getElementById(ddlyear).selectedIndex==0)
    {
        alert('Please Select Expiry date of Year')
        return false; 
    }
     if(document.getElementById(txtccno).value.length<15)
    {
        alert('Please Enter  Valid Credit Card no');
        return false; 
    }
    
}
function locationRate(ddl,rate,hdnRate)
{
    if(document.getElementById(ddl).selectedIndex!=0)
    {
        document.getElementById(rate).innerHTML=document.getElementById(ddl).options[document.getElementById(ddl).selectedIndex].value;
        document.getElementById(hdnRate).value=document.getElementById(ddl).options[document.getElementById(ddl).selectedIndex].value;
        return false;
    }
    else
    {
        document.getElementById(rate).innerHTML="";
        document.getElementById(hdnRate).value="";
        return false;
    }
    
}
function CalMonthlyDues(ddl,lblDue,lblAmount,date,hdn)
{

    if(document.getElementById(ddl).selectedIndex!=0)
    {
        var flDues=parseInt(document.getElementById(ddl).options[document.getElementById(ddl).selectedIndex].value)*parseFloat(document.getElementById(lblDue).innerHTML)+parseInt(date);
        document.getElementById(hdn).value=flDues.toString();
		//alert(flDues + "        " + document.getElementById(hdn).value);
        document.getElementById(lblAmount).innerHTML = document.getElementById(hdn).value;
        document.getElementById(lblAmount).innerHTML =document.getElementById(lblAmount).innerHTML+".00"+" "+"<b>+ $1.25 Service Charge For All Credit Cards</b>" ;
        return false;
    }
    else
    {
        document.getElementById(lblAmount).innerHTML="";
        document.getElementById(hdn).value="";
        return false;
    }
    
}

 function parseCurrency(field)
      {
            var currency = /^\d*(?:\.\d{0,2})?$/;
            var onlyCurrency = /^(\d*(?:\.\d{0,2})?)[\s\S]*$/;
            
            if(!currency.test(field.value))
            {
                  field.value = field.value.replace(onlyCurrency, "$1");
            }
      }
      
      
      function moneyFormat(textObj)
       {
       
   var newValue = document.getElementById(textObj).value;
   var decAmount = "";
   var dolAmount = "";
   var decFlag = false;
   var aChar = "";
   
   // ignore all but digits and decimal points.
   for(i=0; i < newValue.length; i++) {
      aChar = newValue.substring(i,i+1);
      if(aChar >= "0" && aChar <= "9") {
         if(decFlag) {
            decAmount = "" + decAmount + aChar;
         }
         else {
            dolAmount = "" + dolAmount + aChar;
         }
      }
      if(aChar == ".") {
         if(decFlag) {
            dolAmount = "";
            break;
         }
         decFlag=true;
      }
   }
   
   // Ensure that at least a zero appears for the dollar amount.

   if(dolAmount == "") {
      dolAmount = "0";
   }
   // Strip leading zeros.
   if(dolAmount.length > 1) {
      while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
         dolAmount = dolAmount.substring(1,dolAmount.length);
      }
   }
   
   // Round the decimal amount.
   if(decAmount.length > 2) {
      if(decAmount.substring(2,3) > "4") {
         decAmount = parseInt(decAmount.substring(0,2)) + 1;
         if(decAmount < 10) {
            decAmount = "0" + decAmount;
         }
         else {
            decAmount = "" + decAmount;
         }
      }
      else {
         decAmount = decAmount.substring(0,2);
      }
      if (decAmount == 100) {
         decAmount = "00";
         dolAmount = parseInt(dolAmount) + 1;
      }
   }
   
   // Pad right side of decAmount
   if(decAmount.length == 1) {
      decAmount = decAmount + "0";
   }
   if(decAmount.length == 0) {
      decAmount = decAmount + "00";
   }
   
   // Check for negative values and reset textObj
   if(newValue.substring(0,1) != '-' ||
         (dolAmount == "0" && decAmount == "00")) {
      document.getElementById(textObj).value = dolAmount + "." + decAmount;

   }
   else{
      document.getElementById(textObj).value = '-' + dolAmount + "." + decAmount;
   }
}
function AmountisDigits(argvalue)
    {
    argvalue = argvalue.toString();
    var validChars = ".0123456789";
    if (argvalue.substring(0, 2) == "0x") {
    validChars = ".0123456789abcdefABCDEF";
    startFrom = 2;
    } else if (argvalue.charAt(0) == "0") {
    validChars = ".01234567";
    startFrom = 1;
    }
    for (var n = 0; n < argvalue.length; n++) {
    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
    }
    return true;
    }
