/*
   Global JavaScript for whois.com.au web application.

   (C) Copyright 2010 whois.com.au all rights reserved.

   Created by Smiffy http://www.smiffytech.com

   $Rev: 1626 $
   $LastChangedDate: 2011-10-03 09:19:04 +1030 (Mon, 03 Oct 2011) $
*/

/*
   Show help.
*/
function showHelp(fid)
{
  var helpdiv=document.getElementById(fid);
  var helpwrapper=document.getElementById(fid+'-wrapper');
  helpdiv.className='helpshow';
  
  deleteElementById('helpshowhide');
  var helpshowhide=document.createElement('p');
  helpshowhide.setAttribute('id','helpshowhide');

  var helpa=document.createElement('a');
  helpa.setAttribute('href','#'+fid);
  helpa.setAttribute('onclick','hideHelp(\''+fid+'\')');

  var helpt=document.createTextNode('Hide Help');
  helpa.appendChild(helpt);
  
  helpshowhide.appendChild(helpa);

  helpwrapper.insertBefore(helpshowhide,helpwrapper.firstChild);
}

/*
   Hide help.
*/
function hideHelp(fid)
{
  var helpdiv=document.getElementById(fid);
  var helpwrapper=document.getElementById(fid+'-wrapper');
  helpdiv.className='helphide';

  deleteElementById('helpshowhide');
  var helpshowhide=document.createElement('p');
  helpshowhide.setAttribute('id','helpshowhide');

  var helpa=document.createElement('a');
  helpa.setAttribute('href','#'+fid+'-wrapper');
  helpa.setAttribute('onclick','showHelp(\''+fid+'\')');

  var helpt=document.createTextNode('Show Help');
  helpa.appendChild(helpt);
  
  helpshowhide.appendChild(helpa);

  helpwrapper.insertBefore(helpshowhide,helpwrapper.firstChild);
}

/*
   Remove domain search submit button & replace with busy image.
*/
function domSearchSubmit()
{
  var fsub=document.getElementById('f-search-submit');
  if (fsub)
  {
    fsub.parentNode.removeChild(fsub);
  }
  var sform=document.getElementById('search');
  sform.setAttribute('onsubmit','return false');
  var searching=document.createElement('p');
  searching.setAttribute('id','searchingmsg');
  var searchingtxt=document.createTextNode('Searching..');
  searching.appendChild(searchingtxt);
  sform.appendChild(searching);
}

/*
   Change 'remove' link to spinner.
*/
function spinRlink(fid)
{
  var rlink='rlink-'+fid;
  var rlinkwrapper=document.getElementById('rlinkwrapper-'+fid);
  deleteElementById(rlink);
  var spinner=document.createElement('img');
  spinner.setAttribute('src','/ajax-loader.gif');
  spinner.setAttribute('alt','deleting');
  rlinkwrapper.appendChild(spinner);
}

/*
   Show a tooltip.
*/
function showTooltip(curip)
{
  var thisid=curip.id;
  var thistitle=curip.title;
  var widgetid=thisid+'-widget';
  var tooltipid=thisid+'-tooltip';
  var widget=document.getElementById(widgetid);
  var tooltip=document.createElement('div');
  tooltip.setAttribute('id',tooltipid);
  tooltip.setAttribute('class','ftooltip');
  widget.appendChild(tooltip);
  var tooltiptext=document.createTextNode(thistitle);
  tooltip.appendChild(tooltiptext);
}

/*
  Remove a tooltip.
*/
function clearTooltip(curip)
{
  var thisid=curip.id;
  var tooltipid=thisid+'-tooltip';
  deleteElementById(tooltipid);
}

/*
   Retrieve a block of HTML and replace it into
   an existing element.
*/
function HTMLReplacer(fid,uri)
{
  var theelement=document.getElementById(fid);
  var req;

  if (window.XMLHttpRequest)
  {
    req=new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
    req=new ActiveXObject("Microsoft.XMLHTTP");
  }

  if (req)
  {
    req.onreadystatechange=function()
    {
      if (req.readyState==4)
      {
        if (req.responseText)
        {
          theelement.innerHTML=req.responseText;
        }
      }
    }

    req.open('GET',uri,true);
    req.send(null);
  }
}

/*
   Define WAI-ARIA required form field.
*/
function ARIArequired (fid)
{
  document.getElementById(fid).setAttribute('aria-required','true');
}

/*
   Define WAI-ARIA live region.

   Takes input ID & appends '-formrow'.
*/
function ARIAlive (fid,atrtype)
{
  document.getElementById(fid+'-formrow').setAttribute('aria-live',atrtype);
}

/*
   Define WAI-ARIA live landmark.
*/
function ARIAlandmark (fid,lmtype)
{
  document.getElementById(fid).setAttribute('role',lmtype);
}

/*
   Append a field with a link to a script.

   fid - field ID
   href - JS function to add
   text - link text
*/
function jslink(fid,href,text)
{
  var ihref='javascript:'+href+';';
  var widget=document.getElementById(fid+'-widget');

  // Create an a within a p.
  var wrapper=document.createElement('p');
  var anchor=document.createElement('a');
  anchor.setAttribute('href',ihref);
  var linktext=document.createTextNode(text);
  anchor.appendChild(linktext);
  wrapper.appendChild(anchor);
  widget.appendChild(wrapper);
}

/*
   Copy the contents of field fid1 to fid2.
*/
function cpfield(fid1,fid2)
{
  document.getElementById(fid2).value=document.getElementById(fid1).value;
  inputerrclear(fid2);
  document.getElementById(fid2).focus();
}

/*
   Compare contents of field fid1 and fid2.o

   1 = identical.
   0 = different.
*/
function cmpfields(fid1,fid2)
{
  if (document.getElementById(fid1).value==document.getElementById(fid2).value)
  {
    return 1;
  }
  else
  {
    return 0;
  }
}

/*
   Validation of an e-mail address.  Based on:
   http://marketingtechblog.com/programming/javascript-regex-emailaddress/

   fid - field ID
   msg - error message if invalid
*/
function isemail(fid)
{
  inputerrclear(fid);
  var fval=document.getElementById(fid).value;
  var filter=/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
  if (!filter.test(fval)) 
  {
    return(1);
  }
  else
  {
    return(0);
  }
}

/*
   Check that a form input ID fid has >= n characters.

   Set error message msg and any decoration if not.
*/
function checkfinput(fid,n,msg)
{
  inputerrclear(fid);
  if (document.getElementById(fid).value.length<=n)
  {
    inputerr(fid,msg);
    return(1);
  }
  else
  {
    inputok(fid);
    return(0);
  }
}

/*
   Delete an element.
*/
function deleteElementById(fid)
{
  var theelement=document.getElementById(fid);
  if (theelement)
  {
    theelement.parentNode.removeChild(theelement);
  }
}

/*
   Clear out any error messages for a form
   input prior to running checks.

   Takes:
   fid - input ID
*/
function inputerrclear(fid)
{
  var errdiv=document.getElementById(fid + '-err');
  if (errdiv)
  {
    errdiv.parentNode.removeChild(errdiv);
  }

  var fbicon=document.getElementById(fid + '-fbicon');
  if (fbicon)
  {
    fbicon.parentNode.removeChild(fbicon);
  }

  document.getElementById(fid).className='inormal';
}

/*
  Create error message & styling for
  form input.

  Takes:
  fid - input ID
  msg - message
*/
function inputerr(fid, msg)
{
  var formrowid=fid + '-formrow';
  var errid=fid + '-err';
  var widgetid=fid + '-widget';
  var fbiconid=fid + '-fbicon';

  // Get reference to the actual form input.
  var input=document.getElementById(fid);
  // Get reference to formrow div for this input.
  var formrow=document.getElementById(formrowid);
  // Get reference to widget div 
  // containing the form input.
  var widget=document.getElementById(widgetid);

  // Create a new div.
  var errdiv=document.createElement('div');
  // Set ID of div.
  errdiv.setAttribute('id',errid);
  // Set class of div.
  errdiv.setAttribute('class','inputfb');
  // Add div as first child of formrow div.
  formrow.insertBefore(errdiv,formrow.firstChild);
  // Create a text node with our message.
  var errtxt=document.createTextNode(msg);
  // Append the text node to the div just created.
  errdiv.appendChild(errtxt);

  // Find the current class for the input,
  // then append the iwarn class (red border.)
  var thisClass=input.className;
  input.className=thisClass + ' iwarn';

  // Create a new div, set ID and class.
  var fbdiv=document.createElement('div');
  fbdiv.setAttribute('id',fbiconid);
  fbdiv.setAttribute('class','fbcross');
  // Put new div into document after the input. 
  widget.insertBefore(fbdiv,input.nextSibling);
}

/*
   Style form input as being OK.

   Takes:
   fid - input ID
*/
function inputok(fid)
{
  var widgetid=fid + '-widget';
  var fbiconid=fid + '-fbicon';
  var input=document.getElementById(fid);
  var widget=document.getElementById(widgetid);

  var currentClass=input.className;
  input.className=currentClass+' iok';

  // Create a new div, set ID and class.
  var fbdiv=document.createElement('div');
  fbdiv.setAttribute('id',fbiconid);
  fbdiv.setAttribute('class','fbtick');
  // Put new div into document after the input. 
  widget.insertBefore(fbdiv,input.nextSibling);
}

/*
   Create a new countries object.
*/
function countryObj()
{
	this.AF=new Object();
	this.AF.name='Afghanistan';
	this.AF.idd='93';
	this.AL=new Object();
	this.AL.name='Albania';
	this.AL.idd='355';
	this.DZ=new Object();
	this.DZ.name='Algeria';
	this.DZ.idd='213';
	this.AS=new Object();
	this.AS.name='American Samoa';
	this.AS.idd='1';
	this.AD=new Object();
	this.AD.name='Andorra';
	this.AD.idd='376';
	this.AO=new Object();
	this.AO.name='Angola';
	this.AO.idd='244';
	this.AI=new Object();
	this.AI.name='Anguilla';
	this.AI.idd='1';
	this.AQ=new Object();
	this.AQ.name='Antarctica';
	this.AQ.idd='672';
	this.AG=new Object();
	this.AG.name='Antigua';
	this.AG.idd='1';
	this.AR=new Object();
	this.AR.name='Argentina';
	this.AR.idd='54';
	this.AM=new Object();
	this.AM.name='Armenia';
	this.AM.idd='374';
	this.AW=new Object();
	this.AW.name='Aruba';
	this.AW.idd='297';
	this.AU=new Object();
	this.AU.name='Australia';
	this.AU.idd='61';
	this.AT=new Object();
	this.AT.name='Austria';
	this.AT.idd='43';
	this.AZ=new Object();
	this.AZ.name='Azerbaijan';
	this.AZ.idd='994';
	this.BS=new Object();
	this.BS.name='Bahamas';
	this.BS.idd='1';
	this.BH=new Object();
	this.BH.name='Bahrain';
	this.BH.idd='973';
	this.BD=new Object();
	this.BD.name='Bangladesh';
	this.BD.idd='880';
	this.BB=new Object();
	this.BB.name='Barbados';
	this.BB.idd='1';
	this.BY=new Object();
	this.BY.name='Belarus';
	this.BY.idd='375';
	this.BE=new Object();
	this.BE.name='Belgium';
	this.BE.idd='32';
	this.BZ=new Object();
	this.BZ.name='Belize';
	this.BZ.idd='501';
	this.BJ=new Object();
	this.BJ.name='Benin';
	this.BJ.idd='229';
	this.BM=new Object();
	this.BM.name='Bermuda';
	this.BM.idd='1';
	this.BT=new Object();
	this.BT.name='Bhutan';
	this.BT.idd='975';
	this.BO=new Object();
	this.BO.name='Bolivia';
	this.BO.idd='591';
	this.BA=new Object();
	this.BA.name='Bosnia and Herzegovina';
	this.BA.idd='387';
	this.BW=new Object();
	this.BW.name='Botswana';
	this.BW.idd='267';
	this.BR=new Object();
	this.BR.name='Brazil';
	this.BR.idd='55';
	this.VG=new Object();
	this.VG.name='British Virgin Islands';
	this.VG.idd='1';
	this.BN=new Object();
	this.BN.name='Brunei';
	this.BN.idd='673';
	this.BG=new Object();
	this.BG.name='Bulgaria';
	this.BG.idd='359';
	this.BF=new Object();
	this.BF.name='Burkina Faso';
	this.BF.idd='226';
	this.BI=new Object();
	this.BI.name='Burundi';
	this.BI.idd='257';
	this.KH=new Object();
	this.KH.name='Cambodia';
	this.KH.idd='855';
	this.CM=new Object();
	this.CM.name='Cameroon';
	this.CM.idd='237';
	this.CA=new Object();
	this.CA.name='Canada';
	this.CA.idd='1';
	this.CV=new Object();
	this.CV.name='Cape Verde Islands';
	this.CV.idd='238';
	this.KY=new Object();
	this.KY.name='Cayman Islands';
	this.KY.idd='1';
	this.CF=new Object();
	this.CF.name='Central African Republic';
	this.CF.idd='236';
	this.TD=new Object();
	this.TD.name='Chad';
	this.TD.idd='235';
	this.CL=new Object();
	this.CL.name='Chile';
	this.CL.idd='56';
	this.CN=new Object();
	this.CN.name='China (PRC)';
	this.CN.idd='86';
	this.CX=new Object();
	this.CX.name='Christmas Island';
	this.CX.idd='61';
	this.CC=new Object();
	this.CC.name='Cocos-Keeling Islands';
	this.CC.idd='61';
	this.KM=new Object();
	this.KM.name='Comoros';
	this.KM.idd='269';
	this.CG=new Object();
	this.CG.name='Congo';
	this.CG.idd='242';
	this.CD=new Object();
	this.CD.name='Congo Dem. Rep. of';
	this.CD.idd='242';
	this.CK=new Object();
	this.CK.name='Cook Islands';
	this.CK.idd='682';
	this.CR=new Object();
	this.CR.name='Costa Rica';
	this.CR.idd='506';
	this.HR=new Object();
	this.HR.name='Croatia';
	this.HR.idd='385';
	this.CU=new Object();
	this.CU.name='Cuba';
	this.CU.idd='53';
	this.CY=new Object();
	this.CY.name='Cyprus';
	this.CY.idd='357';
	this.CZ=new Object();
	this.CZ.name='Czech Republic';
	this.CZ.idd='420';
	this.DK=new Object();
	this.DK.name='Denmark';
	this.DK.idd='45';
	this.DJ=new Object();
	this.DJ.name='Djibouti';
	this.DJ.idd='253';
	this.DM=new Object();
	this.DM.name='Dominica';
	this.DM.idd='1';
	this.DO=new Object();
	this.DO.name='Dominican Republic';
	this.DO.idd='1';
	this.TP=new Object();
	this.TP.name='East Timor';
	this.TP.idd='670';
	this.EC=new Object();
	this.EC.name='Ecuador';
	this.EC.idd='593';
	this.EG=new Object();
	this.EG.name='Egypt';
	this.EG.idd='20';
	this.SV=new Object();
	this.SV.name='El Salvador';
	this.SV.idd='503';
	this.GQ=new Object();
	this.GQ.name='Equatorial Guinea';
	this.GQ.idd='240';
	this.ER=new Object();
	this.ER.name='Eritrea';
	this.ER.idd='291';
	this.EE=new Object();
	this.EE.name='Estonia';
	this.EE.idd='372';
	this.ET=new Object();
	this.ET.name='Ethiopia';
	this.ET.idd='251';
	this.FK=new Object();
	this.FK.name='Falkland Islands';
	this.FK.idd='500';
	this.FJ=new Object();
	this.FJ.name='Fiji Islands';
	this.FJ.idd='679';
	this.FI=new Object();
	this.FI.name='Finland';
	this.FI.idd='358';
	this.FR=new Object();
	this.FR.name='France';
	this.FR.idd='33';
	this.GF=new Object();
	this.GF.name='French Guiana';
	this.GF.idd='594';
	this.PF=new Object();
	this.PF.name='French Polynesia';
	this.PF.idd='689';
	this.GA=new Object();
	this.GA.name='Gabon';
	this.GA.idd='241';
	this.GM=new Object();
	this.GM.name='Gambia';
	this.GM.idd='220';
	this.GE=new Object();
	this.GE.name='Georgia';
	this.GE.idd='995';
	this.DE=new Object();
	this.DE.name='Germany';
	this.DE.idd='49';
	this.GH=new Object();
	this.GH.name='Ghana';
	this.GH.idd='233';
	this.GI=new Object();
	this.GI.name='Gibraltar';
	this.GI.idd='350';
	this.GR=new Object();
	this.GR.name='Greece';
	this.GR.idd='30';
	this.GL=new Object();
	this.GL.name='Greenland';
	this.GL.idd='299';
	this.GD=new Object();
	this.GD.name='Grenada';
	this.GD.idd='1';
	this.GP=new Object();
	this.GP.name='Guadeloupe';
	this.GP.idd='590';
	this.GU=new Object();
	this.GU.name='Guam';
	this.GU.idd='1';
	this.GT=new Object();
	this.GT.name='Guatemala';
	this.GT.idd='502';
	this.GW=new Object();
	this.GW.name='Guinea-Bissau';
	this.GW.idd='245';
	this.GY=new Object();
	this.GY.name='Guyana';
	this.GY.idd='592';
	this.HT=new Object();
	this.HT.name='Haiti';
	this.HT.idd='509';
	this.HN=new Object();
	this.HN.name='Honduras';
	this.HN.idd='504';
	this.HK=new Object();
	this.HK.name='Hong Kong';
	this.HK.idd='852';
	this.HU=new Object();
	this.HU.name='Hungary';
	this.HU.idd='36';
	this.IS=new Object();
	this.IS.name='Iceland';
	this.IS.idd='354';
	this.IN=new Object();
	this.IN.name='India';
	this.IN.idd='91';
	this.ID=new Object();
	this.ID.name='Indonesia';
	this.ID.idd='62';
	this.IR=new Object();
	this.IR.name='Iran';
	this.IR.idd='98';
	this.IQ=new Object();
	this.IQ.name='Iraq';
	this.IQ.idd='964';
	this.IE=new Object();
	this.IE.name='Ireland';
	this.IE.idd='353';
	this.IL=new Object();
	this.IL.name='Israel';
	this.IL.idd='972';
	this.IT=new Object();
	this.IT.name='Italy';
	this.IT.idd='39';
	this.CI=new Object();
	this.CI.name='Ivory Coast';
	this.CI.idd='225';
	this.JM=new Object();
	this.JM.name='Jamaica';
	this.JM.idd='1';
	this.JP=new Object();
	this.JP.name='Japan';
	this.JP.idd='81';
	this.JO=new Object();
	this.JO.name='Jordan';
	this.JO.idd='962';
	this.KZ=new Object();
	this.KZ.name='Kazakhstan';
	this.KZ.idd='7';
	this.KE=new Object();
	this.KE.name='Kenya';
	this.KE.idd='254';
	this.KI=new Object();
	this.KI.name='Kiribati';
	this.KI.idd='686';
	this.KP=new Object();
	this.KP.name='North Korea';
	this.KP.idd='850';
	this.KR=new Object();
	this.KR.name='South Korea';
	this.KR.idd='82';
	this.KW=new Object();
	this.KW.name='Kuwait';
	this.KW.idd='965';
	this.KG=new Object();
	this.KG.name='Kyrgyz Republic';
	this.KG.idd='996';
	this.LA=new Object();
	this.LA.name='Laos';
	this.LA.idd='856';
	this.LV=new Object();
	this.LV.name='Latvia';
	this.LV.idd='371';
	this.LB=new Object();
	this.LB.name='Lebanon';
	this.LB.idd='961';
	this.LS=new Object();
	this.LS.name='Lesotho';
	this.LS.idd='266';
	this.LR=new Object();
	this.LR.name='Liberia';
	this.LR.idd='231';
	this.LY=new Object();
	this.LY.name='Libya';
	this.LY.idd='218';
	this.LI=new Object();
	this.LI.name='Liechtenstein';
	this.LI.idd='423';
	this.LT=new Object();
	this.LT.name='Lithuania';
	this.LT.idd='370';
	this.LU=new Object();
	this.LU.name='Luxembourg';
	this.LU.idd='352';
	this.MO=new Object();
	this.MO.name='Macau';
	this.MO.idd='853';
	this.MK=new Object();
	this.MK.name='Macedonia';
	this.MK.idd='389';
	this.MG=new Object();
	this.MG.name='Madagascar';
	this.MG.idd='261';
	this.MW=new Object();
	this.MW.name='Malawi';
	this.MW.idd='265';
	this.MY=new Object();
	this.MY.name='Malaysia';
	this.MY.idd='60';
	this.MV=new Object();
	this.MV.name='Maldives';
	this.MV.idd='960';
	this.MT=new Object();
	this.MT.name='Malta';
	this.MT.idd='356';
	this.MH=new Object();
	this.MH.name='Marshall Islands';
	this.MH.idd='692';
	this.MQ=new Object();
	this.MQ.name='Martinique';
	this.MQ.idd='596';
	this.MR=new Object();
	this.MR.name='Mauritania';
	this.MR.idd='222';
	this.MU=new Object();
	this.MU.name='Mauritius';
	this.MU.idd='230';
	this.YT=new Object();
	this.YT.name='Mayotte Island';
	this.YT.idd='269';
	this.MX=new Object();
	this.MX.name='Mexico';
	this.MX.idd='52';
	this.FM=new Object();
	this.FM.name='Micronesia (Federal States of)';
	this.FM.idd='691';
	this.MC=new Object();
	this.MC.name='Monaco';
	this.MC.idd='377';
	this.MN=new Object();
	this.MN.name='Mongolia';
	this.MN.idd='976';
	this.MS=new Object();
	this.MS.name='Montserrat';
	this.MS.idd='1';
	this.MA=new Object();
	this.MA.name='Morocco';
	this.MA.idd='212';
	this.MZ=new Object();
	this.MZ.name='Mozambique';
	this.MZ.idd='258';
	this.MM=new Object();
	this.MM.name='Myanmar';
	this.MM.idd='95';
	this.NA=new Object();
	this.NA.name='Namibia';
	this.NA.idd='264';
	this.NR=new Object();
	this.NR.name='Nauru';
	this.NR.idd='674';
	this.NP=new Object();
	this.NP.name='Nepal';
	this.NP.idd='977';
	this.NL=new Object();
	this.NL.name='Netherlands';
	this.NL.idd='31';
	this.AN=new Object();
	this.AN.name='Netherlands Antilles';
	this.AN.idd='599';
	this.NC=new Object();
	this.NC.name='New Caledonia';
	this.NC.idd='687';
	this.NZ=new Object();
	this.NZ.name='New Zealand';
	this.NZ.idd='64';
	this.NI=new Object();
	this.NI.name='Nicaragua';
	this.NI.idd='505';
	this.NE=new Object();
	this.NE.name='Niger';
	this.NE.idd='227';
	this.NG=new Object();
	this.NG.name='Nigeria';
	this.NG.idd='234';
	this.NU=new Object();
	this.NU.name='Niue';
	this.NU.idd='683';
	this.NF=new Object();
	this.NF.name='Norfolk Island';
	this.NF.idd='672';
	this.NO=new Object();
	this.NO.name='Norway';
	this.NO.idd='47';
	this.OM=new Object();
	this.OM.name='Oman';
	this.OM.idd='968';
	this.PK=new Object();
	this.PK.name='Pakistan';
	this.PK.idd='92';
	this.PW=new Object();
	this.PW.name='Palau';
	this.PW.idd='680';
	this.PA=new Object();
	this.PA.name='Panama';
	this.PA.idd='507';
	this.PG=new Object();
	this.PG.name='Papua New Guinea';
	this.PG.idd='675';
	this.PY=new Object();
	this.PY.name='Paraguay';
	this.PY.idd='595';
	this.PE=new Object();
	this.PE.name='Peru';
	this.PE.idd='51';
	this.PH=new Object();
	this.PH.name='Philippines';
	this.PH.idd='63';
	this.PL=new Object();
	this.PL.name='Poland';
	this.PL.idd='48';
	this.PT=new Object();
	this.PT.name='Portugal';
	this.PT.idd='351';
	this.PR=new Object();
	this.PR.name='Puerto Rico';
	this.PR.idd='1';
	this.QA=new Object();
	this.QA.name='Qatar';
	this.QA.idd='974';
	this.RO=new Object();
	this.RO.name='Romania';
	this.RO.idd='40';
	this.RU=new Object();
	this.RU.name='Russia';
	this.RU.idd='7';
	this.RW=new Object();
	this.RW.name='Rwanda';
	this.RW.idd='250';
	this.SH=new Object();
	this.SH.name='St. Helena';
	this.SH.idd='290';
	this.KN=new Object();
	this.KN.name='St. Kitts/Nevis';
	this.KN.idd='1';
	this.LC=new Object();
	this.LC.name='St. Lucia';
	this.LC.idd='1';
	this.PM=new Object();
	this.PM.name='St. Pierre and Miquelon';
	this.PM.idd='508';
	this.VC=new Object();
	this.VC.name='St. Vincent and Grenadines';
	this.VC.idd='1';
	this.SM=new Object();
	this.SM.name='San Marino';
	this.SM.idd='378';
	this.ST=new Object();
	this.ST.name='São Tomé and Principe';
	this.ST.idd='239';
	this.SA=new Object();
	this.SA.name='Saudi Arabia';
	this.SA.idd='966';
	this.SN=new Object();
	this.SN.name='Senegal';
	this.SN.idd='221';
	this.SC=new Object();
	this.SC.name='Seychelles Islands';
	this.SC.idd='248';
	this.SL=new Object();
	this.SL.name='Sierra Leone';
	this.SL.idd='232';
	this.SG=new Object();
	this.SG.name='Singapore';
	this.SG.idd='65';
	this.SK=new Object();
	this.SK.name='Slovak Republic';
	this.SK.idd='421';
	this.SI=new Object();
	this.SI.name='Slovenia';
	this.SI.idd='386';
	this.SB=new Object();
	this.SB.name='Solomon Islands';
	this.SB.idd='677';
	this.SO=new Object();
	this.SO.name='Somalia';
	this.SO.idd='252';
	this.ZA=new Object();
	this.ZA.name='South Africa';
	this.ZA.idd='27';
	this.ES=new Object();
	this.ES.name='Spain';
	this.ES.idd='34';
	this.LK=new Object();
	this.LK.name='Sri Lanka';
	this.LK.idd='94';
	this.SD=new Object();
	this.SD.name='Sudan';
	this.SD.idd='249';
	this.SR=new Object();
	this.SR.name='Suriname';
	this.SR.idd='597';
	this.SZ=new Object();
	this.SZ.name='Swaziland';
	this.SZ.idd='268';
	this.SE=new Object();
	this.SE.name='Sweden';
	this.SE.idd='46';
	this.CH=new Object();
	this.CH.name='Switzerland';
	this.CH.idd='41';
	this.SY=new Object();
	this.SY.name='Syria';
	this.SY.idd='963';
	this.TW=new Object();
	this.TW.name='Taiwan';
	this.TW.idd='886';
	this.TJ=new Object();
	this.TJ.name='Tajikistan';
	this.TJ.idd='992';
	this.TZ=new Object();
	this.TZ.name='Tanzania';
	this.TZ.idd='255';
	this.TH=new Object();
	this.TH.name='Thailand';
	this.TH.idd='66';
	this.TG=new Object();
	this.TG.name='Togo';
	this.TG.idd='228';
	this.TK=new Object();
	this.TK.name='Tokelau';
	this.TK.idd='690';
	this.TO=new Object();
	this.TO.name='Tonga Islands';
	this.TO.idd='676';
	this.TT=new Object();
	this.TT.name='Trinidad and Tobago';
	this.TT.idd='1';
	this.TN=new Object();
	this.TN.name='Tunisia';
	this.TN.idd='216';
	this.TR=new Object();
	this.TR.name='Turkey';
	this.TR.idd='90';
	this.TM=new Object();
	this.TM.name='Turkmenistan';
	this.TM.idd='993';
	this.TC=new Object();
	this.TC.name='Turks and Caicos Islands';
	this.TC.idd='1';
	this.TV=new Object();
	this.TV.name='Tuvalu';
	this.TV.idd='688';
	this.UG=new Object();
	this.UG.name='Uganda';
	this.UG.idd='256';
	this.UA=new Object();
	this.UA.name='Ukraine';
	this.UA.idd='380';
	this.AE=new Object();
	this.AE.name='United Arab Emirates';
	this.AE.idd='971';
	this.GB=new Object();
	this.GB.name='United Kingdom';
	this.GB.idd='44';
	this.US=new Object();
	this.US.name='United States of America';
	this.US.idd='1';
	this.VI=new Object();
	this.VI.name='US Virgin Islands';
	this.VI.idd='1';
	this.UY=new Object();
	this.UY.name='Uruguay';
	this.UY.idd='598';
	this.UZ=new Object();
	this.UZ.name='Uzbekistan';
	this.UZ.idd='998';
	this.VU=new Object();
	this.VU.name='Vanuatu';
	this.VU.idd='678';
	this.VA=new Object();
	this.VA.name='Vatican City';
	this.VA.idd='379';
	this.VE=new Object();
	this.VE.name='Venezuela';
	this.VE.idd='58';
	this.VN=new Object();
	this.VN.name='Vietnam';
	this.VN.idd='84';
	this.WF=new Object();
	this.WF.name='Wallis and Futuna Islands';
	this.WF.idd='681';
	this.WS=new Object();
	this.WS.name='Western Samoa';
	this.WS.idd='685';
	this.YE=new Object();
	this.YE.name='Yemen';
	this.YE.idd='967';
	this.YU=new Object();
	this.YU.name='Yugoslavia';
	this.YU.idd='389';
	this.ZM=new Object();
	this.ZM.name='Zambia';
	this.ZM.idd='260';
	this.ZW=new Object();
	this.ZW.name='Zimbabwe';
	this.ZW.idd='263';
}

/*
  Test password strength.
*/
function pswdStrength(fid)
{
  var givenpass=document.getElementById(fid).value;
  var meterwrapper=document.getElementById(fid+'-widget');
  var meterdiv=document.getElementById('strmeter');

  if (meterdiv)
  {
    meterdiv.parentNode.removeChild(meterdiv);
  }

  meterdiv=document.createElement('div');
  meterdiv.setAttribute('id','strmeter');
  meterdiv.setAttribute('class','strmeter');
  meterwrapper.appendChild(meterdiv);

  var mediumRegex = new RegExp("^(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");

  if (givenpass.length<5)
  {
    meterdiv.appendChild(document.createTextNode('Too short.'));
    meterdiv.style.color='#F00';
  }
  else if (mediumRegex.test(givenpass))
  {
    meterdiv.appendChild(document.createTextNode('Strength OK.'));
    meterdiv.style.color='#0F0';
  }
  else
  {
    meterdiv.appendChild(document.createTextNode('Weak.'));
    meterdiv.style.color='#F00';
  }
}

/*
   JavaScript for bulk domains module.
*/

/*
   If refreshstate is set, run bdreplace() in 5 seconds.
*/
function bdrefresh()
{
  var refreshstate=document.getElementById('refreshstate').value;
  if (refreshstate==1)
  {
    var tOut=window.setTimeout('bdreplace()',1000);
  }
}


function bdtimedout()
{
  alert('timeout!');
  var message='<p>The automatic refresh has timed out. ';
  message+='You may <a href="/bulkdomains/availability">refresh manually</a> or ';
  message+=' halt the check, using the button below.</p>';
  message+='<form method="post" action="/bulkdomains/availability">';
  message+='<div><input type="hidden" id="refreshstate" value="1" /></div>';
  message+='<div><input type="hidden" name="halt" value="true" /></div>';
  message+='<div><input type="submit" class="button" value="Halt Check" /></div>';
  message+='</form></div><!-- end a_actions -->';

  document.getElementById('autoblock').innerHTML=message;
}


/*
   Invoke HTMLReplacer (in whoiscomau.js) to retrieve 
   new content for div id='automsg' and replace it.

   Then invoke bdrefresh() to keep this happening until
   refreshstate is unset.
*/
function bdreplace()
{
  // HTMLReplacer('autoblock','/bulkdomains/jsrefresh');
  HTMLReplacer('autoblock','/api.pl?a=bdrefresh');
  bdrefresh();
}


  function checkBulkForm()
  {
    // Remove previous error messages.
    deleteElementById('bulkerrdiv');

    // Build TLDs list.
    var items_checked=0;

    if (document.getElementById('f-domainid-319').checked==true) items_checked++;
    if (document.getElementById('f-domainid-316').checked==true) items_checked++;
    if (document.getElementById('f-domainid-320').checked==true) items_checked++;
    if (document.getElementById('f-domainid-317').checked==true) items_checked++;
    if (document.getElementById('f-domainid-318').checked==true) items_checked++;
    if (document.getElementById('f-domainid-35').checked==true) items_checked++;
    if (document.getElementById('f-domainid-85').checked==true) items_checked++;
    if (document.getElementById('f-domainid-97').checked==true) items_checked++;
    if (document.getElementById('f-domainid-21').checked==true) items_checked++;
    if (document.getElementById('f-domainid-142').checked==true) items_checked++;
    if (document.getElementById('f-domainid-151').checked==true) items_checked++;
    if (document.getElementById('f-domainid-152').checked==true) items_checked++;
    if (document.getElementById('f-domainid-321').checked==true) items_checked++;
    if (document.getElementById('f-domainid-38').checked==true) items_checked++;
    if (document.getElementById('f-domainid-161').checked==true) items_checked++;
    if (document.getElementById('f-domainid-40').checked==true) items_checked++;
    if (document.getElementById('f-domainid-42').checked==true) items_checked++;
    if (document.getElementById('f-domainid-23').checked==true) items_checked++;
    if (document.getElementById('f-domainid-323').checked==true) items_checked++;
    if (document.getElementById('f-domainid-322').checked==true) items_checked++;
    if (document.getElementById('f-domainid-325').checked==true) items_checked++;
    if (document.getElementById('f-domainid-324').checked==true) items_checked++;
    if (document.getElementById('f-domainid-326').checked==true) items_checked++;
    if (document.getElementById('f-domainid-327').checked==true) items_checked++;
    if (document.getElementById('f-domainid-328').checked==true) items_checked++;
    if (document.getElementById('f-domainid-329').checked==true) items_checked++;
    if (document.getElementById('f-domainid-26').checked==true) items_checked++;
    if (document.getElementById('f-domainid-246').checked==true) items_checked++;
    if (document.getElementById('f-domainid-275').checked==true) items_checked++;
    if (document.getElementById('f-domainid-331').checked==true) items_checked++;
    if (document.getElementById('f-domainid-330').checked==true) items_checked++;

    // Error if not TLD selected.
    if (items_checked==0)
    {
      setBulkErr('You must choose at least one TLD/extension to check.');
      return false;
    }

    var boxval=document.getElementById('f-domains').value;

    // Test for .'s - no subdomains!
    var naughtydots=/\\./;
    if (naughtydots.test(boxval))
    {
      setBulkErr('One or more dots ( . ) were found in the domains list. TLDs/extensions should be selected using the checkboxes, not put in the domain list.');
      return false;
    }

    // Test for invalid characters.
    var invalidchars=/[^a-zA-Z0-9\-\s]/;
    if (invalidchars.test(boxval))
    {
      setBulkErr('Only letters, numbers and dashes ( - ) are allowed in domain names.');
      return false;
    }

    var boxsize=boxval.length;
    if (boxsize<2)
    {
      setBulkErr('Domain names must be at least 2 characters long. '+boxsize);
      return false;
    }

    // Convert f-domains value to all single-space separation.
    var boxval2=boxval.replace(/\\s+/g,' ');
    var domary=boxval2.split(' ');
    var domarysz=domary.length;

    var perms=domarysz * items_checked;
    if (perms > 200)
    {
      setBulkErr('Domain names x TLDs/extensions exceeds limit of 200. ('+perms+' selected.)');
      return false;
    }

    return true;
  }

  function setBulkErr(msg)
  {
    var bulkerrwrapper=document.getElementById('errwrap');
    var bulkerrdiv=document.createElement('div');
    bulkerrdiv.setAttribute('class','infowrapper');
    bulkerrdiv.setAttribute('id','bulkerrdiv');
    bulkerrwrapper.appendChild(bulkerrdiv);
    var bulkerrinner=document.createElement('div');
    bulkerrinner.setAttribute('class','uhoh');
    bulkerrdiv.appendChild(bulkerrinner);
    var bulkerrp=document.createElement('p');
    bulkerrp.setAttribute('class','uhoh');
    bulkerrinner.appendChild(bulkerrp);
    var bulkerrtext=document.createTextNode(msg);
    bulkerrp.appendChild(bulkerrtext);
    var peetwo=document.createElement('p');
    peetwo.setAttribute('class','uhoh');
    bulkerrinner.appendChild(peetwo);
    var pcyi=document.createTextNode('Please check your input and try again.');
    peetwo.appendChild(pcyi);
  }


/*
   JavaScript for domains module.

*/

/*
   Show link to ausreg iframe WHOIS lookup.
*/
function setwhoisextlink(domain)
{
  var wrapper=document.getElementById('whoisextlink');
  var thelink=document.createElement('a');
  thelink.setAttribute('href','http://cdn.whois.com.au/static/auwhois.html?'+domain);
  thelink.setAttribute('target','_blank');
  var linktext=document.createTextNode('WHOIS lookup for '+domain);
  thelink.appendChild(linktext);
  wrapper.appendChild(thelink);
}

/*
   Hide/unhide advanced section of nameservers form.

   Since hiding implies use of WCA nameservers, clean
   out any extra hosts when collapsing.
*/
function checkbulkrego()
{
  if (validateNSHostForm()==true)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function checktandc(fid)
{
  if (document.getElementById('f-tandc').checked)
  {
    return true;
  }
  else
  {
    var tandcwrap=document.getElementById(fid);
    var tandcsubmitmsgp=document.createElement('p');
    tandcsubmitmsgp.setAttribute('id','tandcfail');
    var tandcsubmitmsg=document.createTextNode('You must accept the Terms and Conditions to continue.');
    tandcsubmitmsgp.appendChild(tandcsubmitmsg);
    tandcwrap.appendChild(tandcsubmitmsgp);
    tandcsubmitmsgp.focus()
    return false;
  } 
}


/*
   Validate a nameserver host entry.
*/
function validateNSHost(fid)
{
  inputerrclear(fid);
  var hostname=document.getElementById(fid).value;
  var l_hostname=hostname.length;

  if (l_hostname==0)
  {
    return(0);
  }

  var hasadot=/\./;
  var nasties=/[^a-zA-Z0-9\.\-]/;
  var theend=/[a-zA-Z0-9]$/;
  var thestart=/^[a-zA-Z0-9]/;

  if (!hasadot.test(hostname) || l_hostname<7 || nasties.test(hostname) || !theend.test(hostname) || !thestart.test(hostname))
  {
    inputerr(fid,'Invalid host name or IP address.');
    return(-1);
  }
  else
  {
    inputok(fid);
    return(1);
  }
}

/*
   Validate nameservers form.
*/
function validateNSHostForm()
{
  /* Using our hosts - don't proceed with check. */
  if (document.getElementById('f-psel0').checked)
  {
    return true;
  }

  var result=0;
  result=result+validateNSHost('f-ns1');
  result=result+validateNSHost('f-ns2');
  result=result+validateNSHost('f-ns3');
  result=result+validateNSHost('f-ns4');
  result=result+validateNSHost('f-ns5');
  result=result+validateNSHost('f-ns6');

  /* 
     Variable result should have a value >=2, otherwise
     inadequate NSs have been provided.
  */
  if (result < 2)
  {
    return false;
  }

  return true;
}

/*
   Invoke validateRID() only if regidtype has
   been selected.
*/
function condValidateRID()
{
  var f_regid_type=document.getElementById('f-regid-type').value;
  if (f_regid_type>0)
  {
    validateRID();
  }
}

/*
   Validate registrant ID, registrant ID type.
*/
function validateRID()
{
  var f_regid_type=document.getElementById('f-regid-type').value;
  var f_regid=document.getElementById('f-regid').value;

  inputerrclear('f-regid-type');
  inputerrclear('f-regid');

  if (f_regid_type==0)
  {
    /*
       Value means that no ID type has been selected.
    */
    inputerr('f-regid-type','Registrant ID type must be selected.');
    return 1;
  }
  
  if (f_regid_type==1 || f_regid_type==2)
  {
    /* Strip spaces. */
    f_regid=f_regid.replace(/\s/g,"");
  }

  var f_regid_len=f_regid.length;
  
  if (f_regid_type==1 && f_regid_len!=11)
  {
    /* Wrong length for ABN */
    inputerr('f-regid','Incorrect length for ABN');
    return 1;
  }

  if (f_regid_type==2 && f_regid_len!=9)
  {
    /* Wrong length for ACN */
    inputerr('f-regid','Incorrect length for ACN');
    return 1;
  }

  inputok('f-regid');
  inputok('f-regid-type');
  return(0);
}

/*
   Validate eligibility type.
*/
function validateEType()
{
  var etype=document.getElementById('f-e_type').value;

  inputerrclear('f-e_type');

  if (etype==0)
  {
    inputerr('f-e_type','You must select a type of entity.');
    return(1);
  }
  else
  {
    inputok('f-e_type');
    return(0);
  }

}

function validateEReason()
{
  var r1=document.getElementById('f-e_reason1').checked;
  var r2=document.getElementById('f-e_reason2').checked;
  
  inputerrclear('f-ereasons');
  if (r1 || r2)
  {
    return(0);
  }
  else
  {
    inputerr('f-ereasons','You must select an eligibility reason');
    return(1);
  }
  
}

/*
   Validate eligibility form.
*/   
function validateEligForm()
{
  var numerrs=0;
  numerrs=numerrs+checkfinput('f-regname',2,'You must provide a registrant name.');
  numerrs=numerrs+validateRID();
  numerrs=validateEType();
  numerrs=validateEReason();

  if (numerrs>0)
  {
    return false;
  }

  return true;
}

function number_format (number, decimals, dec_point, thousands_sep) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');
    // *    returns 13: '100 050.00'
    // Strip all characters but numerical ones.
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}


