function removeImage(thisform) {
 document.directorysignup.logofile.filename = '';
 document.directorysignup.logofile.value = '';
 document.directorysignup.currentlogo.value = 'There is no image file.';
 return true;
}
function newImage(thisform) {
 document.directorysignup.currentlogo.value = document.directorysignup.logofile.value;
 return true;
}
function makeVisible() {
 var tb = document.getElementById('table');
 tb.className='dsu_table_visible';
 var ct = document.getElementById('closetable');
 ct.className='dsu_userlink_right';
 return true;
}
function makeHidden() {
 var tb = document.getElementById('table');
 tb.className='dsu_table_hidden';
 var ct = document.getElementById('closetable');
 ct.className='dsu_userlink_right_hidden';
 return true;
}
function makeLangVisible(langbox,langlist) {
 var obj = document.getElementById(langbox);
 obj.className='dsu_show';
 var name = langbox+"1";
 var obj = document.getElementById(name);
 if (document.forms['directorysignup'].elements[langlist].options.length > 1) {
   obj.className='dsu_show';
 }
 else {
   obj.className='dsu_no_show';
 }
 return true;
}
function deleteLang(langbox,langindex) {
 var obj = document.getElementById(langbox);
 obj.className='dsu_no_show';
 
 if (langindex > 0) {
  document.forms['directorysignup'].elements['languagelist'+langindex].selectedIndex = 0;
  document.forms['directorysignup'].elements['languagelist'+langindex].options[0].selected = "true";
  document.forms['directorysignup'].elements['lang_name'+langindex].value ="";
  document.forms['directorysignup'].elements['lang_short_description'+langindex].value ="";
  document.forms['directorysignup'].elements['lang_long_description'+langindex].value ="";
 }
 return true;
}
function ucwords (str) {
 return str.replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase ( ); } );
}
var countryLangArray = [];
var langTransArray = [];
function languageList(value,lang) {
 value = value.replace( '_', ' ' );
 var country = "";
 switch (value) {
  case 'uk': country = 'UK'; break;
  case 'usa': country= 'USA'; break;
  default: country = ucwords(value);
 }
 createCountryLangArray();
 createLangTransArray();
 document.forms['directorysignup'].languagelist.options.length = 0;
 document.forms['directorysignup'].languagelist.options[0] = new Option('Choose language','Choose language');
 if (country != 'Choose Country') { 
  var optionList = new Array();
  for (i = 0; i < countryLangArray[country].length; i++) {
   optionList[i] = countryLangArray[country][i];
   switch (lang) {
    case 'deutsch': optionList[i] = langTransArray[countryLangArray[country][i]][0]; break;
    case 'espanol': optionList[i] = langTransArray[countryLangArray[country][i]][1]; break;
    case 'francais': optionList[i] = langTransArray[countryLangArray[country][i]][2]; break;
    case 'italiano': optionList[i] = langTransArray[countryLangArray[country][i]][3]; break;
    case 'nederlands': optionList[i] = langTransArray[countryLangArray[country][i]][4]; break;
    case 'polski': optionList[i] = langTransArray[countryLangArray[country][i]][5]; break;
    case 'portugues': optionList[i] = langTransArray[countryLangArray[country][i]][6]; break;
   }
  }
  optionList.sort();
  for (i = 0; i < optionList.length; i++) {
   document.forms['directorysignup'].languagelist.options[i+1] = new Option(optionList[i],optionList[i]);
  }

  if (countryLangArray[country].length > 1) {
   var obj = document.getElementById('langbox');
   obj.className='dsu_show';
  }
  else {
   var obj = document.getElementById('langbox');
   obj.className='dsu_no_show';
  }
 }
 
 document.forms['directorysignup'].elements['languagelist1'].options.length = 0;
 document.forms['directorysignup'].elements['languagelist1'].options[0] = new Option('Add another language','Add another language');
 deleteLang('langbox1','1');
 document.forms['directorysignup'].elements['languagelist2'].options.length = 0;
 document.forms['directorysignup'].elements['languagelist2'].options[0] = new Option('Add another language','Add another language');
 deleteLang('langbox2','2');
 document.forms['directorysignup'].elements['languagelist3'].options.length = 0;
 document.forms['directorysignup'].elements['languagelist3'].options[0] = new Option('Add another language','Add another language');
 deleteLang('langbox3','3');
 document.forms['directorysignup'].elements['languagelist4'].options.length = 0;
 document.forms['directorysignup'].elements['languagelist4'].options[0] = new Option('Add another language','Add another language');
 deleteLang('langbox4','4');
 document.forms['directorysignup'].elements['languagelist5'].options.length = 0;
 document.forms['directorysignup'].elements['languagelist5'].options[0] = new Option('Add another language','Add another language');
 deleteLang('langbox5','5');
 document.forms['directorysignup'].elements['languagelist6'].options.length = 0;
 document.forms['directorysignup'].elements['languagelist6'].options[0] = new Option('Add another language','Add another language');
 deleteLang('langbox6','6');
}
function addLanguageList(lang) {
 var selectedCountry = document.forms['directorysignup'].countrylist.options[document.forms['directorysignup'].countrylist.selectedIndex].value;
 var country = "";
 switch (selectedCountry) {
  case 'uk': country = 'UK'; break;
  case 'usa': country= 'USA'; break;
  default: country = ucwords(selectedCountry);
 }
 createCountryLangArray();
 createLangTransArray();
 doLanguageList(countryLangArray, langTransArray, country, 'languagelist1', 1, lang);
 doLanguageList(countryLangArray, langTransArray, country, 'languagelist2', 2, lang);
 doLanguageList(countryLangArray, langTransArray, country, 'languagelist3', 3, lang);
 doLanguageList(countryLangArray, langTransArray, country, 'languagelist4', 4, lang);
 doLanguageList(countryLangArray, langTransArray, country, 'languagelist5', 5, lang);
 doLanguageList(countryLangArray, langTransArray, country, 'languagelist6', 6, lang);
}
function doLanguageList(countryLangArray, langTransArray, country, langlist, langindex, lang) {
 document.forms['directorysignup'].elements[langlist].options.length = 0;
 document.forms['directorysignup'].elements[langlist].options[0] = new Option('Add another language','Add another language');
 document.forms['directorysignup'].elements['lang_name'+langindex].value ="";
 document.forms['directorysignup'].elements['lang_short_description'+langindex].value ="";
 document.forms['directorysignup'].elements['lang_long_description'+langindex].value ="";

 if (country != 'Choose Country') {
  if (countryLangArray[country].length > langindex) {
   var optionList = new Array();
   for (i = 0; i < countryLangArray[country].length; i++) {
    optionList[i] = countryLangArray[country][i];
    switch (lang) {
     case 'deutsch': optionList[i] = langTransArray[countryLangArray[country][i]][0]; break;
     case 'espanol': optionList[i] = langTransArray[countryLangArray[country][i]][1]; break;
     case 'francais': optionList[i] = langTransArray[countryLangArray[country][i]][2]; break;
     case 'italiano': optionList[i] = langTransArray[countryLangArray[country][i]][3]; break;
     case 'nederlands': optionList[i] = langTransArray[countryLangArray[country][i]][4]; break;
     case 'polski': optionList[i] = langTransArray[countryLangArray[country][i]][5]; break;
     case 'portugues': optionList[i] = langTransArray[countryLangArray[country][i]][6]; break;
    }
   }
   optionList.sort();
   for (i = 0; i < optionList.length; i++) {
    document.forms['directorysignup'].elements[langlist].options[i+1] = new Option(optionList[i],optionList[i]);
   }
  }
 }
}
function fillBillingAddress() {
 document.directorysignup.billingstreet.className = 'dsu_basicinput';
 document.directorysignup.billingcity.className = 'dsu_basicinput_short';
 document.directorysignup.billingcounty.className = 'dsu_basicinput_short';
 document.directorysignup.billingpostal_code.className = 'dsu_basicinput_short';
 document.directorysignup.billingcountry.className = 'dsu_basicinput_short';
 var obj = document.getElementById('bill1');
 obj.className = '';
 var obj = document.getElementById('bill2');
 obj.className = '';
 var obj = document.getElementById('bill3');
 obj.className = '';
 var obj = document.getElementById('bill4');
 obj.className = '';
 var obj = document.getElementById('bill5');
 obj.className = '';
 document.directorysignup.billingstreet.value = document.directorysignup.street.value;
 document.directorysignup.billingcity.value = document.directorysignup.city.value;
 document.directorysignup.billingcounty.value = document.directorysignup.county.value;
 document.directorysignup.billingpostal_code.value = document.directorysignup.postal_code.value;
 document.directorysignup.billingcountry.value = document.directorysignup.country.value;
}
function clearBillingAddress() {
 document.directorysignup.billingstreet.className = 'dsu_basicinput';
 document.directorysignup.billingcity.className = 'dsu_basicinput_short';
 document.directorysignup.billingcounty.className = 'dsu_basicinput_short';
 document.directorysignup.billingpostal_code.className = 'dsu_basicinput_short';
 document.directorysignup.billingcountry.className = 'dsu_basicinput_short';
 var obj = document.getElementById('bill1');
 obj.className = '';
 var obj = document.getElementById('bill2');
 obj.className = '';
 var obj = document.getElementById('bill3');
 obj.className = '';
 var obj = document.getElementById('bill4');
 obj.className = '';
 var obj = document.getElementById('bill5');
 obj.className = '';
 document.directorysignup.billingstreet.value = '';
 document.directorysignup.billingcity.value = '';
 document.directorysignup.billingcounty.value = '';
 document.directorysignup.billingpostal_code.value = '';
 document.directorysignup.billingcountry.value = '';
}
function hideVAT() {
 document.directorysignup.vatnumber.className = 'dsu_basicinput_short_hidden';
 var obj = document.getElementById('div1');
 obj.className = 'z_bookmarks_hidden';
 var obj = document.getElementById('bill6');
 obj.className = 'dsu_hidden';
}
function showVAT() {
 document.directorysignup.vatnumber.className = 'dsu_basicinput_short';
 var obj = document.getElementById('div1');
 obj.className = 'dsu_section_body_indent';
 var obj = document.getElementById('bill6');
 obj.className = 'dsu_indent';
 document.directorysignup.vatnumber.className = 'dsu_basicinput_short_margin';
 document.directorysignup.vatnumber.value = '';
}
function num2money(n_value) {
 // validate input
 if (isNaN(Number(n_value)))
 return '0';

 // save the sign
 var b_negative = Boolean(n_value < 0);
 n_value = Math.abs(n_value);

 // round to 1/100 precision, add ending zeroes if needed
 var s_result = String(Math.round(n_value*1e2)%1e2 + '00').substring(0,2);

 // separate all orders
 var b_first = true;
 var s_subresult;
 while (n_value > 1) {
  s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value%1e3);
  s_result = s_subresult.slice(-3) + (b_first ? '.' : '.') + s_result;
  b_first = false;
  n_value = n_value/1e3;
 }
 // add at least one integer digit
 if (b_first) s_result = '0.' + s_result;

 // apply formatting and return
 return b_negative ? '(' + s_result + ')' : s_result;
}
function calcInvoice() {
 var listing_value = 0.00;
 var additional_value = 0.00;
 var tot_listing_value = 0.00;
 var promo_value = 0.00;
 var subtotal_value = 0.00;
 var vat_perc = 0.00;
 var total_value = 0.00;

 if (validateCalc()) {
 // main listing price
 if (document.directorysignup.listing[0].checked) {
  listing_value = 195.00;
 }
 else if (document.directorysignup.listing[1].checked) {
  listing_value = 95.00;
 }
 else if (document.directorysignup.listing[2].checked) {
  listing_value = 45.00;
 }
 //addisional categories
 for (i = 1; i <= clist; i++) {
  var name = 'name' + i;
  var ni = document.getElementById(name);
  if (ni != null) {
   additional_value = additional_value + (listing_value / 2);
  }
 }

 // vat percentage
 if (document.directorysignup.vat[1].checked && document.directorysignup.vatnumber.value === "") {
  vat_perc = 0.16;
 }
 // promotional code
 var promo_code = document.directorysignup.promo.value;
 // valid code is 3 letters followed by a number -- e.g. KLM173
 // then discount = (the number - 137) / 3
 if (promo_code.match(/^[a-z]{3}[0-9]{3}$/i)) {
  promo_num = promo_code.replace(/^[a-z]{3}/i,'');
  promo_value = (promo_num - 137) / 3;
 }

 // all subtotals and totals for the labels
 tot_listing_value = listing_value + additional_value;
 promo_value = tot_listing_value * (promo_value / 100);
 subtotal_value = tot_listing_value - promo_value;
 vat_value = subtotal_value * vat_perc;
 total_value = subtotal_value + vat_value;
 var obj = document.getElementById('invoice_listing');
 obj.innerHTML = num2money(listing_value);
 document.directorysignup.invoice_listing.value = num2money(listing_value);
 var obj = document.getElementById('invoice_additional');
 obj.innerHTML = num2money(additional_value);
 document.directorysignup.invoice_additional.value = num2money(additional_value);
 var obj = document.getElementById('invoice_tot_listing');
 obj.innerHTML = num2money(tot_listing_value);
 document.directorysignup.invoice_tot_listing.value = num2money(tot_listing_value);
 var obj = document.getElementById('invoice_discount');
 obj.innerHTML = num2money(promo_value);
 document.directorysignup.invoice_discount.value = num2money(promo_value);
 var obj = document.getElementById('invoice_subtotal');
 obj.innerHTML = num2money(subtotal_value);
 document.directorysignup.invoice_subtotal.value = subtotal_value.toFixed(2);
 var obj = document.getElementById('invoice_vat');
 obj.innerHTML = num2money(vat_value);
 document.directorysignup.invoice_vat.value = num2money(vat_value);
 var obj = document.getElementById('invoice_total');
 obj.innerHTML = num2money(total_value);
 document.directorysignup.invoice_total.value = num2money(total_value);

 //make box visible
 var obj = document.getElementById('invoicebox');
 obj.className = "dsu_show";
 }
 
}
function popup(mylink, windowname)
{
 if (! window.focus)return true;
 var href;
 if (typeof(mylink) == 'string')
  href=mylink;
 else
  href=mylink.href;
 window.open(href, windowname, 'width=540,height=500,resizable=yes,scrollbars=yes');
 return false;
}

// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.

// SETUPS:
// ===============================


// Do not edit below this line...
// ================================
function popImage(imageURL,imageTitle){
 var PositionX = 100;
 var PositionY = 100;
 var defaultWidth  = 530;
 var defaultHeight = 700;
 var AutoClose = false;
 if (parseInt(navigator.appVersion.charAt(0))>=4){
  var isNN=(navigator.appName=="Netscape")?1:0;
  var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
 }
 var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
 var optIE='scrollbars=yes,width=150,height=100,left='+PositionX+',top='+PositionY;
 if (isNN){imgWin=window.open('about:blank','',optNN);}
 if (isIE){imgWin=window.open('about:blank','',optIE);}
 with (imgWin.document){
  writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
  writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
  writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
  writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
  writeln('width=300-(document.body.clientWidth-document.images[0].width);');
  writeln('height=300-(document.body.clientHeight-document.images[0].height);');
  writeln('window.resizeTo(530,700);}');writeln('if (isNN){');
  writeln('window.innerWidth=document.images["George"].width+20;');writeln('window.innerHeight=700;}}');
  writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
  if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="yes" onload="reSizeToImage();doTitle();self.focus()">')
  else writeln('</head><body bgcolor=000000 scroll="yes" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
  writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
  close();
 }
}
function validateCalc(){
 var why = "";
 if (document.directorysignup.listing[0].checked == false && document.directorysignup.listing[1].checked == false && document.directorysignup.listing[2].checked == false) why += "Please select a directory listing type.\n";
 if (document.directorysignup.vat[0].checked == false && document.directorysignup.vat[1].checked == false) why += "Please select a VAT type.\n";
 if (why != "") {
  alert(why);
  return false;
 }
 return true;
}

function validateForm(){
 var why = "";
 if (document.forms['directorysignup'].countrylist.selectedIndex === 0) why += "Please choose a country.\n";
 if (document.forms['directorysignup'].languagelist.selectedIndex === 0) why += "Please choose a language.\n";
 if (trim(document.directorysignup.name.value) == "") why += "Please enter the name of your company/institution.\n";
 if (trim(document.directorysignup.short_description.value) == "") why += "Please enter a short description.\n";
 if (trim(document.directorysignup.email.value) == "") why += "Please enter your email.\n";
 if (document.directorysignup.listing[0].checked == false && document.directorysignup.listing[1].checked == false && document.directorysignup.listing[2].checked == false) why += "Please select a directory listing type.\n";
 if (document.forms['directorysignup'].categorylist.selectedIndex === 0) why += "Please choose a listing category.\n";
 if (trim(document.directorysignup.companyinvoice.value) == "") why += "Please enter the name of company name for the invoice.\n";
 if (trim(document.directorysignup.billingstreet.value) == "" || trim(document.directorysignup.billingcity.value) == "" || trim(document.directorysignup.billingpostal_code.value) == "" || trim (document.directorysignup.billingcountry.value) == "" ||  trim (document.directorysignup.billingcontact.value) == "" ||  trim (document.directorysignup.billingemail.value) == "" ) why += "Please complete the billing address information.\n";
 if (document.directorysignup.vat[0].checked == false && document.directorysignup.vat[1].checked == false) why += "Please select a VAT type.\n";
 if (document.directorysignup.confirmation.checked == false) why += "Please confirm the terms and conditions.\n";
 if (why != "") {
  alert(why);
  return false;
 }
 return true;
}
