﻿// JScript File
function GetStringFromResponse(response)
{
/*
    var i = 0;
    var x = "";
    while (i<response.value.length)
    {                    
        x = x + "<label" +  "id=lbl" + i + ">" + response.value[i] + "</label>";               
        i = i + 1;
        x = x + "&nbsp&nbsp <label" +  "id=lbl" + i + ">" + response.value[i] + "</label>";               
        x = x + "<br/>"
        i = i + 1;                            
    }
    return x;        
*/
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function getElementByClassName( searchClass, node, tag)
{
	var elmCollection = getElementsByClass(searchClass,node? node: null ,tag? tag:"");
	if (elmCollection.length) return elmCollection[0];
	return null;
}

function newImage( imgURL) {
	var newImg= new Image();
	newImg.src = imgURL;
	if ( newImg )  return newImg;
	return false;
}

function preloadImages() {
	var a=preloadImages.arguments; 
	var cImg = null;
	for(i=0; i<a.length; i++) 
	    if (a[i].indexOf("#")!=0) {
	        cImg = newImage(a[i] );
	    }
}

function menuInit( applicationPath ) {
	preloadImages(  applicationPath + "/tradepoint/b2c/Pictures/img/menu/menuBgIncPngHover.png",  applicationPath + "/tradepoint/b2c/Pictures/img/menu/menuBgEndPngHover.png");
	
	if(navigator.appName!="Microsoft Internet Explorer") return;
	
	var version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if (isNaN(version)) return;
    if ((version >= 5.5) && (version < 7)) { 
	
	    var menuDiv = $("topNavigation");
	    if ( !menuDiv ) return;	
	    var menuLinks = getElementsByClass("topmenu", menuDiv, "A");
	    for (var i=0;i<menuLinks.length;i++){
		    menuLinks[i].onmouseover = menuHover;
		    menuLinks[i].onmouseout = menuOut;
		    menuLinks[i].applicationPath = applicationPath;
	    }
	    var menuLinksSelected = getElementsByClass("selected", menuDiv, "A");
	    for (var i=0;i<menuLinks.length;i++){
		   
	    }
	    
	}
}

function menuHover() {
	var menuBefore = getElementsByClass("incMenu", this, "SPAN");
	var menuAfter = getElementsByClass("endMenu", this, "SPAN");
	menuBefore.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.applicationPath + "/Tradepoint/b2c/Pictures/img/menu/menuBgIncPngHover.png')";
	menuBefore.backgroundImage = "url(none)";
	menuAfter.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.applicationPath + "/Tradepoint/b2c/Pictures/img/menu/menuBgIncEndHover.png')";
	menuAfter.backgroundImage = "url(none)";	
}
function menuOut() {
	var menuBefore = getElementsByClass("incMenu", this, "SPAN");
	var menuAfter = getElementsByClass("endMenu", this, "SPAN");
	menuBefore.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.applicationPath + "/Tradepoint/b2c/Pictures/img/menu/menuBgIncPng.png')";
	menuBefore.backgroundImage = "url(none)";
	menuAfter.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.applicationPath + "/Tradepoint/b2c/Pictures/img/menu/menuBgIncEnd.png')";
	menuAfter.backgroundImage = "url(none)";	
}


function newImage(Src){
		var img = new Image();
		img.src = Src;
		if(img) return img;
		else return null;
	}
	
function addHoverEvent(img) {
	if (img.baseSrc) return;
	img.baseSrc = img.src;
	s = img.baseSrc.toString();
	var dotPos = s.lastIndexOf(".");
	var srcPart1 = s.substring(0, dotPos);
	var srcExtension = s.substring(dotPos, s.length);
	var srcHover=srcPart1 + "_hover" + srcExtension;
	img.hover=newImage(srcHover);
	img.style.cursor = "pointer";
	img.onmouseover = imgHover;
	img.onmouseout = imgOut;
	return true;
}

function imgHover() {
	if(this.hover && this.hover!= null )	this.src = this.hover.src;		
}
function imgOut() {		
	this.src = this.baseSrc;
}


/* CUSTOM PRODUCT DISPLAY FUNCTION */
function addListingBehaviour( pClassName )
{
	var handlerName = "handler_" + pClassName;
	if ( eval( "window." + handlerName ) )
	{
		eval( handlerName + "()" );		
	}
	
}
/*
	handler for collapsing list details when users choses ListBox display style 
	as a rule, use "handler_" + classname as method name
*/
function handler_PinpointBox( )
{
	var listContainer = getElementsByClass( "PinpointBox" );
	if (!listContainer ) return;
	var itemCount = listContainer.length;
	if (!itemCount) return;
	var container = null;
    var aExpand = null;
    var listHeader = null;
	
    // preload Images
    var urlLocation = location.toString();
    urlLocation = urlLocation.toLowerCase().split("tradepoint");
    var urlRoot = urlLocation[0];
    
    var titleImgHover = new Image();
    titleImgHover.src = (urlRoot + "/Tradepoint/B2C/Pictures/img/itemDock_titleBgHover.gif");
     
	var spanContainer = null;
    
	for ( var i=0; i< itemCount; i++ )
	{
		container = listContainer[i];
		listHeader = getElementByClassName( "pName" ,container,"DIV");
		if (!listHeader) continue;
		
        aExpand = document.createElement("a");
        aExpand.status = 0;
        aExpand.targetBlock = container;
        aExpand.className = "arrow_expand";
        aExpand.href = "javascript:;";
        aExpand.title = "Show item details";
        container.insertBefore(aExpand, listHeader);
        
		var containerWidth = 0;
		
        aExpand.onclick =  function(){
            if ( this.status == 0)
            {
                if (this.targetBlock) 
				{
					this.spanParent = this.targetBlock.parentElement? this.targetBlock.parentElement : this.targetBlock.parentNode ;
					if ( this.spanParent )
					{
						containerWidth = parseInt(this.targetBlock.offsetWidth);
						if( !containerWidth )
							containerWidth = this.targetBlock.style.width? this.targetBlock.style.width : this.targetBlock.clientWidth;
						if( containerWidth )							
							this.spanParent.style.width = parseInt(this.targetBlock.offsetWidth) + "px";	
					}
					this.targetBlock.className =  "PinpointBoxExpanded";
				}
                this.status = 1;
                this.title = "Hide item details";
                this.className = "arrow_collapse";
                this.blur();
            } else {
                if (this.targetBlock) this.targetBlock.className =  "PinpointBox";
				this.status = 0;
                this.className = "arrow_expand";
                this.blur();
            }
       }
	}	
}