﻿//alert(document.referrer);
// JScript File
var errColor = "yellow"
function isIE() 
{
   // Returns True for Microsoft Internet Explorer,
   return (navigator.appName == "Microsoft Internet Explorer");
}

function getCookie(name)
{
   if (isIE()) {
      // In MSIE the cookies can only hold 4096 bytes per domain in either one or the total of
      // multiple cookies, contrasting with other RFC 2109 compliant browsers which
      // each cookie can hold up to 4096 bytes with a reocmmendation of up to 20 cookies per domain
      // This deviation with RFC2109 is explained in MS Tech Bulletin: 306070
      // For MSIE a userData store is used to persist datd simulating the action of a cookie.
      ieReturnVal = "" ;
      oData.className = "userData" ;
      oData.style.behavior = "url(#default#userData)" ;
      oData.load(name)
      ieReturnVal = oData.getAttribute("SimulatedCookie") ;
      return ( ieReturnVal ? ieReturnVal : "") ;
   }
   else {
      var cname = name + "=";
      var dc = document.cookie;
      if (dc.length > 0) {
         begin = dc.indexOf(cname);
         if (begin != -1) {
            begin += cname.length;
            end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
         }
      }
      return null;
   }
}

function setCookie(name, value, expires, path, domain, secure) 
{
   // name = name of cookie
   // value = value to store
   if (isIE()) {
      // In MSIE the cookies can only hold 4096 bytes per domain in either one or the total of
      // multiple cookies, contrasting with other RFC 2109 compliant browsers which
      // each cookie can hold up to 4096 bytes with a reocmmendation of up to 20 cookies per domain
      // This deviation with RFC2109 is explained in MS Tech Bulletin: 306070
      // For MSIE a userData store is used to persist datd simulating the action of a cookie.
      oData.className = "userData" ;
      oData.style.behavior = "url(#default#userData)" ;
      oData.setAttribute("SimulatedCookie",value) ;
      if (expires) {
         oData.expires=expires.toUTCString() ;
      }
      oData.save(name) ;
   }
   else {

      var strcookie = name + "=" + escape(value)+
              ((expires) ? "; expires=" + expires.toGMTString() : "" ) +
              ((path) ? "; path=" + path : "" ) +
              ((domain) ? "; domain=" + domain : "" ) +
              ((secure) ? "; secure" :"") ;
      document.cookie = strcookie ;
   }
}

function delCookie(name) 
{
   if (isIE()) {
      // In MSIE the cookies can only hold 4096 bytes per domain in either one or the total of
      // multiple cookies, contrasting with other RFC 2109 compliant browsers which
      // each cookie can hold up to 4096 bytes with a reocmmendation of up to 20 cookies per domain
      // This deviation with RFC2109 is explained in MS Tech Bulletin: 306070
      // For MSIE a userData store is used to persist datd simulating the action of a cookie.
      var expireNow = new Date() ;
      oData.className = "userData" ;
      oData.style.behavior = "url(#default#userData)" ;
      oData.setAttribute("SimulatedCookie","") ;
      oData.removeAttribute("SimulatedCookie") ;
      expireNow.setSeconds(expireNow.getSeconds() + 3) ;
      oData.expires=expireNow.toUTCString() ;
      oData.save(name) ;
   }
   else {

      var expireNow = new Date();
      document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" ;
   }
}

function getDate(daysoffset) 
{
   // getToday
   // returns a date object with today's date and time
   // optional daysoffset argument specifies a forward + or backwards - offset from
   // today's date eg getToday(-1) returns date object set for yesterday
   daysoffset = ((daysoffset) ? daysoffset : 0 ) ;
   var thedate = new Date();
   thedate.setTime(thedate.getTime() +  (24 * 60 * 60 * 1000 * daysoffset));
   return thedate
}

function isEmail(string)
{
   if (!string) return false;  // gotta be there
   if (string.indexOf("@",0)< 1 ) return false ;  // gotta to have an @ symbol after the 1st char
   if (string.charAt(string.length-1)=="@") return false; // Cannot be the last character 
   if (string.length<6) return false ; // got to be at least 6 chars a@b.cd

   var iChars = " \\/*|,\"<:>[]{}`\';()&$#%";  // none of these allowed
       for (var i = 0; i < string.length; i++) {
           if (iChars.indexOf(string.charAt(i)) != -1) return false;
       }
   return true;
}

function RTrim(str) 
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...
      var i = s.length - 1;       // Get length of string
      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
         // Get the substring from the front of the string to
         // where the last non-whitespace character is...
         s = s.substring(0, i+1);
      }
      return s;
}
function LTrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function XOR(bFirst,bSecond) 
{
	if (bFirst && bSecond) return false ;
   if (!bFirst && !bSecond) return false ;
   return true ;
}

function isDate(dateStr) 
{
   // returns true for a valid date in dd/mm/yyyy format
   var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
   var matchArray = dateStr.match(datePat); // is the format ok?
   var err = new Array();
   if (matchArray == null) {
       err[0] = false;
       err[1] =  "Please enter date in the dd/mm/yyyy format\n";
       return err;
//       alert("Please enter date in one of the following " +
//               "formats:\ndd/mm/yyyy or, dd-mm-yyyy");
//       return false;
   }
   day = matchArray[1]; // parse date into variables
   month = matchArray[3];
   year = matchArray[5];
   if (month < 1 || month > 12) { // check month range
       err[0] = false;
       err[1] =  "Month must be between 1 and 12.";
       return err;
//       alert("Month must be between 1 and 12.");
//       return false;
   }
   if (day < 1 || day > 31) {
       err[0] = false;
       err[1] =  "Day must be between 1 and 31.";
       return err;
//       alert("Day must be between 1 and 31.");
//       return false;
   }
   if ((month==4 || month==6 || month==9 || month==11) && day==31)
   {
       err[0] = false;
       err[1] =  "Month " + month + " doesn't have 31 days!";
       return err;
//       alert("Month " + month + " doesn't have 31 days!")
//       return false;
   }
   if (month == 2) { // check for february 29th
       var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
       if (day > 29 || (day==29 && !isleap)) {
           err[0] = false;
           err[1] =  "February " + year + " doesn't have " + day + " days!";
           return err;
//           alert("February " + year + " doesn't have " + day + " days!");
//           return false;
       }
   }
   err[0]=true;
   err[1]="";
   return err; // date is valid
}
function isCorrectAge(dt){
    var today = new Date();
    var a = dt.split("/");
    var dob = new Date(a[2],a[1]-1,a[0]);
    var yr = 1000*60*60*24*365;
    var age = Math.ceil((today.getTime() - dob.getTime())/yr);
    return (age >= 18 );
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
     window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
         oldonload();
         }
      func();
      }
  }
}
//add by Alvin terms accep check
function checkPPA()
{

var checkAPP = document.getElementById("click_Terms");
//alert(checkAPP.checked);
if (checkAPP.checked)
{
//window.open("https://www.quicken.com.au/Partners/OnlinePP2/PPApply.aspx"，"dd","width=800"); 
window.open ("https://www.quicken.com.au/Partners/OnlinePP2/PPApply.aspx","mywindow"); 
//alert("pass");
document.getElementById("errorText").style.visibility="hidden";
}
else
{
//alert('not checked');
document.getElementById("errorText").style.visibility="visible";
//alert(document.getElementById("errorText").style.visibility);
//return false;
}
}


function showHideFields(fieldID,isVisible){
//alert(fieldID);
    var fld = document.getElementById(fieldID);
//    fld.style.visibility = (isVisible)? 'visible' : 'hidden';
    fld.style.display = (isVisible)? '' : 'none';
    //fld.parentNode.style.visibility =(isVisible)? 'visible' : 'hidden';
    //alert(fieldID.style.visibility);    
}
function enableDisableField(fieldID,isEnabled){
    var fld = document.getElementById(fieldID);
    fld.disabled = isEnabled;
}
function setStateStatus(ctrlID,countryID){
//alert(stateID);
    var disabled = !(countryID == 14)
    var stateID = ctrlID+"ddl_BirthState";
    var placeID = ctrlID+"txt_BirthPlace";
    //enableDisableField("ctl00_Content_TabContainer1_memberDetails_sh_birthdetails_ddl_BirthState",disabled);
    enableDisableField(stateID,disabled);
    enableDisableField(placeID,disabled);
}
function setAddressStateStatus(stateID,countryID){
//alert(stateID);
    var disabled = !(countryID == 14)
    enableDisableField(stateID,disabled);
}
function openModalWindow(turl,arguments,pW,pH){
// args exapmle
//Dim args As String = "'status:no;dialogWidth:450px; dialogHeight:180px;dialogHide:true;help:no;scroll:no'"

    var strReturn; 
    var param;
    var coords = getScreenPosition(pW,pH);
    var args = arguments +';dialogWidth:'+ pW +'px; dialogHeight:'+ pH + 'px;left:'+coords[0]+'; top:'+coords[1]+';screenX:'+coords[0]+';screenY:'+coords[1];
    //alert(args);
    strReturn=window.showModalDialog(turl,null,args);
    return strReturn;
}
function getScreenPosition(pW,pH){
    var scrH = screen.availHeight;
    var scrW = screen.availWidth;
    //var pW = 450;
    //var pH = 200;
    var scrX = (scrW - pW - 10) * .5;
    var scrY = (scrH - pH - 30) * .5;
    var coords = new Array(scrX,scrY);
    return coords;
}
function openPayment(grpID){
//alert(document.getElementsByName(grpID).value);
    var grp = document.getElementsByName(grpID);
    //var args  = "status:no;dialogWidth:980px; dialogHeight:580px;dialogHide:true;help:no;scroll:no";
    var pMethod;
   // var onAccount = document.getElementById(fldID).checked;
    for (var i = 0; i < grp.length; i++){
        if (grp[i].checked){
            pMethod = grp[i].value;
            break;
        }
    }
    var url;
    var dt = new Date();
    var qStr = dt.getTime();
    switch (pMethod){
        case "rb_onAccount" :
            url = "submitOrder.aspx?ID="+qStr+"&PT=1";
            break;          
        case "rb_creditCard" :
            url = "https://"+document.location.host+"/ssl/payment.aspx?ID="+qStr;
//            url = "https://reckondocs.com.au/ssl/payment.aspx?ID="+qStr;
//            url = "ssl/payment.aspx?ID="+qStr;
            break;
        case "rb_OfflineCC" :
            url = "submitOrder.aspx?ID="+qStr+"&PT=5";
            break;
        case "rb_DirectDebit" :
            url = "submitOrder.aspx?ID="+qStr+"&PT=4";
            break;
        case "rb_DirectDeposit" :
            url = "submitOrder.aspx?ID="+qStr+"&PT=3";
            break;
        default:
            alert("Please select a payment method");
            return false;
            break;
    }
//    if (onAccount){
//        url = "submitOrder.aspx?ID="+qStr;
//    }
//    else{
//        url = "ssl/payment.aspx?ID="+qStr;
//    }
    window.open(url,"_self") ;
    //window.open(url);
//    var msg = openModalWindow(url,args);
//    document.getElementById("ctl00_Content_TabContainer1_tab_confirm_lb_paymentMessage").innerText = msg;
    return false;
}
function IsAddressComplete(fldPrefix,allowPO){
    var line1 = document.getElementById(fldPrefix+"_txt_line1");
    var street = document.getElementById(fldPrefix+"_txt_Street");
    var suburb = document.getElementById(fldPrefix+"_txt_Suburb");
    var postcode = document.getElementById(fldPrefix+"_txt_PostCode");
    var country =  document.getElementById(fldPrefix+"_ddl_Country");
    var regEx = /(P\s*\.?\s*)(O\s*.?\s*)(Box)/gi; 
    var errMsg="";
    var isOK = true;
    var err = new Array();
    
    if (! allowPO){
        var str =(street.value +" "+ line1.value);
        var checkPO =  str.match(regEx);
        if (checkPO != null){
            errMsg += "PO Box not allowed in the address \n";
            isOK = false; 
            //line1.style.backgroundColor = errColor; 
            //street.style.backgroundColor = errColor;       
         }
        line1.style.backgroundColor = ( checkPO == null ) ? "" : errColor; 
        street.style.backgroundColor = (checkPO == null) ? "" : errColor; 
    }
    
    if (RTrim(line1.value).length > 30){
        errMsg += "Line1 can not longer than 30 characters.\n";
        isOK = false;
        //alert(RTrim(line1.value).length);
    }
    
    if (RTrim(street.value).length == 0 ){
        errMsg += "Street is required \n";
        isOK = false;
    }
    
    if (RTrim(street.value).length > 30){
        errMsg += "Street can not longer than 30 characters.\n";
        isOK = false;
    }
    
    if (RTrim(suburb.value).length == 0){
        errMsg += "Suburb is required \n";
        isOK = false;
    }
    
    line1.style.backgroundColor = ( RTrim(line1.value).length < 31 ) ? "" : errColor;
    street.style.backgroundColor = ( (RTrim(street.value).length > 0) && (RTrim(street.value).length < 31) ) ? "" : errColor; 
    suburb.style.backgroundColor = (RTrim(suburb.value).length > 0) ? "" : errColor; 
    
    /*
    if (! allowPO){
        var str =(street.value +" "+ line1.value);
        var checkPO =  str.match(regEx);
        if (checkPO != null){
            errMsg += "PO Box not allowed in the address \n";
            isOK = false; 
            //line1.style.backgroundColor = errColor; 
            //street.style.backgroundColor = errColor;       
         }
        line1.style.backgroundColor = ( checkPO == null ) ? "" : errColor; 
        street.style.backgroundColor = (checkPO == null) ? "" : errColor; 
    }
    */

    if (RTrim(postcode.value).length == 0 && country.value==14) {
        errMsg += "PostCode is required. \n";
        isOK = false;   
    }
    if (isNaN(postcode.value)){
        errMsg += "Post code should be all numbers";
       isOK = false;
    }
    postcode.style.backgroundColor = (isNaN(postcode.value) && country.value ==14) ? errColor : ""; 
    postcode.style.backgroundColor = (RTrim(postcode.value).length == 0 && country.value == 14) ?  errColor : ""; 

    err[0] = isOK;
    err[1] = errMsg;
    return err;
}

function hasSalutation(){
    var salutation = new Array("Mr","Mrs","Ms","Dr","Lt","Col","Miss","Prof","Capt","Rev");
    
}
function onUpdating(){
        // get the update progress div
        var updateProgressDiv = $get('updateProgressDiv'); 

        //  get the gridview element        
        //var tabContainer = $get('<%= this.TabContainer1.ClientID %>');
        
        // make it visible
        updateProgressDiv.style.display = '';        
        
        // get the bounds of both the gridview and the progress div
        //var tabContainerBounds = Sys.UI.DomElement.getBounds(tabContainer);
        var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
        
        //  center of gridview
        var x = Math.round(screen.availWidth / 2) - Math.round(updateProgressDivBounds.width / 2);
        var y = Math.round(screen.availHeight / 2) - Math.round(updateProgressDivBounds.height / 2);        

        //    set the progress element to this position
        Sys.UI.DomElement.setLocation (updateProgressDiv, x, y);           
    }

function onUpdated() {
        // get the update progress div
        var updateProgressDiv = $get('updateProgressDiv'); 
        // make it invisible
        updateProgressDiv.style.display = 'none';
    }
function goLite(FRM,BTN)
{
   //window.document.forms[FRM].elements[BTN].style.color = "#EEEEEE";
   window.document.forms[FRM].elements[BTN].style.color = "#444444";
   window.document.forms[FRM].elements[BTN].style.backgroundColor = "#FFFFFF";
}

function goDim(FRM,BTN)
{
   window.document.forms[FRM].elements[BTN].style.color = "#FFFFFF";
   window.document.forms[FRM].elements[BTN].style.backgroundColor = "#FFFFFF";
}
function getValue(source,eventArgs){
    var pfx = source._id.substring(0,source._id.lastIndexOf("_")+1);
    var str = eventArgs.get_text().split(",");
   document.getElementById(source._element.id).value=str[0];
   document.getElementById(pfx+"ddl_State").value=LTrim(str[1]);
   document.getElementById(pfx+"txt_PostCode").value=eventArgs.get_value();
   }

function backToHome()
{
window.location='userHome.aspx';

}
function changeTab(tabContainer,goNext){
    var tc = "ctl00_Content_" + tabContainer;
    var tabCount = $find(tc).get_tabs().length;
    var activeTI = $find(tc).get_activeTabIndex();
    if (goNext){
        if (activeTI < (tabCount - 1)){$find(tc).set_activeTabIndex(activeTI + 1);}
    }
    else{
        if (activeTI > 0){$find(tc).set_activeTabIndex(activeTI - 1);}    
    }

    //$find(tc).set_activeTabIndex(tabID);
    return false;
    //return doSave
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789 ";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function openFile(fl){
   var f1 = "Temp/"+fl;
   window.open(f1,"_new");  
}
function IsDeliveryAddressComplete(fldPrefix,allowPO){
    var line1 = document.getElementById(fldPrefix+"_txt_line1");
    var street = document.getElementById(fldPrefix+"_txt_Street");
    var suburb = document.getElementById(fldPrefix+"_txt_Suburb");
    var postcode = document.getElementById(fldPrefix+"_txt_PostCode");
    var country =  document.getElementById(fldPrefix+"_ddl_Country");
    var regEx = /(P\s*\.?\s*)(O\s*.?\s*)(Box)/gi; 
    var errMsg="";
    var isOK = true;
    var err = new Array();
    
    line1.style.backgroundColor = "";
    if(RTrim(street.value).length > 0)
    {
        street.style.backgroundColor = ""; 
    }
    
    if (RTrim(street.value).length == 0 ){
        errMsg += "Street is required \n";
        isOK = false;
    }
    
    if (RTrim(line1.value).length + RTrim(street.value).length > 28){
        errMsg += "Address Line 1 and Street together can no exceed 28 characters.\n";
        line1.style.backgroundColor = errColor;
         street.style.backgroundColor = errColor;
        isOK = false;
    }
    
    if (RTrim(suburb.value).length == 0){
        errMsg += "Suburb is required \n";
        isOK = false;
    }

    suburb.style.backgroundColor = (RTrim(suburb.value).length > 0) ? "" : errColor; 

    if (! allowPO){
        var str =(street.value +" "+ line1.value);
        var checkPO =  str.match(regEx);
        if (checkPO != null){
            errMsg += "PO Box not allowed in the address \n";
            isOK = false; 
            //line1.style.backgroundColor = errColor; 
            //street.style.backgroundColor = errColor;       
         }
        line1.style.backgroundColor = ( checkPO == null ) ? "" : errColor; 
        street.style.backgroundColor = (checkPO == null) ? "" : errColor; 
    }

    if (RTrim(postcode.value).length == 0 && country.value==14) {
        errMsg += "PostCode is required. \n";
        isOK = false;   
    }
    if (isNaN(postcode.value)){
        errMsg += "Post code should be all numbers";
       isOK = false;
    }
    postcode.style.backgroundColor = (isNaN(postcode.value) && country.value ==14) ? errColor : ""; 
    postcode.style.backgroundColor = (RTrim(postcode.value).length == 0 && country.value == 14) ?  errColor : ""; 

    err[0] = isOK;
    err[1] = errMsg;
    return err;
}


function OpenProductSelectionWindow(OrderID){
    var tUrl = "ProductSelection.aspx?OrderNumber="+OrderID;
    var args = "status:no;dialogHide:true;help:no;scroll:no";
    var rVal = openModalWindow(tUrl,args,650,100);
    var hfProduct = document.getElementById("ctl00_Content_hf_ProductToAdd");
    hfProduct.value = rVal;
    return false;
}



