document.getElementByID(THIS_object_was_required)     Last updated on      

var browserVersion;
var bd = new BrowserDetector();
setBrowserVersion();
var colSeperator = "|-|";
var recordSeperator = ",-,";
var maxCompareList = 6;
var compareButtonThreshold = 2;
//Browser detection functions

//************************************************************************

//Determine if the browser is IE or Netscape Compatible

function setBrowserVersion()
{
if (document.all) {
browserVersion = "IE";
} else {
browserVersion = "Netscape";
}
}

//Detect the internet browser and the operating systems' platform

function BrowserDetector()
{
var agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
this.ns2 = (this.ns && (this.major == 2));
this.ns3 = (this.ns && (this.major == 3));
this.ns4 = (this.ns && (this.major == 4));
this.ns5 = (this.ns && (this.major > 4));
this.ns6 = (this.ns && (this.major == 6));
this.ns7 = (this.ns && (agent.indexOf("netscape/7") !=-1));
this.ns71 = (this.ns && (agent.indexOf('netscape/7.1')!=-1));
this.ns72 = (this.ns && (agent.indexOf('netscape/7.2')!=-1));
this.firefox = (this.ns && (agent.indexOf('firefox')!=-1));
this.ie = (agent.indexOf("msie") != -1);
this.ie3 = (this.ie && (this.major == 2));
this.ie4 = (this.ie && (this.major >= 4));
this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5") != -1));
this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1));
this.cs6 = (agent.indexOf("2000 6")!=-1); // CompuServe 6.0
this.cs7 = (agent.indexOf("cs 2000 7")!=-1); // CompuServe 7.0
this.op3 = (agent.indexOf("opera") != -1);
this.mac = (agent.indexOf("mac") != -1);
this.client = ( (navigator.userAgent.indexOf('AOL')!=-1) || (navigator.userAgent.indexOf('CS 2000')!=-1) )? 1 : 0;
}


// *******************************************************************
//* Misc Function *
// *******************************************************************
/*

function doCompare(url) {
var edcListString = getCookie(COOKIE_COMPARELIST);
if(edcListString == null) {
return;
}
var edcArray = edcListString.split(',-,');
var edcs = new Array();
for(var i in edcArray) {
var productArr = edcArray[i].split('|-|');
edcs.push('edc=' + productArr[0]);
}

var targetURL = url + "?CompareRedirect=1";

if(edcs.length > 0) {
document.location.href = targetURL + '&' + edcs.join('&');
}
}
*/

function checkProductSelect(chk) {
if(chk) {
var record = chk.value.split(colSeperator);
if(chk.checked) {
floatingCompareList.addCompareItem(record[0], record[1], record[2], record[3]);
} else {
floatingCompareList.removeCompareItem(chk.value);
}
}
}

/*************************
* CompareList Class Defination
*/


var floatingCompareList = new FloatingCompareList('floatingCompareList', 'divCompare', 'divContent');

function FloatingCompareList(objName, outterDivID, innerDivID) {
// Constructor, thus do not forget de*... later

var compareList = new Array();

_renderCompareListTable();

// Define property
// Define Methods

this.show = _show;
this.hide = _hide;
this.toggle = _toggle;
this.addCompareItem = _addCompareItem;
this.removeCompareItem = _removeCompareItem;
this.removeCompareItemAt = _removeCompareItemAt;
this.refresh = _refresh;
this.clear = _clear;
this.doCompare = _doCompare;
this.initialCompareButton = _initialCompareButton;
// Private Functions
function _show(e) {
var theEvent = (bd.ns) ? e : event;


var x = (bd.ns) ? e.pageX : event.x + document.body.scrollLeft;
var y = (bd.ns) ? e.pageY : event.y + document.body.scrollTop;
showElement(outterDivID);
_move(x, y);
}

function _hide() {
hideElement(outterDivID);
}

function _toggle(e) {
var theEvent = (bd.ns) ? e : event;
var x = (bd.ns) ? e.pageX : event.x + document.body.scrollLeft;
var y = (bd.ns) ? e.pageY : event.y + document.body.scrollTop;

toggleElement(outterDivID);
_move(x, y);
}

function _move(x, y) {
if(bd.ie && bd.mac) {
//y = y - 130; // Please do not use "hack", systems testing sounds better for MAC/IE
}
var Element = document.getElementById(outterDivID);

Element.style.left = x;
Element.style.top = y;
}

function _addCompareItem(edc, product, img, price) {
if(compareList.length >= maxCompareList) {
_removeCompareItemAt(0);
}

compareList[compareList.length] = edc + colSeperator + product + colSeperator + img + colSeperator + price; // This is "hack" systems testing for IE/MAC. other browser can use array.push()

//alert("addCompareItem " + compareList.length); Oh! my lord, I learn the diff between MAC's IE vs. Win IE

if(compareList.length >= compareButtonThreshold) {
_showCompareButton("compareButtonTop");
_showCompareButton("compareButtonBottom");
_hideCompareButton("compareButtonTopDisabled");
_hideCompareButton("compareButtonBottomDisabled");
}
_flushCompareListToCookie();
//compareList.push(productRec);
_renderCompareListTable();
}

function _removeCompareItem(record) {
var index = indexOfArray(compareList, record);

if(index >= 0) {
_removeCompareItemAt(index);
}

if(compareList.length >= 0 && compareList.length < compareButtonThreshold) {
_showCompareButton("compareButtonTopDisabled");
_showCompareButton("compareButtonBottomDisabled");
_hideCompareButton("compareButtonTop");
_hideCompareButton("compareButtonBottom");
}
}

function _removeCompareItemAt(index) {
if(index >= 0 && index < compareList.length ) {
var cols = compareList[index].split(colSeperator);
var chk = document.getElementById('edc' + cols[0]);
if(chk != null) {
chk.checked = false;
}

if(compareList.length > 0) {
for(var i = index; i < compareList.length - 1; i++) {
compareList[i] = compareList[i + 1];
}
}
compareList.length--;
_flushCompareListToCookie();
_renderCompareListTable();
}
}

function _refresh() {
_renderCompareListTable();
}

function _clear() {
deleteCookie(COOKIE_COMPARELIST, null, null);
clearArray(compareList);
clearChildNodes(innerDivID);
// Please do not use "hack", systems testing sounds better for MAC/IE
if(bd.ie && bd.mac) {
document.getElementById(innerDivID).innerHTML = "";
}

// clear check box
var inputNodes = document.getElementsByTagName("input");

for(var i = 0; i < inputNodes.length; i++) {
if (inputNodes[i].type == "checkbox" &&
inputNodes[i].id.toLowerCase().indexOf("edc") >=0 ) {
//alert("Clear - Setting checkbox to false for: " + inputNodes[i].id);
inputNodes[i].checked = false;
}
}
}

function _flushCompareListToCookie() {
if(compareList != null && compareList.length > 0) {
setCookie(COOKIE_COMPARELIST, compareList.join(recordSeperator), null, null, null, false);
} else {
deleteCookie(COOKIE_COMPARELIST, null, null);
}
}

function _getCompareListFromCookie() {

var cookieValue = getCookie(COOKIE_COMPARELIST);

if(cookieValue != null) {

compareList = cookieValue.split(recordSeperator);

} else {

compareList = new Array();
}
}

function _renderCompareListTable() {

_getCompareListFromCookie();

var compareDiv = getHtmlObjectById(innerDivID);
clearChildNodes(innerDivID); // clear table first
if(compareList.length > 0) {
compareTable = document.createElement("table");
comparetableBody = document.createElement("tbody");
if(browserVersion == 'IE') {
if(bd.mac) {
compareTable.style['width']= '100%';
} else {
compareTable.style.setAttribute('width', '100%');
}
} else {
compareTable.setAttribute('width', '100%');
}

for(var i = 0; i < compareList.length; i++) {
var currentRow = document.createElement("tr");
var currentCell = document.createElement("td");
currentCell.innerHTML = "<a href='javascript:" + objName + ".removeCompareItemAt(" + i + ");'><img border='0' src='http://img.usamyanmar.net/sub_directory/search/remove.gif'/></a>";
currentCell.style.color = '#eeeeee';

currentCell.appendChild(document.createTextNode(".")); // This is the "hack" systems testing for MAC/IE
currentRow.appendChild(currentCell);

if(browserVersion == 'IE') {
currentRow.style.backgroundColor = '#eeeeee';

} else {
currentRow.setAttribute('bgcolor', '#eeeeee');
}

var record = compareList[i].split(colSeperator);
// Render Product Friendly Name, but I still do not know how many graphics modes exist ...
var imgTag = '<table><tr><td width=&quot;50&quot;><img src=&quot;' + record[2] + '&quot; border=&quot;0&quot;></td></tr><tr><td align=&quot;center&quot; class=&quot;btsbred&quot;>' +
record[3] +
'</td></tr></table>';
currentCell=document.createElement("td");
currentCell.innerHTML = '<a href="/shop/products/default.aspx?EDC=' + record[0] + '" onmouseover="stm([\'\', \'' + imgTag + '\'],Style[12])" onmouseout="htm()">' + record[1] + '</a>';
currentRow.appendChild(currentCell);

comparetableBody.appendChild(currentRow);
}

if(browserVersion == 'IE') {
//compareTable.setAttribute('border', '0');
} else {
compareTable.attributes['border'] = '0';
}
compareTable.appendChild(comparetableBody);
compareDiv.appendChild(compareTable);
} else {
if(bd.ie && bd.mac) {
document.getElementById(innerDivID).innerHTML = "";
}
}
}

function _doCompare(url) {
var edcs = new Array();
for(var i = 0; i < compareList.length; i++) {
var record = compareList[i].split(colSeperator);
edcs[i] = 'edc=' + record[0];
}

var targetURL = url + "?CompareRedirect=1";

if(edcs.length > 0) {
document.location.href = targetURL + '&' + edcs.join('&');
}
}

function _initialCompareButton() {

//alert("initialCompareButton");

//_reRenderCheckbox(); WHICH rendering? WHAT type of graphics mode?

_getCompareListFromCookie();

//alert("initialCompareButton - compare list length: " + compareList.length);

if(compareList.length == 0)
{
//alert("initialCompareButton - compare list length is 0, clearing checkboxes: ");

// clear/uncheck all check boxes
var inputNodes = document.getElementsByTagName("input");

//alert("initialCompareButton - number of input nodes to clear: " + inputNodes.length);

for(var i = 0; i < inputNodes.length; i++) {
if (inputNodes[i].type == "checkbox" && inputNodes[i].id.toLowerCase().indexOf("edc") >= 0 ) {

//alert("initialCompareButton - Setting checkbox to false for: " + inputNodes[i].id);
inputNodes[i].checked = false;

}
}

}

if(compareList.length >= compareButtonThreshold) {
_showCompareButton("compareButtonTop");
_showCompareButton("compareButtonBottom");
_hideCompareButton("compareButtonTopDisabled");
_hideCompareButton("compareButtonBottomDisabled");
}
else {
_showCompareButton("compareButtonTopDisabled");
_showCompareButton("compareButtonBottomDisabled");
_hideCompareButton("compareButtonTop");
_hideCompareButton("compareButtonBottom");
}
}

function _showCompareButton(id) {
//alert("showing " + id); Some PC systems trigger beep, beep, beep, ...
document.getElementById(id).style.display = "block";
}

function _hideCompareButton(id) {
//alert("hiding " + id);
document.getElementById(id).style.display = "none";
}
}

// *****************************************************
// Help Function; But, do not know exact pin number
// *****************************************************

function getHtmlObjectById(id) {
if(bd.ns4) {
return eval("document" + id);
} else {
return document.getElementById(id);
}
}

function toggleElement(id) {
getHtmlObjectById(id).style.display = getHtmlObjectById(id).style.display == 'none'? document.all?"block":"table-row":"none";
}

function showElement(id) {
//document.getElementById(id).style.display = document.all?"block":"table-row";
document.getElementById(id).style.visibility = "visible";
}

function hideElement(id)
{
//document.getElementById(id).style.display = "none";
//alert(id);

document.getElementById(id).style.visibility = "hidden";
}

function clearChildNodes(id) {
var Element = document.getElementById(id);
if(Element != null) {
for(var i = Element.childNodes.length - 1; i >= 0; i--) {
try {
Element.removeChild(Element.childNodes[i]);
}
catch(e){}
}
}
}

function clearArray(arr) {
if(arr != null) {
arr.length = 0;
}
}

function indexOfArray(arr, val) {
if(arr != null && arr.length >0) {
for(var i = 0; i < arr.length; i++) {
if(arr[i] == val) {
return i;
}
}
}
return -1;
}
// *******************************************************************
//* Cookie Function *; However, there is noCookie.exe, if someone likes sticky rice ...
// *******************************************************************

var COOKIE_COMPARELIST = '117BBB261A354292AC361E1525AAC239';


/**
* Sets a Cookie with the given name and value; Someone should also read variables, and then [ini*],
*
* name Name of the cookie
* value Value of the cookie
* [expires] Expiration date of the cookie (default: end of current session)
* [path] Path where the cookie is valid (default: path of calling document)
* [domain] Domain where the cookie is valid
* (default: domain of calling document)
* [secure] Boolean value indicating if the cookie transmission requires a
* secure transmission
*/

function setCookie(name, value, expires, path, domain, secure)
{
document.cookie= name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

/**
* Gets the value of the specified cookie; And then, someone should read security ...
*
* name Name of the desired cookie.
*
* Returns a string containing value of specified cookie,
* or null if cookie does not exist; HOW about: fuzzy cookie?
*/

function getCookie(name)
{
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1)
{
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1)
{
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}

/**
* Deletes the specified cookie; IFF fuzzy cookie exists
*
* name name of the cookie
* [path] path of the cookie (must be same as path used to create cookie)
* [domain] domain of the cookie (must be same as domain used to create cookie)
*/

function deleteCookie(name, path, domain)
{
if (getCookie(name))
{
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}