var currentUrl = encodeURIComponent(window.location.href.toString());
var countrySelectURL = "/shared-static/html/countryselect.html?currentUrl=" + currentUrl + "&amp;";
countrySelectURL += "keepThis=true&amp;&amp;TB_iframe=true&amp;height=280&amp;width=530";
var javaScriptInclude = "/shared-static/scripts/jquery.thickbox-mod.js";
var javaScriptPopUpInclude = "/shared-static/scripts/jquery.thickbox.js";

function performExportCountrySelect(){
    if((getUserCountryCode() == null) || (getUserCountryCode() == '')){
        getJSInclude(javaScriptInclude, countrySelectURL);
    }
}

function showPopupMessage(pageURL, height, width){
   
   pageURL += "&amp;" + "keepThis=true&amp;&amp;TB_iframe=true&amp;";
   pageURL += "height=" + height + "&amp;";
   pageURL += "width=" + width;
   getJSInclude(javaScriptPopUpInclude, pageURL);
   
}

//used by Rich Text Editor
function CFC_popup(url, name, features){
    var defaultWidth = 500;
    var defaultHeight = 400;

    if (features.indexOf("width") == -1) features += ",width=" + defaultWidth;
    if (features.indexOf("height") == -1) features += ",height=" + defaultHeight;
    var w = window.open(url, name, features);
    w.focus();
}

function getIEVersion() {
	var dataString = navigator.userAgent;
	var index = dataString.indexOf("MSIE");
	if (index == -1) return;
	return parseFloat(dataString.substring(index + 5));
}

function getCookie(name){
  var cname = name + '=';
  var dc = document.cookie;
  if (dc == null) return '';
  if (dc.length > 0)
  {
    var begin = dc.indexOf(cname);
    if (begin != -1)
    {
      begin += cname.length;
      var end = dc.indexOf(';', begin);
      if (end == -1) end = dc.length;
      return unescape(dc.substring(begin, end));
    }
  }
  return '';
}

function getValueFromCookie(cookieValue, index){
	var cookie_ary = cookieValue.split(";");
	var pair = cookie_ary[index].split(":");
	return value = pair[1];
}

function getOrderId(cookieValue){
	return getValueFromCookie(cookieValue, 0);
}

function getCartItems(cookieValue){
	return getValueFromCookie(cookieValue, 1);
}

var countryNameArray = new Array();
countryNameArray["worldwide"]= "Worldwide";
countryNameArray["al"] = "Albania";
countryNameArray["dz"] = "Algeria";
countryNameArray["ad"] = "Andorra";
countryNameArray["ao"] = "Angola";
countryNameArray["ag"] = "Antigua and Barbuda";
countryNameArray["ar"] = "Argentina";
countryNameArray["am"] = "Armenia";
countryNameArray["au"] = "Australia";
countryNameArray["at"] = "Austria";
countryNameArray["az"] = "Azerbaijan";
countryNameArray["bs"] = "Bahamas";
countryNameArray["bh"] = "Bahrain";
countryNameArray["bd"] = "Bangladesh";
countryNameArray["bb"] = "Barbados";
countryNameArray["by"] = "Belarus";
countryNameArray["be"] = "Belgium";
countryNameArray["bj"] = "Benin";
countryNameArray["bm"] = "Bermuda";
countryNameArray["bo"] = "Bolivia";
countryNameArray["ba"] = "Bosnia and Herzegovina";
countryNameArray["bw"] = "Botswana";
countryNameArray["bv"] = "Bouvet Island";
countryNameArray["br"] = "Brazil";
countryNameArray["bg"] = "Bulgaria";
countryNameArray["bf"] = "Burkina Faso";
countryNameArray["bi"] = "Burundi";
countryNameArray["cm"] = "Cameroon";
countryNameArray["ca"] = "Canada";
countryNameArray["cv"] = "Cape Verde";
countryNameArray["ky"] = "Cayman Islands";
countryNameArray["cf"] = "Central African Republic";
countryNameArray["td"] = "Chad";
countryNameArray["cl"] = "Chile";
countryNameArray["cn"] = "China";
countryNameArray["co"] = "Colombia";
countryNameArray["km"] = "Comoros";
countryNameArray["cg"] = "Congo";
countryNameArray["cr"] = "Costa Rica";
countryNameArray["ci"] = "Cote DIvoire (Ivory Coast)";
countryNameArray["hr"] = "Croatia (Hrvatska)";
countryNameArray["cy"] = "Cyprus";
countryNameArray["cz"] = "Czech Republic";
countryNameArray["dk"] = "Denmark";
countryNameArray["dj"] = "Djibouti";
countryNameArray["dm"] = "Dominica";
countryNameArray["do"] = "Dominican Republic";
countryNameArray["ec"] = "Ecuador";
countryNameArray["eg"] = "Egypt";
countryNameArray["sv"] = "El Salvador";
countryNameArray["er"] = "Eritrea";
countryNameArray["ee"] = "Estonia";
countryNameArray["et"] = "Ethiopia";
countryNameArray["fo"] = "Faroe Islands";
countryNameArray["fi"] = "Finland";
countryNameArray["fr"] = "France";
countryNameArray["fx"] = "France Metropolitan";
countryNameArray["gf"] = "French Guiana";
countryNameArray["ga"] = "Gabon";
countryNameArray["gm"] = "Gambia";
countryNameArray["ge"] = "Georgia";
countryNameArray["de"] = "Germany";
countryNameArray["gh"] = "Ghana";
countryNameArray["gi"] = "Gibraltar";
countryNameArray["gr"] = "Greece";
countryNameArray["gd"] = "Grenada";
countryNameArray["gp"] = "Guadeloupe";
countryNameArray["gt"] = "Guatemala";
countryNameArray["gy"] = "Guyana";
countryNameArray["ht"] = "Haiti";
countryNameArray["hn"] = "Honduras";
countryNameArray["hk"] = "Hong Kong";
countryNameArray["hu"] = "Hungary";
countryNameArray["is"] = "Iceland";
countryNameArray["in"] = "India";
countryNameArray["id"] = "Indonesia";
countryNameArray["iq"] = "Iraq";
countryNameArray["ie"] = "Ireland";
countryNameArray["il"] = "Israel";
countryNameArray["it"] = "Italy";
countryNameArray["jm"] = "Jamaica";
countryNameArray["jp"] = "Japan";
countryNameArray["jo"] = "Jordan";
countryNameArray["kz"] = "Kazakhstan";
countryNameArray["ke"] = "Kenya";
countryNameArray["kr"] = "Korea (South)";
countryNameArray["kw"] = "Kuwait";
countryNameArray["kg"] = "Kyrgyzstan";
countryNameArray["lv"] = "Latvia";
countryNameArray["lb"] = "Lebanon";
countryNameArray["ls"] = "Lesotho";
countryNameArray["lr"] = "Liberia";
countryNameArray["li"] = "Liechtenstein";
countryNameArray["lt"] = "Lithuania";
countryNameArray["lu"] = "Luxembourg";
countryNameArray["mk"] = "Macedonia";
countryNameArray["mg"] = "Madagascar";
countryNameArray["mw"] = "Malawi";
countryNameArray["my"] = "Malaysia";
countryNameArray["mv"] = "Maldives";
countryNameArray["ml"] = "Mali";
countryNameArray["mt"] = "Malta";
countryNameArray["mq"] = "Martinique";
countryNameArray["mr"] = "Mauritania";
countryNameArray["mu"] = "Mauritius";
countryNameArray["yt"] = "Mayotte";
countryNameArray["mx"] = "Mexico";
countryNameArray["md"] = "Moldova";
countryNameArray["mc"] = "Monaco";
countryNameArray["mz"] = "Mozambique";
countryNameArray["na"] = "Namibia";
countryNameArray["nl"] = "Netherlands";
countryNameArray["nz"] = "New Zealand (Aotearoa)";
countryNameArray["ni"] = "Nicaragua";
countryNameArray["ne"] = "Niger";
countryNameArray["ng"] = "Nigeria";
countryNameArray["no"] = "Norway";
countryNameArray["om"] = "Oman";
countryNameArray["pa"] = "Panama";
countryNameArray["py"] = "Paraguay";
countryNameArray["pe"] = "Peru";
countryNameArray["ph"] = "Philippines";
countryNameArray["pl"] = "Poland";
countryNameArray["pt"] = "Portugal";
countryNameArray["pr"] = "Puerto Rico";
countryNameArray["qa"] = "Qatar";
countryNameArray["re"] = "Reunion";
countryNameArray["ro"] = "Romania";
countryNameArray["ru"] = "Russian Federation";
countryNameArray["rw"] = "Rwanda";
countryNameArray["gs"] = "S. Georgia and S. Sandwich Isls.";
countryNameArray["kn"] = "Saint Kitts and Nevis";
countryNameArray["lc"] = "Saint Lucia";
countryNameArray["vc"] = "Saint Vincent and the Grenadines";
countryNameArray["sm"] = "San Marino";
countryNameArray["st"] = "Sao Tome and Principe";
countryNameArray["sa"] = "Saudi Arabia";
countryNameArray["sn"] = "Senegal";
countryNameArray["sc"] = "Seychelles";
countryNameArray["sl"] = "Sierra Leone";
countryNameArray["sg"] = "Singapore";
countryNameArray["sk"] = "Slovak Republic";
countryNameArray["si"] = "Slovenia";
countryNameArray["so"] = "Somalia";
countryNameArray["za"] = "South Africa";
countryNameArray["es"] = "Spain";
countryNameArray["sh"] = "St. Helena";
countryNameArray["sj"] = "Svalbard and Jan Mayen Islands";
countryNameArray["sz"] = "Swaziland";
countryNameArray["se"] = "Sweden";
countryNameArray["ch"] = "Switzerland";
countryNameArray["tw"] = "Taiwan";
countryNameArray["tj"] = "Tajikistan";
countryNameArray["tz"] = "Tanzania";
countryNameArray["th"] = "Thailand";
countryNameArray["tg"] = "Togo";
countryNameArray["tt"] = "Trinidad and Tobago";
countryNameArray["tn"] = "Tunisia";
countryNameArray["tr"] = "Turkey";
countryNameArray["tm"] = "Turkmenistan";
countryNameArray["tc"] = "Turks and Caicos Islands";
countryNameArray["ug"] = "Uganda";
countryNameArray["ua"] = "Ukraine";
countryNameArray["ae"] = "United Arab Emirates";
countryNameArray["uk"] = "United Kingdom-GB";
countryNameArray["us"] = "United States";
countryNameArray["uy"] = "Uruguay";
countryNameArray["uz"] = "Uzbekistan";
countryNameArray["va"] = "Vatican City State (Holy See)";
countryNameArray["ve"] = "Venezuela";
countryNameArray["vn"] = "Viet Nam";
countryNameArray["vg"] = "Virgin Islands (British)";
countryNameArray["vi"] = "Virgin Islands (U.S.)";
countryNameArray["eh"] = "Western Sahara";
countryNameArray["ye"] = "Yemen";
countryNameArray["zr"] = "Zaire";
countryNameArray["zm"] = "Zambia";
countryNameArray["zw"] = "Zimbabwe";


// country icon values
var countryIconArray = new Array();
countryIconArray["worldwide"]= "/shared-static/images/icons/flags/worldwide.jpg";
countryIconArray["al"]= "/shared-static/images/icons/flags/albania.jpg";
countryIconArray["dz"]= "/shared-static/images/icons/flags/algeria.jpg";
countryIconArray["ad"]= "/shared-static/images/icons/flags/andorra.jpg";
countryIconArray["ao"]= "/shared-static/images/icons/flags/angola.jpg";
countryIconArray["ag"]= "/shared-static/images/icons/flags/antigua.jpg";
countryIconArray["ar"]= "/shared-static/images/icons/flags/argentina.jpg";
countryIconArray["am"]= "/shared-static/images/icons/flags/armenia.jpg";
countryIconArray["au"]= "/shared-static/images/icons/flags/australia.jpg";
countryIconArray["at"]= "/shared-static/images/icons/flags/austria.jpg";
countryIconArray["az"]= "/shared-static/images/icons/flags/azerbaijan.jpg";
countryIconArray["bs"]= "/shared-static/images/icons/flags/bahamas.jpg";
countryIconArray["bh"]= "/shared-static/images/icons/flags/bahrain.jpg";
countryIconArray["bd"]= "/shared-static/images/icons/flags/bangladesh.jpg";
countryIconArray["bb"]= "/shared-static/images/icons/flags/barbados.jpg";
countryIconArray["by"]= "/shared-static/images/icons/flags/belarus.jpg";
countryIconArray["be"]= "/shared-static/images/icons/flags/belgium.jpg";
countryIconArray["bj"]= "/shared-static/images/icons/flags/benin.jpg";
countryIconArray["bm"]= "/shared-static/images/icons/flags/bermuda.jpg";
countryIconArray["bo"]= "/shared-static/images/icons/flags/bolivia.jpg";
countryIconArray["ba"]= "/shared-static/images/icons/flags/bosnia.jpg";
countryIconArray["bw"]= "/shared-static/images/icons/flags/botswana.jpg";
countryIconArray["bv"]= "/shared-static/images/icons/flags/bouvetisland.jpg";
countryIconArray["br"]= "/shared-static/images/icons/flags/brazil.jpg";
countryIconArray["bg"]= "/shared-static/images/icons/flags/bulgaria.jpg";
countryIconArray["bf"]= "/shared-static/images/icons/flags/burkinafaso.jpg";
countryIconArray["bi"]= "/shared-static/images/icons/flags/burundi.jpg";
countryIconArray["cm"]= "/shared-static/images/icons/flags/cameroon.jpg";
countryIconArray["ca"]= "/shared-static/images/icons/flags/canada.jpg";
countryIconArray["cv"]= "/shared-static/images/icons/flags/capeverde.jpg";
countryIconArray["ky"]= "/shared-static/images/icons/flags/caymanislands.jpg";
countryIconArray["cf"]= "/shared-static/images/icons/flags/centralafrican.jpg";
countryIconArray["td"]= "/shared-static/images/icons/flags/chad.jpg";
countryIconArray["cl"]= "/shared-static/images/icons/flags/chile.jpg";
countryIconArray["cn"]= "/shared-static/images/icons/flags/china.jpg";
countryIconArray["co"]= "/shared-static/images/icons/flags/columbia.jpg";
countryIconArray["km"]= "/shared-static/images/icons/flags/comoros.jpg";
countryIconArray["cg"]= "/shared-static/images/icons/flags/congo.jpg";
countryIconArray["cr"]= "/shared-static/images/icons/flags/costarica.jpg";
countryIconArray["ci"]= "/shared-static/images/icons/flags/cotedivoire.jpg";
countryIconArray["hr"]= "/shared-static/images/icons/flags/croatia.jpg";
countryIconArray["cy"]= "/shared-static/images/icons/flags/cyprus.jpg";
countryIconArray["cz"]= "/shared-static/images/icons/flags/czech.jpg";
countryIconArray["dk"]= "/shared-static/images/icons/flags/denmark.jpg";
countryIconArray["dj"]= "/shared-static/images/icons/flags/djibouti.jpg";
countryIconArray["dm"]= "/shared-static/images/icons/flags/dominica.jpg";
countryIconArray["do"]= "/shared-static/images/icons/flags/dominicanrepublic.jpg";
countryIconArray["ec"]= "/shared-static/images/icons/flags/ecuador.jpg";
countryIconArray["eg"]= "/shared-static/images/icons/flags/egypt.jpg";
countryIconArray["sv"]= "/shared-static/images/icons/flags/elsalvador.jpg";
countryIconArray["er"]= "/shared-static/images/icons/flags/eritria.jpg";
countryIconArray["ee"]= "/shared-static/images/icons/flags/estonia.jpg";
countryIconArray["et"]= "/shared-static/images/icons/flags/ethiopia.jpg";
countryIconArray["fo"]= "/shared-static/images/icons/flags/faroe.jpg";
countryIconArray["fi"]= "/shared-static/images/icons/flags/finland.jpg";
countryIconArray["fr"]= "/shared-static/images/icons/flags/france.jpg";
countryIconArray["fx"]= "/shared-static/images/icons/flags/france.jpg";
countryIconArray["gf"]= "/shared-static/images/icons/flags/france.jpg";
countryIconArray["ga"]= "/shared-static/images/icons/flags/gabon.jpg";
countryIconArray["gm"]= "/shared-static/images/icons/flags/gambia.jpg";
countryIconArray["ge"]= "/shared-static/images/icons/flags/georgia.jpg";
countryIconArray["de"]= "/shared-static/images/icons/flags/germany.jpg";
countryIconArray["gh"]= "/shared-static/images/icons/flags/ghana.jpg";
countryIconArray["gi"]= "/shared-static/images/icons/flags/gibraltar.jpg";
countryIconArray["gr"]= "/shared-static/images/icons/flags/greece.jpg";
countryIconArray["gd"]= "/shared-static/images/icons/flags/grenada.jpg";
countryIconArray["gp"]= "/shared-static/images/icons/flags/guadaloupe.jpg";
countryIconArray["gt"]= "/shared-static/images/icons/flags/guatamala.jpg";
countryIconArray["gy"]= "/shared-static/images/icons/flags/guyana.jpg";
countryIconArray["ht"]= "/shared-static/images/icons/flags/haiti.jpg";
countryIconArray["hn"]= "/shared-static/images/icons/flags/honduras.jpg";
countryIconArray["hk"]= "/shared-static/images/icons/flags/hongkong.jpg";
countryIconArray["hu"]= "/shared-static/images/icons/flags/hungary.jpg";
countryIconArray["is"]= "/shared-static/images/icons/flags/iceland.jpg";
countryIconArray["in"]= "/shared-static/images/icons/flags/india.jpg";
countryIconArray["id"]= "/shared-static/images/icons/flags/indonesia.jpg";
countryIconArray["iq"]= "/shared-static/images/icons/flags/iraq.jpg";
countryIconArray["ie"]= "/shared-static/images/icons/flags/ireland.jpg";
countryIconArray["il"]= "/shared-static/images/icons/flags/israel.jpg";
countryIconArray["it"]= "/shared-static/images/icons/flags/italy.jpg";
countryIconArray["jm"]= "/shared-static/images/icons/flags/jamaica.jpg";
countryIconArray["jp"]= "/shared-static/images/icons/flags/japan.jpg";
countryIconArray["jo"]= "/shared-static/images/icons/flags/jordan.jpg";
countryIconArray["kz"]= "/shared-static/images/icons/flags/kazakhstan.jpg";
countryIconArray["ke"]= "/shared-static/images/icons/flags/kenya.jpg";
countryIconArray["kr"]= "/shared-static/images/icons/flags/southkorea.jpg";
countryIconArray["kw"]= "/shared-static/images/icons/flags/kuwait.jpg";
countryIconArray["kg"]= "/shared-static/images/icons/flags/kyrgyzstan.jpg";
countryIconArray["lv"]= "/shared-static/images/icons/flags/latvia.jpg";
countryIconArray["lb"]= "/shared-static/images/icons/flags/lebanon.jpg";
countryIconArray["ls"]= "/shared-static/images/icons/flags/lesotho.jpg";
countryIconArray["lr"]= "/shared-static/images/icons/flags/liberia.jpg";
countryIconArray["li"]= "/shared-static/images/icons/flags/liechtenstein.jpg";
countryIconArray["lt"]= "/shared-static/images/icons/flags/lithuania.jpg";
countryIconArray["lu"]= "/shared-static/images/icons/flags/luxembourg.jpg";
countryIconArray["mk"]= "/shared-static/images/icons/flags/macedonia.jpg";
countryIconArray["mg"]= "/shared-static/images/icons/flags/madagascar.jpg";
countryIconArray["mw"]= "/shared-static/images/icons/flags/malawi.jpg";
countryIconArray["my"]= "/shared-static/images/icons/flags/malaysia.jpg";
countryIconArray["mv"]= "/shared-static/images/icons/flags/maldives.jpg";
countryIconArray["ml"]= "/shared-static/images/icons/flags/mali.jpg";
countryIconArray["mt"]= "/shared-static/images/icons/flags/malta.jpg";
countryIconArray["mq"]= "/shared-static/images/icons/flags/martinique.jpg";
countryIconArray["mr"]= "/shared-static/images/icons/flags/mauritania.jpg";
countryIconArray["mu"]= "/shared-static/images/icons/flags/mauritius.jpg";
countryIconArray["yt"]= "/shared-static/images/icons/flags/france.jpg";
countryIconArray["mx"]= "/shared-static/images/icons/flags/mexico.jpg";
countryIconArray["md"]= "/shared-static/images/icons/flags/moldova.jpg";
countryIconArray["mc"]= "/shared-static/images/icons/flags/monaco.jpg";
countryIconArray["mz"]= "/shared-static/images/icons/flags/mozambique.jpg";
countryIconArray["na"]= "/shared-static/images/icons/flags/namibia.jpg";
countryIconArray["nl"]= "/shared-static/images/icons/flags/netherlands.jpg";
countryIconArray["nz"]= "/shared-static/images/icons/flags/newzealand.jpg";
countryIconArray["ni"]= "/shared-static/images/icons/flags/nicaragua.jpg";
countryIconArray["ne"]= "/shared-static/images/icons/flags/niger.jpg";
countryIconArray["ng"]= "/shared-static/images/icons/flags/nigeria.jpg";
countryIconArray["no"]= "/shared-static/images/icons/flags/norway.jpg";
countryIconArray["om"]= "/shared-static/images/icons/flags/oman.jpg";
countryIconArray["pa"]= "/shared-static/images/icons/flags/panama.jpg";
countryIconArray["py"]= "/shared-static/images/icons/flags/paraguay.jpg";
countryIconArray["pe"]= "/shared-static/images/icons/flags/peru.jpg";
countryIconArray["ph"]= "/shared-static/images/icons/flags/philippines.jpg";
countryIconArray["pl"]= "/shared-static/images/icons/flags/poland.jpg";
countryIconArray["pt"]= "/shared-static/images/icons/flags/portugal.jpg";
countryIconArray["pr"]= "/shared-static/images/icons/flags/puertorico.jpg";
countryIconArray["qa"]= "/shared-static/images/icons/flags/qatar.jpg";
countryIconArray["re"]= "/shared-static/images/icons/flags/france.jpg";
countryIconArray["ro"]= "/shared-static/images/icons/flags/romania.jpg";
countryIconArray["ru"]= "/shared-static/images/icons/flags/russia.jpg";
countryIconArray["rw"]= "/shared-static/images/icons/flags/rwanda.jpg";
countryIconArray["gs"]= "/shared-static/images/icons/flags/southgeorgia.jpg";
countryIconArray["kn"]= "/shared-static/images/icons/flags/saintkitts.jpg";
countryIconArray["lc"]= "/shared-static/images/icons/flags/saintlucia.jpg";
countryIconArray["vc"]= "/shared-static/images/icons/flags/saintvincent.jpg";
countryIconArray["sm"]= "/shared-static/images/icons/flags/sanmarino.jpg";
countryIconArray["st"]= "/shared-static/images/icons/flags/saotome.jpg";
countryIconArray["sa"]= "/shared-static/images/icons/flags/saudiarabia.jpg";
countryIconArray["sn"]= "/shared-static/images/icons/flags/senegal.jpg";
countryIconArray["sc"]= "/shared-static/images/icons/flags/seychelles.jpg";
countryIconArray["sl"]= "/shared-static/images/icons/flags/sierraleone.jpg";
countryIconArray["sg"]= "/shared-static/images/icons/flags/singapore.jpg";
countryIconArray["sk"]= "/shared-static/images/icons/flags/slovak.jpg";
countryIconArray["si"]= "/shared-static/images/icons/flags/slovenia.jpg";
countryIconArray["so"]= "/shared-static/images/icons/flags/somalia.jpg";
countryIconArray["za"]= "/shared-static/images/icons/flags/southafrica.jpg";
countryIconArray["es"]= "/shared-static/images/icons/flags/spain.jpg";
countryIconArray["sh"]= "/shared-static/images/icons/flags/sweden.jpg";
countryIconArray["sj"]= "/shared-static/images/icons/flags/norway.jpg";
countryIconArray["sz"]= "/shared-static/images/icons/flags/swaziland.jpg";
countryIconArray["se"]= "/shared-static/images/icons/flags/sweden.jpg";
countryIconArray["ch"]= "/shared-static/images/icons/flags/switzerland.jpg";
countryIconArray["tw"]= "/shared-static/images/icons/flags/taiwan.jpg";
countryIconArray["tj"]= "/shared-static/images/icons/flags/tajikistan.jpg";
countryIconArray["tz"]= "/shared-static/images/icons/flags/tanzania.jpg";
countryIconArray["th"]= "/shared-static/images/icons/flags/thailand.jpg";
countryIconArray["tg"]= "/shared-static/images/icons/flags/togo.jpg";
countryIconArray["tt"]= "/shared-static/images/icons/flags/trinidad.jpg";
countryIconArray["tn"]= "/shared-static/images/icons/flags/tunisia.jpg";
countryIconArray["tr"]= "/shared-static/images/icons/flags/turkey.jpg";
countryIconArray["tm"]= "/shared-static/images/icons/flags/turkmenistan.jpg";
countryIconArray["tc"]= "/shared-static/images/icons/flags/caicosislands.jpg";
countryIconArray["ug"]= "/shared-static/images/icons/flags/uganda.jpg";
countryIconArray["ua"]= "/shared-static/images/icons/flags/ukraine.jpg";
countryIconArray["ae"]= "/shared-static/images/icons/flags/arabemirates.jpg";
countryIconArray["uk"]= "/shared-static/images/icons/flags/unitedkingdom.jpg";
countryIconArray["us"]= "/shared-static/images/icons/flags/unitedstates.jpg";
countryIconArray["uy"]= "/shared-static/images/icons/flags/uruguay.jpg";
countryIconArray["uz"]= "/shared-static/images/icons/flags/uzbekistan.jpg";
countryIconArray["va"]= "/shared-static/images/icons/flags/vaticancity.jpg";
countryIconArray["ve"]= "/shared-static/images/icons/flags/venezuela.jpg";
countryIconArray["vn"]= "/shared-static/images/icons/flags/vietnam.jpg";
countryIconArray["vg"]= "/shared-static/images/icons/flags/virginislands.jpg";
countryIconArray["vi"]= "/shared-static/images/icons/flags/virginislands.jpg";
countryIconArray["eh"]= "/shared-static/images/icons/flags/westernsahara.jpg";
countryIconArray["ye"]= "/shared-static/images/icons/flags/yemen";
countryIconArray["zr"]= "/shared-static/images/icons/flags/zaire.jpg";
countryIconArray["zm"]= "/shared-static/images/icons/flags/zambia.jpg";
countryIconArray["zw"]= "/shared-static/images/icons/flags/zimbabwe.jpg";


var countryPhoneArray = new Array();
countryPhoneArray["worldwide"]= "<img src=\"/shared-static/images/icons/defaultContact.jpg\">";
countryPhoneArray["dz"] = "+21321 650529";
countryPhoneArray["ar"] = "+54 11 4556 0844";
countryPhoneArray["au"] = "1800 331 627";
countryPhoneArray["at"] = "0800 20 10 87";
countryPhoneArray["bh"] = "973 233544";
countryPhoneArray["be"] = "0800 14894";
countryPhoneArray["br"] = "+55 11 50614661";
countryPhoneArray["bg"] = "+359 2 953 1224";
countryPhoneArray["ca"] = "1-800-263-6236";
countryPhoneArray["cl"] = "+56 2 4736100";
countryPhoneArray["cn"] = "010-62816696";
countryPhoneArray["co"] = "+57 1 4372001";
countryPhoneArray["hr"] = "+385 1 33 69 610";
countryPhoneArray["cy"] = "(02) 426379";
countryPhoneArray["cz"] = "+42 0 257 013 400";
countryPhoneArray["dk"] = "80 30 17 40";
countryPhoneArray["ec"] = "+593 9 7900150";
countryPhoneArray["eg"] = "20 (2) 5788050";
countryPhoneArray["ee"] = "+372 620 4350";
countryPhoneArray["fi"] = "+358 9 584 121";
countryPhoneArray["fr"] = "0800 23 20 79";
countryPhoneArray["de"] = "0800 083 09 02";
countryPhoneArray["gr"] = "0030 31 322 525";
countryPhoneArray["hk"] = "(852) 2407-8450";
countryPhoneArray["hu"] = "0036-1-250-4763";
countryPhoneArray["is"] = "354 568 8533";
countryPhoneArray["in"] = "+91-124-4559800-99";
countryPhoneArray["ie"] = "00353 1 284 51 22";
countryPhoneArray["il"] = "972-2-5335599";
countryPhoneArray["it"] = "02 98 22 201";
countryPhoneArray["jp"] = "+81-3-5730-6509";
countryPhoneArray["jo"] = "00 962 6 560 75 01";
countryPhoneArray["ke"] = "00 254 20 572109";
countryPhoneArray["kw"] = "965 431-3729";
countryPhoneArray["lv"] = "00371 704 2835";
countryPhoneArray["lb"] = "00961 1 743 150";
countryPhoneArray["lt"] = "+ 370 5 262 4009";
countryPhoneArray["mk"] = "91-111-595";
countryPhoneArray["mt"] = "00356 21447184";
countryPhoneArray["mu"] = "230 212 9437";
countryPhoneArray["mx"] = "+52 55 52500805";
countryPhoneArray["nl"] = "0800 099 3310";
countryPhoneArray["nz"] = "0800 335 997";
countryPhoneArray["no"] = "00800 5345 5345";
countryPhoneArray["om"] = "968 7715201";
countryPhoneArray["pe"] = "+51 1 5660400";
countryPhoneArray["pl"] = "022 349 60 10";
countryPhoneArray["pt"] = "900 181 461";
countryPhoneArray["qa"] = "00974 4428-716";
countryPhoneArray["ro"] = "00974 4428-716";
countryPhoneArray["ru"] = "+7 985 102 03 14";
countryPhoneArray["sa"] = "00966 1 4646955";
countryPhoneArray["sg"] = "(65) 6861 8638";
countryPhoneArray["sk"] = "+42 1 2 645 34 041";
countryPhoneArray["si"] = "+386 (0)4 2015 050";
countryPhoneArray["za"] = "27 11 652 4000";
countryPhoneArray["es"] = "900 181 461";
countryPhoneArray["se"] = "020 26 34 52";
countryPhoneArray["tw"] = "+886-2-2797 9828";
countryPhoneArray["tn"] = "+216 71 88 01 10";
countryPhoneArray["tr"] = "+90 212 635 85 46";
countryPhoneArray["ua"] = "+7 095 745 1759";
countryPhoneArray["ae"] = "00 971 6-5592 481";
countryPhoneArray["uk"] = "0800 269 210";
countryPhoneArray["us"] = "800.955.6288";
countryPhoneArray["uy"] = "598 2 6130442";
countryPhoneArray["ve"] = "+58 212 7535060";

function getCountryIcon(code) {
	var icon = getItemFromArray(countryIconArray, code);
	if(icon == "" || icon == null)
		icon = getItemFromArray(countryIconArray, "worldwide");
	return icon;
}

function getCountryHeaderName(code) {
	var name = getItemFromArray(countryNameArray, code);
	if(name == "" || name == null)
		name = getItemFromArray(countryNameArray, "worldwide");
	return name;
}

function getCountryPhone(code) {
	var phone = getItemFromArray(countryPhoneArray, code);
	if(phone == "" || phone == null)
		phone = getItemFromArray(countryPhoneArray, "worldwide");
	return phone;
}

function getItemFromArray(itemArray, code){
	var returnValue, i;
	for (i in itemArray) {
	  if(i == code){
	  	returnValue = itemArray[i];
	  }
	}
	return returnValue;
}

// findValue, selectItem and formatItem all used in conjuction with autocomplete
function findValue(li) {
	if( li == null ) return alert("No match!");
	if( !!li.extra ) var sValue = li.extra[0];
	else var sValue = li.selectValue;
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
	return row[0];
}


$(document).ready(function(){
 	if ($.browser.msie && (getIEVersion() < 7)) {
		
		//   Switch menu stylesheets for IE < 7
		$('link[@rel*=style][@title*=menu]').each(function() {
			this.disabled = true;
			if (this.getAttribute('title') == 'menu-ie6')
				this.disabled = false;
		});
	} else {

		//   Switch to superfish menu styles (if not already switched, above)
		$('link[@rel*=style][@title*=menu]').each(function() {
			this.disabled = true;
			if (this.getAttribute('title') == 'menu-sf')
				this.disabled = false;
		});
	}
	//   Turn on global drop-down menu (no fancy hover for IE < 7)
	$("#topNav .nav").superfish({
	    animation: { opacity:"show", height:"show"}, 
	    speed: "fast", 
	    disableHI: true
	})
	.find(">li[ul]")
		.mouseover(function(){
			$("ul", this).bgIframe({opacity:false});
		})
		.find("a")
			.focus(function(){
				$("ul", $(".nav>li[ul]")).bgIframe({opacity:false});
			});

	//   Flip each menu to the left if the screen is too narrow to display on the right
	$("#topNav .nav > li > a").bind("mouseover", function() {
		var windowWidth = Math.min($(window).width(), $(document).width());
		var scrollLeft = Math.max($(window).scrollLeft(), $(document).scrollLeft());
		var thisLeftPadding = parseInt($(this).css("padding-left")) + parseInt($(this).css("margin-left")) + parseInt($(this).css("border-left-width"));
		var thisLeftOffset = $(this).offset()["left"];
		var submenuWidth = $("ul > li", $(this).parent()).width();

		if (windowWidth + scrollLeft < thisLeftPadding + thisLeftOffset + (2 * submenuWidth))
			$("ul", $(this).parent()).addClass("left");
		else
			$("ul", $(this).parent()).removeClass("left");
	});

	//   Setup global drop-down menu appearance
	$("#topNav .nav li ul li:first-child").addClass("first");
	$("#topNav .nav li ul li:last-child").after('<li class="last"><div class="ft"><div class="c"></div></div></li>');

	//Look for the cart cookie and add the value to the header
    var cart_cookie = getCookie("CK_CART_INFO");

    if(cart_cookie != null && cart_cookie.length > 0) {
    	$("#wcmCartItem").empty();
    	$("#wcmCartItem").append(getCartItems(cart_cookie) + "&nbsp;Items");
    } else {
    	$("#wcmCartItem").empty();
    	$("#wcmCartItem").append("0&nbsp;Items");
    }

    var country_cookie = getUserCountryCode();
    var country_icon, country_phone, country_name;

    if(country_cookie != null && country_cookie.length > 0) {
    	country_icon = getCountryIcon(country_cookie);
    	country_phone = getCountryPhone(country_cookie);
    	country_name = getCountryHeaderName(country_cookie);
    } else {
    	country_icon = getCountryIcon("worldwide");
    	country_phone = getCountryPhone("worldwide");
    	country_name = getCountryHeaderName("worldwide");
    }

   $("#globalQuickLinks").append('<span class="worldwide">' + country_name + '</span>');
   $("#world").append('<img src="' + country_icon + '" alt="' + country_name + '" id="worldwide" />');
   $("#eight00").append(country_phone);
   
   
   var callAutoComplete = function() {   
	   if ($('#searchterm').size() != 0) {
		   var fastURL; 
		   if(wcmserver.length > 0){
		   		fastURL = wcmserver + "/site.fastsearch.html?s=";
		   }else{
		   		fastURL = "/site.fastsearch.html?s=";
		   }
		   
		   $("#searchterm").autocomplete(fastURL,
				{
					delay:10,
					minChars:1,
					matchSubset:1,
					matchContains:1,
					cacheLength:0,
					onItemSelect:selectItem,
					onFindValue:findValue,
					formatItem:formatItem,
					autoFill:true
				}
			);
		}
	 };
	
	 
	 setTimeout(callAutoComplete,1000);
	
});