monthName = new Array();
monthName[0] = "JAN";
monthName[1] = "FEB";
monthName[2] = "MAR";
monthName[3] = "APR";
monthName[4] = "MAY";
monthName[5] = "JUN";
monthName[6] = "JUL";
monthName[7] = "AUG";
monthName[8] = "SEP";
monthName[9] = "OCT";
monthName[10] = "NOV";
monthName[11] = "DEC";

monthLastDay = new Array();
monthLastDay[0] = 31;
monthLastDay[1] = 28;
monthLastDay[2] = 31;
monthLastDay[3] = 30;
monthLastDay[4] = 31;
monthLastDay[5] = 30;
monthLastDay[6] = 31;
monthLastDay[7] = 31;
monthLastDay[8] = 30;
monthLastDay[9] = 31;
monthLastDay[10] = 30;
monthLastDay[11] = 31;


folderName = new Array();
orderList = new Array();	

url = document.URL;
prefix = "";
order = 0;

folderName[0] = "aboutus";
folderName[1] = "press";
folderName[2] = "registration";
folderName[3] = "services";
folderName[4] = "solution";
folderName[5] = "tools";
folderName[6] = "info";
folderName[7] = "locator";
folderName[8] = "printing";
folderName[9] = "general";
folderName[10] = "specific";
folderName[11] = "release";
folderName[11] = "archive";
folderName[12] = "office";

if (url.indexOf('file://') != -1)
{
	pathName = url.substr(7, url.length).split('\\');
}
else
	pathName = url.split('/');

for (var i = 0; i < pathName.length - 1; i++)
{
	var found = false;
	for (var j = 0; j < folderName.length && !found; j++)
	{
		if (pathName[i] == folderName[j])
		{
			orderList[order] = j;
			order++;
			found = true;
		}
	}
}
for (var i = 0; i < order; i++)
{
	prefix = prefix + "../";
}

function adminChangeList( box, childList, grandList )
{
	if (box.selectedIndex != -1)
	{
		eval("list = " + childList + "List[box.options[box.selectedIndex].value]");
		emptyList( eval("box.form." + childList + "Id") );
		fillList( eval("box.form." + childList + "Id"), list );
	}
	else
	{
		emptyList( eval("box.form." + childList + "Id") );
	}
	if (grandList != null)
	{
		adminChangeList(eval("box.form." + childList + "Id"), grandList);
	}
}

function changeList( box, childList, grandList )
{
	if (box.selectedIndex != -1)
	{
		eval("list = " + childList + "List[box.options[box.selectedIndex].value]");
		if (box.selectedIndex == 0)
		{
			if (childList == "city")
			{
				list = emptyCitySelcetionList;
			}
			else
				list = emptySelectionList;
		}
		emptyList( eval("box.form." + childList + "Id") );
		if (list != null)
			fillList( eval("box.form." + childList + "Id"), list );
          /** if childList=office, it may select the city list directly **/
          /** need to update the coutry select box **/
          if (childList == "office" && 
              document.forms["searchForm"].cityId.selectedIndex != 0 )
          {
              var c_id = box.options[box.selectedIndex].value;
              //find the corresponding countryId
              //can't use cityList.length, JS bug?? 
              for (var i = 0; i < 1000; i++)
              {
                  if (cityList[i] != null)
                  {
                      for (var j=0; j<cityList[i][1].length; j++)
                      {
                          if (cityList[i][1][j] == c_id)
                          {
                              //find the index country selector from
                              //countryList[1]
                              for (var k=0; k<countryList[1].length;
                                   k++)
                              {
                                  if (countryList[1][k] == i)
                                      document.forms["searchForm"].countryId.selectedIndex = k;
                              }
                          }
                      }
                  }
              }
          }
	}
	else
	{
		emptyList( eval("box.form." + childList + "Id") );
	}
	if (grandList != null)
	{
		changeList(eval("box.form." + childList + "Id"), grandList);
	}
}

function emptyList( box )
{
	while ( box.options.length )
	{
		box.options[0] = null;
	}
}

function fillList( box, arr )
{
    if (arr == emptyCitySelcetionList)
    {
       //Sort the city list
       var tmpCityList = new Array(arr[0].length);
  
       for ( i = 0; i < arr[0].length; i++ )
       {
         tmpCityList[i] = arr[0][i] + "|" + arr[1][i];
       }
       tmpCityList.sort();

       //Add ""Please Select" first
       option = new Option("Please Select", "-1");
       box.options[box.length] = option;

       //rebuild the index list
       for (var i=0; i<tmpCityList.length; i++)
       {
          var tmpArr = tmpCityList[i].split("|");
          var cityName = tmpArr[0];
          var cityIdx = tmpArr[1];

          if (cityIdx != "-1")
          {
             option = new Option( cityName, cityIdx);
             box.options[box.length] = option;
          }
       }
    }
    else
    {
	for ( i = 0; i < arr[0].length; i++ )
	{
		option = new Option( arr[0][i], arr[1][i] );
		box.options[box.length] = option;
	}
    }
    box.selectedIndex=0;
}

function checkForm(theForm)
{
	with (theForm)
	{
		if (officeId.selectedIndex != 0)
			submit();
	}
}

function searchFormSubmit(actionValue)
{
	with (document.forms["searchForm"])
	{
		   elements["action"].value = actionValue;
		   submit();
	}
}

function createClock(offset)
{
	if (document.all || document.getElementById)
	{
		document.write('<div id="activeClock"></div>');
	}
	else
	{
		document.write('<ilayer id="wrapClock"><layer id="activeClock"></layer></ilayer>');
	}
	updateClock(offset);
}

function findCurrentTime(offset)
{
	var time = new Date();

        var year = time.getUTCFullYear();
        var month = time.getUTCMonth();
        var day = time.getUTCDate();

	var totalMinutes = time.getUTCHours() * 60 + time.getUTCMinutes() + offset * 60;
	if (totalMinutes > 24 * 60)
		totalMinutes = totalMinutes - 24 * 60;
	else if (totalMinutes < 0)
        {
		totalMinutes = totalMinutes + 24 * 60;
          // the day is minus 1
          day = day - 1;
          //if day = 0 set the last day of the previous month
          if (day == 0)
          {
            //set to previous month
            month = month - 1;
            if (month == -1)
            {
              month = 11;
              year = year - 1;
            }

            // set the last day of the 
            //if leap year and month=1 (FEB)
            if (((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
                &&
                month == 1)
            {
              day = 29;
            }
            else
            {
              day = monthLastDay[month];
            } 
          }
        }
	hour = Math.floor(totalMinutes / 60);
	minutes = totalMinutes % 60 + 100;
	minutes = '' + minutes;
	second = time.getUTCSeconds() + 100;
	second = '' + second;
        year = '' + year;
	timeString = '' + day + " " + monthName[month] + " " + year.substring(2) + " " + hour + ":" + minutes.substring(1,3) + ":" + second.substring(1,3);
	return "<span class='clock'>" + timeString + "</span:>";
}

function updateClock(offset)
{
	printString = findCurrentTime(offset);
	if (document.layers)
	{
		wc = document.wrapClock;
		lc = wc.document.activeClock;
		lc.document.write(printString);
		lc.document.close();
	}
	else if (document.all)
	{
		activeClock.innerHTML = printString;
	}
	else if (document.getElementById)
	{
		document.getElementById("activeClock").innerHTML = printString;
	}
	setTimeout("updateClock(" + offset + ")",1000);
}

function setBox(country, city, office)
{
	with (document.forms["searchForm"])
	{
		var found = false;

		for (var i = 0; i < countryId.options.length && !found; i++)
		{

			if (countryId.options[i].value == country)
			{
				countryId.selectedIndex = i;
				found = true;
			}
		}
		found = false;
		for (var i = 0; i < cityId.options.length && !found; i++)
		{

			if (cityId.options[i].value == city)
			{
				cityId.selectedIndex = i;
				found = true;
			}
		}
		found = false;
		for (var i = 0; i < officeId.options.length && !found; i++)
		{
			if (officeId.options[i].value == office)
			{
				officeId.selectedIndex = i;
				found = true;
			}
		}
	}
}
