/**********************************************************************************/
/*                                                                                */
/*  Function Name:  toggle_display()                                              */
/*  Description:    Determines if the elment should be visible or not             */
/*  Parameters      id                                                            */
/*  Input:                                                                        */
/*  Output:         true or false                                                 */
/*                                                                                */
/*  Author:         Raymond Chow                                                  */
/*  Date:           19 August 2005                                                */
/*                                                                                */
/**********************************************************************************/

function toggle_display(id,checkbox) {

  if (document.getElementById(id)) {
    var obj = document.getElementById(id);

    if (checkbox.checked && checkbox != null) {
      obj.style.display = "none";
    }
    else {
      obj.style.display = "block";
    }
  }

  return;
}


/**********************************************************************************/
/*                                                                                */
/*  Function Name:  validate_domainlookup()                                       */
/*  Description:    Determines if the form filled out correctly in                */
/*                  domainlookup.php                                              */
/*  Parameters      formref                                                       */
/*  Input:                                                                        */
/*  Output:         true or false                                                 */
/*                                                                                */
/*  Author:         Raymond Chow                                                  */
/*  Date:           18 October 2004                                               */
/*                                                                                */
/**********************************************************************************/

function validate_domainlookup(formref) {

  domainname  = formref.domainname.value;

  var errorintro    = "";
  var errormessage  = "";
  var errorfield    = "";

  if (is_empty(domainname)) {
    errorfield  +=  "Please Enter a Domain Name.\n\n";
  }

  errormessage  = errorintro + errorfield;

  if (errormessage != errorintro)  {
    window.alert(errormessage);
    return false;
  }
  else {
    return true;
  }

}

/**********************************************************************************/
/*                                                                                */
/*  Function Name:  validate_domaintransfer()                                     */
/*  Description:    Determines if the form filled out correctly in                */
/*                  domaintransfer.php                                            */
/*  Parameters      formref                                                       */
/*  Input:                                                                        */
/*  Output:         true or false                                                 */
/*                                                                                */
/*  Author:         Raymond Chow                                                  */
/*  Date:           18 October 2004                                               */
/*                                                                                */
/**********************************************************************************/

function validate_domaintransfer(formref) {

  domainname  = formref.domainname.value;

  var errormessage  = "";

  var stopsubmit    = false;

  if  (!is_domain(domainname))  { stopsubmit  = true; errormessage  +=  "Please Enter a Domain Name.\n";  }

  if    (stopsubmit)  { window.alert(errormessage); return false; }
  else                { return true;  }

}


function validate_cira(formref) {
  if  (formref.needcira)  { return true;  }
  return false;
}

/**********************************************************************************/
/*                                                                                */
/*  Function Name:  validate_review()                                             */
/*  Description:    Determines if the form filled out correctly in                */
/*                                                                                */
/*  Parameters      formref                                                       */
/*  Input:                                                                        */
/*  Output:         true or false                                                 */
/*                                                                                */
/*  Author:         Raymond Chow                                                  */
/*  Date:           26 October 2004                                               */
/*                                                                                */
/**********************************************************************************/

function validate_review(formref,needshipping) {

  if    (needshipping == "true")  { var checkshipping = true;   }
  else                            { var checkshipping = false;  }

  var password          = formref.password.value;
  var passwordconfirm   = formref.passwordconfirm.value;

  var confirmtoken  = formref.confirmtoken.value;
  var answer        = formref.answer.value;

  var mbcompanyname = formref.mbcompanyname.value;
  var mbfirstname   = formref.mbfirstname.value;
  var mblastname    = formref.mblastname.value;
  var mbstreet      = formref.mbstreet.value;
  var mbcity        = formref.mbcity.value;
  var mbstate       = formref.mbstate.value;
  var mbcountrycode = formref.mbcountrycode.value;
  var mbzip         = formref.mbzip.value;
  var mbphone       = formref.mbphone.value;
  var mbemail       = formref.mbemail.value;
  var emailconfirm  = formref.emailconfirm.value;

  var cccompanyname = formref.cccompanyname.value;
  var ccfirstname   = formref.ccfirstname.value;
  var cclastname    = formref.cclastname.value;
  var ccstreet      = formref.ccstreet.value;
  var cccity        = formref.cccity.value;
  var ccstate       = formref.ccstate.value;
  var cccountrycode = formref.cccountrycode.value;
  var cczip         = formref.cczip.value;
  var ccphone       = formref.ccphone.value;
  var ccemail       = formref.ccemail.value;


  if (checkshipping) {

    var shcompanyname = formref.shcompanyname.value;
    var shfirstname   = formref.shfirstname.value;
    var shlastname    = formref.shlastname.value;
    var shstreet      = formref.shstreet.value;
    var shcity        = formref.shcity.value;
    var shstate       = formref.shstate.value;
    var shcountrycode = formref.shcountrycode.value;
    var shzip         = formref.shzip.value;
    var shphone       = formref.shphone.value;
    var shemail       = formref.shemail.value;

  }

  var ccnumber  = formref.ccnumber.value;
  var cccvv2    = formref.cccvv2.value;


  var errormessage  = "";

  var stopsubmit    = false;


  //if (is_empty(mbcompanyname))        { stopsubmit = true; errormessage +=  "Please Enter Valid Contact Company Name\n"; }
  if (!is_name(mbfirstname))          { stopsubmit = true; errormessage +=  "Please Enter Valid Contact First Name\n";   }
  if (!is_name(mblastname))           { stopsubmit = true; errormessage +=  "Please Enter Valid Contact Last Name\n"; }
  if (!is_street(mbstreet))           { stopsubmit = true; errormessage +=  "Please Enter Valid Contact Street Address\n"; }
  if (!is_city(mbcity))               { stopsubmit = true; errormessage +=  "Please Enter Valid Contact City\n"; }
  if (!is_statecode(mbstate))         { stopsubmit = true; errormessage +=  "Please Enter Valid Contact Province/Territory Code\n"; }
  if (!is_countrycode(mbcountrycode)) { stopsubmit = true; errormessage +=  "Please Enter Valid Contact Country Code\n"; }
  if (is_empty(mbzip))                { stopsubmit = true; errormessage +=  "Please Enter Valid Contact Postal Code\n"; }
  if (!is_phonenumber(mbphone))       { stopsubmit = true; errormessage +=  "Please Enter Valid Contact Phone Number\n"; }
  if (!is_email(mbemail))             { stopsubmit = true; errormessage +=  "Please Enter Valid Contact E-Mail Address\n"; }

  if (emailconfirm != mbemail)        { stopsubmit = true; errormessage +=  "Please Confirm Contact E-Mail Address\n";   }

  if (validate_cira(formref)) {
    var ciraregistrantname  = formref.ciraregistrantname.value;
    if (is_empty(ciraregistrantname))   { stopsubmit = true; errormessage +=  "Please Enter Valid CIRA Registrant Name\n";   }
  }

  if (!formref.ccsamemb.checked) {
    //if (is_empty(cccompanyname))        { stopsubmit = true; errormessage +=  "Please Enter Valid Billing Company Name\n"; }
    if (!is_name(ccfirstname))          { stopsubmit = true; errormessage +=  "Please Enter Valid Billing First Name\n";   }
    if (!is_name(cclastname))           { stopsubmit = true; errormessage +=  "Please Enter Valid Billing Last Name\n"; }
    if (!is_street(ccstreet))           { stopsubmit = true; errormessage +=  "Please Enter Valid Billing Street Address\n"; }
    if (!is_city(cccity))               { stopsubmit = true; errormessage +=  "Please Enter Valid Billing City\n"; }
    if (!is_statecode(ccstate))         { stopsubmit = true; errormessage +=  "Please Enter Valid Billing Province/Territory Code\n"; }
    if (!is_countrycode(cccountrycode)) { stopsubmit = true; errormessage +=  "Please Enter Valid Billing Country Code\n"; }
    if (is_empty(cczip))                { stopsubmit = true; errormessage +=  "Please Enter Valid Billing Postal Code\n"; }
    if (!is_phonenumber(ccphone))       { stopsubmit = true; errormessage +=  "Please Enter Valid Billing Phone Number\n"; }
    if (!is_email(ccemail))             { stopsubmit = true; errormessage +=  "Please Enter Valid Billing E-Mail Address\n"; }
  }

  if (checkshipping) {
    if (!formref.shsamemb.checked) {

      //if (is_empty(shcompanyname))        { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping Company Name\n"; }
      if (!is_name(shfirstname))          { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping First Name\n";   }
      if (!is_name(shlastname))           { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping Last Name\n"; }
      if (!is_street(shstreet))           { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping Street Address\n"; }
      if (!is_city(shcity))               { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping City\n"; }
      if (!is_statecode(shstate))         { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping Province/Territory Code\n"; }
      if (!is_countrycode(shcountrycode)) { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping Country Code\n"; }
      if (is_empty(shzip))                { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping Postal Code\n"; }
      if (!is_phonenumber(shphone))       { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping Phone Number\n"; }
      if (!is_email(shemail))             { stopsubmit = true; errormessage +=  "Please Enter Valid Shipping E-Mail Address\n"; }

    }
  }

  if (((!is_empty(password)) || (!is_empty(passwordconfirm))) && (password != passwordconfirm)) {
    stopsubmit = true; errormessage +=  "Please confirm password.\n";
  }

  if (is_empty(answer))               { stopsubmit = true; errormessage +=  "Please Enter Security Answer\n"; }
  if (is_empty(confirmtoken))         { stopsubmit = true; errormessage +=  "Please Enter The Validation Token\n"; }


  if (!formref.tos.checked)           { stopsubmit = true; errormessage +=  "You have not agreed to the Terms of Service\n"; }

  if (is_empty(ccnumber)) { stopsubmit = true; errormessage +=  "Please Enter Valid Credit Card Number\n";    }
  if (is_empty(cccvv2))   { stopsubmit = true; errormessage +=  "Please Enter Valid CVV2 Number\n";    }

  if    (stopsubmit)  { window.alert(errormessage); return false; }
  else                { return true; }

}

function validate_review_old(formref) {

  var ccnumber  = formref.ccnumber.value;
  var cccvv2    = formref.cccvv2.value;

  var errormessage  = "";

  var stopsubmit    = false;

  if (is_empty(ccnumber)) { stopsubmit = true; errormessage +=  "Please Enter Valid Card Number\n";    }

  if    (stopsubmit)  { window.alert(errormessage); return false; }
  else                { return true; }

}

/**********************************************************************************/
/*                                                                                */
/*  Function Name:  openwindow()                                                  */
/*  Description:    Opens a popup window                                          */
/*  Parameters      url, width, height                                            */
/*  Input:          none                                                          */
/*  Output:         none                                                          */
/*                                                                                */
/*  Author:         Jason Matheson                                                */
/*  Date:           ?? 2003                                                       */
/*                                                                                */
/**********************************************************************************/

function openwindow(url, width, height) {
  var win;
  var windowName;
  var params;
  windowName  = "features";
  params = "toolbar=0,";
  params += "location=0,";
  params += "directories=0,";
  params += "status=0,";
  params += "menubar=0,";
  params += "scrollbars=1,";
  params += "resizable=1,";
  params += "top=50,";
  params += "left=50,";
  params += "width="+width+",";
  params += "height="+height;
  win = window.open(url, windowName, params);
}

/**********************************************************************************/
/*                                                                                */
/*  Function Name:  tip_registrantname()                                          */
/*  Description:                                                                  */
/*                                                                                */
/*  Parameters      none                                                          */
/*  Input:          none                                                          */
/*  Output:         none                                                          */
/*                                                                                */
/*  Author:         Raymond Chow                                                  */
/*  Date:           19 August 2005                                                */
/*                                                                                */
/**********************************************************************************/

function tip_registrantname(formref,key) {

  /*
  'CCT'  =>  'Canadian Citizen',
  'CCO'  =>  'Corporation (Canada or Canadian province or territory)',
  'RES'  =>  'Permanent Resident of Canada',
  'GOV'  =>  'Government or government entity in Canada',
  'EDU'  =>  'Canadian Educational Institution',
  'ASS'  =>  'Canadian Unincorporated Association',
  'HOP'  =>  'Canadian Hospital',
  'PRT'  =>  'Partnership Registered in Canada',
  'TDM'  =>  'Trade-mark registered in Canada (by a non-Canadian owner)',
  'TRD'  =>  'Canadian Trade Union',
  'PLT'  =>  'Canadian Political Party',
  'LAM'  =>  'Canadian Library, Archive or Museum',
  'TRS'  =>  'Trust established in Canada',
  'ABO'  =>  'Aboriginal Peoples (individuals or groups) indigenous to Canada',
  'INB'  =>  'Indian Band recognized by the Indian Act of Canada',
  'LGR'  =>  'Legal Representative of a Canadian Citizen or Permanent Resident',
  'OMK'  =>  'Official mark registered in Canada',
  'MAJ'  =>  'Her Majesty the Queen',
  */


  var tip = new Array();

  tip["CCT"] =  "Enter the full legal name of the Canadian citizen who will hold the domain name registration.\n";
  tip["CCT"] += "\nExamples:\n";
  tip["CCT"] += "John Doe\n";
  tip["CCT"] += "Fred-Albert Doon PhD\n";
  tip["CCT"] += "Bernard St-James o/a St-James Services";

  tip["CCO"] =  "Enter the full legal name of the corporation, followed by the jurisdiction of incorporation.\n";
  tip["CCO"] += "\nExamples:\n";
  tip["CCO"] += "123745 Canada Inc.\n";
  tip["CCO"] += "Smith Corp. of Ontario\n";
  tip["CCO"] += "Smith Ltée. Canada";

  tip["RES"] =  "Enter the full legal name of the permanent resident of Canada who will hold the domain name registration.\n";
  tip["RES"] += "\nExamples:\n";
  tip["RES"] += "John Doe\n";
  tip["RES"] += "Fred-Albert Doon DDS\n";
  tip["RES"] += "Bernard St-James o/a St-James Services";

  tip["GOV"] =  "Enter the official government name, followed by the name of jurisdiction to which the registrant is related.\n";
  tip["GOV"] += "\nExamples:\n";
  tip["GOV"] += "Government of Alberta\n";
  tip["GOV"] += "Export Development Corporation (EDC) (Canada)\n";
  tip["GOV"] += "Deposit Insurance Corporation of Ontario (DCIO)\n";
  tip["GOV"] += "The Corporation of the City of Toronto";

  tip["EDU"] =  "Enter the name of a univeristy, college, post-secondary school, vocational school, secondary school, pre-school or other school or educational institution which is located in Canada, followed by it's jurisdiction.\n";
  tip["EDU"] += "\nExamples:\n";
  tip["EDU"] += "University of British Columbia (UBC)\n";
  tip["EDU"] += "St-John’s Middle School of Ottawa\n";
  tip["EDU"] += "Advanced Languages Institute of Ontario (ALI)(Ontario)";

  tip["ASS"] =  "Enter the complete name of the association without any abbreviations.\n";
  tip["ASS"] += "\nExamples:\n";
  tip["ASS"] += "St-Alban’s Reformed Church of Victoria\n";
  tip["ASS"] += "Archdiocese of Montréal\n";
  tip["ASS"] += "Sun Youth Montréal\n";
  tip["ASS"] += "Citizens for the Protection of the Red River\n";
  tip["ASS"] += "Toronto Junior Soccer Association";

  tip["HOP"] =  "Enter the complete official name of the hospital, followed by it's jurisdiction.\n";
  tip["HOP"] += "\nExamples:\n";
  tip["HOP"] += "Royal Victoria Hospital - Québec\n";
  tip["HOP"] += "Sick Children’s Hospital of Ontario\n";
  tip["HOP"] += "Veteran’s Hospital Canada, Pointe Claire";

  tip["PRT"] =  "Enter the registered name of the partnership, followed by the jurisdiction of registration.\n";
  tip["PRT"] += "\nExamples:\n";
  tip["PRT"] += "Xenon Partnership (Ontario)\n";
  tip["PRT"] += "Blake, Cassels and Graydon LLP (Ontario)\n";
  tip["PRT"] += "John Doe Partnership, British Columbia";

  tip["TDM"] =  "Enter the complete legal name of the trade-mark owner (not the trade-mark agent) holding the domain name registration without any abbreviations.\n";
  tip["TDM"] += "\nExample:\n";
  tip["TDM"] += "Arcuros SPA - TMA1762466";

  tip["TRD"] =  "Enter the complete official name of the trade union, followed by the jurisdiction in Canada which recognizes it.\n";
  tip["TRD"] += "\nExamples:\n";
  tip["TRD"] += "Confédération des syndicats nationaux (CSN) - Québec\n";
  tip["TRD"] += "Canadian Union of Postal Workers (CUPW)";

  tip["PLT"] =  "Enter the complete official name of the polital party, followed by the jurisdiction in Canada in which it is registered.\n";
  tip["PLT"] += "\nExamples:\n";
  tip["PLT"] += "Progressive Conservative Party of Canada (PC)\n";
  tip["PLT"] += "Union Nationale du Québec\n";
  tip["PLT"] += "Reform Party - Alberta";

  tip["LAM"] =  "Enter the complete legal name of the institution.\n";
  tip["LAM"] += "\nExamples:\n";
  tip["LAM"] += "Royal Ontario Museum\n";
  tip["LAM"] += "Musé des Beaux Arts de Montréal";

  tip["TRS"] =  "Enter the complete official name of the trust, followed by the total percentage of trustees that are either a Canadian citizen, permanent resident, Canadian corporation or legal representative.\n";
  tip["TRS"] += "\nExamples:\n";
  tip["TRS"] += "Marie Daigle Trust - (100%)\n";
  tip["TRS"] += "Arbeit Trust - (70%)";

  tip["ABO"] =  "Aboriginal Peoples\n\n";
  tip["ABO"] += "Enter the full legal name of the Aboriginal person.\n";
  tip["ABO"] += "\nExamples:\n";
  tip["ABO"] += "John Doe\n";
  tip["ABO"] += "Fred-Albert Doon DDS\n";
  tip["ABO"] += "Bernard St-James o/a St-James Services\n\n";
  tip["ABO"] += "Aboriginal Groups\n\n";
  tip["ABO"] += "Enter the complete official name of the indigenous people a collectivity of Aboriginal persons or, if there is no official name, the name by which the collectivity is commonly known.\n";
  tip["ABO"] += "\nExample:\n";
  tip["ABO"] += "Carrier Sekani Tribal Council";

  tip["INB"] =  "Enter the name of an Indian Band as registered with the Department of Indian and Northern Affairs.\n";
  tip["INB"] += "\nExample:\n";
  tip["INB"] += "Lac la Ronge Indian Band";

  tip["LGR"] =  "Enter the full legal name of the Canadian citizen, followed by the full legal name and capacity of at least one of the official representatives.\n";
  tip["LGR"] += "\nExample:\n";
  tip["LGR"] += "John Smith (Jayne Smith, executor)";

  tip["OMK"] =  "Enter the complete official name of the entity holding the domain name registration without any abbreviations.\n";
  tip["OMK"] += "\nExample:\n";
  tip["OMK"] += "The United Nations Educational, Scientific and Cultural Organization (UNESCO) - 0970388";

  tip["MAJ"] =  "Her Majesty the Queen\n";
  tip["MAJ"] += "Enter the name of Her Majesty the Queen or, after a succession, the name of her successor.";

  formref.registrantnametip.value = tip[key];

}


function toggle_box(id) {

  var obj = document.getElementById(id);

  if    (obj.style.display == "block")  { toggle_invisible(id);  }
  else                                  { toggle_visible(id);    }

  return;
}


function toggle_visible(id) {
  var obj = document.getElementById(id);
  obj.style.display  = "block";
  return;
}


function toggle_invisible(id) {
  var obj = document.getElementById(id);
  obj.style.display  = "none";
  return;
}


function openwindow(url, width, height) {
  var win;
  var windowName;
  var params;
  windowName  = "features";
  params = "toolbar=0,";
  params += "location=0,";
  params += "directories=0,";
  params += "status=0,";
  params += "menubar=0,";
  params += "scrollbars=1,";
  params += "resizable=1,";
  params += "top=50,";
  params += "left=50,";
  params += "width="+width+",";
  params += "height="+height;
  win = window.open(url, windowName, params);
}

function openwindow2(url, width, height) {
  var win;
  var windowName;
  var params;
  windowName  = "features";
  params = "toolbar=0,";
  params += "location=0,";
  params += "directories=0,";
  params += "status=0,";
  params += "menubar=0,";
  params += "scrollbars=1,";
  params += "resizable=1,";
  params += "top=50,";
  params += "left=50,";
  params += "width="+width+",";
  params += "height="+height;
  win = window.open(url, windowName, params);
}
