/**
* @fileoverview ebiz.js: A module used for client specific functionality
*
* This module defines a single symbol named "Venda.ebiz"
* all ebiz utility functions are stored as properties of this namespace
* functions that are spacific this site shoudl be added to this file only.
*/

//Declare namespace for ebiz
Venda.namespace("Ebiz");

/**
 * example function below
 * ebiz.myFunctionname = function(param1, param2) {
 *	..... Place function code here ....
 * }; 
 */

/* ----- Attribute Swatch Function : support up to 2 attributes (ie. colour and size) -----*/

Venda.namespace("Ebiz.AttributeSwatch");
Venda.Ebiz.AttributeSwatch.ListAttributes = new Array();
Venda.Ebiz.AttributeSwatch.filters = new Array();
Venda.Ebiz.AttributeSwatch.existingAttributes = new Array();
Venda.Ebiz.AttributeSwatch.availAttributes = new Array();
Venda.Ebiz.AttributeSwatch.defaultprice = "";
Venda.Ebiz.AttributeSwatch.defaultwasprice = "";
Venda.Ebiz.AttributeSwatch.noswatch = "/content/ebiz/thace5/resources/images/noswatch.gif";

Venda.Ebiz.AttributeSwatch.initListAttributes = function(attrColumn, attrName) {
	for (var eachKey in product.attributeValues) {
		if (typeof product.attributeValues[eachKey] != "function") {
			this.addToListAttributes(attrColumn,product.attributeValues[eachKey].values[attrColumn]);		
		}
	}
	Venda.Ebiz.AttributeSwatch.displayListAttributes(attrColumn, attrName);
	if(this.attrNum==1){Venda.Ebiz.AttributeSwatch.checkAvailOneAttributes(attrColumn, attrName);}
};

Venda.Ebiz.AttributeSwatch.addToListAttributes = function(attrColumn, attrValue) {
	if (!this.isExistInListAttributes(attrColumn,attrValue)) {
		if (!this.ListAttributes[attrColumn]) {
			this.ListAttributes[attrColumn] = new Array();
		}
		this.ListAttributes[attrColumn].push(attrValue);

	}
};

Venda.Ebiz.AttributeSwatch.isExistInListAttributes = function(attrColumn, attrValue) {
	var found = false;
	if (this.ListAttributes[attrColumn]) {
		for (var eachValue in this.ListAttributes[attrColumn]) {
			if (this.ListAttributes[attrColumn][eachValue] == attrValue) { 			
				found = true; 
				break; 
			}
		}
	}
	return found;
};

Venda.Ebiz.AttributeSwatch.createListAttributes=function(attrColumn,attrName,ddObj){
	this.ListAttributes[attrColumn] = new Array();
	for(i=0; i < ddObj.options.length ; i++){
		this.ListAttributes[attrColumn].push(ddObj.options[i].value);
	}
	Venda.Ebiz.AttributeSwatch.displayListAttributes(attrColumn, attrName);
	if(this.attrNum==1){Venda.Ebiz.AttributeSwatch.checkAvailOneAttributes(attrColumn, attrName);}
}

Venda.Ebiz.AttributeSwatch.displayListAttributes = function (attrColumn, attrName){
	var str = "<ul class=attribute_"+attrColumn+">";
	var chkString = "";
	for(var i=0; i < this.ListAttributes[attrColumn].length; i++){
		// if att=color use image for swatch
		if (attrName.toLowerCase() == "colour" || attrName.toLowerCase() == "color") {
			if (!Venda.Ebiz.ProductDetail.allImages[this.ListAttributes[attrColumn][i]] ||  Venda.Ebiz.ProductDetail.allImages[this.ListAttributes[attrColumn][i]].setswatch == "") {

			str += "<li class=\"swatch\"><a class=available id='swatch"+this.ListAttributes[attrColumn][i]+"' onmouseover=\"Venda.Ebiz.AttributeSwatch.showTooltipMessage('swatch"+this.ListAttributes[attrColumn][i]+"');\" onmouseout=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onmouseup=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onclick=\"Venda.Ebiz.AttributeSwatch.actionSet('"+attrColumn+"','"+this.ListAttributes[attrColumn][i]+"'); Venda.Ebiz.AttributeSwatch.changePrice('attr-sellprice','attr-wasprice'); Venda.Ebiz.ProductDetail.changeSet('"+this.ListAttributes[attrColumn][i]+"'); return false;\"><span class=\"swatchattribute\">"+this.ListAttributes[attrColumn][i]+"</span></a></li>";					
			} else {
				// has swatch image
				str += "<li class=\"swatch\"><a class=available id='swatch"+this.ListAttributes[attrColumn][i]+"' title=\""+this.ListAttributes[attrColumn][i]+"\" onmouseover=\"Venda.Ebiz.AttributeSwatch.showTooltipMessage('swatch"+this.ListAttributes[attrColumn][i]+"');\" onmouseout=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onmouseup=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onclick=\"Venda.Ebiz.AttributeSwatch.actionSet('"+attrColumn+"','"+this.ListAttributes[attrColumn][i]+"'); Venda.Ebiz.AttributeSwatch.changePrice('attr-sellprice','attr-wasprice'); Venda.Ebiz.ProductDetail.changeSet('"+this.ListAttributes[attrColumn][i]+"'); return false;\"><img class=\"swatchimage\" src=\""+Venda.Ebiz.ProductDetail.allImages[this.ListAttributes[attrColumn][i]].setswatch+"\" alt=\""+this.ListAttributes[attrColumn][i]+"\"></a></li>";
			}

		} else {
			str += "<li><a class=available id='swatch"+this.ListAttributes[attrColumn][i]+"' onmouseover=\"Venda.Ebiz.AttributeSwatch.showTooltipMessage('swatch"+this.ListAttributes[attrColumn][i]+"');\" onmouseout=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onmouseup=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onclick=\"Venda.Ebiz.AttributeSwatch.actionSet('"+attrColumn+"','"+this.ListAttributes[attrColumn][i]+"'); Venda.Ebiz.AttributeSwatch.changePrice('attr-sellprice','attr-wasprice'); return false;\">"+this.ListAttributes[attrColumn][i]+"</a></li>";		
		}
	}
	str = str + "</ul>";
	document.getElementById("productdetail-"+attrColumn).innerHTML = str;
};


Venda.Ebiz.AttributeSwatch.addFilter = function(attrColumn,attrValue) {
	var filterString="";
	this.filters[attrColumn] = attrValue;
	// clear background alert message
	document.getElementById("displaycolor").className = "default";
	document.getElementById("displaysize").className = "default";
	// update alert message
	Venda.Ebiz.AttributeSwatch.updateMessage();
};

Venda.Ebiz.AttributeSwatch.updateMessage = function(){
	if(this.attrNum==1){
		if(this.filters["att1"]!=""){
			document.getElementById("displaycolor").innerHTML = this.filters['att1'];
		}
	}else{
		if(this.filters["att1"]=="" || this.filters["att1"]==undefined){
			document.getElementById("displaysize").innerHTML = this.filters['att2'];
			document.getElementById("displaycolor").innerHTML = "Please select a " + this.attrDisplayName[0] + ".";
			document.getElementById("displaycolor").className = "warning";
			
		}else if(this.filters["att2"]=="" || this.filters["att2"]==undefined){
			document.getElementById("displaycolor").innerHTML = this.filters['att1'];
			document.getElementById("displaysize").innerHTML = "Please select a " + this.attrDisplayName[1] + ".";
			document.getElementById("displaysize").className = "warning";
		}
		if((this.filters["att1"]!="") && (this.filters["att2"]!="") && (this.filters["att1"]!=undefined) && (this.filters["att2"]!=undefined)){
			document.getElementById("displaycolor").innerHTML = this.filters["att1"];
			document.getElementById("displaysize").innerHTML = this.filters["att2"];
		}
	}
};

Venda.Ebiz.AttributeSwatch.validateAttributes = function(){
	var isSelected = true;
	if(this.attrNum==1){
		if(this.filters["att1"]==undefined || this.filters["att1"]==""){
			document.getElementById("displaycolor").innerHTML = "Please select a " + this.attrDisplayName[0] + ".";
			document.getElementById("displaycolor").className = "warning";
			isSelected = false;
		}
	}else{
		if(this.filters["att1"]==undefined || this.filters["att1"]==""){
			document.getElementById("displaycolor").innerHTML = "Please select a " + this.attrDisplayName[0] + ".";
			document.getElementById("displaycolor").className = "warning";
			isSelected = false;
		}
		if(this.filters["att2"]==undefined || this.filters["att2"]==""){
			document.getElementById("displaysize").innerHTML = "Please select a " + this.attrDisplayName[1] + ".";
			document.getElementById("displaysize").className = "warning";
			isSelected = false;
		}
	}
	return isSelected;
};
var a1="";
var a2 ="";
// Check if attribute exist and has onhand
Venda.Ebiz.AttributeSwatch.checkAvailAttributes = function(attrColumn,attrValue) {
	this.existingAttributes = new Array();
	this.availAttributes = new Array();
	var attrColumnSelect="";
	switch(attrColumn){
		case "att1": attrColumn="att2";attrColumnSelect="att1";break;
		case "att2": attrColumn="att1";attrColumnSelect="att2";break;
	}
	a=0;	
	if(attrColumn =="att1"){a1 = attrValue;}
	if(attrColumn =="att2"){a2 = attrValue;}
	var str="<ul class=attribute_"+attrColumn+">"; 
	for (var eachAttrSet in product.attributeValues) { 
		if(product.attributeValues[eachAttrSet].values[attrColumnSelect]==attrValue && (product.attributeValues[eachAttrSet].data["atronhand"]>0)){
			this.existingAttributes[a]=product.attributeValues[eachAttrSet].values[attrColumn]; 
			a++;
		}
		if(product.attributeValues[eachAttrSet].values[attrColumnSelect]==attrValue && (product.attributeValues[eachAttrSet].values[attrColumn]==a2)){
		 
			if(product.attributeValues[eachAttrSet].data["atronhand"]>0){
				document.getElementById('attrpricetext').className = '';
				document.getElementById('nostocktxt').className = 'hide';				
			}else{
				document.getElementById('attrpricetext').className = 'hide';
				document.getElementById('nostocktxt').className = '';				
			}
		}
		
		if(product.attributeValues[eachAttrSet].values[attrColumnSelect]==attrValue && ((product.attributeValues[eachAttrSet].values[attrColumn]==a2) || (product.attributeValues[eachAttrSet].values[attrColumn]==a1))){
			var etaDate = product.attributeValues[eachAttrSet].data["atretamn"] + "/" + product.attributeValues[eachAttrSet].data["atretady"] + "/" + product.attributeValues[eachAttrSet].data["atretayr"];
			var releaseDate = product.attributeValues[eachAttrSet].data["atrreleasemn"] + "/" + product.attributeValues[eachAttrSet].data["atrreleasedy"] + "/" + product.attributeValues[eachAttrSet].data["atrreleaseyr"];
			var onHand = product.attributeValues[eachAttrSet].data["atronhand"];
			var atrSku = product.attributeValues[eachAttrSet].data["atrsku"];
			
			// RELEASE DATE
			if(releaseDate.match("//") == null){
				if (!Venda.Ebiz.checkDate(releaseDate)){ 
					// if a date is future
					//alert("releaseDate case "+releaseDate);
					jQuery("#preorderbox input").attr("id","addproduct");
					jQuery(".addtobasket input").attr("id","");
					jQuery("#backorderbox input").attr("id","");
					jQuery(".addtobasket").hide();
					jQuery("#preorderbox").show();
					jQuery("#backorderbox").hide();
					jQuery("#stockindicator").html("<p class=\"releaseDate\">This item is available for pre-order with an estimated ship date of "+releaseDate+". <span class=\"stockNote\">Note: You will not be charged for this item until it ships.</span></p>");
					jQuery("#stockindicator").show();
					jQuery("#oixtorderstatus").val('Pre-Order');
					jQuery("#oixtorderestimatedate").val('The estimated ship date is '+releaseDate+'.');
				} else{
						// if a Release date was set but it's already in the past
						jQuery("#preorderbox input").attr("id","");
						jQuery(".addtobasket input").attr("id","addproduct");
						jQuery("#backorderbox input").attr("id","");
						jQuery(".addtobasket").show();
						jQuery("#preorderbox").hide();
						jQuery("#backorderbox").hide();
						jQuery("#stockindicator").html("");
						jQuery("#stockindicator").hide();
						jQuery("#oixtorderstatus").val('');
						jQuery("#oixtorderestimatedate").val('');
				}
				if(etaDate.match("//") == null){
					if(Venda.Ebiz.checkDate(releaseDate) && !Venda.Ebiz.checkDate(etaDate)){
						jQuery("#backorderbox input").attr("id","addproduct");
						jQuery(".addtobasket input").attr("id","");
						jQuery("#preorderbox input").attr("id","");
						jQuery(".addtobasket").hide();
						jQuery("#preorderbox").hide();
						jQuery("#backorderbox").show();
						jQuery("#stockindicator").html("<p class=\"releaseDate\">This item is currently back-order with an estimated ship date of "+etaDate+". <span class=\"stockNote\">Note: You will not be charged for this item until it ships.</span></p>");
						jQuery("#stockindicator").show();
						jQuery("#oixtorderstatus").val('Back-Order');
						jQuery("#oixtorderestimatedate").val('The estimated ship date is '+etaDate+'.');
					}
				}
			} else {
				jQuery("#preorderbox input").attr("id","");
				jQuery(".addtobasket input").attr("id","addproduct");
				jQuery("#backorderbox input").attr("id","");
				jQuery(".addtobasket").show();
				jQuery("#preorderbox").hide();
				jQuery("#backorderbox").hide();
				jQuery("#stockindicator").html("");
				jQuery("#stockindicator").hide();
				jQuery("#oixtorderstatus").val('');
				jQuery("#oixtorderestimatedate").val('');
			}
		}
	}
	this.updateListAttributes(attrColumn);
};

/**
* Take the eta/release date of the attribute then compare to now date
* @param {string} the date of attribute product with "mm/dd/yyyy" format
* return true if now date is greter than date param
*/
Venda.Ebiz.checkDate = function(date){
	var chkDate = new Date(date);
	var nowDate = new Date();
	return (nowDate > chkDate);
};


Venda.Ebiz.AttributeSwatch.updateListAttributes = function(attrColumn) {
	//compare existingAttributes with the full range
	for(i=0; i < this.ListAttributes[attrColumn].length; i++){
		// if there is no any existingAttributes (ie. all out of stock)
		if(this.existingAttributes.length==0){this.availAttributes[i] = false;}
		for(j=0; j < this.existingAttributes.length; j++){			
			if(this.ListAttributes[attrColumn][i]==this.existingAttributes[j]){	
				this.availAttributes[i] = this.existingAttributes[j];
				break;
			}else{
				this.availAttributes[i] = false;
			} 
		}

		if(this.availAttributes[i] !== false){
			if(this.ListAttributes[attrColumn][i]==this.filters[attrColumn]){
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className="selected";
			}else{
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className="available";
			}
		}else{
			document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className="notavail";
			if(this.attrNum==1){
				// if has only one attr - unclickable out of stock attribute
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).attributes["onclick"].value="";
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).style.cursor="default";
			}
			if(this.ListAttributes[attrColumn][i]==this.filters[attrColumn]){
				// clear if no combination
				this.filters[attrColumn]="";
				Venda.Ebiz.AttributeSwatch.addFilter(attrColumn,"");
				document.form.elements[attrColumn].value = "";
			}
		}
	}
};


// Highlight selected option
Venda.Ebiz.AttributeSwatch.highlightSelection = function(attrColumn,id){
	for(i=0; i < this.ListAttributes[attrColumn].length; i++){
		if(this.ListAttributes[attrColumn][i] == id){
			document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className = "selected";

		}else{
			if(document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className != "notavail"){
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className = "available";
			}
		}
	}
};

Venda.Ebiz.AttributeSwatch.changePrice = function(id, wasid){
	var price = "";
	var wasprice = "";

	if (this.attrNum == 1) {
		for (var eachAttrSet in product.attributeValues) {
			if(product.attributeValues[eachAttrSet].values["att1"]==this.filters["att1"]){
				if (product.attributeValues[eachAttrSet].data["atrsell"]!="" && product.attributeValues[eachAttrSet].data["atrsell"]!=undefined) {
					price = parseFloat(product.attributeValues[eachAttrSet].data["atrsell"]).toFixed(2);
				}
				if (product.attributeValues[eachAttrSet].data["atrwas"]!="" && product.attributeValues[eachAttrSet].data["atrwas"]!=undefined){
					wasprice = parseFloat(product.attributeValues[eachAttrSet].data["atrwas"]).toFixed(2);
				}
			}
		}	
	} else 	if (this.attrNum == 2) {
		for (var eachAttrSet in product.attributeValues) {
			if(product.attributeValues[eachAttrSet].values["att1"]==this.filters["att1"] && product.attributeValues[eachAttrSet].values["att2"]==this.filters["att2"]){
				if (product.attributeValues[eachAttrSet].data["atrsell"]!="" && product.attributeValues[eachAttrSet].data["atrsell"]!=undefined) {
					price = parseFloat(product.attributeValues[eachAttrSet].data["atrsell"]).toFixed(2);
				}
				if (product.attributeValues[eachAttrSet].data["atrwas"]!="" && product.attributeValues[eachAttrSet].data["atrwas"]!=undefined){
					wasprice = parseFloat(product.attributeValues[eachAttrSet].data["atrwas"]).toFixed(2);	
				}
			}
		}		
	}

	if (price == "") { price = this.defaultprice;}
	if (wasprice == "") { wasprice = this.defaultwasprice; }
	if (price != "" && wasprice != "") {
		document.getElementById(id).innerHTML = "<span class='textnow'>Now</span> " + product.labels['currsym'] + price;
	}
	if (price != "" && wasprice == "") {
		document.getElementById(id).innerHTML = "<span class='textnow'></span> " + product.labels['currsym'] + price;
	}
	if (wasprice!="" && parseFloat(wasprice)>parseFloat(price)) {	
		document.getElementById(wasid).innerHTML = product.labels['currsym'] + wasprice;	
	}else{
		document.getElementById(wasid).innerHTML = "";
	}
};

Venda.Ebiz.AttributeSwatch.actionSet = function(attrColumn,attrValue){
	document.form.elements[attrColumn].value = attrValue;
	this.addFilter(attrColumn,attrValue);
	this.highlightSelection(attrColumn,attrValue);
	// do checkAvailAttributes only if has more than one attributes
	if(this.attrNum>1){this.checkAvailAttributes(attrColumn,attrValue)}
//################### Kellwood Final Sale Code, by Greg Starek ########################

	var filterKey = "";
	if(this.filters.length>1) {
		for (var thisThing in this.filters ) {
			filterKey = filterKey + this.filters[thisThing];
		}
	} else {
		if (attrColumn=="att1") {
			if (document.getElementById("displaysize").innerHTML!="" && document.getElementById("displaysize").className!="warning") {
				filterKey = attrValue + document.getElementById("displaysize").innerHTML;
			} else {
				for (var theKey in product.attributeValues ) {
					for (var theAttr in product.attributeValues[theKey].values ) {
						var theValue = product.attributeValues[theKey].values[theAttr];
						if ( theAttr==attrColumn && theValue==attrValue ) {
							filterKey = theKey;
						}
					}
				}
			}
		} else if (attrColumn=="att2") {
			if (document.getElementById("displaycolor").innerHTML!="" && document.getElementById("displaycolor").className!="warning") {
				filterKey = document.getElementById("displaycolor").innerHTML + attrValue;
			}
		}
	}
	if (filterKey!="") {
		var indFS = product.attributeValues[filterKey].data['atrsuplsku'];
		if (indFS=="FINAL SALE") {
			messageFS = "<p><font color='Red'><b>FINAL SALE</b></font> - No returns or exchanges</p>";
		} else {
			messageFS = indFS;
		}
		document.getElementById("finalSaleMessage").innerHTML = messageFS;
	} else {
		document.getElementById("finalSaleMessage").innerHTML = "";
	}

//###################  Kellwood Final Sale Code, Ends here   ########################
};


/* ----- Swatch Function : change image and sideview image -----*/

Venda.namespace("Ebiz.ProductDetail");

Venda.Ebiz.ProductDetail.allImages = new Array();
Venda.Ebiz.ProductDetail.config = {
	objDropdown: null,
	objDefaultImage: null,
	objMediumArea: null,
	objLinkArea: null,	
	objSwatchArea: null,
	objSideviewArea: null,
	objZoomThumbs: null,
	objProduct: null,
	swatchTitle: "",
	sideviewTitle: "",
	mediumTitle: "",
	viewLargeTitle: "",
	viewLargeText: "",
	loadingHeader: "",
	loadingImage: "",	
	popupHeader: "",
	flSource: "",
	imageware: "",
	enlargeImg: "",
	enlargeLink: "",
	enlargeText: ""
};
Venda.Ebiz.ProductDetail.init = function(settings) {
	for (var eachProp in settings) {
		this.config[eachProp] = settings[eachProp];
	}
};
Venda.Ebiz.ProductDetail.loadImage = function(attValue, imgSources) {
	this.allImages[attValue] = imgSources;
};
Venda.Ebiz.ProductDetail.isClickable = function(dataChecking) {

	var able = false;
	if (dataChecking instanceof Array) {
		for (var i = 0; i < dataChecking.length; i++) {
			if (dataChecking[i] != "") {
				able = true;
			}
		}
	}
	return able;
}
Venda.Ebiz.ProductDetail.displaySwatch = function() {	

	var allSwatch = "";

	for (var eachData in this.allImages) {		
		if (this.isClickable(this.allImages[eachData].settsideview) && eachData != "" && this.allImages[eachData].setswatch != "") {
			allSwatch = allSwatch + "<a href=\"#\" onclick=\"Venda.Ebiz.ProductDetail.changeSet('"+eachData+"'); return false;\" title=\""+this.config["swatchTitle"]+" - "+eachData+"\"><img src=\""+this.allImages[eachData].setswatch+"\" alt=\" "+eachData+"\"></a>";
			
		} else if(eachData!="" && this.allImages[eachData].setswatch) {
			allSwatch = allSwatch + "<img src=\""+this.allImages[eachData].setswatch+"\">";		
		}
	}
	
	this.config["objSwatchArea"].innerHTML = allSwatch;
};

Venda.Ebiz.ProductDetail.getImageTag = function(mappingData) {
	var imgTag = "";
	if ((mappingData.imgSource=="")&&(mappingData.noImage !="")) {
		mappingData.imgSource = mappingData.noImage;
	}
	if (mappingData.imgSource!="") {
		imgTag = "<img src=\""+mappingData.imgSource+"\" alt=\""+mappingData.alt+"\">";
	}
	if (mappingData.imgChange) {
		imgTag = "<a href=\""+mappingData.imgChange+"\" onclick=\"Venda.Ebiz.ProductDetail.changeMainImage({attValue: '"+mappingData.attValue+"', no: "+mappingData.currentImage+"}); Venda.Ebiz.ProductDetail.changeViewLargeLink({attValue: '"+mappingData.attValue+"', no: "+mappingData.currentImage+"}); Venda.Ebiz.ProductDetail.highlightSideview(this); return false;\" title=\""+mappingData.imgTitle+"\">"+ imgTag + "</a>";
	} 		
	if (mappingData.imgPopup) {
		imgTag = "<a href='' onclick='showZoom(\""+mappingData.imgPopup+"\");return false;' id='enlarge_img2' title='"+this.config["enlargeImg"]+"'>" + imgTag + "</a>";
	}
	return imgTag;
};

Venda.Ebiz.ProductDetail.highlightSideview = function (obj){
	$("#productdetail-sideview a").removeClass("selected");
	obj.className = "selected";	
};

Venda.Ebiz.ProductDetail.changeMainImage = function(mappingData) {
	var attValue = mappingData.attValue;
	var currentImage = mappingData.no | 0;
	var imgSource = this.allImages[attValue].setlsideview[currentImage];
	var imgPopup = this.allImages[attValue].setxlsideview[currentImage];
	var mainImage = this.getImageTag({
		noImage: this.config["noImage"]["medium"],
		imgSource: imgSource,
		imgPopup: imgPopup,
		attValue: attValue,
		alt: "Main image - " + attValue,
		imgTitle: this.config["mediumsTitle"],
		currentImage: 0
	});	
	this.config["objMediumArea"].innerHTML = "" + mainImage;
};

Venda.Ebiz.ProductDetail.changeViewLargeLink= function(mappingData) {
	var attValue = mappingData.attValue;
	var currentImage = mappingData.no | 0;
	var imgPopup = this.allImages[attValue].setxlsideview[currentImage];
	var viewLarge = "";
	
	if (imgPopup) {
		viewLarge = "<a href='' onclick='showZoom(\""+imgPopup+"\");return false;' id='enlarge_link2' title='"+this.config["enlargeLink"]+"'>" + this.config["enlargeText"] + "</a>";
		this.config["objLinkArea"].innerHTML = viewLarge;
	} else {
		viewLarge = "";
		this.config["objLinkArea"].innerHTML = viewLarge;
	}
};

Venda.Ebiz.ProductDetail.changeSideviewSet = function(mappingData) {
	var attValue = mappingData.attValue;
	var currentImage = mappingData.no | 0;
	var altviewData = "";
	var n=0;
	for (var i = 0; i < this.allImages[attValue].setlsideview.length; i++) {
		if (this.allImages[attValue].settsideview[i] != "" && this.allImages[attValue].setlsideview[i] != "") {
			n++;
			altviewData = altviewData + this.getImageTag({
				currentImage: i,
				imgSource: this.allImages[attValue].settsideview[i],
				imgChange: this.allImages[attValue].setlsideview[i],
				attValue: attValue,
				alt: attValue,
				imgTitle: this.config["sideviewTitle"]		
			});
		} 
	}
	this.config["objSideviewArea"].innerHTML = altviewData;
	this.showSideviewImage();
	var zoomThumbs = "";
	if (n==3) {
		zoomThumbs = zoomThumbs + "<div id='ZoomThumb1' class='zThumb' style='top:126px;' onclick=\"newZoom(1,'"+this.allImages[attValue].setxlsideview[1]+"')\"><img class='zThumb' id='ZoomThumbI1' src='"+this.allImages[attValue].settsideview[1]+"' /></div>";
		zoomThumbs = zoomThumbs + "<div id='ZoomThumb2' class='zThumb' style='top:224px;' onclick=\"newZoom(2,'"+this.allImages[attValue].setxlsideview[2]+"')\"><img class='zThumb' id='ZoomThumbI2' src='"+this.allImages[attValue].settsideview[2]+"' /></div>";
		zoomThumbs = zoomThumbs + "<div id='ZoomThumb3' class='zThumb' style='top:322px;' onclick=\"newZoom(3,'"+this.allImages[attValue].setxlsideview[3]+"')\"><img class='zThumb' id='ZoomThumbI3' src='"+this.allImages[attValue].settsideview[3]+"' /></div>";
	}
	if (n==2) {
		zoomThumbs = zoomThumbs + "<div id='ZoomThumb1' class='zThumb' style='top:175px;' onclick=\"newZoom(1,'"+this.allImages[attValue].setxlsideview[1]+"')\"><img class='zThumb' id='ZoomThumbI1' src='"+this.allImages[attValue].settsideview[1]+"' /></div>";
		zoomThumbs = zoomThumbs + "<div id='ZoomThumb2' class='zThumb' style='top:273px;' onclick=\"newZoom(2,'"+this.allImages[attValue].setxlsideview[2]+"')\"><img class='zThumb' id='ZoomThumbI2' src='"+this.allImages[attValue].settsideview[2]+"' /></div>";
	}
	if (n==1) {
		zoomThumbs = zoomThumbs + "<div id='ZoomThumb1' class='zThumb' style='top:224px;' onclick=\"newZoom(1,'"+this.allImages[attValue].setxlsideview[1]+"')\"><img class='zThumb' id='ZoomThumbI1' src='"+this.allImages[attValue].settsideview[1]+"' /></div>";
	}
	this.config["objZoomThumbs"].innerHTML = zoomThumbs;
};

Venda.Ebiz.ProductDetail.changeSet = function(attValue) {
	if (this.allImages[attValue]) {
		this.changeMainImage({attValue:attValue});
		this.changeViewLargeLink({attValue:attValue});
		this.changeSideviewSet({attValue:attValue,no:0});	
	}
};
Venda.Ebiz.ProductDetail.changePopup = function(number,objLink) {
//	$(
	$("#enlargedpopup").attr({src:objLink.href});
	$("#page-popup a").removeClass("selected");
	$(objLink).addClass("selected");	
};

Venda.Ebiz.ProductDetail.loadingPanel = new YAHOO.widget.Panel("loading_panel",  
														{ 
															width:"240px", 
															fixedcenter:true, 
															close:false, 
															draggable:false, 
															zindex:3,
															modal:true,
															visible:false															
														} 
													);	

Venda.Ebiz.ProductDetail.enlargePanel = new YAHOO.widget.Panel("enlarge_panel",  
														{ 
															fade: 0.24,															
															fixedcenter:true,
															draggable: true,
															zindex:4,
															modal:true,
															visible:false															
														} 
													);	


Venda.Ebiz.ProductDetail.createPopupPage = function(attValue,number) {
	var newData = new Array();
	var max = 0;
	var minusNumber = 0;


	if (this.allImages[attValue].setlarge != "") {
		newData[max] = this.allImages[attValue].setlarge;
		max++;
	} else {
		minusNumber = 1;
	}

	for (var i = 0; i < this.allImages[attValue].setlsideview.length; i++) {
		if (this.allImages[attValue].setlsideview[i] != "") {
			newData[max] = this.allImages[attValue].setlsideview[i];
			max++;
		}
	}
	var pageNumber = "";

	if (max > 1) {
		pageNumber = pageNumber + "<div id=\"page-popup\">";
		for (var i = 0; i < max; i++) {
			if (i == (number - minusNumber)) {
				pageNumber = pageNumber + "<a href=\""+newData[i]+"\" onclick=\"Venda.Ebiz.ProductDetail.changePopup("+i+",this); return false;\" class=\"selected\">"+(i+1)+"</a>";			
			} else {
				pageNumber = pageNumber + "<a href=\""+newData[i]+"\" onclick=\"Venda.Ebiz.ProductDetail.changePopup("+i+",this); return false;\">"+(i+1)+"</a>";
			}			
		}
		pageNumber = pageNumber + "</div>";
	}
	return pageNumber;
};
Venda.Ebiz.ProductDetail.setWidthPanel = function (panel, objImage) {
	document.getElementById("tag-invtname").style.display = "inline";
	var widthValue = (objImage.width > (document.getElementById("tag-invtname").offsetWidth + 100)) ? objImage.width + 50: document.getElementById("tag-invtname").offsetWidth + 130;
	panel.cfg.setProperty("width", widthValue + "px");
	document.getElementById("tag-invtname").style.display = "none";			
};
Venda.Ebiz.ProductDetail.doPopup = function(attValue,sLink,number) {
//	var pageNumber = this.createPopupPage(attValue,number);
	var pageNumber = "";	
	
	

	Venda.Ebiz.ProductDetail.loadingPanel.setHeader('<div class="tl"></div><span>'+Venda.Ebiz.ProductDetail.config.loadingHeader+'</span><div class="tr"></div>');
	Venda.Ebiz.ProductDetail.loadingPanel.setBody('<img src="'+Venda.Ebiz.ProductDetail.config.loadingImage+'" />');														
	Venda.Ebiz.ProductDetail.loadingPanel.render(document.body);
	Venda.Ebiz.ProductDetail.loadingPanel.show();

	Venda.Ebiz.ProductDetail.enlargePanel.setHeader('<div class="tl"></div><span>'+Venda.Ebiz.ProductDetail.config.popupHeader+'</span><div class="tr"></div>');		
	Venda.Ebiz.ProductDetail.enlargePanel.setBody( "<div id=\"enlarged\"><img src=\""+sLink+"\" id=\"enlargedpopup\" name=\"enlargedpopup\" onload=\"Venda.Ebiz.ProductDetail.setWidthPanel(Venda.Ebiz.ProductDetail.enlargePanel, this);Venda.Ebiz.ProductDetail.loadingPanel.hide();Venda.Ebiz.ProductDetail.enlargePanel.show();\">"+pageNumber+"</div><a href=\"#\" onClick=\"Venda.Ebiz.ProductDetail.enlargePanel.hide();\">Close</a>");
	Venda.Ebiz.ProductDetail.enlargePanel.render(document.body);	
};

Venda.Ebiz.ProductDetail.preloadImage = function(imgSource) {
	if (imgSource != "") {
		new Image().src = imgSource;
	}
};

Venda.Ebiz.ProductDetail.preloadAllImage = function() {
	for (var eachAttrValue in this.allImages) {
		var allImageData = this.allImages[eachAttrValue];
		
		this.preloadImage(allImageData.setswatch);
		this.preloadImage(allImageData.setlarge);
		for (var eachImage in allImageData.settsideview) {
			this.preloadImage(allImageData.settsideview[eachImage]);			
		}
		for (var eachImage in allImageData.setlsideview) {
			this.preloadImage(allImageData.setlsideview[eachImage]);			
		}
		for (var eachImage in allImageData.setxlsideview) {
			this.preloadImage(allImageData.setxlsideview[eachImage]);
		}		
	}
};

/* display sideview header if exist */
Venda.Ebiz.ProductDetail.showSideviewImage = function(){
	if(this.config["objSideviewArea"].innerHTML!=""){
		document.getElementById("sideviewheader").innerHTML = "<img src=\""+this.config["sideviewHeader"]+"\" alt=\"Alternative View\">";
		document.getElementById("sideviewheader").className = "";
	}else{
		document.getElementById("sideviewheader").innerHTML = "";
		document.getElementById("sideviewheader").className = "hide";
	}
};

/* Show tooltip for unavailable options */
Venda.Ebiz.AttributeSwatch.showTooltipMessage = function (id){
	if(document.getElementById(id).className=="notavail"){
		document.getElementById("swatchUnavailTooltip").className = "show";
		var posLeft = document.getElementById(id).offsetLeft-(document.getElementById("swatchUnavailTooltip").offsetWidth/2)+(document.getElementById(id).offsetWidth/2);
		var posTop = document.getElementById(id).offsetTop-document.getElementById("swatchUnavailTooltip").offsetHeight-document.getElementById("swatchUnavailTooltipArrow").offsetHeight;
		document.getElementById("swatchUnavailTooltip").style.left = 0+"px";
		document.getElementById("swatchUnavailTooltip").style.top = 0+"px";
	}
}

Venda.Ebiz.AttributeSwatch.hideTooltipMessage = function (){
	document.getElementById("swatchUnavailTooltip").className = "hidden";
}
 /**
 * Split a string so it can be displayed on multiple lines so it does not break display layout - used on order confirmation and order receipt page
 * @param {string} strToSplit string that needs to be split 
 * @param {Integer} rowLen length of row which will hold the string
 * @param {string} displayElem the html container which will display the splitted string
 */
Venda.Ebiz.splitString = function(strToSplit, rowLen, dispElem) {
	if(document.getElementById(dispElem)){
		var stringlist = new Array();
		while (strToSplit.length > rowLen) {
		   stringlist.push( strToSplit.slice(0,rowLen));
		   strToSplit=strToSplit.substr(rowLen);
		}
		if (strToSplit.length) {
			stringlist.push(strToSplit);
		}
		document.getElementById(dispElem).innerHTML = stringlist.join('<br>');
	}
};

//Remove function from general.js to Ebiz.js
//order confirmation and order receipt page - split the email address on the RHN if too long
function splitEmailAdd(usemail) {
	var stringlist = new Array();
	while (usemail.length > 30) {
	   stringlist.push( usemail.slice(0,30));
	   usemail=usemail.substr(30);
	}
	if (usemail.length) {
	  stringlist.push(usemail);
	}
	document.write(stringlist.join( '<br>' ));
}

//dynamic nav script
turnonToggle = 1; //change this to 0 if you don't want to use toggling
// preload controls
// change path to the desired location
shown = new Image();
shown.src = "/venda-support/images/bulleton.gif";
hidden = new Image();
hidden.src = "/venda-support/images/bulletoff.gif";

function dynamicContent(where,what) {
	// find out what tag the function is called from so the correct value is passed for url
	identifyTag = where.tagName;
	if (identifyTag == "A"){
		ajaxFunction(where+'&layout=noheaders&temp=subcategories',what);
		if (turnonToggle == 1){toggle(where);}
	} else if (identifyTag == "INPUT" || identifyTag == "SELECT") {
		ajaxFunction(where.value,what);
	}
}

//dynamic popup window script
// images default to venda-support directory, change the path to ebiz resources directory if you need to source your own versions
mingif = '/venda-support/images/min.gif';
closegif = '/venda-support/images/close.gif';
restoregif = '/venda-support/images/restore.gif';
resizegif = '/venda-support/images/resize.gif';

function dynamicWindow(where,name) {
	detailWin=dhtmlwindow.open('productdetailWin', 'iframe', where+'&layout=iframe&temp=productdetail_layer', name, 'width=650px,height=400px,resize=1,scrolling=1,center=1');
}
// you may edit the parameters in the final argument above to alter the appearance of the popup window

//Description: Returns the value of a specified URL parameter 
//Parameters:
//1. currURL = this is the URL which you wish to get the URL parameter value from
//2. urlParam = this is the name of the URL parameter you want to get the value for
//Returns: value for parameter specified urlParam.
function grabURL(currURL,urlParam) {
	//find out a value where is passed from current url
	var url = unescape(currURL);
	var spliter = '&';
	var sField = spliter+urlParam+'=';
	
	if (url.search(sField) == -1) {               
		sField = '?'+urlParam+'=';         
	}
	
	var urlArray = url.split(sField);
	if (urlArray[1]) {
		//get url param value
		var paramArray = urlArray[1].split(spliter);
		return(paramArray[0]);
	}
}

function validateQty(iform){
var iNum = /\D/;
var qty = iform.qty;

    if(iNum.test(qty.value)==true){
        alert("Please enter numbers only");
        return false;
    }
    else if(qty.value < "1"){
        alert("Please enter numbers more than 0."); 
    }
    else{
         iform.submit();
    }		
}	

// This function is used for defaulting the quantity to 1 or to make the quantity positive incase the user enters it wrong by mistake
function qtyValidate(thisBox,item){
  var regExp = /\D/g;
  var nonNum= thisBox.value.match(regExp);

    if(item > 0) {
        if ((nonNum != null) && (nonNum.length > 0) || (thisBox.value == "")) {
             thisBox.value = item;       
        }
    }else{
        if ((nonNum != null) && (nonNum.length > 0) || (thisBox.value == 0)) {
            thisBox.value = 1;        
        }
    }

}  
function popup(url,width,height,name) {
    if (width == '' || width == null) width = 800;
    if (height == ''|| height == null) height = 600;
    if (name == '' || name == null) name = "details";
    var props = "toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,titlebar=no,menubar=no,width="+width+",height="+height;
    w = window.open(url, name, props);
    if  (w)w.focus();
}

function getLayout(gTextId) {
	//find out a value where is passed from current url
	var url = unescape(window.location);
	
	if(url.indexOf("&") >= 0){
	var urlArray = url.split("&layout=")[1];
	var nLayout = urlArray.split("&")[0];
	gTextId.value = nLayout;
	}
}

Venda.Ebiz.validateUserExtendedFields = function(frmObj) {
	if(frmObj) {
		var strDOB = frmObj.usxtdob.value;
		var RegExPattern = /^\d{2}[\/]\d{2}$/;
		if ((strDOB.match(RegExPattern)) && (strDOB!='')) {
			var aDOB = strDOB.split("/");
			var month = aDOB[0];
			var day = [aDOB[1],31,29,31,30,31,30,31,31,30,31,30,31];
			
			if ((month>=1 && month<=12) && (day[0]>=1 && day[0]<=day[eval(month)])) {
				return true;
			} else {
				alert("Invalid date");
			}
		} else {
			alert("Please enter date of birth as MM/DD");
		}
	} 
	return false;
};

Venda.Ebiz.hideCyclingButton = function(invtref,target){
	if(invtref && document.getElementById(target)){
		//take the value of all invtref from the target element
		var productCyclingArray = document.getElementById(target).innerHTML;
		//split the value by / then keep them into array
		productCyclingArray = productCyclingArray.split("/");
		var currentProduct = invtref;
		// check current invtref with first and last item in array if match then hide the button(s)
		if(currentProduct == productCyclingArray[0]){
			document.getElementById("previousInvt").style.display="none";
		}
		if(currentProduct == productCyclingArray[productCyclingArray.length-2]){
			document.getElementById("nextInvt").style.display="none";
		}
	}
};

 /**
 * To focus to phone number textbox when area code is complete filled to max length. The function is used for onkeyup on area code textbox.
 * @param {object} 'obj' is the area code textbox.
 * @param {object} 'target' is the phone number textbox.
 * @param {integer} if 'countspec' is specify then it will be used to determined the area code length filled and jump to phone number.
 */
 Venda.Ebiz.jumpToPhone = function(obj, target, countspec){
	var result = document.getElementById("result");
	if (obj && target) {
		var count = obj.maxLength;
		if (arguments.length==2 && count<1) {count = 3;}
		else if ((arguments.length==3) && (countspec!=count && countspec<count)) {count = countspec;}
		
		if (count>0 && obj.value.length==count) {
			target.focus();
			target.select();
		}
	}
}

Venda.namespace('Ebiz.BKList');

Venda.Ebiz.BKList = function(){};

Venda.Ebiz.BKList.jq = jQuery;

Venda.Ebiz.BKList.init = function(bklist) {
	this.bklist = bklist;
};

Venda.Ebiz.BKList.jq(document).ready(function() {
	var bklist = Venda.Ebiz.BKList.bklist || Venda.Platform.getUrlParam(document.location.href, "bklist") || "";
	if (bklist != "") {
		// change value dropdown
		
			
		// change link prev/next page
		Venda.Ebiz.BKList.jq("ul.products a").attr("href", function() {
			return Venda.Ebiz.BKList.jq(this).attr("href") + "&bklist=" + bklist; 
		});
		Venda.Ebiz.BKList.jq("#buttons a#previousInvt").attr("href", function() {
			return Venda.Ebiz.BKList.jq(this).attr("href") + "&bklist=" + bklist; 
		});
		Venda.Ebiz.BKList.jq("#buttons a#nextInvt").attr("href", function() {
			return Venda.Ebiz.BKList.jq(this).attr("href") + "&bklist=" + bklist; 
		});
		

	}
});


 
/**
 * For Expand Collapse Hidden Div
 */
 var catopen=false;
 jQuery(document).ready(function(){
	jQuery("#catopen,#preopen").click(function(E){
		jQuery("#topsellersslider,#relatedbasket").show("slow");
		jQuery("#topsellersslider ul#topsellerssliderlist").show("slow");
		jQuery("#catclose,#preclose").show("slow");
		jQuery("#catopen,#preopen").hide("slow");
		if(!catopen){
		var classtoset = new Array ('#topsellerssliderlist li','#topsellerssliderlist li .details', '#topsellerssliderlist li .details h3', '#topsellerssliderlist li .details .price', '#topsellerssliderlist li .details .quickbuy', '#topsellerssliderlist li .details .moreinfo','#relatedbasket ul li','#relatedbasket ul li .details','#relatedbasket ul li .details h3','#relatedbasket ul li .details p.price','#relatedbasket ul li .details p.quickbuy','#relatedbasket ul li .details p.moreinfo','#relatedbasket ul li .details .setheigh');
		Venda.Platform.EqualHeight.init(classtoset);
			catopen=true;
		}
	});
	jQuery("#catclose,#preclose").click(function(E){
		jQuery("#topsellersslider,#relatedbasket").hide("slow");
		jQuery("#catclose,#preclose").hide("slow");
		jQuery("#topsellersslider ul#topsellerssliderlist").hide("slow");
		jQuery("#catopen,#preopen").show("slow");
	});
	jQuery("#topsellerssliderlist li,#productlist ul.products li,#searchresults .prods ul li,#relatedbasket ul li").hover(function(){
            jQuery(this).find(".details").css({"visibility":"visible"});			
        },function(){
			jQuery(this).find(".details").css({"visibility":"hidden"});	
			jQuery(this).find(".image").css({"visibility":"visible"});	
	});

	
	//This function is used for  EqualHeight - search result page
	//Venda.Platform.EqualHeight.jq(document).ready(function(){
	var classtoset = new Array ('#searchresults .prods ul li','#searchresults .prods ul li .details','#searchresults .prods ul li .details .setheigh','#searchresults .prods ul li .details h2','#searchresults .prods ul li .details p.price','#searchresults .prods ul li .details p.quickbuy','#searchresults .prods ul li .details .pricebox','#searchresults .prods ul li .morecolor','#searchresults .prods ul li .details p.nostock','#searchresults .prods ul li .details p.moreinfo','#productlist ul.products li','#productlist ul.products li .details','#productlist ul.products li h2.prodname','#productlist ul.products li .details .setheigh','#productlist ul.products li .details .pricebox','#productlist ul.products li .details p.quickbuy','#productlist ul.products li .morecolor','#productlist ul.products li .details p.nostock','#productlist ul.products li .details p.moreinfo','#topsellersslider ul#topsellerssliderlist li','#topsellersslider ul#topsellerssliderlist li .details','#topsellersslider ul#topsellerssliderlist li .details h3','#topsellersslider ul#topsellerssliderlist li p.price','#topsellersslider ul#topsellerssliderlist li p.quickbuy','#topsellersslider ul#topsellerssliderlist li p.moreinfo');
	 Venda.Platform.EqualHeight.init(classtoset);

 });

 
/**
* ajaxFunction using jQuery
* @param {string} target url
* @param {string} output id
* @param {string} formID if not null > set type=post and require form param
* @param {string} callback function
*/
Venda.Ebiz.ajaxFunction = function(ajaxurl,whichDiv,formID,fnAfterLoading) {	
	var ajaxtype = (formID!="")?"POST":"GET";
	var ajaxdata=(formID!="")?jQuery("#"+formID).serialize():"";
	jQuery.ajax({type: ajaxtype,
		url: ajaxurl,
		data: ajaxdata,
		success: function(data){
			jQuery("#"+whichDiv).html(data);
			fnAfterLoading();
		},
		dataType: "html"});
};

