
tlds=new Array();
tlds['ad']=['Andorra'];
tlds['ae']=['United Arab Emirates'];
tlds['aero']=['Aircraft-related'];
tlds['af']=['Afghanistan'];
tlds['ag']=['Antigua and Barbuda'];
tlds['ai']=['Anguilla'];
tlds['al']=['Albania'];
tlds['am']=['Armenia'];
tlds['an']=['Netherland Antilles'];
tlds['ao']=['Angola'];
tlds['aq']=['Antarctica'];
tlds['ar']=['Argentina'];
tlds['arpa']=['Address and Routing Parameter Area'];
tlds['as']=['American Samoa'];
tlds['at']=['Austria'];
tlds['au']=['Australia'];
tlds['aw']=['Aruba'];
tlds['az']=['Azerbaijan'];
tlds['ba']=['Bosnia-Herzegovina'];
tlds['bb']=['Barbados'];
tlds['be']=['Belgium'];
tlds['bf']=['Burkina Faso'];
tlds['bg']=['Bulgaria'];
tlds['bh']=['Bahrain'];
tlds['bi']=['Burundi'];
tlds['biz']=['Business'];
tlds['bj']=['Benin'];
tlds['bm']=['Bermuda'];
tlds['bn']=['Brunei Darussalam'];
tlds['bo']=['Bolivia'];
tlds['br']=['Brazil'];
tlds['bs']=['Bahamas'];
tlds['bt']=['Bhutan'];
tlds['bw']=['Botswana'];
tlds['by']=['Belarus'];
tlds['bz']=['Belize'];
tlds['ca']=['Canada'];
tlds['cc']=['Cocos (Keeling) Islands'];
tlds['cd']=['Democratic Republic of Congo'];
tlds['cf']=['Central African Republic'];
tlds['cg']=['Congo'];
tlds['ch']=['Switzerland'];
tlds['ci']=['Ivory Coast'];
tlds['ck']=['Cook Islands'];
tlds['cl']=['Chile'];
tlds['cm']=['Cameroon'];
tlds['cn']=['China'];
tlds['co']=['Colombia'];
tlds['com']=['Commercial'];
tlds['coop']=['Cooperative-related'];
tlds['cr']=['Costa Rica'];
tlds['cu']=['Cuba'];
tlds['cv']=['Cape Verde'];
tlds['cx']=['Christmas Island'];
tlds['cy']=['Cyprus'];
tlds['cz']=['Czech Republic'];
tlds['de']=['Germany'];
tlds['dj']=['Djibouti'];
tlds['dk']=['Denmark'];
tlds['dm']=['Dominica'];
tlds['do']=['Dominican Republic'];
tlds['dz']=['Algeria'];
tlds['ec']=['Ecuador'];
tlds['edu']=['Educational'];
tlds['ee']=['Estonia'];
tlds['eg']=['Egypt'];
tlds['es']=['Spain'];
tlds['et']=['Ethiopia'];
tlds['fi']=['Finland'];
tlds['fj']=['Fiji'];
tlds['fk']=['Falkland Islands (Malvinas)'];
tlds['fm']=['Micronesia'];
tlds['fo']=['Faroe Islands'];
tlds['fr']=['France'];
tlds['ga']=['Gabon'];
tlds['gd']=['Grenada'];
tlds['ge']=['Georgia'];
tlds['gf']=['French Guyana'];
tlds['gh']=['Ghana'];
tlds['gi']=['Gibraltar'];
tlds['gl']=['Greenland'];
tlds['gm']=['Gambia'];
tlds['gn']=['Guinea'];
tlds['gov']=['Government'];
tlds['gp']=['Guadeloupe (French)'];
tlds['gq']=['Equatorial Guinea'];
tlds['gr']=['Greece'];
tlds['gt']=['Guatemala'];
tlds['gu']=['Guam (US)'];
tlds['gy']=['Guyana'];
tlds['hk']=['Hong Kong'];
tlds['hm']=['Heard and McDonald Islands'];
tlds['hn']=['Honduras'];
tlds['hr']=['Croatia (Hrvatska)'];
tlds['hu']=['Hungary'];
tlds['id']=['Indonesia'];
tlds['ie']=['Ireland'];
tlds['il']=['Israel'];
tlds['in']=['India'];
tlds['info']=['General-purpose tlds'];
tlds['int']=['International'];
tlds['io']=['British Indian Ocean Territory'];
tlds['ir']=['Islamic Republic of Iran'];
tlds['is']=['Iceland'];
tlds['it']=['Italy'];
tlds['jm']=['Jamaica'];
tlds['jo']=['Jordan'];
tlds['jp']=['Japan'];
tlds['ke']=['Kenya'];
tlds['kg']=['Kyrgyzstan'];
tlds['kh']=['Cambodia'];
tlds['ki']=['Kiribati'];
tlds['km']=['Comoros'];
tlds['kn']=['Saint Kitts Nevis Anguilla'];
tlds['kr']=['South Korea'];
tlds['kw']=['Kuwait'];
tlds['ky']=['Cayman Islands'];
tlds['kz']=['Kazakhstan'];
tlds['la']=['Laos'];
tlds['lb']=['Lebanon'];
tlds['lc']=['Saint Lucia'];
tlds['li']=['Liechtenstein'];
tlds['lk']=['Sri Lanka'];
tlds['lr']=['Liberia'];
tlds['ls']=['Lesotho'];
tlds['lt']=['Lithuania'];
tlds['lu']=['Luxembourg'];
tlds['lv']=['Latvia'];
tlds['ly']=['Libya (Libyan Arab Jamahiriya)'];
tlds['ma']=['Morocco'];
tlds['mc']=['Monaco'];
tlds['md']=['Moldavia'];
tlds['mg']=['Madagascar'];
tlds['mh']=['Marshall Islands'];
tlds['mil']=['US Military'];
tlds['ml']=['Mali'];
tlds['mm']=['Myanmar'];
tlds['mn']=['Mongolia'];
tlds['mo']=['Macau'];
tlds['mp']=['Northern Mariana Islands'];
tlds['mq']=['Martinique (French)'];
tlds['mr']=['Mauritania'];
tlds['ms']=['Montserrat'];
tlds['mt']=['Malta'];
tlds['mu']=['Mauritius'];
tlds['museum']=['Museum-related'];
tlds['mv']=['Maldives'];
tlds['mw']=['Malawi'];
tlds['mx']=['Mexico'];
tlds['my']=['Malaysia'];
tlds['mz']=['Mozambique'];
tlds['na']=['Namibia'];
tlds['name']=['Personal name'];
tlds['nc']=['New Caledonia (French)'];
tlds['ne']=['Niger'];
tlds['net']=['Network Infrastructure'];
tlds['nf']=['Norfolk Island'];
tlds['ng']=['Nigeria'];
tlds['ni']=['Nicaragua'];
tlds['nl']=['Netherlands'];
tlds['no']=['Norway'];
tlds['np']=['Nepal'];
tlds['nr']=['Nauru'];
tlds['nu']=['Niue'];
tlds['nz']=['New Zealand'];
tlds['om']=['Oman'];
tlds['org']=['Nonprofit'];
tlds['pa']=['Panama'];
tlds['pe']=['Peru'];
tlds['pf']=['French Polynesia'];
tlds['pf']=['Polynesia (French)'];
tlds['pg']=['Papua New Guinea'];
tlds['ph']=['Philippines'];
tlds['pk']=['Pakistan'];
tlds['pl']=['Poland'];
tlds['pm']=['Saint Pierre and Miquelon'];
tlds['pn']=['Pitcairn'];
tlds['pr']=['Puerto Rico (US)'];
tlds['pro']=['Professional domain'];
tlds['ps']=['Palestina'];
tlds['pt']=['Portugal'];
tlds['pw']=['Palau'];
tlds['py']=['Paraguay'];
tlds['qa']=['Qatar'];
tlds['re']=['Reunion (French)'];
tlds['ro']=['Romania'];
tlds['ru']=['Russian Federation'];
tlds['rw']=['Rwanda'];
tlds['sa']=['Saudi Arabia'];
tlds['sb']=['Solomon Islands'];
tlds['sc']=['Seychelles'];
tlds['se']=['Sweden'];
tlds['sg']=['Singapore'];
tlds['sh']=['Saint Helena'];
tlds['si']=['Slovenia'];
tlds['sk']=['Slovak Republic (Slovakia)'];
tlds['sl']=['Sierra Leone'];
tlds['sm']=['San Marino'];
tlds['sn']=['Senegal'];
tlds['so']=['Somalia'];
tlds['sr']=['Surinam'];
tlds['st']=['Saint Tome and Principe'];
tlds['su']=['Soviet Union'];
tlds['sv']=['El Salvador'];
tlds['sz']=['Swaziland'];
tlds['tc']=['Turks and Caicos Islands'];
tlds['td']=['Chad'];
tlds['tf']=['French Southern Territories'];
tlds['tg']=['Togo'];
tlds['th']=['Thailand'];
tlds['tj']=['Tajikistan'];
tlds['tk']=['Tokelau'];
tlds['tm']=['Turkmenistan'];
tlds['tn']=['Tunisia'];
tlds['to']=['Tonga'];
tlds['tp']=['East Timor'];
tlds['tr']=['Turkey'];
tlds['tt']=['Trinidad and Tobago'];
tlds['tv']=['Tuvalu'];
tlds['tw']=['Taiwan'];
tlds['tz']=['Tanzania'];
tlds['ua']=['Ukraine'];
tlds['ug']=['Uganda'];
tlds['uk']=['United Kingdom'];
tlds['us']=['United States of America'];
tlds['uy']=['Uruguay'];
tlds['uz']=['Uzbekistan'];
tlds['va']=['Vatican City State'];
tlds['vc']=['Saint Vincent and the Grenadines'];
tlds['ve']=['Venezuela'];
tlds['vg']=['Virgin Islands (British)'];
tlds['vi']=['Virgin Islands (US)'];
tlds['vn']=['Vietnam'];
tlds['vu']=['Vanuatu'];
tlds['ws']=['Samoa'];
tlds['ye']=['Yemen'];
tlds['yu']=['Yugoslavia'];
tlds['za']=['South Africa'];
tlds['zm']=['Zambia'];
tlds['zr']=['Zaire'];
tlds['zw']=['Zimbabwe'];

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function ValidEmail(email) 
{
  //minimum length 6: a@b.my
  if (email.length<7) {
    return false
  }
  
  //ensure only valid characters present
  valid_chars="@.-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  email=trimString(email);
  for (i=0; i<email.length; i++) {
    c=email.charAt(i)
    if (valid_chars.indexOf(c,0)==-1) {
      return false
    }
  }
  
  //must contain excatly one @
  email_parts=email.split("@");
  if (email_parts.length!=2) {
    return false;
  }
  
  //@ sign not at beginning or end.
  if ((email_parts[0]=="") || (email_parts[1]=="")) {
    return false;
  }
    
  //if username contains a period, it cannot be at the beginning, end or next to another
  //period
  username_parts=email_parts[0].split(".");
  for (i=0; i<username_parts.length; i++) {
    if (username_parts[i]=="") {
      return false;
    }
  }
  
  //the domain name is at least 4 characters (a@b.my)
  if (email_parts[1].length<5) {
    return false;
  }
  
  //must be at least one period in the domain
  domain_parts=email_parts[1].split(".");
  if (domain_parts.length<2) {
    return false;
  }
  
  //period not at the beginning or end or next to another period
  for (i=0; i<domain_parts.length; i++) {
    if (domain_parts[i]=="") {
      return false;
    }
  }
  
  //match against all known tld's
  tld=domain_parts[domain_parts.length-1];
  tld=tld.toLowerCase();
  if (!tlds[tld]) {
    return false;
  }
  
  return true
}


function VerifyDonateCard(formObj) 
{
   formObj=document.forms['donate'];

   nameField=formObj.name.value;
   address=formObj.address.value;
   zip=formObj.zip.value;
   country=formObj.country.value;
   email=formObj.email.value;
   telephone=formObj.telephone.value;
   amt_donate=formObj.amt_donate.value;
   delivery_address=formObj.delivery_address.value;
   delivery_postcode=formObj.delivery_zip.value;
   delivery_country=formObj.delivery_country.value;
   comment=formObj.comment.value;

  if (nameField=='') {
    alert('Please fill in the name');
    return false;
  }

  if (address=='') {
    alert('Please fill in the address');
    return false;
  }

  if (zip=='') {
    alert('Please fill in the zip/postal code');
    return false;
  }

  if (country=='0') {
    alert('Please select your country');
    return false;
  }

  if (email=='') {
    alert('Please fill in the email');
    return false;
  }

  if (!ValidEmail(email)) {
    alert('Invalid email address');
    return false;
  }


  if (formObj.amt_donate.selectedIndex < 0)
  {
    alert("Please select one of the \"Amount of donation\" options.");
    formObj.amt_donate.focus();
    return false;
  }

  if (formObj.amt_donate.selectedIndex == 0)
  {
    alert("Please select one of the \"Amount of donation\" options.");
    formObj.amt_donate.focus();
    return false;
  }

  if (formObj.amt_donate.value=='33') {
    card1=formObj.cat_1.value;
    if (card1=='') {
      alert('Please fill in the name for Catholic Card 1');
      formObj.cat_1.focus();
      return false;
    } 
  }
  if (formObj.amt_donate.value=='130') {
    card1=formObj.cat_1.value;
    card2=formObj.cat_2.value;
    card3=formObj.cat_3.value;
    card4=formObj.cat_4.value;
    card5=formObj.cat_5.value;

    if (card1=='') {
      alert('Please fill in the name for Catholic Card 1');
      formObj.cat_1.focus();
      return false;
    }

    if (card2=='') {
      alert('Please fill in the name for Catholic Card 2');
      formObj.cat_2.focus();
      return false;
    }

    if (card3=='') {
      alert('Please fill in the name for Catholic Card 3');
      formObj.cat_3.focus();
      return false;
    }

    if (card4=='') {
      alert('Please fill in the name for Catholic Card 4');
      formObj.cat_4.focus();
      return false;
    }

    if (card5=='') {
      alert('Please fill in the name for Catholic Card 5');
      formObj.cat_5.focus();
      return false;
    }
  }

  if (delivery_address=='') {
    alert('Please fill in the delivery address');
    return false;
  }

  if (delivery_postcode=='') {
    alert('Please fill in the delivery postcode');
    return false;
  }

  if (delivery_country=='') {
    alert('Please fill in the delivery country');
    return false;
  }


  formObj.action=__BASE_URL__+"/php/donate_card_process.php";

  formObj.submit();
  return;

}


function VerifyDonate(formObj) 
{
   formObj=document.forms['donate'];

   nameField=formObj.name.value;
   address1=formObj.address1.value;
   address2=formObj.address2.value;
   city=formObj.city.value;
   state=formObj.state.value;
   zip=formObj.zip.value;
   country=formObj.country.value;
   email=formObj.email.value;
   telephone=formObj.telephone.value;
   amt_donate=formObj.amt_donate.value;
   other_amt=formObj.other_amt.value;
   comment=formObj.comment.value;

  if (nameField=='') {
    alert('Please fill in the name');
    return  false;
  }

  if (country==''||formObj.country.selectedIndex < 0) {
    alert('Please fill in the country');
    return  false;
  }

  if (email=='') {
    alert('Please fill in the email');
    return false;
  }

  if (!ValidEmail(email)) {
    alert('Invalid email address');
    return false;
  }


  if (formObj.amt_donate.selectedIndex < 0)
  {
    alert("Please select one of the \"Donation amount\" options.");
    formObj.amt_donate.focus();
    return false;
  }

  if (formObj.amt_donate.selectedIndex == 0)
  {
    alert("The first \"Donation amount\" option is not a valid selection.  Please choose one of the other options.");
    formObj.amt_donate.focus();
    return false;
  }

  if (formObj.amt_donate.selectedIndex > 0)
  {
    if (formObj.amt_donate.value!='other') {
    if (formObj.other_amt.value!="") {
      alert("Please do not fill in the value in \"Other Amount\" field.");
      formObj.other_amt.focus();
      return false;
     }
    } 
  }
  

if (formObj.amt_donate.value == 'other')
{
  if (formObj.other_amt.value=="") {
    alert("Please enter a valid value in the \"Other Amount\" field.");
    formObj.other_amt.focus();
    return false;
   }

}

if (formObj.amt_donate.value == 'other')
{
  var checkOK = "0123456789-.";
  var checkStr = formObj.other_amt.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else
      allNum += ch;
  }

  

  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Donation Amount\" field.");
    formObj.other_amt.focus();
    return false;
  }

  if (decPoints > 1)
  {
    alert("Please enter a valid number in the \"Other Amount\" field.");
    formObj.other_amt.focus();
    return false;
  }

  var countPrecision=new Array();
  string=formObj.other_amt.value;
  if (string.indexOf(".")!=-1) {
     countPrecision=string.split('.'); 
     if((countPrecision[1].length>2) ||(countPrecision[1].length<=1)) {
       alert("Please enter a valid number in the \"Other Amount\" field.");
       formObj.other_amt.focus();
       return false;
    }
  }


 if (formObj.other_amt.value=="0.00") {
  alert("Please enter a correct value in the \"Other Amount\" field.");
  formObj.other_amt.focus();
  return false;
 }


}

 

  formObj.action=__BASE_URL__+"/php/donate_process.php";

  formObj.submit();
  return;

}


function LimitTextArea(field, maxLimit)
{
  if (field.value.length > maxLimit) {
    field.value = field.value.substring(0, maxLimit);
  }
}

function Clear(formObj)
{
   formObj=document.forms['donate'];

   formObj.name.value='';
   formObj.address.value='';
   formObj.zip.value='';
   formObj.country.value='';
   formObj.email.value='';
   formObj.telephone.value='';
   formObj.other_amt.value='';
   formObj.comment.value='';
   formObj.delivery_address.value='';
   formObj.delivery_zip.value='';
   formObj.delivery_country.value='';
}

function Update()
{
  if (document.forms[0].same.checked == true)
  {
    document.forms[0].delivery_address.value = document.forms[0].address.value;
    document.forms[0].delivery_zip.value = document.forms[0].zip.value;
    document.forms[0].delivery_country.value = document.forms[0].country.value;
    return true;
  } else {
    document.forms[0].delivery_address.value ='';
    document.forms[0].delivery_zip.value ='';
    document.forms[0].delivery_country.value ='0';
    return true;
  }
}

function VerifyForm() 
{
   formObj=document.forms['form1'];

   nameField=formObj.name.value.trim();
   email=formObj.email.value.trim();
   comments=formObj.comments.value.trim();

  if (nameField=='') {
    alert('Please fill in the name');
    return false;
  }

  if (email=='') {
    alert('Please fill in the email');
    return false;
  }

  if (!ValidEmail(email)) {
    alert('Invalid email address');
    return false;
  }

   if (comments=='') {
    alert('Please fill in the comment');
    return false;
  }

  if (formObj.security_code.value.trim()=="") {
    alert("You need to enter the code shown to verify your testimonial.");
    return false;
  }

//   formObj.submit();
//   return true;

}

function VerifyContact(formObj) 
{
   formObj=document.forms['form1'];

   nameField=formObj.name.value.trim();
   email=formObj.email.value.trim();
   comments=formObj.comments.value.trim();

  if (nameField=='') {
    alert('Please fill in the name');
    return  false;
  }

  if (email=='') {
    alert('Please fill in the email');
    return false;
  }

  if (!ValidEmail(email)) {
    alert('Invalid email address');
    return false;
  }

   if (comments=='') {
    alert('Please fill in the comment');
    return false;
  }

  if (formObj.security_code.value.trim()=="") {
    alert("You need to enter the code shown to verify your comment.");
    return false;
  }

/*  formObj.action=__BASE_URL__+"/php/success_contact.php";*/
//   return;

}



function ReadCookie(name)
{
  var nameEQ=name+"=";
  var ca=document.cookie.split(';');
  for (var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
  }
  return null;
}

function CreateCookie(name,value,days)
{
 if (days) {
    var date=new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else {
    var expires = "";
  }
  document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function EraseCookie(name)
{
  CreateCookie(name,"",-365);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}