
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className.split(" ");
for (var j = 0; j < classes.length; j++) {
var className = classes[j];
if (className == cl) {
retnode.push(elem[i]);
}
}
}
return retnode;
}

var DomHTML = {

getDocumentWidth: function (_document) {
if (!_document) { _document = document;}
if(_document.body) {
if(_document.body.scrollWidth || _document.body.scrollWidth == 0) {
return _document.body.scrollWidth;
}
if(_document.documentElement) {
return _document.documentElement.offsetWidth;
}
return _document.body.offsetWidth;
}

if(_document.width || _document.width == 0) {
return _document.width;
}
return 0;
},


getScrollTop: function() {
if(window.scrollY) { return window.scrollY;}
if(window.pageYOffset) { return window.pageYOffset;}
if(document.documentElement && document.documentElement.scrollTop){
return document.documentElement.scrollTop;
} else if(document.body && document.body.scrollTop) {
return document.body.scrollTop;
}
return 0;
},


getDocumentHeight: function () {
if(document.body) {
if(document.body.scrollHeight || document.body.scrollHeight == 0) {
return document.body.scrollHeight;
}
if(document.documentElement) {
return document.documentElement.offsetHeight;
}
return document.body.offsetHeight;
}
if(document.height || document.height == 0) {
return document.height;
}
return 0;
},


effects: {

width: function(_target, _width, _fade) {
var current = _target.offsetWidth;
if (!_fade) {
var width = _width;
} else {
var width = current + ((_width - current) / _fade);
if (width != current) {
setTimeout(function() { DomHTML.effects.width(_target, _width, _fade / 1.25)}, 50);
}
}
_target.style.width = width + "px";
},

opacity: function(_target, _opacity, _fade, _fadetype) {
var current = _target.style.opacity * 100;
if (!_fade) {
var opacity = _opacity;
} else {
var opacity = Math.round(current + ((_opacity - current) / _fade));
if (opacity != current) {
setTimeout(function() { DomHTML.effects.opacity(_target, _opacity, _fade / 1.25)}, 50);
}
}
_target.style.zoom = 1;
_target.style.filter = 'alpha(opacity=' + (opacity) + ')';
_target.style.MozOpacity = opacity / 100;
_target.style.opacity = opacity / 100;
}
},


addEvent: function(elemObj, eventType, funcName, useCapture) {
if (!elemObj) { return false;}
if (elemObj.addEventListener){
elemObj.addEventListener(eventType, funcName, useCapture);
} else if (elemObj.attachEvent){
elemObj.attachEvent("on"+eventType, funcName);
} else {
return false;
}
return true;
}

};


var imageWindow = {

images: "",

start: function() {
imageWindow.images = new Array();
var images = document.getElementsByTagName("img");
var imax = images.length;
for (var i=0;i<imax;i++) {
if (!images[i].className) { continue;}
imageWindow.images[images[i].src] = new Image();
imageWindow.images[images[i].src].src = images[i].src;
if (!images[i].className.match(/ImageWindow/)) { continue;}
images[i].onclick = imageWindow.setOpen (images[i]);
images[i].style.cursor = "pointer";
}
},


setOpen: function(TARGET) {
var func = function() {
imageWindow.open(TARGET.src, "imageWindow", TARGET.width, TARGET.height);
}
return func;
},
open: function(URL, NAME, WIDTH, HEIGHT, SCROLL, RESIZE, TOOLBAR, LOCATION, DIRECTORIES, STATUS, MENUBAR) {
    var win;
WIDTH = imageWindow.images[URL].width;
HEIGHT = imageWindow.images[URL].height;
NAME = NAME || "imageWindow";
WIDTH = WIDTH || 640;
HEIGHT = HEIGHT || 480;
SCROLL = SCROLL || "no";
RESIZE = RESIZE || "yes";
TOOLBAR = TOOLBAR || "no";
LOCATION = LOCATION || "no";
DIRECTORIES = DIRECTORIES || "no";
STATUS = STATUS || "no";
MENUBAR = MENUBAR || "no";
if (WIDTH > (screen.width - 100)) {
WIDTH = screen.width - 100;
SCROLL = "yes";
}
if (HEIGHT > (screen.height - 200)) {
HEIGHT = screen.height - 200;
SCROLL = "yes";
}
    win = window.open(
"",
NAME,
"toolbar=" + TOOLBAR +
",location=" + LOCATION +
",directories=" + DIRECTORIES +
",status=" + STATUS +
",menubar=" + MENUBAR +
",scrollbars=" + SCROLL +
",resizable=" + RESIZE +
", width="+ WIDTH +
", height=" + HEIGHT
);
win.document.open();
win.document.write("<html><head><title>imageWindow</title><style type=\"text/css\">*{margin: 0;padding: 0;}</style></head><body><img src=\"" + URL + "\"></body></html>");
win.document.close();
win.moveTo(30, 30);
    win.focus();
}
};

var imageReplace = {

mainImage: "",

start: function() {
var images = document.getElementsByTagName("img");
var imax = images.length;
for (var i=0;i<imax;i++) {
if (!images[i].className) { continue;}
if (images[i].className.match(/MainImage/)) {
imageReplace.mainImage = images[i];
continue;
}
if (!images[i].className.match(/Thumbnail/)) { continue;}
images[i].onmouseover = imageReplace.setReplace (images[i].src);
}
},


setReplace: function(SRC) {
var func = function() {
imageReplace.mainImage.src = SRC;
}
return func;
}

};

var newWindow = {

start: function() {
var links = document.getElementsByTagName("a");
var imax = links.length;
for (var i=0;i<imax;i++) {
if (!links[i].rel) { continue;}
if (!links[i].rel.match(/newWindow/)) { continue;}
var args = links[i].rel.replace("newWindow", "").split(" ");
args.shift();
args.unshift(links[i].title);
args.unshift(links[i].href);
links[i].onclick = newWindow.setOpen (args);
}
},


setOpen: function(URL) {
var func = function() {
newWindow.open(URL);
return false;
}
return func;
},
open: function(_args) {
    var win;
URL = _args[0];
NAME = _args[1] || "newWindow";
WIDTH = _args[2] || 300;
HEIGHT = _args[3] || 450;
SCROLL = _args[4] || "yes";
RESIZE = _args[5] || "yes";
TOOLBAR = _args[6] || "no";
LOCATION = _args[7] || "no";
DIRECTORIES = _args[8] || "no";
STATUS = _args[9] || "no";
MENUBAR = _args[10] || "no";
    win = window.open(
URL,
NAME,
"toolbar=" + TOOLBAR +
",location=" + LOCATION +
",directories=" + DIRECTORIES +
",status=" + STATUS +
",menubar=" + MENUBAR +
",scrollbars=" + SCROLL +
",resizable=" + RESIZE +
", width="+ WIDTH +
", height=" + HEIGHT
);
    win.focus();
}
};


var groupTree = {

start: function() {

var parents = document.getElementsByClassName("Parent");
var imax = parents.length;

for (i = 0; i < imax; i++) {

if (parents[i].className.match(/Enable/)) {
var display = "block";
} else {
var display = "none";
}

var childs = parents[i].childNodes;
var jmax = childs.length;
for (j = 0; j < jmax; j++) {
if (!childs[j].tagName) { continue;}
if (childs[j].tagName.toLowerCase() == "a") {
if (childs[j].href.substr(-1) == "#") {
childs[j].onclick = function () { return false;};
}
}
if (!childs[j].className) { continue;}
if (childs[j].className.match(/Child/)) {
childs[j].style.display = display;
continue;
}
if (childs[j].className.match(/OpenClose/)) {
childs[j].onclick = groupTree.setOpenClose(childs, childs[j]);
continue;
}
}
}

},


setOpenClose: function(_childs, _button) {
var func = function() {
var imax = _childs.length;
if (_button.className.match(/Enable/)) {
var state = "Disable";
} else {
var state = "Enable";
}
for (var i = 0; i < imax; i++) {
if (!_childs[i].className) { continue;}
if (!_childs[i].className.match(/Child/)) { continue;}
if (state == "Enable") {
_childs[i].style.display = "block";
} else {
_childs[i].style.display = "none";
}
}
_button.className = "OpenClose " + state;
}
return func;
}

}

function phiwispot() {
if (document.body.id == "shop-itemdetail") {
imageWindow.start();
imageReplace.start();
}
if (document.body.id == "store-location") {
imageReplace.start();
}
groupTree.start();
newWindow.start();
}
DomHTML.addEvent(window, "load", phiwispot);

