/**
* @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");

 /**
 * The following global variables (directly below) are NEEDED to support legacy javascript functions - DO NOT REMOVE! see RT#113376 for more details.
 * 1. shown
 * 2. hidden
 */

var shown = new Image();
shown.src = "/venda-support/images/bulleton.gif";
var hidden = new Image();
hidden.src = "/venda-support/images/bulletoff.gif";

var monthName=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
 /**
 * 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>');
	}
};

/**
 * change cout char on giftmessage
 * @param {string} target object
 * @param {string} count field name,
 * @param {number} maximun chars
 */
Venda.Ebiz.TrackCount =function(fieldObj,countFieldName,maxChars){
	var countField = eval("fieldObj.form."+countFieldName);	
	var diff = maxChars - fieldObj.value.length;	
	// Need to check & enforce limit here also in case user pastes data
	if (diff < 0){
	  fieldObj.value = fieldObj.value.substring(0,maxChars);
	  diff = maxChars - fieldObj.value.length;
	  alert('Please limit the text ' + maxChars+ ' characters.');
	}
	countField.value = diff;
};
/**
 * hide update button on shopping basket when products cannot update qty
 * @param {string} hide element
 * @param {string} qty field
 */
Venda.Ebiz.disableUpdatebt=function(ele,qtyfield){
	var hasUpdatableItem=false;
	jQuery(qtyfield).each(function(){
		if(jQuery(this).attr("type")!="hidden"){
			hasUpdatableItem=true;
		}
	});
	if(!hasUpdatableItem){jQuery(ele).hide();jQuery(ele).addClass("hide");}
};

/**
 * set oixt for
 * @param {string} wrap ID,class to specifield target element
 * @param {object} {oixt field name, value} 
 */
Venda.Ebiz.SetOixt=function(ParentID,oixtconfig){
	jQuery.each(oixtconfig,function(oixtname, oixtvalue){
		jQuery("#"+ParentID+" ."+oixtname+" input[type=text]").attr("value",oixtvalue);
	});
 };

Venda.namespace("Ebiz.LastaddedArtist");
Venda.Ebiz.LastaddedArtist = function(){};
 /**
 * save artist name from last added product
 * @param {string} icat reference
 */
Venda.Ebiz.LastaddedArtist.set=function(icatref){
	var lastaddedproduct = new CookieJar({expires:3600*24*10,path: '/'});
	lastaddedproduct.put('lastaddedsku', icatref);
};
 
Venda.Ebiz.LastaddedArtist.get=function(target){
	var lastaddedproduct = new CookieJar({expires:3600*24*10,path: '/'});
	var sku=lastaddedproduct.get('lastaddedsku');
	if(sku && sku!=""){
		var handleSuccess = function(o){
			if(o.responseText !== undefined || o.responseText.length !=""){
				jQuery(target).attr("href",o.responseText);
			}
		};
		var handleFailure = function(o){};
		var request = YAHOO.util.Connect.asyncRequest('GET', "/invt/"+sku+"&temp=icaturl&layout=blank", {success:handleSuccess,failure: handleFailure});
	}
};
/**
 * Change child product attribute same as paernt(change request)
 * @param {string} new sttribute value
 */
Venda.Ebiz.ChangeChildAttribute = function(newValue){
	var preorder=Venda.Ebiz.AttributeSwatch.changeReleaseDate();	
	jQuery(".musiclist select[name=att1]").each(function(){
		var current=document.getElementById(jQuery(this).attr("id"));
		var available=false;
		for(var index=0;index<current.length;index++){	
			if(current.options[index].value==newValue){
				current.selectedIndex=index;
				jQuery(this).trigger("onchange");
				available=true;
			}
		}
		jQuery("#trackformat").html("format: "+newValue);
		var invtuuid=jQuery(this).parents("form").find("input[name=invtuuid]").attr("value");
		var price=jQuery.trim(jQuery("#PriceDiv_"+invtuuid).html());
		if(!available || price=="" || preorder==1){
			jQuery(this).parents("form").find("div.addbuybutton .add").hide();
			if(jQuery(this).parents("form").find("div.addbuybutton .tracknotavailable").length==0){
				jQuery(this).parents("form").find("div.addbuybutton").append('<!--<img class="tracknotavailable" alt="Not Available" src="/content/ebiz/universalmusic/resources/images/bt_tracknotavailable.gif"/>-->');
			}else{
				jQuery(this).parents("form").find("div.addbuybutton .tracknotavailable").show();
			}
			current.selectedIndex=0;jQuery(this).trigger("onchange");			
		}else{
			if( preorder==0){
				jQuery(this).parents("form").find("div.addbuybutton .tracknotavailable").hide();
				jQuery(this).parents("form").find("div.addbuybutton .add").show();
			}
		}
		jQuery("div.addbuybutton").show();
	});
};
/**
 * display discover album/artist
 * @param {string} target object to write output
 * @param {string} link id to do prodcess when click
 * @param {string} target page
 */
Venda.Ebiz.showdiscover = function(targetID,targetlinkID,targetPage){
	target=document.getElementById(targetID);
	if(jQuery("#"+targetID).css("display")=="block"){
		jQuery("#"+targetID).slideUp();
		jQuery("#"+targetlinkID).removeClass("arrowup").addClass("arrowdown");
	}else{	
		if(jQuery("#"+targetID+".readytoview").length==0){
			jQuery("#"+targetID).addClass("loading");
			ajaxFunction(targetPage,targetID)
			jQuery("#"+targetID).removeClass("loading");
			jQuery("#"+targetID).addClass("readytoview");			
		}
		jQuery("#"+targetID).slideDown();
		jQuery("#"+targetlinkID).removeClass("arrowdown").addClass("arrowup");
	}
	
};


/**
 * set attribute sku for tracking track
 * @param {object} {attribe name, value}
 */
Venda.Ebiz.Setatrsku = function(attrDataElement){
	var att1=attrDataElement.att1.value;
	var att2=(attrDataElement.att2)?attrDataElement.att2.value:"";
	var atrsku = '';
	mainproduct=getProduct(attrDataElement.invtuuid);
	for (var eachAttrSet in mainproduct.attributeValues) {
		if(mainproduct.attributeValues[eachAttrSet].values["att1"]==att1 && mainproduct.attributeValues[eachAttrSet].values["att2"]==att2){
			atrsku = mainproduct.attributeValues[eachAttrSet].data["atrsku"];
			break;
		}		
	}
	if(atrsku!="") attrDataElement.targetElement.value=atrsku;
};
 /**
 * A skeleton function for validating user extened fields - needs to be amended by the build team
 * @param {object} frmObj HTML form containing user extended field elements
 */
  /*
Venda.Ebiz.validateUserExtendedFields = function(frmObj) {
	if(frmObj) {
		if ( (frmObj.usxtexample1.checked==false) && (frmObj.usxtexample2.checked==false) && (frmObj.usxtexample3.checked==false))  {	
			alert("Please tick at least one checkbox");
			return false;
		}			
		return true;		
	} 
	return false;
};
*/
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(unescape(document.location.href), "bklist") || "";
	if (bklist != "") {
		// change value dropdown
		var selectObj = Venda.Ebiz.BKList.jq("#searchresults #sortby").get(0);
		if (selectObj) {
			var isCorrectObj = selectObj.length || selectObj.options.length > 0 || false;
			if (isCorrectObj) {
				for (var i = 0; i < selectObj.length; i++) {
					selectObj.options[i].value = selectObj.options[i].value + "&bklist=" + bklist;
				}
			}
		}
		var selectObj = Venda.Ebiz.BKList.jq("#searchresults #perpagedpd").get(0);
		if (selectObj) {
			var isCorrectObj = selectObj.length || selectObj.options.length > 0 || false;
			if (isCorrectObj) {
				for (var i = 0; i < selectObj.length; i++) {
					selectObj.options[i].value = selectObj.options[i].value + "&bklist=" + bklist;
				}
			}

		}		
		// change link prev/next page
		Venda.Ebiz.BKList.jq(".pagnNumList a").attr("href", function() {
			return Venda.Ebiz.BKList.jq(this).attr("href") + "&bklist=" + bklist; 
		});
		Venda.Ebiz.BKList.jq(".refinelist a").each(function(){
			var old=Venda.Ebiz.BKList.jq(this).attr("href");
			Venda.Ebiz.BKList.jq(this).attr("href",old+"&bklist=" + bklist);
		});
		// remove bklist out of the breadcrumb
		Venda.Ebiz.BKList.jq(".categorytree a").attr("href", function() {
			var currentLink = Venda.Ebiz.BKList.jq(this).attr("href");
			var newLink = currentLink;
			if (newLink.length > 2) {
				if (currentLink.indexOf("&bklist=") != -1) {
					newLink = currentLink.substring(0, currentLink.indexOf("&bklist="));
				}
				if (newLink.indexOf("&view=") != -1) {
					newLink = newLink.substring(0, newLink.indexOf("&view="));
				}
			}
			return newLink;
		});
		Venda.Ebiz.BKList.jq("input[name=bklist]").each(function(){
			Venda.Ebiz.BKList.jq(this).attr("value",bklist);
		});
		Venda.Ebiz.BKList.jq("#bklist").attr("value",function() {
                        return bklist;
		});
		Venda.Ebiz.BKList.jq("#campaign li a,.viewallversion a,.bklist a").each(function(){
			var old=Venda.Ebiz.BKList.jq(this).attr("href");
			Venda.Ebiz.BKList.jq(this).attr("href",old+"&bklist=" + bklist);
		});
	}
});
 /**
 * Buy attribe product by click "add to basket" ot each attribute (change request)
 * @param {Obj} form of each product 
 * @param {string} attrhidden is target hidden field to set attribute name
 * @param {string} attrref is attribure ref
 * @param {string} next is the process to do next
 */
Venda.Ebiz.buyAttribute=function(form,attrhidden,attrref,target, next ){
  // Set the form target
  if ( target != "" )  {
    form.target = target;
  }
  // Set the hidden field in the form
  if ( next != "" )  {
    form.next.value = next;
  }
  document.getElementById(attrhidden).value=attrref;
  form.ex.value='co_disp-shopc';
};

 /**
 * Switch currency on current page
 * @param {string} target currency
 * @param {string} from currency
 * @param {string} current currency
 * @param {string} base URL http://domainname.dot

 */
Venda.Ebiz.currencySwitch=function(target,from,current,baseURL){
	jQuery("#"+target).attr("href",function(){
		var URL=unescape(location.href);
		var Path=URL.replace(baseURL,"");		
		Path=Path.replace("&setlocn="+target+"&log=4","");
		URL=URL.replace(baseURL+"/"+from,baseURL+"/"+target);
		if(Path.search(/(page|pcat|scat|stry|invt|icat)/ig)==1){
			/* not used dispview: invt,icat, stry,scat,pcat,page */
			URL=baseURL+"/"+target+Path;
			return URL;
		}
		if(URL.indexOf(baseURL+"/"+from)==0){ 
			/* used dispview: invt,icat, stry,scat,pcat,page */
			URL=URL.replace(baseURL+"/"+from,baseURL+"/"+target);
			return URL;
		}else if(URL.indexOf("ex=co_wizr-locayta")>0){
			/* search -- ex=co_wizr-locayta*/
			if(URL.indexOf("&setlocn="+from)>0){
				URL=URL.replace("&setlocn="+from,"&setlocn="+target);
			}else{
				URL+="&setlocn="+target;
			}
			if(URL.indexOf("&log=4")==-1){URL+="&log=4";}
			return URL;
		}else if(URL.indexOf("ex=co_disp-shopc") > 0 & URL.indexOf("mode=add") > 0){
			/* after add to basket */
			if(URL.indexOf("searchparameters=")>0){
				/* add to basket on search result */
				var searchparameters=Venda.Platform.getUrlParam(location.href,"searchparameters");
				var bklist=Venda.Platform.getUrlParam(location.href,"bklist");
				if(bklist){searchparameters+="&bklist="+bklist}
				URL=baseURL+"/bin/venda?ex=co_wizr-locayta&"+searchparameters;
				if(URL.indexOf("&setlocn="+from)>0){
					URL=URL.replace("&setlocn="+from,"&setlocn="+target);
				}else{
					URL+="&setlocn="+target;
				}
				if(URL.indexOf("&log=4")==-1){URL+="&log=4";}
			}else if(document.referrer&&document.referrer!=""){
				/* add to basket on other page --- invt,icat ... etc. */
				URL=unescape(document.referrer);
				URL=URL.replace(baseURL+"/"+from,baseURL+"/"+target);
			}else{
				/* unable to handle back to home */
				URL=baseURL+"/"+target+"/page/home";
			}
			return URL;			
		}else{
			if(URL.indexOf(baseURL+"/"+target)>=0){
				return URL;
			}else{
				return baseURL+"/"+target+"/page/home";
			}
		}		
	});
};


/* ----- 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/animal/resources/images/noswatch.gif";

Venda.Ebiz.AttributeSwatch.initListAttributes = function(attrColumn, attrName) {
	var invtuuid=document.getElementById("invtuuid").value;
	mainproduct=getProduct(invtuuid);
	for (var eachKey in mainproduct.attributeValues) {
		if (typeof mainproduct.attributeValues[eachKey] != "function") {
			this.addToListAttributes(attrColumn,mainproduct.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]+"');Venda.Ebiz.ChangeChildAttribute('"+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]+"');Venda.Ebiz.ChangeChildAttribute('"+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');Venda.Ebiz.ChangeChildAttribute('"+this.ListAttributes[attrColumn][i]+"'); 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 = "<span class=sizeselected>" + this.attrDisplayName[1] + "</span> "+ this.filters['att2'] + " - Please select a " + this.attrDisplayName[0] + ".";
		}else if(this.filters["att2"]=="" || this.filters["att2"]==undefined){
			document.getElementById("alertmessage").innerHTML = this.filters['att1'] + " - 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"]+", <span class=sizeselected>" + this.attrDisplayName[1] +"</span> " + 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";
			document.getElementById("alertmessage").style.display="inline";
			isSelected = false;
		}else{
			document.getElementById("alertmessage").style.display="none";
		}
	}else{
		if(this.filters["att1"]==undefined || this.filters["att2"]==undefined || this.filters["att1"]=="" || this.filters["att2"]==""){
			document.getElementById("alertmessage").className = "warning";
			document.getElementById("alertmessage").style.display="inline";
			isSelected = false;
		}else{
			document.getElementById("alertmessage").style.display="none";
		}
	}
	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="";var invtuuid=document.getElementById("invtuuid").value;
	mainproduct=getProduct(invtuuid);
	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 mainproduct.attributeValues) {
		if(Venda.Ebiz.ProductDetail.config.isDigitalProduct){
			if(mainproduct.attributeValues[eachAttrSet].values[attrColumnSelect]==attrValue){this.existingAttributes[a]=mainproduct.attributeValues[eachAttrSet].values[attrColumn];a++;}
		}else{
			if(mainproduct.attributeValues[eachAttrSet].values[attrColumnSelect]==attrValue && (mainproduct.attributeValues[eachAttrSet].data["atronhand"]>0)){
				this.existingAttributes[a]=mainproduct.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 invtuuid=document.getElementById("invtuuid").value;
	mainproduct=getProduct(invtuuid);
	var str="<ul class=attribute_"+attrColumn+">";
	for (var eachAttrSet in mainproduct.attributeValues) {
		if(Venda.Ebiz.ProductDetail.config.isDigitalProduct){
			this.existingAttributes[a]=mainproduct.attributeValues[eachAttrSet].values[attrColumn]; 
			a++;
		}else{
			if(mainproduct.attributeValues[eachAttrSet].data["atronhand"]>0){
				this.existingAttributes[a]=mainproduct.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.changeReleaseDate = function(){
	var invtuuid=document.getElementById("invtuuid").value;
	var releaseD="";
	var releaseM="";
	var releaseY="";
	var preorder=0;
	var releasedtxt=document.getElementById("releasedtxt").innerHTML;
	var notreleasedtxt=document.getElementById("notreleasedtxt").innerHTML;
	var NOW=new Date();
	mainproduct=getProduct(invtuuid);
	if (this.attrNum == 1) {
		for (var eachAttrSet in mainproduct.attributeValues) {
			if(mainproduct.attributeValues[eachAttrSet].values["att1"]==this.filters["att1"]){
				var releaseDate=new Date();
				if(mainproduct.attributeValues[eachAttrSet].data["atrreleasedy"]!="" && mainproduct.attributeValues[eachAttrSet].data["atrreleasemn"]!="" && mainproduct.attributeValues[eachAttrSet].data["atrreleaseyr"]!=""){
					releaseD=parseInt(mainproduct.attributeValues[eachAttrSet].data["atrreleasedy"]);
					releaseM=parseInt(mainproduct.attributeValues[eachAttrSet].data["atrreleasemn"])-1;
					releaseY=parseInt(mainproduct.attributeValues[eachAttrSet].data["atrreleaseyr"]);
					releaseDate.setFullYear(releaseY,releaseM,releaseD);
					if(NOW>releaseDate){
						/* released */
						document.getElementById("releasedate").innerHTML=releasedtxt+releaseDate.getDate()+" "+monthName[releaseDate.getMonth()]+" "+releaseDate.getFullYear();
						jQuery("#emailme").hide();
						jQuery("#addproductform .add").show();
						preorder=0;
					}else{
						/* not released*/
						document.getElementById("releasedate").innerHTML=notreleasedtxt+releaseDate.getDate()+" "+monthName[releaseDate.getMonth()]+" "+releaseDate.getFullYear();
						jQuery("#addproductform .add").hide();
						jQuery("#emailme").show();
						preorder=1;
					}
				}else{
					document.getElementById("releasedate").innerHTML="";
					jQuery("#addproductform .add").hide();
					jQuery("#emailme").show();
					preorder=1;
				}
			}
		}
	}
	jQuery("#releasedate").show();
	return preorder;
};
Venda.Ebiz.AttributeSwatch.changePrice = function(id, wasid){
	var price = "";
	var wasprice = "";
	var invtuuid=document.getElementById("invtuuid").value;	
	if(document.getElementById(id) && document.getElementById(wasid)){
		mainproduct=getProduct(invtuuid);
		if (this.attrNum == 1) {
			for (var eachAttrSet in mainproduct.attributeValues) {
				if(mainproduct.attributeValues[eachAttrSet].values["att1"]==this.filters["att1"]){
					price = mainproduct.attributeValues[eachAttrSet].data["atrsell"];
					wasprice = mainproduct.attributeValues[eachAttrSet].data["atrwas"];	
				}
			}	
		} else if (this.attrNum == 2) {
			for (var eachAttrSet in mainproduct.attributeValues) {
				if(mainproduct.attributeValues[eachAttrSet].values["att1"]==this.filters["att1"] && mainproduct.attributeValues[eachAttrSet].values["att2"]==this.filters["att2"]){
					price = mainproduct.attributeValues[eachAttrSet].data["atrsell"];
					wasprice = mainproduct.attributeValues[eachAttrSet].data["atrwas"];	
				}
			}		
		}
		/* if price of attribute = null, set to blank */
		if (price == "") { price = "";}
		if (wasprice == "") { wasprice = this.defaultwasprice; }	
		if (price != "" && price!="0" && price!="0.00") {
			price=parseFloat(price);
			document.getElementById(id).innerHTML = product.labels['currsym'] + (price.toFixed(2));
			if (wasprice!="" && parseFloat(wasprice)>parseFloat(price)) {
				wasprice=parseFloat(wasprice);
				document.getElementById(wasid).innerHTML = product.labels['atrwas']+"<span class=\"waslabel\">"+product.labels['currsym'] + (wasprice.toFixed(2))+"</span>";
			}else{
				document.getElementById(wasid).innerHTML = "";
			}
			jQuery("#"+id).parent().css({"display":"block"});
		}else{
			jQuery("#"+id).parent().css({"display":"none"});
		}
	}else{
		/* do nothing */
	}
	
};

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: "",
	isDigitalProduct:true
};
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+"\" onmouseover=\"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);\" onclick=\"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 - " + this.config["mediumTitle"],
																		imgTitle: this.config["mediumTitle"],
																		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"]+"\">"+this.config["viewLargeText"]+"</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 - " + this.config["sideviewTitle"],
										imgTitle: this.config["sideviewTitle"]
						});
			} else {
				allSideview = allSideview + this.getImageTag({
										currentImage: n,
										imgSource: this.allImages[attValue].settsideview[i],
										imgChange: "",
										attValue: attValue,
										alt: this.config["sideviewTitle"],
										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 = this.config["sideviewHeader"];
		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";
};
Venda.Ebiz.displayCatetree=function(cattreeSource,separator,searchresult){
	var cattree=document.getElementById(cattreeSource).innerHTML;
	var splited=cattree.split(separator);
	var Catstring="";
	if(splited.length>2){
		for(var i=2;i<splited.length;i++){
			if(i==splited.length-1 || (splited.length-3==0)){
				var URL=unescape(location.href);
				if(URL.indexOf("ex=co_wizr-locayta")>0 || URL.indexOf("searchparameters=")>0){
					// on search result page					
					Catstring+=splited[i] +separator + searchresult;
				}else{					
					var removedLink=splited[i].match(/^(<.+>)(.+)(<.+>)$/);
					if(removedLink){
						Catstring+=removedLink[2];
					}else{
						 Catstring+=splited[i];
					}
				}				 
			}else{
				Catstring+=splited[i]+separator;
			}
		}
		document.getElementById(cattreeSource).innerHTML=Catstring;
		document.getElementById(cattreeSource).style.display="inline";
	}	
};
 Venda.Ebiz.activeDownloadbuttonorlk=function(){
         jQuery("#orderdetail .downloadbutton a").click(function(){
                 jQuery("#orderdetail").hide();
                 jQuery("#downloadcontent").show();
                 return false;
         });
 };
 
 Venda.Ebiz.activeDownloadbuttonorfn=function(){
         jQuery("#orderreceipt .downloadbutton a").click(function(){
                 jQuery(".checkoutorfnR").hide();
                 jQuery("#downloadcontent").show();
                 jQuery("li.checkoutStep4On").addClass("checkoutStep4");
                 jQuery("li.checkoutStep4").removeClass("checkoutStep4On");
                 jQuery("li.checkoutStepdownload").addClass("checkoutStepdownloadOn");
                 jQuery("li.checkoutStepdownloadOn").removeClass("checkoutStepdownload");
                 return false;
         });
 };
 
  /*
 *  submit product list on  icat offers . clone from Multi-add.js ;)
 */
 Venda.Ebiz.submitOffers = function(sender){
	var str = 0;
	jQuery(".attrproducts select").each(function(){
		if(jQuery(this).val()==""){
			str++;
		}		
	});
	if(str==0){
		document.productform.submit();
	}else{
		alert("Sorry, that combination is not available to purchase. Please try another.");
	}
	return false;
};
 
 
 /*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	jQuery("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		jQuery("body").append("<p id='tooltip'>"+ this.t +"</p>");
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		jQuery("#tooltip").remove();
    });	
	jQuery("a.tooltip").mousemove(function(e){
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
jQuery(document).ready(function(){
	tooltip();
});
 

/**
 * validate promocode in templates/invt/promomerchadisedetail
 * @param {string} code input id
 */
var lccheck=function(n) {var N=n.replace(/\D/g, '');var pt=n.length%2,t=0;for (i=0; i < N.length; i++) {var d=parseInt(N.charAt(i));d=(i%2==pt)?d*2:d;d=(d>9)?d-9:d;t=t+parseInt(d);}return (t%10==0);}
 
Venda.Ebiz.validatepromoCode = function(codeid){
	var skuprefix=jQuery("#addproductform input[name=invt]").attr("value").substr(0,5);
	var promocode=jQuery.trim(jQuery("#"+codeid).attr("value"));
	var codepart=promocode.match("^([a-zA-Z0-9]{3})([0-9]{8})([a-zA-Z0-9]{2})$");
	if(promocode=="enter your code" || promocode==""){
		/* blank Promocode */
		alert('Please enter a valid promotional code.');
		return false;
	}
	if(!codepart){
		alert('Sorry the promotion code you entered is invalid, please try again.');
		jQuery("#"+codeid).focus();
		return false;
	}
	var skupart=codepart[1]+codepart[3];
	var luhnpart=codepart[2];
	if(!lccheck(luhnpart) || skuprefix!=skupart){
		/* validate promocode FAIL */
		alert('Sorry the promotion code you entered is invalid, please try again.');
		jQuery("#"+codeid).focus();			
		return false;
	}
	return true;
};
