

function price(product,country) {
  inum = itemnum(product);
  if (country == defaultCountry) inum = -1;
  cnum = countrynum(country);
  return (inum > -1 && cnum > -1) ? items[inum][cnum] : "NA" ;
  }
  
function writePrice(product,country) {
  document.write(price(product,country));
  }

  
function tax(country) {
  cnum = countrynum(country);
  return (cnum > -1) ? countries[cnum].tax : "";
}

function writeTax(country) {
  document.write(tax(country));
  }

  
function currency(country) {
  cnum = countrynum(country);
  return (cnum > -1) ? countries[cnum].currency : "";
  }

function writeCurrency(country) {
  document.write(currency(country));
}


function addCookie(thing,cookie_name) {
   document.cookie="/"+cookie_name+"="+escape(thing);
}


function rCookiesOn() {
var hascookie = 2;
if (!document.cookie){
  cookie_name = "PalmCurrentCountry";
  document.cookie=cookie_name+"=; path=/";
  (!document.cookie)?hascookie = 0:hascookie=1; 
}
return hascookie;
}

 


function CookieWarning() {
  if (rCookiesOn()==0) {
  var noCookies = window.open("/asia/cookies.html","NoCookies","HEIGHT=450,WIDTH=625,status=0,resizable=0,scrollbars=1,menubar=0");
}
}


/*
function CookieWarning() {
if (rCookiesOn() ==  0) {
  var noCookies = window.open("","NoCookies","HEIGHT=400,WIDTH=300,status=0,resizable=1,scrollbars=1,menubar=0");
 with (noCookies.document) {
 write('<HEAD><TITLE>You need Cookies</TITLE></HEAD>\n<BODY BGCOLOR="#FFFFFF">\n<CENTER>\n');

 write ('<B>This site requires your browser to accept "cookies". Otherwise you will only not see price details.</B></A><P>You can control cookies using the browser\'s preferences\n');
 write('<FORM><INPUT TYPE="Button" VALUE="Close this Window" onClick="self.close();"></FORM>\n');
 write('</CENTER></BODY>\n</HTML>\n');
 close();
 }
 }
 return true;
 }
*/




 function getCookieValue(cookie_name) {
var cv="";
  if(document.cookie)
   {
        index = document.cookie.indexOf(cookie_name+"=");
        if (index != -1)
     {
           	namestart = (document.cookie.indexOf("=", index) + 1);
            nameend = document.cookie.indexOf(";", index);
            if (nameend == -1) {nameend = document.cookie.length;}
            cv = document.cookie.substring(namestart, nameend);     
          
		
           }
           }
return cv;

}

function eatCookie(cookie_name) {
if(document.cookie) {
        index = document.cookie.indexOf(cookie_name);
        if (index != -1) document.cookie=cookie_name+"=";
    }
}


function rememberCountry() {
 var country = unescape(getCookieValue("PalmCurrentCountry"));
 if (countrynum(country) == -1) country = defaultCountry;
 return country;
}

function rememberProduct() {
 var product= unescape(getCookieValue("PalmCurrentProduct"));
 if (product =="undefined") product = "";
 return product;
}

function rememberDealer() {
 var dealer= unescape(getCookieValue("PalmCurrentDealer"));
 if (dealer =="undefined") dealer = "";
 return dealer;
}

function storeCountry(country) {
//document.cookie="PalmCurrentCountry="+escape(country)+"; path=/"; 
 currentCountry = country;
}

function storeProduct(product) {
 document.cookie="PalmCurrentProduct="+escape(product)+"; path=/"; 
}

function storeDealer(dealer) {
 document.cookie="PalmCurrentDealer="+escape(dealer)+"; path=/"; 
}

function forgetCountry() {
  eatCookie("PalmCurrentCountry");
}

function forgetProduct() {
 eatCookie("PalmCurrentProduct");
}

function countrynum(code) {
  var num = -1;
  code = unescape(code);
  if (isint(code) == false) {
      code = code.toUpperCase();
     for (var i=0; i< nctry; i++)  {
      if (countries[i].abbrev.toUpperCase() == code) num = i;
     }
   } //if
  return num;
 } 




function itemnum(code) {
  var num = -1;
  if (isint(code) == false) {
      code = code.toUpperCase();
     for (var i=0; i< nitems; i++)  if (items[i][0].toUpperCase() == code) num = i;
   } //if
   else {
   num = code;
   }
  return num;
 } 
 
  function isint(num) {
    if ( (num == "") || (num <=0) ) {
        return false;
    }
    for (var i=0; i < num.length; i++) {
       var ch= num.substring (i, i+1)
       if (ch < "0" || ch > "9" ) {
       	            return false;
       }
    }
    return true;
}

function ap_goIndex(country) {
 storeCountry(country);
 location.href = "/asia/";

}

function ap_go(country) {
storeCountry(country);
location.replace(location.href)
}

function countryDef(name,abbrev,graphic,currency,tax,cicphone,cicfax,cicemail,tsphone,tsfax,tsemail,ssurl,cgi) {
    this.name = name;
    this.abbrev = abbrev;
    this.graphic =  graphic;
    this.currency= currency;
    this.tax = tax;
    this.cicphone = cicphone;
    this.cicfax = cicfax;
    this.cicemail = cicemail;
    this.tsphone = tsphone;
    this.tsfax = tsfax;
    this.tsemail = tsemail;
    this.ssurl = ssurl;
    this.cgi = cgi;
 }

function addcountry (name,abbrev,graphic,currency,tax,cicphone,cicfax,cicemail,tsphone,tsfax,tsemail,ssurl,cgi) {
  countries[nctry] = new countryDef(name,abbrev,graphic,currency,tax,cicphone,cicfax,cicemail,tsphone,tsfax,tsemail,ssurl,cgi);
  nctry++;
 }


//If you add countries or change their order, adjust these arguments

function itemDef() {
this.product = arguments[0];
}

//use arguments array here to allow for any number of countries to be passed
function additem() {
  items [nitems] = new Array;
  items[nitems] = arguments;
  nitems++;
}
 
function countryGraphic(country) {
var ctrynum = countrynum(country);
var ctrygif = "http://www.palmone.com/asia/images/country/country_00_asp.gif";
if (ctrynum > -1) var ctrygif ="http://www.palmone.com/asia/images/country/"+ countries[ctrynum].graphic;
return ctrygif;
}


 
  
function writeProductsLike(country,product) {
  var uprod = product.toUpperCase();
  var col = countrynum(country);
   col++;
  if(col > 0) {
  with (document) {
  write('<TR><TD><B>Product</B></TD><TD align="middle"><B>'+currency(country)+'<BR>'+tax(country)+'</B></TD></TR>\n');
  for(var i=0;i<nitems;i++) {
  uproduct = items[i][0].toUpperCase();
  if ((uproduct.indexOf(uprod) > -1) || (uprod =="")) {
  write('<TR>');
   write('<TD>'+items[i][0]+'</TD>');
   write('<TD>'+items[i][col]+'</TD>');
   write('</TR>\n');
  
 // write('</TABLE>\n'); can put own table structure around this
  }//if
  } //for
  } //with
  } //if
  }
  function dealerDef(Name,Address,Zone,Country,Phone,Fax,URL) {
  this.name = Name;
  this.address = Address;
  this.zone = Zone;
  this.country = Country;
  this.phone = Phone;
  this.fax = Fax;
  this.url = URL;

  }
  
   function getStored(fname) {
    sep = "&&";
   data = new Array;
  var output="";
  data[0]="";
  data[1]="";
  data[2]="";
  data[3]="";
  data[4]=0;
  sep = "&&";
  vals = rememberDealer()
  if (vals!="") {
     data=vals.split(sep);
     if (fname == "reseller") {output = data[0];}
     if (fname == "zone") {output = data[1];}
     if (fname == "address") {output = data[2];}
     if (fname == "phone") {output = data[3];}
     if (fname == "firstDealer") {output = data[4];}
  }
  else {
  bcookie = sep + sep + sep+ sep;
   storeDealer(bcookie);
  }
  return output;
}
 
  function addDealer (Name,Address,Zone,Country,Phone,Fax,URL) {
 lcname =Name.toLowerCase();
  lczone = Zone.toLowerCase();
  lcaddress = Address.toLowerCase();
  lcphone = Phone.toLowerCase();
  ctrynum = countrynum(currentCountry);
  if(ctrynum >0) currentCountryname = countries[ctrynum].name;
  
 if (
      (Country == currentCountryname)  
  && ((lcname.indexOf(stname) > -1) || (stname ==""))
  && ((lczone.indexOf(stzone) > -1) || (stzone ==""))
  && ((lcaddress.indexOf(staddress) > -1) || (staddress =="")) 
  && ((lcphone.indexOf(stphone) > -1) || (stphone ==""))
  )
 {
  dealers[ndealers] = new dealerDef(Name,Address,Zone,Country,Phone,Fax,URL);
  ndealers++;
  }
  }
  /*
  function writeDealerTable(country) {
  var curstate = "";
  var dct = 0;
  with (document) {
 // write('<TABLE>\n'; can put own table structure around this
  for(var i=0;i<ndealers;i++) {
  if (dealers[i].country == country) {
  write('<TR>');
  
   if ((dealers[i].state != curstate) && (dealers[i].state != "")) {
   write('<TD colspan=2>&nbsp;</TD></TR>\n');
   firsttd= '<B>'+dealers[i].state+'</B>';
   curstate = dealers[i].state;
   }  //if
   else {
   firsttd = "&nbsp;";
   }
   dct++;
   write('<TR><TD>'+firsttd+'</TD>');
   (dealers[i].url == "") ? write('<TD>'+dealers[i].name+'</TD>') : write('<TD><A HREF="'+dealers[i].url+'">'+dealers[i].name+'</A></TD>');
   write('</TR>');
  
 // write('</TABLE>\n'); can put own table structure around this
  } //if
  } //for
  if (dct==0) write('<TR><TD>&nbsp;</TD><TD><B>Your local resellers list is temporarily unavailable while being updated.</B></TD></TR>\n');
  } //with
  }
*/

//Global Variables set as javascript opens
var nitems = 0;
var nctry = 0;
var ndealers = 0;
var currentDealersct = 0;


items = new Array;
countries = new Array;
dealers = new Array;


/* START COUNTRY DATA */
/* Country,code,logo image,currency,tax note,contact phone,contact fax,contact email,tech phone,tech fax,tech email,Secured WEB SRO, */

addcountry('Asia Pacific','AP','cid_Asia_Pacific.gif','','Please select a country first','','','asia.service@palm.com','65 6784 9805','852 301 58614','techsupport@palm-asia.com','/asia/support/sro/option.html','apsupport.cgi');
addcountry('Singapore','SG','cid_Singapore.gif','','','','','asia.service@palm.com','65 6784 9805','852 301 58614','techsupport@palm-asia.com','https://www.service.palmdirect.com/service/SGP/EE','apsupport.cgi');
addcountry('Malaysia','MY','cid_Malaysia.gif','','','','','asia.service@palm.com','1800 80 1627','852 301 58614','techsupport@palm-asia.com','https://www.service.palmdirect.com/service/MYS/EE','apsupport.cgi');
addcountry('Thailand','TH','cid_Thailand.gif','','','','','asia.service@palm.com','001 800 65 6298','852 301 58614','techsupport@palm-asia.com','https://www.service.palmdirect.com/service/THA/EE','apsupport.cgi');
addcountry('Philippines','PH','cid_Philippines.gif','','','','','asia.service@palm.com','1800 1651 0222','852 301 58614','techsupport@palm-asia.com','https://www.service.palmdirect.com/service/PHL/EE','apsupport.cgi');
addcountry('Indonesia','ID','cid_Indonesia.gif','','','','','asia.service@palm.com','001 803 65 7501','852 301 58614','techsupport@palm-asia.com','https://www.service.palmdirect.com/service/IDN/EE','apsupport.cgi');
addcountry('India','IN','cid_India.gif','','','','','asia.service@palm.com','000 800 650 1108','852 301 58614','techsupport@palm-asia.com','https://www.service.palmdirect.com/service/IND/EE','apsupport.cgi');
addcountry('Hong Kong','HK','cid_Hong_Kong.gif','','','','','asia.service@palm.com','800 90 3253','852 301 58614','techsupport@palm-asia.com','https://www.service.palmdirect.com/service/HKG/EE','apsupport.cgi');
addcountry('Taiwan','TW','cid_Taiwan.gif','','','','','asia.service@palm.com','00 80 1 651 358','852 301 58614','techsupport@palm-asia.com','https://www.service.palmdirect.com/service/TWN/EE','apsupport.cgi');
addcountry('Australia','AU','cid_Australia.gif','','','','','asia.techsupport@palmOne.com','1800 350 535','612 9273 5199','techsupport@palm.com.au','https://www.service.palmdirect.com/service/AUS/EE','ausupport.cgi');
addcountry('New Zealand','NZ','cid_New_Zealand.gif','','','','','asia.techsupport@palmOne.com','0800 449 539','612 9273 5934','techsupport@palm.com.au','https://www.service.palmdirect.com/service/NZL/EE','ausupport.cgi');

/* END COUNTRY DATA */
var defaultCountry = "Asia Pacific";
//var currentCountry = rememberCountry();
var destination = location.pathname;

  stname = getStored("reseller").toLowerCase();
  stzone = getStored("zone").toLowerCase();
  staddress = getStored("address").toLowerCase();
  stphone = getStored("phone").toLowerCase(); 
/*
CookieWarning();
if ((currentCountry == defaultCountry) && (location.pathname.indexOf("/asia/") > -1) && (location.pathname.indexOf("asia/choosecountry.html")<0) && (location.pathname.indexOf("asia/")<0)) {

storeProduct(destination);
location.pathname = "/asia/choosecountry.html";

}
*/





