/**
* @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("alertmessage").className = "normal";
	// update alert message
	Venda.Ebiz.AttributeSwatch.updateMessage();
};

Venda.Ebiz.AttributeSwatch.updateMessage = function(){
	if(this.attrNum==1){
		if(this.filters["att1"]!=""){
			document.getElementById("alertmessage").innerHTML = this.filters['att1'];
		}
	}else{
		if(this.filters["att1"]=="" || this.filters["att1"]==undefined){
			document.getElementById("alertmessage").innerHTML = "Please select a " + this.attrDisplayName[0] + ".";
		}else if(this.filters["att2"]=="" || this.filters["att2"]==undefined){
			document.getElementById("alertmessage").innerHTML = "Please select a " + this.attrDisplayName[1] + ".";
		}
		if((this.filters["att1"]!="") && (this.filters["att2"]!="") && (this.filters["att1"]!=undefined) && (this.filters["att2"]!=undefined)){
			document.getElementById("alertmessage").innerHTML = this.filters["att1"]+", " + this.attrDisplayName[1] +" " + 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("alertmessage").className = "warning";
			isSelected = false;
		}
	}else{
		if(this.filters["att1"]==undefined || this.filters["att2"]==undefined || this.filters["att1"]=="" || this.filters["att2"]==""){
			document.getElementById("alertmessage").className = "warning";
			isSelected = false;
		}
	}
	return isSelected;
};

// 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;	
	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++;
		}
	}
	this.updateListAttributes(attrColumn);
};

Venda.Ebiz.AttributeSwatch.checkAvailOneAttributes = function(attrColumn, attrName) {
	this.existingAttributes = new Array();
	this.availAttributes = new Array();
	a=0;	
	var str="<ul class=attribute_"+attrColumn+">";
	for (var eachAttrSet in product.attributeValues) {
		if(product.attributeValues[eachAttrSet].data["atronhand"]>0){
			this.existingAttributes[a]=product.attributeValues[eachAttrSet].values[attrColumn]; 
			a++;
		}
	}
	this.updateListAttributes(attrColumn);
};

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"]){
				price = product.attributeValues[eachAttrSet].data["atrsell"];
				wasprice = product.attributeValues[eachAttrSet].data["atrwas"];	
			}
		}	
	} 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"]){
				price = product.attributeValues[eachAttrSet].data["atrsell"];
				wasprice = product.attributeValues[eachAttrSet].data["atrwas"];	
			}
		}		
	}

	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)}
};







/* ----- 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,
	objProduct: null,
	swatchTitle: "",
	sideviewTitle: "",
	mediumTitle: "",
	viewLargeTitle: "",
	viewLargeText: "",
	loadingHeader: "",
	loadingImage: "",	
	popupHeader: "",
	imageware: ""
};
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) {
		if(!Venda.Ebiz.AttributeSwatch.pdxtImageware){
			// not use image ware
			imgTag = "<a href=\""+mappingData.imgPopup+"\" onclick=\"Venda.Ebiz.ProductDetail.doPopup('"+mappingData.attValue+"',this.href, "+mappingData.currentImage+"); return false;\" title=\""+mappingData.imgTitle+"\">"+ imgTag + "</a>";
		}else{
			// use image ware
			imgTag = this.config["imagewareLink"] + 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 imgSource = (mappingData.no)? this.allImages[attValue].setmsideview[mappingData.no-1] : this.allImages[attValue].setmedium;
	var imgPopup = (mappingData.no)? this.allImages[attValue].setlsideview[mappingData.no-1] : this.allImages[attValue].setlarge;
	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 = "<span></span>" + mainImage;	
	YAHOO.util.Event.addListener(["zoom_img2"],"click", Venda.Widget.Lightbox.showImageware);
};

Venda.Ebiz.ProductDetail.changeViewLargeLink= function(mappingData) {
	var attValue = mappingData.attValue;
	var imgPopup = (mappingData.no)? this.allImages[attValue].setlsideview[mappingData.no-1] : this.allImages[attValue].setlarge;	
	var viewLarge = "";
	if (imgPopup !="") {
		viewLarge = "<div class=\"enlarge\"><a href=\""+imgPopup+"\" onclick=\"Venda.Ebiz.ProductDetail.doPopup('"+attValue+"',this.href, 0); return false;\" title=\""+this.config["viewLargeTitle"]+"\"><img src=\""+ this.config["viewLargeText"] + "\" alt=\""+this.config["viewLargeTitle"]+"\"></a></div>";
	} 
	if(this.config["objLinkArea"]!=null){
		this.config["objLinkArea"].innerHTML = viewLarge;		
	}
};

Venda.Ebiz.ProductDetail.changeSideviewSet = function(attValue) {
	var allSideview = "";
	var n = 0;
	for (var i = 0; i < this.allImages[attValue].settsideview.length; i++) {
		n++;
		if (this.allImages[attValue].settsideview[i] !="") {
			if (this.allImages[attValue].setmsideview[i] !="") {
				allSideview = allSideview + this.getImageTag({
										currentImage: n,
										imgSource: this.allImages[attValue].settsideview[i],
										imgChange: this.allImages[attValue].setmsideview[i],																				
										attValue: attValue,
										alt: "Alternative views - " +attValue,
										imgTitle: this.config["sideviewTitle"]
						});
			} else {
				allSideview = allSideview + this.getImageTag({
										currentImage: n,
										imgSource: this.allImages[attValue].settsideview[i],
										imgChange: "",
										attValue: attValue,
										alt: attValue,
										imgTitle: this.config["sideviewTitle"]																																						
						});				
			}

		}
	}
	this.config["objSideviewArea"].innerHTML = allSideview;
	this.showSideviewImage();
};

Venda.Ebiz.ProductDetail.changeSet = function(attValue) {
	if (this.allImages[attValue]) {
		this.changeMainImage({attValue:attValue});
		// if not tick imageware then use script to change link
		if(!Venda.Ebiz.AttributeSwatch.pdxtImageware){this.changeViewLargeLink({attValue:attValue});}	
		this.changeSideviewSet(attValue);
		
		
	}
};
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.setmedium);
		this.preloadImage(allImageData.setlarge);
		for (var eachImage in allImageData.settsideview) {
			this.preloadImage(allImageData.settsideview[eachImage]);			
		}
		for (var eachImage in allImageData.setmsideview) {
			this.preloadImage(allImageData.setmsideview[eachImage]);			
		}
		for (var eachImage in allImageData.setlsideview) {
			this.preloadImage(allImageData.setlsideview[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 = posLeft+"px";
		document.getElementById("swatchUnavailTooltip").style.top = posTop+"px";
	}
}

Venda.Ebiz.AttributeSwatch.hideTooltipMessage = function (){
	document.getElementById("swatchUnavailTooltip").className = "hide";
}
 /**
 * 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();
		}
	}
}